New Micro, New Project

New Micro, New Project

So I've discovered my new favorite microcontroller.  It's the Teensy, and right now it is version 3.1.  I've used the Teensy on a few small projects at work, and love how powerful it is, in such a small form factor, while being cheap, and Arduino IDE compatible.  After using the Teensy on a few projects, I doubt I'll ever go back to an Arduino, unless some new awesome version comes out.

Anyway so I have this time off of work, and I wanted to give my self a project using the Teensy while I am off.  I didn't know what I wanted to do but I had a few ideas.  I saw the powerful audio library made for the Teensy and thought that would be a fun start.  I also saw some neat LED matrix boards and thought about some kind of bright sign of some kind.  And lastly I knew I wanted to incorporate the ESP8266 WIFI chip.  This is the dirt cheap WIFI chip from China that has been getting more support from communities, and figured it would be the cheapest way to add wireless to any microcontroller project, assuming a WIFI network exists in the area to connect to.

So with all this in mind, I decided to make some kind of scrolling marquee sign, which could be updated over WIFI.  Later I decided to add the audio capabilities for performing FFTs, to visualize the audio being played on my TV.

Parts List

Teensy 3.1 Microcontroller $20
16X32 LED Matrix $25 X 2 = $50
SmartMatrix Shield for Teensy $15
5V 10A Power Supply $25
ESP8266 WIFI Module $5
Various small electronic components (LM317T Voltage Regulator, 220 Ohm, 330 Ohm, and 4.7K Ohm Resistors, small perf board, capacitor, and push button) less than $10.

Total $125 or so

Wiring

So the construction of the project is relatively simple.  Put together the SmartMatrix Shield for the Teensy, and attach it to one of the 16X32 LED matrix boards using any of the methods described in the instructions.  Then connect the second matrix board to the other with provided ribbon cable.  Powering this setup is easy because our 10A power supply is more than enough for our LEDs, and plugs right into our shield.

A push button was added to switch between modes, and is mostly optional but I had one and figured I'd put it to use.  Wire it so that between ground, and the DI pin is a relativly large resistor.  I used a 4.7K ohm.  Also in my wiring I used DI 15.  Then wire the 3.3V out of the Teensy to one side of the push button, and the other side goes to DI 15.  Now when the button is off ground will be going to the digital, and when it is pressed the digital will see 3.3V which is a high.

I also wired a headphone jack to A2 so that the audio can be visualized in an audio spectrum.

Lastly the WIFI module.  This needs to be powered by 3.3V, but draws too much for the 3.3V from the Teensy.  I tried some large capacitors and it would some times work, but had other issues and in the end I just bought a LM317T voltage regulator to convert my 5V from my power supply, to the 3.3V the WIFI board needed.  Using a value of 220 Ohm for R1 and 330 Ohm for R2 should give an output of 3.13V, plus a small amount for a compensation current.  A different regulator could be used but this is what Radio Shack had.  Then the TX and RX need to be wired up.

Below is very crude drawing of the wiring.  Note that the 5V and Gnd are wired to the Teensy using the shield, and are only shown to have the wiring make sense and shouldn't be wired up if that shield is used.



Software

In my mind this is where it gets interesting.  So the SmartMatrix boards I bought have a working library and demo which generally was designed to work with a single 32x32 matrix board.  I first had to make sure a single 16x32 worked, then looked into making the software support 16x64.  Luckily some work had been done to support multiple boards being daisy chained together, but they were for much older revisions of the library, which didn't have the audio example I wanted.  So I took the newest revision of the library, and updated it with the changes others had made for the older versions to support the wide display.

After this it looked like all the already made functions for text scrolling, and object drawing works on 16x64.  I then looked at the audio example and modified it to support 32 FFT categories instead of 16.  I also added some tweaks to it to dynamically change the scale to help with varying audio levels, and to try to detect when there is no audio, instead of displaying noise.

Next was the ESP8266.  This supports many AT commands and behaves more or less like a serial port, where commands are issued, and then you then parse each byte one at a time to determine what the reply is.  After some examples I was able to connect to my WIFI and get an IP address.  I then sent the commands to allow it to accept connections on port 4040, and then parsed the requested URL and turned that into the text to be displayed.

With these changes now when I turn on my device, it will connect to my WIFI and start displaying the assigned IP address on the scrolling LEDs.  If I navigate to the IP address like in this example it would update the text to be scrolled to "Hello World."

http://192.168.0.119:4040/Hello_World

This is of course only if my device connected successfully and only if the IP address was correct.  At the moment it doesn't support all special characters, and it replaces all underscores with spaces.  I didn't take the time to support replacing "%20" with a space.  It will continue to scroll that text over and over until new text is sent.  Also at the moment the display is limited to 70 characters or less.

All of the source and libraries used can be downloaded from here.  Arduino IDE version 1.0.6 was used and Teensyduino version 1.20 was used.  You'll need to update the SSID and Password to your network before uploading.

Assembly

To make it look a little better I made a small cage for the hardware.  I used a metal stud normally used in walls, and cut them to the length I needed.  I then used some small chunks of metal and screws to make the cage.  The LED panels have magnets on them so they just stick to the metal cage.  In the cage is all the electronics, and the voltage adapter.  I then can hang it from the wall using two screws.  Below are some images of the assembled cage and lights.

Assembled

Back View

Into Back

With Cage Off

Teensy and WIFI Board

And here are a couple videos of it in action.  The first video just shows how the IP address is shown on startup.  The second video shows the 4 modes, of 'text only', 'audio only', 'text and small audio', and then 'text will full audio'.  The lights are bright and during the day time the text is still very easily readable at 30 feet away.  The video may look odd because the camera is constantly trying to adjust for brightness but it looks normal in person.

LED Matrix Startup


LED Matrix In Action


Improvements

So since making this I know of several things that could be better.  These are all optional and maybe I'll get to them some day.  

  • Microphone 
    • I'd rather use a small microphone and amplifier circuit like this one for detecting sound but didn't order one, and besides I figured the best case for getting the right audio signal would be a hard line from a headphone jack.  This would just make it simpler for the user
  • WIFI page for configuring
    • I would be nice if a web page was made for configuring things like what network and password to connect to on the ESP8266 instead of hard coding it in the sketch.
  • VLC page for current song
    • Right now the device is passive and only updates the text if it is told to.  It would be nice if instead the device looked at a URL and read the current playing song from that.  VLC has this capability and when turned on a basic page gives this information.  It would just take some time to write the code to parse it. The software would also need a way to know what the URL.
  • Maybe make it taller
    • Originally I intended on having two rows of text for the song and artist.  But then realized I'd rather have the audio spectrum and went to one row of text.  If I had bought two 32x32 matrix boards, I could have two rows of text, and room for the audio spectrum.  This would increase cost, and the software would need some adjustments because I'm not sure the library currently supports multiples lines of scrolling text.
  • Improve WIFI connection
    • At the moment there is no retry for a network connection, if it fails the display will show 0.0.0.0 for the IP address.  This has only happened a few times but it could detect this, reset the chip and try again.  Also there are several arbitrary waits that I think could be reduced.  And at the moment it will attempt to reconnect to the network each power up, and this is not really needed because the chip remembers the last connection made.  This could also save several seconds on startup.