im using an arduino mega attached to a 20x4 lcd and xbee. LCD is a i2c interface. Im using the following the code to write the data received by the xbee on the LCD.
/*****************************************************************
XBee_Serial_Passthrough.ino
Set up a software serial port to pass data between an XBee Shield
and the serial monitor.
Hardware Hookup:
The XBee Shield makes all of the connections you'll need
between Arduino and XBee. If you have the shield make
sure the SWITCH IS IN THE "DLINE" POSITION. That will connect
the XBee's DOUT and DIN pins to Arduino pins 2 and 3.
*****************************************************************/
// We'll use SoftwareSerial to communicate with the XBee:
#include <SoftwareSerial.h>
#include <Wire.h>
#include <LCD03.h>
LCD03 lcd;
// XBee's DOUT (TX) is connected to pin 2 (Arduino's Software RX)
// XBee's DIN (RX) is connected to pin 3 (Arduino's Software TX)
SoftwareSerial XBee(10, 11); // RX, TX
void setup()
{
// Set up both ports at 9600 baud. This value is most important
// for the XBee. Make sure the baud rate matches the config
// setting of your XBee.
XBee.begin(9600);
Serial.begin(9600);
// Initialise a 20x4 LCD
lcd.begin(20, 4);
// Turn on the backlight
lcd.backlight();
// Write to the LCD
lcd.print("Hello world");
// Wait for 5 seconds
delay(5000);
// Clear the LCD
lcd.clear();
}
void loop()
{
if (Serial.available())
{ // If data comes in from serial monitor, send it out to XBee
XBee.write(Serial.read());
}
if (XBee.available())
{ // If data comes in from XBee, send it out to serial monitor
Serial.write(XBee.read());
lcd.write(XBee.read());
}
}
However, it shows black boxes on the LCD instead of words. If i use lcd.print("test"); it shows 'text' which means that the LCD is receiving the data sent from xbee but i cannot use lcd.print as the data received is random. Moreover, how can i clear the screen after every word as all the words come in a single line.