A timetravelling Plant, which is a 3D printed mechanical plant/flower that shows the time to travel.
The Flower Pot design is a really cool idea and a great make by Jason Suter. A very nice guide can be found on Makezine. It is a really cool mechanical flower with integrated lights and is definately a fun and inspiring 3D printer project.
I placed the code on a raspberry pi which is connected via WiFi. The NeoPixel ring is connected to the GPIOs.
Programming in Python
I made the folling script in python. Essentially the code is doing the following:
- Import necessary libraries
- Define the Neopixel Ring
- Define a mapping function. It converts a percentage of relative time to LED colours between Red and Green.
- Define traveltime function. It use the Google API to go online and retrieves traveltime
- Some calculations. To estimate the relative traveltime, the duration in traffic (current travel time) is taken as a relative measure to duration no traffic.
- Finally, the script calls the necessary functions in order
- Everything is automated within a crontab job - repeating every 5th minute between 3pm and 6pm or whatever fits the best
import requests import time import board import neopixel # definitions num_pixels = 16 pixels = neopixel.NeoPixel(board.D18, num_pixels, brightness = 0.05) def map(x, in_min, in_max, out_min, out_max): if x < in_min: return out_min elif x > in_max: return out_max else: return int((x-in_min) * (out_max-out_min) / (in_max-in_min) + out_min) def traveltime(): origin = 'PLACE YOUR ORIGINAL ADDRESS HERE' dest_01 = 'PLACE YOUR DESTINATION ADDRESS HERE' api_key = 'PLACE YOUR PERSONAL API KEY HERE' url = ('https://maps.googleapis.com/maps/api/directions/json?origin=' + origin + '&destination=' + dest_01 + '&departure_time=now&key=' + api_key) json_data = requests.get(url).json() durnotraf = json_data['routes']['legs']['duration']['value'] durtraf = json_data['routes']['legs']['duration_in_traffic']['value'] recommendation = durtraf / durnotraf return recommendation travel = traveltime() val = map(float(travel), 1, 1.5, 0, 255) pixels.fill((val, 255-val, 0))
Finally I automated the above in a small crontab job
The Timetravelling Plant
The timetravel plant is now placed at my desk - not far from the Weather Frame. The plant keeps monitoring current traffic conditions for my commute - so I don’t need to do that every 5th minute.