The purpose of the group assignment this week is to measure the consumption of an output device and document how it was determined. Because of the current situation, I will be conducting the experiment individually with the equipment that I do have, for now.
*TO BE UPDATED*
I wanted to test out the MAX7219 to drive an 8x8 LED display Matrix. First thing was to understand how it works and read the data sheet. The Matrix contains an 8x8 LED sets of rows and columns that can display still or moving images or words which works by pulsating different LEDs for a short time and then shifting the rows and columns to make the object move. The dot matrix display contains numbered rows and columns with 16 pins.
The board contains the MAX7219, two capacitors, and a resistor. The capacitors are used to control the noise signals from the Vin and Gnd and the resistor is used to set an upper limit on the current fed to the diodes. It is also mentioned in some discussions that it would be more appropriate to use an external power-supply if there are more than one matrix. From the arduino we see the four connections (mentioned earlier) and then the same 4 connections that would be used to connect another matrix. SegDP-A-G correspond to the columns and Dig0-8 correspond to the rows when connected to the Matrix.
As the drivers continue switching between the rows of the matrix about 800 times a second, it gives the impression that all the LEDs are constantly on. As explained on the arduino website, the maximum current that a single matrix will ever demand is 8 times the current you have set with the resistor, around 10mA from the MAX7219 and 20mA from the resistor. If all the LEDs are turned on at the same time, the supply will be 170mA. The USB-hub on the computer should supply up to 500mA.
PeakCurrent=(8 x LedCurrent) + MAX7219-Supply
PeakCurrent=(8 x 20mA) + 10mA = 170mA
I began with an example sketch that scrolls text to the left using the MaxMatrix library. (linked below).
#include <MaxMatrix.h>
#include <avr/pgmspace.h>
#define maxDisplays 2 byte Buf7219[7]; const int data = 11; const int load = 10; const int clock = 13; // SCK
MaxMatrix m(data, load, clock, maxDisplays);
PROGMEM const unsigned char CH[] = {
3, 8, B0000000, B0000000, B0000000, B0000000, B0000000, 1, 8, B1011111, B0000000, B0000000, B0000000, B0000000, 3, 8, B0000011, B0000000, B0000011, B0000000, B0000000, 5, 8, B0010100, B0111110, B0010100, B0111110, B0010100, 4, 8, B0100100, B1101010, B0101011, B0010010, B0000000, 5, 8, B1100011, B0010011, B0001000, B1100100, B1100011, 5, 8, B0110110, B1001001, B1010110, B0100000, B1010000, 1, 8, B0000011, B0000000, B0000000, B0000000, B0000000, 3, 8, B0011100, B0100010, B1000001, B0000000, B0000000, 3, 8, B1000001, B0100010, B0011100, B0000000, B0000000, 5, 8, B0101000, B0011000, B0001110, B0011000, B0101000, 5, 8, B0001000, B0001000, B0111110, B0001000, B0001000, 2, 8, B10110000, B1110000, B0000000, B0000000, B0000000, 4, 8, B0001000, B0001000, B0001000, B0001000, B0000000, 2, 8, B1100000, B1100000, B0000000, B0000000, B0000000, 4, 8, B1100000, B0011000, B0000110, B0000001, B0000000, 4, 8, B0111110, B1000001, B1000001, B0111110, B0000000, 3, 8, B1000010, B1111111, B1000000, B0000000, B0000000, 4, 8, B1100010, B1010001, B1001001, B1000110, B0000000, 4, 8, B0100010, B1000001, B1001001, B0110110, B0000000, 4, 8, B0011000, B0010100, B0010010, B1111111, B0000000, 4, 8, B0100111, B1000101, B1000101, B0111001, B0000000, 4, 8, B0111110, B1001001, B1001001, B0110000, B0000000, 4, 8, B1100001, B0010001, B0001001, B0000111, B0000000, 4, 8, B0110110, B1001001, B1001001, B0110110, B0000000, 4, 8, B0000110, B1001001, B1001001, B0111110, B0000000, 2, 8, B01010000, B0000000, B0000000, B0000000, B0000000, 2, 8, B10000000, B01010000, B0000000, B0000000, B0000000, 3, 8, B0010000, B0101000, B1000100, B0000000, B0000000, 3, 8, B0010100, B0010100, B0010100, B0000000, B0000000, 3, 8, B1000100, B0101000, B0010000, B0000000, B0000000, 4, 8, B0000010, B1011001, B0001001, B0000110, B0000000, 5, 8, B0111110, B1001001, B1010101, B1011101, B0001110, 4, 8, B1111110, B0010001, B0010001, B1111110, B0000000, 4, 8, B1111111, B1001001, B1001001, B0110110, B0000000, 4, 8, B0111110, B1000001, B1000001, B0100010, B0000000, 4, 8, B1111111, B1000001, B1000001, B0111110, B0000000, 4, 8, B1111111, B1001001, B1001001, B1000001, B0000000, 4, 8, B1111111, B0001001, B0001001, B0000001, B0000000, 4, 8, B0111110, B1000001, B1001001, B1111010, B0000000, 4, 8, B1111111, B0001000, B0001000, B1111111, B0000000, 3, 8, B1000001, B1111111, B1000001, B0000000, B0000000, 4, 8, B0110000, B1000000, B1000001, B0111111, B0000000, 4, 8, B1111111, B0001000, B0010100, B1100011, B0000000, 4, 8, B1111111, B1000000, B1000000, B1000000, B0000000, 5, 8, B1111111, B0000010, B0001100, B0000010, B1111111, 5, 8, B1111111, B0000100, B0001000, B0010000, B1111111, 4, 8, B0111110, B1000001, B1000001, B0111110, B0000000, 4, 8, B1111111, B0001001, B0001001, B0000110, B0000000, 4, 8, B0111110, B1000001, B1000001, B10111110, B0000000, 4, 8, B1111111, B0001001, B0001001, B1110110, B0000000, 4, 8, B1000110, B1001001, B1001001, B0110010, B0000000, 5, 8, B0000001, B0000001, B1111111, B0000001, B0000001, 4, 8, B0111111, B1000000, B1000000, B0111111, B0000000, 5, 8, B0001111, B0110000, B1000000, B0110000, B0001111, 5, 8, B0111111, B1000000, B0111000, B1000000, B0111111, 5, 8, B1100011, B0010100, B0001000, B0010100, B1100011, 5, 8, B0000111, B0001000, B1110000, B0001000, B0000111, 4, 8, B1100001, B1010001, B1001001, B1000111, B0000000, 2, 8, B1111111, B1000001, B0000000, B0000000, B0000000, 4, 8, B0000001, B0000110, B0011000, B1100000, B0000000, 2, 8, B1000001, B1111111, B0000000, B0000000, B0000000, 3, 8, B0000010, B0000001, B0000010, B0000000, B0000000, 4, 8, B1000000, B1000000, B1000000, B1000000, B0000000, 2, 8, B0000001, B0000010, B0000000, B0000000, B0000000, 4, 8, B0100000, B1010100, B1010100, B1111000, B0000000, 4, 8, B1111111, B1000100, B1000100, B0111000, B0000000, 4, 8, B0111000, B1000100, B1000100, B0000000, B0000000, 4, 8, B0111000, B1000100, B1000100, B1111111, B0000000, 4, 8, B0111000, B1010100, B1010100, B0011000, B0000000, 3, 8, B0000100, B1111110, B0000101, B0000000, B0000000, 4, 8, B10011000, B10100100, B10100100, B01111000, B0000000, 4, 8, B1111111, B0000100, B0000100, B1111000, B0000000, 3, 8, B1000100, B1111101, B1000000, B0000000, B0000000, 4, 8, B1000000, B10000000, B10000100, B1111101, B0000000, 4, 8, B1111111, B0010000, B0101000, B1000100, B0000000, 3, 8, B1000001, B1111111, B1000000, B0000000, B0000000, 5, 8, B1111100, B0000100, B1111100, B0000100, B1111000, 4, 8, B1111100, B0000100, B0000100, B1111000, B0000000, 4, 8, B0111000, B1000100, B1000100, B0111000, B0000000, 4, 8, B11111100, B0100100, B0100100, B0011000, B0000000, 4, 8, B0011000, B0100100, B0100100, B11111100, B0000000, 4, 8, B1111100, B0001000, B0000100, B0000100, B0000000, 4, 8, B1001000, B1010100, B1010100, B0100100, B0000000, 3, 8, B0000100, B0111111, B1000100, B0000000, B0000000, 4, 8, B0111100, B1000000, B1000000, B1111100, B0000000, 5, 8, B0011100, B0100000, B1000000, B0100000, B0011100, 5, 8, B0111100, B1000000, B0111100, B1000000, B0111100, 5, 8, B1000100, B0101000, B0010000, B0101000, B1000100, 4, 8, B10011100, B10100000, B10100000, B1111100, B0000000, 3, 8, B1100100, B1010100, B1001100, B0000000, B0000000, 3, 8, B0001000, B0110110, B1000001, B0000000, B0000000, 1, 8, B1111111, B0000000, B0000000, B0000000, B0000000, 3, 8, B1000001, B0110110, B0001000, B0000000, B0000000, 4, 8, B0001000, B0000100, B0001000, B0000100, B0000000, };
void setup()
{
m.init();
m.setIntensity(3);
}
char string[] = "The quick brown fox juumped over the lazy DOG.;:@'+=-/&";
void loop()
{
delay(100);
m.shiftLeft(false, true);
printStringWithShift(string,100);
}
void printCharWithShift(char c, int shift_speed)
{
if (c < 32) return;
c -= 32;
memcpy_P(Buf7219, CH + 7*c, 7);
m.writeSprite(maxDisplays*8, 0, Buf7219);
m.setColumn(maxDisplays*8 + Buf7219[0], 0);
for (int i=0; i<=Buf7219[0]; i++)
{
delay(shift_speed);
m.shiftLeft(false, false);
}
}
void printStringWithShift(char* s, int shift_speed)
{
while (*s != 0)
{
printCharWithShift(*s, shift_speed);
s++;
}
}
This sketch has the PROGMEM qualifier which places data inside the programming memory to embed the type face which will them be called through memcpy_p(). The PROGMEM stores the data in the flash memory instead of the SRAM that is avialable in the MAX7219 so as to make sure not to fill up the SRAM if you print a lot. In the case of our example sketch above, the full alphabet and some characters are saved in the flash memory to allow us to simply type the phrase as in char string[] = "";.
To understand the void printCharWithShift function I checked the ASCII table and I looked at the html number associating the alphabet. In the void function we see that if c < 32 it "returns" meaning does nothing and detects again, else when it is = or > than 32 it subtracts 32 from the value of the character from the ASCII table, resulting in the same character saved in the PROGMEM. Once it finds the character, it then makes a copy into a buffer and then writes it to the MAX7219 using writeSprite().
Now that I understand how to display text and text with a shift, I would like to test with images.
I kept all the connections the same and began looking for a tutorial on how to manipulate the LEDs to display a moving graphic. I went with a face smiling then frowning.
Using the LedControl library functions, setRow(), setColumn(), or setLed(), you can manipulate one LED at a time. In this code we are setting each row for each graphic, happy or sad face. The setRow() function allows you to plug in 3 points, the addr, row, and value. setRow(addr, row, value). The addr is the address of your matrix, and since I am only using one matrix the value will be zero in all cases. The row will begin from 0 and continue to 7 to cover all the 8 rows. Finally, the value is the state of the led true or false (1 or 0).
To make it simpler I drew out the faces first and found the corresponding rows and their values for each face
Next I set the bytes for the happy and sad face, and added a neutral from the existing example. Each byte contains 8 values that will then represent each row. Once they are set, we can call a loop function, drawFaces(), that simply calls the ledControl and sets the row from 0-7 with the bit-1 corresponding to the first row and so on. After each face there is a delay of 1000 and then jumps to the next face and keeps going.