我有一个DHT11温度/湿度传感器连接到我的arduino。我的arduino串口显示器读数正确。
现在我想将数据路由到Max / msp到SerialReceive。我连接到我的arduino并且在我获得arduino的数据读取更新的同时给了我一声巨响。唯一的问题是我没有在Max / msp中获得相同的数据。如何将数据从arduino转换为Max / msp中的相同数据。
代码Arduino:
#include "dht.h" //library
dht DHT;
#define DHTPIN 2
int VTemperature = 2;
int VHumidity = 2;
void setup(){
Serial.begin(9600);
}
void loop()
{
int chk = DHT.read11(DHTPIN);
VTemperature = digitalRead(DHT.temperature);
Serial.println(DHT.temperature);
VHumidity = digitalRead(DHT.humidity);
Serial.println(DHT.humidity);
Serial.print("\r");
delay(1000);
}
Patch Max / Msp
----------begin_max5_patcher----------
902.3oc0YtrbaBCEFds8SgFV65QW3l6p1c8cnSlLxfhCoXIFPj5jL4cu5BNE
mfswxXhyFtHqH8qONmi9g7xzIdKEaXUdfuC9MXxjWlNYhoIcCSZteh2Z5ljb
Zkoad750KYkdyr+j5tLdNSZ9MTSiUxmxYlN2pahZ419gaZsfJStOiu51RVhz
pALdw7fYfPHdNbFH.pOhUWCto4u4NAWVk8rY3Q5NYaNK0LehkO7sXuVckSWa
UxOKyn4duMwkp1krxaYb5RqV2NRVcJepfYUjZM.7VR4q7.2n6wqSmpOLqu3h
8Wkn1NwR1FyB0qnLiKAURprtB7iBQQcA.cVPEten5iHZN5iMmPjXCUI6ipjt
nJ9PXcn4RJURu3TAG52lJp.uSmJ9vgkJqYUUzUrOfEQAi2IGv8jCn8yARjdg
ShLQEDWnPTzwS49XZkSoS6CPI4hJ1kkP9Hn8jCDJ.MZDZOIV07BZxe.P.7Dy
mRD4hRqhfyiB8ifgyTWEiVDBi0WEDgC7WnxfZQjtq2qW62QSXGIwDQH58.TC
plzgF3iQ6i2n4AKBPwQeD5tvbU0Gc8d8I2n+Ec2wH34t4H9qvli2UJVW8z5k
h7wOVEc73RrIhLB5Zb4hO6ZAToHqSxRFCxdZUA7WXK95LsQPGvcdVkbPQ9y4
fUkBsclvSbWpOs5u9ggl5uwNSdm1za1.GrWwxUqH.BdhQ76hPhaHz5sLvYD5
6.AMkim8+yCqQKiA8KrUTBx5H0EC4imQKoX0pb1YsU+A2rwTwiXe0MLb6w2X
Q6DMem161cSNcmool3RgJQCBGj3idmpYAkMbIJ7voZcFzf51UzuX4OxjYIzC
mpMrEqzApfDfp39WAi5VzGadQZ6wSD8DGIeiO8cguYdU6cye+Wzxncc669Do
RTWlrcDablA9u5SYUxLNUlI3s5CZm9beVZJi2lSoYU5LOyRD1YjQeUi90pOp
bHilbBPWUxw+JSN8PM5uVzUjbzeRuqH4fPipbvmqbVmkVHT0gZp0fhMuUtu0
rGxOvX.b26BsepQe6miMrs0lgawQ5Sj3ngZTudziGO8fGfxFu+QOw7OsfX+7
Lsu6B73E0m5dnwqRy6lpt0yhwSN8PMwWUpw0XeqaGZQwirxplgzHDkSyGrNA
MuQoJZkau0LhdkrGy11eaKzRkyNoxVWco0+0lP6aT3sVjxJ40YFCbS0y7qS+
GLY+hsE
-----------end_max5_patcher-----------
答案 0 :(得分:1)
您确定要使用digitalRead而不是analogRead吗?我不熟悉您正在使用的传感器,但似乎他们需要使用analogRead。无论如何,我只是遇到了同样的串口问题,并在这里找到答案:
http://www.underwater.ca/blog/arduino-to-max-msp/
上面链接中的补丁将带来您在Arduino串行监视器中可以看到的相同数据。为了分离您的模拟值,您需要在变量之间添加空格,因此您的循环应如下所示:
void loop() {
int chk = DHT.read11(DHTPIN);
VTemperature = digitalRead(DHT.temperature);
Serial.print(DHT.temperature);
Serial.print(" "); //Delimiter, important!
VHumidity = digitalRead(DHT.humidity);
Serial.println(DHT.humidity);
delay(1000);
}`
在max中,您可以使用解包对象解析这两个值(现在由空格分隔)。