Max/msp to Arduino to Solenoïds

hi all,

this is my first post on this forum.

i want to drive 16 solenoids from max/msp using an arduino card.

i found a lot of really useful informations on the playground: i know about the shift registers to extend the number of digital outputs, and i found a good schematic to drive solenoids without frying the arduino (and my macbook).

the only thing that i can't figure out, as i'm a total noob in programming, is how i can get data from max/msp into the arduino, and transform those datas into simple triggers on the digital I/o of the arduino.

i have to use Simple Message System right ?

but i'd like to have an idea of what the code should be like.

does someone have an idea ?

:slight_smile:

This sounds like an extension of my MIDI Glockenspiel project:-

http://www.thebox.myzen.co.uk/Hardware/Glockenspiel.html

That only has 8 solenoids. The software is available for download if you want a look.

So you could use MIDI protocol from MAX to fire the solenoids.

You could also just send 2 bytes of data (one bit per solenoid) from max/msp to the arduino, using the serial object.
In you arduino sketch, you read the serial port, see which bit is at 1 and trigger the right solenoid.

You could also just send 2 bytes of data (one bit per solenoid) from max/msp to the arduino, using the serial object.
In you arduino sketch, you read the serial port, see which bit is at 1 and trigger the right solenoid.

Yes good point. :slight_smile:

But I would use a bit of a protocol to stop the bytes being mixed up. That is, start with a unique header (this rules out using only two bytes for the data) followed by say four bytes with a nibbles worth in each. That way you can synchronises the data between transmitter and receiver.

For example the header could be 0x02 and the following four bytes could be 0x3n where n is four bits corresponding to four solenoids.

I'm no good with all those protocols stuff. What are the risks of having f***ed up datas without headers, by (for exemple) just using the Serial.available() command in arduino and assuming that both max/msp and the arduino run at 9600bps ? From where might the problem come... ?

From where might the problem come... ?

In any data transmission system a byte might become corrupted or lost.
Interference, interrupts, faulty connections, the glitches when one program starts up and the serial levels stables at their proper state. Information theory says it will happen.

If this happens then there will be a loss of synchronization between the transmitter and receiver, and you will find the wrong solenoids being activated.

It will at some time happen, but if you can stand it then don't bother, but you are asking for trouble.

thanks for the answers.

your midi glockenspiel is really inspiring.

i still have a lot of work to figure out the code, but thank you very much !