簡體   English   中英

帶有Arduino和Xbee的20x4 LCD

[英]20x4 lcd with arduino and xbee

即時通訊使用連接到20x4液晶顯示器和xbee的arduino mega。 LCD是i2c接口。 我使用以下代碼將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());

  }
}

但是,它在LCD上顯示黑框而不是文字。 如果我使用lcd.print(“ test”); 它顯示“文本”,這表示LCD正在接收從xbee發送的數據,但是我不能使用lcd.print,因為接收到的數據是隨機的。 而且,由於所有單詞都在同一行中,因此每個單詞后我如何清除屏幕。

我認為發生此問題的原因有兩個:

  1. 數據在傳輸時可能會損壞,因此可能必須實施某種錯誤檢查方法(例如:校驗和),如果是這種情況,則再次請求數據。
  2. 您必須檢查從發送器模塊發送的數據格式是什么。 我的意思是LCD希望數據采用ASCII格式,即從xbee收到的相同格式。

基本上,您必須在多個點檢查數據,並找出問題出在哪里。 既然你說的是寫作

 lcd.print("test");

確實可以正常工作,因此我相信I2C設置正確,因此上述問題是我唯一能想到的。

方法:-為什么不在arduino的串行監視器上顯示接收到的xbee串行數據,並檢查接收到的數據是否正確。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM