【发布时间】:2014-06-13 14:52:18
【问题描述】:
我有一个 arduino uno、xbee pro series 2 b 和一个 voc 传感器:tgs 2602。 我想通过 xbee 将传感器的电阻值从 arduino 发送到串行监视器。 tgs2602--> xbee - xbee-->xbee 盾牌-->arduino uno
我将我的第一个 xbee 配置为 AT Modus 中的路由器,采样率为 1000 毫秒,并在 API 中配置我的协调器。 我使用的草图如下所示:
//Remote XBee:AT, Base XBee:API
float voc;
void setup(){
Serial.begin(9600);
};
void loop(){
if(Serial.available() >=21){ //Makesure the frame is all there
if (Serial.read()== 0x7E){ //7E is the start byte
for (int i = 1; i<18; i++) { //Skip ahead to the analog data
byte discardByte = Serial.read();
}
int analogMSB = Serial.read(); // Read the first analog byte data
int analogLSB = Serial.read(); //Read the second byte
int analogReading = analogLSB + (analogMSB * 256);
float volt = analogReading/1023.0 * 5 ; // Rechne die von ADC ausgegebenen Werten in Volt um
float Rs1 = 10*(5-volt)/volt; //Rechne den Widerstandswert
Serial.println(Rs1);
}
}
}
我在 youtube 的示例中使用了这段代码。
我在串行监视器中收到的数据是 5105。即使我触摸传感器,这个值也不会改变。
为什么? 我是不是做错了什么。
我需要你的帮助。
谢谢
【问题讨论】:
-
您可能想要查看框架类型并确保它是正确的。除了模拟读数外,XBee 还会向您发送状态帧。也许转储整个帧以确保它正确并且您正在正确解析它,和/或转储读取的 LSB 和 MSB 值。
-
嗨,tomlogic,我做到了! “discardByte = 0 18 146 0 125 51 162 0 64 173 23 24 85 236 1 1 0”。
-
146 = 0x92,所以这是一个数据样本。
analogMSB和analogLSB是什么?它们有什么不同吗?传感器是否连接到第一个模拟输入 (A0)? -
嗨 tomlogic,analogMSB = 2,analogLSB=0,它们没有变化。传感器连接到第二个模拟输入。 (抱歉回复晚了)
-
嗨,我正在使用 xbee 稳压分线板,我想知道问题是否出在电压上。