element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Upcycle It
  • Challenges & Projects
  • Design Challenges
  • Upcycle It
  • More
  • Cancel
Upcycle It
Blog Upcycled Clock - Commute time to work using Google Maps API
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: carmelito
  • Date Created: 13 May 2017 4:37 AM Date Created
  • Views 1366 views
  • Likes 6 likes
  • Comments 5 comments
  • upcycledclock
  • python
  • upcycle_it
  • upcycleit
  • led strip
  • apa102
  • google_maps
  • Espeak
  • iot
  • intel edison
Related
Recommended

Upcycled Clock - Commute time to work using Google Maps API

carmelito
carmelito
13 May 2017

If you live in California, specifically in Los Angeles and the surrounding counties you soon realize that the area has a huge traffic problem, which meant I had to find a more visual way of identifying, what is the ideal time to leave for work, which is normally a 25 to 30 mins commute on a good day. I know you’re going to say we have “google now” and many other service, but nothing beats an visual LED indicator. The idea here is that as part of the final setup we are going to replace one of the mirror panels with a 3D printed part which diffuses the LEDs. Here is a quick video that demo’s the setup and I am using eSpeak to read out the time to work, for more details on eSpeak and how to setup it up check out blog at - Upcycled Clock - Reading out the weather using eSpeak

 

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

 

As part of setup we are going to use the Google Maps Distance Matrix API to capture the time to work, which is basically the “duration_in_traffic” element in the JSON returned by the API once you have followed the setup steps below.

 

To get started go the documentation link below, and use Get A Key button to create

https://developers.google.com/maps/documentation/distance-matrix/start

  • an app
  • followed by generating the API key.

Now create the URL, and modify the origin and destination address to suite your needs. And you will also have to add in the API key. In addition, a suggestion here is to use a tool like Postman to check that your URL is well formed, and to check if you get a response from the Maps API which is basically a JSON.

https://maps.googleapis.com/maps/api/distancematrix/json?origins=395+santa+monica+place,+Santa+Monica,+CA&destinations=21821+Oxnard+St,+Woodland+Hills,+CA|&traffic_model=best_guess&key=YourAPIKey&departure_time=now

 

 

{gallery} Google Maps - Distance matrix API

image

Create the App

image

Make a note of the API Key

image

Using Postman to test the URL, which returns a JSON

 

 

For the circuit as show in the picture below , I used

Grove button connected to D2 , which is used to trigger the Google Maps API

To power the LED strip , I am using 4x AA batteries

  • Data – pin #11
  • Clock – pin #13

For a running a basic test with the LED strip check out blog at - Upcycled Clock – Testing the RGB LED strip

And a portable speaker connected to USB sound card, which reads out the time to work.

image

Before you run the python program below you will also have to setup eSpeak ,  check out blog at - Upcycled Clock - Reading out the weather using eSpeak

 

Now Update the python program with you URL that you created and test above and upload and run the python program on your Intel Edison

 

#!/usr/bin/python
# Create by Carmelito to test time it would take to get to work using Google Maps API and LED strip, and this is based on
# Google Maps API -Distance Matrix - https://developers.google.com/maps/documentation/distance-matrix/intro#traffic-model
# Grove Button https://github.com/intel-iot-devkit/upm/blob/master/examples/python/grovebutton.py
# Led Strip https://github.com/intel-iot-devkit/upm/blob/master/examples/python/apa102.py


import urllib2, json
from upm import pyupm_grove as grove
from upm import pyupm_apa102 as mylib
import time
import subprocess

def get_time_intraffic():
    #modify the URL below based to add your orgin, destination address and API Key from google
    response = urllib2.urlopen('https://maps.googleapis.com/maps/api/distancematrix/json?origins=395+santa+monica+place,+Santa+Monica,+CA&destinations=2… ')
    data = json.load(response)
    timeInTraffic = data['rows'][0]['elements'][0]['duration']['value']
    distanceInTraffic = data['rows'][0]['elements'][0]['distance']['value']
    print ('distance :'+str(distanceInTraffic/1000)+ ' km' + ' time to work :' + str(timeInTraffic/60) + ' mins')
    return timeInTraffic/60


