Hi, I am building a device to send OSC messages from the arduino to a device running projection mapping software (mad mapper) and have set the triggers to latch using a basic armed/disarmed variable. I would like to be able to rearm the triggers also via OSC (sent from another device TO the arduino) but as there will be multiple triggers I would like to use the OSC routing to determine which is rearmed.
I do not understand what I am doing well enough to understand the documentation for the protocol so any help would be much appreciated.
I am using the arduino ethernet shield and OSCMessage.h library.
#include <Ethernet.h>
#include <EthernetUdp.h>
#include <SPI.h>
#include <OSCMessage.h>
EthernetUDP Udp;
// Inputs
const int Trigger1 = 1; // the number of the pushbutton pin
// variables will change:
int TState1 = 0;
int T1fire = 'armed';
int reset;
//the Arduino's IP
IPAddress ip(10, 0, 0, 10);
//destination IP
IPAddress outIp(10, 0, 0, 101);
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() {
pinMode(Trigger1, INPUT);
Ethernet.begin(mac,ip);
Udp.begin(8888);
}
void loop(){
TState1 = digitalRead(Trigger1);
if ((TState1 == LOW) && (T1fire == 'armed')){
OSCMessage msg("/qlab/test");
msg.add((int32_t)analogRead(0));
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
T1fire = 'disarmed';
////rearm device code here
}
}
#include <Ethernet.h>
#include <EthernetUdp.h>
#include <SPI.h>
#include <OSCMessage.h>
EthernetUDP Udp;
// Inputs
const int T1 = 1;
const int R1 = 4; // the number of the pushbutton pin
// variables will change:
int TState1 = 0;
int T1fire = 0;
int RState1 = 0;
//the Arduino's IP
IPAddress ip(10, 0, 0, 10);
//destination IP
IPAddress outIp(10, 0, 0, 111);
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() {
pinMode(T1, INPUT);
pinMode(R1, INPUT);
pinMode(LED_BUILTIN, OUTPUT);
Ethernet.begin(mac,ip);
Udp.begin(9999);
digitalWrite(LED_BUILTIN, 0);
}
void loop(){
TState1 = digitalRead(T1);
RState1 = digitalRead(R1);
if ((TState1 == LOW) && (T1fire == 0)){
OSCMessage msg("/qlab/test");
msg.add((int32_t)analogRead(0));
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
T1fire = 1;
digitalWrite(LED_BUILTIN, 1);
delay(20);
}
if (RState1 == LOW){
T1fire = 0;
digitalWrite(LED_BUILTIN, 0);
}
////rearm device code here
}
Start off here Wikipedia OSC
And check out the reference links, this will give you lots of information about how OSC works.
I have an app running on my iPad called TouchOSC, and that allows me to send and receive OSC messages with other computers.
Here is a video for a project where I used a Raspberry Pi to send OSC messages to my iPad to implement what is in effect a child's cut out theater. Cut out theater
This was in the MagPi Magazine #57 and free downloads are available from the magazine's web site.
I used the Processing language to write the driving code, and the links to the Git Hub page that contain the software are in the article.
In my book Chapter 8 is devoted to OSC and its use with a language called "Pure Data", this is like a free open source version of Max MSP. This chapter goes into the nitty gritty of an Open Sound Control message, at a level of detail you might not wish to know. It covered the messages right down to the composition of various byte and talks about the slip protocol for sending messages.
However using the Processing language simplifies all that.
There are some Arduino OSC libraries with examples that you could look at, like ArdOSC, ArduinoOSC, microOSC and OSC. But I have not dabbled with these myself so I am not too sure how useful they will be.