Serial conundrum

Hi all,

I have a little 4 x 7 segment display that runs off SPI — the one from Sparkfun. Works like a charm using this code that I wrote:

void outputDisplay(char* stringIn) {
  digitalWrite(slaveSelectPin,LOW);
  SPI.transfer(byte(0x76)); //reset display
  for (int i = 0; i<4; i++){
    SPI.transfer(stringIn[i]); //output char
  }
  digitalWrite(slaveSelectPin,HIGH);
}

At the moment I am trying to do something simple and get it to display anything that gets sent to the serial.

 if (Serial.available() > 0) {
      // read the incoming byte:
      incomingByte = Serial.read();
      outputDisplay((char*)incomingByte);
 }

The problem is that it’s not working as expect it— it seems to just send random stuff to the display.

I seem to want to convert from ASCII to a string?

Any help on this?

James

Your displaying always 4 characters at once:

  for (int i = 0; i<4; i++){
    SPI.transfer(stringIn[i]); //output char
  }

With this version you could send a string:

void outputDisplay(char* stringIn) {
  digitalWrite(slaveSelectPin,LOW);
  SPI.transfer(byte(0x76)); //reset display
  while (*stringIn) {
    SPI.transfer(*stringIn++);
  }
  digitalWrite(slaveSelectPin,HIGH);
}

So a byte:

void outputDisplay(char c) {
  digitalWrite(slaveSelectPin,LOW);
  SPI.transfer(c); //output char
  digitalWrite(slaveSelectPin,HIGH);
}

Then your serial might look like this:

outputDisplay(0x76);
if (Serial.available() > 0) {
      // read the incoming byte:
      char incomingByte = Serial.read();
      outputDisplay(incomingByte);
 }

If you wanna wrap around you may have to do a little more but this should give you the idea.

Brilliant — thank you very much!