def main():
    #Grove button connected to D2 on grove connector shield
    button = grove.GroveButton(2)
    # Grove light sensor connected to A2
    lightSensor = grove.GroveLight(2)
    #Instantiate a strip of 30 LEDs on SPI bus 0 connect data-D12 and Clk - D11
    ledStrip = mylib.APA102(60, 0, False)
    ledStrip.setAllLeds(61,0,0,0)
    time.sleep(1)
    text = 'Hello from the Intel Edison'
    while True:
        print(button.name(), ' value is ', button.value())
        print ("Light Value: " + str(lightSensor.raw_value()))
        if button.value() == 1:
            #get the time to work from home in mins
            timeInTraffic = get_time_intraffic()
            print (timeInTraffic)
            if timeInTraffic < 30:
                print("Setting all LEDs to Green- time to leave now")
                text = 'Leave now, there is no traffic, time to work  '+str(timeInTraffic) +'   minutes'
                try:
                    subprocess.check_output(['espeak', text])
                except subprocess.CalledProcessError:
                    print ("Something is not working..")
                ledStrip.setAllLeds(61, 0, 255, 0)
                time.sleep(2)
            elif timeInTraffic >= 30 and timeInTraffic <40:
                print("Setting all LEDs to orange - hmm flip a coin")
                text = 'Hmm, there is seems to be some traffic,  time to work  '+str(timeInTraffic) +'   minutes'
                try:
                    subprocess.check_output(['espeak', text])
                except subprocess.CalledProcessError:
                    print ("Something is not working..")
                ledStrip.setAllLeds(61, 200, 100, 100)
                time.sleep(2)
            elif timeInTraffic >= 40:
                print("Setting all LEDs to Red - to much traffic")
                text = 'It a bad idea to leave now, there is a lot of traffic and the time to work is  '+str(timeInTraffic) +'   minutes'
                try:
                    subprocess.check_output(['espeak', text])
                except subprocess.CalledProcessError:
                    print ("Something is not working..")
                ledStrip.setAllLeds(61, 255, 0, 0)
                time.sleep(2)
            else:
                print("Do nothing")
        if lightSensor.raw_value() < 150:
            print("Light value below threshold, setting all LEDS off")
            ledStrip.setAllLeds(61,0,0,0)
            time.sleep(2)
        time.sleep(1)
    # Delete the button object
    del button


if __name__ == '__main__':
    main()

 

 

 

References for the blog

Google Maps Distance Matrix API - https://developers.google.com/maps/documentation/distance-matrix/start

eSpeak Documentation - http://espeak.sourceforge.net/commands.html

Postman for testing the API- https://www.getpostman.com/docs/postman/launching_postman/sending_the_first_request

  • Sign in to reply

Top Comments

  • balearicdynamics
    balearicdynamics over 8 years ago +2
    Hello Carmelito, this commute time idea sounds very helpful and it is not a problem only in your area, as Workshopshed signals; I can suggest also Germany, Italy, Netherlands, Sofia (Bulgaria), Madrid…
  • DAB
    DAB over 8 years ago in reply to Workshopshed +2
    I ended up just spending the night at one of the hotels near the airport. That way I could just drive in at any time the night before, get a good nights sleep and have the hotel drive me to the airport…
  • DAB
    DAB over 8 years ago +1
    Nice update. Yes, on various business trips to LA, I have spent more than my fair share of time stuck in traffic. DAB
Parents
  • DAB
    DAB over 8 years ago

    Nice update.

     

    Yes, on various business trips to LA, I have spent more than my fair share of time stuck in traffic.

     

    DAB

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Workshopshed
    Workshopshed over 8 years ago in reply to DAB

    I used to work in Valencia (for a few weeks at a time) getting back to LAX was always a grind.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • DAB
    DAB over 8 years ago in reply to Workshopshed

    I ended up just spending the night at one of the hotels near the airport.

    That way I could just drive in at any time the night before, get a good nights sleep and have the hotel drive me to the airport in the morning.

     

    DAB

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
Comment
  • DAB
    DAB over 8 years ago in reply to Workshopshed

    I ended up just spending the night at one of the hotels near the airport.

    That way I could just drive in at any time the night before, get a good nights sleep and have the hotel drive me to the airport in the morning.

     

    DAB

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube