Happy New Year to everyone! Hopefully you all ate lots of food and drank a few lemonades over the Christmas break.
I foresee a big year for Squarebit in the number of products that I will be adding to the store over the course of the year. This year I am hoping to also increase the frequency of my posts here and write a lot more about the various projects that I do, both for Squarebit and in my spare time.
- New Years Interactive SMS Screen
- Arduino Software
- Processing software - SMS
- Processing software – Countdown clock
- Admin Command Set
- Wrap Up
- Arduino and Processing Code [zip]
Last week for New Years Eve, I was fortunate enough to be able to spend it with all of my friends and have a good old fashioned house party. We needed a countdown clock and being the geekreally cool guy and alpha male of my group I decided to create one and display it at the party. I usually take things too far and a simple countdown clock wouldn't do.
Riding the wave of social media, everyone likes to send short tweets to each other or write on each others walls of Facebook. I took the idea of writing on walls a step further and created an interactive SMS screen that people could send messages to and have them projected onto an actual wall!
I had a few ideas about how I could achieve this. Using the internet allowed various methods (Twitter, Facebook, a dedicated web page) however, the house we were at does not have the internet connected, and being in a popular tourist area meant mobile internet reception at Christmas was almost non-existent.
Today everybody has a mobile phone on them, and most people have free or near free SMS, so this was the perfect way to get people to send their messages. As Squarebit is Australia's distributor for IteadStudio, I had access to their GSM module that sends and receives both SMS and phone calls using a standard SIM card. Combined with an Arduino Leonardo, this provided a very simple and cost effective receiver from my perspective, and also a very intuitive and practically free solution for the users. I had not used a GSM module before and this seemed like the perfect project to get into it in depth.
This GSM is a fantastic piece of hardware and very well made from Itead Studio. It uses a IComSat chip to connect to the phone network and interfaces via software serial to the Arduino. The software serial pins are selectable with jumper pins on the board in case you have another shield already attached.
Using various AT commands, the Arduino is able to instruct the module to do almost anything that a regular mobile phone can do, from sending and receiving and SMS, to making and accepting a phone call (there is on board headphone and mic jacks!), to even making data connections using GPRS to send and receive data from the internet!
As for the SIM card, any providers SIM will do. As this isn't a complete phone, it is not “locked” to a network. I went down to my local service station and picked up a $2 prepaid SIM and since I had no intention of sending text messages, just receiving, I didn't need to put credit on it. I did need to go through the registration process online with the telco provider to activate the SIM card under my name and to obtain a mobile number.
As this is a common mobile interface chip for use with the Arduino, the major driver software had already been written to allow the Arduino to communicate to the GSM shield. There a couple of different software libraries available, and after trying a few the best one that I found was from open-electronics.
I must admit that I had very little knowledge about AT commands and interfacing to GSM modules. The software is fairly self explanatory and the included tutorials on the site are a good read for some background information. If you would like a bit more solid information, I would suggest doing a bit of research into AT commands and reading the software library code to get a better understanding.
I first experimented with the library examples to receive a text message and output the result over serial to the Arduino. At first this wasn't working and I wasn't receiving any information, the software would continuously time-out with the error DB:NO RESP, ERROR: SIM900 doesn't answer. Check power and serial pins in GSM.cpp
I traced through the code to find why the error was occurring and in finding the spot it still wasn't much clearer. I continued to read the comments at the site and finally I realised I had not turned the GSM shield on!
One thing that I found wasn't clear to me at first was that the GSM shield has it's own power switch. This switch needs to be pressed and the green light on the board needs to flash on. When you do this, and if debugging is switched on in the code, that is #define DEBUG_ON is uncommented in GSM.h, you should see a heap of codes fly over the serial lines and the SIM should now be connected to the network.
I was now able to send text messages to the controller and have them appear on the Arduino serial console! This processes took me about an hour or so of programming and debugging.
For the user display, I went with Processing as my interface language. Processing is a very easy to use language for creating interfaces while also allowing an interface to serial ports, and hence the Arduino. The interface didn't need to be fancy, just display text messages and also act as a countdown clock.
As stated earlier, when the GSM module boots up and registers the SIM on the network it would spit out a heap of codes over serial. This was useful for debugging but not so pretty for the final projected screen. I could have disabled this in the library but as a work around each time that I received an SMS I would parse on the Arduino, and format into a string in the format
I used a pipe (|) as delimiter as not only was it not used in the GSM library output, but also it would be very unlikely that someone sending a text message would used one in their message also. It turns out this theory was correct!
Once the message had been sent from the Arduino over serial to the Processing sketch, it was just a matter of displaying it on the screen. I wanted to display the name of the person that sent the SMS alongside their message. I had all of the mobile numbers of my friends that were attending the party and their numbers were hard coded into an array with their names. As a new message was recieived d, the Processign sketch would go through the array until the number was found, pull out the name, and put in on the screen with the message. If a person's number was not in the array, their message would not be displayed.
I programmed the system to store up to 15 messages, the maximum allowed based one the height of the screen resolution vs the font size. As obviously not all messages are going to be single lines, I needed to do a bit of pixel calculations and testing with line numbers to make sure multi line messages displayed over multiple lines too.
In the bottom right hand corner of the screen was the mobile number of the SIM in the GSM mobile so people wouldn't bug me all night for the number!
As a bonus feature, we have a friend that is overseas at the moment and I wanted him to get involved as well. His international mobile number was added to the array like everyone else’s, however when a message was received by him, his name was changed to a different colour to make it more obvious that he had sent a message.
Not to be forgotten, and the main point of new years eve, is the countdown clock! Throughout the night the countdown clock was a simple text field at the bottom left of the screen with the SMS messages as the focus. As the night went on the clock ticked down but as it got closer to midnight obviously the clock should become the primary focus and the SMS messages should disappear.
At each cycle of the sketch, the Processing program would check the time and update the clock at each changing second. At ten minutes to midnight the countdown clock changed from a small line in the bottom to take up the whole screen. There was quite a bit of blank space on the screen with just the clock so I also made the lower portion of the screen have a a few text messages as well.
In the final seconds of the year the countdown clock was the major feature. I made the seconds remaining take up the whole screen, starting at 12 seconds rather then ten for a bit of a run up!
Finally at midnight the screen displayed a Happy New Year message!
I also wanted a way to be able to control the system as the night went on. Rather then go inside to the PC and fiddle around with a keyboard or mouse, I created a basic command set that would allow me to send specifically formatted commands via SMS to the GSM module, and have them parsed by the Processing interface to control certain aspects of the system. On previously coded admin phone numbers could issue these commands.
I also wanted to send text messages to the wall so I didn't want all of the messages from my mobile number to be treated as admin commands. To differentiate between messages that I wanted to add to the wall as a user and those as an admin, a semi-colon was used as a delimiter between commands and extra data.
As stated earlier, I have all of the mobile numbers of my friends that were attending the party and their numbers were hard coded into an array with their names. However I knew people would be there whose numbers I didn't have and I wanted to be able to add these people without typing and then recompiling.
Using the add command, I was able to send a text message to add a user's number to the array. For feedback that this actually happened and as a sanity check for myself, a welcome message would be displayed where the countdown clock message at the bottom left is for a few seconds.
Mistakes happens and sometimes during testing I would add a number to the array with the incorrect spelling of a name. By sending the add command again, if the mobile number was previously in the array, the name that was issued with the second add command would overwrite this name. Again the welcome message is shown as feedback of its success.
;del;[message id];[admin reason – optional]
I also wanted to be able to delete messages from the wall. As I would only display 15 messages, the message at the bottom has message ID 15, the second from the bottom 14, and so on. By sending a text message with the delete command and the message number, that message would be deleted. While not elegant, it worked!
The message is not actually deleted but rather overwritten with the text [message deleted]. By including another semi-colon and adding some text a reason can be added . Finally, if the admin reason is “forever”, the message is actually deleted from the array of messages.
;alert;[message];[line 2];[line 3]
I though that perhaps I would like to be able to issue large, communal alerts to everyone. On receiving the alert command, the whole screen would be taken up with a single large message. Line breaks can be added by including multiple semi-colons in the message alert.
After new years, the happy new years message is displayed indefinitely. I could have just made it a time-out message and go back to the SMS screen, but instead I chose to send a message to revert back to the SMS message board. On going back to this screen, the countdown clock mesasge in the bottom left displayed a happy new years message.
All up this was one very over the top countdown clock but it was very well received. I didn't think it was get as much use as it did but I was ecstatic that everyone enjoyed it and had fun with it. Highlighting my overseas friends messages on the board brought him into the party as well and let him say hello to everyone there.
If you want to use this, the code is freely available here. All you need as an Arduino, a GSM module, and a PC running the Processing sketch. I wrote this in about three days and it isn't the best code I have written but it works well and I hope you find it useful!
I am hoping that next new years, or at parties across the world, people can implement a similar board for their friends to use and interact with. I would love to know what other features people add to it and what they use it for, so if you do use it, please take some pictures and send me an email and so I can show it on the site!