OSC in Arduino: Unterschied zwischen den Versionen

Aus hyperdramatik
Zur Navigation springen Zur Suche springen
 
(2 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 1: Zeile 1:
Example for sending data from an Arduino ESP Dev Module to COMPUTER in the same network with OSC.


==DOWNLOAD OSCuino LIBRARY==
=Installing the OSCuino Library=
 
==Download  Library==
Download OSCuino library from github: https://github.com/CNMAT/OSC
Download OSCuino library from github: https://github.com/CNMAT/OSC
Code –> Download ZIP
Code –> Download ZIP


==INSTALL OSCuino LIBRARY==
==Install Library==
Arduino Menu: Sketch –> Include Library –> Add .ZIP Library
Arduino Menu: Sketch –> Include Library –> Add .ZIP Library
select .ZIP file
select .ZIP file


==OPEN CODE EXAMPLE==
=Code Example=
 
<source lang="js" line start="2" highlight="4-6">
/////////////////////////////////////////////////
// Code for
// ESP32 DEVKIT V1 38pin version
/////////////////////////////////////////////////
// reads an analog value and sends it as OSC message
/////////////////////////////////////////////////
// when uploading code: sometimes necessairy
// to presss&hold the "BOOT" button
// when you see the following lines:
// "Connecting........_____....._____....."
/////////////////////////////////////////////////
 
#include <WiFi.h>
#include <WiFiUdp.h>
#include <OSCBundle.h>
 
#define SENSOR_PIN_1 36
 
 
// OSC-Stuff ----------------------------------------------------------
 
///////////////////// VARIABLES TO EDIT /////////////////////////////
IPAddress outIp = {192, 168, 236, 90};  // IP Adress of Receiver PC
const char *ssid = "Ladenlokal";  // wifi name
const char *password = "puppe2010";  // wifi password (min. 8 characters)
const char *hostName = "myName";  // choose a name for your device
const char *oscAddress = "/myAddress/mySubAddress";  // choose an OSC address for sending your messages to
int sendFrequencyMillis = 40; // send new OSC message every somany milliseconds
/////////////////////////////////////////////////////////////////////
 
WiFiUDP Udp;
const unsigned int localPort = 9000; // not needed
const unsigned int destPort = 6448;
 
float s1; // variablee for storing sensor value
unsigned long millisOld;  // variable for keeping track of time passed
 
 
void setup() {
  Serial.begin(115200); // begin serial connection
 
  WiFi.setHostname(hostName);
  WiFi.mode(WIFI_STA); // WiFi mode station (connect to wifi router only)
  WiFi.begin(ssid, password); // begin wifi connection
 
  // Wait for connection:
  uint16_t timeOut = 0;
  while ((WiFi.status() != WL_CONNECTED) && (timeOut < 10)) {
    delay(500);
    timeOut++;
    Serial.println(timeOut);
  }
 
  Serial.print("local IP address: ");
  Serial.println(WiFi.localIP());
 
  Udp.begin(localPort);
 
  Serial.print("Listening at port: ");
  Serial.println(localPort);
}
 
 
void loop() {
  s1 = analogRead(SENSOR_PIN_1);  // read sensor value
 
  if (millis() >= (millisOld + sendFrequencyMillis)) {
    millisOld = millis();  // update millisOld to be able to keep track of time
   
    Serial.println(s1);  // print sensor value
 
    // publish sensor value over OSC:
    if (WiFi.status() == WL_CONNECTED)
    {
      OSCMessage msg(oscAddress);
      msg.add(s1);
 
      Udp.beginPacket(outIp, destPort);
      msg.send(Udp);
      Udp.endPacket();
      msg.empty();
    }
  }
}
</source>
 
==UPLOAD SKETCH==
 
Tip: sometimes you need to press and hold the BOOT button on the ESP while the Arduino IDE is trying to program.


“Hard resetting via RTS pin…” means the upload was successful
see: http://hyperdramatik.net/mediawiki/index.php?title=OSC_between_Arduino_and_Processing

Aktuelle Version vom 5. Mai 2022, 10:55 Uhr

Installing the OSCuino Library

Download Library

Download OSCuino library from github: https://github.com/CNMAT/OSC Code –> Download ZIP

Install Library

Arduino Menu: Sketch –> Include Library –> Add .ZIP Library select .ZIP file

Code Example

see: http://hyperdramatik.net/mediawiki/index.php?title=OSC_between_Arduino_and_Processing