Skip to content

Commit 251b9ce

Browse files
committed
added OSCuino library example to arduino-osc
1 parent 3359ecd commit 251b9ce

File tree

4 files changed

+262
-9
lines changed

4 files changed

+262
-9
lines changed

arduino-osc/.DS_Store

0 Bytes
Binary file not shown.

arduino-osc/OSC_ethernet_fixedIP/OSC_ethernet_fixedIP.ino

+33-6
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x0B, 0xCE }; //physical mac address
2525
//the IP address for the shield:
2626
byte ip[] = { 192, 168, 1, 177 };
2727

28+
byte destIp[] = { 192, 168, 1, 5 };
29+
30+
2831
OSCServer server;
2932
OSCClient client;
3033

@@ -35,8 +38,9 @@ int flag=0;
3538

3639
void setup(){
3740

38-
pinMode(2, OUTPUT);
41+
// pinMode(2, OUTPUT);
3942
Serial.begin(9600);
43+
delay(10);
4044
Serial.println("DNS and DHCP-based OSC server");
4145
// start the Ethernet connection:
4246
Ethernet.begin(mac, ip);
@@ -62,7 +66,7 @@ void setup(){
6266

6367
void loop(){
6468

65-
if(server.aviableCheck()>0){
69+
if(server.availableCheck()>0){
6670
// Serial.println("alive! ");
6771
}
6872
}
@@ -102,20 +106,37 @@ void funcOnOff(OSCMessage *_mes){
102106
//When the button on the TouchOSC inteface is pressed, a message is sent from the iDevice
103107
//to the Arduino to switch (togle) the LED on the Arduino on/off
104108
//then a messeage is sent bak from the Arduino to the iDevice to toggle the buttom on/off
105-
109+
////////////////////////////////////////////
110+
/////////////////////////
111+
////////
112+
//
106113
void funcFader(OSCMessage *_mes){
107114
float value = _mes->getArgFloat(0); //TouchOSC expects float values
108115

109116
//create new osc message
110117
OSCMessage newMes;
118+
119+
// print out the return address (ie., sender )
120+
for (byte thisByte = 0; thisByte < 4; thisByte++) {
121+
// print the value of each byte of the IP address:
122+
Serial.print(_mes->getIpAddress()[thisByte], DEC);
123+
Serial.print(".");
124+
}
125+
126+
Serial.println(" ");
111127

112128
//set destination ip address & port no
129+
130+
// newMes.setAddress(ipDest ,destPort);
113131
newMes.setAddress(_mes->getIpAddress(),destPort);
132+
133+
// format the message
134+
114135
newMes.beginMessage("/1/fader1");
115136

116-
Serial.println(value);
117-
int ledValue = value * 255.0;
118-
analogWrite(ledPin, ledValue);
137+
Serial.println(value);
138+
int ledValue = value * 255.0;
139+
analogWrite(ledPin, ledValue);
119140

120141

121142
newMes.addArgFloat(value);
@@ -124,5 +145,11 @@ void funcFader(OSCMessage *_mes){
124145
//
125146
// turn local feedback off on touch-osc control to test this
126147
client.send(&newMes);
148+
// newMes.flush(); //object data clear
149+
150+
127151

128152
}
153+
154+
155+

arduino-osc/OSCuino_tz/OSCuino_tz.ino

+160
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
// OSCuino version of
2+
//
3+
// generic Arduino OSC program
4+
// works from Max or touchOSC
5+
//
6+
// plug LED into pin 5 (and gnd)
7+
//
8+
// requires ethernet shield
9+
//
10+
// use serial monitor to get the ip address
11+
//
12+
// use these OSC commands (will work from first page of touchOSC simple layout
13+
//
14+
// /1/fader1
15+
// /1/toggle1
16+
//
17+
18+
// this version uses a fixed ip address instead of DHCP
19+
//
20+
//
21+
//
22+
// THis code was derived from work by Trippylightning at
23+
// http://trippylighting.com/teensy-arduino-ect/touchosc-and-arduino-oscuino/
24+
//
25+
//DHCP-based OSC server test code
26+
//for use with IDE 1.0.5
27+
//for use with W5100 or W5200 based ethernet shields
28+
29+
#include <SPI.h>
30+
#include <Ethernet.h>
31+
#include <EthernetUdp.h>
32+
#include <OSCBundle.h>
33+
34+
35+
IPAddress outIp(192, 168, 1, 5);
36+
// you can find this written on the board of some Arduino Ethernets or shields
37+
byte mac[] = {
38+
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
39+
40+
// NOTE: Alternatively, you can assign a fixed IP to configure your
41+
// Ethernet shield.
42+
byte ip[] = { 192, 168, 1, 177 };
43+
44+
45+
int serverPort = 8000; //TouchOSC (incoming port)
46+
int destPort = 9000; //TouchOSC (outgoing port)
47+
int ledPin = 5; //pin 13 on Arduino Uno. Pin 6 on a Teensy++2
48+
int ledState = LOW;
49+
float msgfloat = 0.0; // for testing
50+
51+
52+
//Create UDP message object
53+
EthernetUDP Udp;
54+
55+
void setup(){
56+
57+
pinMode(ledPin, OUTPUT);
58+
59+
Serial.begin(9600); //9600 for a "normal" Arduino board (Uno for example). 115200 for a Teensy ++2
60+
Serial.println("OSC test");
61+
62+
// start the Ethernet connection:
63+
// NOTE: Alternatively, you can assign a fixed IP to configure your
64+
// Ethernet shield.
65+
Ethernet.begin(mac, ip);
66+
67+
// print your local IP address:
68+
Serial.print("Arduino IP address: ");
69+
for (byte thisByte = 0; thisByte < 4; thisByte++) {
70+
// print the value of each byte of the IP address:
71+
Serial.print(Ethernet.localIP()[thisByte], DEC);
72+
Serial.print(".");
73+
}
74+
75+
Udp.begin(serverPort);
76+
}
77+
78+
void loop(){
79+
//process received messages
80+
OSCMsgReceive();
81+
}
82+
83+
void OSCMsgReceive(){
84+
OSCMessage msgIN;
85+
int size;
86+
if((size = Udp.parsePacket())>0){
87+
while(size--)
88+
msgIN.fill(Udp.read());
89+
if(!msgIN.hasError()){
90+
msgIN.route("/1/toggle1",toggleOnOff);
91+
msgIN.route("/1/fader1",funcValue);
92+
}
93+
}
94+
}
95+
96+
/////////////////////////////////////////////
97+
//
98+
//
99+
//
100+
//
101+
void toggleOnOff(OSCMessage &msg, int addrOffset){
102+
103+
Serial.println("toggleOnOff");
104+
// Serial.print("addrOffset: ");
105+
// Serial.println(addrOffset);
106+
107+
msgfloat = msg.getFloat(0);
108+
Serial.print("togglevalue: ");
109+
Serial.println(msgfloat);
110+
111+
ledState = (int) msg.getFloat(0);
112+
113+
if (ledState) {
114+
Serial.println("LED on");
115+
digitalWrite(ledPin, HIGH);
116+
}
117+
else {
118+
Serial.println("LED off");
119+
digitalWrite(ledPin, LOW);
120+
}
121+
122+
// construct outgoing message....
123+
124+
OSCMessage msgOUT("/1/toggle1");
125+
126+
msgOUT.add(msgfloat);
127+
128+
129+
// Udp.beginPacket(outIp, destPort);
130+
Udp.beginPacket(Udp.remoteIP(), destPort);
131+
msgOUT.send(Udp); // send the bytes
132+
133+
Udp.endPacket(); // mark the end of the OSC Packet
134+
msgOUT.empty(); // free space occupied by message
135+
}
136+
/////////////////////////////////////////
137+
//
138+
//
139+
void funcValue(OSCMessage &msg, int addrOffset ){
140+
141+
float value = msg.getFloat(0);
142+
int ledValue = value * 255.0;
143+
144+
analogWrite(ledPin, ledValue);
145+
146+
Serial.print("fader value: ");
147+
Serial.println(value);
148+
149+
OSCMessage msgOUT("/1/fader1");
150+
msgOUT.add(value);
151+
152+
Udp.beginPacket(Udp.remoteIP(), destPort);
153+
msgOUT.send(Udp); // send the bytes
154+
Udp.endPacket(); // mark the end of the OSC Packet
155+
msgOUT.empty(); // free space occupied by message
156+
}
157+
158+
159+
160+

arduino-osc/arduino-osc-ethernet1.maxpat

+69-3
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
"appversion" : {
55
"major" : 6,
66
"minor" : 1,
7-
"revision" : 7,
7+
"revision" : 10,
88
"architecture" : "x86"
99
}
1010
,
11-
"rect" : [ 25.0, 69.0, 514.0, 343.0 ],
11+
"rect" : [ 25.0, 69.0, 592.0, 355.0 ],
1212
"bglocked" : 0,
1313
"openinpresentation" : 0,
1414
"default_fontsize" : 12.0,
@@ -28,6 +28,45 @@
2828
"digest" : "",
2929
"tags" : "",
3030
"boxes" : [ {
31+
"box" : {
32+
"fontname" : "Arial",
33+
"fontsize" : 12.0,
34+
"id" : "obj-8",
35+
"maxclass" : "message",
36+
"numinlets" : 2,
37+
"numoutlets" : 1,
38+
"outlettype" : [ "" ],
39+
"patching_rect" : [ 519.0, 172.0, 32.5, 18.0 ],
40+
"text" : "_"
41+
}
42+
43+
}
44+
, {
45+
"box" : {
46+
"fontname" : "Arial",
47+
"fontsize" : 12.0,
48+
"id" : "obj-12",
49+
"maxclass" : "message",
50+
"numinlets" : 2,
51+
"numoutlets" : 1,
52+
"outlettype" : [ "" ],
53+
"patching_rect" : [ 428.0, 212.0, 110.0, 18.0 ],
54+
"text" : "/1/fader1 0.519685"
55+
}
56+
57+
}
58+
, {
59+
"box" : {
60+
"id" : "obj-7",
61+
"maxclass" : "button",
62+
"numinlets" : 1,
63+
"numoutlets" : 1,
64+
"outlettype" : [ "bang" ],
65+
"patching_rect" : [ 380.0, 212.0, 20.0, 20.0 ]
66+
}
67+
68+
}
69+
, {
3170
"box" : {
3271
"fontname" : "Arial",
3372
"fontsize" : 12.0,
@@ -259,7 +298,7 @@
259298
"numinlets" : 1,
260299
"numoutlets" : 0,
261300
"patching_rect" : [ 225.0, 111.0, 167.0, 20.0 ],
262-
"text" : "udpsend 192.168.1.122 8000"
301+
"text" : "udpsend 192.168.1.177 8000"
263302
}
264303

265304
}
@@ -279,13 +318,31 @@
279318
}
280319
],
281320
"lines" : [ {
321+
"patchline" : {
322+
"destination" : [ "obj-12", 1 ],
323+
"disabled" : 0,
324+
"hidden" : 0,
325+
"source" : [ "obj-1", 0 ]
326+
}
327+
328+
}
329+
, {
282330
"patchline" : {
283331
"destination" : [ "obj-17", 0 ],
284332
"disabled" : 0,
285333
"hidden" : 0,
286334
"source" : [ "obj-1", 0 ]
287335
}
288336

337+
}
338+
, {
339+
"patchline" : {
340+
"destination" : [ "obj-7", 0 ],
341+
"disabled" : 0,
342+
"hidden" : 0,
343+
"source" : [ "obj-1", 0 ]
344+
}
345+
289346
}
290347
, {
291348
"patchline" : {
@@ -376,6 +433,15 @@
376433
"source" : [ "obj-6", 0 ]
377434
}
378435

436+
}
437+
, {
438+
"patchline" : {
439+
"destination" : [ "obj-12", 1 ],
440+
"disabled" : 0,
441+
"hidden" : 0,
442+
"source" : [ "obj-8", 0 ]
443+
}
444+
379445
}
380446
, {
381447
"patchline" : {

0 commit comments

Comments
 (0)