POV Display using Arduino programming problem

Hello.

I have been working on building a POV Display using an Arduino Uno. I use Windows 7 and Arduino IDE version 1.0.1. The problem I have been having is that the Arduino outputs byte stream totally different from what I am expecting it to. For example in the code below, I want it to display the byte stream stored in the variable 'comma'.

int pins[] = {2,3,4,5,6,7,8,9};	// an array of pin numbers
int rows= 8;		        // Total LED's in a row

byte comma[]={00000000,00000000,00000000,00000101,00000110,00000000,00000000,00000000};


// customizable parameters
int timer1 = 5000;			                // time between columns
int timer2 = 15;		                // time between frames
int timer3 = 0;			                // time between drawings
int frame_len = 8;		                // frame length

void setup()
{
  int i;
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  for (i = 0; i < rows; i++)
    pinMode(pins[i], OUTPUT);	// set each pin as an output
  Serial.begin(19200);
}

void loop()
{
  digitalWrite(10, OUTPUT);
  digitalWrite(11, OUTPUT);
  show(comma);
}

void show( byte* image )
{
  int a,b,c;
  
  // go through all data for all columns in each frame.
    for (b = 0; b < frame_len; b++)
    {
      for (c = 0; c < rows; c++)
      {
        Serial.println(image[c], BIN);
      }
      delay(timer1);
    }
}

However the data that was output was weird so I sent it to the serial monitor to check what it was actually outputting. This is what I keep getting,

0
0
0
1000001
1001000
0
0
0

instead of,

0
0
0
00000101
00000110
0
0
0

I simply do not understand what the problem is. Is there something wrong with the code? Am I using the data array incorrectly? What is it?

You are entering values in octal, and printing in binary, and expecting the values to match. That is a quite unrealistic expectation.

PaulS:
You are entering values in octal, and printing in binary, and expecting the values to match. That is a quite unrealistic expectation.

Sorry @PaulS. My Bad. I have not yet learnt to use the serial monitor. However that does not solve my problem. Let me give you an example. I have connected 8 LED's to port pin's 2-9 which are connected to ground through a 220 ohm resistor. I want to output a frame of 8 bytes stored in an array 'A'. The frame is:

{00000111,00001100,00111000,11001000,11001000,00111000,00001100,00000111}

What I get on the LED's however is a 5 byte repeating frame:

{10000001,10011001,00011000,11000011,00011000}

The code is the same as in the original post.

11001000

Is not a byte sized value. I suspect that you want either 0b11001000 or B11001000 in your declarations.

PaulS:

11001000

Is not a byte sized value. I suspect that you want either 0b11001000 or B11001000 in your declarations.

I changed the declarations to

byte A[]={B00000111,B00001100,B00111000,B11001000,B11001000,B00111000,B00001100,B00000111};

However when I display A, using the show function, I still keep getting a weird output sequence. This is different from the one I got before changing the declarations. It still repeats after 5 bytes instead of displaying all 8 bytes in the array A.

10000001
11000011
01111110
00100100
00011000

None of the values you are printing seem to match the array declaration. I think it is time to suck it up and learn hex. Use 0xNN in the declaration, and HEX in the print statement. Printing the index and the value together would be useful, too.

PaulS:
None of the values you are printing seem to match the array declaration. I think it is time to suck it up and learn hex. Use 0xNN in the declaration, and HEX in the print statement. Printing the index and the value together would be useful, too.

I think I confused you here. After I changed the encoding in the serial print statement to octal, I got the output as:

0
0
0
11     // Is this equivalent to 00000011? If yes then it is right.
11
0
0
0

However even if it prints correctly on the serial monitor, my problem is that it is not doing so on the port pins 2-9. I used the serial monitor just to check what byte stream is actually being printed by the arduino. If you forget the serial comm. commands that I have used, my real problem is that the arduino is not outputting the correct stream on the port pins 2-9. This incorrect stream is what I explained in the previous reply.

karanjthakkar:

PaulS:

11001000

Is not a byte sized value. I suspect that you want either 0b11001000 or B11001000 in your declarations.

I changed the declarations to

byte A[]={B00000111,B00001100,B00111000,B11001000,B11001000,B00111000,B00001100,B00000111};

