Update ncd test code (works)

Update ncd test code (works)

--- Photon/Controllers/NCD8LightTest/src/NCD8LightTest.ino
+++ Photon/Controllers/NCD8LightTest/src/NCD8LightTest.ino
@@ -6,12 +6,12 @@
  *
  * To update Photon:
  *   1. Edit this code
- *   2. "particle flash RearPanel"
+ *   2. "particle flash RonTest"
  *
  * Hardware
  * 1. Photon
- * 2. ControlEverything.com NCD8Relay Photon Controller
- * 3. NCD8PWM board connected via I2C to NCD8Relay board
+ * 2. ControlEverything.com NCD Photon Screw Terminal Breakout board
+ * 3. NCD8PWM board connected via I2C to NCD STB board
  * NCD 8-channel PWM OC board with adress switches set per ADDRESS
  * LED connected to channel 0
  *
@@ -20,9 +20,10 @@
  *
  * History
  * 2/23/20 Initial creation
+ * 11/3/20 Modify for STB board
  */

-#define ADDRESS  0x40  // high jumper set (address 64)
+#define ADDRESS  1 // low jumper set (address 1)

 #include "Particle.h"

@@ -41,6 +42,7 @@
       Serial.println("Uh oh, wire was already enabled");
     }

+    retries = 3;
     do {
         Wire.beginTransmission(ADDRESS);
         status = Wire.endTransmission();
@@ -48,86 +50,165 @@
     } while( status != 0 && retries-- > 0);

     if(status == 0) {
-      Serial.println("Status = 0");
+      Serial.println("Status = 0, setting Mode1 and Mode2");
         Wire.beginTransmission(ADDRESS);
-        Wire.write(0);      // Mode1 register
-        Wire.write(0);      // Osc on, diable AI, subaddrs, and allcall
+        Wire.write(0);      // Control register - No AI, point to reg 0 Mode1
+        Wire.write(0);      // Mode1 register: Osc on (no sleep), diable AI, subaddrs, and allcall
         Wire.endTransmission();

         Wire.beginTransmission(ADDRESS);
         Wire.write(1);      // Mode2 register
-        Wire.write(0x04);   // Dimming, Not inverted, totem-pole
+        Wire.write(0x04);   // Dimming, Not inverted, totem-pole (this is the default except D0)
         Wire.endTransmission();

     } else {
         Serial.println("Transmission failed");
     }

-    Wire.beginTransmission(ADDRESS);
-	  Wire.write(2);    // 2 + led #
-	  Wire.write(128);  // 1/2 brightness
-	  status = Wire.endTransmission();
-    if(status != 0){
-      Serial.println("Write failed");
-    }else{
-      Serial.println("Write succeeded");
-    }
+    Serial.println("Turning ON all LEDS");
+    Wire.beginTransmission(ADDRESS);
+	  Wire.write(0x8c); // AI + LEDOUT0
+	  Wire.write(0x55); // LEDOUT0 All 4 LEDS ON
+	  Wire.write(0x55); // LEDOUT1 All 4 LEDS ON
+	  status = Wire.endTransmission();
+    if(status != 0){
+      Serial.println("Write failed");
+    }else{
+      Serial.println("Write succeeded");
+    }
+
+    delay(2000);
+
+    Serial.println("Turning OFF all LEDS");
+    Wire.beginTransmission(ADDRESS);
+	  Wire.write(0x8c); // AI + LEDOUT0
+	  Wire.write(0x00); // LEDOUT0 All 4 LEDS OFF
+	  Wire.write(0xaa); // LEDOUT1 All 4 LEDS Dimming
+	  status = Wire.endTransmission();
+    if(status != 0){
+      Serial.println("Write failed");
+    }else{
+      Serial.println("Write succeeded");
+    }
+
+//    delay(2000);
+
+    // Serial.println("Setting LED 2 = 255");
+    // Wire.beginTransmission(ADDRESS);
+	  // Wire.write(3);    // 2 + led #
+	  // Wire.write(255);  // Full brightness
+	  // status = Wire.endTransmission();
+    // if(status != 0){
+    //   Serial.println("Write failed");
+    // }else{
+    //   Serial.println("Write succeeded");
+    // }
+
+    // delay(1000);
+
+    // Serial.println("Setting LED 2 = 0");
+    // Wire.beginTransmission(ADDRESS);
+	  // Wire.write(3);    // 2 + led #
+	  // Wire.write(0);    // Off
+	  // status = Wire.endTransmission();
+    // if(status != 0){
+    //   Serial.println("Write failed");
+    // }else{
+    //   Serial.println("Write succeeded");
+    // }
+
+    // Repeat
+    // TODO:
 }
-
-// void loop() {
-//     bool devicesFound = false;
-//     String newDevices;
-
-//     Serial.println("Starting loop...");
-//     //Step through all 127 possible I2C addresses to scan for devices on the I2C bus.
-//     for(int i = 1; i < 128; i++){
-//         //Make a general call to device at the current address to see if anything responds.
-//         Wire.beginTransmission(i);
-//         byte status = Wire.endTransmission();
-//         if(status == 0){
-//             //Device found so append it to our device list event string
-//             // Devicess found at 1, 3, 32, 112 (0x01, 0x03, 0x20, 0x70)
-//             char devices[32];
-//             sprintf(devices, "Device at: %ix, ", i);
-//             newDevices.concat(devices);
-//             devicesFound = true;
-//         }
-//     }
-//     if(devicesFound){
-//         Serial.println(newDevices);
-//     }else{
-//         Serial.println("No devices found");
-//     }
-
-//     delay(2000);
-// }

 // From TravisE_NCD_Technica
 unsigned long scanInterval = 10000;
 unsigned long lastScan;
+byte dimming = 0;

 void loop() {
-    if(millis() > lastScan + scanInterval){
-        lastScan = millis();
-        // bool devicesFound = false;
-        // String newDevices = "Devices at: ";
-        // //Step through all 127 possible I2C addresses to scan for devices on the I2C bus.
-        // for(int i = 1; i < 128; i++){
-        //     //Make a general call to device at the current address to see if anything responds.
-        //     Wire.beginTransmission(i);
-        //     byte status = Wire.endTransmission();
-        //     if(status == 0){
-        //         //Device found so append it to our device list event string
-        //         newDevices.concat(i);
-        //         newDevices.concat(", ");
-        //         devicesFound = true;
-        //     }
+    byte status;
+    // if(millis() > lastScan + scanInterval){
+    //     lastScan = millis();
+
+    //     bool devicesFound = false;
+    //     String newDevices = "Devices at: ";
+    //     //Step through all 127 possible I2C addresses to scan for devices on the I2C bus.
+    //     for(int i = 1; i < 128; i++){
+    //         //Make a general call to device at the current address to see if anything responds.
+    //         Wire.beginTransmission(i);
+    //         byte status = Wire.endTransmission();
+    //         if(status == 0){
+    //             //Device found so append it to our device list event string
+    //             newDevices.concat(i);
+    //             newDevices.concat(", ");
+    //             devicesFound = true;
+    //         }

-        // }
-        // if(devicesFound){
-        //     Serial.println(newDevices);
-        // }else{
-        //     Serial.println("No Devices Found");
-        // }
-    }
+    //     }
+    //     if(devicesFound){
+    //         Serial.println(newDevices);
+    //     }else{
+    //         Serial.println("No Devices Found");
+    //     }
+    // }
+
+    Serial.println("Turning ON LEDS 0-3");
+    Wire.beginTransmission(ADDRESS);
+	  Wire.write(0x8c); // AI + LEDOUT0
+	  Wire.write(0x55); // LEDOUT0 All 4 LEDS ON
+	  //Wire.write(0x55); // LEDOUT1 All 4 LEDS ON
+	  status = Wire.endTransmission();
+    if(status != 0){
+      Serial.println("Write failed");
+    }else{
+      Serial.println("Write succeeded");
+    }
+
+    Serial.println("Setting LEDs 4-7 = 255");
+    Wire.beginTransmission(ADDRESS);
+	  Wire.write(0x86); // AI + 2 + led # 4
+	  Wire.write(dimming);  // Full brightness
+	  Wire.write(dimming);  // Full brightness
+	  Wire.write(dimming);  // Full brightness
+	  Wire.write(dimming);  // Full brightness
+	  status = Wire.endTransmission();
+    if(status != 0){
+      Serial.println("Write failed");
+    }else{
+      Serial.println("Write succeeded");
+    }
+
+    delay(1000);
+    dimming += 16;
+
+    Serial.println("Turning OFF LEDS 0-3");
+    Wire.beginTransmission(ADDRESS);
+	  Wire.write(0x8c); // AI + LEDOUT0
+	  Wire.write(0x00); // LEDOUT0 All 4 LEDS OFF
+	  //Wire.write(0x00); // LEDOUT1 All 4 LEDS OFF
+	  status = Wire.endTransmission();
+    if(status != 0){
+      Serial.println("Write failed");
+    }else{
+      Serial.println("Write succeeded");
+    }
+
+    Serial.println("Setting LEDs 4-7 = 0");
+    Wire.beginTransmission(ADDRESS);
+	  Wire.write(0x86);    // 2 + led # 4
+	  Wire.write(dimming);
+	  Wire.write(dimming);
+	  Wire.write(dimming);
+	  Wire.write(dimming);
+	  status = Wire.endTransmission();
+    if(status != 0){
+      Serial.println("Write failed");
+    }else{
+      Serial.println("Write succeeded");
+    }
+
+    delay(1000);
+    dimming += 16;
+
 }


Jira 870, Change sensortag_button.ino to use localName

Feature added:
  - Since the BLE library now support the Scan
    Response Data processing, update the sketch
    to look for the sensorTag localName instead
    of its specific unit address.

Cod mods:
1. sensortag_button.ino:
   - Replace MAC address comparison with localName
     string comparison.

--- libraries/CurieBLE/examples/central/sensortag_button/sensortag_button.ino
+++ libraries/CurieBLE/examples/central/sensortag_button/sensortag_button.ino
@@ -43,23 +43,12 @@
     Serial.print(peripheral.advertisedServiceUuid());
     Serial.println();

