Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By BLCKPSTV
#70424 Hey everybody,

I'm giving this yet another try. I want to send analog data wireless from my Wemos D1 mini to max msp.
I've been able to achieve this by the CNMAT-OSC library. Wel I get the messages from test that's on there github page.

What I don't get is the exact voltage reading from the piezo (the analogread that needs to be send) to max/msp.

Following is the code to sent the data.

Code: Select all/*---------------------------------------------------------------------------------------------
  Open Sound Control (OSC) library for the ESP8266/ESP32
  Example for sending messages from the ESP8266/ESP32 to a remote computer
  The example is sending "hello, osc." to the address "/test".
  This example code is in the public domain.
--------------------------------------------------------------------------------------------- */

#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <OSCMessage.h>
#include <OSCBundle.h>


char ssid[] = "lala";          // your network SSID (name)
char pass[] = "lala";                    // your network password

WiFiUDP Udp;                                // A UDP instance to let us send and receive packets over UDP
const IPAddress outIp(192,168,1,6);        // remote IP of your computer
const unsigned int outPort = 9999;          // remote port to receive OSC
const unsigned int localPort = 8888;        // local port to listen for OSC packets (actually not used for sending)

const int PIEZO_PIN =A0; //PIEZO OUTPUT

void setup() {
    Serial.begin(115200);
    pinMode(BUILTIN_LED, OUTPUT);

    // Connect to WiFi network
    Serial.println();
    Serial.println();
    Serial.print("Connecting to ");
    Serial.println(ssid);
    WiFi.begin(ssid, pass);

    while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
    }
    Serial.println("");

    Serial.println("WiFi connected");
    Serial.println("IP address: ");
    Serial.println(WiFi.localIP());

    Serial.println("Starting UDP");
    Udp.begin(localPort);
    Serial.print("Local port: ");
#ifdef ESP32
    Serial.println(localPort);
#else
    Serial.println(Udp.localPort());
#endif

}

void loop() {
    int piezoADC = analogRead(PIEZO_PIN);
    float piezoV = piezoADC / 1023.0 *5.0;
   
    OSCMessage msg("/test");
    msg.add(Serial.println(piezoV));
    Udp.beginPacket(outIp, outPort);
    msg.send(Udp);
    Udp.endPacket();
    msg.empty();
    delay(500);
}


And the responding result in max/msp is the following

https://ibb.co/daaE1G

So it get a message but not with the corresponding result I get when I tested it with arduino and the serial plotter and monitor. Which show me with this code the following data.

Code: Select all/******************************************************************************
Piezo_Vibration_Sensor.ino
Example sketch for SparkFun's Piezo Vibration Sensor
  (https://www.sparkfun.com/products/9197)
Jim Lindblom @ SparkFun Electronics
April 29, 2016

- Connect a 1Mohm resistor across the Piezo sensor's pins.
- Connect one leg of the Piezo to GND
- Connect the other leg of the piezo to A0

Vibrations on the Piezo sensor create voltags, which are sensed by the Arduino's
A0 pin. Check the serial monitor to view the voltage generated.

Development environment specifics:
Arduino 1.6.7
******************************************************************************/
const int PIEZO_PIN = A0; // Piezo output

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  // Read Piezo ADC value in, and convert it to a voltage
  int piezoADC = analogRead(PIEZO_PIN);
  float piezoV = piezoADC / 1023.0 * 5.0;
  Serial.println(piezoV); // Print the voltage.
}


https://ibb.co/jN0ggG
https://ibb.co/mZwMgG

I want these result/data to come into max/msp

Also don't think the eps could be damaged because it won't get peak voltages above the 1V, but if there is somebody that thinks otherwise please tell me!!! And or what I can do to withhold my board from breaking!! :)

Any tips for this would be very much appreciated ofcourse!