2016-03-08 118 views
0

即時通訊使用附加到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

回答

0

有兩個原因,我覺得這個問題是存在的: -

  1. 可能中的數據被同時獲得傳輸損壞,所以可能會執行一些錯誤檢查方法(如:校驗),並要求如果是這樣的話,再次提供數據。
  2. 您必須檢查從發射器模塊發送的數據格式是什麼。我的意思是LCD預計數據是ASCII格式,是從xbee接收的相同格式。

基本上,你必須檢查你的數據在多個點,並找出問題發生的地方。 既然你說寫

lcd.print("test"); 

不正常工作,因此我相信,I2C設置正確,那麼上述問題是我能想到的唯一的東西。

方法: - 爲什麼不在Arduino的串口監視器上顯示接收到的串口數據xbee,並檢查收到的數據是否正確。