Forums > MaxMSP

Problem running SensorBox firmware on Lilypad Arduino

July 27, 2012 | 4:34 am

Hello,

I’m trying to get my Lilypad arduino to send serial data to a Max/MSP patch using the SensorBox Firmware developed by Andrew Benson [url]http://cycling74.com/toolbox/sensorbox/[/url]. I uploaded the sketch to my arduino but I’m getting a constant green light on it and the nothing happens when I try to run the Max Patch. My circuit consists of a sensor attached to AO, a 10k resistor connected to AO and ground, Rx and Tx connected to Tx and Rx on the LilyPad XBee breakout Board, 3.3vpower and ground are connected to same on the XBee breakout board and a 3.7v LiPo battery connect to the XBee breakout Board via the lilypower board.

The circuit works beautifully when I run other arduino code so I’m not sure why I’m having a problem. I have tried adjusting the baud rate, with no effect and I have removed the radios and battery and tried running the program through the FTDI, again with no success. Is there something in the arduino code that is causing my circuit to malfunction? Any help would be appreciated. Here is the SensorBox firmware and I have attached the SensorBox max patch:

// Code for Getting all the Arduino inputs into MaxMSP
//Andrew Benson
//http://pixlpa.com

char analogValue[12];//array of analog values
char current=0;//current position of analog value in array
int digVal;//digital pins bits are packed into a single variable
char imask = 128;//index bytes start with 1
char theEnd = 255;//byte to signal message end to Max patch

void setup(void) {
  Serial.begin(57600);
  digVal=0;
  for (int i = 2;i<14;i++){
    digitalWrite(i,HIGH);//enable pullups
  }
  while (establishContact()==0){delay(100);}  //wait for 99 byte
}

//uses serial.write() to avoid needless symbol creation in MaxMSP
void loop() {
  digVal=0; //reset digital value to 0
  //read digital pins
  for (int i = 0;i<11;i++){
     digVal |= (digitalRead(i+2)< >7);
  Serial.write(theEnd);//ends digital message
}

//read an analog pin and then pack into low/high bytes
void packValue(int index) {
      int tempA = analogRead(index);
      analogValue[current]=tempA & 127;
      current++;
      analogValue[current] = (tempA>>7);
      current++;
}

char establishContact(void){
    if (Serial.available() > 0) {
      char checkup = Serial.read();
      if (checkup==99) return 1;
      else return 0;
    }
    else return 0;
}
Attachments:
  1. SensorBoxAB.maxpat

July 27, 2012 | 11:22 am

I forgot to mention that the Arduino serial monitor is bland and not reading any data.


July 27, 2012 | 10:10 pm

Not sure if you noticed this, but the SensorBox firmware won’t send anything unless you send the number "99" to the arduino. Otherwise, make sure the serial port is connected and the firmware is properly compiled and installed. I have never tested on a LilyPad.


July 29, 2012 | 6:16 am

I’m glad it works.

I don’t know how much of an issue speed is for this patch/project
but if you suspect that you may need to read the digital pins on the Arduino faster,

this loop

for (int i = 0;i<11;i++){
digVal |= (digitalRead(i+2)< }

can be replaced with one instruction to read an 8 bit port all at once.
In this case- it would require two instructions, because you’re reading 11 bits.

Direct port reads & writes are much faster than digitalRead() & digitalWrite().


August 6, 2012 | 1:08 pm

Thank you Andrew and Cappy for your feedback. Everything is working great now.


August 8, 2012 | 11:22 pm

@cappy that’s true, but not as easily portable. If you are always using Arduino boards based on the same chip, PORT reads are definitely more efficient. But with this sort of application the bottleneck is typically the serial communication and the Max message processing, not the pin-reading instructions, in my experience.


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