-    /*see if peripheral is a SensorTag
-      The localName SensorTag is in the Scan Response data packet
-      In this release we do not have the feature that gets the scan response data and hence
-      the local name in the scan is blank
-      We have to explicitly find the BLE mac address
-      Please use another deviice like nrfConnect app to discover the Bluetooth Address
-    */
-    //if (peripheral.localName() == "SensorTag") {
-
-
-    /******************************************************
-    * ATTENTION:
-    * Change to the mac address according to your device!
-    * Use a central app that can display the BT MAC address
-    * ******************************************************
-    */
-    if (peripheral.address() == "68:C9:0B:06:BC:81") {
+    /* see if peripheral is a SensorTag
+     * The localName, CC2650 SensorTag, is in the Scan Response Data packet.
+     * If this is not the expected name, please change the following
+     * if-statement accordingly.
+     */
+    if (peripheral.localName() == "CC2650 SensorTag") {
       // stop scanning
       BLE.stopScan();


Resolved double code

Resolved double code

--- firefighter/firefighter.ino
+++ firefighter/firefighter.ino
@@ -1,130 +1,10 @@
-#include "Motor.h"
-#include "colorSensor.h"
-#include "servo.h"
-
-Motor leftMotor1(2, 3);
-Motor leftMotor2(4, 5);
-Motor rightMotor1(6, 7);
-Motor rightMotor2(8, 9);
-Motor strafeMotor(10, 11);
-ColorSensor colour_sensor(44, 46, 48, 50, 52);
-#define servo_pin 45
-#define fire_sensor 47
-void hDrive(double move, double rotate, double strafe) {
-  double leftSpeed, rightSpeed;
-
-  move = constrain(move, -1.0, 1.0);
-  rotate = constrain(rotate, -1.0, 1.0);
-  strafe = constrain(strafe, -1.0, 1.0);
-
-  if (move > 0.0) {
-    if (rotate > 0.0) {
-      leftSpeed =  move - rotate;
-      rightSpeed = max(move, rotate);
-    } else {
-      leftSpeed = max(move, -rotate);
-      rightSpeed = move + rotate;
-    }
-  } else {
-    if (rotate > 0.0) {
-      leftSpeed = -max(-move, rotate);
-      rightSpeed = move + rotate;
-    } else {
-      leftSpeed = move - rotate;
-      rightSpeed = -max(-move, -rotate);
-    }
-  }
-
-  leftMotor1.set(constrain(leftSpeed, -1.0, 1.0));
-  leftMotor2.set(constrain(leftSpeed, -1.0, 1.0));
-  rightMotor1.set(-constrain(rightSpeed, -1.0, 1.0));
-  rightMotor2.set(-constrain(rightSpeed, -1.0, 1.0));
-  strafeMotor.set(strafe);
-}
-
-void setup() {
-  Serial.begin(9600);
-  pinMode(servo_pin, OUTPUT);
-  pinMode(fire_sensor, INPUT);
- }
-
-void scanForFire(){
-  servo_pin.write(0);
-  for(int i = 0; i <= 180;i += 10){
-    if(digitalRead(fire_sensor)){
-      delay(10);//make sure that the reading isn't a false positive
-      while(digitalRead(fire_sensor))
-      {
-        //Turn on extinguisher
-        delay(50);
-      }
-    }
-    else if(val == HIGH && !directionRight)
-    {
-      directionRight = true;  //Forward
-    }
-  }
-}
-int btn = 0;
-void loop() {
-
-  // put your main code here, to run repeatedly:
-  if(digitalRead(21)){
-    delay(100);
-    Serial.println("pressed");
-
-    if(!btn){
-      //hDrive(1.0, 0.0, 0.0);
-      delay(100);
-
-      int ri = colour_sensor.getColor('r');
-      int r = ri;
-      int g = colour_sensor.getColor('g');
-      int b = colour_sensor.getColor('b');
-      String colour = String(ri) + " " + String(g) + " " + String(b);
-      Serial.println(colour);
-      hDrive(.3,0,0);
-      while(r > ri - 30)
-      {
-
-        r = colour_sensor.getColor('r');
-        String colour = String(r);
-        Serial.println(colour);
-      }
-      Serial.println("Done");
-      hDrive(0.0, 0.0, 0.0);
-      btn = 1;
-
-    }
-    else if(val == HIGH && !directionLeft)
-    {
-      directionLeft = true;  //Forward
-    }
-  }
-}
-
-double getAngle() {
-  return ((pulseLeft - pulseRight) * 12.5 / 700) / 8;
-}
-
-double getPercentError(double actual, double target) {
-  return abs(actual - target) / target;
-}
-
-void turnToAngle(double targetAngle) {
-  while (abs(getAngle()) < abs(targetAngle)) {
-    hDrive(0.0, getPercentError(getAngle(), targetAngle()), 0.0);
-  }
-  hDrive(0.0, 0.0, 0.0);
-}
-
-
 #include "Ultrasonic.h"
 #include "ColorSensor.h"
 #include <Servo.h>

 #define WALL_DISTANCE 5
-
+#define servo_pin 45
+#define fire_sensor 47

 Motor leftMotor1(3, 4);
 Motor leftMotor2(5, 6);
@@ -213,6 +93,71 @@
   delay(100);
 }

+void hDrive(double move, double rotate, double strafe) {
+  double leftSpeed, rightSpeed;
+
+  move = constrain(move, -1.0, 1.0);
+  rotate = constrain(rotate, -1.0, 1.0);
+  strafe = constrain(strafe, -1.0, 1.0);
+
+  if (move > 0.0) {
+    if (rotate > 0.0) {
+      leftSpeed =  move - rotate;
+      rightSpeed = max(move, rotate);
+    } else {
+      leftSpeed = max(move, -rotate);
+      rightSpeed = move + rotate;
+    }
+  } else {
+    if (rotate > 0.0) {
+      leftSpeed = -max(-move, rotate);
+      rightSpeed = move + rotate;
+    } else {
+      leftSpeed = move - rotate;
+      rightSpeed = -max(-move, -rotate);
+    }
+  }
+
+  leftMotor1.set(constrain(leftSpeed, -1.0, 1.0));
+  leftMotor2.set(constrain(leftSpeed, -1.0, 1.0));
+  rightMotor1.set(-constrain(rightSpeed, -1.0, 1.0));
+  rightMotor2.set(-constrain(rightSpeed, -1.0, 1.0));
+  strafeMotor.set(strafe);
+}
+
+void scanForFire(){
+  servo_pin.write(0);
+  for(int i = 0; i <= 180;i += 10){
+    if(digitalRead(fire_sensor)){
+      delay(10);//make sure that the reading isn't a false positive
+      while(digitalRead(fire_sensor))
+      {
+        //Turn on extinguisher
+        delay(50);
+      }
+    }
+    else if(val == HIGH && !directionRight)
+    {
+      directionRight = true;  //Forward
+    }
+  }
+}
+
+double getAngle() {
+  return ((pulseLeft - pulseRight) * 12.5 / 700) / 8;
+}
+
+double getPercentError(double actual, double target) {
+  return abs(actual - target) / target;
+}
+
+void turnToAngle(double targetAngle) {
+  while (abs(getAngle()) < abs(targetAngle)) {
+    hDrive(0.0, getPercentError(getAngle(), targetAngle()), 0.0);
+  }
+  hDrive(0.0, 0.0, 0.0);
+}
+
 void drivetrainCheck() {
   hDrive(0.3, 0.0, 0.0); delay(300); hDrive(-0.3, 0.0, 0.0); delay(300);
   hDrive(0.0, 0.3, 0.0); delay(300); hDrive(0.0, -0.3, 0.0); delay(300);
@@ -269,21 +214,6 @@
   }
 }

-void scanForFire(){
-//  servo_pin.write(0);
-//  for(int i = 0; i <= 180;i += 10){
-//    if(digitalRead(fire_sensor)){
-//      delay(10);//make sure that the reading isn't a false positive
-//      while(digitalRead(fire_sensor))
-//      {
-//        //Turn on extinguisher
-//        delay(50);
-//      }
-//    }
-//    break;
-//  }
-}
-
 void countPulseRight() {
   int Lstate = digitalRead(encoderARight);
   if((encoderALastRight == LOW) && Lstate==HIGH)


This looks right.

This looks right.

git-svn-id: d8bfcd070c2c81762cca1b3912331324182919ba@17014 0d6f1817-ed0e-0410-87c9-987e46238f29

--- zimodem/serout.ino
+++ zimodem/serout.ino
@@ -119,21 +119,20 @@
     uint32_t invertMask = 0;
     if(pinSupport[pinCTS])
     {
-      uart_set_pin(UART_NUM_2, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, pinCTS, /*cts_io_num*/UART_PIN_NO_CHANGE);
+      uart_set_pin(UART_NUM_2, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, /*cts_io_num*/pinCTS);
       // cts is input to me, output to true RS232
       if(ctsActive == 0)
-        invertMask = invertMask | UART_INVERSE_RTS;
+        invertMask = invertMask | UART_INVERSE_CTS;
     }
     if(pinSupport[pinRTS])
     {
-      uart_set_pin(UART_NUM_2, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, /*rts_io_num*/UART_PIN_NO_CHANGE, pinRTS);
+      uart_set_pin(UART_NUM_2, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, /*rts_io_num*/ pinRTS, UART_PIN_NO_CHANGE);
       s_pinWrite(pinRTS, rtsActive);
       // rts is output to me, input to true RS232
       if(rtsActive == 0)
-        invertMask = invertMask | UART_INVERSE_CTS;
-    }
-    uart_set_line_inverse(UART_NUM_2, invertMask);
-    //uart_set_hw_flow_ctrl(UART_NUM_2,UART_HW_FLOWCTRL_DISABLE,0);
+        invertMask = invertMask | UART_INVERSE_RTS;
+    }
+    //uart_set_line_inverse(UART_NUM_2, invertMask);
     if(pinSupport[pinRTS])
     {
       if(pinSupport[pinCTS])
@@ -143,7 +142,7 @@
     }
     else
     if(pinSupport[pinCTS])
-      uart_set_hw_flow_ctrl(UART_NUM_2,UART_HW_FLOWCTRL_RTS,SER_BUFSIZE);
+      uart_set_hw_flow_ctrl(UART_NUM_2,UART_HW_FLOWCTRL_CTS,SER_BUFSIZE);
   }
   else
     uart_set_hw_flow_ctrl(UART_NUM_2,UART_HW_FLOWCTRL_DISABLE,0);
@@ -170,11 +169,13 @@
   switch(flowControlType)
   {
   case FCT_RTSCTS:
+#ifndef ZIMODEM_ESP32
     if(pinSupport[pinCTS])
     {
       //debugPrintf("CTS: pin %d (%d == %d)\n",pinCTS,digitalRead(pinCTS),ctsActive);
       return (digitalRead(pinCTS) == ctsActive);
     }
+#endif
     return true;
   case FCT_NORMAL:
   case FCT_AUTOOFF:
@@ -190,11 +191,13 @@

 bool ZSerial::isSerialCancelled()
 {
+#ifndef ZIMODEM_ESP32
   if(flowControlType == FCT_RTSCTS)
   {
     if(pinSupport[pinCTS])
       return (digitalRead(pinCTS) == ctsInactive);
   }
+#endif
   return false;
 }


Correct description

Correct description

--- arduino-makefile/examples/SPI/SPI.ino
+++ arduino-makefile/examples/SPI/SPI.ino
@@ -1,5 +1,5 @@
 /*
-  12 bit ADC - MCP3202
+  AT93C46 SPI EEPROM sample code

   created 19 Aug 2013
   by Anuj Deshpande


Cleaned up a little bit and fixed odometry errors.

--- scr_arduino/scr_arduino.ino
+++ scr_arduino/scr_arduino.ino
@@ -1,7 +1,7 @@
 /*
  * Squad Collaborative Robotics
  * Prototype Embedded Collector Bot Code
-   Arduino Mega 2560 R3
+ * Arduino Mega 2560 R3
  */

 // ROS Includes
@@ -22,8 +22,7 @@
 #define LEFT_ENCODER_B_PIN 4
 #define RIGHT_ENCODER_A_PIN 3
 #define RIGHT_ENCODER_B_PIN 5
-#define ENCODER_TIME_DELAY_MS 100
-#define TICKS_PER_REVOLUTION 750
+#define TICKS_PER_REVOLUTION 3200
 #define PI 3.141592654

 // Pololu Motor Driver Pins
@@ -35,8 +34,8 @@
 ros::NodeHandle_<ArduinoHardware, 5, 5, 256, 256>  nh;

 // Encoder Messages
-std_msgs::Int32 l_enc_msg;
-std_msgs::Int32 r_enc_msg;
+// std_msgs::Int32 l_enc_msg;
+// std_msgs::Int32 r_enc_msg;

 // Wheel Speed Messages
 std_msgs::Float32 l_wheel_msg;
@@ -47,8 +46,8 @@

 // Initialize Publishers
 //ros::Publisher left_encoder_pub("left_encoder", &l_enc_msg);
+//ros::Publisher right_encoder_pub("right_encoder", &l_enc_msg);
 ros::Publisher left_wheel_pub("lw_speed", &l_wheel_msg);
-//ros::Publisher right_encoder_pub("right_encoder", &l_enc_msg);
 ros::Publisher right_wheel_pub("rw_speed", &r_wheel_msg);

 // Placeholders for wheel speeds in rad/s
@@ -63,20 +62,29 @@
 double lw_cmd_spd = 0;
 double rw_cmd_spd = 0;

-// Encoder initialization
+// Encoder object initialization
 Encoder L_DCMotorEncoder(LEFT_ENCODER_A_PIN, LEFT_ENCODER_B_PIN);
 Encoder R_DCMotorEncoder(RIGHT_ENCODER_A_PIN, RIGHT_ENCODER_B_PIN);

+// Encoder value initialization
 long last_encoder_time = micros();  // not the best way to get this done... should check existence in Update Wheel Function
+
+// Left Encoder
+long L_EncoderValue = 0;
 float L_EncoderVelocity = 0; // Radians per second
 long L_LastEncoderValue = 0;
 double L_EncoderDelta = 0;
 double L_LastEncoderDelta = 0;
+
+// Right Encoder
+long R_EncoderValue = 0;
 float R_EncoderVelocity = 0; // Radians per second
 long R_LastEncoderValue = 0;
 double R_EncoderDelta = 0;
 double R_LastEncoderDelta = 0;
-double beta = 0.0;  // Low Pass Parameter for encoder velocity
+
+// Low Pass Parameter for encoder velocity
+double beta = 0.0;

 // Speed Controller Initialization
 double L_PIDout = 0;
@@ -105,34 +113,32 @@
   rw_cmd_spd = motor_com.right_motor_w;
 }

