update

update

--- SimpleFishFeeder/SimpleFishFeeder.ino
+++ SimpleFishFeeder/SimpleFishFeeder.ino
@@ -126,12 +126,16 @@
   while(Serial.available()) {
     String inputStr = Serial.readString();
     char charBuf[50];
-    inputStr.toCharArray(charBuf, 10) ;
+    inputStr.toCharArray(charBuf, 20) ;//2016/05/09 23:30:00
     if(getTime(charBuf))
     {
       _clock.adjust(_datetime);
     }
-
+
+  //
+  float batteryVoltageRead = analogRead (A0);
+  float batteryVoltage =float( batteryVoltageRead * (5/1023.));
+  Serial.println (batteryVoltage);
   }

   unsigned long currentMillis = millis();


ping code, reports distances on serialport

--- arduino/ultrasounder/ultrasounder.ino
+++ arduino/ultrasounder/ultrasounder.ino
@@ -0,0 +1,67 @@
+// Get this from https://code.google.com/p/arduino-new-ping/
+#include <NewPing.h>
+
+// Based on the 15 sensors example...
+
+#define SONAR_NUM     3 // Number or sensors.
+#define MAX_DISTANCE 200 // Maximum distance (in cm) to ping.
+#define PING_INTERVAL 33 // Milliseconds between sensor pings (29ms is about the min to avoid cross-sensor echo).
+
+unsigned long pingTimer[SONAR_NUM]; // Holds the times when the next ping should happen for each sensor.
+unsigned int cm[SONAR_NUM];         // Where the ping distances are stored.
+uint8_t currentSensor = 0;          // Keeps track of which sensor is active.
+
+NewPing sonar[SONAR_NUM] = {     // Sensor object array.
+  NewPing(2, 3, MAX_DISTANCE), // Each sensor's trigger pin, echo pin, and max distance to ping.
+  NewPing(4, 5, MAX_DISTANCE),
+  NewPing(6, 7, MAX_DISTANCE),
+};
+
+void setup()
+{
+  Serial.begin(115200);
+  pingTimer[0] = millis() + 75;           // First ping starts at 75ms, gives time for the Arduino to chill before starting.
+  for (uint8_t i = 1; i < SONAR_NUM; i++) // Set the starting time for each sensor.
+  {
+    pingTimer[i] = pingTimer[i - 1] + PING_INTERVAL;
+  }
+  Serial.println(F("Pinger booted"));
+}
+
+
+void loop() {
+  for (uint8_t i = 0; i < SONAR_NUM; i++) // Loop through all the sensors.
+  {
+    if (millis() >= pingTimer[i])         // Is it this sensor's time to ping?
+    {
+      pingTimer[i] += PING_INTERVAL * SONAR_NUM;  // Set next time this sensor will be pinged.
+      if (i == 0 && currentSensor == SONAR_NUM - 1) oneSensorCycle(); // Sensor ping cycle complete, do something with the results.
+      sonar[currentSensor].timer_stop();          // Make sure previous timer is canceled before starting a new ping (insurance).
+      currentSensor = i;                          // Sensor being accessed.
+      cm[currentSensor] = 0;                      // Make distance zero in case there's no ping echo for this sensor.
+      sonar[currentSensor].ping_timer(echoCheck); // Do the ping (processing continues, interrupt will call echoCheck to look for echo).
+    }
+  }
+  // The rest of your code would go here.
+}
+
+void echoCheck() // If ping received, set the sensor distance to array. This is called from interrupt, be quick!
+{
+  if (sonar[currentSensor].check_timer())
+  {
+    cm[currentSensor] = sonar[currentSensor].ping_result / US_ROUNDTRIP_CM;
+  }
+}
+
+void oneSensorCycle() // Sensor ping cycle complete, do something with the results.
+{
+  for (uint8_t i = 0; i < SONAR_NUM; i++)
+  {
+    Serial.print("!PING:");
+    Serial.print(i);
+    Serial.print(",");
+    Serial.println(cm[i]);
+  }
+}
+
+


Adjust values

Adjust values

--- ArduinoMazeSolver/ArduinoMazeSolver.ino
+++ ArduinoMazeSolver/ArduinoMazeSolver.ino
@@ -20,8 +20,8 @@

 const int maxMotorSpeed = 255;

-Turn fullPath[100];
-Turn simplePath[100];
+Turn fullPath[150];
+Turn simplePath[150];

 byte pathLength;
 byte fullPathLength;
@@ -559,7 +559,7 @@
 	for(byte i=0; i<fullPathLength; i++)
 	{
 		sendTurn(fullPath[i]);
-		delay(1000);
+		delay(100);
 	}
 }
 #pragma endregion


Calibration and Complementary Filter

Calibration and Complementary Filter

Calibration of sensor and Angluar positions of each MPU(finger)

--- BitBangingMpu6050/BitBangingMpu6050.ino
+++ BitBangingMpu6050/BitBangingMpu6050.ino
@@ -1,7 +1,4 @@
-// MPU-6050 Short Example Sketch
-// By Arduino User JohnChi
-// August 17, 2014
-// Public Domain
+//Flick Project
 #define SDA_PORT PORTD
 #define SDA_PIN 4
 #define SCL_PORT PORTD
@@ -615,6 +612,7 @@
 // lower address, so that has to be corrected.
 // The register part "reg" is only used internally,
 // and are swapped in code.
+
 typedef union accel_t_gyro_union
 {
   struct
@@ -625,8 +623,6 @@
     uint8_t y_accel_l;
     uint8_t z_accel_h;
     uint8_t z_accel_l;
-    uint8_t t_h;
-    uint8_t t_l;
     uint8_t x_gyro_h;
     uint8_t x_gyro_l;
     uint8_t y_gyro_h;
@@ -639,17 +635,75 @@
     int16_t x_accel;
     int16_t y_accel;
     int16_t z_accel;
-    int16_t temperature;
     int16_t x_gyro;
     int16_t y_gyro;
     int16_t z_gyro;
   } value;
 };
-int pin3=3;
-int pin6=6;
-int pin7=7;
-int pin8=8;
-int pin9=9;
+
+int read_gyro_accel_vals(uint8_t* accel_t_gyro_ptr) {
+  // Read the raw values.
+  // Read 14 bytes at once,
+  // containing acceleration, temperature and gyro.
+  // With the default settings of the MPU-6050,
+  // there is no filter enabled, and the values
+  // are not very stable.  Returns the error value
+
+  accel_t_gyro_union* accel_t_gyro = (accel_t_gyro_union *) accel_t_gyro_ptr;
+
+  int error = MPU6050_read (MPU6050_ACCEL_XOUT_H, (uint8_t *) accel_t_gyro, sizeof(*accel_t_gyro));
+
+  // Swap all high and low bytes.
+  // After this, the registers values are swapped,
+  // so the structure name like x_accel_l does no
+  // longer contain the lower byte.
+  uint8_t swap;
+  #define SWAP(x,y) swap = x; x = y; y = swap
+
+  SWAP ((*accel_t_gyro).reg.x_accel_h, (*accel_t_gyro).reg.x_accel_l);
+  SWAP ((*accel_t_gyro).reg.y_accel_h, (*accel_t_gyro).reg.y_accel_l);
+  SWAP ((*accel_t_gyro).reg.z_accel_h, (*accel_t_gyro).reg.z_accel_l);
+  SWAP ((*accel_t_gyro).reg.x_gyro_h, (*accel_t_gyro).reg.x_gyro_l);
+  SWAP ((*accel_t_gyro).reg.y_gyro_h, (*accel_t_gyro).reg.y_gyro_l);
+  SWAP ((*accel_t_gyro).reg.z_gyro_h, (*accel_t_gyro).reg.z_gyro_l);
+
+  return error;
+}
+
+unsigned long last_read_time[5];
+float         last_x_angle[5];  // These are the filtered angles
+float         last_y_angle[5];
+float         last_z_angle[5];
+float         last_gyro_x_angle[5];  // Store the gyro angles to compare drift
+float         last_gyro_y_angle[5];
+float         last_gyro_z_angle[5];
+
+
+void set_last_read_angle_data(unsigned long time, float x, float y, float z, float x_gyro, float y_gyro, float z_gyro, int a) {
+  last_read_time[a] = time;
+  last_x_angle[a] = x;
+  last_y_angle[a] = y;
+  last_z_angle[a] = z;
+  last_gyro_x_angle[a] = x_gyro;
+  last_gyro_y_angle[a] = y_gyro;
+  last_gyro_z_angle[a] = z_gyro;
+}
+
+inline unsigned long get_last_time(int a) {return last_read_time[a];}
+inline float get_last_x_angle(int a) {return last_x_angle[a];}
+inline float get_last_y_angle(int a) {return last_y_angle[a];}
+inline float get_last_z_angle(int a) {return last_z_angle[a];}
+inline float get_last_gyro_x_angle(int a) {return last_gyro_x_angle[a];}
+inline float get_last_gyro_y_angle(int a) {return last_gyro_y_angle[a];}
+inline float get_last_gyro_z_angle(int a) {return last_gyro_z_angle[a];}
+
+float    base_x_accel[5];
+float    base_y_accel[5];
+float    base_z_accel[5];
+
+float    base_x_gyro[5];
+float    base_y_gyro[5];
+float    base_z_gyro[5];

 const int MPU_addr=0x69;  // I2C address of the MPU-6050
@@ -703,31 +757,73 @@
   Serial.println("\nI2C Scanner");
     }
       mySerial.begin(115200);
-
+      calibrate_sensor1();
+      set_last_read_angle_data(millis(), 0, 0, 0, 0, 0, 0, 0);
+      calibrate_sensor2();
+      set_last_read_angle_data(millis(), 0, 0, 0, 0, 0, 0, 1);
+      calibrate_sensor3();
+      set_last_read_angle_data(millis(), 0, 0, 0, 0, 0, 0, 2);
+      calibrate_sensor4();
+      set_last_read_angle_data(millis(), 0, 0, 0, 0, 0, 0, 3);
+      calibrate_sensor5();
+      set_last_read_angle_data(millis(), 0, 0, 0, 0, 0, 0, 4);
 }
+
+
+
+
 void loop(){

 byte error, address;
 address=105;
-  int nDevices;
-
-  Serial.println(F("Scanning I2C bus (7-bit addresses) ..."));
-  nDevices = 0;
+  //int nDevices;
+
+  //Serial.println(F("Scanning I2C bus (7-bit addresses) ..."));
+  //nDevices = 0;
   for(int j=6;j<=10;j++)
       {
         if(flag!=j)
         {
         pinMode(j,OUTPUT);
         digitalWrite(j,LOW);
-
         }
       }
       pinMode(flag,OUTPUT);
       digitalWrite(flag,HIGH);
+      if(flag==6)
+      {
+        mpunumber1();
+        delay(1000);
+      }
+      if(flag==7)
+      {
+        mpunumber2();
+        delay(1000);
+      }
+       if(flag==8)
+       {
+        mpunumber3();
+        delay(1000);
+      }
+       if(flag==9)
+       {
+        {
+        mpunumber4();
+        delay(1000);
+      }
+       }
+       if(flag==10)
+       {
+        mpunumber5();
+        flag=6;
+        delay(1000);
+      }
+       else
+        ++flag;
       // The i2c_scanner uses the return value of
       // the Write.endTransmisstion to see if
       // a device did acknowledge to the address.
-      Wire.beginTransmission(address);
+      /*Wire.beginTransmission(address);
       error = Wire.endTransmission();

       if (error == 0)
@@ -809,7 +905,7 @@
   dT = ( (double) accel_t_gyro.value.temperature + 12412.0) / 340.0;
   Serial.print(dT, 3);
   Serial.print(F(" degrees Celsius"));
-  Serial.println(F(""));*/
+  Serial.println(F(""));

   // Print the raw gyro values.
@@ -830,12 +926,6 @@
     mySerial.println("The Gyro Z value is : ");
     mySerial.print(accel_t_gyro.value.z_gyro);
         mySerial.print("\n");
-
-  //Serial.print(F(", "));
-  //Serial.println(F(""));
-
- //delay(1000);
-

           nDevices++;

@@ -857,7 +947,7 @@
     flag=6;
     else
       flag++;
-  //delay(5000);           // wait 5 seconds for next scan
+  //delay(5000);           // wait 5 seconds for next scan*/
 }

@@ -957,3 +1047,1211 @@
   return (error);
 }

