Restore CalibrateTurnAngle. Switch loop to use millis, and set loop time to compromise of 10 millis.

--- Elcano_C2_LowLevel/Elcano_C2_LowLevel.ino
+++ Elcano_C2_LowLevel/Elcano_C2_LowLevel.ino
@@ -38,9 +38,11 @@
 #define s7s Serial2
 Servo STEER_SERVO;

-#define LOOP_TIME_US 400
+// 10 milliseconds -- adjust to accomodate the fastest needed response or
+// sensor data capture.
+#define LOOP_TIME_MS 10
 #define ERROR_HISTORY 20 //number of errors to accumulate
-#define TEN_SECONDS_IN_MICROS 10000000
+//#define TEN_SECONDS_IN_MICROS 10000000
 #define ULONG_MAX 4294967295

 /*================ReadTurnAngle ================*/
@@ -80,9 +82,6 @@
 #define RC_NUM_SIGNALS 7
 volatile unsigned long RC_rise[RC_NUM_SIGNALS];
 volatile unsigned long RC_elapsed[RC_NUM_SIGNALS];
-// We'll copy values here before using them in an attempt to have the
-// values change while we're using them.
-unsigned long local_results[RC_NUM_SIGNALS];
 // This tells us when we have started receiving RC data. Until then, we
 // ignore RC_rise and RC_elapsed.
 volatile bool RC_Done[RC_NUM_SIGNALS];
@@ -91,10 +90,9 @@

 long speed_errors[ERROR_HISTORY];
 long old_turn_degx1000;
-// @ToDo: Remove calibration and test code to its own file.
-//unsigned long calibrationTime_ms;
-//unsigned long stoppedTime_ms;
-//unsigned long straightTime_ms;
+unsigned long calibrationTime_ms;
+unsigned long stoppedTime_ms;
+unsigned long straightTime_ms;
 int  throttle_control = MIN_ACC_OUT;
 int  brake_control = MIN_BRAKE_OUT;
 int  steer_control = STRAIGHT_TURN_OUT;
@@ -274,10 +272,9 @@
     speed_errors[i] = 0;
   }

-  // @ToDo: Remove any test and calibration code.
-  // //setupWheelRev(); // WheelRev4 addition
-  //CalibrateTurnAngle(32, 20);
-  //calibrationTime_ms = millis();
+  //setupWheelRev(); // WheelRev4 addition
+  CalibrateTurnAngle(32, 20);
+  calibrationTime_ms = millis();

   attachInterrupt(digitalPinToInterrupt(IRPT_TURN),  ISR_TURN_rise,  RISING);
   //attachInterrupt(digitalPinToInterrupt(IRPT_RDR),   ISR_RDR_rise,   RISING);
@@ -291,8 +288,8 @@
 /*---------------------------------------------------------------------------------------*/

 // Time at which this loop pass should end in order to maintain a
-// loop period of LOOP_TIME_US.
-unsigned long nextTime = micros();
+// loop period of LOOP_TIME_MS.
+unsigned long nextTime = millis();
 // Time at which we reach the end of loop(), which should be before
 // nextTime if we have set the loop period long enough.
 unsigned long endTime;
@@ -303,24 +300,15 @@
 SerialData Results;

 void loop() {
-  // Get the next loop start time. Note this (and the micros() counter) will
+  // Get the next loop start time. Note this (and the millis() counter) will
   // roll over back to zero after they exceed the 32-bit size of unsigned long,
-  // which happens after about 70 minues of operation. If the new nextTime
-  // value is <= LOOP_TIME_US, we've rolled over.
-  nextTime = nextTime + LOOP_TIME_US;
-
-  // ToDo: Verify why this is being copied, e.g. is it to avoid having the
-  // values change while we're using them? Because they can change right here
-  // while we're copying them. Would it help to disable interrupts while we
-  // copy them? or does that just freeze them in some intermediate state?
-  // How about if we just make sure that anytime we exit the interrupt routine,
-  // the RC_elapsed values are in a valid state? Then we don't need to copy
-  // them. (This is all under the assumption that we're copying to avoid
-  // an inconsistent state.)
-  for (int i = 0; i < RC_NUM_SIGNALS; i++)
-    local_results[i] = RC_elapsed[i];
-
-  byte automate = processRC(local_results);
+  // which happens after about 1.5 months of operation (should check this).
+  // But leave the overflow computation in place, in case we need to go back to
+  // using the micros() counter.
+  // If the new nextTime value is <= LOOP_TIME_MS, we've rolled over.
+  nextTime = nextTime + LOOP_TIME_MS;
+
+  byte automate = processRC(RC_elapsed);
   // @ToDo: Verify that this should be conditional. May be moot if it is
   // replaced in the conversion to the new Elcano Serial protocol.
   if (automate == 0x01)
@@ -335,18 +323,17 @@
   // @ToDo: Is this working and should it be uncommented?
   // show_speed (&Results);

-  // @ToDo: Remove all test or calibration code. If needed, put it in a separate file.
-  //calibrationTime_ms += LOOP_TIME_US;
-  //straightTime_ms = (steer_control == STRAIGHT_TURN_OUT) ? straightTime_ms + LOOP_TIME_US : 0;
-  //stoppedTime_ms = (throttle_control == MIN_ACC_OUT) ? stoppedTime_ms + LOOP_TIME_US : 0;
-  //if (calibrationTime_ms > 40000 && straightTime_ms > 3000 && stoppedTime_ms > 3000)
-  //{
-  //  //       int oldBrake = brake_control;
-  //  //       brake(MAX_BRAKE_OUT);  // put on brakes
-  //  CalibrateTurnAngle(16, 10);  // WARNING: No response to controls while calibrating
-  //  //       brake(oldBrake);       // restore brake state
-  //  calibrationTime_ms = 0;
-  //}
+  calibrationTime_ms += LOOP_TIME_MS;
+  straightTime_ms = (steer_control == STRAIGHT_TURN_OUT) ? straightTime_ms + LOOP_TIME_MS : 0;
+  stoppedTime_ms = (throttle_control == MIN_ACC_OUT) ? stoppedTime_ms + LOOP_TIME_MS : 0;
+  if (calibrationTime_ms > 40000 && straightTime_ms > 3000 && stoppedTime_ms > 3000)
+  {
+    //       int oldBrake = brake_control;
+    //       brake(MAX_BRAKE_OUT);  // put on brakes
+    CalibrateTurnAngle(16, 10);  // WARNING: No response to controls while calibrating
+    //       brake(oldBrake);       // restore brake state
+    calibrationTime_ms = 0;
+  }

   // @ToDo: What information do we need to send to C6? Is that communication already
   // hiding in here somewhere, or does it need to be added?
@@ -356,17 +343,17 @@
   // point, there should be *no* more controller activity -- we want
   // minimal time between now, when we capture the actual loop end time,
   // and when we pause til the desired loop end time.
-  endTime = micros();
+  endTime = millis();
   delayTime = 0L;

-  // Did the micros() counter or nextTime overflow and roll over during
+  // Did the millis() counter or nextTime overflow and roll over during
   // this loop pass? Did the loop's processing time overrun the desired
   // loop period? We have different computations for the delay time in
   // various cases:
   if ((nextTime >= endTime) &&
-      (((endTime < LOOP_TIME_US) && (nextTime < LOOP_TIME_US)) ||
-       ((endTime >= LOOP_TIME_US) && (nextTime >= LOOP_TIME_US)))) {
-    // 1) Neither micros() nor nextTime rolled over --or-- micros() rolled
+      (((endTime < LOOP_TIME_MS) && (nextTime < LOOP_TIME_MS)) ||
+       ((endTime >= LOOP_TIME_MS) && (nextTime >= LOOP_TIME_MS)))) {
+    // 1) Neither millis() nor nextTime rolled over --or-- millis() rolled
     // over *and* nextTime rolled over when we incremented it. For this case,
     // endTime and nextTime will be in their usual relationship, with
     // nextTime >= endTime, and both nextTime and endTime are either greater
@@ -379,11 +366,11 @@
     // Negate the first if condition and use DeMorgan's laws...
     // Now pick out the "nextTime rolled over" case. We don't need to test both
     // nextTime and endTime as we know only one rolled over.)
-    if (nextTime < LOOP_TIME_US) {
-      // 2) nextTime rolled over when we incremented it, but the micros() timer
+    if (nextTime < LOOP_TIME_MS) {
+      // 2) nextTime rolled over when we incremented it, but the millis() timer
       // hasn't yet rolled over.
       // In this case, we know we didn't exhaust the loop time, and the time we
-      // need to wait is the remaining time til micros() will roll over, i.e.
+      // need to wait is the remaining time til millis() will roll over, i.e.
       // from endTime until the max long value, plus the time from zero to
       // nextTime.
       delayTime = ULONG_MAX - endTime + nextTime;
@@ -392,10 +379,10 @@
       // nextTime < endTime -or-
       // nextTime >= endTime -and- nextTime did not roll over but endTime did.)
       // What remains are these two cases:
-      // 3) nextTime hasn't rolled over, but micros() has.
-      // In this case, we overran the loop time. Since micros() has rolled over,
+      // 3) nextTime hasn't rolled over, but millis() has.
+      // In this case, we overran the loop time. Since millis() has rolled over,
       // we can just use the normal overrun fixup. So combine this with...
-      // 4) Neither nextTime nor micros rolled over, but we overran the desired
+      // 4) Neither nextTime nor millis rolled over, but we overran the desired
       // loop period.
       // In this case, we have no delay, but instead extend the allowed time for
       // this loop pass to the actual time it took.
@@ -1210,7 +1197,7 @@
   ComputeSpeed (&history);
   //   PrintSpeed(&history);

-  Odometer_m += (float)(LOOP_TIME_US * SpeedCyclometer_mmPs) / MEG;
+  Odometer_m += (float)(LOOP_TIME_MS * SpeedCyclometer_mmPs) / 1000.0;
   // Since Results have not been cleared, angle information will also be sent.
   Results->speed_cmPs = SpeedCyclometer_mmPs / 10;
 //  Results->write(&Serial3);  // Send speed to C6
@@ -1220,55 +1207,59 @@
 }
 /*---------------------------------------------------------------------------------------*/
 /*========================CalibrateTurnAngle======================*/
-/*  This routine should only be called when
+/* The Hall angle sensors we are using have been observed to drift,
+   and should periodically be zeroed.
+   This routine should only be called when
           - Wheels are pointed straight ahead, and have been for a while.
           - Trike is not moving, and is stable.
-    Calibration will block any response to controls; there will be no turning or movemnet during calibration.
-    Angle sensors can drift, and should periodically be zeroed.
+   Calibration will block any response to controls; there will be
+   no turning or movement during calibration. This condition should be
+   very brief -- this does not wait nor turn off interrupts -- so should
+   be safe to call during loop().
 */
-//void CalibrateTurnAngle(int count, int pause)
-//{
-//  int totalRight = 0;
-//  int totalLeft = 0;
-//  int i, left, right;
-//  for (i = 0; i < count; i++)
-//  {
-//    totalRight += analogRead(A2);
-//    totalLeft += analogRead(A3);
-//    delay(pause);
-//  }
-//  right = totalRight / count;
-//  left  = totalLeft  / count;
-//  // Only recalibrate when instruments are reasonable
-//  // Do not make garbage readings the new normal.
-//  if (RIGHT_MIN_COUNT <= right && right <= RIGHT_MAX_COUNT)
-//  {
-//    RightStraight_A2 = right;
-//    Right_Min_Count = RightStraight_A2 - 60;   // 60 counts is 20 degrees
-//    Right_Max_Count = RightStraight_A2 + 60;
-//  }
-//  else
-//  {
-//    RightStraight_A2 = RIGHT_MIN_COUNT + (RIGHT_MAX_COUNT - RIGHT_MIN_COUNT) / 2 ;
-//    Right_Min_Count = RIGHT_MIN_COUNT;
-//    Right_Max_Count = RIGHT_MAX_COUNT;
-//  }
-//  if  (LEFT_MIN_COUNT  <= left  && left  <= LEFT_MAX_COUNT)
-//  {
-//    LeftStraight_A3  = left;
-//    Left_Min_Count  = LeftStraight_A3  - 60;
-//    Left_Max_Count  = LeftStraight_A3  + 60;
-//  }
-//  else
-//  {
-//    LeftStraight_A3  = LEFT_MIN_COUNT + (LEFT_MAX_COUNT - LEFT_MIN_COUNT) / 2 ;
-//    Left_Min_Count = LEFT_MIN_COUNT;
-//    Left_Max_Count = LEFT_MAX_COUNT;
-//  }
-//  //    Serial.print("\tCALIBRATE: Left Straight\t"); Serial.print(LeftStraight_A3);
-//  //    Serial.print("\tRight Straight\t"); Serial.println(RightStraight_A2);
-//  old_turn_degx1000 = 0; // straight
-//}
+void CalibrateTurnAngle(int count, int pause)
+{
+  int totalRight = 0;
+  int totalLeft = 0;
+  int i, left, right;
+  for (i = 0; i < count; i++)
+  {
+    totalRight += analogRead(A2);
+    totalLeft += analogRead(A3);
+    delay(pause);
+  }
+  right = totalRight / count;
+  left  = totalLeft  / count;
+  // Only recalibrate when instruments are reasonable
+  // Do not make garbage readings the new normal.
+  if (RIGHT_MIN_COUNT <= right && right <= RIGHT_MAX_COUNT)
+  {
+    RightStraight_A2 = right;
+    Right_Min_Count = RightStraight_A2 - 60;   // 60 counts is 20 degrees
+    Right_Max_Count = RightStraight_A2 + 60;
+  }
+  else
+  {
+    RightStraight_A2 = RIGHT_MIN_COUNT + (RIGHT_MAX_COUNT - RIGHT_MIN_COUNT) / 2 ;
+    Right_Min_Count = RIGHT_MIN_COUNT;
+    Right_Max_Count = RIGHT_MAX_COUNT;
+  }
+  if  (LEFT_MIN_COUNT  <= left  && left  <= LEFT_MAX_COUNT)
+  {
+    LeftStraight_A3  = left;
+    Left_Min_Count  = LeftStraight_A3  - 60;
+    Left_Max_Count  = LeftStraight_A3  + 60;
+  }
+  else
+  {
+    LeftStraight_A3  = LEFT_MIN_COUNT + (LEFT_MAX_COUNT - LEFT_MIN_COUNT) / 2 ;
+    Left_Min_Count = LEFT_MIN_COUNT;
+    Left_Max_Count = LEFT_MAX_COUNT;
+  }
+  //    Serial.print("\tCALIBRATE: Left Straight\t"); Serial.print(LeftStraight_A3);
+  //    Serial.print("\tRight Straight\t"); Serial.println(RightStraight_A2);
+  old_turn_degx1000 = 0; // straight
+}
 /*---------------------------------------------------------------------------------------*/
 /*======================ReadTurnAngle======================*/
 int TurnAngle_degx10()


Update configuration comments, update SmartLEDShieldV4.h name

--- AnimatedGIFs.ino
+++ AnimatedGIFs.ino
@@ -56,16 +56,15 @@

 /*
  * CONFIGURATION:
+ *  - If you're using SmartLED Shield V4 (or above), uncomment the line that includes <SmartMatrixShieldV4.h>
  *  - update the "SmartMatrix configuration and memory allocation" section to match the width and height and other configuration of your display
- *  - Note for 128x32 and 64x64 displays - need to reduce RAM:
+ *  - Note for 128x32 and 64x64 displays with Teensy 3.2 - need to reduce RAM:
  *    set kRefreshDepth=24 and kDmaBufferRows=2 or set USB Type: "None" in Arduino,
  *    decrease refreshRate in setup() to 90 or lower to get good an accurate GIF frame rate
- *  - WIDTH and HEIGHT are defined in GIFParseFunctions.cpp, update to match the size of your GIFs
- *    only play GIFs that are size WIDTHxHEIGHT or smaller
  */

 #if defined (ARDUINO)
-//#include <SmartMatrixShieldV4.h>  // uncomment this line for SmartMatrix Shield V4 (needs to be before #include <SmartMatrix3.h>)
+//#include <SmartLEDShieldV4.h>  // uncomment this line for SmartLED Shield V4 (needs to be before #include <SmartMatrix3.h>)
 #include <SmartMatrix3.h>
 #elif defined (SPARK)
 #include "application.h"


Remove out of date comment

Remove out of date comment

--- AnimatedGIFs.ino
+++ AnimatedGIFs.ino
@@ -222,7 +222,6 @@
         while(1);
     }

-    // for ESP32 we need to allocate SmartMatrix DMA buffers after initializing the SD card to avoid using up too much memory
 #if (ENABLE_SCROLLING == 1)
     scrollingLayer.start("TESTING TESTING TESTING", -1);
 #endif


set relays to off state at startup

set relays to off state at startup

--- Firmeware/EnsembleThree/EnsembleThree.ino
+++ Firmeware/EnsembleThree/EnsembleThree.ino
@@ -43,8 +43,6 @@

   // set output pins
   pinMode(A1, OUTPUT);
-  //pinMode(A2, OUTPUT);
-  //pinMode(A3, OUTPUT);
   servo1.attach(A2);
   servo2.attach(A3);

@@ -53,6 +51,9 @@

   pinMode(C1, OUTPUT);
   pinMode(C2, OUTPUT);
+  // turn relays off
+  digitalWrite(C1, HIGH);
+  digitalWrite(C2, HIGH);

   // set note2pin array


fix RH value

fix RH value

--- Node/Node.ino
+++ Node/Node.ino
@@ -106,7 +106,7 @@

   si7021_thc thc = sensor.getTempAndRH();
   double t = thc.celsiusHundredths / 100.0;
-  double RH = thc.humidityPercent;
+  int RH = thc.humidityPercent;
   Serial.print("Temp: "); Serial.print(t);
   Serial.print("\tHum: "); Serial.println(RH);

@@ -120,11 +120,11 @@
   double T = 273.15 + t;
   double e_omega = 6.112*exp((17.62*T - 4812.903)/(T - 30.03));
   double f = 1.0016 + 0.00000315*P - 0.074/P;
-  double e = RH*e_omega*f;
+  double e = RH*e_omega*f/100;
   double AH = e/(Rv*T);
-  double m = AH*V*1000.0;
+  double m = AH*V*1000000.0;

-  Serial.print("Water mass[g]: "); Serial.println(m);
+  Serial.print("Water mass[mg]: "); Serial.println(m);

   Serial.flush();


remove irrelevant stuff from some comments

--- OpenStage.ino
+++ OpenStage.ino
@@ -244,10 +244,9 @@
 // * Stage Position
 // The stage controller unit keeps track of how far the stage has moved along each axis. This
 // allows the unit to do handy things such as moving to a pre-defined absolute location. When
-// the controller boots up it assumes it is at [0,0,0]. Axes can be zeroed independently at any
-// time using push-buttons.  In future, we coudld  save the position to EEPROM so it's persistant.
-// Note that there are no encoders: if you manually move the stage, it loses it's position and needs
-// to be reset. **BE CAREFUL** Manually moving the stage and forgetting to reset might cause a
+// the controller boots up it assumes it is at [0,0,0]. Note that there are no encoders:
+// if you manually move the stage, it loses it's position and needs to be reset.
+// **BE CAREFUL** Manually moving the stage and forgetting to reset might cause a
 // dangerous stage motion.
 //
 // The absolute positioning abilities of the stage can be accessed most diectly using the right


Add citation info

Add citation info

--- OpenStage.ino
+++ OpenStage.ino
@@ -23,7 +23,13 @@

-
+* Citing
+  This work has been published under the title: "Openstage: A Low-Cost
+  Motorized Microscope Stage with Sub-Micron Positioning Accuracy" by
+  Campbell, Eifert, and Turner in PLoS ONE, 2014, DOI: 10.1371/journal.pone.0088977
+  http://www.plosone.org/article/info%3Adoi%2F10.1371%2Fjournal.pone.0088977
+  Please cite us if you publish using our methods.
+

 * Purpose
   OpenStage is a sub-micron positioning system for microscope stages.
@@ -311,6 +317,8 @@
 // This is important, as it minimises the possibility of the user double-clicking a button
 // unbound to a location as it may make the stage perform a large motion to back to zero.
 bool locationStored[4]={0,0,0,0};
+
+

 //------------------------------------------------------------------------------------------------
 // * Motor control DIO lines


Removed temporary code

Removed temporary code

--- Arduino/V0p2_Main/V0p2_Main.ino
+++ Arduino/V0p2_Main/V0p2_Main.ino
@@ -135,13 +135,6 @@
   LED_HEATCALL_ON();
   OTV0P2BASE::sleepLowPowerMs(1000); // TODO: use this time to gather entropy.

-  // TODO temp code
-  pinMode(6, INPUT); // force QM-1 on
-  fastDigitalWrite(6, HIGH);
-  pinMode(A2, INPUT); // set up RN2483 reset (currently shorting to ground)
-  fastDigitalWrite(A2, LOW);
-  pinMode(A3, OUTPUT); // force QM-1 on
-  fastDigitalWrite(A3, HIGH);
   }
 #endif // ALT_MAIN_LOOP


Optimized serial to one Serial.print statement

--- Arduino/_firmware/_firmware.ino
+++ Arduino/_firmware/_firmware.ino
@@ -1,6 +1,6 @@
 unsigned int long PRINT_DELAY = 2000; //in milliseconds
 unsigned int long last_print_time = 0;
-
+String data;
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //                                           OneWire temperature sensor
 #include <OneWire.h>
@@ -113,15 +113,17 @@
   //////////////////////////////////////////////////////Printing

   if (millis() - last_print_time >= PRINT_DELAY){
-    Serial.print ("rpm = ");
-    Serial.println (rpm);
-    Serial.print ("Ambient temperature: ");
-    Serial.println (ambient_temperature, 1);
-    Serial.print ("Casing temperature: ");
-    Serial.println (casing_temperature, 1);
-    Serial.print ("Drop count = ");
-    Serial.println (drop_count);
-    Serial.println();
+    data = "";
+    data += ambient_temperature;
+    data += ",";
+    data += casing_temperature;
+    data += ",";
+    data += drop_count;
+    data += ",";
+    data += rpm;
+
+    Serial.println (data);
+
     last_print_time = millis();
   }
 }