+// Subscriber to speed commands on computer
+ros::Subscriber<scr_proto::SpeedCommand> motor_sub("speed_command", MotorCallback);
+
 void updateEncoderReading() {
   // Get raw ticks
-  long L_encoderValue = L_DCMotorEncoder.read();
-  long R_encoderValue = R_DCMotorEncoder.read();
-
+  L_EncoderValue = L_DCMotorEncoder.read();
+  R_EncoderValue = R_DCMotorEncoder.read();
+
+  // Current time in micro seconds
   long now = micros();

   long dt = (now - last_encoder_time);

-  // Get position in revolutions (includes multiple revolutions)
-// Serial.println(encoderValue);
-  L_EncoderDelta = (double)(L_encoderValue - L_LastEncoderValue) * (1-beta) + L_LastEncoderDelta * beta;
-  R_EncoderDelta = (double)(R_encoderValue - R_LastEncoderValue) * (1-beta) + R_LastEncoderDelta * beta;
-// Serial.println(g_EncoderAngle);
-
-  // Get velocity in ticks/sec
-  L_EncoderVelocity = 1000000.0*(double)(L_EncoderDelta)/dt;
-  R_EncoderVelocity = 1000000.0*(double)(R_EncoderDelta)/dt;
-
-  // Convert to revolutions/sec
-  L_EncoderVelocity /= (double)TICKS_PER_REVOLUTION;
-  R_EncoderVelocity /= (double)TICKS_PER_REVOLUTION;
-
-  // Convert to rad/s
+  // Get position in revolutions (includes multiple revolutions) with low pass filter
+  L_EncoderDelta = (double)(L_EncoderValue - L_LastEncoderValue) * (1-beta) + L_LastEncoderDelta * beta;
+  R_EncoderDelta = (double)(R_EncoderValue - R_LastEncoderValue) * (1-beta) + R_LastEncoderDelta * beta;
+
+  // Get velocity in revs/sec
+  L_EncoderVelocity = 1000000.0/dt * L_EncoderDelta/TICKS_PER_REVOLUTION;
+  R_EncoderVelocity = 1000000.0/dt * R_EncoderDelta/TICKS_PER_REVOLUTION;
+
+  // Convert to rad/sec
   L_WheelVelocity = L_EncoderVelocity * 2 * PI;
   R_WheelVelocity = R_EncoderVelocity * 2 * PI;

-  // Set last known encoder ticks
+  // Update previous values
   L_LastEncoderValue = L_encoderValue;
   R_LastEncoderValue = R_encoderValue;

@@ -142,9 +148,9 @@
   R_LastEncoderDelta = R_EncoderDelta;
 }

-ros::Subscriber<scr_proto::SpeedCommand> motor_sub("speed_command", MotorCallback);
-
-
+
+
+// Pololu Motor Driver Initialization
 // Rx, Tx, Reset Pins
 PololuQik2s12v10 pmd(PMD_RX, PMD_TX, PMD_RESET);

@@ -161,8 +167,8 @@
   nh.subscribe(motor_sub);

   // Encoder Pubs
-  //nh.advertise(left_encoder_pub);
-  //nh.advertise(right_encoder_pub);
+  // nh.advertise(left_encoder_pub);
+  // nh.advertise(right_encoder_pub);

   // Wheel Speeds in rad/s
   nh.advertise(right_wheel_pub);
@@ -194,14 +200,14 @@
   rm_cmd += R_PIDout;

   // Populate messages
-  //l_enc_msg.data = lm_cmd;
-  //r_enc_msg.data = rm_cmd;
+  // l_enc_msg.data = L_encoderValue;
+  // r_enc_msg.data = rm_cmd;
   l_wheel_msg.data = L_WheelVelocity;
   r_wheel_msg.data = R_WheelVelocity;

   // Publish Data
-  //left_encoder_pub.publish( &l_enc_msg );
-  //right_encoder_pub.publish( &r_enc_msg );
+  // left_encoder_pub.publish( &l_enc_msg );
+  // right_encoder_pub.publish( &r_enc_msg );
   left_wheel_pub.publish( &l_wheel_msg );
   right_wheel_pub.publish( &r_wheel_msg );


Version 01.00 of the latency-testing firmware looks for rapid motion and then a change in brightness and reports the time in microseconds between the two.  Compiled but not yet tested.

--- Latency_Hardware/OSVR_Latency_hardware_firmware/OSVR_Latency_hardware_firmware.ino
+++ Latency_Hardware/OSVR_Latency_hardware_firmware/OSVR_Latency_hardware_firmware.ino
@@ -1,6 +1,6 @@
 // OSRVR latency-testing hardware firmware source code.
-// Author: Russell Taylor working for Sensics.com through Reliasolve.com
-// LICENSE: XXX
+// Author: Russell Taylor working for Sensics.com through ReliaSolve.com
+// LICENSE: Apache License 2.0.

 // This code is based on the "Accelerometer_Gyro_Shield_test" example from
 // Robogaia industries that ships along with their 6-axis Gyro/Accelerometer
@@ -104,40 +104,23 @@

 // pins used for the connection with the sensor
 // the other you need are controlled by the SPI library):
-//const int dataReadyPin = 6;
 const int chipSelectPin = 10;

