与arduino和xbee 20x4液晶显示器

与arduino和xbee 20x4液晶显示器

问题描述:

即时通讯使用附加到20x4 lcd和xbee的arduino mega。 LCD是一个i​​2c接口。我使用以下代码将xbee接收到的数据写入LCD。与arduino和xbee 20x4液晶显示器

/***************************************************************** 
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()); 

    } 
} 

但是,它显示液晶显示屏上的黑色框而不是单词。 如果我使用lcd.print(“test”);它显示'文本'这意味着LCD正在接收从xbee发送的数据,但我不能使用lcd.print作为接收的数据是随机的。 此外,我怎样才能清除每个单词后的屏幕,因为所有的单词都在一行中。

+0

你发送给Arduino的文本是什么?你怎么发送它?你是否检查过通过串口发送的数据? –

+0

另一个xbee模块连接到一个7“液晶显示器和arduino巨型。图像显示在液晶显示器上,并且图像的名称被发送到xbee,例如(饮品)显示在连接到20x4液晶显示器的xbee系列上。数据即将发布,但文字在20x4液晶显示屏上显示不正常。这些词语正在打破,例如喝酒。 – shayaan123

有两个原因,我觉得这个问题是存在的: -

  1. 可能中的数据被同时获得传输损坏,所以可能会执行一些错误检查方法(如:校验),并要求如果是这样的话,再次提供数据。
  2. 您必须检查从发射器模块发送的数据格式是什么。我的意思是LCD预计数据是ASCII格式,是从xbee接收的相同格式。

基本上,你必须检查你的数据在多个点,并找出问题发生的地方。 既然你说写

lcd.print("test"); 

不正常工作,因此我相信,I2C设置正确,那么上述问题是我能想到的唯一的东西。

方法: - 为什么不在Arduino的串口监视器上显示接收到的串口数据xbee,并检查收到的数据是否正确。