Wireless communication with Arduino – Part 3

One of the Firefly devs actually responded to my earlier question and said I didn’t need the Firefly firmata on the Arduino if I was only using the Firefly serial read/write components. For now, this works, but I wonder if I will need to output data from Grasshopper to the Arduino at some point in the future. Possibly not, if the Arduino at the base station is only acting as an interface to the XBee coordinator radio. I will have to look into this.

XBee_3
The flex sensor as a wireless sensor. The wires going to the wireless sensor is only for power as I didn’t have a battery pack.
I used the following code to read the incoming serial data from the wireless sensor node:
void setup() {
  Serial.begin(9600);
}
void loop() {
  //make sure everything we need is in the buffer
  if (Serial.available() >= 21) {
    //look for the start byte
    if (Serial.read() == 0x7E) {
      //discard some bytes that we’re not using
      for (int i = 1; i < 19; i++) {
        byte discardByte = Serial.read();
      }
      //grab the two bytes that make up the analog value from the wireless sensor
      int analogMSB = Serial.read();
      int analogLSB = Serial.read();
      //convert to decimal to create the analog reading
      int analogReading = analogLSB + (analogMSB * 256);
      Serial.println(analogReading);
    }
  }
}
The following graphic shows how the data was used to create a concept of a hallway with moving walls. By using the inverse of the sensor data, I was able to work with two sets of data so that the walls of the hallway would react with each other. Eventually, I would like to introduce a second wireless sensor as another data source.
flexSensorToSurface_Day5_grasshopper
The result is shown below. As the flex sensor is bent, one wall extends outwards while the other recedes.
flexSensorToSurface_Day5_1flexSensorToSurface_Day5_2flexSensorToSurface_Day5_3

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s