+
+void mpunumber1()
+{
+    byte error, address;
+    address=105;
+    Wire.beginTransmission(address);
+      error = Wire.endTransmission();
+
+      if (error == 0)
+        {
+          /*Serial.print("MPU number : ");
+          Serial.println(flag-5);
+          Serial.print(F("I2C device found at address 0x"));
+          if (address<16)
+            Serial.print(F("0"));
+          Serial.print(address,HEX);
+          Serial.println(F("  !"));*/
+
+  int error;
+  double dT;
+  accel_t_gyro_union accel_t_gyro;
+
+  error = read_gyro_accel_vals((uint8_t*) &accel_t_gyro);
+  unsigned long t_now = millis();
+  /*Serial.println(F(""));
+  Serial.println(F("MPU-6050"));*/
+
+  // Read the raw values.
+  // Read 14 bytes at once,
+  // containing acceleration, temperature and gyro.
+  // With the default settings of the MPU-6050,
+  // there is no filter enabled, and the values
+  // are not very stable.
+  //error = MPU6050_read (MPU6050_ACCEL_XOUT_H, (uint8_t *) &accel_t_gyro, sizeof(accel_t_gyro));
+ /* Serial.print(F("Read accel, temp and gyro, error = "));
+  Serial.println(error,DEC);*/
+
+
+  // Swap all high and low bytes.
+  // After this, the registers values are swapped,
+  // so the structure name like x_accel_l does no
+  // longer contain the lower byte.
+  /*uint8_t swap;
+  #define SWAP(x,y) swap = x; x = y; y = swap
+
+  SWAP (accel_t_gyro.reg.x_accel_h, accel_t_gyro.reg.x_accel_l);
+  SWAP (accel_t_gyro.reg.y_accel_h, accel_t_gyro.reg.y_accel_l);
+  SWAP (accel_t_gyro.reg.z_accel_h, accel_t_gyro.reg.z_accel_l);
+  SWAP (accel_t_gyro.reg.x_gyro_h, accel_t_gyro.reg.x_gyro_l);
+  SWAP (accel_t_gyro.reg.y_gyro_h, accel_t_gyro.reg.y_gyro_l);
+  SWAP (accel_t_gyro.reg.z_gyro_h, accel_t_gyro.reg.z_gyro_l);*/
+
+
+  // Print the raw acceleration values
+
+ // Serial.print(F("accel x,y,z: "));
+  /*mySerial.println("The Accl X value from Thumb is : ");
+  //Serial.print(accel_t_gyro.value.x_accel, DEC);
+  //Serial.print(F(", "));
+    mySerial.print(accel_t_gyro.value.x_accel);
+  mySerial.print("\n");
+    mySerial.println("The Accl Y value from Thumb is : ");
+//Serial.print(accel_t_gyro.value.y_accel, DEC);
+      mySerial.print(accel_t_gyro.value.y_accel);
+  mySerial.print("\n");
+
+ // Serial.print(F(", "));
+   mySerial.println("The Accl Z value from Thumb is : ");
+
+  //Serial.print(accel_t_gyro.value.z_accel, DEC);
+     mySerial.print(accel_t_gyro.value.z_accel);
+
+  //Serial.println(F(""));
+    mySerial.print("\n");*/
+
+
+
+  // The temperature sensor is -40 to +85 degrees Celsius.
+  // It is a signed integer.
+  // According to the datasheet:
+  //   340 per degrees Celsius, -512 at 35 degrees.
+  // At 0 degrees: -512 - (340 * 35) = -12412
+
+  /*Serial.print(F("temperature: "));
+  dT = ( (double) accel_t_gyro.value.temperature + 12412.0) / 340.0;
+  Serial.print(dT, 3);
+  Serial.print(F(" degrees Celsius"));
+  Serial.println(F(""));*/
+
+
+  // Print the raw gyro values.
+
+  //Serial.print(F("gyro x,y,z : "));
+  /*mySerial.println("The Gyro X value from Thumb is : ");
+  mySerial.print(accel_t_gyro.value.x_gyro);
+      mySerial.print("\n");
+  //Serial.print(accel_t_gyro.value.x_gyro, DEC);
+  //Serial.print(F(", "));
+  //Serial.print(accel_t_gyro.value.y_gyro, DEC);
+    mySerial.println("The Gyro Y value from Thumb is : ");
+    mySerial.print(accel_t_gyro.value.y_gyro);
+        mySerial.print("\n");
+
+  //Serial.print(F(", "));
+  //Serial.print(accel_t_gyro.value.z_gyro, DEC);
+    mySerial.println("The Gyro Z value from Thumb is : ");
+    mySerial.print(accel_t_gyro.value.z_gyro);
+        mySerial.print("\n");*/
+        //mySerial.println("Thumb angle values");
+    float FS_SEL = 131;
+
+  float gyro_x = (accel_t_gyro.value.x_gyro - base_x_gyro[0])/FS_SEL;
+  float gyro_y = (accel_t_gyro.value.y_gyro - base_y_gyro[0])/FS_SEL;
+  float gyro_z = (accel_t_gyro.value.z_gyro - base_z_gyro[0])/FS_SEL;
+
+
+  // Get raw acceleration values
+  //float G_CONVERT = 16384;
+  float accel_x = accel_t_gyro.value.x_accel;
+  float accel_y = accel_t_gyro.value.y_accel;
+  float accel_z = accel_t_gyro.value.z_accel;
+
+  // Get angle values from accelerometer
+  float RADIANS_TO_DEGREES = 180/3.14159;
+//  float accel_vector_length = sqrt(pow(accel_x,2) + pow(accel_y,2) + pow(accel_z,2));
+  float accel_angle_y = atan(-1*accel_x/sqrt(pow(accel_y,2) + pow(accel_z,2)))*RADIANS_TO_DEGREES;
+  float accel_angle_x = atan(accel_y/sqrt(pow(accel_x,2) + pow(accel_z,2)))*RADIANS_TO_DEGREES;
+
+  float accel_angle_z = 0;
+
+  // Compute the (filtered) gyro angles
+  float dt =(t_now - get_last_time(0))/1000.0;
+  float gyro_angle_x = gyro_x*dt + get_last_x_angle(0);
+  float gyro_angle_y = gyro_y*dt + get_last_y_angle(0);
+  float gyro_angle_z = gyro_z*dt + get_last_z_angle(0);
+
+  // Compute the drifting gyro angles
+  float unfiltered_gyro_angle_x = gyro_x*dt + get_last_gyro_x_angle(0);
+  float unfiltered_gyro_angle_y = gyro_y*dt + get_last_gyro_y_angle(0);
+  float unfiltered_gyro_angle_z = gyro_z*dt + get_last_gyro_z_angle(0);
+
+  // Apply the complementary filter to figure out the change in angle - choice of alpha is
+  // estimated now.  Alpha depends on the sampling rate...
+  float alpha = 0.96;
+  float angle_x = alpha*gyro_angle_x + (1.0 - alpha)*accel_angle_x;
+  float angle_y = alpha*gyro_angle_y + (1.0 - alpha)*accel_angle_y;
+  float angle_z = gyro_angle_z;  //Accelerometer doesn't give z-angle
+
+  // Update the saved data with the latest values
+  set_last_read_angle_data(t_now, angle_x, angle_y, angle_z, unfiltered_gyro_angle_x, unfiltered_gyro_angle_y, unfiltered_gyro_angle_z, 0);
+
+  // Send the data to the serial port
+ /* mySerial.print(F("DEL:"));              //Delta T
+  mySerial.print(dt, DEC);
+  mySerial.print(F("#ACC:"));              //Accelerometer angle
+  mySerial.print(accel_angle_x, 2);
+  mySerial.print(F(","));
+  mySerial.print(accel_angle_y, 2);
+  mySerial.print(F(","));
+  mySerial.print(accel_angle_z, 2);
+  mySerial.print(F("#GYR:"));
+  Serial.print(unfiltered_gyro_angle_x, 2);        //Gyroscope angle
+  Serial.print(F(","));
+  Serial.print(unfiltered_gyro_angle_y, 2);
+  Serial.print(F(","));
+  Serial.print(unfiltered_gyro_angle_z, 2);*/
+  mySerial.println(F("Thumb Angles x y z "));             //Filtered angle
+  mySerial.print(angle_x, DEC);
+  mySerial.println(F(","));
+  mySerial.print(angle_y, DEC);
+  mySerial.println(F(","));
+  mySerial.print(angle_z, DEC);
+  mySerial.println(F(""));
+
+  // Delay so we don't swamp the serial port
+
+         // nDevices++;
+
+        }
+      else if (error==4)
+        {
+          Serial.print(F("Unknown error at address 0x"));
+          if (address<16)
+            Serial.print("0");
+          Serial.println(address,HEX);
+        }
+
+
+}
+
+
+void mpunumber2()
+{
+    byte error, address;
+    address=105;
+    Wire.beginTransmission(address);
+      error = Wire.endTransmission();
+
+      if (error == 0)
+        {
+          /*Serial.print("MPU number : ");
+          Serial.println(flag-5);
+          Serial.print(F("I2C device found at address 0x"));
+          if (address<16)
+            Serial.print(F("0"));
+          Serial.print(address,HEX);
+          Serial.println(F("  !"));*/
+
+  int error;
+  double dT;
+  accel_t_gyro_union accel_t_gyro;
+
+  error = read_gyro_accel_vals((uint8_t*) &accel_t_gyro);
+  unsigned long t_now = millis();
+  /*Serial.println(F(""));
+  Serial.println(F("MPU-6050"));*/
+
+  // Read the raw values.
+  // Read 14 bytes at once,
+  // containing acceleration, temperature and gyro.
+  // With the default settings of the MPU-6050,
+  // there is no filter enabled, and the values
+  // are not very stable.
+  //error = MPU6050_read (MPU6050_ACCEL_XOUT_H, (uint8_t *) &accel_t_gyro, sizeof(accel_t_gyro));
+ /* Serial.print(F("Read accel, temp and gyro, error = "));
+  Serial.println(error,DEC);*/
+
+
+  // Swap all high and low bytes.
+  // After this, the registers values are swapped,
+  // so the structure name like x_accel_l does no
+  // longer contain the lower byte.
+  /*uint8_t swap;
+  #define SWAP(x,y) swap = x; x = y; y = swap
+
+  SWAP (accel_t_gyro.reg.x_accel_h, accel_t_gyro.reg.x_accel_l);
+  SWAP (accel_t_gyro.reg.y_accel_h, accel_t_gyro.reg.y_accel_l);
+  SWAP (accel_t_gyro.reg.z_accel_h, accel_t_gyro.reg.z_accel_l);
+  SWAP (accel_t_gyro.reg.x_gyro_h, accel_t_gyro.reg.x_gyro_l);
+  SWAP (accel_t_gyro.reg.y_gyro_h, accel_t_gyro.reg.y_gyro_l);
+  SWAP (accel_t_gyro.reg.z_gyro_h, accel_t_gyro.reg.z_gyro_l);*/
+
+
+  // Print the raw acceleration values
+
+ // Serial.print(F("accel x,y,z: "));
+  /*mySerial.println("The Accl X value from Thumb is : ");
+  //Serial.print(accel_t_gyro.value.x_accel, DEC);
+  //Serial.print(F(", "));
+    mySerial.print(accel_t_gyro.value.x_accel);
+  mySerial.print("\n");
+    mySerial.println("The Accl Y value from Thumb is : ");
+//Serial.print(accel_t_gyro.value.y_accel, DEC);
+      mySerial.print(accel_t_gyro.value.y_accel);
+  mySerial.print("\n");
+
+ // Serial.print(F(", "));
+   mySerial.println("The Accl Z value from Thumb is : ");
+
+  //Serial.print(accel_t_gyro.value.z_accel, DEC);
+     mySerial.print(accel_t_gyro.value.z_accel);
+
+  //Serial.println(F(""));
+    mySerial.print("\n");*/
+
+
+
+  // The temperature sensor is -40 to +85 degrees Celsius.
+  // It is a signed integer.
+  // According to the datasheet:
+  //   340 per degrees Celsius, -512 at 35 degrees.
+  // At 0 degrees: -512 - (340 * 35) = -12412
+
+  /*Serial.print(F("temperature: "));
+  dT = ( (double) accel_t_gyro.value.temperature + 12412.0) / 340.0;
+  Serial.print(dT, 3);
+  Serial.print(F(" degrees Celsius"));
+  Serial.println(F(""));*/
+
+
+  // Print the raw gyro values.
+
+  //Serial.print(F("gyro x,y,z : "));
+  /*mySerial.println("The Gyro X value from Thumb is : ");
+  mySerial.print(accel_t_gyro.value.x_gyro);
+      mySerial.print("\n");
+  //Serial.print(accel_t_gyro.value.x_gyro, DEC);
+  //Serial.print(F(", "));
+  //Serial.print(accel_t_gyro.value.y_gyro, DEC);
+    mySerial.println("The Gyro Y value from Thumb is : ");
+    mySerial.print(accel_t_gyro.value.y_gyro);
+        mySerial.print("\n");
+
+  //Serial.print(F(", "));
+  //Serial.print(accel_t_gyro.value.z_gyro, DEC);
+    mySerial.println("The Gyro Z value from Thumb is : ");
+    mySerial.print(accel_t_gyro.value.z_gyro);
+        mySerial.print("\n");*/
+        //mySerial.println("Thumb angle values");
+    float FS_SEL = 131;
+
+  float gyro_x = (accel_t_gyro.value.x_gyro - base_x_gyro[1])/FS_SEL;
+  float gyro_y = (accel_t_gyro.value.y_gyro - base_y_gyro[1])/FS_SEL;
+  float gyro_z = (accel_t_gyro.value.z_gyro - base_z_gyro[1])/FS_SEL;
+
+
+  // Get raw acceleration values
+  //float G_CONVERT = 16384;
+  float accel_x = accel_t_gyro.value.x_accel;
+  float accel_y = accel_t_gyro.value.y_accel;
+  float accel_z = accel_t_gyro.value.z_accel;
+
+  // Get angle values from accelerometer
+  float RADIANS_TO_DEGREES = 180/3.14159;
+//  float accel_vector_length = sqrt(pow(accel_x,2) + pow(accel_y,2) + pow(accel_z,2));
+  float accel_angle_y = atan(-1*accel_x/sqrt(pow(accel_y,2) + pow(accel_z,2)))*RADIANS_TO_DEGREES;
+  float accel_angle_x = atan(accel_y/sqrt(pow(accel_x,2) + pow(accel_z,2)))*RADIANS_TO_DEGREES;
+
+  float accel_angle_z = 0;
+
+  // Compute the (filtered) gyro angles
+  float dt =(t_now - get_last_time(1))/1000.0;
+  float gyro_angle_x = gyro_x*dt + get_last_x_angle(1);
+  float gyro_angle_y = gyro_y*dt + get_last_y_angle(1);
+  float gyro_angle_z = gyro_z*dt + get_last_z_angle(1);
+
+  // Compute the drifting gyro angles
+  float unfiltered_gyro_angle_x = gyro_x*dt + get_last_gyro_x_angle(1);
+  float unfiltered_gyro_angle_y = gyro_y*dt + get_last_gyro_y_angle(1);
+  float unfiltered_gyro_angle_z = gyro_z*dt + get_last_gyro_z_angle(1);
+
+  // Apply the complementary filter to figure out the change in angle - choice of alpha is
+  // estimated now.  Alpha depends on the sampling rate...
+  float alpha = 0.96;
+  float angle_x = alpha*gyro_angle_x + (1.0 - alpha)*accel_angle_x;
+  float angle_y = alpha*gyro_angle_y + (1.0 - alpha)*accel_angle_y;
+  float angle_z = gyro_angle_z;  //Accelerometer doesn't give z-angle
+
+  // Update the saved data with the latest values
+  set_last_read_angle_data(t_now, angle_x, angle_y, angle_z, unfiltered_gyro_angle_x, unfiltered_gyro_angle_y, unfiltered_gyro_angle_z, 1);
+
+  // Send the data to the serial port
+ /* mySerial.print(F("DEL:"));              //Delta T
+  mySerial.print(dt, DEC);
+  mySerial.print(F("#ACC:"));              //Accelerometer angle
+  mySerial.print(accel_angle_x, 2);
+  mySerial.print(F(","));
+  mySerial.print(accel_angle_y, 2);
+  mySerial.print(F(","));
+  mySerial.print(accel_angle_z, 2);
+  mySerial.print(F("#GYR:"));
+  Serial.print(unfiltered_gyro_angle_x, 2);        //Gyroscope angle
+  Serial.print(F(","));
+  Serial.print(unfiltered_gyro_angle_y, 2);
+  Serial.print(F(","));
+  Serial.print(unfiltered_gyro_angle_z, 2);*/
+  mySerial.println(F("Index Finger Angles x y z "));             //Filtered angle
+  mySerial.print(angle_x, DEC);
+  mySerial.println(F(","));
+  mySerial.print(angle_y, DEC);
+  mySerial.println(F(","));
+  mySerial.print(angle_z, DEC);
+  mySerial.println(F(""));
+
+  // Delay so we don't swamp the serial port
+
+         // nDevices++;
+
+        }
+      else if (error==4)
+        {
+          Serial.print(F("Unknown error at address 0x"));
+          if (address<16)
+            Serial.print("0");
+          Serial.println(address,HEX);
+        }
+
+
+}
+
+void mpunumber3()
+{
+  byte error, address;
+    address=105;
+    Wire.beginTransmission(address);
+      error = Wire.endTransmission();
+
+      if (error == 0)
+        {
+          /*Serial.print("MPU number : ");
+          Serial.println(flag-5);
+          Serial.print(F("I2C device found at address 0x"));
+          if (address<16)
+            Serial.print(F("0"));
+          Serial.print(address,HEX);
+          Serial.println(F("  !"));*/
+
+  int error;
+  double dT;
+  accel_t_gyro_union accel_t_gyro;
+
+  error = read_gyro_accel_vals((uint8_t*) &accel_t_gyro);
+  unsigned long t_now = millis();
+  /*Serial.println(F(""));
+  Serial.println(F("MPU-6050"));*/
+
+  // Read the raw values.
+  // Read 14 bytes at once,
+  // containing acceleration, temperature and gyro.
+  // With the default settings of the MPU-6050,
+  // there is no filter enabled, and the values
+  // are not very stable.
+  //error = MPU6050_read (MPU6050_ACCEL_XOUT_H, (uint8_t *) &accel_t_gyro, sizeof(accel_t_gyro));
+ /* Serial.print(F("Read accel, temp and gyro, error = "));
+  Serial.println(error,DEC);*/
+
+
+  // Swap all high and low bytes.
+  // After this, the registers values are swapped,
+  // so the structure name like x_accel_l does no
+  // longer contain the lower byte.
+  /*uint8_t swap;
+  #define SWAP(x,y) swap = x; x = y; y = swap
+
+  SWAP (accel_t_gyro.reg.x_accel_h, accel_t_gyro.reg.x_accel_l);
+  SWAP (accel_t_gyro.reg.y_accel_h, accel_t_gyro.reg.y_accel_l);
+  SWAP (accel_t_gyro.reg.z_accel_h, accel_t_gyro.reg.z_accel_l);
+  SWAP (accel_t_gyro.reg.x_gyro_h, accel_t_gyro.reg.x_gyro_l);
+  SWAP (accel_t_gyro.reg.y_gyro_h, accel_t_gyro.reg.y_gyro_l);
+  SWAP (accel_t_gyro.reg.z_gyro_h, accel_t_gyro.reg.z_gyro_l);*/
+
+
+  // Print the raw acceleration values
+
+ // Serial.print(F("accel x,y,z: "));
+  /*mySerial.println("The Accl X value from Thumb is : ");
+  //Serial.print(accel_t_gyro.value.x_accel, DEC);
+  //Serial.print(F(", "));
+    mySerial.print(accel_t_gyro.value.x_accel);
+  mySerial.print("\n");
+    mySerial.println("The Accl Y value from Thumb is : ");
+//Serial.print(accel_t_gyro.value.y_accel, DEC);
+      mySerial.print(accel_t_gyro.value.y_accel);
+  mySerial.print("\n");
+
+ // Serial.print(F(", "));
+   mySerial.println("The Accl Z value from Thumb is : ");
+
+  //Serial.print(accel_t_gyro.value.z_accel, DEC);
+     mySerial.print(accel_t_gyro.value.z_accel);
+
+  //Serial.println(F(""));
+    mySerial.print("\n");*/
+
+
+
+  // The temperature sensor is -40 to +85 degrees Celsius.
+  // It is a signed integer.
+  // According to the datasheet:
+  //   340 per degrees Celsius, -512 at 35 degrees.
+  // At 0 degrees: -512 - (340 * 35) = -12412
+
+  /*Serial.print(F("temperature: "));
+  dT = ( (double) accel_t_gyro.value.temperature + 12412.0) / 340.0;
+  Serial.print(dT, 3);
+  Serial.print(F(" degrees Celsius"));
+  Serial.println(F(""));*/
+
+
+  // Print the raw gyro values.
+
+  //Serial.print(F("gyro x,y,z : "));
+  /*mySerial.println("The Gyro X value from Thumb is : ");
+  mySerial.print(accel_t_gyro.value.x_gyro);
+      mySerial.print("\n");
+  //Serial.print(accel_t_gyro.value.x_gyro, DEC);
+  //Serial.print(F(", "));
+  //Serial.print(accel_t_gyro.value.y_gyro, DEC);
+    mySerial.println("The Gyro Y value from Thumb is : ");
+    mySerial.print(accel_t_gyro.value.y_gyro);
+        mySerial.print("\n");
+
+  //Serial.print(F(", "));
+  //Serial.print(accel_t_gyro.value.z_gyro, DEC);
+    mySerial.println("The Gyro Z value from Thumb is : ");
+    mySerial.print(accel_t_gyro.value.z_gyro);
+        mySerial.print("\n");*/
+        //mySerial.println(" angle values");
+    float FS_SEL = 131;
+
+  float gyro_x = (accel_t_gyro.value.x_gyro - base_x_gyro[2])/FS_SEL;
+  float gyro_y = (accel_t_gyro.value.y_gyro - base_y_gyro[2])/FS_SEL;
+  float gyro_z = (accel_t_gyro.value.z_gyro - base_z_gyro[2])/FS_SEL;
+
+
+  // Get raw acceleration values
+  //float G_CONVERT = 16384;
+  float accel_x = accel_t_gyro.value.x_accel;
+  float accel_y = accel_t_gyro.value.y_accel;
+  float accel_z = accel_t_gyro.value.z_accel;
+
+  // Get angle values from accelerometer
+  float RADIANS_TO_DEGREES = 180/3.14159;
+//  float accel_vector_length = sqrt(pow(accel_x,2) + pow(accel_y,2) + pow(accel_z,2));
+  float accel_angle_y = atan(-1*accel_x/sqrt(pow(accel_y,2) + pow(accel_z,2)))*RADIANS_TO_DEGREES;
+  float accel_angle_x = atan(accel_y/sqrt(pow(accel_x,2) + pow(accel_z,2)))*RADIANS_TO_DEGREES;
+
+  float accel_angle_z = 0;
+
+  // Compute the (filtered) gyro angles
+  float dt =(t_now - get_last_time(2))/1000.0;
+  float gyro_angle_x = gyro_x*dt + get_last_x_angle(2);
+  float gyro_angle_y = gyro_y*dt + get_last_y_angle(2);
+  float gyro_angle_z = gyro_z*dt + get_last_z_angle(2);
+
+  // Compute the drifting gyro angles
+  float unfiltered_gyro_angle_x = gyro_x*dt + get_last_gyro_x_angle(2);
+  float unfiltered_gyro_angle_y = gyro_y*dt + get_last_gyro_y_angle(2);
+  float unfiltered_gyro_angle_z = gyro_z*dt + get_last_gyro_z_angle(2);
+
+  // Apply the complementary filter to figure out the change in angle - choice of alpha is
+  // estimated now.  Alpha depends on the sampling rate...
+  float alpha = 0.96;
+  float angle_x = alpha*gyro_angle_x + (1.0 - alpha)*accel_angle_x;
+  float angle_y = alpha*gyro_angle_y + (1.0 - alpha)*accel_angle_y;
+  float angle_z = gyro_angle_z;  //Accelerometer doesn't give z-angle
+
+  // Update the saved data with the latest values
+  set_last_read_angle_data(t_now, angle_x, angle_y, angle_z, unfiltered_gyro_angle_x, unfiltered_gyro_angle_y, unfiltered_gyro_angle_z, 2);
+
+  // Send the data to the serial port
+ /* mySerial.print(F("DEL:"));              //Delta T
+  mySerial.print(dt, DEC);
+  mySerial.print(F("#ACC:"));              //Accelerometer angle
+  mySerial.print(accel_angle_x, 2);
+  mySerial.print(F(","));
+  mySerial.print(accel_angle_y, 2);
+  mySerial.print(F(","));
+  mySerial.print(accel_angle_z, 2);
+  mySerial.print(F("#GYR:"));
+  Serial.print(unfiltered_gyro_angle_x, 2);        //Gyroscope angle
+  Serial.print(F(","));
+  Serial.print(unfiltered_gyro_angle_y, 2);
+  Serial.print(F(","));
+  Serial.print(unfiltered_gyro_angle_z, 2);*/
+  mySerial.println(F("Middle Finger Angles x y z "));             //Filtered angle
+  mySerial.print(angle_x, DEC);
+  mySerial.println(F(","));
+  mySerial.print(angle_y, DEC);
+  mySerial.println(F(","));
+  mySerial.print(angle_z, DEC);
+  mySerial.println(F(""));
+
+  // Delay so we don't swamp the serial port
+
+         // nDevices++;
+
+        }
+      else if (error==4)
+        {
+          Serial.print(F("Unknown error at address 0x"));
+          if (address<16)
+            Serial.print("0");
+          Serial.println(address,HEX);
+        }
+
+
+}
+
+void mpunumber4()
+{
+  byte error, address;
+    address=105;
+    Wire.beginTransmission(address);
+      error = Wire.endTransmission();
+
+      if (error == 0)
+        {
+          /*Serial.print("MPU number : ");
+          Serial.println(flag-5);
+          Serial.print(F("I2C device found at address 0x"));
+          if (address<16)
+            Serial.print(F("0"));
+          Serial.print(address,HEX);
+          Serial.println(F("  !"));*/
+
+  int error;
+  double dT;
+  accel_t_gyro_union accel_t_gyro;
+
+  error = read_gyro_accel_vals((uint8_t*) &accel_t_gyro);
+  unsigned long t_now = millis();
+  /*Serial.println(F(""));
+  Serial.println(F("MPU-6050"));*/
+
+  // Read the raw values.
+  // Read 14 bytes at once,
+  // containing acceleration, temperature and gyro.
+  // With the default settings of the MPU-6050,
+  // there is no filter enabled, and the values
+  // are not very stable.
+  //error = MPU6050_read (MPU6050_ACCEL_XOUT_H, (uint8_t *) &accel_t_gyro, sizeof(accel_t_gyro));
+ /* Serial.print(F("Read accel, temp and gyro, error = "));
+  Serial.println(error,DEC);*/
+
+
+  // Swap all high and low bytes.
+  // After this, the registers values are swapped,
+  // so the structure name like x_accel_l does no
+  // longer contain the lower byte.
+  /*uint8_t swap;
+  #define SWAP(x,y) swap = x; x = y; y = swap
+
+  SWAP (accel_t_gyro.reg.x_accel_h, accel_t_gyro.reg.x_accel_l);
+  SWAP (accel_t_gyro.reg.y_accel_h, accel_t_gyro.reg.y_accel_l);
+  SWAP (accel_t_gyro.reg.z_accel_h, accel_t_gyro.reg.z_accel_l);
+  SWAP (accel_t_gyro.reg.x_gyro_h, accel_t_gyro.reg.x_gyro_l);
+  SWAP (accel_t_gyro.reg.y_gyro_h, accel_t_gyro.reg.y_gyro_l);
+  SWAP (accel_t_gyro.reg.z_gyro_h, accel_t_gyro.reg.z_gyro_l);*/
+
+
+  // Print the raw acceleration values
+
+ // Serial.print(F("accel x,y,z: "));
+  /*mySerial.println("The Accl X value from Thumb is : ");
+  //Serial.print(accel_t_gyro.value.x_accel, DEC);
+  //Serial.print(F(", "));
+    mySerial.print(accel_t_gyro.value.x_accel);
+  mySerial.print("\n");
+    mySerial.println("The Accl Y value from Thumb is : ");
+//Serial.print(accel_t_gyro.value.y_accel, DEC);
+      mySerial.print(accel_t_gyro.value.y_accel);
+  mySerial.print("\n");
+
+ // Serial.print(F(", "));
+   mySerial.println("The Accl Z value from Thumb is : ");
+
+  //Serial.print(accel_t_gyro.value.z_accel, DEC);
+     mySerial.print(accel_t_gyro.value.z_accel);
+
+  //Serial.println(F(""));
+    mySerial.print("\n");*/
+
+
+
+  // The temperature sensor is -40 to +85 degrees Celsius.
+  // It is a signed integer.
+  // According to the datasheet:
+  //   340 per degrees Celsius, -512 at 35 degrees.
+  // At 0 degrees: -512 - (340 * 35) = -12412
+
+  /*Serial.print(F("temperature: "));
+  dT = ( (double) accel_t_gyro.value.temperature + 12412.0) / 340.0;
+  Serial.print(dT, 3);
+  Serial.print(F(" degrees Celsius"));
+  Serial.println(F(""));*/
+
+
+  // Print the raw gyro values.
+
+  //Serial.print(F("gyro x,y,z : "));
+  /*mySerial.println("The Gyro X value from Thumb is : ");
+  mySerial.print(accel_t_gyro.value.x_gyro);
+      mySerial.print("\n");
+  //Serial.print(accel_t_gyro.value.x_gyro, DEC);
+  //Serial.print(F(", "));
+  //Serial.print(accel_t_gyro.value.y_gyro, DEC);
+    mySerial.println("The Gyro Y value from Thumb is : ");
+    mySerial.print(accel_t_gyro.value.y_gyro);
+        mySerial.print("\n");
+
+  //Serial.print(F(", "));
+  //Serial.print(accel_t_gyro.value.z_gyro, DEC);
+    mySerial.println("The Gyro Z value from Thumb is : ");
+    mySerial.print(accel_t_gyro.value.z_gyro);
+        mySerial.print("\n");*/
+        //mySerial.println("Thumb angle values");
+    float FS_SEL = 131;
+
+  float gyro_x = (accel_t_gyro.value.x_gyro - base_x_gyro[3])/FS_SEL;
+  float gyro_y = (accel_t_gyro.value.y_gyro - base_y_gyro[3])/FS_SEL;
+  float gyro_z = (accel_t_gyro.value.z_gyro - base_z_gyro[3])/FS_SEL;
+
+
+  // Get raw acceleration values
+  //float G_CONVERT = 16384;
+  float accel_x = accel_t_gyro.value.x_accel;
+  float accel_y = accel_t_gyro.value.y_accel;
+  float accel_z = accel_t_gyro.value.z_accel;
+
+  // Get angle values from accelerometer
+  float RADIANS_TO_DEGREES = 180/3.14159;
+//  float accel_vector_length = sqrt(pow(accel_x,2) + pow(accel_y,2) + pow(accel_z,2));
+  float accel_angle_y = atan(-1*accel_x/sqrt(pow(accel_y,2) + pow(accel_z,2)))*RADIANS_TO_DEGREES;
+  float accel_angle_x = atan(accel_y/sqrt(pow(accel_x,2) + pow(accel_z,2)))*RADIANS_TO_DEGREES;
+
+  float accel_angle_z = 0;
+
+  // Compute the (filtered) gyro angles
+  float dt =(t_now - get_last_time(3))/1000.0;
+  float gyro_angle_x = gyro_x*dt + get_last_x_angle(3);
+  float gyro_angle_y = gyro_y*dt + get_last_y_angle(3);
+  float gyro_angle_z = gyro_z*dt + get_last_z_angle(3);
+
+  // Compute the drifting gyro angles
+  float unfiltered_gyro_angle_x = gyro_x*dt + get_last_gyro_x_angle(3);
+  float unfiltered_gyro_angle_y = gyro_y*dt + get_last_gyro_y_angle(3);
+  float unfiltered_gyro_angle_z = gyro_z*dt + get_last_gyro_z_angle(3);
+
+  // Apply the complementary filter to figure out the change in angle - choice of alpha is
+  // estimated now.  Alpha depends on the sampling rate...
+  float alpha = 0.96;
+  float angle_x = alpha*gyro_angle_x + (1.0 - alpha)*accel_angle_x;
+  float angle_y = alpha*gyro_angle_y + (1.0 - alpha)*accel_angle_y;
+  float angle_z = gyro_angle_z;  //Accelerometer doesn't give z-angle
+
+  // Update the saved data with the latest values
+  set_last_read_angle_data(t_now, angle_x, angle_y, angle_z, unfiltered_gyro_angle_x, unfiltered_gyro_angle_y, unfiltered_gyro_angle_z, 3);
+
+  // Send the data to the serial port
+ /* mySerial.print(F("DEL:"));              //Delta T
+  mySerial.print(dt, DEC);
+  mySerial.print(F("#ACC:"));              //Accelerometer angle
+  mySerial.print(accel_angle_x, 2);
+  mySerial.print(F(","));
+  mySerial.print(accel_angle_y, 2);
+  mySerial.print(F(","));
+  mySerial.print(accel_angle_z, 2);
+  mySerial.print(F("#GYR:"));
+  Serial.print(unfiltered_gyro_angle_x, 2);        //Gyroscope angle
+  Serial.print(F(","));
+  Serial.print(unfiltered_gyro_angle_y, 2);
+  Serial.print(F(","));
+  Serial.print(unfiltered_gyro_angle_z, 2);*/
+  mySerial.println(F("Ring Finger Angles x y z "));             //Filtered angle
+  mySerial.print(angle_x, DEC);
+  mySerial.println(F(","));
+  mySerial.print(angle_y, DEC);
+  mySerial.println(F(","));
+  mySerial.print(angle_z, DEC);
+  mySerial.println(F(""));
+
+  // Delay so we don't swamp the serial port
+
+         // nDevices++;
+
+        }
+      else if (error==4)
+        {
+          Serial.print(F("Unknown error at address 0x"));
+          if (address<16)
+            Serial.print("0");
+          Serial.println(address,HEX);
+        }
+
+
+}
+
+void mpunumber5()
+{
+  byte error, address;
+    address=105;
+    Wire.beginTransmission(address);
+      error = Wire.endTransmission();
+
+      if (error == 0)
+        {
+          /*Serial.print("MPU number : ");
+          Serial.println(flag-5);
+          Serial.print(F("I2C device found at address 0x"));
+          if (address<16)
+            Serial.print(F("0"));
+          Serial.print(address,HEX);
+          Serial.println(F("  !"));*/
+
+  int error;
+  double dT;
+  accel_t_gyro_union accel_t_gyro;
+
+  error = read_gyro_accel_vals((uint8_t*) &accel_t_gyro);
+  unsigned long t_now = millis();
+  /*Serial.println(F(""));
+  Serial.println(F("MPU-6050"));*/
+
+  // Read the raw values.
+  // Read 14 bytes at once,
+  // containing acceleration, temperature and gyro.
+  // With the default settings of the MPU-6050,
+  // there is no filter enabled, and the values
+  // are not very stable.
+  //error = MPU6050_read (MPU6050_ACCEL_XOUT_H, (uint8_t *) &accel_t_gyro, sizeof(accel_t_gyro));
+ /* Serial.print(F("Read accel, temp and gyro, error = "));
+  Serial.println(error,DEC);*/
+
+
+  // Swap all high and low bytes.
+  // After this, the registers values are swapped,
+  // so the structure name like x_accel_l does no
+  // longer contain the lower byte.
+  /*uint8_t swap;
+  #define SWAP(x,y) swap = x; x = y; y = swap
+
+  SWAP (accel_t_gyro.reg.x_accel_h, accel_t_gyro.reg.x_accel_l);
+  SWAP (accel_t_gyro.reg.y_accel_h, accel_t_gyro.reg.y_accel_l);
+  SWAP (accel_t_gyro.reg.z_accel_h, accel_t_gyro.reg.z_accel_l);
+  SWAP (accel_t_gyro.reg.x_gyro_h, accel_t_gyro.reg.x_gyro_l);
+  SWAP (accel_t_gyro.reg.y_gyro_h, accel_t_gyro.reg.y_gyro_l);
+  SWAP (accel_t_gyro.reg.z_gyro_h, accel_t_gyro.reg.z_gyro_l);*/
+
+
+  // Print the raw acceleration values
+
+ // Serial.print(F("accel x,y,z: "));
+  /*mySerial.println("The Accl X value from Thumb is : ");
+  //Serial.print(accel_t_gyro.value.x_accel, DEC);
+  //Serial.print(F(", "));
+    mySerial.print(accel_t_gyro.value.x_accel);
+  mySerial.print("\n");
+    mySerial.println("The Accl Y value from Thumb is : ");
+//Serial.print(accel_t_gyro.value.y_accel, DEC);
+      mySerial.print(accel_t_gyro.value.y_accel);
+  mySerial.print("\n");
+
+ // Serial.print(F(", "));
+   mySerial.println("The Accl Z value from Thumb is : ");
+
+  //Serial.print(accel_t_gyro.value.z_accel, DEC);
+     mySerial.print(accel_t_gyro.value.z_accel);
+
+  //Serial.println(F(""));
+    mySerial.print("\n");*/
+
+
+
+  // The temperature sensor is -40 to +85 degrees Celsius.
+  // It is a signed integer.
+  // According to the datasheet:
+  //   340 per degrees Celsius, -512 at 35 degrees.
+  // At 0 degrees: -512 - (340 * 35) = -12412
+
+  /*Serial.print(F("temperature: "));
+  dT = ( (double) accel_t_gyro.value.temperature + 12412.0) / 340.0;
+  Serial.print(dT, 3);
+  Serial.print(F(" degrees Celsius"));
+  Serial.println(F(""));*/
+
+
+  // Print the raw gyro values.
+
+  //Serial.print(F("gyro x,y,z : "));
+  /*mySerial.println("The Gyro X value from Thumb is : ");
+  mySerial.print(accel_t_gyro.value.x_gyro);
+      mySerial.print("\n");
+  //Serial.print(accel_t_gyro.value.x_gyro, DEC);
+  //Serial.print(F(", "));
+  //Serial.print(accel_t_gyro.value.y_gyro, DEC);
+    mySerial.println("The Gyro Y value from Thumb is : ");
+    mySerial.print(accel_t_gyro.value.y_gyro);
+        mySerial.print("\n");
+
+  //Serial.print(F(", "));
+  //Serial.print(accel_t_gyro.value.z_gyro, DEC);
+    mySerial.println("The Gyro Z value from Thumb is : ");
+    mySerial.print(accel_t_gyro.value.z_gyro);
+        mySerial.print("\n");*/
+        //mySerial.println("Thumb angle values");
+    float FS_SEL = 131;
+
+  float gyro_x = (accel_t_gyro.value.x_gyro - base_x_gyro[4])/FS_SEL;
+  float gyro_y = (accel_t_gyro.value.y_gyro - base_y_gyro[4])/FS_SEL;
+  float gyro_z = (accel_t_gyro.value.z_gyro - base_z_gyro[4])/FS_SEL;
+
+
+  // Get raw acceleration values
+  //float G_CONVERT = 16384;
+  float accel_x = accel_t_gyro.value.x_accel;
+  float accel_y = accel_t_gyro.value.y_accel;
+  float accel_z = accel_t_gyro.value.z_accel;
+
+  // Get angle values from accelerometer
+  float RADIANS_TO_DEGREES = 180/3.14159;
+//  float accel_vector_length = sqrt(pow(accel_x,2) + pow(accel_y,2) + pow(accel_z,2));
+  float accel_angle_y = atan(-1*accel_x/sqrt(pow(accel_y,2) + pow(accel_z,2)))*RADIANS_TO_DEGREES;
+  float accel_angle_x = atan(accel_y/sqrt(pow(accel_x,2) + pow(accel_z,2)))*RADIANS_TO_DEGREES;
+
+  float accel_angle_z = 0;
+
+  // Compute the (filtered) gyro angles
+  float dt =(t_now - get_last_time(4))/1000.0;
+  float gyro_angle_x = gyro_x*dt + get_last_x_angle(4);
+  float gyro_angle_y = gyro_y*dt + get_last_y_angle(4);
+  float gyro_angle_z = gyro_z*dt + get_last_z_angle(4);
+
+  // Compute the drifting gyro angles
+  float unfiltered_gyro_angle_x = gyro_x*dt + get_last_gyro_x_angle(4);
+  float unfiltered_gyro_angle_y = gyro_y*dt + get_last_gyro_y_angle(4);
+  float unfiltered_gyro_angle_z = gyro_z*dt + get_last_gyro_z_angle(4);
+
+  // Apply the complementary filter to figure out the change in angle - choice of alpha is
+  // estimated now.  Alpha depends on the sampling rate...
+  float alpha = 0.96;
+  float angle_x = alpha*gyro_angle_x + (1.0 - alpha)*accel_angle_x;
+  float angle_y = alpha*gyro_angle_y + (1.0 - alpha)*accel_angle_y;
+  float angle_z = gyro_angle_z;  //Accelerometer doesn't give z-angle
+
+  // Update the saved data with the latest values
+  set_last_read_angle_data(t_now, angle_x, angle_y, angle_z, unfiltered_gyro_angle_x, unfiltered_gyro_angle_y, unfiltered_gyro_angle_z, 4);
+
+  // Send the data to the serial port
+ /* mySerial.print(F("DEL:"));              //Delta T
+  mySerial.print(dt, DEC);
+  mySerial.print(F("#ACC:"));              //Accelerometer angle
+  mySerial.print(accel_angle_x, 2);
+  mySerial.print(F(","));
+  mySerial.print(accel_angle_y, 2);
+  mySerial.print(F(","));
+  mySerial.print(accel_angle_z, 2);
+  mySerial.print(F("#GYR:"));
+  Serial.print(unfiltered_gyro_angle_x, 2);        //Gyroscope angle
+  Serial.print(F(","));
+  Serial.print(unfiltered_gyro_angle_y, 2);
+  Serial.print(F(","));
+  Serial.print(unfiltered_gyro_angle_z, 2);*/
+  mySerial.println(F("Pinky Finger Angles x y z "));             //Filtered angle
+  mySerial.print(angle_x, DEC);
+  mySerial.println(F(","));
+  mySerial.print(angle_y, DEC);
+  mySerial.println(F(","));
+  mySerial.print(angle_z, DEC);
+  mySerial.println(F(""));
+
+  // Delay so we don't swamp the serial port
+
+         // nDevices++;
+
+        }
+      else if (error==4)
+        {
+          Serial.print(F("Unknown error at address 0x"));
+          if (address<16)
+            Serial.print("0");
+          Serial.println(address,HEX);
+        }
+
+
+}
+
+
+void calibrate_sensor1()
+{
+  int                   num_readings = 10;
+  float                 x_accel = 0;
+  float                 y_accel = 0;
+  float                 z_accel = 0;
+  float                 x_gyro = 0;
+  float                 y_gyro = 0;
+  float                 z_gyro = 0;
+  accel_t_gyro_union    accel_t_gyro;
+
+for(int j=7;j<=10;j++)
+      {
+
+        pinMode(j,OUTPUT);
+        digitalWrite(j,LOW);
+
+      }
+  pinMode(6,OUTPUT);
+        digitalWrite(6,HIGH);
+  //Serial.println("Starting Calibration");
+
+  // Discard the first set of values read from the IMU
+  read_gyro_accel_vals((uint8_t *) &accel_t_gyro);
+
+  // Read and average the raw values from the IMU
+  for (int i = 0; i < num_readings; i++) {
+    read_gyro_accel_vals((uint8_t *) &accel_t_gyro);
+    x_accel += accel_t_gyro.value.x_accel;
+    y_accel += accel_t_gyro.value.y_accel;
+    z_accel += accel_t_gyro.value.z_accel;
+    x_gyro += accel_t_gyro.value.x_gyro;
+    y_gyro += accel_t_gyro.value.y_gyro;
+    z_gyro += accel_t_gyro.value.z_gyro;
+    delay(100);
+  }
+  x_accel /= num_readings;
+  y_accel /= num_readings;
+  z_accel /= num_readings;
+  x_gyro /= num_readings;
+  y_gyro /= num_readings;
+  z_gyro /= num_readings;
+
+  // Store the raw calibration values globally
+  base_x_accel[0] = x_accel;
+  base_y_accel[0] = y_accel;
+  base_z_accel[0] = z_accel;
+  base_x_gyro[0] = x_gyro;
+  base_y_gyro[0] = y_gyro;
+  base_z_gyro[0] = z_gyro;
+
+
+
+}
+void calibrate_sensor2()
+{
+  int                   num_readings = 10;
+  float                 x_accel = 0;
+  float                 y_accel = 0;
+  float                 z_accel = 0;
+  float                 x_gyro = 0;
+  float                 y_gyro = 0;
+  float                 z_gyro = 0;
+  accel_t_gyro_union    accel_t_gyro;
+
+for(int j=6;j<=10;j++)
+      {
+
+        pinMode(j,OUTPUT);
+        digitalWrite(j,LOW);
+
+      }
+  pinMode(7,OUTPUT);
+        digitalWrite(7,HIGH);
+  //Serial.println("Starting Calibration");
+
+  // Discard the first set of values read from the IMU
+  read_gyro_accel_vals((uint8_t *) &accel_t_gyro);
+
+  // Read and average the raw values from the IMU
+  for (int i = 0; i < num_readings; i++) {
+    read_gyro_accel_vals((uint8_t *) &accel_t_gyro);
+    x_accel += accel_t_gyro.value.x_accel;
+    y_accel += accel_t_gyro.value.y_accel;
+    z_accel += accel_t_gyro.value.z_accel;
+    x_gyro += accel_t_gyro.value.x_gyro;
+    y_gyro += accel_t_gyro.value.y_gyro;
+    z_gyro += accel_t_gyro.value.z_gyro;
+    delay(100);
+  }
+  x_accel /= num_readings;
+  y_accel /= num_readings;
+  z_accel /= num_readings;
+  x_gyro /= num_readings;
+  y_gyro /= num_readings;
+  z_gyro /= num_readings;
+
+  // Store the raw calibration values globally
+  base_x_accel[1] = x_accel;
+  base_y_accel[1] = y_accel;
+  base_z_accel[1] = z_accel;
+  base_x_gyro[1] = x_gyro;
+  base_y_gyro[1] = y_gyro;
+  base_z_gyro[1] = z_gyro;
+}
+void calibrate_sensor3()
+{
+    int                   num_readings = 10;
+  float                 x_accel = 0;
+  float                 y_accel = 0;
+  float                 z_accel = 0;
+  float                 x_gyro = 0;
+  float                 y_gyro = 0;
+  float                 z_gyro = 0;
+  accel_t_gyro_union    accel_t_gyro;
+
+for(int j=6;j<=10;j++)
+      {
+
+        pinMode(j,OUTPUT);
+        digitalWrite(j,LOW);
+
+      }
+  pinMode(8,OUTPUT);
+        digitalWrite(8,HIGH);
+  //Serial.println("Starting Calibration");
+
+  // Discard the first set of values read from the IMU
+  read_gyro_accel_vals((uint8_t *) &accel_t_gyro);
+
+  // Read and average the raw values from the IMU
+  for (int i = 0; i < num_readings; i++) {
+    read_gyro_accel_vals((uint8_t *) &accel_t_gyro);
+    x_accel += accel_t_gyro.value.x_accel;
+    y_accel += accel_t_gyro.value.y_accel;
+    z_accel += accel_t_gyro.value.z_accel;
+    x_gyro += accel_t_gyro.value.x_gyro;
+    y_gyro += accel_t_gyro.value.y_gyro;
+    z_gyro += accel_t_gyro.value.z_gyro;
+    delay(100);
+  }
+  x_accel /= num_readings;
+  y_accel /= num_readings;
+  z_accel /= num_readings;
+  x_gyro /= num_readings;
+  y_gyro /= num_readings;
+  z_gyro /= num_readings;
+
+  // Store the raw calibration values globally
+  base_x_accel[2] = x_accel;
+  base_y_accel[2] = y_accel;
+  base_z_accel[2] = z_accel;
+  base_x_gyro[2] = x_gyro;
+  base_y_gyro[2] = y_gyro;
+  base_z_gyro[2] = z_gyro;
+}
+void calibrate_sensor4()
+{
+    int                   num_readings = 10;
+  float                 x_accel = 0;
+  float                 y_accel = 0;
+  float                 z_accel = 0;
+  float                 x_gyro = 0;
+  float                 y_gyro = 0;
+  float                 z_gyro = 0;
+  accel_t_gyro_union    accel_t_gyro;
+
+for(int j=6;j<=10;j++)
+      {
+
+        pinMode(j,OUTPUT);
+        digitalWrite(j,LOW);
+
+      }
+  pinMode(9,OUTPUT);
+        digitalWrite(9,HIGH);
+  //Serial.println("Starting Calibration");
+
+  // Discard the first set of values read from the IMU
+  read_gyro_accel_vals((uint8_t *) &accel_t_gyro);
+
+  // Read and average the raw values from the IMU
+  for (int i = 0; i < num_readings; i++) {
+    read_gyro_accel_vals((uint8_t *) &accel_t_gyro);
+    x_accel += accel_t_gyro.value.x_accel;
+    y_accel += accel_t_gyro.value.y_accel;
+    z_accel += accel_t_gyro.value.z_accel;
+    x_gyro += accel_t_gyro.value.x_gyro;
+    y_gyro += accel_t_gyro.value.y_gyro;
+    z_gyro += accel_t_gyro.value.z_gyro;
+    delay(100);
+  }
+  x_accel /= num_readings;
+  y_accel /= num_readings;
+  z_accel /= num_readings;
+  x_gyro /= num_readings;
+  y_gyro /= num_readings;
+  z_gyro /= num_readings;
+
+  // Store the raw calibration values globally
+  base_x_accel[3] = x_accel;
+  base_y_accel[3] = y_accel;
+  base_z_accel[3] = z_accel;
+  base_x_gyro[3] = x_gyro;
+  base_y_gyro[3] = y_gyro;
+  base_z_gyro[3] = z_gyro;
+}
+void calibrate_sensor5()
+{
+    int                   num_readings = 10;
+  float                 x_accel = 0;
+  float                 y_accel = 0;
+  float                 z_accel = 0;
+  float                 x_gyro = 0;
+  float                 y_gyro = 0;
+  float                 z_gyro = 0;
+  accel_t_gyro_union    accel_t_gyro;
+
+for(int j=6;j<=9;j++)
+      {
+
+        pinMode(j,OUTPUT);
+        digitalWrite(j,LOW);
+
+      }
+  pinMode(10,OUTPUT);
+        digitalWrite(10,HIGH);
+  //Serial.println("Starting Calibration");
+
+  // Discard the first set of values read from the IMU
+  read_gyro_accel_vals((uint8_t *) &accel_t_gyro);
+
+  // Read and average the raw values from the IMU
+  for (int i = 0; i < num_readings; i++) {
+    read_gyro_accel_vals((uint8_t *) &accel_t_gyro);
+    x_accel += accel_t_gyro.value.x_accel;
+    y_accel += accel_t_gyro.value.y_accel;
+    z_accel += accel_t_gyro.value.z_accel;
+    x_gyro += accel_t_gyro.value.x_gyro;
+    y_gyro += accel_t_gyro.value.y_gyro;
+    z_gyro += accel_t_gyro.value.z_gyro;
+    delay(100);
+  }
+  x_accel /= num_readings;
+  y_accel /= num_readings;
+  z_accel /= num_readings;
+  x_gyro /= num_readings;
+  y_gyro /= num_readings;
+  z_gyro /= num_readings;
+
+  // Store the raw calibration values globally
+  base_x_accel[4] = x_accel;
+  base_y_accel[4] = y_accel;
+  base_z_accel[4] = z_accel;
+  base_x_gyro[4] = x_gyro;
+  base_y_gyro[4] = y_gyro;
+  base_z_gyro[4] = z_gyro;
+}
+
+


