Greetings,
I have an LED display that displays text strings using the following code.
The code runs on a Nano and outputs the formatted strings with control characters over serial interface.
my intention is to convert the code to allow a wireless interface using two nanos talking via HC-12 wireless modules. the first storing the numerous strings and sending them periodically via the 1st HC-12. the second one receives the string and packages the string in the format for the display and sends it to the LED display using the dedicated serial input. drawing attached.
Here is the current working code that has no wireless ability and only sends the preexisting strings. basically i want this to accept wireless inputs.
#include <string.h>
char s[2]={0,0};
char buf[200]={0}; //make this larger than any anticipated string.
char scroll_txt[]={0x76,0x18,0x06,0x39,0}; //command for scrolling text, speed 0x30 - 0x39
char centre_txt[]={0x76,0x18,0x17,0}; //command for centred text
char EOL_chars[]={0x0d,0};
char text[]="Why do they call it the novel coronavirus? It’s a long story…";
///////////////////////////////////////////////////////
void setup()
{
Serial.begin(1200,SERIAL_7E2); //SERIAL_7E2
}
///////////////////////////////////////////////////////
unsigned char WB_Parity_Calc( char *str )
{
unsigned char Par;
Par = 0x00;
while( *str )
Par ^= *str++;
Par = Par & 0x7F;
return ~Par;
}
///////////////////////////////////////////////////////
void loop() {
memset(buf, '\0', sizeof(buf)); //clear output string
strncat(buf,scroll_txt,sizeof(buf)); //scroll text or
//strncat(buf,centre_txt,sizeof(buf)); //centre text
strncat(buf,text,sizeof(buf));
strncat(buf,EOL_chars,sizeof(buf));
s[0]=WB_Parity_Calc(buf); //make a 1 character C-string with checksum
strncat(buf,s,sizeof(buf)); //concatenate checksum char
Serial.println(buf); //transmit the resulting string
delay(3000);
}
///////////////////////////////////////////////////////
here is the code i curently have for the transmitting nano #1
// Transmitter
#include <SoftwareSerial.h>
#define RX 2
#define TX 3
SoftwareSerial mySerial(RX, TX);
///////////////////////////////////////////
void setup() {
Serial.begin(9600);
mySerial.begin(9600);
}
///////////////////////////////////////////
void loop() {
digitalWrite(LED_BUILTIN, HIGH);
delay(1000);
mySerial.write("Hello World");
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
}
///////////////////////////////////////////
Here is the modified code for the receiving nano #2 that currently doesn't work. i get the following error:
incompatible types in assignment of 'int' to 'char [60]' when I try to save the incoming string which is guess is in integer form to a string of Characters.... problem is i have no idea ho to solve it.
// Receiver
#include <string.h>
#include <SoftwareSerial.h>
#define RX 2
#define TX 3
char s[2]={0,0};
char buf[200]={0}; //make this larger than any anticipated string.
char scroll_txt[]={0x76,0x18,0x06,0x39,0}; //command for scrolling text, speed 0x30 - 0x39
char centre_txt[]={0x76,0x18,0x17,0}; //command for centred text
char EOL_chars[]={0x0d,0};
char text[60];
SoftwareSerial mySerial(RX, TX);
///////////////////////////////////////////////////////
void setup() {
Serial.begin(1200,SERIAL_7E2); //SERIAL_7E2
mySerial.begin(9600);
pinMode(LED_BUILTIN,OUTPUT);
}
///////////////////////////////////////////////////////
unsigned char WB_Parity_Calc( char *str )
{
unsigned char Par;
Par = 0x00;
while( *str )
Par ^= *str++;
Par = Par & 0x7F;
return ~Par;
}
///////////////////////////////////////////////////////
void loop() {
if(mySerial.available())
{
text = mySerial.read();
}
memset(buf, '\0', sizeof(buf)); //clear output string
strncat(buf,scroll_txt,sizeof(buf)); //scroll text or
//strncat(buf,centre_txt,sizeof(buf)); //centre text
strncat(buf,text,sizeof(buf));
strncat(buf,EOL_chars,sizeof(buf));
s[0]=WB_Parity_Calc(buf); //make a 1 character C-string with checksum
strncat(buf,s,sizeof(buf)); //concatenate checksum char
Serial.println(buf); //transmit the resulting string
digitalWrite(LED_BUILTIN, HIGH);
delay(3000);
digitalWrite(LED_BUILTIN, LOW);
}
///////////////////////////////////////////////////////
please help!
WIRELESS LED DISPLAY.pdf (381 KB)
