APC Australia

Add a backpack to your Arduino

Make a tiny 8x8-LED scrolling message board using an Arduino Nano and LED backpack. Darren Yates shows how.

-

Nothing seems to grab the eye faster than a scrolling message board — whether you like it or not, you’re hooked. Over the last few months, we’ve been playing around with the tiny Arduino Nano microcontr­oller and 170-point breadboard you can buy on eBay. The Nano gets you all the features of the larger Arduino Uno, but in a smaller package and there’s a bucketload of extras you can plug in. One of those is a compact 8x8 LED matrix ‘backpack’ for around $5 online, so this month, we’re putting all of this together to create an 8x8 scrolling message board.

HOLTEK HT16K33

The particular backpack we’re using features Holtek’s HT16K33 LED controller chip. There are other popular options, but the HT16K33 module is more compact and uses the I2C or ‘inter-integrated circuit’ serial bus. Despite having 64 individual LEDs, the HT16K33 allows you to drive the whole matrix with just four connection­s, two for power and two for the I2C bus.

You can address each LED individual­ly using the excellent Adafruit_LEDBackpac­k and GFX libraries. The libraries do the hard work of converting ASCII characters into individual LED pixels, so much so that all you have to do is use a simple print(“text”) command. Getting the text to scroll is not as hard as you might think and we can do it using a for-loop.

Swapping hats for a second, elsewhere in APC this month, you’ll find my ‘Learn to code Python’ masterclas­s, where I talk about how loops work. The code here is a bit different, but this message board is a perfect real-life example of why loops are so important.

HOW TO SCROLL

Okay, you can see how the for-loop works here in the source code, which you’ll find at apcmag.com/magstuff. The for-loop allows us to set the ‘cursor’ or text start position. First, its placed at position (7,0), which is the matrix’s top-right corner, thanks to the initial ‘int xpos=7’ parameter in the ‘for’ command. It then runs through the code, setting the cursor, clearing the display, printing the message to the chip and updating it on the matrix. On the next loop through, the variable ‘xpos’ is decremente­d, setting the cursor to (6,0), clearing and reprinting the display. This has the effect of shifting the start of the message one pixel towards the left.

After a 100-millisecon­d delay each time, the loop continues until the value of ‘xpos’ becomes greater than the negative length of the ‘message’ string variable multiplied by six (the pixel width of each character). This way, you can type your message into the source code at the top and the code automatica­lly ensures that the loop size matches the message pixel length. If it didn’t, some of your message’s characters may not display or, if set too high, it may take a day before repeating again.

You can adjust the brightness by using a matrix. set Brightness( level )— where ‘level’ is an integer between 0 (dim) and 15 (bright). That said, we found ‘0’ more than bright enough for indoors.

SETTING ROTATION

The Adafruit library can also rotate the display orientatio­n. Because we’re plugging the matrix straight into a breadboard, we need to rotate the text to appear the right way around. Do this with matrix. set Rotation( int)—w here ‘int’ is an integer value between 0 and 3. Setting this to ‘1’ gives us the correct orientatio­n for our applicatio­n.

PLUGGING INTO THE NANO

The Arduino Nano supports I2C on its A4 (SDA) and A5 (SCL) pins. Thankfully, the pin arrangemen­t on the 8x8 matrix allows us to plug it straight into position aligned with Nano pins A5 to A2. Pin A3 aligns with the HT16K33 module’s GND (0V) pin and pin A2 with the module’s Vcc (5V) pin. The nano has 5V and GND pins on this side of the board, so we just use wire links to connect these up — 5V to A2 and GND to A3. How do we do this without blowing up the A2 and A3 pins? Remember that, with Arduino boards, all analog and digital input/ output (I/O) pins are initialise­d as ‘inputs’ unless specifical­ly coded otherwise. Inputs have a high impedance and as we’re only connecting up standard nano-level voltages in 5V and 0V, those inputs are fine. The whole thing can be powered by any USB port or even a USB battery pack.

FLASHING THE CODE

Once you’ve downloaded the source code zip file, unzip it and copy the contents of the ‘libraries’ subfolder into the same in your Arduino integrated developmen­t environmen­t or ‘IDE’ (download this for free from arduino.cc/ download, we’re using version 1.6.9). Plug the Arduino Nano into your PC and from the IDE menu, select ‘Tools’, set the ‘Board’ to ‘Arduino Nano’, the ‘processor’ to ‘ATMEGA328’ and the ‘Port’ to the COM port for your Nano board. The COM port you need to select will be the one that is not ‘COM1’ — COM1 is your mouse, so if you only have two COM ports listed, choose the other one. Load the ‘messageboa­rd.ino’ source code and from the IDE menu again, choose ‘Sketch’ and ‘Upload’. This will compile the source code into machine code for the Arduino Nano chip and upload it to the board. Provided you’ve followed the overlay wiring diagram and built your message board, within seconds, you should be seeing the ‘welcome’ message scrolling across the display.

Once you’ve programmed the nano board with your message, you no longer need the computer — just plug the Nano’s USB port into a USB battery pack or USB phone charger and the message will scroll indefinite­ly.

HAVE A PLAY

These 8x8 LED backpacks are incredibly useful and there’s a stack of different things you can do with them. Off the top of my head, I’ve got a couple of games, a clock and an audio spectrum analyser. Arduino really is a great way to learn how coding and electronic­s can come together to build almost whatever you want.

 ??  ?? The LED backpack uses Holtek’s HT16K33 driver chip.
The LED backpack uses Holtek’s HT16K33 driver chip.
 ??  ?? The 170-point breadboard is ideal for this project (and the Arduino Nano!).
The 170-point breadboard is ideal for this project (and the Arduino Nano!).
 ??  ?? Enter your own message into the source code before your flash.
Enter your own message into the source code before your flash.
 ??  ?? Use this overlay diagram to wire up the project.
Use this overlay diagram to wire up the project.
 ??  ?? The 8x8 LED matrix backpack requires just four connection­s. The Arduino Nano is a compact, cheap version of the Arduino Uno board.
The 8x8 LED matrix backpack requires just four connection­s. The Arduino Nano is a compact, cheap version of the Arduino Uno board.
 ??  ?? Our tiny 8x8 scrolling message board project fits on a 170-point breadboard.
Our tiny 8x8 scrolling message board project fits on a 170-point breadboard.

Newspapers in English

Newspapers from Australia