Hello all!
I have started with transferring the data from Arduino to the Processing, actually to draw, internally on mac.
I have started with the examples, however, I cannot get the basic stuff working.
For example, I am using the OSC/README.md at master · CNMAT/OSC · GitHub
Arduino library, and the oscP5 for processing.
Started with a simple send/receive the msg. For example, I want to send the msg from the Arduino -> Processing, wondering, why does this not do anything?
Arduino code:
/*
Make an OSC message and send it over UDP
Adrian Freed
*/
#include <SPI.h>
#include <Ethernet.h>
#include <EthernetUdp.h>
#include <OSCMessage.h>
EthernetUDP Udp;
//the Arduino's IP
IPAddress ip(128, 32, 122, 252);
//destination IP
IPAddress outIp(128, 32, 122, 125);
const unsigned int outPort = 9999;
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // you can find this written on the board of some Arduino Ethernets or shields
void setup() {
Serial.begin(115200);
Ethernet.begin(mac,ip);
Udp.begin(8888);
}
void loop(){
//the message wants an OSC address as first argument
OSCMessage msg("/analog/0");
//msg.add((intOSC_t)analogRead(0));
int randNumber = random(1, 20);
msg.add((intOSC_t)randNumber);
Udp.beginPacket(outIp, outPort);
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
delay(20);
}
Processing code:
/*
Receives and visualizes OSCBundles sent over UDP
Use with /examples/UDPSendMessage
or with /examples/SerialSendMessage in conjunction
with /Applications/Processing/SLIPSerialToUDP
*/
import oscP5.*;
import netP5.*;
OscP5 oscP5;
void setup() {
size(150,300);
frameRate(30);
//set this to the receiving port
oscP5 = new OscP5(this,9001);
}
void draw() {
background(0);
//draw the analog values
float analog0Height = map(analogValue0, 0, 1024, 0, 200);
fill(255);
rect(50, 250, 50, -analog0Height);
//and the labels
textSize(12);
text("/analog/0", 50, 270);
}
int analogValue0 = 50;
// incoming osc message are forwarded to the oscEvent method.
void oscEvent(OscMessage theOscMessage) {
//println(theOscMessage.addrPattern());
if (theOscMessage.addrPattern().equals("/analog/0")){
analogValue0 = theOscMessage.get(0).intValue();
}
}
Any ideas, comments are more than welcome!
Best.