However when I display A, using the show function, I still keep getting a weird output sequence. This is different from the one I got before changing the declarations. It still repeats after 5 bytes instead of displaying all 8 bytes in the array A.

10000001

11000011
01111110
00100100
00011000

I hope you understand what I am trying to say here.

11     // Is this equivalent to 00000011? If yes then it is right.

Yes, leading 0's are not printed (or needed).

However even if it prints correctly on the serial monitor, my problem is that it is not doing so on the port pins 2-9. I used the serial monitor just to check what byte stream is actually being printed by the arduino.

Nothing in the code you posted causes any output to those pins.

Would you like to post all of your code, for review?

PaulS:
Would you like to post all of your code, for review?

int pins[] = {2,3,4,5,6,7,8,9};	// an array of pin numbers
int rows= 8;		        // Total LED's in a row

//data corresponding to the each alphabet and a few characters to be displayed
byte N[]={B00000000,B11111111,B11000000,B01110000,B00111100,B00001110,B00000011,B11111111};
byte E[]={B00000000,B11111111,B11011011,B11011011,B11011011,B11011011,B11000011,B11000011};
byte H[]={B00000000,B11111111,B11111111,B00011000,B00011000,B00011000,B11111111,B11111111}; 
byte A[]={B00000111,B00001100,B00111000,B11001000,B11001000,B00111000,B00001100,B00000111};
byte K[]={B00000000,B11111111,B00011000,B00111100,B01100110,B11000011,B10000001,B00000000};
byte R[]={B00000000,B11111111,B10011000,B10011100,B10010110,B10010011,B11110001,B11110001};
byte L[]={B00000000,B11111111,B11111111,B00000011,B00000011,B00000011,B00000011,B00000011};
byte O[]={B00000000,B11111111,B11111111,B11000011,B11000011,B11000011,B11111111,B11111111};
byte V[]={B00000000,B11100000,B00111000,B00001110,B00000011,B00001110,B00111000,B11100000};
byte I[]={B00000000,B11000011,B11000011,B11000011,B11111111,B11000011,B11000011,B11000011};
byte fullstop[]={B00000000,B00000000,B00000000,B00000011,B00000011,B00000000,B00000000,B00000000};
byte comma[]={B00000000,B00000000,B00000000,B00000101,B00000110,B00000000,B00000000,B00000000};
byte heart[]={B01110000,B11111000,B11111100,B00111110,B00111110,B11111100,B11111000,B01110000};


// customizable parameters
int timer1 = 2000;			        
// time between columns
int timer2 = 15;		                // time between frames
int timer3 = 0;			                // time between drawings
int frame_len = 8;		                // frame length

void setup()
{
  int i;
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  for (i = 0; i < rows; i++)
    pinMode(pins[i], OUTPUT);	// set each pin as an output
}

void loop()
{
  digitalWrite(10, OUTPUT);
  digitalWrite(11, OUTPUT);
  show(A);
}

void show( byte* image )
{
  int a,b,c;
  
  // go through all data for all columns in each frame.
    for (b = 0; b < frame_len; b++)
    {
      for (c = 0; c < rows; c++)
      {
        boolean pixel = bitRead(image[c],b);
        if (pixel == 0) {
          digitalWrite(pins[c], LOW);
        }
        else {
          digitalWrite(pins[c], HIGH);
        }
      }
      delay(timer1);
    }
    for (c = 0; c < rows; c++)
    {
      digitalWrite(pins[c], LOW);
    }
}
        boolean pixel = bitRead(image[c],b);
        if (pixel == 0) {
          digitalWrite(pins[c], LOW);
        }
        else {
          digitalWrite(pins[c], HIGH);
        }

bitRead() does not return a boolean. It returns either 0 (LOW) or 1 (HIGH). So, this code is unnecessarily complicated.

All you need is:

   digitalWrite(pins[c], bitRead(image[c], b));

Using c as the pins[] index doesn't look right. It seems like the index into pins[] should also be b.

PaulS:
Using c as the pins[] index doesn't look right. It seems like the index into pins[] should also be b.

This was the key @PaulS. It was such a minor thing that it totally missed my attention. Worked like a charm after I did the changes. Thank you so much. :grin: XD