HELP needed in LED Dot Matrix display

The below code write a mono character "A" to the 8x8 dot matrix.

Please help me out in how to pick the Data value from serial Read and replace Data = "A".

#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Max72xxPanel.h>



int pinCS = 10; // Attach CS to this pin, DIN to MOSI and CLK to SCK (cf http://arduino.cc/en/Reference/SPI )
int numberOfHorizontalDisplays = 2;
int numberOfVerticalDisplays = 2;

Max72xxPanel matrix = Max72xxPanel(pinCS, numberOfHorizontalDisplays, numberOfVerticalDisplays);

String Data ="A";


void setup() {

  Serial.begin(9600);

  matrix.setIntensity(7); // Use a value between 0 and 15 for brightness
  
}


void loop() {


  matrix.fillScreen(LOW);
    
  matrix.drawChar(0, 0, Data[0], HIGH, LOW, 1);
  matrix.write();

}

Where do you read data from the serial port? Where do you test that there is even data to read?

   Data = "something else";

doesn't seem all that difficult to do.

PaulS:
Where do you read data from the serial port? Where do you test that there is even data to read?

   Data = "something else";

doesn't seem all that difficult to do.

I tried doing this, but error in compile..

void loop() {

if(Serial.available()){

  String Data  = Serial.read();
  
  matrix.fillScreen(LOW);
    
  matrix.drawChar(0, 0, Data[0], HIGH, LOW, 1);
  matrix.write();

  }
}

I tried doing this, but error in compile..

So, fix the error(s). You didn't share them, so obviously you don't need help.

PaulS:
So, fix the error(s). You didn't share them, so obviously you don't need help.

Ahh sorry.. Really sorry..

ERROR

exit status 1
conversion from 'int' to 'String' is ambiguous

Since that library used the String class you will need to call the setCharAt() method to insert the char that Serial.read() returns. To show the String on the serial monitor you need to convert the String to a C-style, null-terminated string with c_str().

String Data ="A";

void setup()
{
  Serial.begin(9600);

  // print original String
  Serial.print(Data.c_str());

}

void loop() {

  char c;

  if(Serial.available()) {

    // read character 
    c  = Serial.read();

    // replace character at first position
    Data.setCharAt(0, c);

    // print new String
    Serial.print(Data.c_str());

  }

}

I don't understand your code..

To be more precise, what I an trying to do is.
I want to type a character in the serial command, and want it to display on the dot matrix.

I want to type a character in the serial command, and want it to display on the dot matrix.

So do that. Get rid of the String class. The drawChar() function takes a char, NOT a String.

void loop()
{
   if(Serial.available() > 0)
   {
       char c = Serial.read();

       matrix.fillScreen(LOW);
       matrix.drawChar(0, 0, c, HIGH, LOW, 1);
       matrix.write();
   }
}

PaulS:
So do that. Get rid of the String class. The drawChar() function takes a char, NOT a String.

void loop()

{
  if(Serial.available() > 0)
  {
      char c = Serial.read();

matrix.fillScreen(LOW);
      matrix.drawChar(0, 0, c, HIGH, LOW, 1);
      matrix.write();
  }
}

I tried the same initially, but I face a problem in the display.

Always an unknown character is printed on the display.
When a character is send through the serial command, its displayed for a nano second and vanishes, over the character shown in the picture below.

  • Initialize the String named Data with a value, in your case A
  • Determine if there is a character on the serial port (open Serial Monitor on Arduino IDE, type a character, hit the Send button)
  • If there was a character available, read it and replace whatever character is in the String named Data with the character just read
  • Write the character in the String Data to the 8x8 dot matrix
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Max72xxPanel.h>



int pinCS = 10; // Attach CS to this pin, DIN to MOSI and CLK to SCK (cf http://arduino.cc/en/Reference/SPI )
int numberOfHorizontalDisplays = 2;
int numberOfVerticalDisplays = 2;

Max72xxPanel matrix = Max72xxPanel(pinCS, numberOfHorizontalDisplays, numberOfVerticalDisplays);

String Data ="A";    // Initialize String Data


void setup() {

  Serial.begin(9600);

  matrix.setIntensity(7); // Use a value between 0 and 15 for brightness

}


void loop() {

  char c;

  // is there a character available on the serial port?
  if(Serial.available()) {

    // read character
    c  = Serial.read();

    // replace character at first position of String Data
    Data.setCharAt(0, c);


  }

  matrix.fillScreen(LOW);

  // show character at first position of Stirng Data on the 8x8 matrix
  matrix.drawChar(0, 0, Data[0], HIGH, LOW, 1);
  matrix.write();

}

Always an unknown character is printed on the display.

What is sending the data to the Arduino? What baud rate is it using? What, exactly, is it sending? Carriage return? Line feed? Both? Neither?

Write the character in the String Data to the 8x8 dot matrix

Nonsense. There is NO excuse for using String in this application AT ALL.

PaulS:
What is sending the data to the Arduino? What baud rate is it using? What, exactly, is it sending? Carriage return? Line feed? Both? Neither?

Wow.. Great..
Tested all baud rates but the problem was not solved.

But select " NO LINE ENDING " solves the problem.

Carriage return and Newline creates the problem.
Can you please explain the reason..??

Can you please explain the reason..??

Sure. What does a carriage return look like? A line feed? These characters have no visual representation, so they appear to cause the display problems.

PaulS:
Sure. What does a carriage return look like? A line feed? These characters have no visual representation, so they appear to cause the display problems.

Thank you..:slight_smile:

Now the challenge is how to print a word. eg. "FOX"

I need the length of the word, then have to print each character at +6 position to the previous character.

This thread may have seemed terse, but look... the OP asked and listened/learned something!
I'm sure he'll be back, but a good example of how the forum SHOULD work!
Thanks PaulS

Edit: that was fast! here he is!

Joy:
Now the challenge is how to print a word. eg. "FOX"

I need the length of the word, then have to print each character at +6 position to the previous character.

Please tell me how will I do this..?

Well, technically you don't need the length of the string (small s), but if you want it, try strlen()

In this case, you simply need to keep track of your pixel position, and render each (printable) character as it arrives.

lastchancename:
Well, technically you don't need the length of the string (small s), but if you want it, try strlen()

In this case, you simply need to keep track of your pixel position, and render each (printable) character as it arrives.

The input from the serial port is a "char", how do I read the length of this..??