Serial data to a Sure ht1632

Hi I’m just starting out in this. I’ve tried to read a lot before coming here, but my lack of syntax and knowledge of programming is great. I thought that I would be able to search the forum for someone who has done the same project before, but I just can’t seem to find it. I am wanting to make an led Marquee sign that has serial data in (as done from serial monitor etc…) to a Sure electronics 3208 ht1632 chip set. So as when the text comes in from the serial monitor or other then it scrolls from the right side to the left side, clears out the info if it is updated. I have tried the following and of course it doesn’t like it (please don’t laugh at my overwhelming ignorance). This was my attempt at throwing some stuff together from other programs to make it work. If there is already a working program for this I couldn’t find it. Please Help me :frowning:

/* http://scuola.arduino.cc/en/content/interfacing-arduino-uno-sure-electronics-led-dot-matrix-based-ht1632c-controller
Pin 11 to GND
Pin 12 to VCC
Pin 3 ( CS1) to Arduino Digital pin 9
Pin 5 (WR) to Arduino Digital pin 10
Pin 7 (DATA) to Arduino Digital pin 11
*/
#include <font_5x4.h>
#include <HT1632.h>
#include <images.h>

int i = 0;
int wd;
const char rotation;

void setup () {
// Setup and begin the matrix
// HT1632.begin(CS1,WR,DATA)
HT1632.begin( 9, 10, 11);
// initialize the serial communications:
Serial.begin(9600);

// Give the width, in columns, of the assigned string
// FONT_5x4_WIDTH and FONT_5x4_HEIGHT are parameter specified in the “font_5x4.h” file
wd = HT1632.getTextWidth(“I hope that you enjoy playing around with these Sure 3208 displays Doc !”, FONT_5X4_WIDTH, FONT_5X4_HEIGHT);
}

void loop () {
// when characters arrive over the serial port…
if (Serial.available())
// wait a bit for the entire message to arrive
delay(100);
// read all the available characters
while (Serial.available() > 0)
// store data from serial
rotation = (Serial.read ());

// Font rendering example
HT1632.drawTarget(BUFFER_BOARD(1));
HT1632.clear();
HT1632.drawText ((rotation), 2*OUT_SIZE - i, 2, FONT_5X4, FONT_5X4_WIDTH, FONT_5X4_HEIGHT, FONT_5X4_STEP_GLYPH);
HT1632.render();

i = (i+1)%(wd + OUT_SIZE * 2);
delay(200);
}

Hi,

I've not tested your code, but the most obvious thing that stands out is you're reading everything from the serial buffer into a single character, here:

while (Serial.available() > 0) 
  // store data from serial
 rotation = (Serial.read ());

When that loop is complete, the final character from the serial buffer is all you've stored since each successive new read overwrites the one before.

You might want to store your buffer into a character array, therefore you'll be able to keep a few characters that you can have displaying on the screen. You'll need some logic such that as you fill your array it shuffles the characters left.

Hope this helps, Geoff

Thank you for your reply. I spent a lot of hours today figuring out what you meant as I had no clue. I now have to project to where it will not give syntax errors. However the portion that is sent by the Serial monitor comes across as garbage. :frowning: here is the new sketch. I have tried adding delays but because of another sketch that does an echo, I think that it has something to do with the converting the serial info to char array. If anyone knows the solution it would be appreciated. Thanks

/* http://scuola.arduino.cc/en/content/interfacing-arduino-uno-sure-electronics-led-dot-matrix-based-ht1632c-controller
Pin 11 to GND
Pin 12 to VCC
Pin 3 ( CS1) to Arduino Digital pin 9
Pin 5 (WR) to Arduino Digital pin 10
Pin 7 (DATA) to Arduino Digital pin 11
*/
#include <font_5x4.h>
#include <HT1632.h>
#include <images.h>

int i = 0;
int wd;
String msg[1];
char final_message[30];
byte serialdata;

void setup () {
// Setup and begin the matrix
// HT1632.begin(CS1,WR,DATA)
HT1632.begin( 9, 10, 11);
// initialize the serial communications:
Serial.begin(9600);

msg[0] = “Welcome”;
msg[0].toCharArray(final_message,30);
wd = HT1632.getTextWidth(final_message, FONT_5X4_WIDTH, FONT_5X4_HEIGHT); // Give the width, in columns, of the assigned string

}

