简体   繁体   English

带有Arduino和Xbee的20x4 LCD

[英]20x4 lcd with arduino and xbee

im using an arduino mega attached to a 20x4 lcd and xbee. 即时通讯使用连接到20x4液晶显示器和xbee的arduino mega。 LCD is a i2c interface. LCD是i2c接口。 Im using the following the code to write the data received by the xbee on the LCD. 我使用以下代码将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());

  }
}

However, it shows black boxes on the LCD instead of words. 但是,它在LCD上显示黑框而不是文字。 If i use lcd.print("test"); 如果我使用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. 它显示“文本”,这表示LCD正在接收从xbee发送的数据,但是我不能使用lcd.print,因为接收到的数据是随机的。 Moreover, how can i clear the screen after every word as all the words come in a single line. 而且,由于所有单词都在同一行中,因此每个单词后我如何清除屏幕。

There are two reasons why i think this problem is occurring :- 我认为发生此问题的原因有两个:

  1. Probably the data is getting corrupted while getting transmitted, so might have to implement some error check method (eg: checksum), and request again for data if that is the case. 数据在传输时可能会损坏,因此可能必须实施某种错误检查方法(例如:校验和),如果是这种情况,则再次请求数据。
  2. You have to check what is the format of data that is being transmitted from your transmitter module. 您必须检查从发送器模块发送的数据格式是什么。 I mean LCD expects the data to be in ASCII format, is that the same format received from xbee. 我的意思是LCD希望数据采用ASCII格式,即从xbee收到的相同格式。

Basically you have to check your data at multiple points and find out where exactly the problem occurs. 基本上,您必须在多个点检查数据,并找出问题出在哪里。 Since you are saying that writing 既然你说的是写作

 lcd.print("test");

does work properly hence i believe the I2C is set correctly, so above mentioned problems are the only things i can think of. 确实可以正常工作,因此我相信I2C设置正确,因此上述问题是我唯一能想到的。

Approach:- Why don't you display the serial data received xbee on serial monitor of arduino and check if the data received is correct or not. 方法:-为什么不在arduino的串行监视器上显示接收到的xbee串行数据,并检查接收到的数据是否正确。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM