C++ 带arduino和xbee的20x4液晶显示器

C++ 带arduino和xbee的20x4液晶显示器,c++,arduino,xbee,lcd,C++,Arduino,Xbee,Lcd,我正在使用一个连接到20x4 lcd和xbee的arduino mega。LCD是一个i2c接口。Im使用以下代码将xbee接收到的数据写入LCD /***************************************************************** XBee_Serial_Passthrough.ino Set up a software serial port to pass data between an XBee Shield and the serial

我正在使用一个连接到20x4 lcd和xbee的arduino mega。LCD是一个i2c接口。Im使用以下代码将xbee接收到的数据写入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());

  }
}
/*****************************************************************
XBee_Serial_Passthrough.ino
设置软件串行端口以在XBee屏蔽之间传递数据
和串行监视器。
硬件连接:
XBee屏蔽提供您所需的所有连接
在Arduino和XBee之间。如果你有盾牌的话
确保开关处于“数据线”位置。那会有联系的
XBee的DOUT和DIN引脚连接到Arduino引脚2和3。
*****************************************************************/
//我们将使用SoftwareSerial与XBee进行通信:
#包括
#包括
#包括
LCD03液晶显示器;
//XBee的DOUT(TX)连接到引脚2(Arduino的软件RX)
//XBee的DIN(RX)连接到引脚3(Arduino的软件TX)
软件系列XBee(10,11);//接收,发送
无效设置()
{
//将两个端口设置为9600波特。此值最重要
//对于XBee。确保波特率与配置匹配
//设置您的XBee。
XBee.begin(9600);
Serial.begin(9600);
//初始化20x4液晶显示器
lcd.begin(20,4);
//打开背光灯
lcd.backlight();
//写入LCD
lcd.print(“你好世界”);
//等待5秒钟
延迟(5000);
//清除LCD
lcd.clear();
}
void循环()
{
if(Serial.available())
{//如果数据来自串行监视器,则将其发送到XBee
XBee.write(Serial.read());
}
if(XBee.available())
{//如果数据来自XBee,则将其发送到串行监视器
Serial.write(XBee.read());
lcd.write(XBee.read());
}
}
然而,它在LCD上显示的是黑匣子而不是文字。 如果我使用lcd.print(“测试”);它显示“文本”,这意味着LCD正在接收从xbee发送的数据,但我不能使用LCD.print,因为接收的数据是随机的。
此外,我如何在每个单词后清除屏幕,因为所有单词都在一行中

我认为出现这个问题的原因有两个:-

  • 可能数据在传输过程中被破坏了,因此可能必须实现一些错误检查方法(例如:校验和),如果是这种情况,则再次请求数据
  • 您必须检查从变送器模块传输的数据格式。我的意思是LCD希望数据是ASCII格式的,就是从xbee收到的相同格式
  • 基本上,您必须在多个点检查数据,并找出问题发生的确切位置。 既然你说的是写作

     lcd.print("test");
    
    工作正常,因此我相信I2C设置正确,所以上述问题是我唯一能想到的

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

    以及您向arduino发送的文本是什么?你怎么寄的?您是否检查了通过串行端口发送的数据?另一个xbee模块连接到7''lcd和arduino mega。图像显示在lcd上,图像名称发送到xbee,例如(饮料)显示在连接到20x4 lcd的xbee序列上。串行数据正在传输,但20x4 lcd上的文本传输不正确。这些词正在破译█请给我一杯饮料。