-
-////////////////////////////////////////////////////
-//Calibration values
-
- int xAccelerationGain=1;
- int xAccelerationOffset=0;
-
- int yAccelerationGain=1;
- int yAccelerationOffset=0;
-
- int zAccelerationGain=1;
- int zAccelerationOffset=0;
-
- int xGyroGain=1;
- int xGyroOffset=0;
-
- int yGyroGain=1;
- int yGyroOffset=0;
-
- int zGyroGain=1;
- int zGyroOffset=0;
-
-//end calibration values
-//////////////////////////////////////////////
-
+// Thresholds
+const int GYRO_THRESHOLD = 10;
+const int ACCEL_CHANGE_THRESHOLD = 10;
+const int BRIGHTNESS_CHANGE_THRESHOLD = 10;
+const unsigned long TIMEOUT_USEC = 1000000L;

 //*****************************************************
 void setup()
 //*****************************************************
 {
   Serial.begin(9600);
+  Serial.print("OSVR_latency_hardware_firmware v01.00\n");
+  Serial.print(" Mount the photosensor rigidly on the screen.\n");
+  Serial.print(" Move the interial sensor along with the tracking hardware.\n");
+  Serial.print(" Make the app change the brightness in front of the photosensor.\n");

   MPU6000_Init();
   delay(100);
@@ -147,144 +130,125 @@
 void loop()
 //*****************************************************
 {
-        int xAccelerationValue;
-        int yAccelerationValue;
-        int zAccelerationValue;
-
-        int xGyroValue;
-        int yGyroValue;
-        int zGyroValue;
-
-        //the values received from MPU 6000 are raw and have to be calibrated
-        //we use a linear function y=mx +b to transform the raw counts to real
-        //acceleration values  G   and rotations / sec rot gyros
-        // in this example the gain (m) and offset (x) are setup to m=1 and x=0 so there is no change in raw data
-        //
-
-        xAccelerationValue = xAccelerationGain * getXAccelerometerCounts()  +  xAccelerationOffset;
-        Serial.print("AccelerationX= ");
-        Serial.print(xAccelerationValue);
-
-        yAccelerationValue = yAccelerationGain * getYAccelerometerCounts()  +  yAccelerationOffset;
-        Serial.print(" AccelerationY= ");
-        Serial.print(yAccelerationValue);
-
-        zAccelerationValue = zAccelerationGain * getZAccelerometerCounts()  +  zAccelerationOffset;
-        Serial.print(" AccelerationZ= ");
-        Serial.print(zAccelerationValue);
-
-        xGyroValue = xGyroGain * getXGyroCounts()  +  xGyroOffset;
-        Serial.print(" GyroX= ");
-        Serial.print(xGyroValue);
-
-        yGyroValue = yGyroGain * getYGyroCounts()  +  yGyroOffset;
-        Serial.print(" GyroY= ");
-        Serial.print(yGyroValue);
-
-        zGyroValue = zGyroGain * getZGyroCounts()  +  zGyroOffset;
-        Serial.print(" GyroZ= ");
-        Serial.print(zGyroValue);
-
-        //Serial.print(" Temperature= ");
-        //Serial.print(getTemperature());
-
-        Serial.print("\r\n");
-
-     // Don't cycle too fast.
-     delay(100);
-
-}//end loop
-
-
-
-//*****************************************************
-int getXAccelerometerCounts(void)
-//*****************************************************
-{
-    int tempData_HI,tempData_LO;
-     //Read the  data
-    tempData_HI = readRegister(ACCEL_XOUT_H);
-    tempData_LO = readRegister(ACCEL_XOUT_L );
-
-    return ((tempData_HI << 8) | tempData_LO);
-
-}//end func
-
-//*****************************************************
-int getYAccelerometerCounts(void)
-//*****************************************************
-{
-    int tempData_HI,tempData_LO;
-
-    tempData_HI = readRegister(ACCEL_YOUT_H);
-    tempData_LO = readRegister(ACCEL_YOUT_L );
-
-    return ((tempData_HI << 8) + tempData_LO);
-}//end func
+  // We run a finite-state machine that cycles through cases of waiting for
+  // a period of non motion, detecting a sudden motion, waiting until there
+  // is a change in brightness, and reporting the time passed in microseconds
+  // between the motion and the brightness change.
+  static enum { S_CALM, S_MOTION, S_BRIGHTNESS } state = S_CALM;
+  static unsigned long start;
+  static int initial_brightness;

-//*****************************************************
-int getZAccelerometerCounts(void)
-//*****************************************************
-{
-    int tempData_HI,tempData_LO;
-
-    tempData_HI = readRegister(ACCEL_ZOUT_H );
-    tempData_LO = readRegister(ACCEL_ZOUT_L );
-
-    return ((tempData_HI << 8) + tempData_LO);
-
-}//end func
-
-//*****************************************************
-int getXGyroCounts(void)
-//*****************************************************
-{
-     int tempData_HI,tempData_LO;
-
-     tempData_HI = readRegister(GYRO_XOUT_H );
-     tempData_LO = readRegister(GYRO_XOUT_L );
-
-     return ((tempData_HI << 8) + tempData_LO);
-}//end func
-
-//*****************************************************
-int getYGyroCounts(void)
-//*****************************************************
-{
-     int tempData_HI,tempData_LO;
-
-     tempData_HI = readRegister(GYRO_YOUT_H);
-     tempData_LO = readRegister(GYRO_YOUT_L );
-
-     return ((tempData_HI << 8) + tempData_LO);
-}//end func
-
-//*****************************************************
-int getZGyroCounts(void)
-//*****************************************************
-{
-     int tempData_HI,tempData_LO;
-
-     tempData_HI = readRegister(GYRO_ZOUT_H);
-     tempData_LO = readRegister(GYRO_ZOUT_L);
-
-     return ((tempData_HI << 8) + tempData_LO);
-}//end func
-
-//*****************************************************
-unsigned int getTemperature(void)
-//*****************************************************
-{
-     int tempData_HI,tempData_LO;
-
-     tempData_HI = readRegister(TEMP_OUT_H + READ_FLAG);
-     tempData_LO = readRegister(TEMP_OUT_L + READ_FLAG);
-
-     return ((tempData_HI << 8) + tempData_LO);
-}//end func
-
-
-//Read from or write to register
+  switch (state) {
+    case S_CALM:
+      {
+        // Wait for a period of at least 100 cycles where there is no motion above
+        // the motion threshold.
+        static int calm_cycles = 0;
+        if (moving()) {
+          calm_cycles = 0;
+        } if (++calm_cycles >= 100) {
+            state = S_MOTION;
+            calm_cycles = 0;
+        }
+      }
+      break;
+
+    case S_MOTION:
+      {
+        // Wait for a sudden motion.  When we find it, record the time in microseconds
+        // so we can compare it to when the brightness changes.  Also record the brightness
+        // so we can look for changes.
+        if (moving) {
+          start = micros();
+          initial_brightness = analogRead(A0);
+          state = S_BRIGHTNESS;
+        }
+      }
+      break;
+
+    case S_BRIGHTNESS:
+      {
+        // Wait for a change in brightness compared to the original value that
+        // passes a threshold.  When we get it, report the latency.
+        // If it takes too long, then we time out and start over.
+        int brightness = analogRead(A0);
+        unsigned long now = micros();
+        if (abs(brightness - initial_brightness > BRIGHTNESS_CHANGE_THRESHOLD)) {
+          Serial.print("Latency ");
+          Serial.print(now - start);
+          Serial.print(" usecs\n");
+          state = S_CALM;
+        } else if (now - start > TIMEOUT_USEC) {
+          Serial.print("Timeout: no brightness change after motion, restarting\n");
+          state = S_CALM;
+        }
+      }
+      break;
+
+    default:
+      Serial.print("Error: Unrecognized state; restarting\n");
+      break;
+  }
+}
+
+
+// Determine whether we're undergoing acceleration or rotation.
+// Does this by comparing the gyros to a threshold and
+// comparing accelerations to see if they are changing.
+//*****************************************************
+inline bool moving(void)
+//*****************************************************
+{
+  byte accX, accY, accZ;
+  byte gyroX, gyroY, gyroZ;
+  getAccelerometerAndGyroHighCounts(accX, accY, accZ, gyroX, gyroY, gyroZ);
+
+  // If the gyros are above threshold, then we're moving.
+  if (gyroX > GYRO_THRESHOLD) { return true; }
+  if (gyroY > GYRO_THRESHOLD) { return true; }
+  if (gyroZ > GYRO_THRESHOLD) { return true; }
+
+  // See if the accelerations are sufficiently different from the
+  // ones we read last time.  If so, we're moving.
+  static int prevX = 0;
+  static int prevY = 0;
+  static int prevZ = 0;
+  bool ret = false;
+  if ( abs(accX - prevX) > ACCEL_CHANGE_THRESHOLD ) {
+    ret = true;
+  }
+  if ( abs(accY - prevY) > ACCEL_CHANGE_THRESHOLD ) {
+    ret = true;
+  }
+  if ( abs(accZ - prevZ) > ACCEL_CHANGE_THRESHOLD ) {
+    ret = true;
+  }
+  prevX = accX;
+  prevY = accY;
+  prevZ = accZ;
+
+  return ret;
+}
+
+//*****************************************************
+  // We only read the high-order bytes for two reasons:
+  // 1) Speed.
+  // 2) To avoid getting a measurement whose upper and lower bytes are
+  // inconsisent.
+inline void getAccelerometerAndGyroHighCounts(byte &accX, byte &accY, byte &accZ,
+                                       byte &gyroX, byte &gyroY, byte &gyroZ)
+//*****************************************************
+{
+    accX = readRegister(ACCEL_XOUT_H);
+    accY = readRegister(ACCEL_YOUT_H);
+    accZ = readRegister(ACCEL_ZOUT_H);
+    gyroX = readRegister(GYRO_XOUT_H);
+    gyroY = readRegister(GYRO_YOUT_H);
+    gyroZ = readRegister(GYRO_ZOUT_H);
+}
+
+
+//Read from register
 //*****************************************************
 unsigned int readRegister(byte thisRegister)
 //*****************************************************
@@ -307,7 +271,7 @@
 }

-//Sends a write command
+//Write to register
 //*****************************************************
 void writeRegister(byte thisRegister, byte thisValue)
 //*****************************************************
@@ -360,14 +324,11 @@
     // We want to sample as rapidly as possible, so that we have the minimum
     // latency between motion and its detection.  Even at 1kHz, we're going to
     // have some fraction of a second of latency on our reads.
-    //MPU6000_SPI_write(MPUREG_SMPLRT_DIV,0x04);     // Sample rate = 200Hz    Fsample= 1Khz/(4+1) = 200Hz
-    //writeRegister(MPUREG_SMPLRT_DIV,19);     // Sample rate = 50Hz    Fsample= 1Khz/(19+1) = 50Hz
     writeRegister(MPUREG_SMPLRT_DIV,0);
     delay(1);

     // Set the filter pass frequency on the low-pass filter to the maximum
     // (no filter, corresponding to a 2.1Khz cutoff).
-    //writeRegister(MPUREG_CONFIG, BITS_DLPF_CFG_20HZ);
     writeRegister(MPUREG_CONFIG, BITS_DLPF_CFG_2100HZ_NOLPF);
     delay(1);


move example

move example

--- Examples/Echo_SMS/Echo_SMS.ino
+++ Examples/Echo_SMS/Echo_SMS.ino
@@ -1,32 +0,0 @@
-#include <SIM900.h>
-#include <SoftwareSerial.h>
-
-SoftwareSerial ser(10,3);
-SIM900 sim900(&ser,7);
-
-char phone_number[]="0612345678";
-char pin_number[]="0000";
-
-void setup(){
-  Serial.begin(115200);
-
-  sim900.init(pin_number);
-}
-
-void loop(){
-  /*
-   * Lit le premier SMS
-   */
-  char numTel[15];
-  char* msg = sim900.readSMS(1,numTel,500);
-  if(msg != NULL){
-    Serial.print("SMS de: ");Serial.println(numTel);
-    Serial.println(msg);
-    sim900.deleteSMS(1);
-
-    //Envoi d'une réponse
-    sim900.sendSMS(numTel,"message recu");
-  }
-
-  delay(5000);
-}


Updated Max patch for Serial Call Response ASCII example


Improved inter-update delay accuracy

Improved inter-update delay accuracy

--- arduino-weather-station/arduino-weather-station.ino
+++ arduino-weather-station/arduino-weather-station.ino
@@ -50,7 +50,7 @@
     weatherSensor.begin();

     blinkLedSynchronous(statusLed, 3); // Device initialized
-    Serial.println("arduino-weather-station v1.4.1 (https://github.com/drasive/arduino-weather-station)");
+    Serial.println("arduino-weather-station v1.4.2 (https://github.com/drasive/arduino-weather-station)");
     Serial.println("Initialization successful\n");
     delay(1 * 1000);
 }
@@ -111,8 +111,8 @@

         statusLed.update();

-        delay(100);
-    } while (timeSinceLastUpdate <= UPDATE_INTERVAL * 1000);
+        delay(50);
+    } while (timeSinceLastUpdate <= UPDATE_INTERVAL * 1000 - (50 / 2));
 }


Delete mpu01.ino

Delete mpu01.ino