Beautifying and comments

Beautifying and comments

--- Arduino/arduino.ino
+++ Arduino/arduino.ino
@@ -61,15 +61,18 @@
   EthernetUDP udp;
   byte ethernetMac[] = ETHERNET_MAC;
 #endif
+
 #ifdef USE_WIFI_SHIELD
   WiFiServer server = WiFiServer(SERVER_PORT);
   WiFiUDP udp;
   int connectionStatus = WL_IDLE_STATUS;
 #endif
+
 #ifdef USE_STROMBEWUSST_SERVER
   // UDP Format: <32xkey><1xtimeframe><1xticks>
   char udpBuffer[34] = STROMBEWUSST_KEY;
 #endif
+
 // TimeStorage - stores the # of bytes needed to store the information
 const int timeStorage = 60 / TIMEFRAME * 60 * STORAGE_HOURS;
 byte storage[timeStorage];
@@ -79,6 +82,7 @@

 void setup() {
   Serial.begin(9600);
+
   pinMode(TRIGGER_PIN, INPUT);

   #ifdef USE_WIFI_SHIELD
@@ -108,7 +112,10 @@

 void loop()
 {
+  // Check if time moved on to a new frame
   pointerLoop();
+
+  // Check if we got a signal right now
   triggerCheck();
 }

@@ -213,12 +220,11 @@
   int pos = storagePointer;
   for (int i=0; i<frames; i++)
   {
-    pos--;
-    if (pos == -1)
+    if (--pos == -1)
     {
       pos = timeStorage-1;
     }
-    sum = sum + (int)storage[pos];
+    sum += (int)storage[pos];
   }
   return sum;
 }


