OSC Problem
in
Integration and Hardware
•
1 year ago
Hello,
I'm having a problem sending OSC messages to Max using the OSCP5 library. Here's my program. Basically, I'm getting values from the arduino and I want to print those values to Max but when I print the "analogInputMessage", I get something like this - "null:0 | /analog/0 i, null:0 | /analog/1 i, null:0 | /analog/2 i" as the value. I know that I'm getting values from the arduino perfectly fine. I can't figure out what is wrong. Why are the values null? Why isn't it adding them? Also, the oscEvent function isn't tripped when I run the program. It looks like it isn't sending anything. If you could help that would be much appreciated.
- import processing.serial.*; // import the Processing serial library
- import cc.arduino.*;
- import oscP5.*;
- import netP5.*;
- OscP5 oscP5;
- NetAddress myRemoteLocation;
- Serial myPort;
- Arduino arduino;
- int incomingPort = 12000;
- int outgoingPort = 12001;
- String ipAddress = "127.0.0.1";
- int [] analogInputData = new int [3];
- int r = 0;
- int g = 0;
- int b = 0;
- int [] data = new int [3];
- int [] channelData = new int [3];
- float ellipseRed, ellipseGreen, ellipseBlue;
- void setup() {
- size(1000, 1000);
- oscP5 = new OscP5(this, incomingPort);
- myRemoteLocation = new NetAddress(ipAddress, outgoingPort);
- arduino = new Arduino(this, Arduino.list()[0], 57000);
- for (int i = 0; i < 3; i++) {
- analogInputData[i] = 0;
- data[i] = 0;
- channelData[i] = 0;
- }
- }
- void draw() {
- loadPixels();
- for (int i = 0; i < 1000*1000; i+=10) {
- for (int j = 0; j < 3; j++) {
- analogInputData[j] = arduino.analogRead(j);
- if (j == 0) {
- r = int(map(analogInputData[j], 62, 675, 0, 255));
- }
- else if (j == 1) {
- g = int(map(analogInputData[j], 62, 675, 0, 255));
- }
- else if (j == 2) {
- b = int(map(analogInputData[j], 62, 675, 0, 255));
- }
- OscMessage analogInputMessage = new OscMessage("/analog/"+j);
- analogInputMessage.add(analogInputData[j]);
- oscP5.send(analogInputMessage, myRemoteLocation);
- print(analogInputMessage + ", ");
- }
- pixels[i] = color(r, g, b);
- println(i);
- if (i < (1000*1000)-10) {
- for (int k = 0; k < 10; k++) {
- pixels[i+k] = color(pixels[i]);
- }
- if (color(pixels[i]) == color(pixels[i+1])) {
- pixels[i] = pixels [int(random(i))];
- }
- }
- }
- updatePixels();
- }
- //void oscEvent(OscMessage theOscMessage)
- //{
- // for (int i = 0; i < 3; i++) {
- // data[i] = theOscMessage.get(i).intValue();
- // channelData[i] = data[i];
- // }
- //
- // // print out the message
- // print("OSC Message Recieved: ");
- // print(theOscMessage.addrPattern() + " ");
- // println(channelData[0] + " " + channelData[1] + " " + channelData[2]);
- //}
- /* incoming osc message are forwarded to the oscEvent method. */
- void oscEvent(OscMessage theOscMessage) {
- /* print the address pattern and the typetag of the received OscMessage */
- print("### received an osc message.");
- print(" addrpattern: "+theOscMessage.addrPattern());
- println(" typetag: "+theOscMessage.typetag());
- }
1