compile compliance script correctly w/o LMIC logging

--- examples/compliance-otaa-halconfig/compliance-otaa-halconfig.ino
+++ examples/compliance-otaa-halconfig/compliance-otaa-halconfig.ino
@@ -145,6 +145,7 @@

 cEventQueue eventQueue;

+#if LMIC_ENABLE_event_logging
 extern "C" {
     void LMICOS_logEvent(const char *pMessage);
     void LMICOS_logEventUint32(const char *pMessage, uint32_t datum);
@@ -159,6 +160,7 @@
     {
     eventQueue.putEvent(ev_t(-2), pMessage, datum);
     }
+#endif // LMIC_ENABLE_event_logging

 uint8_t lastTxChannel;
 bool lastTxStart;


Fix #420: hard-code testing keys (slim AVR)

--- examples/compliance-otaa-halconfig/compliance-otaa-halconfig.ino
+++ examples/compliance-otaa-halconfig/compliance-otaa-halconfig.ino
@@ -29,18 +29,18 @@

 // This EUI must be in little-endian format, so least-significant-byte
 // first.  This corresponds to 0x0000000000000001
-static const u1_t PROGMEM APPEUI[8]= { 1, 0, 0, 0, 0, 0, 0, 0 };
-void os_getArtEui (u1_t* buf) { memcpy_P(buf, APPEUI, 8);}
+// static const u1_t PROGMEM APPEUI[8]= { 1, 0, 0, 0, 0, 0, 0, 0 };
+void os_getArtEui (u1_t* buf) { memset(buf, 0, 8); buf[0] = 1; }

 // This should also be in little endian format, see above.
 // This corresponds to 0x0000000000000001
-static const u1_t PROGMEM DEVEUI[8]= { 1, 0, 0, 0, 0, 0, 0, 0 };
-void os_getDevEui (u1_t* buf) { memcpy_P(buf, DEVEUI, 8);}
+// static const u1_t PROGMEM DEVEUI[8]= { 1, 0, 0, 0, 0, 0, 0, 0 };
+void os_getDevEui (u1_t* buf) { memset(buf, 0, 8); buf[0] = 1; }

 // This key should be in big endian format (or, since it is not really a
 // number but a block of memory, endianness does not really apply).
-static const u1_t PROGMEM APPKEY[16] = { 0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 2 };
-void os_getDevKey (u1_t* buf) {  memcpy_P(buf, APPKEY, 16);}
+// static const u1_t PROGMEM APPKEY[16] = { 0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 2 };
+void os_getDevKey (u1_t* buf) { memset(buf, 0, 16); buf[15] = 2; }

 // this data must be kept short -- max is 11 bytes for US DR0
 static uint8_t mydata[] = { 0xCA, 0xFE, 0xF0, 0x0D };


Update to serial output

Update to serial output

--- computer_box/computer_box.ino
+++ computer_box/computer_box.ino
@@ -61,11 +61,11 @@
 }

 void loop() {
-  Serial.print("{");
+  Serial.print("{ \"computer\": { ");
   read_voltages();
   Serial.print(",");
   read_temperature();
-  Serial.println("}");
+  Serial.println("} }");

   // Blink lights
   blink_led();
@@ -116,7 +116,7 @@
   //   return;
   // }

-  Serial.print("\"temperature\":{");
+  Serial.print("\"temp\":{");
   Serial.print("\"h\":"); Serial.print(h); Serial.print(',');
   Serial.print("\"c\":"); Serial.print(c); Serial.print(',');

@@ -126,8 +126,9 @@
     Serial.print("\":");
     Serial.print(get_temperature(sensors_address[x]));

-    if x < num_ds18 - 1:
+    if (x < num_ds18 - 1) {
       Serial.print(",");
+    }
   }

   Serial.print('}');
@@ -188,26 +189,27 @@
   int x;
   sensor_bus.reset();
   sensor_bus.select(address);
-  sensor_bus.write(0x44,1);
-
+  sensor_bus.write(0x44, 1);
+
   sensor_bus.reset();
   sensor_bus.select(address);
-  sensor_bus.write(0xBE,1);
-
-  for(x=0;x<9;x++)
+  sensor_bus.write(0xBE, 1);
+
+  for (x = 0; x < 9; x++)
     data[x] = sensor_bus.read();
-
+
   int tr = data[0];
-  if(data[1] > 0x80) {
-   tr = !tr+1;
-   tr = tr*-1;
+  if (data[1] > 0x80) {
+    tr = !tr + 1;
+    tr = tr * -1;
   }
   int cpc = data[7];
   int cr = data[6];
-
-  tr = tr>>1;
-
-  float temperature = tr - (float)0.25+(cpc-cr)/(float)cpc;
-
+
+  tr = tr >> 1;
+
+  float temperature = tr - (float)0.25 + (cpc - cr) / (float)cpc;
+
   return temperature;
 }
+


Super lint

Super lint


Cleaned up a parsing edge case.

Cleaned up a parsing edge case.

