week7

For this week, I try to learn how to use the WIFININA library and the OSCMessage library in Arduino to try to communicate with Touchdesigner.

I followed the WifiUDP_OSC_MIDI_Client example.

Firstly,I changed the remoteAddress with my Mac's IP Address. And  send the values detected from the DHT11 sensor and button every three seconds to the TD.

截屏2021-03-30 上午7.46.34.png

void loop() {
  // once every three seconds:
  if (millis() % 1000 < 3) {
    int sensor = digitalRead(11);
    float h = dht.readHumidity();
    float t = dht.readTemperature();

if (isnan(h) || isnan(t)) {
    Serial.println(F("Failed to read from DHT sensor!"));
    return;
  }
    
    if (counter % 2 != 0) {

      midimsg[0] = int(h);
      midimsg[1] = int(t);
      
    }

   if(sensor==HIGH){
      midimsg[2] =1;
   }else{
      midimsg[2] =0;
   }
     
    counter++;
    OSCMessage msg("/Data/0");
    for (int b = 0; b < sizeof(midimsg); b++) {
      msg.add(midimsg[b]);
      Serial.print(midimsg[b], DEC);
      Serial.print(" ");
    }
    Serial.println();
    Udp.beginPacket(remoteAddress, remotePort);
    msg.send(Udp); // send the bytes to the SLIP stream
    Udp.endPacket(); // mark the end of the OSC Packet
    msg.empty(); // free space occupied by message
  }
}

In TD, choose OSC In Module and change its Network Port to 8000. For the Local address, i just use the default value.

截屏2021-03-30 上午7.34.59.png

The three data obtained from Arduino are selected separately, followed by the math module to map with the corresponding numerical range, and I refer to the tutorial for visual visualization.I associate the value of temperature and humidity with the color of the liquid, but the effect is not obvious, and use buttons to control the generation of the effect.