Autoconnect to remote control with buzzer information

--- Arduino/Communication/Communication.ino
+++ Arduino/Communication/Communication.ino
@@ -1,36 +1,87 @@
 #include <SPI.h>

+#define MAX_INTERRUPT_TIME 100
+
 const int slaveSelectPin = 46;
+const int buzzerPin = A0;
+
+int buzzer = 0;
+int beeps = 0;
+bool on = false;

 double lastTime;
+bool droneConnected = false;

 void setup() {
   Serial.begin(9600);

   pinMode(slaveSelectPin, OUTPUT);
+  pinMode(buzzerPin, INPUT);
+  pinMode(LED_BUILTIN, OUTPUT);
+
   SPI.begin();

-  Serial.write(' ');
   lastTime = millis();
+
+  //   Controller calibrates the middle at startup
+  for (int i = 0; i < 4; i++) digitalPotWrite(i, 127);
 }

 void loop() {
-  if (millis() - lastTime > 500) {
-    for (int i = 0; i < 4; i++) digitalPotWrite(i, 0);
+  buzzer = analogRead(buzzerPin);
+
+  if (buzzer > 400) on = true;
+
+  if (buzzer == 0 && on) {
+    switch (beeps) {
+      case 0:
+        digitalPotWrite(0, 0);
+        delay(1000);
+        break;
+      case 1:
+        delay(2000);
+        digitalPotWrite(0, 255);
+        break;
+      case 2:
+        delay(1000);
+        digitalPotWrite(0, 0);
+        break;
+      case 3:
+        delay(1000);
+        droneConnected = true;
+        Serial.write(' ');
+    }
+    beeps++;
+    delay(100);
+  }
+
+  if (droneConnected && millis() - lastTime > MAX_INTERRUPT_TIME) {
+    digitalPotWrite(0, 0);
+    Serial.write(' ');
+    digitalWrite(LED_BUILTIN, HIGH);
+  } else {
+    digitalWrite(LED_BUILTIN, LOW);
   }
 }

 void serialEvent() {
-  if (Serial.available() == 4) {
+  // throttle min      0 max      255
+  // pitch    backward 0 forward  255
+  // roll     left     0 right    255
+  // yaw      left     0 right    255
+
+  if (droneConnected && Serial.available() == 4) {
     for (int i = 0; i < 4; i++) digitalPotWrite(i, Serial.read() + 127);
     Serial.write(' ');
     lastTime = millis();
+  } else {
+    for (int i = 1; i < 4; i++) digitalPotWrite(i, 127);
   }
 }

 void digitalPotWrite(int address, int value) {
   digitalWrite(slaveSelectPin, LOW);
   SPI.transfer(address);
-  SPI.transfer(255 - value);
+  SPI.transfer(value);
   digitalWrite(slaveSelectPin, HIGH);
 }


Remove wind code

Remove wind code

--- Guzheng/Guzheng.ino
+++ Guzheng/Guzheng.ino
@@ -3,13 +3,6 @@
  *
  * Licensed under the MIT License
  */
-
-/* Uncomment the define if you are using a wind instrument, such
- * as a trumpet or flute. It will disable several things that
- * are specific to string and percussion instruments. DO NOT
- * uncomment it if you are using a piano or string instrument!
- */
-// #define WIND

 // Port I/O defines
 #define THRESHOLD 500
@@ -156,7 +149,6 @@
       buttonState = 0;
     }
     if(analogRead(i) > THRESHOLD) {
-#ifndef WIND
       /* Apply the AND operator to the lastNote indicator and the
        * corresponding value from the laser array to check if the
        * laser bit has been set or not
@@ -164,17 +156,13 @@
        * If it returns a non zero value, then that means it is set.
        * If it is a zero, then the bit has not been set yet */
       if (!(lastNote & (laserArray[i]))) {
-#endif
         // Beam has been cut
         musicOn(i);
-#ifndef WIND
         /* Set the bit using the OR operator between lastNote and
          * the corresponding value from the laser array */
         lastNote |= (laserArray[i]);
       }
-#endif
     } else {
-#ifndef WIND
       /* Check if the last note bit has been set or not using the
        * AND operator. This won't always be true because this section
        * of the code runs even if the beam hasn't been cut yet */
@@ -182,7 +170,6 @@
         /* Unset the flag using the AND and invert operators */
         lastNote &= ~(laserArray[i]);
       }
-#endif
       // Hand is gone. Stop the sound
       musicOff(i);
     }