void loop () {
// when characters arrive over the serial port…
if (Serial.available()> 0) {
// store data from serial
serialdata = (Serial.read ());
msg[serialdata].toCharArray(final_message,30);

}

// Font rendering example
HT1632.drawTarget(BUFFER_BOARD(1));
HT1632.clear();
HT1632.drawText (final_message, 2*OUT_SIZE - i, 2, FONT_5X4, FONT_5X4_WIDTH, FONT_5X4_HEIGHT, FONT_5X4_STEP_GLYPH);
HT1632.render();

i = (i+1)%(wd + OUT_SIZE * 2);
delay(125);
}

What HT1632 library are you using? Can you provide the download link? I have the Adafruit one but can't test your code as it's written for something else I presume?

Geoff

Ok it is the one that is listed here from github http://scuola.arduino.cc/lesson/d37dc9b/Interfacing_Arduino_UNO_with_SURE_electronics_LED_Dot_Matrix Thank you again for helping.

Thanks

I don't have one of those displays handy, but just looking at your logic I'm wondering why you have an array of one String object (msg[1] rather than just delaring a single one.

// String msg[1]; becomes
String msg;
// and later
  msg = "Welcome";
  msg.toCharArray(final_message,30);

The loop where you load serial data into the String object probably could be as simple as   if (Serial.available()> 0) { msg += Serial.read(); }Unlike an array of characters you don't need to add the new characters at an index in the array, but you can just append them to the end. (note this will grow, and with nothing yet to reset it this will ultimately eat up all your available RAM if there's no mechanism to blank out the message eventually).

Once you've loaded up the String object in that loop, this line should be after the loop msg.toCharArray(final_message,30);That's simply to take what's in that String object, and put it in a character array that you can output to the display.

If you have that working, you can move onto making it scroll - and sorting out the String object so it isn't able to bloat out and use up all your RAM. You're on the way though.

Cheers ! Geoff

lol it is on its way. now instead of clearing the screen it now if you type the letter "a" it appends that to the welcome but does it in the ascii equivalent so it looks like welcome97

its different at least

Good point. To get it to treat it as a character,

if (Serial.available()> 0) { msg += char(Serial.read()); }

Also, if there’s a chance your information will contain the newline (generated from the enter key) you’ll want to avoid storing ASCII 13 & 10, so something like this

char thisChar;
if (Serial.available()> 0) { 
thisChar = Serial.read();
if(thisChar != 10 && thisChar != 13) msg += thisChar; 
}

That should get you nearer,
Geoff

strykeroz I sure appreciate all your help. This is the closest i’ve been so far. However it only returns the last letter from the serial monitor. e.g. “12345” would return “5” on the led display.

/* http://scuola.arduino.cc/en/content/interfacing-arduino-uno-sure-electronics-led-dot-matrix-based-ht1632c-controller
Pin 11 to GND
Pin 12 to VCC
Pin 3 ( CS1) to Arduino Digital pin 9
Pin 5 (WR) to Arduino Digital pin 10
Pin 7 (DATA) to Arduino Digital pin 11
*/
#include <font_5x4.h>
#include <HT1632.h>
#include <images.h>

int i = 0;
int wd;
int serialdata;

void setup () {
// Setup and begin the matrix
// HT1632.begin(CS1,WR,DATA)
HT1632.begin( 9, 10, 11);
// initialize the serial communications:
Serial.begin(9600);

}

void loop () {
// when characters arrive over the serial port…
if (Serial.available()) {
// store data from serial
serialdata = (Serial.read ());

}

// Font rendering example
HT1632.drawTarget(BUFFER_BOARD(1));
HT1632.clear();
HT1632.drawText ((char )&serialdata, 2OUT_SIZE - i, 2, FONT_5X4, FONT_5X4_WIDTH, FONT_5X4_HEIGHT, FONT_5X4_STEP_GLYPH);
HT1632.render();

i = (i+1)%(wd + OUT_SIZE * 2);
delay(125);
}

Hi,

Somehow you've ignored what I've been telling you though? This version is back to storing just the final character in the serial stream, only now as an integer..

  int serialdata;  //...and then later...

   // when characters arrive over the serial port...
  if (Serial.available()) {
    // store data from serial
 serialdata = (Serial.read ());
  }

So you've reintroduced your original issue, and lost the String object entirely and replaced it with an integer. Looks like you've taken a big step backwards.