this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add: Send & receive OSC messages with NoceMCU

+319
+274
ESP8266OSC.ino
··· 1 + /*--------------------------------------------------------------------------------------------- 2 + 3 + Open Sound Control (OSC) library for the ESP8266/ESP32 4 + 5 + Example for receiving open sound control (OSC) messages on the ESP8266/ESP32 6 + Send integers '0' or '1' to the address "/led" to turn on/off the built-in LED of the esp8266. 7 + 8 + This example code is in the public domain. 9 + 10 + Changes: 11 + 12 + T.Goerke 05/18 13 + - combined send & receive 14 + - OSC messages can be used to set outgoing osc server (last octet) & port (optional) 15 + 16 + Example: (using https://github.com/nulltask/osc-cli) 17 + 18 + NoceMCU IP OSC IP 19 + pi@nodered:~$ osc --host 192.168.1.207:8888 /osc 215 9999 20 + OSC Port 21 + 22 + - add MPR121 cap sensor board 23 + - send NoteOn & NoteOff OSC messages to Renoise 24 + - (send Analog Filter Cutoff to renoise) 25 + --------------------------------------------------------------------------------------------- */ 26 + #ifdef ESP8266 27 + #include <ESP8266WiFi.h> 28 + #else 29 + #include <WiFi.h> 30 + #endif 31 + #include <WiFiUdp.h> 32 + #include <OSCMessage.h> 33 + #include <OSCBundle.h> 34 + #include <OSCData.h> 35 + 36 + #include <Wire.h> 37 + #include "Adafruit_MPR121.h" 38 + Adafruit_MPR121 cap = Adafruit_MPR121(); 39 + // Keeps track of the last pins touched 40 + // so we know when buttons are 'released' 41 + uint16_t lasttouched = 0; 42 + uint16_t currtouched = 0; 43 + 44 + char* players[]={ 45 + "Brian", 46 + "Fynn", 47 + "Jannes", 48 + "Aron", 49 + "Konrad", 50 + "Hannes", 51 + "Julian", 52 + "Alejandro", 53 + "Marco", 54 + "Noah", 55 + "Fernando", 56 + "Achim", 57 + "Torsten" 58 + }; 59 + 60 + char ssid[] = "DLRobotik"; // your network SSID (name) 61 + char pass[] = "Aquabot!"; // your network password 62 + 63 + /** 64 + char ssid[] = "WLAN1-004149"; // your network SSID (name) 65 + char pass[] = "B15C611673A3135"; // your network password 66 + **/ 67 + 68 + // A UDP instance to let us send and receive packets over UDP 69 + WiFiUDP Udp; 70 + const unsigned int localPort = 8888; // local port to listen for UDP packets 71 + 72 + unsigned int maxPort = 9999; // remote port (not needed for receive) 73 + unsigned int renoisePort = 9000; // remote port (not needed for receive) 74 + unsigned int p5Port = 9990; // remote port (not needed for receive) 75 + 76 + unsigned int maxHost = 147; // last octet of osc server host 77 + unsigned int renoiseHost = 147; // last octet of osc server host 78 + unsigned int p5Host = 147; // last octet of osc server host 79 + 80 + OSCErrorCode error; 81 + unsigned int ledState = LOW; // LOW means led is *on* 82 + #ifndef BUILTIN_LED 83 + #ifdef LED_BUILTIN 84 + #define BUILTIN_LED LED_BUILTIN 85 + #else 86 + #define BUILTIN_LED 13 87 + #endif 88 + #endif 89 + 90 + void setup() { 91 + pinMode(BUILTIN_LED, OUTPUT); 92 + digitalWrite(BUILTIN_LED, ledState); // turn *on* led 93 + 94 + Serial.begin(115200); 95 + 96 + // Connect to WiFi network 97 + Serial.println(); 98 + Serial.println(); 99 + Serial.print("Connecting to "); 100 + Serial.println(ssid); 101 + WiFi.begin(ssid, pass); 102 + 103 + while (WiFi.status() != WL_CONNECTED) { 104 + delay(500); 105 + Serial.print("."); 106 + } 107 + Serial.println(""); 108 + 109 + Serial.println("WiFi connected"); 110 + Serial.println("IP address: "); 111 + Serial.println(WiFi.localIP()); 112 + 113 + Serial.println("Starting UDP"); 114 + Udp.begin(localPort); 115 + Serial.print("Local port: "); 116 + #ifdef ESP32 117 + Serial.println(localPort); 118 + #else 119 + Serial.println(Udp.localPort()); 120 + #endif 121 + 122 + delay(20); 123 + Serial.println("Adafruit MPR121 Capacitive Touch sensor..."); 124 + // Default address is 0x5A, if tied to 3.3V its 0x5B 125 + // If tied to SDA its 0x5C and if SCL then 0x5D 126 + if (!cap.begin(0x5A)) { 127 + Serial.println("MPR121 not found, check wiring?"); 128 + while (1); 129 + } 130 + Serial.println("MPR121 found!"); 131 + } 132 + 133 + void renoise(OSCMessage &msg) { 134 + renoiseHost = msg.getInt(0); 135 + Serial.println("/set/renoise"); 136 + Serial.print("host: "); Serial.println(renoiseHost); 137 + if (msg.isInt(1)) { 138 + renoisePort = msg.getInt(1); 139 + Serial.print("port: "); 140 + Serial.println(renoisePort); 141 + } 142 + } 143 + void maxmsp(OSCMessage &msg) { 144 + maxHost = msg.getInt(0); 145 + Serial.println("/set/max"); 146 + Serial.print("host: "); Serial.println(maxHost); 147 + if (msg.isInt(1)) { 148 + maxPort = msg.getInt(1); 149 + Serial.print("port: "); 150 + Serial.println(maxPort); 151 + } 152 + } 153 + void p5(OSCMessage &msg) { 154 + p5Host = msg.getInt(0); 155 + Serial.println("/set/p5"); 156 + Serial.print("host: "); Serial.println(p5Host); 157 + if (msg.isInt(1)) { 158 + p5Port = msg.getInt(1); 159 + Serial.print("port: "); 160 + Serial.println(p5Port); 161 + } 162 + } 163 + 164 + void led(OSCMessage &msg) { 165 + ledState = msg.getInt(0); 166 + digitalWrite(BUILTIN_LED, ledState); 167 + Serial.print("/led: "); 168 + Serial.println(ledState); 169 + } 170 + 171 + void sendRenoiseNoteOn(int note, IPAddress outIp, int outPort) { 172 + OSCMessage msg("/renoise/trigger/note_on"); 173 + msg.add((int)1).add((int)1).add(note).add((int)127); 174 + Udp.beginPacket(outIp, outPort); 175 + msg.send(Udp); 176 + Udp.endPacket(); 177 + msg.empty(); 178 + } 179 + 180 + void sendPot(int sensor, IPAddress outIp, int outPort) { 181 + OSCMessage msg("/pot"); 182 + msg.add((int)sensor); 183 + Udp.beginPacket(outIp, outPort); 184 + msg.send(Udp); 185 + Udp.endPacket(); 186 + msg.empty(); 187 + } 188 + 189 + void sendRenoiseNoteOff(int note, IPAddress outIp, int outPort) { 190 + OSCMessage msg("/renoise/trigger/note_off"); 191 + msg.add((int)1).add((int)1).add(note); 192 + Udp.beginPacket(outIp, outPort); 193 + msg.send(Udp); 194 + Udp.endPacket(); 195 + msg.empty(); 196 + } 197 + 198 + void sendRenoiseEffect(float cutoff, IPAddress outIp, int outPort) { 199 + OSCMessage msg("/renoise/song/track/1/device/2/set_parameter_by_index"); 200 + msg.add(2).add((float)cutoff); 201 + Udp.beginPacket(outIp, outPort); 202 + msg.send(Udp); 203 + Udp.endPacket(); 204 + msg.empty(); 205 + } 206 + 207 + void sendPlayer(int id, char* name, IPAddress outIp, int outPort) { 208 + OSCMessage msg("/player"); 209 + msg.add(id); 210 + msg.add(name); 211 + Udp.beginPacket(outIp, outPort); 212 + msg.send(Udp); 213 + Udp.endPacket(); 214 + msg.empty(); 215 + } 216 + 217 + void loop() { 218 + 219 + IPAddress maxIp(192,168,1,maxHost); 220 + IPAddress p5Ip(192,168,1,p5Host); 221 + IPAddress renoiseIp(192,168,1,renoiseHost); 222 + 223 + currtouched = cap.touched(); 224 + 225 + // Get the currently touched pads 226 + currtouched = cap.touched(); 227 + 228 + for (uint8_t i=0; i<12; i++) { 229 + // it if *is* touched and *wasnt* touched before, alert! 230 + if ((currtouched & _BV(i)) && !(lasttouched & _BV(i)) ) { 231 + Serial.print(i); Serial.print(" "); Serial.print(players[i]); Serial.println(" touched"); 232 + sendRenoiseNoteOn(48+i, renoiseIp, renoisePort); // C2 is 36, C3 is 48, C4 is 60 233 + sendPlayer(i, players[i], p5Ip, p5Port); 234 + } 235 + // if it *was* touched and now *isnt*, alert! 236 + if (!(currtouched & _BV(i)) && (lasttouched & _BV(i)) ) { 237 + Serial.print(i); Serial.print(" "); Serial.print(players[i]); Serial.println(" released"); 238 + sendRenoiseNoteOff(48+i, renoiseIp, renoisePort); 239 + } 240 + } 241 + 242 + // reset our state 243 + lasttouched = currtouched; 244 + 245 + // fun with ReNoise 246 + // http://tutorials.renoise.com/wiki/Open_Sound_Control 247 + //int note = map(analogRead(A0),0,1024,0,119); 248 + //Serial.println(note); 249 + //sendRenoiseNoteOn(note, outIp, outPort); delay(100); 250 + //sendRenoiseNoteOff(note, outIp, outPort); //delay(1000); 251 + 252 + //int sensor = analogRead(A0); 253 + //Serial.println(sensor); 254 + //sendPot(sensor, outIp, outPort); //delay(1000); 255 + 256 + /* Receive OSC message */ 257 + OSCMessage msg; 258 + int size = Udp.parsePacket(); 259 + if (size > 0) { 260 + while (size--) { 261 + msg.fill(Udp.read()); 262 + } 263 + if (!msg.hasError()) { 264 + msg.dispatch("/led", led); 265 + msg.dispatch("/set/max", maxmsp); 266 + msg.dispatch("/set/renoise", renoise); 267 + msg.dispatch("/set/p5", p5); 268 + } else { 269 + error = msg.getError(); 270 + Serial.print("error: "); 271 + Serial.println(error); 272 + } 273 + } 274 + }
+45
README-arduino-cli.txt
··· 1 + Install arduino-cli in /usr/local/bin 2 + Then follow https://docs.arduino.cc/arduino-cli/getting-started 3 + 4 + To compile an example using the MPR121 board for Arduino UNO do this: 5 + 6 + arduino-cli config init 7 + arduino-cli core update-index 8 + arduino-cli board list 9 + arduino-cli core install arduino:avr 10 + arduino-cli core update-index 11 + arduino-cli core search esp8266 12 + vi ~/.arduino15/arduino-cli.yaml 13 + add for ESP8266 14 + board_manager: 15 + additional_urls: 16 + - https://arduino.esp8266.com/stable/package_esp8266com_index.json 17 + 18 + arduino-cli core search esp8266 --additional-urls https://arduino.esp8266.com/stable/package_esp8266com_index.json 19 + arduino-cli core update-index 20 + arduino-cli compile ESP8266OSC.ino 21 + arduino-cli core update-index 22 + arduino-cli board list 23 + cd ~/sketchbook/MPR121/ 24 + less MPR121.ino 25 + arduino-cli lib search mpr121|grep Name 26 + arduino-cli lib install "Adafruit MPR121" 27 + arduino-cli compile --fqbn arduino:avr:uno MPR121.ino 28 + arduino-cli upload -p /dev/ttyACM0 --fqbn arduino:avr:uno MPR121.ino 29 + arduino-cli monitor -p /dev/ttyACM0 30 + 31 + No let's try the ESP8266 board 32 + 33 + 561 cd ESP8266OSC 34 + 567 less ESP8266OSC.ino 35 + 581 arduino-cli core search esp8266 --additional-urls https://arduino.esp8266.com/stable/package_esp8266com_index.json 36 + 582 arduino-cli board install esp8266 37 + 596 arduino-cli core install esp8266:esp8266 38 + 607 vi ~/.arduino15/arduino-cli.yaml 39 + 608 arduino-cli core install esp8266:esp8266 --config-file ~/.arduino15/arduino-cli.yaml 40 + 611 arduino-cli board listall|grep -i nodemcu 41 + Install required libraries 42 + arduino-cli install "Adafruit MPR121" 43 + arduino-cli install "OSC" 44 + 612 arduino-cli compile --fqbn esp8266:esp8266:nodemcuv2 ESP8266OSC.ino 45 + 614 arduino-cli upload -p /dev/ttyUSB0 --fqbn esp8266:esp8266:nodemcuv2 ESP8266OSC.ino