Forums > MaxMSP

max/arduino mega/OSC/ethernet


ro2
October 6, 2012 | 8:53 am

hello every body
i have a project in france for au sound design interactive installation.
I want read the digital statue of 20 pins of an arduino mega by ethenet.
I found some solutions with oscbundle CNMAT.
buy impossible to write a correct arduino program .
I have make some test with one pin no problem, i read the statue on max, but impossible to read more.

can you tell me where I can found more informations

thank you


October 6, 2012 | 11:17 am

you have first to read those value and, maybe only when a value has changed in order to not flood the Max patch, then to send it using OSC.

the "Button" example is only for one input.
you’ll have to create an array to store current values
then, in loop, you’ll have to read all digital inputs using a for loop, for instance, and store values in the array or even directly send them over OSC.

a smarter way to explore, create a callback checking when a value just changed and able to fire a message only when a value has changed.

(just written this in my currently in progress Arduino Book: http://cprogrammingforarduino.com)



ro2
October 6, 2012 | 1:48 pm

my arduino programme who don’t work

/*
OSCBundles are the prefered method of using OSCMessages

*/
//////////////////////librairie/////////////////////////////////
#include
#include
#include
//////////////////////variable//////////////////////////////////
byte myMac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte myIp[] = { 192, 168, 127, 11 }; //adresse du module
int destPort=12001;//port de communication idem sur max et module
byte destIp[] = { 192, 168, 127, 10 };//adresse de l’ordinateur

//declare the bundle
OSCBundle bndl;

void setup() {

Ethernet.begin(myMac ,myIp);
}

void loop(){
//’addMessage’ and ‘add’ can be composed together
bndl.addMessage("/analog/0").add(digitalRead(2));
bndl.addMessage("/analog/1").add(digitalRead(3));
bndl.send();

delay(50);

}



ro2
October 6, 2012 | 4:45 pm

this one run but only for one digital input , I want more 30
I use an other library ardOSD (but no support)
thank you

#include
#include
#include

byte myMac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte myIp[] = { 192, 168, 127, 11 }; //adresse du module
int destPort=12001;//port de communication idem sur max et module
byte destIp[] = { 192, 168, 127, 10 };//adresse de l’ordinateur

long int inputNumber = 0;
long int inputValue = 0;
OSCClient client;

//create new osc message
OSCMessage global_mes;

void setup(){

Ethernet.begin(myMac ,myIp);
// initialize the pushbutton pin as an input:

pinMode(2, INPUT);

}

void loop(){
//////etat des entres numerique//////
inputNumber = 2;
inputValue = digitalRead(inputNumber);//etat de l’entrée 2
global_mes.setAddress(destIp,destPort);
global_mes.beginMessage("/ard/digi1");
global_mes.addArgInt32(inputValue);
client.send(&global_mes);
global_mes.flush(); //object data clear

delay(50);

}


October 6, 2012 | 5:10 pm

I see the SPI lib.
I don’t know why you need this, btw.

about a code for reading more than one input, without using shift registers (i.e direct connection of your sensor/source to the digital inputs):

const int firstPin = 2;         // first digital input
const int inputNumber = 10;     // number of inputs

int digitalStates[inputNumber];

void setup() {
  // configure all your inputs
  for(int i = firstPin ; i < inputNumber + firstPin ; i++)
  {
    pinMode(i, INPUT);
  }
}

void loop(){

  for(int i = firstPin ; i < inputNumber + firstPin ; i++)
  {
    int currentPinState = digitalRead(i);
    if ( currentPinState != digitalStates[i] )
    {
      digitalStates[i] = currentPinState;

      // add here the code to send the new value to Ethernet port over OSC
    }

  }
}

Viewing 5 posts - 1 through 5 (of 5 total)