BitBanging_Multiple

BitBanging_Multiple

Updated Arduino Code for 5 MPUs connected to Arduino Pro Mini

--- BitBangingMpu6050/BitBangingMpu6050.ino
+++ BitBangingMpu6050/BitBangingMpu6050.ino
@@ -600,9 +600,9 @@
 // But only if the AD0 pin is low.
 // Some sensor boards have AD0 high, and the
 // I2C address thus becomes 0x69.
-#define MPU6050_I2C_ADDRESS 0x68
-
-
+#define MPU6050_I2C_ADDRESS 0x69
+
+ int flag=6;
 // Declaring an union for the registers and the axis values.
 // The byte order does not match the byte order of
 // the compiler and AVR chip.
@@ -642,10 +642,16 @@
     int16_t z_gyro;
   } value;
 };
-
-
-const int MPU_addr=0x68;  // I2C address of the MPU-6050
-int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;
+int pin3=3;
+int pin6=6;
+int pin7=7;
+int pin8=8;
+int pin9=9;
+
+
+const int MPU_addr=0x69;  // I2C address of the MPU-6050
+//int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;
+
 void setup(){

  int error;
@@ -659,6 +665,19 @@
   Serial.println(F("June 2012"));

   while (!Serial);             // Leonardo: wait for serial monitor
+  int i;
+    for(i=6;i<=10;i++)
+    {
+      for(int j=6;j<=10;j++)
+      {
+        if(i!=j)
+        {
+          pinMode(j,OUTPUT);
+        digitalWrite(j,LOW);
+        }
+      }
+      pinMode(i,OUTPUT);
+      digitalWrite(i,HIGH);
   error = MPU6050_read (MPU6050_WHO_AM_I, &c, 1);
   Serial.print(F("WHO_AM_I : "));
   Serial.print(c,HEX);
@@ -674,23 +693,32 @@
   Serial.print(c,HEX);
   Serial.print(F(", error = "));
   Serial.println(error,DEC);
-
+

   // Clear the 'sleep' bit to start the sensor.
   MPU6050_write_reg (MPU6050_PWR_MGMT_1, 0);
   Serial.println("\nI2C Scanner");
-
+    }
 }
 void loop(){

 byte error, address;
+address=105;
   int nDevices;

   Serial.println(F("Scanning I2C bus (7-bit addresses) ..."));
-
   nDevices = 0;
-  for(address = 1; address < 127; address++ )
-    {
+  for(int j=6;j<=10;j++)
+      {
+        if(flag!=j)
+        {
+        pinMode(j,OUTPUT);
+        digitalWrite(j,LOW);
+
+        }
+      }
+      pinMode(flag,OUTPUT);
+      digitalWrite(flag,HIGH);
       // The i2c_scanner uses the return value of
       // the Write.endTransmisstion to see if
       // a device did acknowledge to the address.
@@ -699,6 +727,8 @@

       if (error == 0)
         {
+          Serial.print("MPU number : ");
+          Serial.println(flag-5);
           Serial.print(F("I2C device found at address 0x"));
           if (address<16)
             Serial.print(F("0"));
@@ -775,24 +805,29 @@
   Serial.print(F(", "));
   Serial.println(F(""));

-  delay(1000);
+ //delay(1000);

           nDevices++;
+
         }
       else if (error==4)
         {
-          Serial.print(F("Unknow error at address 0x"));
+          Serial.print(F("Unknown error at address 0x"));
           if (address<16)
             Serial.print("0");
           Serial.println(address,HEX);
         }
-    }
+
   if (nDevices == 0)
     Serial.println("No I2C devices found\n");
   else
     Serial.println("done\n");
-
+
+  if(flag==1078io)
+    flag=6;
+    else
+      flag++;
   //delay(5000);           // wait 5 seconds for next scan
 }


