I am creating a new post as I messed up my first one with little detail and zero experience posting here!
I have followed a tutorial online to make a 48x8 LED matrix. This is my first real project using Arduino. I have basic but limited electronics experience. The matrix once plugged in turns on and starts to scroll right to left. But instead of displaying characters, it displays blocks of bright / dim LED's. I have checked my PIN connections from my Nano to my 74HC595 IC's. I have checked all my power points / gnd. All power point are 5+v dc. I am using a 12v dc - 2a power supply with voltage regulators. The code I am using and the circuit diagram has been copied from the tutorial page. If anyone has any ideas would be very grateful.
#define max_char 100
int charIndex;
int scrollspeed = 20; //Set the scroll speed ( lower=faster)
int i;
int x;
int y;
char r_char;
char msg[] = "HELLO WORLD"; //Change the text here.
//Columns
int clockPin1 = 3; //Arduino pin connected to Clock Pin 11 of 74HC595
int latchPin1 = 2; //Arduino pin connected to Latch Pin 12 of 74HC595
int dataPin1 = 4; //Arduino pin connected to Data Pin 14 of 74HC595
//Rows
int clockPin2 = 7; //Arduino pin connected to Clock Pin 11 of 74HC595
int latchPin2 = 6; //Arduino pin connected to Latch Pin 12 of 74HC595
int dataPin2 = 5; //Arduino pin connected to Data Pin 14 of 74HC595
//BITMAP
//Bits in this array represents one LED of the matrix
// 8 is # of rows, 6 is # of LED matrices
byte bitmap[8][7];
int numZones = sizeof(bitmap) / 8; // One Zone refers to one 8 x 8 Matrix ( Group of 8 columns)
int maxZoneIndex = numZones - 1;
int numCols = numZones * 8;
char alphabets[][8] = {
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // SPACE
{0x00, 0x00, 0x00, 0x5F, 0x00, 0x00}, // !
{0x00, 0x00, 0x07, 0x00, 0x07, 0x00}, // "
{0x00, 0x14, 0x7F, 0x14, 0x7F, 0x14}, // #
{0x00, 0x24, 0x2A, 0x7F, 0x2A, 0x12}, // $
{0x00, 0x23, 0x13, 0x08, 0x64, 0x62}, // %
{0x00, 0x36, 0x49, 0x55, 0x22, 0x50}, // &
{0x00, 0x00, 0x05, 0x03, 0x00, 0x00}, // '
{0x00, 0x00, 0x1C, 0x22, 0x41, 0x00}, // (
{0x00, 0x00, 0x41, 0x22, 0x1C, 0x00}, // )
{0x00, 0x14, 0x08, 0x3E, 0x08, 0x14}, // *
{0x00, 0x08, 0x08, 0x3E, 0x08, 0x08}, // +
{0x00, 0x00, 0x50, 0x30, 0x00, 0x00}, // ,
{0x00, 0x08, 0x08, 0x08, 0x08, 0x08}, // -
{0x00, 0x00, 0x60, 0x60, 0x00, 0x00}, // .
{0x00, 0x20, 0x10, 0x08, 0x04, 0x02}, // /
{0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E}, // 0
{0x00, 0x00, 0x42, 0x7F, 0x40, 0x00}, // 1
{0x00, 0x42, 0x61, 0x51, 0x49, 0x46}, // 2
{0x00, 0x21, 0x41, 0x45, 0x4B, 0x31}, // 3
{0x00, 0x18, 0x14, 0x12, 0x7F, 0x10}, // 4
{0x00, 0x27, 0x45, 0x45, 0x45, 0x39}, // 5
{0x00, 0x3C, 0x4A, 0x49, 0x49, 0x30}, // 6
{0x00, 0x01, 0x71, 0x09, 0x05, 0x03}, // 7
{0x00, 0x36, 0x49, 0x49, 0x49, 0x36}, // 8
{0x00, 0x06, 0x49, 0x49, 0x29, 0x1E}, // 9
{0x00, 0x36, 0x36, 0x00, 0x00, 0x00}, // :
{0x00, 0x56, 0x36, 0x00, 0x00, 0x00}, // ;
{0x00, 0x08, 0x14, 0x22, 0x41, 0x00}, // <
{0x00, 0x14, 0x14, 0x14, 0x14, 0x14}, // =
{0x00, 0x00, 0x41, 0x22, 0x14, 0x08}, // >
{0x00, 0x02, 0x01, 0x51, 0x09, 0x06}, // ?
{0x00, 0x30, 0x49, 0x79, 0x41, 0x3E}, // @
{0x00, 0x7E, 0x11, 0x11, 0x11, 0x7E}, // A
{0x00, 0x7F, 0x49, 0x49, 0x49, 0x36}, // B
{0x00, 0x3E, 0x41, 0x41, 0x41, 0x22}, // C
{0x00, 0x7F, 0x41, 0x41, 0x22, 0x1C}, // D
{0x00, 0x7F, 0x49, 0x49, 0x49, 0x41}, // E
{0x00, 0x7F, 0x09, 0x09, 0x09, 0x01}, // F
{0x00, 0x3E, 0x41, 0x49, 0x49, 0x7A}, // G
{0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F}, // H
{0x00, 0x00, 0x41, 0x7F, 0x41, 0x00}, // I
{0x00, 0x20, 0x40, 0x41, 0x3F, 0x01}, // J
{0x00, 0x7F, 0x08, 0x14, 0x22, 0x41}, // K
{0x00, 0x7F, 0x40, 0x40, 0x40, 0x40}, // L
{0x00, 0x7F, 0x02, 0x0C, 0x02, 0x7F}, // M
{0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F}, // N
{0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E}, // O
{0x00, 0x7F, 0x09, 0x09, 0x09, 0x06}, // P
{0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E}, // Q
{0x00, 0x7F, 0x09, 0x19, 0x29, 0x46}, // R
{0x00, 0x46, 0x49, 0x49, 0x49, 0x31}, // S
{0x00, 0x01, 0x01, 0x7F, 0x01, 0x01}, // T
{0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F}, // U
{0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F}, // V
{0x00, 0x3F, 0x40, 0x30, 0x40, 0x3F}, // W
{0x00, 0x63, 0x14, 0x08, 0x14, 0x63}, // X
{0x00, 0x07, 0x08, 0x70, 0x08, 0x07}, // Y
{0x00, 0x61, 0x51, 0x49, 0x45, 0x43}, // Z
{0x00, 0x00, 0x7F, 0x41, 0x41, 0x00}, // [
{0x00, 0x02, 0x04, 0x08, 0x10, 0x20}, // backslash
{0x00, 0x00, 0x41, 0x41, 0x7F, 0x00}, // ]
{0x00, 0x04, 0x02, 0x01, 0x02, 0x04}, // ^
{0x00, 0x40, 0x40, 0x40, 0x40, 0x40}, // _
{0x00, 0x00, 0x01, 0x02, 0x04, 0x00}, // `
{0x00, 0x20, 0x54, 0x54, 0x54, 0x78}, // a
{0x00, 0x7F, 0x50, 0x48, 0x48, 0x30}, // b
{0x00, 0x38, 0x44, 0x44, 0x44, 0x28}, // c
{0x00, 0x38, 0x44, 0x44, 0x48, 0x7F}, // d
{0x00, 0x38, 0x54, 0x54, 0x54, 0x18}, // e
{0x00, 0x08, 0x7E, 0x09, 0x01, 0x02}, // f
{0x00, 0x0C, 0x52, 0x52, 0x52, 0x3E}, // g
{0x00, 0x7F, 0x08, 0x04, 0x04, 0x78}, // h
{0x00, 0x00, 0x44, 0x7D, 0x40, 0x00}, // i
{0x00, 0x20, 0x40, 0x44, 0x3D, 0x00}, // j
{0x00, 0x7F, 0x10, 0x28, 0x44, 0x00}, // k
{0x00, 0x00, 0x41, 0x7F, 0x40, 0x00}, // l
{0x00, 0x78, 0x04, 0x18, 0x04, 0x78}, // m
{0x00, 0x7C, 0x08, 0x04, 0x04, 0x78}, // n
{0x00, 0x38, 0x44, 0x44, 0x44, 0x38}, // o
{0x00, 0x7C, 0x14, 0x14, 0x14, 0x08}, // p
{0x00, 0x08, 0x14, 0x14, 0x18, 0xFC}, // q
{0x00, 0x7C, 0x08, 0x04, 0x04, 0x08}, // r
{0x00, 0x48, 0x54, 0x54, 0x54, 0x20}, // s
{0x00, 0x04, 0x3F, 0x44, 0x40, 0x20}, // t
{0x00, 0x3C, 0x40, 0x40, 0x20, 0x7C}, // u
{0x00, 0x1C, 0x20, 0x40, 0x20, 0x1C}, // v
{0x00, 0x3C, 0x40, 0x30, 0x40, 0x3C}, // w
{0x00, 0x44, 0x28, 0x10, 0x28, 0x44}, // x
{0x00, 0x0C, 0x50, 0x50, 0x50, 0x3C}, // y
{0x00, 0x44, 0x64, 0x54, 0x4C, 0x44}, // z
{0x00, 0x00, 0x08, 0x36, 0x41, 0x00}, // {
};
void clearBitmap()
{
//Clear bitmap
for (int row = 0; row < 8; row++) {
for (int zone = 0; zone <= maxZoneIndex; zone++) {
bitmap[row][zone] = 0;
}
}
}
void setup() {
pinMode(latchPin1, OUTPUT);
pinMode(clockPin1, OUTPUT);
pinMode(dataPin1, OUTPUT);
pinMode(latchPin2, OUTPUT);
pinMode(clockPin2, OUTPUT);
pinMode(dataPin2, OUTPUT);
Serial.begin(9600);
clearBitmap();
}
//FUNCTIONS
// Displays bitmap array in the matrix
void RefreshDisplay() {
for (int row = 0; row < 8; row++) {
int rowbit = 1 << row;
digitalWrite(latchPin2, LOW);//Hold latchPin LOW for transmitting data
shiftOut(dataPin2, clockPin2, LSBFIRST, rowbit); //Transmit data
//Start sending column bytes
digitalWrite(latchPin1, LOW);//Hold latchPin LOW for transmitting data
//Shift out to each matrix
for (int zone = maxZoneIndex; zone >= 0; zone--)
{
shiftOut(dataPin1, clockPin1, MSBFIRST, bitmap[row][zone]);
}
//flip both latches at once to eliminate flicker
digitalWrite(latchPin1, HIGH);//Return the latch pin 1 high to signal chip
digitalWrite(latchPin2, HIGH);//Return the latch pin 2 high to signal chip
//Wait
delayMicroseconds(300);
}
}
// Converts row and colum to bitmap bit and turn it off/on
void Plot(int col, int row, bool isOn) {
int zone = col / 8;
int colBitIndex = x % 8;
byte colBit = 1 << colBitIndex;
if (isOn)
bitmap[row][zone] = bitmap[y][zone] | colBit;
else
bitmap[row][zone] = bitmap[y][zone] & (~colBit);
}
// Plot each character of the message one column at a time, updated the display, shift bitmap left.
void XProcess() {
for (charIndex = 0; charIndex < (sizeof(msg) - 1); charIndex++)
{
int alphabetIndex = msg[charIndex] - ' '; // I changed '@' to ' ' to display the different alphabets
if (alphabetIndex < 0) alphabetIndex = 0;
//Draw one character of the message
// Each character is 5 columns wide, loop two more times to create 2 pixel space betwen characters
for (int col = 0; col < 8; col++)
{
for (int row = 0; row < 8; row++)
{
// Set the pixel to what the alphabet say for columns 0 thru 4, but always leave columns 5 and 6 blank.
bool isOn = 0;
if (col < 8) isOn = bitRead( alphabets[alphabetIndex][col], 7 - row ) == 1;
Plot( numCols - 1, row, isOn); //Draw on the rightmost column, the shift loop below will scroll it leftward.
}
for (int refreshCount = 0; refreshCount < scrollspeed; refreshCount++)
RefreshDisplay();
//Shift the bitmap one column to left
for (int row = 0; row < 8; row++)
{
for (int zone = 0; zone < numZones; zone++)
{
//This right shift would show as a left scroll on display because leftmost column is represented by least significant bit of the byte.
bitmap[row][zone] = bitmap[row][zone] >> 1;
// Shift over lowest bit from the next zone as highest bit of this zone.
if (zone < maxZoneIndex) bitWrite(bitmap[row][zone], 7, bitRead(bitmap[row][zone + 1], 0));
}
}
}
}
}
void serialInput() {
//check if serial is avaible an before reading a new message delete's the old message
if (Serial.available()) {
for (i = 0; i < 105; i++) {
msg[i] = '\0';
}
//resests the index
charIndex = 0;
}
//while is reading the message
while (Serial.available()) {
//the message can have up to 100 characters
if (charIndex < (max_char - 1))
{
r_char = Serial.read(); // Reads a character
msg[charIndex] = r_char; // Stores the character in message array
charIndex++; // Increment position
msg[charIndex] = '\0'; // Delete the last position
}
}
}
void loop() {
XProcess();
serialInput();
}
Oops
Déja-vu.
Really !
What exactly is this telling me? I’m not familiar with coding yet. I am running through some online courses. Maybe I shouldn’t be attempting a project like this but I’ve put too much time and effort into this now. I apologise for my ignorance. I am trying to understand and learn.
char msg[] = "HELLO WORLD";
Your definition of msg is only as big as the string you defined + 1 character for the '\0' because you have not given the array a size.
for (i = 0; i < 105; i++) {
msg[i] = '\0';
How many memory locations are you clobbering with '\0'?
Maybe not the problem but I don't see decoupling capacitors on the 74HC595.
I also don't see current limiting resistors for the leds but they might be on the display itself.
Your other Topic has been locked as it is the identical or too similar your other post.
Please use the original post and do not duplicate.
Other post/duplicate DELETED
Please do NOT cross post / duplicate as it wastes peoples time and efforts to have more than one post for a single topic.
Continued cross posting could result in a time out from the forum.
Could you also take a few moments to Learn How To Use The Forum.
Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.
You must declare msg
with a sufficient size : char msg[ max_char + 1 ] = "HELLO WORLD";
And to clear the string, you can simply do msg[0] = '\0';
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.