Controlling I2C BlinkM from Max/MSP

Hi all

I am inexperienced with Arduino and haven't worked with Serial objects in Max/MSP before. Here goes...

I need to control the RGB values of the I2C BlinkM (actually i need to control 5 BlinkM's, but one will do for now).

At the moment i send 4 values to the Serial object (Serial c 9600). 3 x RGB values (0-254) and '255' to imply that this is one 'set' of numbers.

In the Arduino code i pick up the numbers and sort them into an array. '255' resets the array, which is now ready for a new 'set'. With normal LEDs (analogWrite) i have no problem controlling them with the incomming integers, but i can't seem to control (or understand) the I2C BlinkM.

I have studied the BlinkM examples. They seem hard to understand and some of the examples have a different syntax (C i guess?) than the normal Arduino.

If i prepend '1,0,4,0,99' to the integer message from Max - my Max patch works fine with the BlinkM Communicator example.

My Arduino code looks like this:

#include "Wire.h"
#include "BlinkM_funcs.h"

#include <avr/pgmspace.h> // for progmem stuff

#define BLINKM_ARDUINO_POWERED 1

int serialValue; // variable for incomming values
int valArray[10]; // array for incomming values
int indexNo = 0; // index for controlling array w values

void setup(){

if(BLINKM_ARDUINO_POWERED){
BlinkM_beginWithPower();
} else {
BlinkM_begin();
}
Serial.begin(9600);
pinMode(13, OUTPUT);
}

void loop(){

while(Serial.available()>0){
serialValue = Serial.read(); // read incomming values

if(serialValue==255){ // test if end of numbers has been reached
indexNo=0; // reset index
} else {
valArray[indexNo] = serialValue; // fill array with incomming value (indexNo)
indexNo++; // push index
}

digitalWrite(13, HIGH); // check if we're in loop
BlinkM_setRGB(1,valArray[0],valArray[1],valArray[2]); // control RGB values of the BlinkM
delay(50);
}
}


Whenever i start to send actual numbers the BlinkM picks up the initial color (if i send a number to GREEN) - but only very dim and then freezes. Nothing happens after that. I can tell from the TX/RX that data is being received and from PIN 13 that we're still in the loop. But i have no control whatsoever of the BlinkM.

I use a USB powered Duamilanove Arduino board.

Every bit of help is greatly appreciated :slight_smile:

Best regards - Jakob

If i prepend '1,0,4,0,99' to the integer message from Max - my Max patch works fine with the BlinkM Communicator example.

What does this mean? It appears that you are currently sending (or, at least you think you are) 4 binary values. Putting a string in front of a set of binary values will completely change the behavior of the Arduino. Is that what you are doing?

Aah... sorry. I am prepending 5 integers ('1,0,4,0,99') as explained in the Bleything example patch. So i am not sending Strings or anything like that.