--- arduino/mpu01.ino
+++ arduino/mpu01.ino
@@ -1,217 +0,0 @@
-void mpuSetup() {
-    // join I2C bus (I2Cdev library doesn't do this automatically)
-    #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
-        Wire.begin();
-        Wire.setClock(400000); // 400kHz I2C clock. Comment this line if having compilation difficulties
-    #elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE
-        Fastwire::setup(400, true);
-    #endif
-
-    // initialize serial communication
-    // (115200 chosen because it is required for Teapot Demo output, but it's
-    // really up to you depending on your project)
-    //Serial.begin(115200); // Written in main loop
-    while (!Serial); // wait for Leonardo enumeration, others continue immediately
-
-    // NOTE: 8MHz or slower host processors, like the Teensy @ 3.3v or Ardunio
-    // Pro Mini running at 3.3v, cannot handle this baud rate reliably due to
-    // the baud timing being too misaligned with processor ticks. You must use
-    // 38400 or slower in these cases, or use some kind of external separate
-    // crystal solution for the UART timer.
-
-    // initialize device
-    // Serial.println(F("Initializing I2C devices..."));
-    mpu.initialize();
-    pinMode(INTERRUPT_PIN, INPUT);
-
-    // verify connection
-    // Serial.println(F("Testing device connections..."));
-    // Serial.println(mpu.testConnection() ? F("MPU6050 connection successful") : F("MPU6050 connection failed"));
-
-    // wait for ready
-    // Serial.println(F("\nSend any character to begin DMP programming and demo: "));
-    while (Serial.available() && Serial.read()); // empty buffer
-    //while (!Serial.available());                 // wait for data
-    //while (Serial.available() && Serial.read()); // empty buffer again
-
-    // load and configure the DMP
-    // Serial.println(F("Initializing DMP..."));
-    devStatus = mpu.dmpInitialize();
-
-    // supply your own gyro offsets here, scaled for min sensitivity
-    mpu.setXGyroOffset(220);
-    mpu.setYGyroOffset(76);
-    mpu.setZGyroOffset(-85);
-    mpu.setZAccelOffset(1788); // 1688 factory default for my test chip
-
-    // make sure it worked (returns 0 if so)
-    if (devStatus == 0) {
-        // turn on the DMP, now that it's ready
-        // Serial.println(F("Enabling DMP..."));
-        mpu.setDMPEnabled(true);
-
-        // enable Arduino interrupt detection
-        // Serial.println(F("Enabling interrupt detection (Arduino external interrupt 0)..."));
-        attachInterrupt(digitalPinToInterrupt(INTERRUPT_PIN), dmpDataReady, RISING);
-        mpuIntStatus = mpu.getIntStatus();
-
-        // set our DMP Ready flag so the main loop() function knows it's okay to use it
-        // Serial.println(F("DMP ready! Waiting for first interrupt..."));
-        dmpReady = true;
-
-        // get expected DMP packet size for later comparison
-        packetSize = mpu.dmpGetFIFOPacketSize();
-    } else {
-        // ERROR!
-        // 1 = initial memory load failed
-        // 2 = DMP configuration updates failed
-        // (if it's going to break, usually the code will be 1)
-        // Serial.print(F("DMP Initialization failed (code "));
-        // Serial.print(devStatus);
-        // Serial.println(F(")"));
-    }
-
-    // configure LED for output
-    pinMode(LED_PIN, OUTPUT);
-}
-
-
-
-// ================================================================
-// ===                    MAIN PROGRAM LOOP                     ===
-// ================================================================
-
-SENS mpuLoop(SENS temp) {
-    // if programming failed, don't try to do anything
-    if (!dmpReady) return;
-
-    // wait for MPU interrupt or extra packet(s) available
-    while (!mpuInterrupt && fifoCount < packetSize) {
-        // other program behavior stuff here
-        // .
-        // .
-        // .
-        // if you are really paranoid you can frequently test in between other
-        // stuff to see if mpuInterrupt is true, and if so, "break;" from the
-        // while() loop to immediately process the MPU data
-        // .
-        // .
-        // .
-    }
-
-    // reset interrupt flag and get INT_STATUS byte
-    mpuInterrupt = false;
-    mpuIntStatus = mpu.getIntStatus();
-
-    // get current FIFO count
-    fifoCount = mpu.getFIFOCount();
-
-    // check for overflow (this should never happen unless our code is too inefficient)
-    if ((mpuIntStatus & 0x10) || fifoCount == 1024) {
-        // reset so we can continue cleanly
-        mpu.resetFIFO();
-        // Serial.println(F("FIFO overflow!"));
-
-    // otherwise, check for DMP data ready interrupt (this should happen frequently)
-    } else if (mpuIntStatus & 0x02) {
-        // wait for correct available data length, should be a VERY short wait
-        while (fifoCount < packetSize) fifoCount = mpu.getFIFOCount();
-
-        // read a packet from FIFO
-        mpu.getFIFOBytes(fifoBuffer, packetSize);
-
-        // track FIFO count here in case there is > 1 packet available
-        // (this lets us immediately read more without waiting for an interrupt)
-        fifoCount -= packetSize;
-
-        #ifdef OUTPUT_READABLE_QUATERNION
-            // display quaternion values in easy matrix form: w x y z
-            mpu.dmpGetQuaternion(&q, fifoBuffer);
-            // Serial.print("quat\t");
-            // Serial.print(q.w);
-            // Serial.print("\t");
-            // Serial.print(q.x);
-            // Serial.print("\t");
-            // Serial.print(q.y);
-            // Serial.print("\t");
-            // Serial.println(q.z);
-        #endif
-
-        #ifdef OUTPUT_READABLE_EULER
-            // display Euler angles in degrees
-            mpu.dmpGetQuaternion(&q, fifoBuffer);
-            mpu.dmpGetEuler(euler, &q);
-            // Serial.print("euler\t");
-            // Serial.print(euler[0] * 180/M_PI);
-            // Serial.print("\t");
-            // Serial.print(euler[1] * 180/M_PI);
-            // Serial.print("\t");
-            // Serial.println(euler[2] * 180/M_PI);
-        #endif
-
-		// *** THIS ONE IS USED ***
-
-        #ifdef OUTPUT_READABLE_YAWPITCHROLL
-            // display Euler angles in degrees
-            mpu.dmpGetQuaternion(&q, fifoBuffer);
-            mpu.dmpGetGravity(&gravity, &q);
-            mpu.dmpGetYawPitchRoll(ypr, &q, &gravity);
-
-			// Change structure
-
-			temp.gyr.yaw = ypr[0] * 180/M_PI + 180;
-			temp.gyr.roll = ypr[1] * 180/M_PI;
-			temp.gyr.pitch = ypr[2] * 180/M_PI * -1;
-
-        #endif
-
-        #ifdef OUTPUT_READABLE_REALACCEL
-            // display real acceleration, adjusted to remove gravity
-            mpu.dmpGetQuaternion(&q, fifoBuffer);
-            mpu.dmpGetAccel(&aa, fifoBuffer);
-            mpu.dmpGetGravity(&gravity, &q);
-            mpu.dmpGetLinearAccel(&aaReal, &aa, &gravity);
-            // Serial.print("areal\t");
-            // Serial.print(aaReal.x);
-            // Serial.print("\t");
-            // Serial.print(aaReal.y);
-            // Serial.print("\t");
-            // Serial.println(aaReal.z);
-        #endif
-
-        #ifdef OUTPUT_READABLE_WORLDACCEL
-            // display initial world-frame acceleration, adjusted to remove gravity
-            // and rotated based on known orientation from quaternion
-            mpu.dmpGetQuaternion(&q, fifoBuffer);
-            mpu.dmpGetAccel(&aa, fifoBuffer);
-            mpu.dmpGetGravity(&gravity, &q);
-            mpu.dmpGetLinearAccel(&aaReal, &aa, &gravity);
-            mpu.dmpGetLinearAccelInWorld(&aaWorld, &aaReal, &q);
-            // Serial.print("aworld\t");
-            // Serial.print(aaWorld.x);
-            // Serial.print("\t");
-            // Serial.print(aaWorld.y);
-            // Serial.print("\t");
-            // Serial.println(aaWorld.z);
-        #endif
-
-        #ifdef OUTPUT_TEAPOT
-            // display quaternion values in InvenSense Teapot demo format:
-            teapotPacket[2] = fifoBuffer[0];
-            teapotPacket[3] = fifoBuffer[1];
-            teapotPacket[4] = fifoBuffer[4];
-            teapotPacket[5] = fifoBuffer[5];
-            teapotPacket[6] = fifoBuffer[8];
-            teapotPacket[7] = fifoBuffer[9];
-            teapotPacket[8] = fifoBuffer[12];
-            teapotPacket[9] = fifoBuffer[13];
-            Serial.write(teapotPacket, 14);
-            teapotPacket[11]++; // packetCount, loops at 0xFF on purpose
-        #endif
-
-        // blink LED to indicate activity (commented out)
-        // blinkState = !blinkState;
-        // digitalWrite(LED_PIN, blinkState);
-    }
-	return temp;
-}


Instrument state always synchronized before polling MIDI.