Update Ball-Board.ino

Update Ball-Board.ino

--- Firmware/Ball/Ball-Board/Ball-Board.ino
+++ Firmware/Ball/Ball-Board/Ball-Board.ino
@@ -624,97 +624,97 @@
     	    if(directX) directX = false;
     	    else directX = true;
   	}
-  		digitalWrite(pinDirX, directX); // dirX
-
-  		// Si ont doit demarer le moteur
-  		if(x > (setpointX + hysteresis) || (x < setpointX - hysteresis ))
-  		{
-    		if(x > minX && x < maxX) runX = true;
-    		else runX = false;
-  		}
-  		else runX = false;
+  	digitalWrite(pinDirX, directX); // dirX
+
+  	// Si ont doit demarer le moteur
+  	if(x > (setpointX + hysteresis) || (x < setpointX - hysteresis ))
+  	{
+    	    if(x > minX && x < maxX) runX = true;
+    	    else runX = false;
+  	}
+  	else runX = false;

-  		// Calcul du PID X
-  		if(x < 90) vx = (90 - x);
-  		if(x == 0) vx = 0;
-  		if(x > 90) vx = (x - 90);
-
-  		speedX = 1000 / (vx);
-  		speedX = speedX * multiplier; // DEL
-  		if(speedX < 15) speedX = 15;
-
-		// Mise en route du moteur
-  		unsigned long currentX = millis();
+  	// Calcul du PID X
+  	if(x < 90) vx = (90 - x);
+  	if(x == 0) vx = 0;
+  	if(x > 90) vx = (x - 90);
+
+  	speedX = 1000 / (vx);
+  	speedX = speedX * multiplier; // DEL
+  	if(speedX < 15) speedX = 15;
+
+	// Mise en route du moteur
+  	unsigned long currentX = millis();

     	if (currentX - previousMillisX >= speedX)
     	{
-      		previousMillisX = currentX;
-
-      		if(runX)
-      		{
-        		digitalWrite(pinStepX, 1);
-        		delayMicroseconds( 500 );
-        		digitalWrite(pinStepX, 0);
-    	 		delayMicroseconds( 500 );
-      		}
-  		}
+      	    previousMillisX = currentX;
+
+	    if(runX)
+      	    {
+                digitalWrite(pinStepX, 1);
+        	delayMicroseconds( 500 );
+        	digitalWrite(pinStepX, 0);
+    	 	delayMicroseconds( 500 );
+            }
+  	}

     	//======================================================================
-		// Y88b   d88P
-		//  Y88b d88P
-  		//   Y88o88P
-   		//    Y888P
+	// Y88b   d88P
+	//  Y88b d88P
+  	//   Y88o88P
+   	//    Y888P
     	//     888
     	//     888
         //     888
         //     888
-		//======================================================================
-
-  		// Direction
-  		if(y < 90) directY = false;
-  		else directY = true;
-  		if(invertY)
-  		{
-    		if(directY) directY = false;
-    		else directY = true;
-  		}
-  		digitalWrite(pinDirY, directY);
-
-		// Si ont doit demarer le moteur
-  		if(y > (setpointY + hysteresis) || (y < setpointY - hysteresis ))
-  		{
-    		if(y > minY && y < maxY) runY = true;
-    		else runY = false;
-  		}
-  		else runY = false;
-
-  		// Calcul du PID Y
-  		if(y < 90) vy = (90 - y);
-  		if(y == 0) vy = 0;
-  		if(y > 90) vy = (y - 90);
-
-  		speedY = 1000 / (vy);
-  		speedY = speedY * multiplier; // DEL
-  		if(speedY < 15) speedY = 15;
+	//======================================================================
+
+	// Direction
+  	if(y < 90) directY = false;
+  	else directY = true;
+  	if(invertY)
+  	{
+    	    if(directY) directY = false;
+    	    else directY = true;
+  	}
+  	digitalWrite(pinDirY, directY);
+
+	// Si ont doit demarer le moteur
+  	if(y > (setpointY + hysteresis) || (y < setpointY - hysteresis ))
+  	{
+    	    if(y > minY && y < maxY) runY = true;
+    	    else runY = false;
+  	}
+  	else runY = false;
+
+  	// Calcul du PID Y
+  	if(y < 90) vy = (90 - y);
+  	if(y == 0) vy = 0;
+  	if(y > 90) vy = (y - 90);
+
+  	speedY = 1000 / (vy);
+  	speedY = speedY * multiplier; // DEL
+  	if(speedY < 15) speedY = 15;

-  		// Mise en route du moteur
-  		unsigned long currentY = millis(); // millis();
+	// Mise en route du moteur
+  	unsigned long currentY = millis(); // millis();

     	if (currentY - previousMillisY >= speedY)
     	{
-      		previousMillisY = currentY;
+      	    previousMillisY = currentY;

-      		if(runY)
-      		{
-        		digitalWrite(pinStepY, 1);
-        		delayMicroseconds( 500 );
-        		digitalWrite(pinStepY, 0);
-        		delayMicroseconds( 500 );
-      		}
-  		}
+            if(runY)
+      	    {
+        	digitalWrite(pinStepY, 1);
+        	delayMicroseconds( 500 );
+        	digitalWrite(pinStepY, 0);
+        	delayMicroseconds( 500 );
+            }
+  	}

     	//======================================================================
-		// 8888888888P
+	// 8888888888P
         //       d88P
         //      d88P
     	//     d88P
@@ -722,35 +722,32 @@
         //   d88P
         //  d88P
         // d8888888888
-		//======================================================================
+	//======================================================================

-		digitalWrite(pinDirZ, directZ);
-		if(speedZ != 0)
-  		{
-  			unsigned long currentZ = millis();
-  			if (currentZ - previousMillisZ >= speedZ)
-    		{
-      			previousMillisZ = currentZ;
-
-    	 		digitalWrite(pinStepY, 1);
+	digitalWrite(pinDirZ, directZ);
+	if(speedZ != 0)
+  	{
+  	    unsigned long currentZ = millis();
+
+	    if (currentZ - previousMillisZ >= speedZ)
+    	    {
+      		previousMillisZ = currentZ;
+
+		digitalWrite(pinStepY, 1);
     	    	delayMicroseconds( 500 );
     	    	digitalWrite(pinStepY, 0);
     	    	delayMicroseconds( 500 );
     	    	if(directZ) Zangle++;
     	    	else Zangle--;
-  			}
-  		}
-  		if(Zangle == 201) Zangle = 0;
-  		if(Zangle == -1)  Zangle = 0;
-
-
-  }
-
-
-
-
-
-  	// SEND SERIAL DATA
+  	    }
+  	}
+
+	if(Zangle == 201) Zangle = 0;
+  	if(Zangle == -1)  Zangle = 0;
+
+    }
+
+    // TRIGGER / SEC
     //-------------------------------------------------------------------------//
     unsigned long currentS = millis(); // millis();

@@ -763,24 +760,18 @@
     	else LED_PING = true;
     	digitalWrite(PING, LED_PING);

-
-
-
-
-
+	// IF THE MPU6050 ARE ALWAYS CONNECTED, IF NOT, HE RECONNECT AUTOMATICLY
     	if(!accelgyro.testConnection());
     	{
-    		production = false;
-    		emgStop = true;
-    		accelgyro.initialize();
-    		if(accelgyro.testConnection())
-    		{
-    			production = true;
-    		}
+    	    production = false;
+    	    emgStop = true;
+    	    accelgyro.initialize();
+    	    if(accelgyro.testConnection())
+    	    {
+    		production = true;
+    	    }
     	}
-
-
-
+
     	/*

     	// SEND STATUT
@@ -802,5 +793,38 @@
     	Serial.println(" ");

     	*/
-    }
+    } // ENF OF PRODUCTION
+} // END OF LOOP
+
+// VOID FOR TAKE THE CURRENT
+int current(int Cpin)
+{
+    int mVperAmp = 185; // use 100 for 20A Module and 66 for 30A Module
+    int RawValue= 0;
+    int ACSoffset = 2500;
+    double Voltage = 0;
+    double Amps = 0;
+
+    RawValue = analogRead(Cpin);
+    Voltage = (RawValue / 1024.0) * 5000; // Gets you mV
+    Amps = ((Voltage - ACSoffset) / mVperAmp);
+
+    return(Amps);
 }
+
+// VOID FOR TAKE THE BATTERY VOLTAGE
+int voltage(int Vpin)
+{
+    float vout = 0.0;
+    float vin = 0.0;
+    float R1 = 100000.0; // resistance of R1 (100K) -see text!
+    float R2 = 10000.0; // resistance of R2 (10K) - see text!
+    int value = 0;
+
+    value = analogRead(Vpin);
+    vout = (value * 5.0) / 1024.0;
+    vin = vout / (R2/(R1+R2));
+    if (vin<0.09) vin=0.0;
+
+    return(vin);
+}


Corrected = to == in condition - arrgggghhh

--- ESP8266-code/HackspacePIREnv.ino
+++ ESP8266-code/HackspacePIREnv.ino
@@ -83,7 +83,7 @@
    String data =String("occupied=") + pir_active+"&rssi="+rssi+"&temperatureC="+temp +"&humidity=" + humidity;
    Serial.println(data);
    log_data(data);
-   if (pir_active = 1)
+   if (pir_active == 1)
        log_anyonein();

    delay(60*1000);


corrected pinout for flex sensors

corrected pinout for flex sensors

--- Arduino/OSCGlove/OSCGlove.ino
+++ Arduino/OSCGlove/OSCGlove.ino
@@ -108,9 +108,9 @@
   if (now - next >= 0) {
     next = now + cycle_time_ms;

-    middle_finger = analogRead(A6);
-    ring_finger = analogRead(A9);
-    little_finger = analogRead(A10);
+    middle_finger = analogRead(A11);
+    ring_finger = analogRead(A10);
+    little_finger = analogRead(A9);
   }
 }


changed flex sensor input for middle finger

--- Arduino/OSCGlove/OSCGlove.ino
+++ Arduino/OSCGlove/OSCGlove.ino
@@ -108,7 +108,7 @@
   if (now - next >= 0) {
     next = now + cycle_time_ms;

-    middle_finger = analogRead(A7);
+    middle_finger = analogRead(A6);
     ring_finger = analogRead(A9);
     little_finger = analogRead(A10);
   }


Infer length of array rather than having a #define

--- moros/moros.ino
+++ moros/moros.ino
@@ -47,8 +47,7 @@
   void (* handle_button_press)();
 } player;

