Little serial problem (Easy problem I'm sure)

Hello very simple problem I have a piece of code given by Nick Gammon I have it working with changing the 'showString(HELLO WORLD, 650);'
This sends off the data to flash letters on a matrix driven by a 7219 max chip. I am very new and I want to change the hello world to a serial input from the computer I then might try do this wirelessly or some thing but for now I will keep it simple. So here is the original code that works by just changing the string in the void loop at the bottom:

#include <Boards.h>
#include <Firmata.h>


#include <SPI.h>
#include <avr/pgmspace.h>
#include "font.h"

char* myStrings[]={"This is string 1", "This is string 2", "This is string 3",
"This is string 4", "This is string 5","This is string 6"};

 // define max7219 registers
const byte MAX7219_REG_NOOP        = 0x0;
const byte MAX7219_REG_DIGIT0      = 0x1;
const byte MAX7219_REG_DIGIT1      = 0x2;
const byte MAX7219_REG_DIGIT2      = 0x3;
const byte MAX7219_REG_DIGIT3      = 0x4;
const byte MAX7219_REG_DIGIT4      = 0x5;
const byte MAX7219_REG_DIGIT5      = 0x6;
const byte MAX7219_REG_DIGIT6      = 0x7;
const byte MAX7219_REG_DIGIT7      = 0x8;
const byte MAX7219_REG_DECODEMODE  = 0x9;
const byte MAX7219_REG_INTENSITY   = 0xA;
const byte MAX7219_REG_SCANLIMIT   = 0xB;
const byte MAX7219_REG_SHUTDOWN    = 0xC;
const byte MAX7219_REG_DISPLAYTEST = 0xF;
 

 
void sendByte (const byte reg, const byte data)
  {    
  digitalWrite (SS, LOW);
  SPI.transfer (reg);
  SPI.transfer (data);
  digitalWrite (SS, HIGH); 
  }  // end of sendByte
 
 
void letter (const byte c)
 {
  for (byte col = 0; col < 8; col++)
    sendByte (col + 1, pgm_read_byte (&cp437_font [c] [col]));
 }  // end of letter
 
void showString (const char * s, const unsigned long time)
{
  char c;
  while (c = *s++)
    {
    letter (c); 
    delay (time);
    letter (' ');  // brief gap between letters
    delay (400);      
    }
}  // end of showString

void setup () {
  
 Serial.begin(9600);
 
  SPI.begin ();
    
  sendByte (MAX7219_REG_SCANLIMIT, 7);   // show all 8 digits
  sendByte (MAX7219_REG_DECODEMODE, 0);  // using an led matrix (not digits)
  sendByte (MAX7219_REG_DISPLAYTEST, 0); // no display test
  
  // clear display
  for (byte col = 0; col < 8; col++)
    sendByte (col + 1, 0);

  sendByte (MAX7219_REG_INTENSITY, 7);  // character intensity: range: 0 to 15
  sendByte (MAX7219_REG_SHUTDOWN, 1);   // not in shutdown mode (ie. start it up)
                                     
}   // end of setup
 
void loop () 
 {
 showString ("Hello World", 650);
 }  // end of loop

Like I saiud this works like a treat and I really like it. So here is what I would like to change and for some reason just cannot do it :/:

(I shall only contain the void loop here)

void loop () 
 {
   Serial.begin(9600);                   //Setup up the baud rate etc
   while (Serial.available()== 0);   //Infin loop until serial data comes in
 showString (Serial.read() , 650);  //Output the input to the matrix
 }  // end of loop

I get this error that [invalid conversion from 'int' to 'const char*']
Can any one spot the problem? It would mean a lot to me if any one helps :smiley: Thank you!

:grin:

You need to assemble the string in a char[] variable before sending it to showString(). Strings are an array of char with a null (ie 0x00) char at the end to mark the end of the string.

In addition to what MarkT says, the Serial.read() function returns one character per call. You need to call it over and over again, until the end of the message is received. How will you know that you have received a complete message? The fact that there is no more serial data to read does NOT indicate that the whole packet has been received.

Yes, as MarkT says, you'll need to construct a string (array of type char) to use with showString() - Serial.read() only gives you one character at a time.

If you are new to C programming, strings are a bit tricky compared with their implementation in other languages. There's a reasonable explanation of it here: http://www.cs.bu.edu/teaching/cpp/string/array-vs-ptr/

You'll need a character buffer to write the characters into one at a time as you receive them and then have some means of triggering actually sending the string to the display. You'll have to think about how you will define a string for display being received over the serial link. Will it have a terminator (e.g. NUL or new-line)? Will it be of a fixed length?