--- examples/MalariaFMSynth/MalariaDSP1/MalariaDSP1.ino
+++ examples/MalariaFMSynth/MalariaDSP1/MalariaDSP1.ino
@@ -33,8 +33,8 @@
 }

 void updateControl() {
+  instrument.updateControl();
   MIDI.read();
-  instrument.updateControl();
 }

 int updateAudio() {


Fixed merge conflict

Fixed merge conflict

--- arduino/arduino.ino
+++ arduino/arduino.ino
@@ -6,6 +6,8 @@

 unsigned long nextUpdate = 0;

+int timer1_counter;
+
 void setup()
 {
     Serial.begin(57600);
@@ -13,16 +15,36 @@
     stepperX.setMaxSpeed(1000);
     stepperX.setAcceleration(300);

-    stepperY.setMaxSpeed(1000);
-    stepperY.setAcceleration(300);
+
+    stepperY.setMaxSpeed(750);
+    stepperY.setAcceleration(100);
+

+    // initialize timer1
+    noInterrupts();           // disable all interrupts
+    TCCR1A = 0;
+    TCCR1B = 0;
+
+    // Set timer1_counter to the correct value for our interrupt interval
+    timer1_counter = 64886;   // preload timer 65536-16MHz/256/100Hz
+    //timer1_counter = 64286;   // preload timer 65536-16MHz/256/50Hz
+    //timer1_counter = 34286;   // preload timer 65536-16MHz/256/2Hz
+
+    TCNT1 = timer1_counter;   // preload timer
+    //TCCR1B |= (1 << CS11) | (1 << CS10);    // 64 prescaler
+    TCCR1B |= (1 << CS11);    // 8 prescaler
+    TIMSK1 |= (1 << TOIE1);   // enable timer overflow interrupt
+    interrupts();             // enable all interrupts
 }
-
+ISR(TIMER1_OVF_vect)        // interrupt service routine
+{
+    TCNT1 = timer1_counter;   // preload timer
+    stepperX.run();
+    stepperY.run();
+}
 void loop()
 {

-    stepperX.run();
-    stepperY.run();

     handleInput();


comment

comment

--- arduino/arduino.ino
+++ arduino/arduino.ino
@@ -113,7 +113,7 @@
 void OnDumpIn()
 {
   int valve       = (int)      cmdMessenger.readFloatArg();
-  int milliliters = (int)      cmdMessenger.readFloatArg();  // 65 liters each time by design
+  int milliliters = (int)      cmdMessenger.readFloatArg();  // 65 liters max each time by design

   cmdMessenger.sendCmd(kAcknowledge,"Set valve dosage");


went back to stable version of the BitController; the Queue class is not utilized

--- BitController/BitController.ino
+++ BitController/BitController.ino
@@ -23,7 +23,6 @@
  *
  */

-#include "Queue.h"

 //include Bluetooth connectivity for debugging
 #include <SoftwareSerial.h>
@@ -77,18 +76,6 @@
 //threshold intensity values for each cardinal point
 int move_threshold = 55;

-uint8_t dir[5] = {0};
-//1 is north
-//2 is west
-//3 is east
-//4 is north-west
-//5 is north-east
-//0 is no signal
-uint8_t index = 0;
-boolean motion = false;
-
-Queue<uint8_t> lastDir;
-
 void setup()
 {
   Serial.begin(115200);
@@ -143,16 +130,6 @@
   Serial.print(e_base);
   Serial.println();
   Serial.println();
-
-  //initializes movement queue
-  lastDir.enqueue(0);
-  lastDir.enqueue(0);
-  lastDir.enqueue(0);
-
-  analogWrite(l1_motor, 0);
-  analogWrite(l2_motor, 0);
-  analogWrite(r1_motor, 0);
-  analogWrite(r2_motor, 0);
 }

@@ -233,14 +210,82 @@
   Serial.println();

   delay(10);
-
-  index++;
-  if(index > 2)
-  {
-    dir[2] = dir[1];
-    dir[1] = dir[0];
-    index == 0;
-  }
+}
+
+
+
+//void move()
+//Determines movement direction for Bit based on intensity values of each
+//sensor. this method has been replaced by the determineDirection() method
+// as of Version 0.1.0 and was only used as a test with the north and east
+//cardinal points
+void move()
+{
+  printSensors();
+
+  //Check if movement threshold has been reached by any of the sensors.
+  if(sensorVals[n] > move_threshold || sensorVals[w] > move_threshold || sensorVals[e] > move_threshold)
+  {
+    //If north intensity is higher than east intensity, the Bit should move
+    //due north.
+    if ((sensorVals[n]*.6) > sensorVals[e])
+    {
+      BT.print("go north");
+      Serial.print("go north");
+      analogWrite(l1_motor, 255);
+      analogWrite(l2_motor, 0);
+      analogWrite(r1_motor, 255);
+      analogWrite(r2_motor, 0);
+    }
+    //If east intensity is higher than north intensity, the Bit should move
+    //due east.
+    else if ((sensorVals[e]*.6) > sensorVals[n])
+    {
+      BT.print("go east");
+      Serial.print("go east");
+      analogWrite(l1_motor, 255);
+      analogWrite(l2_motor, 0);
+      analogWrite(r1_motor, 0);
+      analogWrite(r2_motor, 255);
+    }
+    //If the north and east intensity ratios are comparable, then Bit should
+    //move due north-east. If the ratio of north intensity to east intensity is
+    //1, then the intensities are equal. If the ratio is within 0.15 of 1, so
+    //either 0.85 and 1.15, then the intensities are comparable and Bit moves
+    //due north-east.
+    else if (abs(((double)sensorVals[n]/(double)sensorVals[e]) - 1)  < 0.15)
+    {
+      BT.print("go north-east");
+      Serial.print("go north-east");
+      analogWrite(l1_motor, 255);
+      analogWrite(l2_motor, 0);
+      analogWrite(r1_motor, 55);
+      analogWrite(r2_motor, 0);
+    }
+    //If no direction can be determined, move along previously determined path
+    else
+    {
+      //some error
+      //continue along previous path
+      BT.print("don't know");
+      Serial.print("don't know");
+    }
+  }
+  //if movement threshold has not been reached, Bit will stop
+  else
+  {
+    BT.print("no signal");
+    Serial.print("no signal");
+    analogWrite(l1_motor, 0);
+    analogWrite(l2_motor, 0);
+    analogWrite(r1_motor, 0);
+    analogWrite(r2_motor, 0);
+  }
+
+//  BT.println();
+//  BT.println();
+//  Serial.println();
+//  Serial.println();
 }

@@ -257,18 +302,14 @@
       //if the west and east intensities are very close, this means that the
       //BitBeacon is coming directly from north and Bit should head north
       if (abs(sensorVals[w]-sensorVals[e]) < 50)
-      {
-        dir[index] = 1;
-        if(index == 2 && dir[0] = 1 && dir[1] = 1 && dir[2] = 1)
-        {
-          analogWrite(l1_motor, 200);
-          analogWrite(l2_motor, 0);
-          analogWrite(r1_motor, 200);
-          analogWrite(r2_motor, 0);
-          //lcd.println("head north");
-          Serial.println("head north");
-          BT.println("head north");
-        }
+      {
+        analogWrite(l1_motor, 200);
+        analogWrite(l2_motor, 0);
+        analogWrite(r1_motor, 200);
+        analogWrite(r2_motor, 0);
+        //lcd.println("head north");
+        Serial.println("head north");
+        BT.println("head north");
       }
       //If west intensity is greater than east intensity, then this means
       //that the BitBeacon signal is coming from north-west
@@ -276,18 +317,13 @@
       //turns left (west)
       else if (sensorVals[w]*1.2 >= sensorVals[e]*1.2)
       {
-        dir[index] = 4;
-        if(index == 2 && dir[0] = 4 && dir[1] = 4 && dir[2] = 4)
-        {
-          analogWrite(l1_motor, 50);
-          analogWrite(l2_motor, 0);
-          analogWrite(r1_motor, 230);
-          analogWrite(r2_motor, 0);
-          //lcd.println("head north-west");
-          Serial.println("head north-west");
-          BT.println("head north-west");
-        }
-
+        analogWrite(l1_motor, 50);
+        analogWrite(l2_motor, 0);
+        analogWrite(r1_motor, 230);
+        analogWrite(r2_motor, 0);
+        //lcd.println("head north-west");
+        Serial.println("head north-west");
+        BT.println("head north-west");
       }
       //If east intensity is greater than east intensity, then this means
       //that the BitBeacon signal is coming from north-east
@@ -295,17 +331,13 @@
       //turns right (east)
       else if (sensorVals[e]*1.2 >= sensorVals[w]*1.2)
       {
-        dir[index] = 5;
-        if(index == 2 && dir[0] = 5 && dir[1] = 5 && dir[2] = 5)
-        {
-          analogWrite(l1_motor, 230);
-          analogWrite(l2_motor, 0);
-          analogWrite(r1_motor, 50);
-          analogWrite(r2_motor, 0);
-          //lcd.println("head north-east");
-          Serial.println("head north-east");
-          BT.println("head north-east");
-        }
+        analogWrite(l1_motor, 230);
+        analogWrite(l2_motor, 0);
+        analogWrite(r1_motor, 50);
+        analogWrite(r2_motor, 0);
+        //lcd.println("head north-east");
+        Serial.println("head north-east");
+        BT.println("head north-east");
       }
       //if neither conditions above are met, then Bit contiues along the
       //previous known direction
@@ -325,17 +357,12 @@
     //As of Version 0.1.0. the delineation between east and north-east is a fuzzy
     else if ((sensorVals[e]*.65) > sensorVals[n] && sensorVals[e]*.9 > sensorVals[w])
     {
-      dir[index] = 3;
-      if(index == 2 && dir[0] = 3 && dir[1] = 3 && dir[2] = 3)
-      {
-        analogWrite(l1_motor, 200);
-        analogWrite(l2_motor, 0);
-        analogWrite(r1_motor, 0);
-        analogWrite(r2_motor, 200);
-        Serial.println("head east");
-        BT.println("head east");
-      }
-
+      analogWrite(l1_motor, 200);
+      analogWrite(l2_motor, 0);
+      analogWrite(r1_motor, 0);
+      analogWrite(r2_motor, 200);
+      Serial.println("head east");
+      BT.println("head east");
     }

     //if the west intensity value is greater than the north and west intensity
@@ -345,16 +372,12 @@
     //As of Version 0.1.0. the delineation between west and north-west is a fuzzy
     else if ((sensorVals[w]*.65) > sensorVals[n] && sensorVals[w]*.9 > sensorVals[e])
     {
-      dir[index] = 2;
-      if(index == 2 && dir[0] = 2 && dir[1] = 2 && dir[2] = 2)
-      {
         analogWrite(l1_motor, 0);
         analogWrite(l2_motor, 200);
         analogWrite(r1_motor, 200);
         analogWrite(r2_motor, 0);
-        Serial.println("head west");
-        BT.println("head west");
-        }
+       Serial.println("head west");
+       BT.println("head west");
     }

     //If no direction can be determined, Bit continues along the previously
@@ -369,16 +392,12 @@
   //If a movement threshold has not been crossed, Bit stops moving.
   else
   {
-    dir[index] = 0;
-    if(index == 2 && dir[0] = 0 && dir[1] = 0 && dir[2] = 0)
-    {
-      analogWrite(l1_motor, 0);
-      analogWrite(l2_motor, 0);
-      analogWrite(r1_motor, 0);
-      analogWrite(r2_motor, 0);
-      Serial.println("no signal");
-      BT.println("no signal");
-    }
+    analogWrite(l1_motor, 0);
+    analogWrite(l2_motor, 0);
+    analogWrite(r1_motor, 0);
+    analogWrite(r2_motor, 0);
+    Serial.println("no signal");
+    BT.println("no signal");
   }
 }

@@ -449,4 +468,3 @@
   }

 }
-


Adjust beat intensity

Adjust beat intensity

--- heartbeat_with_pulse.ino
+++ heartbeat_with_pulse.ino
@@ -30,11 +30,11 @@
 Bounce modeButton;

 // config
-int staticBpm = 60; // From http://ecg.utah.edu/img/items/Normal%2012_Lead%20ECG.jpg
+int staticBpm = 60; // in case no pulse is found
 int maxBpm = 180; // avoids the system going crazy
 byte beat[]  = {2,2,2,2,3,4,3,2,1,0,10,2,2,3,4,6,8,5,3,3,3,3}; // From http://ecg.utah.edu/img/items/Normal%2012_Lead%20ECG.jpg
 byte beatLength = 22;
-int beatMaxIntensity = 12; // max value in beat array
+int beatMaxIntensity = 10; // max value in beat array
 int movesPerBeat = 4;
 int minMagnitude = 0;
 int maxMagnitude = 50; // max difference between two magnitude measurements from accelerometer at which we show maxHue


initial dmp + rs485 commit, untested

initial dmp + rs485 commit, untested

--- arduino/src/mpu9250_basicDMP/mpu9250_basicDMP.ino
+++ arduino/src/mpu9250_basicDMP/mpu9250_basicDMP.ino
@@ -1,16 +1,41 @@
 #include "freeram.h"
-
 #include "mpu.h"
 #include "I2Cdev.h"
+#include "RS485_protocol.h"
+
+const byte ENABLE_PIN = 4;
+const byte SLAVE_ID = 1;
+union float2bytes { float f; byte b[sizeof(float)]; };
+
+
+void fWrite (const byte content)
+  {
+  Serial.write (content);
+  }
+
+int fAvailable ()
+  {
+  return Serial.available ();
+  }
+
+ int fRead ()
+  {
+  return Serial.read ();
+  }
+

 int ret;
 void setup() {
     Fastwire::setup(400,0);
     Serial.begin(38400);
     ret = mympu_open(200);
+    pinMode (ENABLE_PIN, OUTPUT);  // driver output enable
+    digitalWrite (ENABLE_PIN, LOW);
+
+#ifdef DMP_DEBUG
     Serial.print("MPU init: "); Serial.println(ret);
     Serial.print("Free mem: "); Serial.println(freeRam());
-
+#endif
 }

 unsigned int c = 0; //cumulative number of successful MPU/DMP reads
@@ -19,8 +44,97 @@
 unsigned int err_o = 0; //cumulative number of MPU/DMP reads that had overflow bit set

 void loop() {
-    ret = mympu_update();

+    byte buffer [10];
+
+    byte received = recvMsg (fAvailable, fRead, buffer, sizeof (buffer));
+
+    if (received != 0)
+      {
+      if (buffer [0] != SLAVE_ID)
+        return;  // not my device
+
+      //TODO: remove
+      if (buffer [1] != 2)
+        return;  // unknown command
+
+      ret = mympu_update(); // get new sensor data
+      delay (2);  // give the master a moment to prepare to receive
+
+      float2bytes ypr0;
+      float2bytes ypr1;
+      float2bytes ypr2;
+      float2bytes gyro0;
+      float2bytes gyro1;
+      float2bytes gyro2;
+      float2bytes accel0;
+      float2bytes accel1;
+      float2bytes accel2;
+
+      ypr0.f = mympu.ypr[0];
+      ypr1.f = mympu.ypr[1];
+      ypr2.f = mympu.ypr[2];
+      gyro0.f = mympu.gyro[0];
+      gyro1.f = mympu.gyro[1];
+      gyro2.f = mympu.gyro[2];
+      accel0.f = mympu.accel[0];
+      accel1.f = mympu.accel[1];
+      accel2.f = mympu.accel[2];
+
+//receiving on stm32:
+//       for ( int i=0; i < sizeof(float); i++ )
+//         f2b.b[i] = read_byte();
+//       x = f2b.f;
+
+      byte msg [] = {
+         0,  // send to master
+		 SLAVE_ID, // sent from SLAVE_ID
+         ypr0.b[0],
+		 ypr0.b[1],
+		 ypr0.b[2],
+		 ypr0.b[3],
+		 ypr1.b[0],
+		 ypr1.b[1],
+		 ypr1.b[2],
+		 ypr1.b[3],
+		 ypr2.b[0],
+		 ypr2.b[1],
+		 ypr2.b[2],
+		 ypr2.b[3],
+		 gyro0.b[0],
+		 gyro0.b[1],
+		 gyro0.b[2],
+		 gyro0.b[3],
+		 gyro1.b[0],
+		 gyro1.b[1],
+		 gyro1.b[2],
+		 gyro1.b[3],
+		 gyro2.b[0],
+		 gyro2.b[1],
+		 gyro2.b[2],
+		 gyro2.b[3],
+		 accel0.b[0],
+		 accel0.b[1],
+		 accel0.b[2],
+		 accel0.b[3],
+		 accel1.b[0],
+		 accel1.b[1],
+		 accel1.b[2],
+		 accel1.b[3],
+		 accel2.b[0],
+		 accel2.b[1],
+		 accel2.b[2],
+		 accel2.b[3],
+      };
+
+      digitalWrite (ENABLE_PIN, HIGH);  // enable sending
+      sendMsg (fWrite, msg, sizeof msg);
+      Serial.flush();
+      digitalWrite (ENABLE_PIN, LOW);  // disable sending
+
+     }
+
+#ifdef DMP_DEBUG
     switch (ret) {
 	case 0: c++; break;
 	case 1: np++; return;
@@ -44,4 +158,5 @@
 	    Serial.print(" a2: "); Serial.print(mympu.accel[1]);
 	    Serial.print(" a3: "); Serial.println(mympu.accel[2]);
     }
+#endif
 }


