0

I have a DHT11 temp/humidity sensor connected to my arduino. I've have correct readout to my arduino serial monitor.

Now I want to route that data to Max/msp thru SerialReceive. I have connection to my arduino and it gives me a bang on the same time I get an update of the data read of my arduino. Only thing is I don't get the same data in Max/msp. How do I translate the data from arduino to the same data in Max/msp.

code 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-----------
Blckpstv
  • 117
  • 3
  • 17

1 Answers1

1

Are you sure that you want to use digitalRead rather than analogRead? I am not familiar with the sensors that you're using, but it seems likely that they would require analogRead. Regardless, I just had this same serial port question and found the answer here:

http://www.underwater.ca/blog/arduino-to-max-msp/

The patch in the link above will bring in the same data that you can see in the Arduino Serial Monitor. In order to separate your analog values, you need to add a space between your variables, so your loop should look like this:

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);
}`

Within max, you can parse the two values (which are now seperated by a space) message using the unpack object.

Joe P.
  • 73
  • 8
  • The arduino forum has lots of libraries/patches to work with! I like the Arduino2maxfordummies one. Really easy! – Blckpstv Apr 14 '17 at 19:56