Program a character into a dot matrix display and show it off on your backpack!
LED-HACKPACK-2-min.jpg

A simple project to display cool 8-bit art and animation on your backpack! This is a quick and easy project you could finish off in minutes and show off to your friends. What it does is, when you move your backpack, a dot matrix display turns on and shows any character you have programmed in it. In this case its a fun pixelated character.

dot-matrix-display-stuff-to-use-min.jpg

How Does the LED Hackpack Work?

The objective of the project is to light up a character on a dot matrix display. The display should light up when you move the bag. There are two parts to this project.

Part 1: The Wake Part

This part uses the accelerometer to sense when the bag moves. The accelerometer sends this data to the Arduino via the ‘Analog In’ pins.

Part2: The Display Part
The display shown on the LED matrix is driven by the MAX7219 IC. It talks to the Arduino using the SPI protocol. But we don't need to know much about this because there's a library “ledcontrol” that does the job for us.

Wiring Up the Dot Matrix Display, Arduino, and Accelerometer

circuit-min.jpg

The circuit is as straight forward as it gets. The accelerometer returns analog values for acceleration in each axis. But here we only need the values for one axis. So connect either the X,Y or Z axis output from the accelerometer to any of the analog input pins (I have used A0 in the code provided). Power up the accelerometer. Be careful at this point because some modules use 3.3V and some use 5V. Give power accordingly or else you might end up with a burnt module. Connect its ground (GND) to the ground on the Arduino.

figure-min.jpg

The dot matrix display has 3 input pins DIN (Data in), CS (Chip Select) and CLK (Clock). These are SPI (Serial Peripheral Interface) pins. Like I said before, the library does the job for us :) They are all digital, connect them to any of the GPIO pins. I connected DIN to pin 13, CS to pin 12, CLK to pin 11 in the code provided.

The dot matrix display takes in power via the 5V pins from the Arduino. Connect ground (GND) to the ground on the Arduino. And that's all there is with the circuit.

The Code

We should include the LedControl.h library to our code. This is what makes talking to the LED dot matrix display extremely easy.


As this is not an included library in the Arduino IDE, we should manually add it. If you don’t know how to, follow this guide to importing libraries on Arduino.

The code:

#include "LedControl.h"
LedControl lc=LedControl(13,11,12,1);
int a[5],k=0,rno=0;
unsigned long delayTime=200;
byte invader1a[] =
{
B00011000,  			// First frame of invader #1
B00111100,
B01111110,
B11011011,
B11111111,
B00100100,
B01011010,
B10100101
};

byte invader1b[] =
{
B00011000, 			// Second frame of invader #1
B00111100,
B01111110,
B11011011,
B11111111,
B00100100,
B01011010,
B01000010
};

byte invader2a[] =
{
B00100100, 			// First frame of invader #2
B00100100,
B01111110,
B11011011,
B11111111,
B11111111,
B10100101,
B00100100
};

byte invader2b[] =
{
B00100100,		 	// Second frame of invader #2
B10100101,
B11111111,
B11011011,
B11111111,
B01111110,
B00100100,
B01000010
};

void lister(){			//  Makes a stack of the analog input from A0
for (k=0;k<4;k++){	
a[k]=a[k+1];
}
a[4]=analogRead(A0)/75;
Serial.print("Input = ");
Serial.println(a[4]);
delay(100);
}

int check(){			// Checks all the values in the stack and returns 1 if any value is different
int flag=0;
for(k=0;k<4;k++){
if(a[k]!=a[k+1]){
flag=1;
break;
}

}
return(flag);
}

void sinvader1a()		// Draws frame one from invader #1
{
for (int i = 0; i < 8; i++)  
{
lc.setColumn(0,i,invader1a[i]);
}
}

void sinvader1b()		// Draws frame two from invader #1
{
for (int i = 0; i < 8; i++)
{
lc.setColumn(0,i,invader1b[i]);
}
}

void sinvader2a()		// Draws frame one from invader #2
{
for (int i = 0; i < 8; i++)  
{
lc.setColumn(0,i,invader2a[i]);
}
}

void sinvader2b()		// Draws frame two from invader #2
{
for (int i = 0; i < 8; i++)
{
lc.setColumn(0,i,invader2b[i]);
}
}

void setup(){
lc.setIntensity(0,5); 	 // Set intensity level
lc.clearDisplay(0); 		 // Clear Display
}

void disp(long sel){ 		// Displays invader depending on the arguments recived
if(sel==1){
sinvader1a();
delay(delayTime);
sinvader1b();
delay(delayTime);
}
if(sel==2){
sinvader2a();
delay(delayTime);
sinvader2b();
delay(delayTime);
}
}

void loop(){

int inc=-1,test;
lister();
test=check();
Serial.print("Test = ");
Serial.println(test);
if (test==1){
lc.shutdown(0,false);	//Truns on the display
disp(rno);
}
else{

if(rno==0||rno==1)
inc=-inc;

rno=rno+inc;
lc.shutdown(0,true);	// Turns off the display
}
}

Here are some of the basic functions in the header:

Creating a new LedControl Variable: (‘lc’ in this case)

LedControl lc=LedControl(13,11,12,1);  // DIN, CLK, CS, No of grids used

Turning on the dot matrix display:

lc.shutdown(0,false);
Note: Initially the grid is in a low power state.

To Clear the display:

 lc.clearDisplay(0);

To set individual LEDs high:

lc.setLed(0,row,col,true);

Setting entire columns/rows in one go:

lc.setColumn(0,i,array[x]);
lc.setRow(0,i,array[x]);

To know more read: http://wayoda.github.io/LedControl/pages/software

Upload the code provided to the Arduino.

Calibration

Dot-matrix-printer-2-min.jpg

Insert the display head pins through the fabric

dot-matrix-display-hackpack-1-min.jpg

Conceal the electronics inside the bag and connect the display driver to the pins.

Play around with the delay and A0’s division factor. Do this till you are happy with how sensitive your backpack is to motion.

You might have to play around with these values as you change power sources too.

Show It Off!

Show off your cool new addon to your friends. And get them interested in becoming Makers too! Check out the demo video of my project.

NOTE: You could add more characters to the display by playing around with the ‘disp’ function and the arguments it receives. Play around with the ‘sinvader’ functions to change the orientation of the characters. ‘lc.setColumn’ could be changed to ‘lc.setRow’ for this.

Vinayan Hari

Maker Pro Logo
Continue to site
Quote of the day

-