Displaying numbers on 7 segment LED.

I got seven 7-segment LED displays, max7219 and I want to send a number via usb to the display.

I wrote a small program in VB.NET to send a number to the Arduino. I'm having a problem though. I made it to work with a single digit numbers, but I can't figure out how to sent bigger numbers. There are two problems. 1. LedControl library can't display number bigger than 9. I have to split it and send it to a specific LED 2. When I send a number to Arduino, VB.NET sends it in ASCII code and on top of that I believe it breaks up the numbers. So when I send 123, it will send it as "49" then "50" then "51"

So the question is, how can I assign a number that I receive on Arduino to a specific LED display?

You could use something like this:

int getInt(){
  // waits for a string of up to 5 ascii digits terminated by any non digit character
  byte counter = 0;
  char buffer[7]; // the biggest arduino int is represented by a 5 byte string, sign if neg and null
  while( counter < 7){
    buffer[counter] = Serial.read();  // block till a char is available
    if( (buffer[counter] >= '0' && buffer[counter] <= '9') || buffer[counter] == '-' ){  // check for digit or minus sign
      counter++; // got a digit so increment counter      
    }
    else {
      buffer[counter] = 0;   // not a digit so terminate string and return value
      return (atoi(buffer));
    } 
  }
  return 0;  // return 0 if no valid digit is received
}

The function getInt will block until it gets an ascii string of up to five digits terminated by any non digit character.
It would be used as follows:

int val;

if(Serial.available() >0 ){
val = getInt();
Serial.print("getInt returned ");
Serial.println(val,DEC);
}

Note that this function will return 0 if its called and the first character read is not a digit (or minus sign). If you want to distinguish between a non digit character and 0, you can use this function instead.

boolean getInt( int* value){
  // waits for a string of up to 5 ascii digits terminated by any non digit character
  byte counter = 0;
  char buffer[7]; // the biggest arduino int is represented by a 5 byte string, sign if neg and null
  while( counter < 7){
    buffer[counter] = Serial.read();  // block till a char is available
    if((buffer[counter] >= '0' && buffer[counter] <= '9') || buffer[counter] == '-' ){  // check for digit or minus sign
      counter++; // got a digit so increment counter      
    }
    else {
      buffer[counter] = 0;   // not a digit so terminate string and return value
      *value = atoi(buffer);
      return counter > 0;  // return true if more than 1 digit received
    } 
  }
  return false;  // no valid digit received
}

It is slightly more complicated to use because you have to pass a pointer to the value you want returned.

int val;
if(Serial.available() >0 ){
if( getInt(&val) == true) {
Serial.print("getInt returned ");
Serial.println(val,DEC);
}
else
Serial.println(“getInt returned false”);
}

Hi,

I got seven 7-segment LED displays, max7219 and I want to send a number via usb to the display.

  1. LedControl library can’t display number bigger than 9. I have to split it and send it to a specific LED

  2. When I send a number to Arduino, VB.NET sends it in ASCII code and on top of that I believe it breaks up the numbers. So when I send 123, it will send it as “49” then “50” then “51”

The LedControl-library can handle ascii-chars directly you don’t have to convert them back
see http://www.arduino.cc/playground/Main/LedControl#CharSeg7Control

My idea would be to use some sort of easy protocol for transmitting your numbers. I don’t know how many digits you attached to the MAX7221? lets assume the maximum 8.
On the arduino side you create a buffer of 8 chars and fill it with 8 ASCII characters comingg from the VB.NET app.
The VB-app must fill up the actual value (in ascii) with either space-chars or leading zeros:

int value 123 becomes "     123" or "00000123"

whatever you like better.
When you have received all 8 chars you display them in a loop

//the value coming from the VB-app 
LedControl lc=new LedControl(......);
//the value coming from the VB-app 
char valueFromVB[8]; 

for(int i=0;i<8;i++) {
    lc.setChar(ADDRESS_OF_YOUR_DISPLAY,i,valueFromVB[i],false)
}

Does that help?
Eberhard