I have tested it out directly using a serial port and everything checks out fine so i know that it's working perfectly, but when i create a simple sketch to send the baud rate sync ("0x55") and wait for the arduino to receive the acknowledgment packet ("0x06"), i get back nothing, i.e. the buffer appears to be empty.
Below is the simple code i am using to connect the LCD to serial port two and print the response back to serial port one for me to read in the serial terminal.
void loop(){
Serial2.flush();
Serial2.print(0x55,BYTE); //baud rate sync command (this works as the screen would otherwise show a splash screen)
Serial.print(Serial2.read(),BYTE); //should print out 0x06 but i get FF which means nothings in the buffer
if (XX == 0x06)
{Serial.print(0xAA,BYTE);}
delay(1000);
}
I have tested near everything on it's own and together, it just seems the combination of the ATMega chip Rx and the Screen Tx don't mix, any help would be greatly appreciated.
I have experimented with delays and it doesnt seem to make any difference, even if i print what should be in the buffer aftef i know it's been sent, it still returns nothing, which is why i havent bothered to include the serial.available command.
Here is the new code i'm using to both give enough time for a response and to only print if data is available, i know for a fact data is being sent to the rx pin and yet it is still not print, any ideas?
//MEGA//
int XX = 0;
int pin = 13;
void setup(){
Serial.begin(9600);
Serial2.begin(9600);
pinMode(13,OUTPUT);
delay(5000); //gives me time to power up the LCD
}
void loop(){
Serial2.print(0x55,BYTE); //Send autobaud command
delay(1000);
while(Serial2.available())
{
XX = Serial2.read(); //grab buffer
Serial.print(XX,BYTE); //print buffer data to serial port
if (XX == 0x06){pin=HIGH;} //if correct byte, LED on
}
delay(1000);
}
if (XX == 0x06){pin=HIGH;} //if correct byte, LED on
Had you correctly define pin as a const int, rather than an int, the compiler would have told you that this is not how to turn the LED on. You need to use digitalWrite(pin, HIGH); to do that.
Allow up to 500ms delay after power-up or reset for the module to settle. Do not attempt to communicate with the module during this period. The device may send garbage on its TX Data line during this period, the host should disable its Rx Data reception.
So you should wait 500 ms, then flush the buffer, to clear any garbage, and then attempt to read the byte. Something like this:
Serial2.print(0x55,BYTE); //Send autobaud command
delay(500);
Serial2.flush();
// wait until data available
while(!Serial2.available())
{}
XX = Serial2.read(); //grab buffer
if (XX == 0x06)
{
digitalWrite(pin, HIGH);
} //if correct byte, LED on
I see what you mean, but it still doesn't produce a result, the 500ms delay is from when you power the device on and before you send 0x55, which is what i'm doing, from what i can tell the problem is the ATMega chip just isn't picking up any serial data being sent to it from the LCD(even when i know it's being sent), however this problem only exists with the LCD as it will receive serial data from another arduino without problem.
Ah yes, well it seems I misread the spec. You are right, you wait 500 ms after power-up, not after sending the command.
So it should probably be instead:
delay(500); // power-up delay
Serial2.flush();
Serial2.print(0x55,BYTE); //Send autobaud command
// wait until data available
while(!Serial2.available())
{}
XX = Serial2.read(); //grab buffer
if (XX == 0x06)
{
digitalWrite(pin, HIGH);
} //if correct byte, LED on
But if it works with another Arduino it might be the voltage levels perhaps.
This is pretty much what i'm doing, but i don't see how there could be a voltage level problem, if i remove the ATMega chip and directly connect the LCD to the FTDI chip on the arduino i can send/receive data from the screen perfectly, which is why i can't understand why the ATMega can't receive at all.
Is the lcd using the same digital 0 and 1 as its Rx and Tx pins, if you have anything connected to those pins the atmega may not receive anything in its serial port.
Do you know that 0x06 is a non printable char, and not the number 6, right?
Nothing else is connected to the Rx and Tx pins so the signal isn’t being ‘diverted’ anywhere else, and i know, but this sketch won’t pick up anything being sent from the LCD.