Hi,
I am using the SoftwareSerial library to send message over Serial to a 2X16 LCD display. In the below code, I send over 32 characters. The 1 - 16 characters go on the first line and 17-32 go on the 2nd line. This works fine when using the Arduino IDE serial monitor. I can send over server messages and the LCD is updated. My issue is when I send the data via usb using python or C# (.net or Raspberry Pi). The first 32 characters update the LCD, but then it stops updating. In both cases I am using while loops to send over the messages. Any help would be great
The bellow code is flashed on the an Atty84
/*
LiquidCrystal Library - Serial Input
*/
#include <LiquidCrystal.h>
#include <SoftwareSerial.h>
#define rxPin 2 // receive
#define txPin 3 // transmit
SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin);
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(4, 5, 6, 7, 8, 9);
char lineOne[16];
char lineTwo[16];
int maxChar = 32;
char inLineData[32]; // Allocate some space for the string - only 32 chars / 16 allowed per line
char inLineChar=-1; // Where to store the character read
void setup(){
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// define pin modes for tx, rx, led pins:
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
mySerial.begin(9600);
mySerial.print("LCD Display...");
lcd.print("Initializing...");
delay(800);
lcd.clear();
lcd.print("Ready");
}
void loop()
{
// when characters arrive over the serial port...
if (mySerial.available()) {
// wait a bit for the entire message to arrive
delay(1000);
// read all the available characters
byte index = 0;
int readData;
while (mySerial.available() > 0) {
readData = mySerial.read(); // Read a character
inLineData[index] = readData; // Store it
// display each character to the LCD
if(index < 16){
lcd.setCursor(index, 0);
lcd.write(inLineData[index]);
}else{
lcd.setCursor(index, 1);
lcd.write(inLineData[index]);
}
delay(100);
if(index>15){
delay(100);
lcd.setCursor(index - 16, 1);
lcd.write(inLineData[index]);
}
index++;
}
delay(2000);
index = 0;
}
}
Example loop in python
while 1:
// output serial message
sleep(2)