working except for return not using interrupts

--- beanWheelwriterControl/beanWheelwriterControl.ino
+++ beanWheelwriterControl/beanWheelwriterControl.ino
@@ -63,6 +63,7 @@
   //PORTD |= 0b00000100;

   pinMode(d2, INPUT); // listening pin
+  // PORTD |= 0b01000000; // the listening pin is mapped to bit 6

   // start the input pin off (meaning the bus is high, normal state)
   PORTD &= 0b11111011;
@@ -93,15 +94,15 @@
         print_str("\"the quick brown fox jumps over the lazy dog.\"");
         send_return(46);*/

-        print_str("testing");
-        /*print_str("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
+        //print_str("testing");
+        print_str("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
         send_return(26);

         print_str("1234567890");
         send_return(10);

         print_str(",./?");
-        send_return(4);*/
+        send_return(4);

         /*
         sendByteOnPin(0b00000000);
@@ -121,7 +122,7 @@
   }
 }

-void sendByteOnPin(int command) {
+inline void sendByteOnPin(int command) {
     // This will actually send 10 bytes,
     // starting with a zero (always)
     // and then the next nine bytes
@@ -261,7 +262,7 @@
     q.enqueue(0b000001010);
     sendBytes();

-    //delay(LETTER_DELAY); // before next character
+    delay(LETTER_DELAY); // before next character
 }

 void send_return(int numChars) {
@@ -376,12 +377,16 @@

 void sendBytes() {
     while (!q.isEmpty()) {
+        //Serial.println("sending bytes!");
         sendByteOnPin(q.dequeue());
         // wait for low then high (for a zero)
-        while (digitalRead(d2) == 1) {
+        //PORTD |= 0b01000000;
+        //int pinStatus = ((PIND & 0b01000000) >> 6);
+        //Serial.println(pinStatus);
+        while (((PIND & 0b01000000) >> 6) == 1) {
           // busy
         }
-        while (digitalRead(d2) == 0) {
+        while (((PIND & 0b01000000) >> 6) == 0) {
           // busy
         }
     }


Add the fan status to the arduino output message

--- computer_box/computer_box.ino
+++ computer_box/computer_box.ino
@@ -56,6 +56,8 @@
   read_dht_temp();
   read_ds18b20_temp();

+  read_fan_status();
+
   Serial.println("}");

   toggle_led();
@@ -109,6 +111,12 @@
   }
 }

+void read_fan_status(4) {
+  int fan_status digitalRead(fan_pin);
+
+  Serial.print("\"fan\":"); Serial.print(fan_status); Serial.print(',');
+}
+
 float get_ds18b20_temp(uint8_t *addr) {
   byte data[12];

@@ -134,7 +142,6 @@

   return TemperatureSum;
 }
-
 /************************************
 * Utitlity Methods
 *************************************/


Final fix.

Final fix.

--- software/Arduino/ServoController/ServoController.ino
+++ software/Arduino/ServoController/ServoController.ino
@@ -61,6 +61,7 @@
     correctionFactorXY += (Serial.read() - '0');
     if (negXY) correctionFactorXY = -correctionFactorXY;
     rotateStepperBy(correctionFactorXY);
+    currentZBodyPosition += correctionFactorXY;
     currentZMotorPosition += correctionFactorXY;
     if (Serial.read() == '1') negZ = 1;
     correctionFactorZ += (Serial.read() - '0') * 100;


test read after soldering finsihed; to be tested

--- Flasher.ino
+++ Flasher.ino
@@ -66,16 +66,29 @@
   static bool first = true;

   if ( first ) {
-
+
+#if 0
     for ( int i=0; i<sizeof(eepromData); ++i )
       eepromData[i] = (uint8_t)(i & 0xff);

     HexDump(eepromData, sizeof(eepromData), eepromAddr);
+#endif

     first = false;
   }

-  testAddressLatches();
+  //testAddressLatches();
+
+  // read 16 bytes from (E)EPROM
+  for ( int i=0; i<16; ++i ) {
+
+    eepromAddr = (uint32_t)(i + 0x0000);
+    eeprom.setAddress( eepromAddr );
+
+    eepromData[i] = eeprom.read();
+  }
+
+  HexDump(eepromData, 16, eepromAddr);
 }

 /** Function to create hex dump from data, organized as 8 bit words. */


Update PowerOFF.ino

Update PowerOFF.ino

--- examples/Basics/PowerOFF/PowerOFF.ino
+++ examples/Basics/PowerOFF/PowerOFF.ino
@@ -22,7 +22,7 @@
 void loop() {

   if(M5.BtnA.wasPressed()) {
-    M5.Power.powerOFF();
+    M5.powerOFF();
   }

   M5.update();


add button capability

add button capability

--- arduino/garage_controller/garage_controller.ino
+++ arduino/garage_controller/garage_controller.ino
@@ -8,6 +8,7 @@
 const int sensorPin =   2;      // the number of the door sensor pin
 const int pirPin =      3;      // the number of the motion detector pin
 const int relayPin =    4;      // the number of the door opening relay pin
+const int buttonPin =   5;      // the number of the button switch pin

 // Variables will change:
@@ -25,8 +26,19 @@
   digitalWrite(pirPin, LOW);
   pinMode(relayPin, OUTPUT);
   digitalWrite(relayPin, HIGH);
+  pinMode(buttonPin, INPUT);
+  digitalWrite(buttonPin, HIGH);
   //delay(20000); // Wait for PIR to warm up
   Serial.begin(9600);
+}
+
+String checkButton() {
+  int state = digitalRead(buttonPin);
+  if (state == HIGH) {
+    return "UNPRESSED";
+  } else {
+    return "PRESSED";
+  }
 }

 String checkDoor() {
@@ -84,7 +96,7 @@
   if(currentMillis - previousMillis > interval) {
     previousMillis = currentMillis;
     checkRelay();
-    Serial.println(checkDoor() + ":" + checkMotion());
+    Serial.println(checkDoor() + ":" + checkMotion() + ":" + checkButton());
     digitalWrite(ledPin, ledState);
   }
 }


trying to throw more garbage away

trying to throw more garbage away

--- KISS_OSD/KISS_OSD.ino
+++ KISS_OSD/KISS_OSD.ino
@@ -165,6 +165,8 @@
   }
 }

+static uint8_t lastTempUnit;
+
 void setup()
 {
   uint8_t i = 0;
@@ -194,6 +196,7 @@
   while (!OSD.notInVSync());
   cleanScreen();
   settings.ReadSettings();
+  lastTempUnit = settings.m_tempUnit;
   DISPLAY_NICKNAME_DV = setupPPM(DISPLAY_NICKNAME_DV);
   DISPLAY_TIMER_DV = setupPPM(DISPLAY_TIMER_DV);
   DISPLAY_RC_THROTTLE_DV = setupPPM(DISPLAY_RC_THROTTLE_DV);
@@ -205,7 +208,7 @@
   DISPLAY_STATS_DV = setupPPM(DISPLAY_STATS_DV);
   DISPLAY_ESC_TEMPERATURE_DV = setupPPM(DISPLAY_ESC_TEMPERATURE_DV);
   NewSerial.begin(115200);
-  delay(5000); // Wait until FC is ready - otherwise we get garbage data
+  //delay(5000); // Wait until FC is ready - otherwise we get garbage data; this didn't work. Now trying to throw away data.
 }

 static int16_t  throttle = 0;
@@ -287,12 +290,18 @@
 static uint8_t minBytes = 0;
 static uint8_t recBytes = 0;
 static uint32_t LastLoopTime = 0;
