We have all had an incident where we were late due to a traffic jam or unforeseen weather. Being on time can sometimes be hard to always do, especially as a college student who commutes to college in a major city (Atlanta). There have been many cases where I was late to class due to heaver traffic, accidents, or weather (people tend to drive slower in bad weather conditions like heavy rain). The solution for this problem is a device that I created called nTime. nTime is an Arduino and PcDuino (similar to a raspberry pi) powered device that automatically sets your alarm based on the weather and traffic data to your destination. For example, if there is a crash on the route to your destination and there is heavy rain, you alarm will be set earlier than if there was low traffic and it is sunny. nTime is also able to alert you of any upcomming events on your google calendar. For example if you had a meeting at 4:00, there would be a reminder on the screen that you have a meeting that day at 4.
Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.
Step 1: How It Works
The way this works is the PcDuino is running a couple APIs: Google Calendar API, Google Maps API, and Yahoo Weather API. All the processing for calculating the optimum alarm time is done within the pcDuino and the information is sent vis serial interface to the Arduino mega that is controlling the screen. The arduino mega also communicates to an Arduino pro mini that controls the neopixels.
Step 2: Supplies
The materials used in this project were:
- Arduino mega
- Arduino pro mini
- 160 x 95 mm project enclosure
- 3.2'' Touch LCD with adapter board
- 2 1W speakers
- Audio amp (for speakers)
- SD card (larger than 8 gb)
- Keyboard and mouse/ HDMI monitor (this is for setting up the pcDuino. After setup I just use putty to ssh into the pcDuino)
- Hot glue gun
- Soldering iron and solder
- Jig saw
Step 3: Setting Up PcDuino
The PcDuino, like a raspberry pi, is a cost effective single board computer. the specific model that I am using is the PcDuino8. In order to setup the PcDuino, you must have an SD card of 8 gb or larger to upload the image to the PcDuino (I used Win32DiskImager to upload the image). The image can be found here:
For more information about the specs of the PcDuino8 and how to upload an image to it please use this start up guide I have attached.
Step 4: Hardware
The hardware for the nTime is fairly simple. The mega with the screen plugs directly into the pcDuino. The arduino with the neopixels is connected to the mega via serial (using serial port 3 on the mega). This arduino is also connected to pin 13 of the PcDuino. This pin goes high whenever any functions are triggered that involve talking (text to speech or TTS). When nTime talks, pin 13 goes high, and this triggers the "night rider" sort of animation on the neopixels.
Step 5: Program PcDuino
Everything on the PcDuino side is run from a python script that I wrote (I attached the script to this instructable). Here is just a brief rundown of what is going on in the script. I first add a series of libraries that are needed to run the script. Some of those libraries need to be downloaded onto the PcDuino. The libraries for running the google API can be downloaded with this command:
$ pip install --upgrade google-api-python-client
More information on the Google API can be found here:
There are a couple of things you have to do before running an API from Google. You have to run a sample script that will download a text file onto the PcDuino with all your credentials (like your API keys and OAuth 2.0 client IDs). More information about how to get started with Google APIs can be found on the link I provided above. This library will work for both the Google maps and Google calendar APIs. Here are some links for running the Google maps and Google calendar APIs:
Google Calendar: https://developers.google.com/google-apps/calendar...
One thing to note about the Google maps API is that it returns two values that tell how long it takes to get to the destination: one is the normal duration, the other is the duration in in traffic. I use the duration in traffic value to calculate exactly when to wake up (see more about calculating the alarm in the "Calculate alarm" section).
For the weather information I used the Yahoo weather API. This API was fairly simple to use. Here is a link with more information and some examples on how to run these APIs. They have a variety of weather APIs that are available. I used the generic forecast API that gives me the current weather and conditions as well as a five day forecast that I plan on implementing into a future model of the nTime.
Getting the data from the json returned by the API was a fairly difficult step. The rest of the python script consists of sending some data down to the arduino via serial communication and computing the alarm times. In order to send serial data down to the arduino, you need to install the python serial library onto the PcDuino. You can do this with this command in terminal:
python -m pip install pyserial
Once installed, be sure to actually import it into the serial port (import serial) and include these lines in the beginning of the script:
ser = serial.Serial('/dev/ttyACM0', 9600)<br>ser.close() ser.open()
This will connect the PcDuino with the arduino directly plugged into the usb port of the PcDuino and allow for serial commands. To send data to the arduino, use the simple ser.write() command and within the parentheses put the data you want to send over. It is important to note that you must send data over as a string. If you want to convert a variable that is an integer to a string you can use this function to convert from integer to string: str(integer). If you want to read data from the arduino, use the ser.read function that will read the incoming data from the arduino. This is the method I used to communicate with the arduino.
If you want to use text to speech (TTS) to allow nTime to have a voice, you need to install espeak. That can be sone with this command:
$ sudo apt-get install espeak
Using espeak is pretty easy. If you want to text if it is working, just plug in a speaker or headphones into the audio jack of the PcDuino and enter this command into terminal:
espeak "Hello world"
You should hear "Hello world" returned as a result.
Please look at the "Calculating alarm" section of this Instructable to see exactly how I calculate when to wake up based on traffic data.
Step 6: Program Arduino Mega
The program for the arduino mega is fairly complicated. While most of the computing is done on the PcDuino, a lot still needs to happen within the arduino mega. First off, a couple of libraries need to be installed. The UTFT and URTouch libraries need to be installed. They can be downloaded here:
After the libraries are installed, you will be able to use the touchscreen and lcd. Please note that sometimes the touchscreen stops working (the lcd does not pick up any touches on the screen). If or when this happens, just unplug and plug the mega back in until it starts to work again. I am not sure why this happens and I am continuing to look for a more permanent solution to this problem. It would take a long time to explain what each aspect of the code is doing so please have a look at it for yourself (warning: its kind of complicated).
The first screen on the display shows the current time and date as well as the current weather and conditions. You can see some of the other screens in the images above and some of the exact features are described in the Features section of this Instructable.
Step 7: Programming Neopixel Arduino
While I was testing the circuit, I used and arduino uno to control the neopixel. I later switched over to a pro mini that would be used in the final enclosure. I hot glued the neopixel to the back of the pro mini to save space when I would move it over to the enclosure. Like mentioned in the hardware step, the this arduino is connected via serial to the arduino mega. The code for the neopixel arduino is pretty simple. In the setup, it waits to receive a "1" from the arduino mega. When it receives a "1", the pro mini initiates the start up in which all the pixels turn on then fade in and out. The pixels will automatically be blue until the settings are changed on the mega using the RGB sliders. The last image shows the RGB sliders that are used to change the color of the neopixels. The camera cant really pick up the color of the neopixels very well, but the box in the upper right corner accuratly shows the color of the neopixels.
Step 8: Making the Enclosure
When making the enclosure, I first designed the layout of nTime in a program called incscape. I simply made measurements of all the components that make up the front of the case and drew those measurements in incscape. I then printed it out and taped it to the front panel of the enclosure. After making holes in the corners of the shapes (as seen in image 3), I used a jig saw to cut out the shapes for the screen, speakers, and neopixel space. After cutting, sanding, and making sure all the components fit in their spaces, I added some metal mesh like material to cover the space for the speakers (image 4). I then cut out spaces for the switch and dc jack on the right side of the enclosure, and on the left side, I just out a space that would allow me to access the Ethernet and HDMI ports of the PcDuino.
Step 9: Audio
For the audio I used the PAM8403 2 channel audio amplifier. You can see quick and simple schematic how I wired up everything. It is very important to have good power to this module because it will reduce extra noise coming out the speakers. The input for the amplifier comes directly from the PcDuino. You can see in image 4 how the amplifier and speakers were placed in the enclosure.
Audio is needed for the alarm mp3 that is played on the PcDuino and also for the text to speech (TTS) that is used to say the current time or say out loud when the your next even is. I plan on doing more with audio in a future model of nTime so be on the look out for version 2.
Step 10: Filling the Case
Next, I filled the front panel with all the components. In the first image, you can see where I placed the lcd, speakers, and neopixel. Image 4 is just a picture of me testing to make sure everything still worked before I put the PcDuino into the enclosure. On the screen you can see I am running the page that allows me to change the color of the neopixel based on some RGB sliders. The next step is to put the PcDuino into the case and make sure everything runs correctly.
Step 11: Using Google Calendar
nTime gets most of its data from google calendar. All the user inputs come from the description of a Google calendar event. In order to work with my python script, the description must be formatted EXACTLY as the one displayed in the first image. The event name must also be titled "Wake up" in order for my script to recognize the event (the name "Wake up" is what allows nTime to differentiate between an event that is used as an alarm or a normal calendar event). These are the inputs that are needed in the description of the calendar event:
- Origin: Input your address or where you are leaving from
- Destination: Input the destination, in my case, it is the address to a building at Georgia State University (the college I attend)
- Preparation time: Put how long it should take you to get ready
- Expected Arrival (army): Put the time you need to be there by. It is important that it is in army time and if the first digit of the time is a single number (1-9) make sure to put a "0" before the hours number
- City you live in: Put the city you live in. This is used for the Yahoo weather API
- City you work in: Put the city you work in. This is also used for the Yahoo weather API
- State (lowercase): Put the state (make sure it is lowercase)
- Error time (min): Input your error time. This is the amount of error time you want to be calculated into your alarm. For example, if you normally don't slack off in the mornings, you should input a lower error time. However, I tend to lollygag in the mornings so I put a higher error time.
One thing to note is that it does not matter when you put the actual event on the calendar. What I mean by this is that you can put the "Wake up" event at anytime throughout the day, as long is it is on the same day that you want to be woken up, the python script will see the "Wake up" name and your alarm will be set. So as long as the event is on the same day you want to be woken up, your alarm will be set.
Step 12: Calculating Alarm Time
After all the information is obtained from running the APIs, I have to calculate the time to wake up. I first convert time to seconds. I do this by multiplying hours by 3600 and minutes by 60. The reason I do this is because it is much easier to compare a single value of seconds than comparing multiple values which I would have to do if I kept time in hours and minutes. It also makes it a lot easier to add and subtract time values.
I calculate the time you need to wake up by subtracting the time you need to be there by the time it takes to get there (this time is obtained from the Google maps API so it is automatically adjusted when there is traffic) then by the prep time that was inputted into the Google calendar description then by the error time (the first image makes makes the calculation seem much simpler). If the current time value (in seconds) is the same as the time value of the alarm, then a signal is sent down to the arduno mega letting it know that it is time to wake up and it displays the alarm screen. If there is any extreme weather conditions like fog, heavy rain, or snow, more time is subtracted from the final alarm time.
Step 13: Getting Calendar Events
nTime is also able to tell you events you have on your calendar (that are not titled "Wake up"). You can see on my calendar that I made an event called "meeting" and it is scheduled for 4:26 pm. When an event is available on your calendar, a notification pops up at the top of your screen (it is yellow and looks sort of like a list; image 2). If you click the notification, nTime tells you the event name and the time usinf TTS. In this case, nTime would say "You have a meeting at 4:26". After it talks, the information about the event is displayed on the screen (image 3).
Step 14: Features
To navigate through the screens of nTime, just use the previous and next buttons on the bottom corners of the screen. There are currently only 2 screens: Image 1 shows the first screen and image 2 shows the second.
Setting a local alarm
If you want to set another random alarm for anytime throughout the day, navigate to the second screen and select the "Set alarm" button. This will open a screen that allows you to set an alarm using the arrows above and below the hours and minutes (image 2). You can confirm the alarm by selecting the "Set alarm" button on the right and you can also adjust the snooze time with the "Snooze" button located under it. The snooze time is automatically set to 10 minutes and it can be changed by selecting this button. When selected, the snooze screen comes up (image 3) and you can select the time you want to snooze for. When the local alarm time equals the current time, the alarm screen pops up (image 4) and you can either stop the alarm by hitting "OK" or snooze it for the specefied time by clicking "Snooze".
nTime will automatically update the weather and any notifications every 2 hours. If you want to update it on the spot, just click the update button located on the bottom next to the previous screen button
If you click the button next to the update button that resembles an old fashion microphone, nTime will say the time out loud using TTS.
Step 15: Future
I do plan on making updates to this project. I am even planing on making a version two with a lot more features that I want to add. If you guys have any suggestions for improvements to nTime or any features you would like to see in a version 2, please leave a comment below! Thanks for viewing my project!
Participated in the
First Time Authors Contest 2016
Participated in the
Arduino Contest 2016
Participated in the
IoT Builders Contest