首页 文章

Xbee pro系列2b和TGS 2602-接收值是错误的,不会改变

提问于
浏览
1

我有一个arduino uno,xbee pro系列2 b和一个voc传感器:tgs 2602.我想通过xbee将传感器的电阻值发送到arduino的串行监视器 . tgs2602 - > xbee - xbee - > xbee shield - > arduino uno

我将我的第一个xbee配置为AT Modus中的路由器,采样率为1000ms,我的协调器采用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.即使我触摸传感器,该值也不会改变 .

为什么?难道我做错了什么 .

我需要你的帮助 .

谢谢

1 回答

  • 0

    确保为模拟输入正确配置所有内容 . Digi在configuring an analog input with a potentiometer上有一个很好的教程 . 按照这些步骤进行操作,然后逐步进行更改,直到您在Arduino上读取传感器 .

    例如,一旦您将电位计工作在XBee和PC上,请将其连接到Arduino并确保读数正确 . 然后用传感器更换电位计,看看读数是否仍然正确 .

相关问题