Transfering data from 5 accelerometers from an Lilypad to Processing, and visualize it in animation (and maybe sound)
in
Integration and Hardware
•
5 months ago
Hi, we are three students working on an interactive cloth that is containing an lilypad and 5 accelerometers (only z-values) which is connected to an MacBook Pro with an USB.
It would be very helpfull if you could produce a string of code (maybe for both Arduino and Processing) we can use to get the numbers from the 5 accelerometers to Processing so I can use the values to move 5 different objects up and down according to the physical movement.
So far we have numbers coming from the Arduino circuit board to the Arduino software, reading the position of Z. However, we want the numbers to appear in Processing and are having difficulties doing so. We also want to know how to use this information to animate some jumping characters.
It is good to know that we have taken a lot of resources from a project called NAMA by
Luiz Zanotello found on this address:
http://www.viraseres.com/nama/
The working code on the Arduino look like this:
- ///////////////////////////////////////////////////////////////
- // Nama Project v1.0
- // Instrument Arduino code.
- // ------------------------------------------------------------
- // Created by Luiz Zanotello on May/2012.
- // Under Creative Commons License: CC BY-NC-SA 3.0.
- // More information at: http://www.viraseres.com/nama
- ///////////////////////////////////////////////////////////////
- //purple
- ////////////////////////////////////
- const int a1pinV = 9; //output current pin
- const int a1pinZ = A2; //data pin
- //yellow
- /////////////////////////////////
- const int a2pinV = 9; //output current pi
- const int a2pinZ = A3; //data pin
- //pink
- ////////////////////////////////
- const int a3pinV = 9; //output current pi
- const int a3pinZ = A4; //data pin
- //orange
- ///////////////////////////////////
- const int a4pinV = 9; //output current pi
- const int a4pinZ = A5; //data pin
- //green
- ///////////////////////////////////
- //const int a4pinV = 3; //output current pi
- //const int a4pinZ = 9; //data pin
- ////////////////////////////////////////////////////////
- void setup()
- {
- //Begin serial transmition:
- Serial.begin(4800);
- //Set output pins (+ current):
- pinMode(a1pinV, OUTPUT);
- digitalWrite(a1pinV, HIGH);
- pinMode(a2pinV, OUTPUT);
- digitalWrite(a2pinV, HIGH);
- pinMode(a3pinV, OUTPUT);
- digitalWrite(a3pinV, HIGH);
- pinMode(a4pinV, OUTPUT);
- digitalWrite(a4pinV, HIGH);
- }
- ////////////////////////////////////////////////////////
- void loop()
- {
- // Printing analog data received from accelerometers
- Serial.println();
- Serial.print(4); // Number of accelerometers
- Serial.print(',');
- // Serial.print(analogRead(a4pinZ)); // Accelerometer 1 reading (z)
- Serial.print(',');
- Serial.print(analogRead(a2pinZ)); // Accelerometer Yellow reading
- Serial.print(',');
- Serial.print(analogRead(a3pinZ)); // Accelerometer Green reading
- Serial.print(',');
- Serial.print(analogRead(a4pinZ)); // Accelerometer Orange reading
- Serial.print(',');
- Serial.print(analogRead(a1pinZ)); // Accelerometer Purple reading
- // Serial.print(',');
- // Serial.print(analogRead(aCpinY)); // Central accelerometer reading (y)
- // Serial.print(tranG);
- delay(1000);
- }
- ////////////////////////////////////////////////////////
- import processing.serial.*;
- Serial myPort; // The serial port
- void setup() {
- // List all the available serial ports
- println(Serial.list());
- // Open the port you are using at the rate you want:
- myPort = new Serial(this, Serial.list()[4], 4800);
- }
- void draw() {
- while (myPort.available() > 0) {
- int inByte = myPort.read();
- println(inByte);
- }
- }
And here is a snippet of numbers gathered from the Arduino, yes it is only reading the analog values, we have one digital that is not showing:
4,,636,73,96,638
4,,646,38,73,619
4,,619,57,76,617
4,,628,31,81,617
4,,656,38,57,619
4,,646,64,63,630
The connections on the Lilypad look like this, and we are getting values from A2, A3, A4 and A5 but not 9, because it is digital and need another string of code than analog:
Best, Marius, Laurie and Mari
This is a school project with Kingston University
1