+static uint32_t StartupTime = 0;

 boolean ReadTelemetry()
 {
   uint16_t i = 0;
   minBytes = 100;
   recBytes = 0;
+
+  if(StartupTime == 0)
+  {
+    StartupTime = millis();
+  }

   while(recBytes < minBytes && micros()-LastLoopTime < 20000)
   {
@@ -300,7 +309,12 @@
     while(NewSerial.available()) serialBuf[recBytes++] = NewSerial.read();
     if(recBytes == 1 && serialBuf[0] != 5)recBytes = 0; // check for start byte, reset if its wrong
     if(recBytes == 2) minBytes = serialBuf[1]+STARTCOUNT+1; // got the transmission length
-    if(recBytes == minBytes){
+    if(recBytes == minBytes)
+    {
+       if(millis()-StartupTime < 3000)
+       {
+         return false; //throwing away garbage data sent by FC during startup phase
+       }
        uint32_t checksum = 0;
        for(i=2;i<minBytes;i++){
           checksum += serialBuf[i];
@@ -421,8 +435,25 @@
            for(i=0; i<4; i++)
            {
              ESCTemps[i] = 9 * ESCTemps[i] / 5 + 32;
+             if(lastTempUnit == 0)
+             {
+               maxTemps[i] = 9 * maxTemps[i] / 5 + 32;
+             }
+           }
+           if(lastTempUnit == 0)
+           {
+             MaxTemp = 9 * MaxTemp / 5 + 32;
            }
          }
+         if(lastTempUnit == 1 && settings.m_tempUnit == 0)
+         {
+           for(i=0; i<4; i++)
+           {
+             maxTemps[i] = (maxTemps[i] - 32) * 5 / 9;
+           }
+           MaxTemp = (MaxTemp - 32) * 5 / 9;
+         }
+         lastTempUnit = settings.m_tempUnit;
          if(armedOnce)
          {
            MaxTemp = findMax4(MaxTemp, ESCTemps, 4);


switched to SDfat library and changed the SD fail interaction

--- code/Reciever_0/Reciever_0.ino
+++ code/Reciever_0/Reciever_0.ino
@@ -1,20 +1,24 @@
 #include <RFM69.h>
 #include <SPI.h>
 #include "RTClib.h"
-#include <SD.h>
+#include <SdFat.h>

 #define NODE_ID     0 //Network Node ID. All Senders must send to this ID #
 #define NETWORK_ID  101 //Network ID. All Nodes must be on the same Network
 #define FREQUENCY   RF69_433MHZ //Match this to the frequency of your radio
 #define KEY         "p6ZNvTmGfdY2hUXb" //has to be same 16 characters/bytes on all nodes.
 #define LED         3 //LED Pin Number
-#define debug       1 //debug false/true
+#define debug       0 //debug false/true

 /*==============|| DS3231_RTC ||==============*/
 RTC_DS3231 rtc; //Initialize the Real Time Clock
-DateTime now;
+DateTime now; //initialize a DateTime Object
+
+

 /*==============|| SD ||==============*/
+SdFat SD; //This is the SD Card
+SdFile dataFile; //this is the DatFile
 const int CHIP_SELECT = 4; //SPI SS pin for SD card
 const int CARD_DETECT = 5; //Card Detect Pin
 int CARD_PRESENT; //var for Card Detect sensor reading
@@ -42,13 +46,16 @@
   if (!SD.begin(CHIP_SELECT)) { //Checks the SD card to make sure it responds. On success, it initializes it.
     if (debug) Serial.println("Card failed, or not present");
     CARD_PRESENT = digitalRead(CARD_DETECT);  //read CD pin
+    //this delays the program while there is no card inserted.
     while (CARD_PRESENT == 0) { //The CD pin is 0 if there is no card inserted
       CARD_PRESENT = digitalRead(CARD_DETECT); //read it the value for every loop, or we will never exit the While Loop
-      Blink(LED, 50); //blink!
-    }
-    if (!SD.begin(CHIP_SELECT))
-      Blink(LED, 50);
-    if (debug) Serial.println("SD card initialized"); //when the SD card is re-inserted, intiliaze it!
+      Blink(LED, 50); //blink to show an error.
+    }
+    delay(10); //wait for card to stablize from insertion before initializing
+
+    if (!SD.begin(CHIP_SELECT)) //when the SD card is re-inserted, intiliaze it!
+      Blink(LED, 50); //if it fails again....well, you're probably out of luck.
+    if (debug) Serial.println("SD card initialized");
   }
   if (debug) Serial.println("SD card initialized"); ///Victory

@@ -59,11 +66,6 @@
     Serial.print("RFM69 initialized");
     Serial.print(", key: ");
     Serial.println(KEY);
-  }
-  if(debug) {
-    DateTime now = rtc.now();
-    Serial.print("Current time is: ");
-    Serial.println(now.unixtime());
   }
 }

@@ -79,62 +81,43 @@
         radio.sendACK();
       }
       if (debug) printData(); //Print the data out to the Serial Monitor
-      //ID, time, sensor, temp, excite volts, battery volts, number of attempts
-      if (writeDataToCard(data_rcv.nodeID, now.unixtime(), data_rcv.sens_val, data_rcv.temp, data_rcv.excite_v, data_rcv.batt_v, data_rcv.num_attempts)) { //Write the data to the SD card
+      //and write the data to the SD card
+      if (writeDataToCard(data_rcv.nodeID, now.unixtime(), data_rcv.sens_val, data_rcv.temp, data_rcv.excite_v, data_rcv.batt_v, data_rcv.num_attempts)) {
         Blink(LED, 100); //Blink the LED on success
       }
     }
     else { //if the data is an unexpected size
       if (debug) Serial.println("Invalid packet received!!");
-      if (badPacket(now.unixtime())) {
-        Blink(LED, 100);
-        Blink(LED, 100);
+      if (badPacket(now.unixtime())) { //note that int he log.txt file and blink thrice
+        Blink(LED, 50);
+        Blink(LED, 50);
+        Blink(LED, 50);
       }
     }
   }
+  checkSdCard();
 }

 int writeDataToCard(int id, long utm, int s_v, float t, float e_v, float b_v, int num_a) {
-  //ID, time, sensor, temp, excite volts, battery volts, number of attempts
-  CARD_PRESENT = digitalRead(CARD_DETECT);
-  if (CARD_PRESENT == 0) {
-    Blink(LED, 25);
-    Blink(LED, 25);
-    if (debug) Serial.println("Card Not Present");
-    while (CARD_PRESENT == 0) {
-      CARD_PRESENT = digitalRead(CARD_DETECT);
-      Blink(LED, 100);
-    }
-    if (!SD.begin(CHIP_SELECT))  Blink(LED, 25); //Serial.println("SD card initialized");
-    else Blink(LED, 25); Blink(LED, 25); //Serial.println("SD Card Failed to Initialize");
-  }
-  //Write data to card
+//  CARD_PRESENT = digitalRead(CARD_DETECT); //Check for card insertion
+//  if (CARD_PRESENT == 0) { //if card NOT present....Wait and blink until it is
+//    if (debug) Serial.println("Card Not Present");
+//    while (CARD_PRESENT == 0) {
+//      CARD_PRESENT = digitalRead(CARD_DETECT);
+//      Blink(LED, 50);
+//    }
+//    if (!SD.begin(CHIP_SELECT))
+//      Blink(LED, 25);
+//    if (debug) Serial.println("SD card initialized");
+//  }
+
+  //creates filename to store data based on the Node Address
   String address = String(String(NETWORK_ID) + "_" + String(id));
-  String fileName = String(address + ".csv"); //creates filename based on Node Address
+  String fileName = String(address + ".csv");
   char __fileName[fileName.length() + 1];
   fileName.toCharArray(__fileName, sizeof(__fileName));
-  File dataFile = SD.open(__fileName, FILE_WRITE); //Opens file (creates if it doesn't exist) and Appends data to the end of it
-  if (dataFile) {
-    dataFile.print(NETWORK_ID);
-    dataFile.print("_");
-    dataFile.print(id);
-    dataFile.print(",");
-    dataFile.print(utm);
-    dataFile.print(",");
-    dataFile.print(s_v);
-    dataFile.print(",");
-    dataFile.print(t);
-    dataFile.print(",");
-    dataFile.print(b_v);
-    dataFile.print(",");
-    dataFile.print(e_v);
-    dataFile.print(",");
-    dataFile.print(num_a);
-    dataFile.println();
-    dataFile.close();
-    return 1; //returns a 1, Success
-  }
-  else {
+  //Opens and checks file
+  if (!dataFile.open(__fileName, O_RDWR | O_CREAT | O_AT_END)) {
     if (debug) {
       Serial.print("Error opening: ");
       Serial.println(fileName);
@@ -143,6 +126,25 @@
     Blink(LED, 100);
     return 0; //returns a 0, failure
   }
+  //Print data to new line
+  dataFile.print(NETWORK_ID);
+  dataFile.print("_");
+  dataFile.print(id);
+  dataFile.print(",");
+  dataFile.print(utm);
+  dataFile.print(",");
+  dataFile.print(s_v);
+  dataFile.print(",");
+  dataFile.print(t);
+  dataFile.print(",");
+  dataFile.print(b_v);
+  dataFile.print(",");
+  dataFile.print(e_v);
+  dataFile.print(",");
+  dataFile.print(num_a);
+  dataFile.println();
+  dataFile.close();
+  return 1; //returns a 1, Success
 }

 void printData() {
@@ -173,56 +175,40 @@
 }

 int badPacket(long utm) {
-  //ID, time, sensor, temp, excite volts, battery volts, number of attempts
   CARD_PRESENT = digitalRead(CARD_DETECT);
   if (CARD_PRESENT == 0) {
-    Blink(LED, 25);
-    Blink(LED, 25);
     if (debug) Serial.println("Card Not Present");
     while (CARD_PRESENT == 0) {
       CARD_PRESENT = digitalRead(CARD_DETECT);
       Blink(LED, 100);
     }
-    if (!SD.begin(CHIP_SELECT))  Blink(LED, 25); //Serial.println("SD card initialized");
-    else Blink(LED, 25); Blink(LED, 25); //Serial.println("SD Card Failed to Initialize");
-  }
-  //Write data to card
-  String fileName = String("log.txt");
-  char __fileName[fileName.length() + 1];
-  fileName.toCharArray(__fileName, sizeof(__fileName));
-  File dataFile = SD.open(__fileName, FILE_WRITE); //Opens file (creates if it doesn't exist) and Appends data to the end of it
-  if (dataFile) {
-    dataFile.print("Bad Packet Recieved at: ");
-    dataFile.print(utm);
-    dataFile.println();
-    dataFile.close();
-    return 1; //returns a 1, Success
-  }
-  else {
-    if (debug) {
-      Serial.print("Error opening: ");
-      Serial.println(fileName);
-    }
-    Blink(LED, 100);
-    Blink(LED, 100);
-    return 0; //returns a 0, failure
-  }
-}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+    if (!SD.begin(CHIP_SELECT))  Blink(LED, 25);
+    if (debug) Serial.println("SD card initialized");
+  }
+  if (!dataFile.open("log.txt", O_RDWR | O_CREAT | O_AT_END)) {
+    if (debug) Serial.println("Error opening: log.txt");
+    Blink(LED, 100);
+    Blink(LED, 100);
+    return 0;
+  }
+  dataFile.print("Bad Packet Recieved at: ");
+  dataFile.print(utm);
+  dataFile.println();
+  dataFile.close();
+  return 1;
+}
+
+void checkSdCard() {
+  CARD_PRESENT = digitalRead(CARD_DETECT); //Check for card insertion
+  if (CARD_PRESENT == 0) { //if card NOT present....Wait and blink until it is
+    if (debug) Serial.println("Card Not Present");
+    while (CARD_PRESENT == 0) {
+//      CARD_PRESENT = digitalRead(CARD_DETECT);
+      Blink(LED, 50);
+    }
+//    if (!SD.begin(CHIP_SELECT))
+//      Blink(LED, 25);
+//    if (debug) Serial.println("SD card initialized");
+  }
+}
+


allow three buttons to wake device

allow three buttons to wake device

--- vibrate_alarm_clock.ino
+++ vibrate_alarm_clock.ino
@@ -255,20 +255,20 @@
   timeLastPressedAlarmSetButton = currentMillis;

   Serial.println("Alarm Set Button Pressed");
-
-  //Do not process button if not active
-  if(!showLCD && currentState != ALARM){
-    return;
-  }
-
+
   switch(currentState)
   {
     case ALARM: stopAlarm();
     break;
     case NORMAL :
-    {
-      currentState = SETTING_ALARM;
-      settingAlarmProcess = A_HOUR;
+    {
+      if(showLCD){
+        currentState = SETTING_ALARM;
+        settingAlarmProcess = A_HOUR;
+      } else {
+        showLCD = true;
+      }
+
     }
     break;
     case SETTING_ALARM:
@@ -305,19 +305,16 @@
   timeLastPressedTimeSetButton = currentMillis;

   Serial.println("Time Set Button Pressed");
-
-  //Do not process button if not active
-  if(!showLCD && currentState != ALARM){
-    return;
-  }
-
+
   switch(currentState)
   {
     case ALARM: stopAlarm();
     break;
     case NORMAL :
    {
-
+      if(!showLCD){
+        showLCD = true;
+      }
    }
     break;
     case SETTING_ALARM:


Add comment

Add comment

--- examples/GettingStarted/BlynkBlink/BlynkBlink.ino
+++ examples/GettingStarted/BlynkBlink/BlynkBlink.ino
@@ -46,9 +46,12 @@
 ********************************************************************/

 #define BLYNK_PRINT Serial // Enables Serial Monitor
+
+// Following includes are for Arduino Ethernet Shield (W5100)
+// If you're using another shield, see Boards_* examples
 #include <SPI.h>
 #include <Ethernet.h>
-#include <BlynkSimpleEthernet.h> // This part is for Ethernet stuff
+#include <BlynkSimpleEthernet.h>

 char auth[] = "YourAuthToken"; // Put your Auth Token here. (see Step 3 above)


update button test

update button test

--- proj/ledvo_lounge_button_test/Animation_Base.ino
+++ proj/ledvo_lounge_button_test/Animation_Base.ino
@@ -20,10 +20,10 @@
   // get the strobe effect that we want
   EVERY_N_MILLISECONDS_I(thisTimer, 200) {
     thisTimer.setPeriod(map(analogRead(DJ_POT), 0, 687, 50, 800));
-    fill_solid(ih_leds, ih_LED_total, CHSV(255, 255, gBrightness));
-    fill_solid(oh_leds, oh_LED_total, CHSV(255, 255, gBrightness));
+    fill_solid(ih_leds, ih_LED_total, CHSV(255, 0, gBrightness));
+    fill_solid(oh_leds, oh_LED_total, CHSV(255, 0, gBrightness));
     for (uint8_t dd = 0; dd < 3; dd++) {
-      fill_solid(d_leds[dd], d_LED_num, CHSV(255, 255, gBrightness));
+      fill_solid(d_leds[dd], d_LED_num, CHSV(255, 0, gBrightness));
     }
   }
   //FastLED.setBrightness(gBrightness);
@@ -64,7 +64,7 @@
 // Same as blackout, but with white.
 void whiteout() {
   fill_solid(ih_leds, ih_LED_total, CRGB::White);
-  //fill_solid(oh_leds, oh_LED_total, CRGB::White);
+  fill_solid(oh_leds, oh_LED_total, CRGB::White);
   for (uint8_t dd = 0; dd < 3; dd++) {
     fill_solid(d_leds[dd], d_LED_num, CRGB::White);
   }