Category Archives: Project

How To Get the Arduino Time Library up and going

I’m working on a new arduino project at the moment and for it to work, I need the arduino to be able to tell the time. 

To make this work, I decided to use the Arduino Time Library (specifically the updated Time library). I was going to use the TimeSerial sketch. I expected this would be an easy task, and indeed it did look straight forward, with nice simple functions to call up the hours (hour()), minutes (minute()) and seconds (second()).

However, despite this, I really struggled in working out what the actual time was. And I’m not sure if it was just that it was late at night, and my brain wasn’t functioning at its fullest, but I really could not find an easy guide anywhere. After lots of trial and error I worked it out, and here, for you, is the tutorial of how to flipping get the flipping Time Library to work.

Know the software to use

I didn’t get this, but you will need to use both the Arduino IDE and Processing. For some reason I thought it was the case that you use one or the other. The Arduino IDE talks to the arduino, and Processing is responsible for getting the time.

Know the programs to run

You will need to run two programs: TimeSerial (in Arduino IDE) and SyncArduinoClock (in Processing). Get these both opened in their respective software.

Image

Edit the Processing sketch

Now what’s going to happen, is Processing is kind of going to “jump start” the Arduino and give it the time at a certain time point. The arduino is capable of keeping time (if it has power) once it knows what the time is initially. So you need to get Processing talking on the right port. When I opened it, the line “public static final short portIndex = 0;” was set to 0, which is a bluetooth port. When you run it, it will try and talk to bluetooth, which wasn’t useful to me. But what was useful, was that in the terminal window at the bottom of Processing, it told me what was on each of the ports. Reading this I saw this line “[4] “/dev/tty.usbserial-A600bMH2″” and so changed the line of code to read “public static final short portIndex = 4;” so that it was now talking to the right port.

Image

Start your engines (in the correct order)

This step got me for a while, you need to start your sketches running in the correct order. If you start Processing first then Arduino complains that it can’t get to the port it wants to. So, start the TimeSerial arduino sketch, in Arduino. If you open the Serial viewer, you’ll see a message that says “Waiting for sync message”. This is because it is waiting for a message from Processing.

At this point, start the SyncArduinoClock Processing sketch. A box will hopefully appear that says “Click to send time sync”. Click it.

Image

You should now see in the Arduino serial monitor that there is a lot of weird text appearing. That is because it’s trying to count for itself, and also receiving sync messages from Processing. Go back to Processing, and stop that sketch running. And back to Arduino, and hopefully, you should be getting a nice neat print out of the date, and time every second. 

You’ll never be late for anything again.

Hope that helped someone avoid the long hours of struggle trying to understand how to get the stupid thing to work!

Tagged ,

Twitfortune

In this post I would like to introduce you to both my new Projects page, and my first project, Twitfortune.

Twitfortune is a website that gives out twitter generated advice, like a fortune cookie. The adive can range from the utterly non-understandable, to amusing, to genuinely useful.

The idea came from seeing many friends posting “note to self” style tweets. I thought it was strange that people use the very public platform of twitter to write seemingly personal things. With this in mind, I decided to call out these ordinarily private tweets and create a website based around them. Seeing as the tweets often contained advice to the author, they suggested a fortune cookie style. The fact that these pieces of advice were not written specifically for others to read gives each fortune a slightly cryptic air.

The process of creating these fortunes is fairly straight forward. I search twitter for the latest instances of the words “note to self”. The tweet is then stripped of these words to leave only the message. Further work is done to remove any puncutation symbols that might follow, to make it look a bit nicer.

The final bit of processing done on the tweets is to make them a little less introspective. All instances of the first person (I, me, my etc) are  replaced with their equivalent second person words (You, your etc). This means they are now peices of advice for the reader. Strangely specific, peculiar, obscure pieces of advice mind you.

After testing it out, I realised that there were two common actions I wanted to do. Firstly, the most amusing ones I wanted to share with people. I found myself taking lots of screen shots and messaging them to my sister. I realised I could make that process easier by providing people with a method of sharing the fortunes: sending them back to twitter! So I added the “Tweet it” option to each fortune. The second action I found myself often doing was translating the tweets. Many people were beginning tweets with the english words “note to self” and continuing on in another language. I wanted to know what they were saying! So I added the “Translate it” option. This takes you straight to the google translation of the fortune, from whatever language it was written in to English.

So there you have it. Twitfortune, check it out!