--- firmware/firmware.ino
+++ firmware/firmware.ino
@@ -204,7 +204,7 @@
     if (!strncmp("m", entry_name, 1))
     {
       size_t motor_idx = entry_name[1] - '0';
-      if (motor_idx >= NUM_MOTORS) {
+      if (motor_idx >= NUM_MOTORS || entry_name[2] != '\0') {
         reportJsonError(JSMN_ERROR_INVAL);
         return;
       }
@@ -214,7 +214,7 @@
     if (!strncmp("s", entry_name, 1))
     {
       size_t sensor_idx = entry_name[1] - '0';
-      if (sensor_idx >= NUM_SENSORS) {
+      if (sensor_idx >= NUM_SENSORS || entry_name[2] != '\0') {
         reportJsonError(JSMN_ERROR_INVAL);
         return;
       }


Speed up the LED self test.

Speed up the LED self test.

--- firmware/firmware.ino
+++ firmware/firmware.ino
@@ -29,9 +29,10 @@
     clearDisplay();

     Serial.println("Testing LEDs...");
-    for(int hue = 0; hue < 260; hue++) {
-        for(int saturation = 0; saturation < 256; saturation++) {
+    for(int hue = 0; hue < 260; hue += 10) {
+        for(int saturation = 0; saturation < 256; saturation += 10) {
             setLED(hue, saturation, 255);
+            delay(5);
         }
     }


tab to spaces for consistency

tab to spaces for consistency

--- firmware/firmware.ino
+++ firmware/firmware.ino
@@ -14,7 +14,7 @@
 Heartbeat heartbeat(HEARTBEAT_PIN);

 void setup() {
-	Serial.begin(115200);
+    Serial.begin(115200);
     heartbeat.begin();
     // Parser should be initialize before Matrix so that when Matrix
     // Enters DumpConfigMode, Parser wil already know it's ID


btSerial.print() fix

btSerial.print() fix

--- Arduino/TurquoiseBicuspidATTinyBLE.ino
+++ Arduino/TurquoiseBicuspidATTinyBLE.ino
@@ -1,12 +1,9 @@
 #include <SoftwareSerial.h>

 // ATtiny settings: ATtiny85 @8MHz (internal oscillator; BOD disabled), burn bootloader
-
-SoftwareSerial btSerial(3, 2); // TX, RX
+SoftwareSerial btSerial(3, 2); // ATtiny TX, RX

 // Global
-int BUTT = 2;
-int BUTT_STATE = 0;
 int TIME_START = 0;
 int REDPIN = 0;
 int GREPIN = 1;
@@ -28,7 +25,6 @@

 void setup()
 {
-  pinMode(BUTT, INPUT);
   pinMode(REDPIN, OUTPUT);
   pinMode(GREPIN, OUTPUT);
   pinMode(BLUPIN, OUTPUT);
@@ -37,30 +33,26 @@
   btSerial.begin(9600);
   //btSerial.write("AT+RENEW"); // Reset all settings.
   delay(250);
-  btSerial.write("AT+ROLE0"); // Slave mode (0: Peripheral, 1: Central, default: 0)
-  delay(250);
-  btSerial.write("AT+MODE2"); // (0: Tranmission, 1: PIO+0, 2: Remote Control+0, default: 0)
-  delay(250);
-  btSerial.write("AT+IMME1"); // (0: work immediately, 1: wait for AT+ commands, wait for AT+START to resume work, default: 0) Don't enter transmission mode until told. ("AT+IMME0" is wait until "AT+START" to work. "AT+WORK1" is connect right away.)
-  delay(250);
-  btSerial.write("AT+BAUD0");
-  delay(250);
-  btSerial.write("AT+NAMETurquoiseB");
-  delay(250);
-  btSerial.write("AT+PASS123456");
-  delay(250);
-  btSerial.write("AT+START"); // Work immediately when AT+IMME1 is set.
+  btSerial.print("AT+ROLE0"); // Slave mode (0: Peripheral, 1: Central, default: 0)
+  delay(250);
+  btSerial.print("AT+MODE2"); // (0: Tranmission, 1: PIO+0, 2: Remote Control+0, default: 0)
+  delay(250);
+  btSerial.print("AT+IMME1"); // (0: work immediately, 1: wait for AT+ commands, wait for AT+START to resume work, default: 0) Don't enter transmission mode until told. ("AT+IMME0" is wait until "AT+START" to work. "AT+WORK1" is connect right away.)
+  delay(250);
+  btSerial.print("AT+BAUD0");
+  delay(250);
+  btSerial.print("AT+NAMETurquoiseB");
+  delay(250);
+  btSerial.print("AT+PASS123456");
+  delay(250);
+  btSerial.print("AT+START"); // Work immediately when AT+IMME1 is set.
   delay(250);

   TIME_START = millis();
 }

 void loop()
-{
-  // clear button
-  BUTT_STATE = digitalRead(BUTT);
-  if(BUTT_STATE == HIGH) {
-  }
+{
   // read from bluetooth
   int index = 0;
   if(btSerial.available()) {


Dependent constraints are now fast.

Dependent constraints are now fast.

--- Project/demo_just_get_it_working/demo_just_get_it_working.ino
+++ Project/demo_just_get_it_working/demo_just_get_it_working.ino
@@ -124,29 +124,28 @@
 /*
  * Increments towards the intended angle, keeping other angles in valid ranges.
  */
-boolean go_towards(int servo_number, int angle)
+void go_towards(int servo_number, int angle)
 {
   angle = constrain_servo_angle(servo_number, angle);
+
   int diff = angle - angles[servo_number];
-
   int dir;
   if (diff == 0)
-    return false;
+    dir = 0;
   else
     dir = diff / abs(diff);

   angles[servo_number] += dir;
   servo[servo_number].write( angles[servo_number] );

-  if ( servo_number = 1 )
-    go_to(3, angles[3]);
-  if ( servo_number = 3 )
-    go_to(1, angles[1]);
+  if ( servo_number == 3)
+  {
+    angles[(servo_number + 2) % 4] = constrain_servo_angle((servo_number + 2) % 4, angles[(servo_number + 2) % 4]);
+    servo[(servo_number + 2) % 4].write( angles[(servo_number + 2) % 4] );
+  }

 //  if ( angles[servo_number] % 15 == 0 )
 //    Serial.print(angles[servo_number]);
-
-  return true;
 }

 void go_to(int servo_number, int angle)
@@ -154,18 +153,17 @@
   int min_delay_time = 10, max_delay_time = 100, delay_time = max_delay_time;

   int previous_angle;
-  bool continue_flag;
   do {
     previous_angle = angles[servo_number];

     delay(delay_time);

-    continue_flag = go_towards(servo_number, angle);
+    go_towards(servo_number, angle);

     if ( abs(angle - angles[servo_number]) > 15 && delay_time > min_delay_time )
       delay_time -= min_delay_time;
     else if ( abs(angle - angles[servo_number]) <= 15 && delay_time < max_delay_time)
       delay_time += min_delay_time;
-  } while ( previous_angle - angles[servo_number] != 0 && continue_flag );
+  } while ( previous_angle - angles[servo_number] != 0 );
 }


Updated baudrate and delay time on WriteTagMultipleRecords

--- examples/WriteTagMultipleRecords/WriteTagMultipleRecords.ino
+++ examples/WriteTagMultipleRecords/WriteTagMultipleRecords.ino
@@ -5,7 +5,7 @@
 NfcAdapter nfc = NfcAdapter();

 void setup() {
-    Serial.begin(115200);
+    Serial.begin(9600);
     Serial.println("NDEF Writer");
     nfc.begin();
 }
@@ -19,10 +19,10 @@
         message.addTextRecord("Goodbye, Arduino!");
         boolean success = nfc.write(message);
         if (success) {
-            Serial.println("Try reading this tag with your phone.");
+            Serial.println("Success. Try reading this tag with your phone.");
         } else {
             Serial.println("Write failed");
         }
     }
-    delay(5000);
-}+    delay(3000);
+}


if change

if change


Delete mq3_shield_4_newton.ino

Delete mq3_shield_4_newton.ino

--- arduino/mq3_shield/mq3_shield_4_newton.ino
+++ arduino/mq3_shield/mq3_shield_4_newton.ino
@@ -1,108 +0,0 @@
-#include <LiquidCrystal.h>
-#include <OneSheeld.h>
-#include <GPSShield.h>
-#include <SMSShield.h>
-LiquidCrystal lcd(6, 7, 10, 11, 12, 13);
-int buttonState = 0;
-boolean isMessageSent = false;
-float get_latitude ;
-float get_longitude ;
-String latitude ;
-String longitude ;
-String sms_text ;
-float volt_2_gl(float v){
-  float a = 2.64581 ;
-  float b = 0.59843 ;
-  float gl = (v-a)/b ;
-  return gl ;
-}
-void setup() {
-  OneSheeld.begin(); // Start communication with 1Sheeld
-  lcd.begin(1, 2);
-  pinMode(9, INPUT);
-  pinMode(4, OUTPUT);
-  lcd.print("P. Pennestri'");
-  lcd.setCursor(0, 1);
-  lcd.print("L.S.S. I. Newton");
-  delay(3000);
-  lcd.clear();
-  lcd.print("Warming Up");
-  lcd.setCursor(0, 1);
-  lcd.print("Don't Breath");
-  delay(30000);
-  lcd.clear();
-}
-
-void loop() {
-   buttonState = digitalRead(9); // read the state of the pushbutton value
-   if (buttonState == HIGH) {
-   isMessageSent = false;
-   lcd.print("Breath in");
-   delay(15000);
-   delay(15000);
-   delay(15000);
-   delay(5000);
-   lcd.clear();
-   digitalWrite(4, HIGH);   // turn the LED on (HIGH is the voltage level)
-   delay(1000);              // wait for a second
-   digitalWrite(4, LOW);    // turn the LED off by making the voltage LOW
-   delay(1000);              // wait for a second
-   int mq3_value1 = analogRead(A5);
-   float voltage1 = mq3_value1 * (5.0 / 1023.0); // get mq3 voltage
-
-   if(voltage1<2.42){
-    lcd.print("No alcohol");
-    lcd.setCursor(0, 1);
-    lcd.print("You can drive ");
-    delay(15000);
-    lcd.clear();
-   }
-
-   if(voltage1>=2.42){
-     float response = volt_2_gl(voltage1);
-     // send sms if response >= 0.5 g/l
-     lcd.print(response);
-     lcd.print(" g/l");
-     lcd.setCursor(0, 1);
-     lcd.print("DO NOT DRIVE!");
-     delay(15000);
-     delay(15000);
-     delay(15000);
-     delay(5000);
-     lcd.clear();
-
-          if(response>=0.5){
-
-        if(!isMessageSent)
-    {
-         lcd.print("SMS Sent");
-         lcd.clear();
-         get_latitude = GPS.getLatitude();
-         latitude = String(get_latitude);
-         get_longitude = GPS.getLongitude();
-         longitude = String(get_longitude);
-         sms_text = "I need HELP \n pick me up at \n https://www.google.it/maps/place/" + latitude + "+" + longitude  ;
-
-         SMS.send("3511012085", sms_text);  // send sms
-         isMessageSent = true;  // Set the flag.
-        delay(10000);
-    }
-
-     }
-
-     lcd.print("Going to idle state");
-     lcd.setCursor(0, 1);
-     lcd.print("Don't Breath");
-     delay(15000);
-     delay(15000);
-     delay(15000);
-     delay(5000);
-   }} else{
-     lcd.print("Ready to Start");
-     delay(1000);
-     lcd.clear();
-   }
-
-
-
-}


new parsing - need to test

new parsing - need to test

--- arduino/v2/v2.ino
+++ arduino/v2/v2.ino
@@ -25,7 +25,12 @@
 float angle = 0.0;
 float distance = 0.0;
 int altitude = 30;
-int velocity = 2;
+int velocity = 0;
+
+
+int count = 0;
+String inputString = "";         // a string to hold incoming data
+boolean stringComplete = false;  // whether the string is complete

 // XBee's DOUT (TX) is connected to pin 2 (Arduino's Software RX)
 // XBee's DIN (RX) is connected to pin 3 (Arduino's Software TX)
@@ -67,27 +72,54 @@

 void loop()
 {
-
-
    if (XBee.available())
     { // If data comes in from XBee, send it out to serial monitor
-      //angle = XBee.parseFloat();
-      //distance = XBee.parseFloat();
-      //Serial.write(angle);
-      Serial.write(XBee.read());
+
+    // get the new byte:
+    char inChar = (char)XBee.read();
+    // add it to the inputString:
+    inputString += inChar;
+    while (inChar != ',')
+    {
+      inChar = (char)XBee.read();
+      // add it to the inputString:
+      inputString += inChar;
+    }
+    char floatbuf[32];
+    inputString.toCharArray(floatbuf, sizeof(floatbuf));
+    angle = atof(floatbuf);
+
+    inputString = "";
+    // get the new byte:
+    inChar = (char)XBee.read();
+    // add it to the inputString:
+    inputString += inChar;
+    while (inChar != '\n')
+    {
+      inChar = (char)XBee.read();
+      // add it to the inputString:
+      inputString += inChar;
     }

-    /*
-    altitude += velocity;
-    if (altitude > 128 || altitude < 0) {
-      velocity = -velocity;
-      altitude += velocity*3;
+    inputString.toCharArray(floatbuf, sizeof(floatbuf));
+    distance = atof(floatbuf);
+
+      Serial.print("angle:");
+      Serial.println(angle);
+      Serial.print("dist:");
+      Serial.println(distance);
+//      Serial.write(XBee.read());
     }
-    // angle += 0.2;
-    glcd.clear();
-    drawBackground();
-    drawMarker(altitude, 30, angle);
-    */
+
+      altitude += velocity;
+      if (altitude > 128 || altitude < 0) {
+        velocity = -velocity;
+        altitude += velocity*3;
+      }
+      // angle += 0.2;
+      glcd.clear();
+      drawBackground();
+      drawMarker(altitude, 30, angle);
 }

 // this handy function will return the number of bytes currently free in RAM, great for debugging!


Added command to reset Controller data

Added command to reset Controller data

	Automatically reset Controller data when there's no Input
	Preamble and Postamble 0x0C to manually reset Controller Data

--- ps2_controller/ps2_controller.ino
+++ ps2_controller/ps2_controller.ino
@@ -1,14 +1,17 @@
 /*
-PS2 Controller for Arduino Mega2560 v1.1a by WhatAboutGaming
-For use in the Twitch.TV stream TwitchTriesToPlay.
-https://www.twitch.tv/twitchtriestoplay
-https://github.com/WhatAboutGaming/Twitch-Plays-Stuff
-
-Reference:
-https://gist.github.com/scanlime/5042071
-http://store.curiousinventor.com/guides/PS2/
-http://www.lynxmotion.com/images/files/ps2cmd01.txt
+  PS2 Controller for Arduino Mega2560 v1.1a by WhatAboutGaming
+  For use in the Twitch.TV stream TwitchTriesToPlay.
+  https://www.twitch.tv/twitchtriestoplay
+  https://github.com/WhatAboutGaming/Twitch-Plays-Stuff
+
+  Reference:
+  https://gist.github.com/scanlime/5042071
+  http://store.curiousinventor.com/guides/PS2/
+  http://www.lynxmotion.com/images/files/ps2cmd01.txt
 */
+
+//  Todo: Add command to send Neutral controller data and reset controller inputs
+//  Send Neutral Controller data periodically (500ms, maybe?) when there's no input running

 #define axisLx 2
 #define axisLy 3
@@ -70,6 +73,9 @@
 unsigned long calcPingTimestampOut = 0;
 unsigned long calcPongTimestampOut = 0;

+unsigned long resetControllerDataDelay = 500;
+unsigned long previousResetControllerDataDelay = 0;
+
 unsigned int leftMotorVal = 0;
 unsigned int rightMotorVal = 0;
 unsigned int analogLedVal = 0;
@@ -121,6 +127,7 @@
 byte serial_rx_buffer_reset[12];
 byte serial_rx_buffer_disconnect[12];
 byte serial_rx_buffer_inverted_controller[12];
+byte serial_rx_buffer_reset_controller[12];
 unsigned long serial_rx_buffer_counter = 0;
 unsigned long controller = 0;

@@ -350,6 +357,9 @@
   //  Computer sends Disconnect to the Arduino in case of PING timeout (The Arduino didn't respond with PONG in time)
   //  The Arduino then sends Disconnect Understood back to the Computer, both close connections on their ends, then start connection again
   //  The Computer then sends Reconnect Successful to tell the Arduino Connection is working as intended
+
+  //  Preamble/Postamble = 0x0C for Reset Controller Data
+  //  This is used when the computer requests Arduino to reset Controller data, Arduino then responds back with a 0x01 Controller Data Command.
   if (Serial.available() > 0) {

     controller = Serial.readBytes(serial_rx_buffer, sizeof(serial_rx_buffer)) && 0xFF;
@@ -408,10 +418,19 @@
     else if ((serial_rx_buffer[0] == 0x09) && (serial_rx_buffer[11] == 0x09)) {
       // Disconnect Arduino
       for (serial_rx_buffer_counter = 0; serial_rx_buffer_counter < sizeof(serial_rx_buffer_disconnect); serial_rx_buffer_counter++) {
-        //  Pass Serial Buffer to Disconnect Buffer
+        //  Pass Serial Buffer to Reset Controller Buffer
         serial_rx_buffer_disconnect[serial_rx_buffer_counter] = serial_rx_buffer[serial_rx_buffer_counter];
       }
       arduinoDisconnect();
+    }
+    else if ((serial_rx_buffer[0] == 0x0C) && (serial_rx_buffer[11] == 0x0C)) {
+      // Reset Controller Data
+      for (serial_rx_buffer_counter = 0; serial_rx_buffer_counter < sizeof(serial_rx_buffer_reset_controller); serial_rx_buffer_counter++) {
+        //  Pass Serial Buffer to Reset Controller Data Buffer
+        serial_rx_buffer_reset_controller[serial_rx_buffer_counter] = serial_rx_buffer[serial_rx_buffer_counter];
+        Serial.write(serial_rx_buffer_reset_controller[serial_rx_buffer_counter]);
+      }
+      manualResetControllerData();
     }
   }
   pressButtons();
@@ -419,6 +438,7 @@
   calculatePing();
   calculatePong();
   getAttention();
+  autoResetControllerData();
 } // Close Loop Function

 void arduinoDisconnect() {
@@ -656,9 +676,9 @@
   Serial.end();
   isConnected = false;
   disconnectDone = currentMillis;
-  delay(2500); // Wait 2.5 seconds before resetting
+  delay(2500); // Wait 2.5 seconds before resetting
   Serial.begin(baudRate);
-
+
   //  Tell the computer the connection has began succesfully
   serial_rx_buffer_disconnect[0] = 0x0B;
   serial_rx_buffer_disconnect[11] = 0x0B;
@@ -1058,7 +1078,7 @@
 }

 void calculatePing() {
-  //  Calculate delay since last PONG sent from the computer, If the computer doesn't respond with PONG in 30 seconds since the last PONG sent from the computer, connection is interrupted and the restarted
+  //  Calculate delay since last PONG sent from the computer, If the computer doesn't respond with PONG in 10 seconds since the last PONG sent from the computer, connection is interrupted and the restarted
   calcPingTimestampIn = (currentMillis - previousPingDelay);
   if ((calcPongTimestampIn - calcPingTimestampIn >= 10000) && (calcPongTimestampIn - calcPingTimestampIn <= currentMillis)) {
     disconnectCalled = currentMillis;
@@ -1290,6 +1310,128 @@
   }
 */

+void manualResetControllerData()
+{
+  //  This function resets controller data when requested by the computer. Can be used for example when something goes wrong on the computer's end.
+  serial_rx_buffer_controller[0] = 0x01; //  Preamble
+  serial_rx_buffer_controller[1] = 0x00; //  SELECT, L3, R3, START, DUP, DRIGHT, DDOWN, DLEFT
+  serial_rx_buffer_controller[2] = 0x00; //  L2, R2, L1, R1, Triangle/Delta, Circle/O, Cross/X, Square
+  serial_rx_buffer_controller[3] = 0x7F; //  RX
+  serial_rx_buffer_controller[4] = 0x7F; //  RY
+  serial_rx_buffer_controller[5] = 0x7F; //  LX
+  serial_rx_buffer_controller[6] = 0x7F; //  LY
+  serial_rx_buffer_controller[7] = 0x00; //  Analog button (Used to change between Digital and Analog modes in older games), Buffer Array Element 7  //  All other bits in this Buffer Array Element are unused
+  serial_rx_buffer_controller[8] = 0x00; //  Unused
+  serial_rx_buffer_controller[9] = 0x00; //  Delay Byte 2
+  serial_rx_buffer_controller[10] = 0x00; // Delay Byte 1
+  serial_rx_buffer_controller[11] = 0x01; // Postamble
+
+  for (serial_rx_buffer_counter = 0; serial_rx_buffer_counter < sizeof(serial_rx_buffer); serial_rx_buffer_counter++) {
+    Serial.write(serial_rx_buffer_controller[serial_rx_buffer_counter]); //  This line writes the serial data back to the computer as a way to check if the Arduino isn't interpreting wrong values
+    serial_rx_buffer_inverted_controller[serial_rx_buffer_counter] = (255 - serial_rx_buffer_controller[serial_rx_buffer_counter]); //  Invert 0 to 255 and vice versa to make it easier to determine which commands to enable or not, and their values
+  }
+
+  //  First 8 buttons, Buffer Array Element 1
+  //  SELECT, L3, R3, START, DUP, DRIGHT, DDOWN, DLEFT
+  digitalWrite(commandArray[0], (serial_rx_buffer_inverted_controller[1] & B00000001));
+  digitalWrite(commandArray[1], (serial_rx_buffer_inverted_controller[1] & B00000010));
+  digitalWrite(commandArray[2], (serial_rx_buffer_inverted_controller[1] & B00000100));
+  digitalWrite(commandArray[3], (serial_rx_buffer_inverted_controller[1] & B00001000));
+  digitalWrite(commandArray[4], (serial_rx_buffer_inverted_controller[1] & B00010000));
+  digitalWrite(commandArray[5], (serial_rx_buffer_inverted_controller[1] & B00100000));
+  digitalWrite(commandArray[6], (serial_rx_buffer_inverted_controller[1] & B01000000));
+  digitalWrite(commandArray[7], (serial_rx_buffer_inverted_controller[1] & B10000000));
+
+  //  Second 8 buttons, Buffer Array Element 2
+  //  L2, R2, L1, R1, Triangle/Delta, Circle/O, Cross/X, Square
+  digitalWrite(commandArray[8], (serial_rx_buffer_inverted_controller[2] & B00000001));
+  digitalWrite(commandArray[9], (serial_rx_buffer_inverted_controller[2] & B00000010));
+  digitalWrite(commandArray[10], (serial_rx_buffer_inverted_controller[2] & B00000100));
+  digitalWrite(commandArray[11], (serial_rx_buffer_inverted_controller[2] & B00001000));
+  digitalWrite(commandArray[12], (serial_rx_buffer_inverted_controller[2] & B00010000));
+  digitalWrite(commandArray[13], (serial_rx_buffer_inverted_controller[2] & B00100000));
+  digitalWrite(commandArray[14], (serial_rx_buffer_inverted_controller[2] & B01000000));
+  digitalWrite(commandArray[15], (serial_rx_buffer_inverted_controller[2] & B10000000));
+
+  //  4 Axis, Buffer Array Elements 3, 4, 5, 6
+  //  RX, RY, LX, LY
+  analogWrite(commandArray[16], serial_rx_buffer_inverted_controller[3]);
+  analogWrite(commandArray[17], serial_rx_buffer_inverted_controller[4]);
+  analogWrite(commandArray[18], serial_rx_buffer_inverted_controller[5]);
+  analogWrite(commandArray[19], serial_rx_buffer_inverted_controller[6]);
+
+  //  Analog button (Used to change between Digital and Analog modes in older games), Buffer Array Element 7
+  //  All other bits in this Buffer Array Element are unused
+  digitalWrite(commandArray[20], (serial_rx_buffer_inverted_controller[7] & B00000001));
+
+  //  Buffer Array Element 8 is unused in this code, but is existing in case changes are needed
+  Serial.flush();
+}
+
+void autoResetControllerData()
+{
+  //  This function resets controller data when every 500ms, but only when there's no Input being executed.
+  if (currentMillis - previousResetControllerDataDelay >= resetControllerDataDelay) {
+    if (isInputting == false) {
+      //  This function resets contreoller data when requested by the computer. Can be used for example when something goes wrong on the computer's end.
+      serial_rx_buffer_controller[0] = 0x01; //  Preamble
+      serial_rx_buffer_controller[1] = 0x00; //  SELECT, L3, R3, START, DUP, DRIGHT, DDOWN, DLEFT
+      serial_rx_buffer_controller[2] = 0x00; //  L2, R2, L1, R1, Triangle/Delta, Circle/O, Cross/X, Square
+      serial_rx_buffer_controller[3] = 0x7F; //  RX
+      serial_rx_buffer_controller[4] = 0x7F; //  RY
+      serial_rx_buffer_controller[5] = 0x7F; //  LX
+      serial_rx_buffer_controller[6] = 0x7F; //  LY
+      serial_rx_buffer_controller[7] = 0x00; //  Analog button (Used to change between Digital and Analog modes in older games), Buffer Array Element 7  //  All other bits in this Buffer Array Element are unused
+      serial_rx_buffer_controller[8] = 0x00; //  Unused
+      serial_rx_buffer_controller[9] = 0x00; //  Delay Byte 2
+      serial_rx_buffer_controller[10] = 0x00; // Delay Byte 1
+      serial_rx_buffer_controller[11] = 0x01; // Postamble
+
+      for (serial_rx_buffer_counter = 0; serial_rx_buffer_counter < sizeof(serial_rx_buffer); serial_rx_buffer_counter++) {
+        Serial.write(serial_rx_buffer_controller[serial_rx_buffer_counter]); //  This line writes the serial data back to the computer as a way to check if the Arduino isn't interpreting wrong values
+        serial_rx_buffer_inverted_controller[serial_rx_buffer_counter] = (255 - serial_rx_buffer_controller[serial_rx_buffer_counter]); //  Invert 0 to 255 and vice versa to make it easier to determine which commands to enable or not, and their values
+      }
+
+      //  First 8 buttons, Buffer Array Element 1
+      //  SELECT, L3, R3, START, DUP, DRIGHT, DDOWN, DLEFT
+      digitalWrite(commandArray[0], (serial_rx_buffer_inverted_controller[1] & B00000001));
+      digitalWrite(commandArray[1], (serial_rx_buffer_inverted_controller[1] & B00000010));
+      digitalWrite(commandArray[2], (serial_rx_buffer_inverted_controller[1] & B00000100));
+      digitalWrite(commandArray[3], (serial_rx_buffer_inverted_controller[1] & B00001000));
+      digitalWrite(commandArray[4], (serial_rx_buffer_inverted_controller[1] & B00010000));
+      digitalWrite(commandArray[5], (serial_rx_buffer_inverted_controller[1] & B00100000));
+      digitalWrite(commandArray[6], (serial_rx_buffer_inverted_controller[1] & B01000000));
+      digitalWrite(commandArray[7], (serial_rx_buffer_inverted_controller[1] & B10000000));
+
+      //  Second 8 buttons, Buffer Array Element 2
+      //  L2, R2, L1, R1, Triangle/Delta, Circle/O, Cross/X, Square
+      digitalWrite(commandArray[8], (serial_rx_buffer_inverted_controller[2] & B00000001));
+      digitalWrite(commandArray[9], (serial_rx_buffer_inverted_controller[2] & B00000010));
+      digitalWrite(commandArray[10], (serial_rx_buffer_inverted_controller[2] & B00000100));
+      digitalWrite(commandArray[11], (serial_rx_buffer_inverted_controller[2] & B00001000));
+      digitalWrite(commandArray[12], (serial_rx_buffer_inverted_controller[2] & B00010000));
+      digitalWrite(commandArray[13], (serial_rx_buffer_inverted_controller[2] & B00100000));
+      digitalWrite(commandArray[14], (serial_rx_buffer_inverted_controller[2] & B01000000));
+      digitalWrite(commandArray[15], (serial_rx_buffer_inverted_controller[2] & B10000000));
+
+      //  4 Axis, Buffer Array Elements 3, 4, 5, 6
+      //  RX, RY, LX, LY
+      analogWrite(commandArray[16], serial_rx_buffer_inverted_controller[3]);
+      analogWrite(commandArray[17], serial_rx_buffer_inverted_controller[4]);
+      analogWrite(commandArray[18], serial_rx_buffer_inverted_controller[5]);
+      analogWrite(commandArray[19], serial_rx_buffer_inverted_controller[6]);
+
+      //  Analog button (Used to change between Digital and Analog modes in older games), Buffer Array Element 7
+      //  All other bits in this Buffer Array Element are unused
+      digitalWrite(commandArray[20], (serial_rx_buffer_inverted_controller[7] & B00000001));
+
+      //  Buffer Array Element 8 is unused in this code, but is existing in case changes are needed
+      Serial.flush();
+    }
+    previousResetControllerDataDelay += resetControllerDataDelay;
+  }
+}
+
 void readMotors() {
   if ((serial_rx_buffer_motor[0] == 0x02) && (serial_rx_buffer_motor[11] == 0x02))
   {


try another font

try another font

--- rcxr01_demo1/src/rcxr01_demo1.ino
+++ rcxr01_demo1/src/rcxr01_demo1.ino
@@ -68,7 +68,7 @@
   u8x8_c = u8x8.getU8x8(); // low-level c access for custom lcd funcs
   lcd_clear_all_symbols();
   u8x8.setPowerSave(0);
-  u8x8.setFont(u8x8_font_chroma48medium8_r);
+  u8x8.setFont(u8x8_font_victoriamedium8_r);
   u8x8.drawString(0,0,"rxcr-01 demo");
   u8x8.setCursor(0,1);


commit vor der umstellung auf delay

commit vor der umstellung auf delay

--- ATtiny_Humidor_Monitoring/ATtiny_Humidor_Monitoring.ino
+++ ATtiny_Humidor_Monitoring/ATtiny_Humidor_Monitoring.ino
@@ -84,6 +84,7 @@
 int scaPin = 0;
 */

+int dhtPin = 4;
 //DHT11 und 22 lib
 #include <DHT.h>
 #include <DHT_U.h>
@@ -95,14 +96,15 @@
 DHT_Unified dht(dhtPin, DHTTYPE);

 //Pausen zwischen den Messungen in Millisekunden
-unsigned long stime = 10000;
-unsigned long mtime = 10000;
-
-boolean fanOn;
+unsigned long stime = 10000; // Zeit fuer Daten Senden
+unsigned long mtime = 10000; // Zeit fuer die Daten Messung
+
+boolean fanOn; // Boolean Feld fuer den Status vom Luefter.

 void setup() {
   //Serial.begin(115200);
   // VirtualWire Initialise the IO and ISR
+
   vw_set_ptt_inverted(false); // Required for RF Link module
   vw_set_tx_pin(txPin);
   vw_setup(1200); //Bits pro Sekunde
@@ -113,7 +115,8 @@

   //init DHT device
   dht.begin();
-  sensor_t sensor;
+  //sensor_t sensor;
+
 }

 unsigned long task, task1, task2 = 0;
@@ -174,16 +177,22 @@

 float get_temp() {
   // Read temperature as Celsius (the default)
+
   sensors_event_t event;
   dht.temperature().getEvent(&event);
   return event.temperature;
+
+  //return dht.readTemperature();
 }

 float get_hum() {
   // Read humidity
+
   sensors_event_t event;
   dht.humidity().getEvent(&event);
   return event.relative_humidity;
+
+  //return dht.readHumidity();
 }

 void TransmitData(float temp, float hum) {
@@ -212,5 +221,6 @@

   vw_send((uint8_t *)&wData, sizeof(wData));
   vw_wait_tx();
-}
-
+
+}
+


Cleanup

Cleanup

--- examples/ArtnetNeoPixel/ArtnetNeoPixel.ino
+++ examples/ArtnetNeoPixel/ArtnetNeoPixel.ino
@@ -12,13 +12,13 @@

 // Neopixel settings
 const int numLeds = 240; // change for your setup
+const int numberOfChannels = numLeds * 3; // Total number of channels you want to receive (1 led = 3 channels)
 const byte dataPin = 2;
 Adafruit_NeoPixel leds = Adafruit_NeoPixel(numLeds, dataPin, NEO_GRB + NEO_KHZ800);

 // Artnet settings
 Artnet artnet;
 const int startUniverse = 0; // CHANGE FOR YOUR SETUP most software this is 1, some software send out artnet first universe as 0.
-const int numberOfChannels = numLeds * 3; // Total number of channels you want to receive (1 led = 3 channels)

 // Check if we got all universes
 const int maxUniverses = numberOfChannels / 512 + ((numberOfChannels % 512) ? 1 : 0);


Better library link

Better library link

--- examples/ServoWebsocket/ServoWebsocket.ino
+++ examples/ServoWebsocket/ServoWebsocket.ino
@@ -1,7 +1,7 @@
 /*
  * Servo WebSocketServer
  *
- * Install the library from https://github.com/Links2004/arduinoWebSockets
+ * Install the library from https://github.com/Links2004/arduinoWebSockets/releases
  */

 #include <Arduino.h>


update equalizer

update equalizer

--- arduino/Equalizer/Equalizer.ino
+++ arduino/Equalizer/Equalizer.ino
@@ -1,18 +1,18 @@
-/*  Spectrum Analyzer using Rainbowduino, MSGEQ7 IC and 8x8 RGB LED Array
-    Rainbowduino = Ardiuno w/ ATmega328 16MHz
-    Analog signal is filtered by the MSGEQ7 into 7 channels of DC peak values
-
-*/
+#include <Adafruit_NeoPixel.h>
+#include <avr/power.h>

 int  AUDIO = 0; // ADC channel connected to the DC output pin (3)
-int  STROBE = 7; // digital pin connected to the Strobe line (4)
-int  RESET = 6; // digital pin connected to the Reset Line (7)
+int  STROBE = 8; // digital pin connected to the Strobe line (4)
+int  RESET = 7; // digital pin connected to the Reset Line (7)
 int  SAMPLES = 16; // number of analog samples to take into the average
 int  OFFSET = 37; // the DC offset seen on the output of the MSGEQ7 (300 to 600mV nominal)
+int PIN = 6;
+unsigned int output[8];  // LED output array
+byte logLed;
+byte wheelPos;
+Adafruit_NeoPixel strip = Adafruit_NeoPixel(49, PIN, NEO_GRB + NEO_KHZ800);
+uint32_t colors[8];

-unsigned int output[8];  // LED output array
-
-byte logLed;
 void setup()
 {
   Serial.begin(115200);
@@ -29,6 +29,20 @@
   digitalWrite(RESET, LOW);  // set the Reset line low
   delay(1);  //wait 1 millisecond - chip now ready for strobing through the outputs

+
+  colors[0] = strip.Color(255,0,0);
+  colors[1] = strip.Color(0,255,0);
+  colors[2] = strip.Color(0,0,255);
+  colors[3] = strip.Color(255,255,0);
+  colors[4] = strip.Color(255,0,255);
+  colors[5] = strip.Color(0,255,255);
+  colors[6] = strip.Color(255,255,255);
+  colors[7] = strip.Color(0,0,0);
+
+  wheelPos = 0;
+
+  strip.begin();
+  strip.show(); // Initialize all pixels to 'off'
 }

 void loop() {
@@ -44,6 +58,8 @@
   delayMicroseconds(200);  //wait 200 microseconds
   digitalWrite(RESET, LOW);  // set the Reset line low
   delayMicroseconds(200);  //wait 200 microsecond - chip now ready for strobing through the outputs
+  int currentLed = 0;
+  byte currentWheelPos = wheelPos;

   for (byte i = 0; i < 7; i++){   // cycle through the seven channels
     digitalWrite(STROBE, HIGH); // Strobe High to switch to the next analog channel
@@ -51,6 +67,7 @@
     digitalWrite(STROBE, LOW);  // set the Strobe line low for the next time
     delay(1);    // wait 1 milliseconds for the analog signal to stabilize
     averageValue = 0;    //reset average
+
     for (byte y = 0; y < SAMPLES; y++){  //sample analog channel
       spectrumValue = analogRead(AUDIO); // get the audio peak DC value for this spectrum
       spectrumValue = spectrumValue - OFFSET; // subtract DC offset that appears on the output
@@ -65,23 +82,37 @@
     logLed = logPeak(averageValue);  //log-scale into range for the display

     peakAverage = peakAverage + logLed;  //accumulate the peaks across all channels
-
+
+    uint32_t color = Wheel(currentWheelPos);
+    uint32_t bgColor = colors[7];
     if (goingUp) {
-      for (int i=0; i<logLed-1; i++) {
+      for (int i=0; i<logLed; i++) {
         lightArray += "[255, 255, 0],";
+        strip.setPixelColor(currentLed, color);
+        currentLed++;
       }
-      for (int i=0; i<8-logLed; i++) {
-        lightArray += "[0,0,0],";
+      for (int i=0; i<7-logLed; i++) {
+        lightArray += "[255,255,255],";
+        strip.setPixelColor(currentLed, bgColor);
+        currentLed++;
       }
     } else {
-      for (int i=0; i<8-logLed; i++) {
-        lightArray += "[0,0,0],";
+      for (int i=0; i<7-logLed; i++) {
+        lightArray += "[255,255,255],";
+        strip.setPixelColor(currentLed, bgColor);
+        currentLed++;
       }
-      for (int i=0; i<logLed-1; i++) {
+      for (int i=0; i<logLed; i++) {
         lightArray += "[255, 255, 0],";
+        strip.setPixelColor(currentLed, color);
+        currentLed++;
       }
     }
     goingUp = !goingUp;
+    currentWheelPos += 36;
+    if (currentWheelPos > 255) {
+      currentWheelPos = 0;
+    }
   }

   peakAverage = peakAverage / 8;   //average the peaks
@@ -92,7 +123,12 @@
 //  }

   lightArray += "[0,0,0]]";
-  Serial.println(lightArray);
+//  Serial.println(lightArray);
+  wheelPos++;
+  if (wheelPos > 255) {
+    wheelPos = 0;
+  }
+  strip.show();
 }

@@ -106,28 +142,43 @@

 byte logPeak(int peak){
   if (peak > 725){      //+175
-    return 8;
+    return 7;
   }
   else if(peak > 550){  //+150
-    return 7;
+    return 6;
   }
   else if(peak > 400){  //+125
-    return 6;
+    return 5;
   }
   else if(peak > 275){  //+100
-    return 5;
+    return 4;
   }
   else if(peak > 175){  //+75
-    return 4;
+    return 3;
   }
   else if(peak > 100){  //+50
-    return 3;
+    return 2;
   }
   else if(peak > 50){  //+25
-    return 2;
-  }
-  else if(peak > 25){  //baseline
     return 1;
   }
+//  else if(peak > 25){  //baseline
+//    return 1;
+//  }
   return 0;
 }
+
+// Input a value 0 to 255 to get a color value.
+// The colours are a transition r - g - b - back to r.
+uint32_t Wheel(byte WheelPos) {
+  WheelPos = 255 - WheelPos;
+  if(WheelPos < 85) {
+   return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
+  } else if(WheelPos < 170) {
+    WheelPos -= 85;
+   return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
+  } else {
+   WheelPos -= 170;
+   return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
+  }
+}


Added buzzer on EXIT knock, print message on unknown INIT command

--- arduino/KnockGame/KnockGame.ino
+++ arduino/KnockGame/KnockGame.ino
@@ -28,6 +28,9 @@
 // Unused
 #define LED3_PIN 7

+// Currently used for vibration on EXIT knock
+#define BUZZER_PIN 8
+
 #define HANDSHAKE_STR "handshake"
 #define KNOCK_STR "knock"

@@ -100,6 +103,13 @@
     global_state |= STATE_KNOCK;
     digitalWrite(LED2_PIN, 1);
   }
+  else {
+    if (global_debug) {
+      Serial.print("DEBUG Unknown action ");
+      Serial.println(gamearg);
+    }
+    return;
+  }

   char *userarg = sCmd.next();
   if (userarg) {
@@ -127,6 +137,17 @@
   else if (!strcmp(gamearg, KNOCK_STR)) {
     global_state &= ~STATE_KNOCK;
     digitalWrite(LED2_PIN, 0);
+
+    digitalWrite(BUZZER_PIN, 1);
+    delay(2000);
+    digitalWrite(BUZZER_PIN, 0);
+  }
+  else {
+    if (global_debug) {
+      Serial.print("DEBUG Unknown action ");
+      Serial.println(gamearg);
+    }
+    return;
   }

   if (global_debug) {
@@ -247,11 +268,13 @@
   pinMode(LED1_PIN, OUTPUT);
   pinMode(LED2_PIN, OUTPUT);
   pinMode(LED3_PIN, OUTPUT);
+  pinMode(BUZZER_PIN, OUTPUT);
   pinMode(BUTTON_PIN, INPUT);

   digitalWrite(LED1_PIN, 0);
   digitalWrite(LED2_PIN, 0);
   digitalWrite(LED3_PIN, 0);
+  digitalWrite(BUZZER_PIN, 0);

   global_debug = debug;
   global_userid = -1;


Internal pullup on the switches

Internal pullup on the switches

--- arduino/SmokeTest/SmokeTest.ino
+++ arduino/SmokeTest/SmokeTest.ino
@@ -1,21 +1,29 @@

-#define LED_S_GREEN   12 // D6
-#define LED_S_RED     13 // D7
+#define LED_S_GREEN   13 // D7
+#define LED_S_RED     12 // D6
 #define LED_RGB_RED   15 // D8
 #define LED_RGB_GREEN 10 // SD3
 #define LED_RGB_BLUE  14 // D5
-
+#define SW1 2
+#define SW2 0

 void setup() {
+
   pinMode(LED_S_GREEN, OUTPUT);
   pinMode(LED_S_RED, OUTPUT);

+// RGB led
   pinMode(LED_RGB_RED, OUTPUT);
   pinMode(LED_RGB_GREEN, OUTPUT);
   pinMode(LED_RGB_BLUE, OUTPUT);
+
+// Switches
+  pinMode(SW1, INPUT_PULLUP);
+  pinMode(SW2, INPUT_PULLUP);
 }

 void loop() {
+
   digitalWrite(LED_S_GREEN, HIGH);
   digitalWrite(LED_S_RED, HIGH);

@@ -25,10 +33,17 @@

   delay(1000);

+ byte sw1_state = digitalRead(SW1);
+ byte sw2_state = digitalRead(SW2);
+
+  // Do not flash if the button is not held down.
+  if (sw1_state) {
+    digitalWrite(LED_S_GREEN, LOW);
+  }
+  if (sw2_state) {
+    digitalWrite(LED_S_RED, LOW);
+  }

-  digitalWrite(LED_S_GREEN, LOW);
-  digitalWrite(LED_S_RED, LOW);
-
   digitalWrite(LED_RGB_RED, LOW);
   digitalWrite(LED_RGB_GREEN, LOW);
   digitalWrite(LED_RGB_BLUE, LOW);


[FW] Some changes to allow RAM access.

[FW] Some changes to allow RAM access.

--- firmware/MultiRomVC4000/MultiRomVC4000.ino
+++ firmware/MultiRomVC4000/MultiRomVC4000.ino
@@ -67,8 +67,6 @@
       blinkTimeLow = 1000;
     }
     romFile.close();
-
-    disableSRAM();
     enableVCBus();
   } else {
     // ROM file could not be opened.
@@ -92,17 +90,6 @@
   pinMode(CE2SRAM, OUTPUT);
   digitalWrite(CE1SRAM, LOW);
   digitalWrite(CE2SRAM, HIGH);
-}
-
-void disableSRAM() {
-  // Ensure that CE1+2 are in LOW state before turning them OFF.
-  // Switching them to INPUT mode while in HIGH state will
-  // activate the internal pullup resistors to VCC (which is a
-  // bad idea!).
-  digitalWrite(CE1SRAM, LOW);
-  digitalWrite(CE2SRAM, LOW);
-  pinMode(CE1SRAM, INPUT);
-  pinMode(CE2SRAM, INPUT);
 }

 void disableVCBus() {


Doing PI-control. Minimum iState had been erroneously set to 0 shortly before this commit. Not sure how it has affected results.

--- temp_ctrl/temp_ctrl.ino
+++ temp_ctrl/temp_ctrl.ino
@@ -29,10 +29,10 @@

 #	define DUTY_INIT 0.0

-#define PGAIN 0
-#define IGAIN 0.001
+#define PGAIN 1.1
+#define IGAIN 0.0005
 #define DGAIN 0
-#define IMIN 0
+#define IMIN -10000 // arbitrarily large min and max so they don't have effect, for now
 #define IMAX 10000

 #define TARGET 23.5 // ~20.5C ambient + 23.5C rise = 44C'ish
@@ -133,7 +133,7 @@
 	dTerm = pid->dGain * (pid->dState - pos);
 	pid->dState = pos;

-	return pTerm + dTerm + iTerm;
+	return pTerm - dTerm + iTerm;
 }

 #define TEMPERATURE_DATA_POINT_COUNT 10


Update

Update

Code use for test runs on Saturday.

--- beta/beta.ino
+++ beta/beta.ino
@@ -1,9 +1,11 @@
-#include "TinyGPS.h"
+ #include "TinyGPS.h"
 #include <SoftwareSerial.h>

 //gps serial port RX, TX
 SoftwareSerial gss(9, 10);
-SoftwareSerial device(11, 3);
+SoftwareSerial device(3, 11);
+
+int incomingByte = 0;

 //keep track of how long push button was pressed
 int state = HIGH;
@@ -12,96 +14,98 @@
 long time = 0;
 int debounce = 200; //the debounce time, increase if the output flickers

-//flags
 boolean runGPS = false;

 TinyGPS gps;

-void createFile(char fname[40])
+void setUpdateRate()
 {
-  int wait = 100; //delay to send commands to openlog
-  gss.write(26);
-  gss.write(26);
-  gss.write(26);
+  device.write((byte)0xA0); //A0
+  //device.print(160, HEX);
+  delay(200);

+  device.write((byte)0xA1);  //A1
+  //device.print(161, BIN);
+  delay(200);

-  gss.print("new ");
-  gss.print(fname);
-  gss.print("/r");
-  delay(wait);
-  gss.print("append ");
-  gss.print(fname);
-  gss.print("/r");
-  delay(wait);
+  device.write((byte)0x00);    //00
+  //device.print(0, BIN);
+  delay(200);
+
+  device.write((byte)0x03);    //03
+  //device.print(3, BIN);
+  delay(200);
+
+  device.write((byte)0x0E);   //0E
+  //device.print(14, BIN);
+  delay(200);
+
+  device.write((byte)0x05);   //10 10Hz
+  //device.print(05, BIN);
+  delay(200);
+
+  device.write((byte)0x01);
+  //device.print(1, HEX);
+  delay(200);
+
+  device.write((byte)0x0A);
+  //device.print(10, HEX);
+  delay(200);
+
+  device.write((byte)0x0D);
+  //device.print(13, BIN);
+  delay(200);
+
+  device.write((byte)0x0A);
+  //device.print(10, HEX);
+  delay(200);
+
+  if (gss.available() > 0)
+  {
+    Serial.print(gss.read(), HEX);
+  }
 }

-void setGPSBaud()
+void setBaud()
 {
-  device.write((byte)160); //A0
-  delay(50);
-  device.write((byte)161);  //A1
-  delay(50);
-  device.write((byte)0);    //00
-  delay(50);
-  device.write((byte)4);
-  delay(50);
-  device.write((byte)5);    //messageID
-  delay(50);
-  device.write((byte)0);    //COM PORT
-  delay(50);
-  device.write((byte)3);    //BAUD RATE: 38400
-  delay(50);
-  device.write((byte)0);
-  delay(50);
-  device.write((byte)5);
-  delay(50);
-  device.write((byte)13);
-  delay(50);
-  device.write((byte)10);
-  delay(50);
+  device.write((byte)0xA0); //A0
+
+  device.write((byte)0xA1);  //A1
+
+  device.write((byte)0x00);    //00
+
+  device.write((byte)0x04);    //03
+
+  device.write((byte)0x05);   //0E
+
+  device.write((byte)0x00);   //10 10Hz
+
+  device.write((byte)0x01);
+
+  device.write((byte)0x00);
+
+  device.write((byte)0x04);
+
+  device.write((byte)0xD0);
+
+  device.write((byte)0xA0);
+
+  if (gss.available() > 0)
+  {
+    Serial.print(gss.read(), HEX);
+  }
 }

-void setUpdateRate()
-{
-  device.write((byte)160); //A0
-  delay(50);
-  device.write((byte)161);  //A1
-  delay(50);
-  device.write((byte)0);    //00
-  delay(50);
-  device.write((byte)3);    //03
-  delay(50);
-  device.write((byte)14);   //0E
-  delay(50);
-  device.write((byte)10);   //10 10Hz
-  delay(50);
-  device.write((byte)0);
-  delay(50);
-  device.write((byte)15);
-  delay(50);
-  device.write((byte)13);
-  delay(50);
-  device.write((byte)10);
-  delay(50);
-}
 void setup()
 {
-  //delay(10000);
   pinMode(2, INPUT);
   pinMode(3, OUTPUT);
-  pinMode(13, OUTPUT);
+  pinMode(11, OUTPUT);

   Serial.begin(9600);
   gss.begin(9600);

-  setGPSBaud();
-  delay(1000);
-  setUpdateRate();
-  delay(1000);
-
-  //attachInterrupt(2, pushButton, CHANGE);
-
-  createFile("test.log");
+  attachInterrupt(2, pushButton, CHANGE);
 }

 void pushButton()
@@ -125,7 +129,6 @@
   }

   time = millis();
-
 }

 void getLocation()
@@ -156,6 +159,7 @@
     gss.println(speeds);

   }
+
 }

 void loop()


Se integran dos islas al nodo central-receptor

--- hardware/nodo-central/src/nodo-central.ino
+++ hardware/nodo-central/src/nodo-central.ino
@@ -133,17 +133,18 @@
       // Espera aqui hasta recibir algo

       done = radio.read(&got_isla, 2);
-      Serial.print("Dato Recibido =");
+      Serial.print("Dato Recibido = ");
       Serial.print((int)got_isla[0]);
+      Serial.print(",");
       Serial.println((int)got_isla[1]);
       delay(20); // Para dar tiempo al emisor
     }

-    radio.stopListening(); // Dejamos d escuchar para poder hablar
-
-    radio.write(&got_isla, 2);
-    Serial.println("Enviando Respuesta");
-    radio.startListening(); // Volvemos a la escucha para recibir mas paquetes
+    // radio.stopListening(); // Dejamos d escuchar para poder hablar
+    //
+    // radio.write(&got_isla, 2);
+    // Serial.println("Enviando Respuesta");
+    // radio.startListening(); // Volvemos a la escucha para recibir mas paquetes
     //sendDataEthernet(got_time); // Se envía get
   }
 }


update Lock to include latest features

update Lock to include latest features

--- tinkering/Lock/Lock.ino
+++ tinkering/Lock/Lock.ino
@@ -1,14 +1,16 @@
 #define ONE_BUTTON P1_1
 #define ZERO_BUTTON P4_5

-const uint16_t code = 0b10100111001;
-const byte size = 11;
+#define MAX_CODE 6

-const unsigned int debounce_time = 40; // ms
+const bool code[] = {1, 0, 0, 1};

+const unsigned int debounce_time = 200; // ms
+
+const byte code_size = sizeof(code);
 byte code_idx = 0;

-enum State { LOCKED, PARTIAL, UNLOCKED };
+enum State {LOCKED, INCORRECT, PARTIAL, UNLOCKED};

 State state = LOCKED;

@@ -23,6 +25,10 @@
 	code_idx = 0;
 }

+void incorrect() {
+	code_idx++;
+}
+
 void partial() {
 	code_idx++;
 }
@@ -30,14 +36,16 @@
 void unlocked() {
 	digitalWrite(RED_LED, LOW);
 	digitalWrite(GREEN_LED, HIGH);
+
+	code_idx = code_size;
 }

-StateFunc funcs[] = {locked, partial, unlocked};
+StateFunc funcs[] = {locked, incorrect, partial, unlocked};

 void change(State next) {
+	funcs[next]();
+
 	state = next;
-
-	funcs[next]();
 }

 unsigned long last_one = 0;
@@ -47,16 +55,22 @@
 	if (state == UNLOCKED) {
 		change(LOCKED);
 	}
+	else if (state == INCORRECT) {
+		change(INCORRECT);
+
+		if (code_idx == MAX_CODE)
+			change(LOCKED);
+	}
 	else {
-		if (bitRead(code, size - 1 - code_idx) != bit) {
-			change(LOCKED);
+		if (code[code_size - 1 - code_idx] == bit) {
+			change(PARTIAL);
+
+			if (code_idx == code_size) {
+				change(UNLOCKED);
+			}
 		}
 		else {
-			change(PARTIAL);
-		}
-
-		if (code_idx == size) {
-			change(UNLOCKED);
+			change(INCORRECT);
 		}
 	}
 }
@@ -92,5 +106,38 @@
 	change(LOCKED);
 }

+bool blink_state = false;
+unsigned long blink_time = 0;
+
+State last_state = LOCKED;
+
 void loop() {
+	if (last_state != state) {
+		if (state == LOCKED) {
+			digitalWrite(RED_LED, LOW);
+			delay(125);
+			digitalWrite(RED_LED, HIGH);
+			delay(125);
+			digitalWrite(RED_LED, LOW);
+			delay(125);
+			digitalWrite(RED_LED, HIGH);
+			delay(125);
+			digitalWrite(RED_LED, LOW);
+			delay(250);
+			digitalWrite(RED_LED, HIGH);
+		}
+
+		last_state = state;
+	}
+
+	unsigned long time = millis();
+
+	if ((state == PARTIAL || state == INCORRECT) && time > blink_time) {
+		digitalWrite(RED_LED, blink_state);
+
+		blink_state = !blink_state;
+		blink_time = time + 1000;
+	}
+
+	sleep(80);
 }


Update climate_meter.ino

Update climate_meter.ino

--- climate_meter/climate_meter.ino
+++ climate_meter/climate_meter.ino
@@ -7,12 +7,23 @@
  * DHT11/22 - 1 unit,
  * DS18B20  - 3 units,
  *
- * Communicates using Modbus RTU:
- * Holding Registers (4x) 40001 - 40010
+ * Supports Modbus RTU.
+ * Holding Registers (4X), function 03H.
+ * Register address 1 corresponds to the physical address 0.
+ *
+ * Register  Type   Description
+ * 01-02     Float  Pressure (BMP280)
+ * 03-04     Float  Temperature (BMP280)
+ * 05-06     Float  Humidity (DHT22)
+ * 06-08     Float  Temperature (DHT22)
+ * 07-10     Float  Temerature 0 (DS18B20)
+ * 08-12     Float  Temerature 1 (DS18B20)
+ * 11-14     Float  Temerature 2 (DS18B20)
  *
  * (c) 2017-2019, Mikhail Shiryaev
  */

+#include <Adafruit_BMP280.h>   // https://github.com/adafruit/Adafruit_BMP280_Library
 #include <DHT.h>               // https://github.com/adafruit/DHT-sensor-library
 #include <OneWire.h>           // http://www.pjrc.com/teensy/td_libs_OneWire.html
 #include <DallasTemperature.h> // https://github.com/milesburton/Arduino-Temperature-Control-Library
@@ -23,10 +34,11 @@
 #define ONE_WIRE_PIN1 6 // the 2nd DS18B20 data
 #define ONE_WIRE_PIN2 7 // the 3rd DS18B20 data

+#define BMP_ADDR        0x76   // BMP280 I2C address
 #define DHT_TYPE        DHT22  // DHT11 or DHT22
 #define ONE_WIRE_CNT    3      // count of 1-wire connections
 #define EMPTY_VAL       -100.0 // empty float value of measurement
-#define MODBUS_BUF_LEN  25     // length of Modbus RTU output buffer
+#define MODBUS_BUF_LEN  33     // length of Modbus RTU output buffer

 //#define DEBUG                // write detailed log to Serial port and disable Modbus

@@ -41,6 +53,12 @@
  #define DEBUG_PRINTLN(val)
  #define DEBUG_WRITETIME()
 #endif
+
+// BMP280 by I2C
+Adafruit_BMP280 bmp;
+bool bmpFound = false;
+float bmpP = EMPTY_VAL;
+float bmpT = EMPTY_VAL;

 // DHT instance
 DHT dht(DHT_PIN, DHT_TYPE);
@@ -104,9 +122,14 @@
 byte modbusBuf[MODBUS_BUF_LEN] = {
   0x00,       // Slave address
   0x03,       // Function code
-  0x14,       // Byte count (20)
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // register values
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // register values
+  0x1C,       // Byte count (28)
+  0x00, 0x00, 0x00, 0x00, // Register values
+  0x00, 0x00, 0x00, 0x00,
+  0x00, 0x00, 0x00, 0x00,
+  0x00, 0x00, 0x00, 0x00,
+  0x00, 0x00, 0x00, 0x00,
+  0x00, 0x00, 0x00, 0x00,
+  0x00, 0x00, 0x00, 0x00,
   0x00, 0x00  // CRC
 };

@@ -114,6 +137,21 @@
 #ifdef DEBUG
 unsigned long time;
 #endif
+
+// Initialize BMP280 sensor
+void initBMP() {
+  if (bmp.begin(BMP_ADDR)) {
+    DEBUG_PRINTLN("BMP280 sensor initialized");
+    bmpFound = true;
+    bmp.setSampling(Adafruit_BMP280::MODE_NORMAL,     /* Operating Mode. */
+                    Adafruit_BMP280::SAMPLING_X2,     /* Temp. oversampling */
+                    Adafruit_BMP280::SAMPLING_X16,    /* Pressure oversampling */
+                    Adafruit_BMP280::FILTER_X16,      /* Filtering. */
+                    Adafruit_BMP280::STANDBY_MS_500); /* Standby time. */
+  } else {
+    DEBUG_PRINTLN("BMP280 sensor not found");
+  }
+}

 // Initialize DHT sensor
 void initDHT() {
@@ -139,6 +177,26 @@
   Serial.println(millis() - time);
 }
 #endif
+
+// Read data from BMP280 sensor
+void readBMP() {
+  DEBUG_WRITETIME();
+  DEBUG_PRINTLN("Reading from BMP280 sensor");
+
+  if (bmpFound) {
+    bmpP = bmp.readPressure();    // Pa
+    bmpT = bmp.readTemperature(); // *C
+  }
+
+  DEBUG_WRITETIME();
+  DEBUG_PRINT("t = ");
+  DEBUG_PRINTLN(bmpT);
+  DEBUG_PRINT("p = ");
+  DEBUG_PRINTLN(bmpP);
+
+  DEBUG_WRITETIME();
+  DEBUG_PRINTLN();
+}

 // Read data from DHT sensor
 void readDHT() {
@@ -186,23 +244,25 @@
 // Process serial communication using Modbus protocol
 void communicate() {
 #ifndef DEBUG
-  // wait for the request 00 03 00 00 00 0A C4 1C
+  // wait for the request 00 03 00 00 00 0E C5 DF
   boolean sendResponse = false;
   while (Serial.available() > 0) {
     byte inByte = (byte)Serial.read();

-    if (inByte == 0x1C) {
+    if (inByte == 0xDF) {
       sendResponse = true;
     }
   }

   // send response
   if (sendResponse) {
-    memcpy(modbusBuf + 3, (byte*)&dhtH, 4);
-    memcpy(modbusBuf + 7, (byte*)&dhtT, 4);
-    memcpy(modbusBuf + 11, (byte*)&dsT, 12);
+    memcpy(modbusBuf + 3, (byte*)&bmpP, 4);
+    memcpy(modbusBuf + 7, (byte*)&bmpT, 4);
+    memcpy(modbusBuf + 11, (byte*)&dhtH, 4);
+    memcpy(modbusBuf + 15, (byte*)&dhtT, 4);
+    memcpy(modbusBuf + 19, (byte*)&dsT, 12);
     unsigned short crc = CRC16(modbusBuf, MODBUS_BUF_LEN - 2);
-    memcpy(modbusBuf + 23, (byte*)&crc, 2);
+    memcpy(modbusBuf + 31, (byte*)&crc, 2);
     Serial.write(modbusBuf, MODBUS_BUF_LEN);
   }
 #endif
@@ -227,6 +287,7 @@
   Serial.begin(9600);
   DEBUG_PRINTLN();
   DEBUG_PRINTLN("SERIAL TH meter started");
+  initBMP();
   initDHT();
   initDS();
   DEBUG_PRINTLN();
@@ -238,12 +299,14 @@
   delay(500);
 #endif

-  readDHT(); // around 270 ms
-  communicate();
-  readDS(0); // around 800 ms
-  communicate();
-  readDS(1); // around 800 ms
-  communicate();
-  readDS(2); // around 800 ms
-  communicate();
-}
+  readBMP(); // around 3 ms
+  communicate();
+  readDHT(); // around 50 ms
+  communicate();
+  readDS(0); // around 700 ms
+  communicate();
+  readDS(1); // around 700 ms
+  communicate();
+  readDS(2); // around 700 ms
+  communicate();
+}


Update 01_HelloWorld.ino

Update 01_HelloWorld.ino

fixed print staement

--- code/examples/01_HelloWorld.ino
+++ code/examples/01_HelloWorld.ino
@@ -16,7 +16,7 @@
     SPI1.setDataMode(SPI_MODE0);
     SPI1.setClockDivider(SPI_CLOCK_DIV4);
     display.begin(true);                //Initialize the ePaper and reset the screen
-    display.print('Hello World!');      //Write “Hello World!” into the buffer
+    display.print("Hello World!");      //Write “Hello World!” into the buffer
     display.updateFull();               //Trigger an update based on the buffer content
 }


Fix some c++ compile errors in Tracer

Fix some c++ compile errors in Tracer

Signed-off-by: Cody Massin <420bebd5a852fd1111446fa9e2d3f8a881db9ffd@gmail.com>

--- Tracer/Tracer.ino
+++ Tracer/Tracer.ino
@@ -19,21 +19,21 @@
     }
     for (int i = 0; i < sizeof(letters); i++) {
       digitalWrite(Lights[i], PATTERN_ON);
-      delay(250)
+      delay(250);
       digitalWrite(Lights[i], PATTERN_OFF);
-      delay(250)
+      delay(250);
     }
-    for(var int j=0; j< 3; j++) {
+    for(int j=0; j< 3; j++) {

       for (int i = 0; i < sizeof(letters); i++) {
         digitalWrite(Lights[i], PATTERN_ON);
       }
-      delay(250)
+      delay(250);
       for (int i = 0; i < sizeof(letters); i++) {
         digitalWrite(Lights[i], PATTERN_OFF);
       }
-      delay(250)
+      delay(250);

     }
-    delay(250)
+    delay(250);
 }


Thinking about putting ',' in frequency display

--- DigitalVFO.ino
+++ DigitalVFO.ino
@@ -1143,6 +1143,9 @@
 //     col, row    position to display left-most digit at
 // If the value is too long it will be truncated at the left.
 //----------------------------------------
+
+// list of row 0 column positions for the display digits
+//int freq_digit_offset[] = {4, 5, 7, 8, 9, 11, 12, 11};

 void display_sel_value(ULONG value, int sel_col, int num_digits, int col, int row)
 {
@@ -1831,7 +1834,7 @@
 #if (DEBUG != 0)
   Serial.printf(F("\n"));
   Serial.printf(F("*************************************************\n"));
-  Serial.printf(F("*           %s %s%s (%s)          *\n"),
+  Serial.printf(F("*            %s %s%s (%s)           *\n"),
                 ProgramName, Version, MinorVersion, Callsign);
   Serial.printf(F("*************************************************\n"));
   Serial.printf(F("\n"));


Wird nicht gebraucht

Wird nicht gebraucht

--- MazeSolver.ino
+++ MazeSolver.ino
@@ -1,284 +0,0 @@
-#include <QTRSensors.h>
-#include "Direction.h"
-
-const int numberOfSensors = 6;
-// pid loop vars
-const float proportionalConst = 0.1f;
-const float derivateConst = 1.0f;
-const int calibrationSeconds = 4;
-const int twoHundred = 200;
-
-int speed_a = 3;  //speed control for motor outputs 1 and 2 is on digital pin 10  (Right motor)
-int speed_b = 11; //speed control for motor outputs 3 and 4 is on digital pin 11  (Left motor)
-int dir_a = 12;  //direction control for motor outputs 1 and 2 is on digital pin 12  (Right motor)
-int dir_b = 13;  //direction control for motor outputs 3 and 4 is on digital pin 13  (Left motor)
-
-// motor tuning vars for maze navigating
-int turnSpeed = 200;  // tune value motors will run while turning (0-255) NOT TESTED
-int turnSpeedSlow = 125;  // tune value motors will run as they slow down from turning cycle to avoid overrun (0-255) NOT TESTED
-int drivePastDelay = 300; // tune value in mseconds motors will run past intersection to align wheels for turn NOT TESTED
-
-
-unsigned char pins[6] = { 0, 1, 2, 3, 4, 5 };
-QTRSensorsAnalog qtra(pins, numberOfSensors, 4, 2);
-unsigned int sensorValues[numberOfSensors];
-
-Direction direction = forward;
-
-unsigned int position;
-int lastError;
-int loopIndex;
-
-void setup()
-{
-	pinMode(12, OUTPUT);
-	pinMode(13, OUTPUT);
-
-	Serial.begin(9600);
-
-	delay(500);
-
-	calibrate();
-
-	Serial.println('\n');
-	delay(1000);
-}
-
-void loop()
-{
-	switch (Serial.read())
-	{
-	case '1':
-		direction = none;
-		break;
-	case '2':
-		direction = forward;
-		break;
-	default:
-		break;
-	}
-
-	if (loopIndex % 100 == 0)
-	{
-		printSensorValues();
-	}
-
-	drive();
-
-	loopIndex++;
-}
-
-void calibrate()
-{
-	for (int i = 0; i < calibrationSeconds / 0.025; i++)
-	{
-		qtra.calibrate();
-	}
-
-	// print the calibration minimum values measured when emitters were on
-	for (int i = 0; i < numberOfSensors; i++)
-	{
-		Serial.print(qtra.calibratedMinimumOn[i]);
-		Serial.print(' ');
-	}
-	Serial.println();
-
-	// print the calibration maximum values measured when emitters were on
-	for (int i = 0; i < numberOfSensors; i++)
-	{
-		Serial.print(qtra.calibratedMaximumOn[i]);
-		Serial.print(' ');
-	}
-}
-
-void drive()
-{
-	if (direction == none)
-	{
-		moveMotorOnSide(left, 0);
-		moveMotorOnSide(right, 0);
-		return;
-	}
-
-	position = qtra.readLine(sensorValues);
-	int posPropotionalToMid = position - 2500;
-
-	int motorSpeed = proportionalConst * posPropotionalToMid + derivateConst * (posPropotionalToMid - lastError);
-	lastError = posPropotionalToMid;
-
-	moveMotorOnSide(left, twoHundred - motorSpeed);
-	//Serial.print(' ');
-	moveMotorOnSide(right, twoHundred + motorSpeed);
-
-}
-
-void moveMotorOnSide(Direction side, int speed)
-{
-	speed = max(min(speed, 180), 0);
-	//Serial.print("Motor ");
-	//Serial.print(side == left ? "left " : "right ");
-	//Serial.print(' ');
-	//Serial.print(speed);
-	digitalWrite(side == left ? 13 : 12, HIGH);
-	analogWrite(side == left ? 3 : 11, speed);
-}
-
-void printSensorValues()
-{
-	for (unsigned char i = 0; i < numberOfSensors; i++)
-	{
-		Serial.print(sensorValues[i]);
-		Serial.print('\t');
-	}
-
-	Serial.println((int)position - 2500);
-}
-// Turns to the sent variable of
-// 'L' (left), 'R' (right), 'S' (straight), or 'B' (back)
-// To Do: Tune 'turnSpeed'
-void turn(char dir)
-{
-  switch(dir)
-  {
-    // Turn left 90deg
-    case 'L':
-      digitalWrite(dir_a, HIGH);
-      analogWrite(speed_a, turnSpeed);
-      digitalWrite(dir_b, LOW);
-      analogWrite(speed_b, turnSpeed);
-
-      position = qtrra.readLine(sensorValues);
-
-
-      while (sensorValues[5] <300)  // wait for outer most sensor to find the line
-      {
-        position = qtrra.readLine(sensorValues);
-      }
-
-      // slow down speed
-      analogWrite(speed_a, turnSpeedSlow);
-      analogWrite(speed_b, turnSpeedSlow);
-
-      // find center
-      while (position > 3000)  // tune - wait for line position to find near center
-      {
-        position = qtrra.readLine(sensorValues); //possible bug: libary uses position to calculate the next val
-      }
-
-      // stop both motors
-      analogWrite(speed_b, 0);  // stop right motor first to better avoid over run
-      analogWrite(speed_a, 0);
-      break;
-
-    // Turn right 90deg
-    case 'R':
-      digitalWrite(dir_a, LOW);
-      analogWrite(speed_a, turnSpeed);
-      digitalWrite(dir_b, HIGH);
-      analogWrite(speed_b, turnSpeed);
-
-      line_position = qtrra.readLine(sensorValues);
-
-      while (sensorValues[0] <300)  // wait for outer most sensor to find the line
-      {
-        position = qtrra.readLine(sensorValues);
-      }
-
-      // slow down speed
-      analogWrite(speed_a, turnSpeedSlow);
-      analogWrite(speed_b, turnSpeedSlow);
-
-      // find center
-      while (position < 3000)  // tune - wait for line position to find near center
-      {
-        position = qtrra.readLine(sensorValues);
-      }
-
-      // stop both motors
-      analogWrite(speed_a, 0);
-      analogWrite(speed_b, 0);
-      break;
-
-    // Turn right 180deg to go back
-    case 'B':
-      digitalWrite(dir_a, LOW);
-      analogWrite(speed_a, turnSpeed);
-      digitalWrite(dir_b, HIGH);
-      analogWrite(speed_b, turnSpeed);
-
-      position = qtrrc.readLine(sensorValues);
-
-      while (sensorValues[0] <300)  // wait for outer most sensor to find the line
-      {
-        position = qtrra.readLine(sensorValues);
-      }
-
-      // slow down speed
-      analogWrite(speed_a, turnSpeedSlow);
-      analogWrite(speed_b, turnSpeedSlow);
-
-      // find center
-      while (position < 300)  // tune - wait for line position to find near center
-      {
-        position = qtrrc.readLine(sensorValues);
-      }
-
-      // stop both motors
-      analogWrite(speed_a, 0);
-      analogWrite(speed_b, 0);
-      break;
-
-    // Straight ahead
-    case 'S':
-      // do nothing
-      break;
-  }
-} // end turn
-
-void MazeSolve()
-{
-  while(1)
-  {
-
-    follow_line();
-
-    // Drive straight a bit.
-    digitalWrite(dir_a, LOW);
-    analogWrite(pwm_a, 200);
-    digitalWrite(dir_b, LOW);
-    analogWrite(pwm_b, 200);
-    delay(25);
-
-    // These variables record whether the robot has seen a line to the
-    // left, straight ahead, and right, whil examining the current
-    // intersection.
-    unsigned char found_left=0;
-    unsigned char found_straight=0;
-    unsigned char found_right=0;
-
-    // Now read the sensors and check the intersection type.
-    line_position = qtrra.readLine(sensorValues);
-
-    // Check for left and right exits.
-    if(sensorValues[0] > 400)
-    found_right = 1;
-    if(sensorValues[5] > 400)
-    found_left = 1;
-
-    // Drive straight a bit more
-    digitalWrite(dir_a, LOW);
-    analogWrite(pwm_a, 200);
-    digitalWrite(dir_b, LOW);
-    analogWrite(pwm_b, 200);
-    delay(drivePastDelay);
-
-    line_position = qtrra.readLine(sensorValues);
-   // if(sensorValues[1] > 200 || sensorValues[2] > 200 || sensorValues[3] > 200 || sensorValues[4] > 200) //To Do: Which sensor values indicate a straight
-   // found_straight = 1;
-
-   // unsigned char dir = select_turn(found_left, found_straight, found_right); //To Do: this method
-
-    // Make the turn indicated by the path.
-    turn(dir);
-    //To Do: End of the maze
-  }


Accelerometer and magnetometer calibrated. The magnetometer is preliminar, and we have the gyroscope left

--- OpenRocket.ino
+++ OpenRocket.ino
@@ -8,7 +8,7 @@
 */

 #define HW__VERSION_CODE 10724 // SparkFun "9DOF Sensor Stick" version "SEN-10724" (HMC5883L magnetometer)
-#define OUTPUT__BAUD_RATE 57600
+#define OUTPUT__BAUD_RATE 9600
 #define OUTPUT__DATA_INTERVAL 20  // in milliseconds
 #define WRITE__DATA_INTERVAL 1000  // in milliseconds

@@ -32,12 +32,12 @@
 // Put MIN/MAX and OFFSET readings for your board here!
 // Accelerometer
 // "accel x,y,z (min/max) = X_MIN/X_MAX  Y_MIN/Y_MAX  Z_MIN/Z_MAX"
-#define ACCEL_X_MIN ((float) -250)
-#define ACCEL_X_MAX ((float) 250)
-#define ACCEL_Y_MIN ((float) -250)
-#define ACCEL_Y_MAX ((float) 250)
-#define ACCEL_Z_MIN ((float) -250)
-#define ACCEL_Z_MAX ((float) 250)
+#define ACCEL_X_MIN ((float) -268)
+#define ACCEL_X_MAX ((float) 260)
+#define ACCEL_Y_MIN ((float) -256)
+#define ACCEL_Y_MAX ((float) 272)
+#define ACCEL_Z_MIN ((float) -281)
+#define ACCEL_Z_MAX ((float) 238)

 // Magnetometer (standard calibration)
 // "magn x,y,z (min/max) = X_MIN/X_MAX  Y_MIN/Y_MAX  Z_MIN/Z_MAX"


Delete C_COMMUT-Industruino.ino

Delete C_COMMUT-Industruino.ino


debounce update

debounce update

--- _06-power-meter/_06-power-meter.ino
+++ _06-power-meter/_06-power-meter.ino
@@ -244,7 +244,17 @@

 void count_powermeter()
 {
-  // if (( millis() - startMills ) < 600 ) {
+  long removebounce ;
+  // 600 rev/kWh --> 1 rev 6 sec 1kW
+  // max A : 40
+  // 220 V * 45A = 9900,
+  // 0.6sec -> 10kW
+  //
+
+  if (( millis() - startMills ) < 500 ) {
+    return;
+  }
+
   if (( millis() - startMills ) < ( revMills / 3 )) {
     return;
   } else {


trying new code to speed up scanner motor

--- ImageAnalysis/PrinterMechanics_Scanner/PrinterMechanics_Scanner.ino
+++ ImageAnalysis/PrinterMechanics_Scanner/PrinterMechanics_Scanner.ino
@@ -25,6 +25,7 @@
 int start_pos = 100;
 int end_pos = 145;
 int rot_speed = 30;
+int current_pos;

 Servo dvd_down;

@@ -86,53 +87,53 @@
 	//Serial.println(analogRead(JoyH_Y));
 	//Serial.println(analogRead(JoyV_Y));
 	//Serial.println(analogRead(JoyV_X));
-	Serial.println(digitalRead(JoyV_SW));
+	//Serial.println(digitalRead(JoyV_SW));

 	// Big
 	if (analogRead(JoyH_Y)<400)
 	{
-		move_big();
+		move_stepper(StepPinH_Y, 100);
 		digitalWrite(DirectionPinH_Y, LOW);
 	}

 	if (analogRead(JoyH_Y)>600)
 	{
-		move_big();
+		move_stepper(StepPinH_Y, 100);
 		digitalWrite(DirectionPinH_Y, HIGH);
 	}

 	// Scanner
 	if (analogRead(JoyH_X)<400)
 	{
-		move_scanner();
+		move_stepper(StepPinH_X, 1);
 		digitalWrite(DirectionPinH_X, HIGH);
 	}

 	if (analogRead(JoyH_X)>600)
 	{
-		move_scanner();
+		move_stepper(StepPinH_X, 1);
 		digitalWrite(DirectionPinH_X, LOW);
 	}

 	// DVD
 	if (analogRead(JoyV_Y)<400)
 	{
-		move_dvd();
+		move_stepper(StepPinV_Y, 700);
 		digitalWrite(DirectionPinV_Y, HIGH);
 	}

 	if (analogRead(JoyV_Y)>600)
 	{
-		move_dvd();
+		move_stepper(StepPinV_Y, 700);
 		digitalWrite(DirectionPinV_Y, LOW);
 	}

 	// Servo

-	//if (analogRead(JoyV_X)<400)
+
 	if (digitalRead(JoyV_SW) == HIGH)
 	{
-		Serial.println(digitalRead(JoyV_SW));
+		//Serial.println(digitalRead(JoyV_SW));
 		if (dvd_down.read() != start_pos) {
 			// Slowly move back to restart
 			for (int i = end_pos; i > start_pos - 1; i--) {
@@ -142,52 +143,25 @@
 		}
 	}

-	//if (analogRead(JoyV_X)>600)
+
 	if (digitalRead(JoyV_SW) == LOW)
 	{
-		Serial.println(digitalRead(JoyV_SW));
+		//Serial.println(digitalRead(JoyV_SW));
 		if (dvd_down.read() != end_pos) {
 			for (int i = start_pos; i < end_pos + 1; i++) {
 				dvd_down.write(i);
 				delay(rot_speed);
+
 			}
 		}
 	}

 }

-void move_big() // big motor
-{
-	digitalWrite(StepPinH_Y, HIGH);
-	delayMicroseconds(100); //big motor
+void move_stepper(int motor_pin, int delay_val) {
+	digitalWrite(motor_pin, HIGH);
+	delayMicroseconds(delay_val); //big motor

-	digitalWrite(StepPinH_Y, LOW);
-	delayMicroseconds(100); //big motor
-}
-
-void move_scanner()
-{
-	digitalWrite(StepPinH_X, HIGH);
-	delayMicroseconds(1); //scanner
-
-	digitalWrite(StepPinH_X, LOW);
-	delayMicroseconds(1); //scanner
-}
-
-void move_dvd()
-{
-	digitalWrite(StepPinV_Y, HIGH);
-	delayMicroseconds(700); //DVD
-
-	digitalWrite(StepPinV_Y, LOW);
-	delayMicroseconds(700); //DVD
-}
-
-void move_servo()
-{
-	digitalWrite(StepPinV_Y, HIGH);
-	delayMicroseconds(700); //DVD
-
-	digitalWrite(StepPinV_Y, LOW);
-	delayMicroseconds(700); //DVD
+	digitalWrite(motor_pin, LOW);
+	delayMicroseconds(delay_val); //big motor
 }


vel=0 when ROS is disconnected

vel=0 when ROS is disconnected

--- arduino/opencr_arduino/opencr/libraries/turtlebot3/examples/turtlebot3_with_open_manipulator/turtlebot3_with_open_manipulator_core/turtlebot3_with_open_manipulator_core.ino
+++ arduino/opencr_arduino/opencr/libraries/turtlebot3/examples/turtlebot3_with_open_manipulator/turtlebot3_with_open_manipulator_core/turtlebot3_with_open_manipulator_core.ino
@@ -38,7 +38,7 @@
   nh.subscribe(motor_power_sub);
   nh.subscribe(reset_sub);

-  nh.advertise(sensor_state_pub);
+  nh.advertise(sensor_state_pub);
   nh.advertise(version_info_pub);
   nh.advertise(imu_pub);
   nh.advertise(cmd_vel_rc100_pub);
@@ -86,7 +86,7 @@

   if ((t-tTime[0]) >= (1000 / CONTROL_MOTOR_SPEED_FREQUENCY))
   {
-    updateGoalVelocity();
+    updateGoalVelocity(nh.connected());
     motor_driver.controlMotor(WHEEL_RADIUS, WHEEL_SEPARATION, goal_velocity);
     tTime[0] = t;
   }
@@ -135,7 +135,7 @@
   // Send log message after ROS connection
   sendLogMsg();

-  // Receive data from RC100
+  // Receive data from RC100
   controllers.getRCdata(goal_velocity_from_rc100);

   // Check push button pressed for simple test drive
@@ -218,7 +218,7 @@
 void gripperMoveTimeCallback(const std_msgs::Float64& time_msg)
 {
   double data = time_msg.data;
-
+
   manipulator_driver.writeGripperProfileControlParam(data);
 }

@@ -261,7 +261,7 @@
   initOdom();

   sprintf(log_msg, "Reset Odometry");
-  nh.loginfo(log_msg);
+  nh.loginfo(log_msg);
 }

 /*******************************************************************************
@@ -326,7 +326,7 @@
   // sensor_state_msg.sonar = sensors.getSonarData();

   sensor_state_msg.illumination = sensors.getIlluminationData();
-
+
   sensor_state_msg.button = sensors.checkPushButton();

   sensor_state_msg.torque = motor_driver.getTorque();
@@ -359,7 +359,7 @@
   if (battery_state == 0)
     battery_state_msg.present = false;
   else
-    battery_state_msg.present = true;
+    battery_state_msg.present = true;

   battery_state_pub.publish(&battery_state_msg);
 }
@@ -411,7 +411,7 @@
       if (!strcmp(get_tf_prefix, ""))
       {
         sprintf(odom_header_frame_id, "odom");
-        sprintf(odom_child_frame_id, "base_footprint");
+        sprintf(odom_child_frame_id, "base_footprint");

         sprintf(imu_frame_id, "imu_link");
         sprintf(mag_frame_id, "mag_link");
@@ -435,16 +435,16 @@
       }

       sprintf(log_msg, "Setup TF on Odometry [%s]", odom_header_frame_id);
-      nh.loginfo(log_msg);
+      nh.loginfo(log_msg);

       sprintf(log_msg, "Setup TF on IMU [%s]", imu_frame_id);
-      nh.loginfo(log_msg);
+      nh.loginfo(log_msg);

       sprintf(log_msg, "Setup TF on MagneticField [%s]", mag_frame_id);
-      nh.loginfo(log_msg);
+      nh.loginfo(log_msg);

       sprintf(log_msg, "Setup TF on JointState [%s]", joint_state_header_frame_id);
-      nh.loginfo(log_msg);
+      nh.loginfo(log_msg);

       isChecked = true;
     }
@@ -473,7 +473,7 @@
 }

 /*******************************************************************************
-* Update the joint states
+* Update the joint states
 *******************************************************************************/
 void updateJointStates(void)
 {
@@ -533,7 +533,7 @@
 {
   int32_t current_tick = 0;
   static int32_t last_tick[WHEEL_NUM] = {0, 0};
-
+
   if (init_encoder)
   {
     for (int index = 0; index < WHEEL_NUM; index++)
@@ -543,7 +543,7 @@
       last_rad[index]       = 0.0;

       last_velocity[index]  = 0.0;
-    }
+    }

     last_tick[LEFT] = left_tick;
     last_tick[RIGHT] = right_tick;
@@ -597,9 +597,9 @@
     wheel_r = 0.0;

   delta_s     = WHEEL_RADIUS * (wheel_r + wheel_l) / 2.0;
-  // theta = WHEEL_RADIUS * (wheel_r - wheel_l) / WHEEL_SEPARATION;
+  // theta = WHEEL_RADIUS * (wheel_r - wheel_l) / WHEEL_SEPARATION;
   orientation = sensors.getOrientation();
-  theta       = atan2f(orientation[1]*orientation[2] + orientation[0]*orientation[3],
+  theta       = atan2f(orientation[1]*orientation[2] + orientation[0]*orientation[3],
                 0.5f - orientation[2]*orientation[2] - orientation[3]*orientation[3]);

   delta_theta = theta - last_theta;
@@ -657,7 +657,7 @@
       else  move_time = joint_trajectory_point.data[points] - joint_trajectory_point.data[points - POINT_SIZE];

       for (uint32_t positions = points + 1; positions < (points + POINT_SIZE); positions++)
-      {
+      {
         if ((points + POINT_SIZE) >= all_points_cnt)
         {
           goal_joint_position[write_cnt] = joint_trajectory_point.data[positions];
@@ -703,7 +703,7 @@

   motor_driver.readEncoder(current_tick[LEFT], current_tick[RIGHT]);

-  if (buttons & (1<<0))
+  if (buttons & (1<<0))
   {
     move[LINEAR] = true;
     saved_tick[RIGHT] = current_tick[RIGHT];
@@ -719,7 +719,7 @@
   }

   if (move[LINEAR])
-  {
+  {
     if (abs(saved_tick[RIGHT] - current_tick[RIGHT]) <= diff_encoder)
     {
       goal_velocity_from_button[LINEAR]  = 0.05;
@@ -731,7 +731,7 @@
     }
   }
   else if (move[ANGULAR])
-  {
+  {
     if (abs(saved_tick[RIGHT] - current_tick[RIGHT]) <= diff_encoder)
     {
       goal_velocity_from_button[ANGULAR]= -0.7;
@@ -750,11 +750,11 @@
 void updateVariable(bool isConnected)
 {
   static bool variable_flag = false;
-
+
   if (isConnected)
   {
     if (variable_flag == false)
-    {
+    {
       sensors.initIMU();
       initOdom();

@@ -773,11 +773,11 @@
 void waitForSerialLink(bool isConnected)
 {
   static bool wait_flag = false;
-
+
   if (isConnected)
   {
     if (wait_flag == false)
-    {
+    {
       delay(10);

       wait_flag = true;
@@ -854,17 +854,17 @@
 void sendLogMsg(void)
 {
   static bool log_flag = false;
-  char log_msg[100];
+  char log_msg[100];

   String firmware_version = FIRMWARE_VER;
   String bringup_log      = "This core(v" + firmware_version + ") is compatible with TB3 with OpenManipulator";
-
+
   const char* init_log_data = bringup_log.c_str();

   if (nh.connected())
   {
     if (log_flag == false)
-    {
+    {
       sprintf(log_msg, "--------------------------");
       nh.loginfo(log_msg);

@@ -931,8 +931,12 @@
 /*******************************************************************************
 * Update Goal Velocity
 *******************************************************************************/
-void updateGoalVelocity(void)
-{
+void updateGoalVelocity(bool isConnected)
+{
+    if(!isConnected){
+    goal_velocity_from_cmd[LINEAR] = 0.0;
+    goal_velocity_from_cmd[ANGULAR] = 0.0;
+  }
   goal_velocity[LINEAR]  = goal_velocity_from_button[LINEAR]  + goal_velocity_from_cmd[LINEAR]  + goal_velocity_from_rc100[LINEAR];
   goal_velocity[ANGULAR] = goal_velocity_from_button[ANGULAR] + goal_velocity_from_cmd[ANGULAR] + goal_velocity_from_rc100[ANGULAR];
 }
@@ -971,7 +975,7 @@
   DEBUG_SERIAL.print("    x : "); DEBUG_SERIAL.println(quat[1]);
   DEBUG_SERIAL.print("    y : "); DEBUG_SERIAL.println(quat[2]);
   DEBUG_SERIAL.print("    z : "); DEBUG_SERIAL.println(quat[3]);
-
+
   DEBUG_SERIAL.println("---------------------------------------");
   DEBUG_SERIAL.println("DYNAMIXELS");
   DEBUG_SERIAL.println("---------------------------------------");
@@ -980,7 +984,7 @@

   int32_t encoder[WHEEL_NUM] = {0, 0};
   motor_driver.readEncoder(encoder[LEFT], encoder[RIGHT]);
-
+
   DEBUG_SERIAL.println("Encoder(left) : " + String(encoder[LEFT]));
   DEBUG_SERIAL.println("Encoder(right) : " + String(encoder[RIGHT]));

@@ -998,7 +1002,7 @@
   DEBUG_SERIAL.println("---------------------------------------");
   DEBUG_SERIAL.println("TurtleBot3");
   DEBUG_SERIAL.println("---------------------------------------");
-  DEBUG_SERIAL.println("Odometry : ");
+  DEBUG_SERIAL.println("Odometry : ");
   DEBUG_SERIAL.print("         x : "); DEBUG_SERIAL.println(odom_pose[0]);
   DEBUG_SERIAL.print("         y : "); DEBUG_SERIAL.println(odom_pose[1]);
   DEBUG_SERIAL.print("     theta : "); DEBUG_SERIAL.println(odom_pose[2]);