Digital switch issues using Sensorbox + Xbee


    Nov 10 2011 | 6:01 am
    I have a circuit and a patch that I've been using on and off for a performance project for the past year. I just recently rewired the circuit for increased durability, and I'm suddenly experiencing a problem I've never encountered before. For the record, I'm using Max 5 on OS 10.6.7 on a MacBook Pro.
    My circuit contains a Lilypad Arduino with 6 digital switches, and that is attached to a Lilypad Xbee that wirelessly sends serial data to Max. In Max I'm using Sensorbox to read the data, which is then processed as audio in various ways.
    The issue I'm having is that now after I poll the serial port and receive connection, all of my digital switches are activated all at once, and they do not respond to opening or closing the physical switches. I've looked through my circuit many times and cannot find any wrong wiring or short circuits.
    My Lilypad is loaded with the Arduino code that Andrew provides with Sensorbox with a slight modification of a 9600 baud rate:
    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(9600);
    digVal=0;
    for (int i = 2;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() {
    if (Serial.available() >= 21) {
    if (Serial.read() == 0x7E) {
    for (int i = 0; i byte discard = Serial.read();
    }
    }
    digVal=0; //reset digital value to 0
    //read digital pins
    for (int i = 0;i digVal |= (digitalRead(i+2)< }
    }
    //read analog pins
    for (int g = 0;g packValue(g);
    }
    char total = current+1;
    sendOFF(total);//send everything to Max
    current=0;//reset analog value counter
    delay(10);//wait 10 milliseconds
    //see if someone tried to turn us off:
    if(establishContact()==1) {
    while(establishContact()==0) {delay(100);}//go into idle mode
    }
    }
    void sendOFF(char total){
    //Send analog values in the format 0x81 a1 a2.....0xFF
    Serial.write(imask|1);
    for (int i = 0;i Serial.write(analogValue[i]);
    }
    Serial.write(theEnd);//ends analog stream
    Serial.write((imask|2));
    Serial.write((digVal&127));
    Serial.write(digVal>>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;
    }
    My patch is here:
    I know you cannot fully reproduce this error without my circuit, but I'm wondering if there's some glaring error here that I'm overlooking. Thanks in advance.

    • Nov 10 2011 | 11:34 am
      Is it a pullup/pulldown resistor wiring/code error perhaps?
      What did you do to rewire stuff for 'increased durability'?
    • Nov 10 2011 | 2:33 pm
      I was wondering about the resistors, too, but the circuit and the Arduino code did not change. All I did was replace some wires that had been starting to come loose due to wear and tear in the performance. If I was pulling up where I should be pulling down, wouldn't the switches still respond, just in the opposite manner?
      Also, I should have mentioned I"m using Series 1 Xbees, and they are properly paired.
    • Nov 10 2011 | 4:42 pm
      It would be good to verify that your switches are wired to ground, and that there are no short circuits. The pullup-resistors are set to ON in the code, so there is no need for pullup/pulldown. Have you verified that the serial communication is functioning?
      A.