Back to main blog BYOB Party #1, "Bring you own Bulbs" - The Internet of Holiday Lights
This kind of brings back memories from the "Euro vision Song Contest"
Welcome Belgium
Welcome Germany
Welcome Canada...
you get the idea
so what I wanted to do here was to have a matrix display to show a scrolling sign to say welcome to whom ever publishes their name to the "element14_IoT" topic of the Elclipse MQTT broker
I initially tried this using an arduino UNO and could get the display working no problems but there was no room for additional functionality like communications via radio and this was an important feature I wanted
over to Light Strip Larry, the MEGA star sports a significant amount of RAM and FLASH space, the Arduino mega was to be driving some WS2812 LED strips but this seemed more appropriate for a MEGA star and could work
Adafruit has a great article on getting this up and running on an UNO or MEGA and that part was straight forward, now all I needed was to modify it to handle an NRF24L01 while simultaneously driving a 32*128 pixel array of full colour LEDs, well we got there and this is the resulting code and wiring
This is the panel front and back
initial Adafruit article can be found here for those wanting to reproduce my project, all the wiring and code are there to get the first level of the project up and running
https://learn.adafruit.com/32x16-32x32-rgb-led-matrix
This shows the wiring into an UNO, the text is there to tell you the differences when using a MEGA, and yes you have to adhere to them or it will not work, I had to re-configure the NRF24L01 to work around this
With an UNO you rapidly run out of pins too which is another good reason to use a MEGA, here are my attempts
the additional grey ribbon wire running off to the right on the mega is for the NRF24L01 radio
modifying the code was fairly straight forward
Adding the additional headers include statements (NRF stuff)
// Bunch of constants in the form of definitions // 1 = output debug to serial port, 0 = no debug #define debug 0 /* Include needed Lbraries */ #include <SPI.h> #include <Wire.h> #include "nRF24L01.h" #include "RF24.h" #include "printf.h" #include <avr/pgmspace.h> #include <Infineon.h> /* End include libraries */ #include <Adafruit_GFX.h> // Core graphics library #include <RGBmatrixPanel.h> // Hardware-specific library
note there is some code from other IoT-Holiday Lights in there, its been a hectic few weeks and I will eventually get to cleaning it all up
#define CLK 11 // MUST be on PORTB! (Use pin 11 on Mega)
this is the one item you can not ignore when moving to a mega
for the NRF radio I had to use alternate pins as seen in this config statement
RF24 radio(A5, 10);
This same code base has been used through many iterations of holiday light modules so most of the commands below can be ignored in this version, only "SETNAME" is used
//Command Strings PROGMEM const char helloCmd[] = "Hello"; PROGMEM const char SETNAMECmd[] = "SETNAME"; PROGMEM const char REDCmd[] = "RED"; PROGMEM const char GREENCmd[] = "GREEN"; PROGMEM const char BLUECmd[] = "BLUE"; PROGMEM const char WHITECmd[] = "WHITE"; PROGMEM const char FLASHCmd[] = "FLASH"; PROGMEM const char RAINBOWCmd[] = "RAINBOW"; PROGMEM const char OFFCmd[] = "OFF";
I was originally going to have the ability to send commands for other cool stuff but ran out of time
this is the main loop that monitors the NRF radio, the serial port and refreshes the display in a minimal loop
void loop() { // Notice how the main loop is very simple and the functions // seperate the logic into easily manageable parts if (CheckSerial()) { DoCommand(inputBuffer, "\0"); } if (CheckNRF()) { DoCommand(NRFrdata, "\0"); SendNRFTest(); // echo back command } doMatrix(); }
as you can see, there is a call to check the Serial followed by a call to the Radio followed by a call to update the display, if either of the calls to the radio or serial finds data then it will call the command function passing in the command found
Do matrix is the same as found on the Adafruit site so ill not go into details here except where I may make small changes
The DoCommand function is detailed on my tutorials as well no please refer to there for more details ( Fast Track to Arduino Programming )
the one thing to note is that the case statement calls the setDisplayName function when the command is found, passing in with it any parameters that may also be present. remember that because we are using the NRF radios we have a max of 32bytes we can send including the command without getting into more sophisticated code so we have limits in the messages
case SETNAME : SetDisplayName(Parameter, Parameter2 ); break;
so the interesting stuff is in this function
void SetDisplayName(char* newName, char* newName2) { sprintf(str, "Happy New Year: %s %s ", newName, newName2); //strcpy(str, newName); textMin = sizeof(str) * -12; }
As you can see, the changes are pretty simple if you ignore adding the NRF radio stuff and the command processing all of which is explained elsewhere
what this does is add the passed in parameters to the function, it inserts it into the greeting file and exists
the main routine loop as you recall includes a call to doMatrix(), this function takes care of all the business of the bouncy balls and rendering the text, a pretty neat bit of code and the libraries Adafruit include have all sorts of graphics ability too.
You may well ask why even bother with the command which takes away from having a longer message, well if it where omitted then there is a risk of receiving crap from other radios in the vicinity that could mess with the program and later you may want to extend what is done so you may as well have it in from the start
Thats pretty much it for this node, a fairly simple one pragmatically speaking and once running can be quite fun to use. As with the whole project, the NRF Radios prooved to be un reliable at anything more than a few feet, this may be due to all the equipment in the area but i will have to investigate that at another time, I have in the past got much better range out of them so I know it can be done. on the other hand, the new range of WIFI boards that sell for only a few $$$ look very interesting and if they proove to be reliable, I may ditch the NRF radios or at least the NRF24L01 versions altogether
There is a video in my closing blog that will demonstrate all I have talked about as far as the end functionality and it is quite cool