-#define PLAYER_COUNT 2
-player players[PLAYER_COUNT] = {
+player players[2] = {
   {
     INITIAL_TIME_MS,
     0,
@@ -78,7 +77,7 @@
   Serial.println("hello!");

   char timea[12];
-  for(int i = 0; i < PLAYER_COUNT; i++) {
+  for(int i = 0; i < sizeof(players) / sizeof(players[0]); i++) {
     players[i].tft.begin();
     players[i].tft.background(0,0,0);
     players[i].tft.stroke(255,255,255);


code for forward and back motions

code for forward and back motions

--- motor/motor.ino
+++ motor/motor.ino
@@ -36,14 +36,15 @@
   myservo.attach(11);
   int pos = myservo.read();

-  //set servo at 45 degrees to begin with
+  //set servo at to 180 degrees to begin with
   while (pos != 180) {
     myservo.write(pos);
     delay(15);
     pos++;
   }
-  myservo.write(130);
-  delay(2000);
+
+  openCage();
+  closeCage();
 }

 void loop() {
@@ -51,14 +52,12 @@

 //opens cage to deliver drink
 void openCage() {
-  myservo.write(85);
-  delay(1500);
+  myservo.write(130);
+  delay(5000);
 }

 //closes cage after delivery
 void closeCage() {
-  myservo.write(-85);
-  delay(1500);
+  myservo.write(180);
+  delay(5000);
 }
-
-//


Clear the text before setting the previous value

--- battery_indicator/battery_indicator.ino
+++ battery_indicator/battery_indicator.ino
@@ -28,7 +28,7 @@

   int bat_val = battery.update();
   if (bat_val != bat_val_prev) {
-    bat_val_prev = bat_val;
+
     // Large number center screen
     // Clear
     Robot.stroke(0,0,0);
@@ -41,6 +41,8 @@

     Robot.textSize(2);
     Robot.text("mV", 92, 58);
+
+    bat_val_prev = bat_val;
   }

   delay(2000);


update me commentaar

update me commentaar

--- programma/programma.ino
+++ programma/programma.ino
@@ -5,24 +5,21 @@
 #include <SPI.h>
 #include <nRF24L01.h>
 #include <RF24.h>
-//#include <SoftwareSerial.h>
-//SoftwareSerial mySerial(3, 2); // RX, TX , maakt een serieele poort aan op pin 3 en 2
-int RadioZekerUit=0;

 /*-----( Declare objects )-----*/
 RF24 radio(CE_PIN, CSN_PIN); // Create a Radio
-bool schuinKijken = false;
+
 void setup() {

-  Serial.begin(9600);
-  //mySerial.begin(9600);
+  Serial.begin(9600);              // begin met de serieele communicatie
+
   pinMode(LmotorA,OUTPUT);        // zet de pinnen voor de H brug op output
   pinMode(RmotorA,OUTPUT);
   pinMode(LmotorB,OUTPUT);
   pinMode(RmotorB,OUTPUT);

-  pinMode(Achteruit, OUTPUT);
+  pinMode(Achteruit, OUTPUT);     //pinnen voor de mp3 trigger
   pinMode(Roses, OUTPUT);
   pinMode(Vooruit, OUTPUT);

@@ -35,53 +32,46 @@
 void loop() {
    Snelheid = 1500;             // zet snelheid in de center positie
    Stuur = 1500;                // zet stuur in de center positie
-   currentMillis = millis(); // wordt gebruikt voor verschillende time-outs
+   currentMillis = millis();    // wordt gebruikt voor verschillende time-outs

  if (radio.available() )       // kijkt of er een RF signaal is
   {
-    RadioZekerUit = 0;
-    if(!myserialuit){
+    RadioZekerUit = 0;         //Zorgt ervoor dat je nog in de radio if blijft
+    if(!myserialuit){          //zet de serial uit, voor extra performantie
       Serial.end();
       myserialuit = true;
     }

     // Fetch the data payload

-      done = radio.read(input, sizeof(input));
+      done = radio.read(input, sizeof(input));

       Snelheid= (input[1])+1000;     // geeft de geontvangde data door aan snelheid.
-      /*if (Snelheid < 1300) digitalWrite(Achteruit, LOW);
-      else digitalWrite(Achteruit, HIGH);*/
-
-      /*if (Snelheid > 1700) digitalWrite(Vooruit, LOW);
-      else digitalWrite(Vooruit, HIGH);*/
+
       Stuur  = (input[2])+1000;     // geeft de geontvangde data door aan stuur.
-      Rij();
+      Rij();                        //roept de rij methode aan om de motors aan te sturen

     }
-  else if(RadioZekerUit>3000) {
+  else if(RadioZekerUit>3000) {   //als er geen radio communicatie is ga erin

-      if(myserialuit){
-        Serial.begin(9600);
+      if(myserialuit){           //als de seriele communicatie uit staat zet deze aan
+        Serial.begin(9600);
         myserialuit = false;
       }

-      if (Serial.available() > 1) {
-        reader = Serial.parseInt();
-        delay(2);
+      if (Serial.available() > 1) {  //leest de seriele communicatie uit
+        reader = Serial.parseInt();    // zet de seriele data om in een int
+        delay(2);
       }

-
-
-       Automatichrijden();
-
-
-  }else if(RadioZekerUit<3002){
+       Automatichrijden();         //al de methodes die kunnen worden aangeroepen door de nano
+
+  }else if(RadioZekerUit<3002){    // zorgt ervoor dat men checkt of er geen radio singalen meer aankomen
        RadioZekerUit ++;
     }
 }
@@ -90,57 +80,62 @@

 //*-------------------------------------Methodes automatisch rijden----------------------------------------*/
 void Automatichrijden(){
-    if(reader == 11){
+    if(reader == 11){             //als er een 11 wordt doorgestuurd stop de wagen
       Stoop();
-    }else if(reader == 2){
+    }else if(reader == 2){        //als er een 2 wordt doorgestuurd laat de wagen traag rijden
       Snelheid = 1650;
       Stuur = 1500;
       Rij();
-    }else if(reader == 5){
+    }else if(reader == 5){        //als er een 5 wordt doorgestuurd laat de wagen snel rijden
       Snelheid = 1800;
       Stuur = 1500;
       Rij();
-    }else if(reader == 3){
+    }else if(reader == 3){        //als er een 3 wordt doorgestuurd laat de wagen 90 graden naar rechts draaien
       RechtsDraaien90();
     }
-    else if(reader == 4){
+    else if(reader == 4){         //als er een 4 wordt doorgestuurd laat de wagen naar links draaien
       LinksDraaien90();
+    }else if(reader == 6){        //als er een 6 wordt doorgestuurd draai de wagen volledig rond zijn as
+      Draaien180();
     }else{
-      Stoop();
-    }
-}
-
-void RechtsDraaien90(){
+      Stoop();                    // als er een onbekende waarde wordt doorgestuurd stop de wagen
+    }
+}
+
+void RechtsDraaien90(){        //methode om rechts te draaien
     Snelheid = 1500;
     Stuur = 2023;
     Rij();
-    delay(1500);
+    delay(2000);
     Stoop();
     reader=0;
     delay(1500);
 }

-
-void LinksDraaien90(){
+void Draaien180(){            //methode om rond zijn as te draaien
+    Snelheid = 1500;
+    Stuur = 2023;
+    Rij();
+    delay(3500);
+    Stoop();
+    reader=0;
+    delay(1500);
+}
+
+void LinksDraaien90(){       //methode om links te draaien

     Snelheid = 1500;
     Stuur = 1023;
     Rij();
-    delay(1500);
+    delay(2000);
     Stoop();
     reader=0;
     delay(1500);
 }

-void AchteruitRijden(){
-  Snelheid = 1500;
-  Stuur = 2023;
-  Rij();
-  delay(2000);
-  Stoop();
-}
-
-void Stoop(){
+
+
+void Stoop(){              //methode om de wagen te laten stoppen
   Snelheid = 1500;
   Stuur = 1500;
   Rij();
@@ -148,25 +143,7 @@

 }

-//----------------------------------------------Methodes voor zigzag---------------------------------------
-
-/*void Draaien90() {
-    Snelheid = 1500;
-    if (rechtsDraaien == true) {Stuur = 2023; rechtsDraaien = false;}
-    else { Stuur = 1023; rechtsDraaien = true; }
-    Rij();
-    delay(2000);
-    Stoop();
-    delay(200);
-}*/
-
-void Links30() {
-  Snelheid = 1500;
-  Stuur = 2023;
-  Rij();
-  delay(500);
-  Stoop();
-}
+

     //------------------------------------------------------------ Code voor RC inputs. ---------------------------------------------------------


try_to_add_food() added

try_to_add_food() added

--- SmartFeeder/SmartFeeder/SmartFeeder.ino
+++ SmartFeeder/SmartFeeder/SmartFeeder.ino
@@ -76,3 +76,14 @@
   }
   return true;
 }
+
+bool try_to_add_food(bool option)
+{
+  if(option = true || !is_bowl_full())
+  {
+    run_motor();
+    return true;
+  }
+  return false;
+}
+


Remove Serial initialization

Remove Serial initialization

--- examples/DmxSerialRecv/DmxSerialRecv.ino
+++ examples/DmxSerialRecv/DmxSerialRecv.ino
@@ -1,70 +1,68 @@
-// - - - - -
-// DmxSerial - A hardware supported interface to DMX.
-// DmxSerialRecv.ino: Sample DMX application for retrieving 3 DMX values:
-// address 1 (red) -> PWM Port 9
-// address 2 (green) -> PWM Port 6
-// address 3 (blue) -> PWM Port 5
-//
-// Copyright (c) 2011-2015 by Matthias Hertel, http://www.mathertel.de
-// This work is licensed under a BSD style license. See http://www.mathertel.de/License.aspx
-//
-// Documentation and samples are available at http://www.mathertel.de/Arduino
-// 25.07.2011 creation of the DmxSerial library.
-// 10.09.2011 fully control the serial hardware register
-//            without using the Arduino Serial (HardwareSerial) class to avoid ISR implementation conflicts.
-// 01.12.2011 include file and extension changed to work with the Arduino 1.0 environment
-// 28.12.2011 changed to channels 1..3 (RGB) for compatibility with the DmxSerialSend sample.
-// 10.05.2012 added some lines to loop to show how to fall back to a default color when no data was received since some time.
-// - - - - -
-
-#include <DMXSerial.h>
-
-// Constants for demo program
-
-const int RedPin =    9;  // PWM output pin for Red Light.
-const int GreenPin =  6;  // PWM output pin for Green Light.
-const int BluePin =   5;  // PWM output pin for Blue Light.
-
-// This Example receives the 3 values starting with this channel:
-const int startChannel = 0 * 3 + 1;
-
-#define RedDefaultLevel   100
-#define GreenDefaultLevel 200
-#define BlueDefaultLevel  255
-
-void setup() {
-  Serial.begin(115200);
-
-  DMXSerial.init(DMXReceiver);
-
-  // set some default values
-  DMXSerial.write(1, 80);
-  DMXSerial.write(2, 0);
-  DMXSerial.write(3, 0);
-
-  // enable pwm outputs
-  pinMode(RedPin,   OUTPUT); // sets the digital pin as output
-  pinMode(GreenPin, OUTPUT);
-  pinMode(BluePin,  OUTPUT);
-}
-
-
-void loop() {
-  // Calculate how long no data backet was received
-  unsigned long lastPacket = DMXSerial.noDataSince();
-
-  if (lastPacket < 5000) {
-    // read recent DMX values and set pwm levels
-    analogWrite(RedPin,   DMXSerial.read(startChannel));
-    analogWrite(GreenPin, DMXSerial.read(startChannel + 1));
-    analogWrite(BluePin,  DMXSerial.read(startChannel + 2));
-
-  } else {
-    // Show pure red color, when no data was received since 5 seconds or more.
-    analogWrite(RedPin,   RedDefaultLevel);
-    analogWrite(GreenPin, GreenDefaultLevel);
-    analogWrite(BluePin,  BlueDefaultLevel);
-  } // if
-}
-
-// End.
+// - - - - -
+// DmxSerial - A hardware supported interface to DMX.
+// DmxSerialRecv.ino: Sample DMX application for retrieving 3 DMX values:
+// address 1 (red) -> PWM Port 9
+// address 2 (green) -> PWM Port 6
+// address 3 (blue) -> PWM Port 5
+//
+// Copyright (c) 2011-2015 by Matthias Hertel, http://www.mathertel.de
+// This work is licensed under a BSD style license. See http://www.mathertel.de/License.aspx
+//
+// Documentation and samples are available at http://www.mathertel.de/Arduino
+// 25.07.2011 creation of the DmxSerial library.
+// 10.09.2011 fully control the serial hardware register
+//            without using the Arduino Serial (HardwareSerial) class to avoid ISR implementation conflicts.
+// 01.12.2011 include file and extension changed to work with the Arduino 1.0 environment
+// 28.12.2011 changed to channels 1..3 (RGB) for compatibility with the DmxSerialSend sample.
+// 10.05.2012 added some lines to loop to show how to fall back to a default color when no data was received since some time.
+// - - - - -
+
+#include <DMXSerial.h>
+
+// Constants for demo program
+
+const int RedPin =    9;  // PWM output pin for Red Light.
+const int GreenPin =  6;  // PWM output pin for Green Light.
+const int BluePin =   5;  // PWM output pin for Blue Light.
+
+// This Example receives the 3 values starting with this channel:
+const int startChannel = 0 * 3 + 1;
+
+#define RedDefaultLevel   100
+#define GreenDefaultLevel 200
+#define BlueDefaultLevel  255
+
+void setup() {
+  DMXSerial.init(DMXReceiver);
+
+  // set some default values
+  DMXSerial.write(1, 80);
+  DMXSerial.write(2, 0);
+  DMXSerial.write(3, 0);
+
+  // enable pwm outputs
+  pinMode(RedPin,   OUTPUT); // sets the digital pin as output
+  pinMode(GreenPin, OUTPUT);
+  pinMode(BluePin,  OUTPUT);
+}
+
+
+void loop() {
+  // Calculate how long no data bucket was received
+  unsigned long lastPacket = DMXSerial.noDataSince();
+
+  if (lastPacket < 5000) {
+    // read recent DMX values and set pwm levels
+    analogWrite(RedPin,   DMXSerial.read(startChannel));
+    analogWrite(GreenPin, DMXSerial.read(startChannel + 1));
+    analogWrite(BluePin,  DMXSerial.read(startChannel + 2));
+
+  } else {
+    // Show pure red color, when no data was received since 5 seconds or more.
+    analogWrite(RedPin,   RedDefaultLevel);
+    analogWrite(GreenPin, GreenDefaultLevel);
+    analogWrite(BluePin,  BlueDefaultLevel);
+  } // if
+}
+
+// End.


temp version to get around now-missing status_text array

--- examples/Habitat_Temps/Habitat_Temps.ino
+++ examples/Habitat_Temps/Habitat_Temps.ino
@@ -24,6 +24,7 @@

 #include <Arduino.h>
+#include <Systronix_i2c_common.h>
 #include <Systronix_PCA9548A.h>	// best version of I2C library is #included by the library. Don't include it here!
 #include <Systronix_TMP275.h>   // temp sensor
 #include <SALT_power_FRU.h>     // MUX and sensors pass through PowerFRU, if we have one
@@ -46,6 +47,7 @@
 // Also MUX and sensors powered by FRU if a SALT new board
 SALT_power_FRU fru;

+Systronix_i2c_common i2c_common;

 //Systronix_PCA9548A PCA9548A_70(PCA9548A_SLAVE_ADDR_0);
 Systronix_PCA9548A PCA9548A_70;
@@ -54,14 +56,18 @@
 //TMP102 on board SALT has same address as TMP275 0 so don't use that
 //

-// Drawer 1 uses Mux 1
-Systronix_TMP275 Mux1Temp1;   // D1C1, top animal drawer, left compartment
-Systronix_TMP275 Mux1Temp2;   // D1C2, center
-Systronix_TMP275 Mux1Temp3;   // D1C3
+// Drawer 1 uses Mux 0
+Systronix_TMP275 Mux0Temp0;   // Ambient Temp back of habitat
+Systronix_TMP275 Mux0Temp1;   // D1C1, top animal drawer, left compartment
+Systronix_TMP275 Mux0Temp2;   // D1C2, center
+Systronix_TMP275 Mux0Temp3;   // D1C3

 // End Cap Mux 0
-Systronix_TMP275 Mux0Temp1;
-Systronix_TMP275 Mux0Temp2;
+Systronix_TMP275 Mux0Temp5;
+Systronix_TMP275 Mux0Temp6;
+
+// back of D1C3, mostly for convenience of plugging first drawer cable from mux to ext sensor board not inside the drawer
+Systronix_TMP275 Mux0Temp7;

 // Drawer 2
 Systronix_TMP275 Mux2Temp1;
@@ -138,36 +144,42 @@
   actual access of the TMP275.
   Here all we can do is setup and begin which just get I2C ready for that sensor instance.
 */
-Mux1Temp1.setup (TMP275_SLAVE_ADDR_1, Wire1, (char*)"D1-C1");	// initialize this sensor instance
-Mux1Temp1.begin (I2C_PINS_29_30, I2C_RATE_100);
-
-
-Mux1Temp2.setup (TMP275_SLAVE_ADDR_2, Wire1, (char*)"D1-C2");	// initialize this sensor instance
-Mux1Temp2.begin (I2C_PINS_29_30, I2C_RATE_100);
-
-
-Mux1Temp3.setup (TMP275_SLAVE_ADDR_3, Wire1, (char*)"D1-C3");	// initialize this sensor instance
-Mux1Temp3.begin (I2C_PINS_29_30, I2C_RATE_100);
-
-
-Mux0Temp1.setup (TMP275_SLAVE_ADDR_1, Wire1, (char*)"ECTop");	// initialize this sensor instance
+Mux0Temp0.setup (TMP275_SLAVE_ADDR_0, Wire1, (char*)"Ambient"); // initialize this sensor instance
+Mux0Temp0.begin (I2C_PINS_29_30, I2C_RATE_100);
+
+Mux0Temp1.setup (TMP275_SLAVE_ADDR_1, Wire1, (char*)"D1-C1");	// initialize this sensor instance
 Mux0Temp1.begin (I2C_PINS_29_30, I2C_RATE_100);

-Mux0Temp2.setup (TMP275_SLAVE_ADDR_2, Wire1, (char*)"ECBot");	// initialize this sensor instance
+Mux0Temp2.setup (TMP275_SLAVE_ADDR_2, Wire1, (char*)"D1-C2");	// initialize this sensor instance
 Mux0Temp2.begin (I2C_PINS_29_30, I2C_RATE_100);

-Mux2Temp1.setup (TMP275_SLAVE_ADDR_1, Wire1, (char*)"D2-C1");	// initialize this sensor instance
-Mux2Temp1.begin (I2C_PINS_29_30, I2C_RATE_100);
-
-
-Mux2Temp2.setup (TMP275_SLAVE_ADDR_2, Wire1, (char*)"D2-C2");	// initialize this sensor instance
-Mux2Temp2.begin (I2C_PINS_29_30, I2C_RATE_100);
-
-
-Mux2Temp3.setup (TMP275_SLAVE_ADDR_3, Wire1, (char*)"D2-C3"); // initialize this sensor instance
-Mux2Temp3.begin (I2C_PINS_29_30, I2C_RATE_100);
+Mux0Temp3.setup (TMP275_SLAVE_ADDR_3, Wire1, (char*)"D1-C3");	// initialize this sensor instance
+Mux0Temp3.begin (I2C_PINS_29_30, I2C_RATE_100);
+
+
+Mux0Temp5.setup (TMP275_SLAVE_ADDR_5, Wire1, (char*)"ECTop");	// initialize this sensor instance
+Mux0Temp5.begin (I2C_PINS_29_30, I2C_RATE_100);
+
+
+Mux0Temp6.setup (TMP275_SLAVE_ADDR_6, Wire1, (char*)"ECBot");	// initialize this sensor instance
+Mux0Temp6.begin (I2C_PINS_29_30, I2C_RATE_100);
+
+Mux0Temp7.setup (TMP275_SLAVE_ADDR_7, Wire1, (char*)"D1C3 Back"); // initialize this sensor instance
+Mux0Temp7.begin (I2C_PINS_29_30, I2C_RATE_100);
+
+
+// Mux2Temp1.setup (TMP275_SLAVE_ADDR_1, Wire1, (char*)"D2-C1");	// initialize this sensor instance
+// Mux2Temp1.begin (I2C_PINS_29_30, I2C_RATE_100);
+
+
+// Mux2Temp2.setup (TMP275_SLAVE_ADDR_2, Wire1, (char*)"D2-C2");	// initialize this sensor instance
+// Mux2Temp2.begin (I2C_PINS_29_30, I2C_RATE_100);
+
+
+// Mux2Temp3.setup (TMP275_SLAVE_ADDR_3, Wire1, (char*)"D2-C3"); // initialize this sensor instance
+// Mux2Temp3.begin (I2C_PINS_29_30, I2C_RATE_100);

   uint8_t iter = 0;
@@ -186,7 +198,8 @@
     Serial.printf(" Attempt #%u: Init control reg to 0x%.2X - ", iter, config_value);
     if (SUCCESS != stat)
     {
-      text_ptr = (PCA9548A_70.status_text[PCA9548A_70.error.error_val]);
+//      text_ptr = (PCA9548A_70.status_text[PCA9548A_70.error.error_val]);
+      text_ptr = "where are i2c error strings?";
       Serial.printf("failed - returned 0x%.2X: %s\r\n", PCA9548A_70.error.error_val, text_ptr);
 #if defined I2C_T3_H
     // reset I2C just to be safe
@@ -269,8 +282,8 @@
 //  int16_t temp0;
   uint8_t stat=0;  // status flag
   uint8_t control_read_val = 0;
-  uint16_t rawtemp;
-  float temp;
+  // uint16_t rawtemp;
+  // float temp;

   uint8_t inbyte = 0;

@@ -320,7 +333,8 @@
   stat = PCA9548A_70.control_write(PCA9548A_PORT_0_ENABLE);
   if (SUCCESS != stat)
   {
-    text_ptr = (PCA9548A_70.status_text[PCA9548A_70.error.error_val]);
+    // text_ptr = (PCA9548A_70.status_text[PCA9548A_70.error.error_val]);
+    text_ptr = "where are i2c error strings?";
     Serial.printf("mux0 control write failed with return of 0x%.2X: %s\r\n", PCA9548A_70.error.error_val, text_ptr);
     delay(dtime/2); // don't blast repeat failures too quickly
   }
@@ -330,60 +344,42 @@
     if (verbose) Serial.printf("OK control=0x%.2X\r\n", control_read_val);
   }

-  SensorPtr = &Mux0Temp1;   // EC Top
-  stat = sensor_read (SensorPtr);
-
-  SensorPtr = &Mux0Temp2;   // EC Bot
-  stat = sensor_read (SensorPtr);
-
-  // Enable Mux Channel 1
-  stat = PCA9548A_70.control_write(PCA9548A_PORT_1_ENABLE);
-  if (SUCCESS != stat)
-  {
-    text_ptr = (PCA9548A_70.status_text[PCA9548A_70.error.error_val]);
-    Serial.printf("mux1 control write failed with return of 0x%.2X: %s\r\n", PCA9548A_70.error.error_val, text_ptr);
-    delay(dtime/2); // don't blast repeat failures too quickly
-  }
-  else
-  {
-    stat = PCA9548A_70.control_read(&control_read_val);
-    if (verbose) Serial.printf("OK control=0x%.2X\r\n", control_read_val);
-  }
+  SensorPtr = &Mux0Temp0;
+  stat = sensor_read (SensorPtr);
+
+  SensorPtr = &Mux0Temp1;
+  stat = sensor_read (SensorPtr);
+
+  // // Enable Mux Channel 1
+  // stat = PCA9548A_70.control_write(PCA9548A_PORT_1_ENABLE);
+  // if (SUCCESS != stat)
+  // {
+  //   text_ptr = (PCA9548A_70.status_text[PCA9548A_70.error.error_val]);
+  //   Serial.printf("mux1 control write failed with return of 0x%.2X: %s\r\n", PCA9548A_70.error.error_val, text_ptr);
+  //   delay(dtime/2); // don't blast repeat failures too quickly
+  // }
+  // else
+  // {
+  //   stat = PCA9548A_70.control_read(&control_read_val);
+  //   if (verbose) Serial.printf("OK control=0x%.2X\r\n", control_read_val);
+  // }

   // ------------------------------
-  SensorPtr = &Mux1Temp1;
-  stat = sensor_read (SensorPtr);
-
-  SensorPtr = &Mux1Temp2;
-  stat = sensor_read (SensorPtr);
-
-  SensorPtr = &Mux1Temp3;
-  stat = sensor_read (SensorPtr);
-
-    // Enable Mux Channel 2
-  stat = PCA9548A_70.control_write(PCA9548A_PORT_2_ENABLE);
-  if (SUCCESS != stat)
-  {
-    text_ptr = (PCA9548A_70.status_text[PCA9548A_70.error.error_val]);
-    Serial.printf("mux2 control write failed with return of 0x%.2X: %s\r\n", PCA9548A_70.error.error_val, text_ptr);
-    delay(dtime/2); // don't blast repeat failures too quickly
-  }
-  else
-  {
-    stat = PCA9548A_70.control_read(&control_read_val);
-    if (verbose) Serial.printf("OK control=0x%.2X\r\n", control_read_val);
-  }
-
-  // ------------------------------
-  SensorPtr = &Mux2Temp1;
-  stat = sensor_read (SensorPtr);
-
-  SensorPtr = &Mux2Temp2;
-  stat = sensor_read (SensorPtr);
-
-  SensorPtr = &Mux2Temp3;
-  stat = sensor_read (SensorPtr);
+  SensorPtr = &Mux0Temp2;
+  stat = sensor_read (SensorPtr);
+
+  SensorPtr = &Mux0Temp3;
+  stat = sensor_read (SensorPtr);
+
+  SensorPtr = &Mux0Temp5;
+  stat = sensor_read (SensorPtr);
+
+  SensorPtr = &Mux0Temp6;
+  stat = sensor_read (SensorPtr);
+
+  SensorPtr = &Mux0Temp7;
+  stat = sensor_read (SensorPtr);

   Serial.println();


Added U8Glib text translate test

Added U8Glib text translate test

--- examples/HelloWorld/HelloWorld.ino
+++ examples/HelloWorld/HelloWorld.ino
@@ -3,6 +3,15 @@
 #include <Utf8.h>
 #include <U8glib.h>
 #include <U8GettextSimple.h>
+
+void printHexString(const char *str) {
+  while(*str) {
+    Serial.print(" 0x");
+    Serial.print((uint8_t)*str, HEX);
+    ++ str;
+  }
+  Serial.println();
+}

 void setup() {
   // put your setup code here, to run once:
@@ -35,4 +44,9 @@
   Serial.println(u8gettextGetLanguage());

   Serial.println(_("Hello, world!"));
+
+  delay(3000);
+  Serial.println("[Test 3]");
+
+  printHexString(U_("Hello, world!"));
 }


also stop broadcast IR in multi selection stage

--- glass/glass.ino
+++ glass/glass.ino
@@ -126,18 +126,25 @@
     else if (true == isPacketValid(message)) {
       DEBUG_PRINT("[XBee]: send message: ");
       DEBUG_PRINTLN(message);
+
       XBee.print(message);
+
       //check if led broadcast related msg
-      //turn of broadcast when a client is connected
+      //turn off broadcast when a client is connected
       //e.g. "IDCSEL ON" or "IDCSELAON"
-      //turn on when IDCSELOFF
-      if(message[8] == 'O' && message[9] == 'N') {
+      //also turn off when in multiple selecting mode
+      //e.g. "IDSSEL080" or "IDCSEL1st"
+      if((message[7] == 'O' && message[8] == 'N')
+        || (message[7] == '8' && message[8] == '0')
+        || (message[7] == 's' && message[8] == 't')) {
         ir_bcast_mode = false;
         DEBUG_PRINTLN("turning off IR bcast");
-      } else if(message[7] == 'O' && message[8] == 'F') {
+      } else if(message[6] == 'O' && message[7] == 'F') {
+        //turn broadcast back on when IDCSELOFF
         ir_bcast_mode = true;
         DEBUG_PRINTLN("turning on IR bcast");
       }
+
     }
   }