esp01 to esp12

esp01 to esp12

--- _56-gopro-control/a-93-config-on-rtc-with-external-poweron-signal-autoexec/a-93-config-on-rtc-with-external-poweron-signal-autoexec.ino
+++ _56-gopro-control/a-93-config-on-rtc-with-external-poweron-signal-autoexec/a-93-config-on-rtc-with-external-poweron-signal-autoexec.ino
@@ -1,4 +1,4 @@
-// esp-01 4M / 3M flash / esp-solar / 160MHz
+// esp12 4M / 3M flash / esp-solar / 160MHz
 /*
   gopro wifi : https://github.com/KonradIT/goprowifihack
   twitter api : https://dev.twitter.com/rest/reference/post/media/upload
@@ -233,7 +233,7 @@
   bool ok = system_rtc_mem_read(65, &rtc_boot_mode, sizeof(rtc_boot_mode));
   uint32_t hash = calc_hash(rtc_boot_mode);
   if (!ok || rtc_boot_mode.hash != hash) {
-    rtc_boot_mode.gopro_mode     = true;
+    rtc_boot_mode.gopro_mode     = false;
     rtc_boot_mode.formatspiffs   = false;
     rtc_boot_mode.Temperature    = 0;
     rtc_boot_mode.gopro_size     = 0;


Tweaked debouncing times.

Tweaked debouncing times.

--- project/project.ino
+++ project/project.ino
@@ -65,8 +65,8 @@
 // Pin P2 is pin 2 as digital and pin 1 as analog. Debounce time is 100 milliseconds.
 static IoButton button(2, 1, 100);

-// Enable input pin. Long 1000ms debouncing.
-static InPin enable_input(0, 1000);
+// Enable input pin. Debounce time is 250ms.
+static InPin enable_input(0, 250);

 // The current led pattern. The actual led value is computed by ledPattern() based
 // on time_in_state and this pattern; The led pattern define the led on/off states


GPS timeout parametrized

GPS timeout parametrized

--- arduino/sim808/gps.ino
+++ arduino/sim808/gps.ino
@@ -1,15 +1,20 @@
+// number and timeout for GPS to fix (lock)
+#define MAX_GPS_TRIES 30
+#define GPS_RETRY_DELAY 1000
+
 void getGPSinfo(){
   // full procedure for turning gps on, getting data and turning it off again
   debugPrint(F("GPS on "));
   if(!checkResp(F("at+cgnspwr=1"),20,1000,ok))gpsdata="err";
   debugPrint(F("GPS INFO "));
   String ret="0";
-  // TODO: introduce safety timeout here, or GPS may get into endless loop
+  // safety count prevents GPS getting into endless loop when unreliable
+  int gpstries = 0;
   do{
+    delay(GPS_RETRY_DELAY);
     gpsdata=parseinfo();
     debugPrintln("bot "+ret);
-    delay(500);
-  }while(gpsdata[2]!='1');
+  }while(gpsdata[2]!='1' && ++gpstries < MAX_GPS_TRIES);
   debugPrint(F("GPS off "));
   if(!checkResp(F("at+cgnspwr=1"),20,1000,ok))debugPrintln(F("GPS PWR ERR"));
 }


Fix bug to call spinOnce. Changes to detect imu/mag init failures.

--- Arduino/victoria_teensy_circuit_test_ros_node/victoria_teensy_circuit_test_ros_node.ino
+++ Arduino/victoria_teensy_circuit_test_ros_node/victoria_teensy_circuit_test_ros_node.ino
@@ -27,6 +27,8 @@
 // IMU and Magnetometer
 LSM6 imu;
 LIS3MDL mag;
+bool imu_err = false;
+bool mag_err = false;

 char debug_str[80];

@@ -45,17 +47,18 @@
   Wire.setDefaultTimeout(200000); // 200ms

   // Setup IMU and magenetometer that use I2C
-  if (!imu.init())
-  {
-    Serial.println("Failed to detect and initialize IMU!");
-    while (1);
+  if (imu.init()) {
+    imu.enableDefault();
+    // TODO: set timeout?
+  } else {
+    imu_err = true;
   }
-  imu.enableDefault();

-  if (!mag.init())
-  {
-    Serial.println("Failed to detect and initialize magnetometer!");
-    while (1);
+  if (mag.init()) {
+    mag.enableDefault();
+    // TODO: set timeout?
+  } else {
+    mag_err = true;
   }

   mag.enableDefault();
@@ -87,25 +90,36 @@
   ros_encoder_pub.publish(&ros_debug_msg);

   // Read the IMU
-  long i2c_start_time = millis();
-  imu.read();
-  long i2c_duration = millis() - i2c_start_time;
-
-  snprintf(debug_str, sizeof(debug_str), "A: %6d %6d %6d    G: %6d %6d %6d   I2C Duration: %ld",
-    imu.a.x, imu.a.y, imu.a.z,
-    imu.g.x, imu.g.y, imu.g.z,
-    i2c_duration);
-  ros_debug_msg.data = debug_str;
+  if (imu_err) {
+    ros_debug_msg.data = "IMU failure!";
+  } else {
+    long i2c_start_time = millis();
+    imu.read();
+    long i2c_duration = millis() - i2c_start_time;
+
+    snprintf(debug_str, sizeof(debug_str), "A: %6d %6d %6d    G: %6d %6d %6d   I2C Duration: %ld",
+      imu.a.x, imu.a.y, imu.a.z,
+      imu.g.x, imu.g.y, imu.g.z,
+      i2c_duration);
+    ros_debug_msg.data = debug_str;
+  }
   ros_imu_pub.publish(&ros_debug_msg);

   // Read the Magnetometer
-  i2c_start_time = millis();
-  mag.read();
-  i2c_duration = millis() - i2c_start_time;
+  if (mag_err) {
+    ros_debug_msg.data = "Magnetometer failure!";
+  } else {
+    long i2c_start_time = millis();
+    mag.read();
+    long i2c_duration = millis() - i2c_start_time;
+
+    snprintf(debug_str, sizeof(debug_str), "M: %6d %6d %6d   I2C Duration: %ld",
+      mag.m.x, mag.m.y, mag.m.z,
+      i2c_duration);
+    ros_debug_msg.data = debug_str;
+  }
+  ros_magnetometer_pub.publish(&ros_debug_msg);

-  snprintf(debug_str, sizeof(debug_str), "M: %6d %6d %6d   I2C Duration: %ld",
-    mag.m.x, mag.m.y, mag.m.z,
-    i2c_duration);
-  ros_debug_msg.data = debug_str;
-  ros_magnetometer_pub.publish(&ros_debug_msg);
+  // Send all the ROS messages
+  ros_nh.spinOnce();
 }


enfait j'ai remis les ternaires puisque je suis un cancer

--- Margoulineur2000.ino
+++ Margoulineur2000.ino
@@ -247,23 +247,39 @@
           // Starting of a new sector ... try to to authenticate
           Serial.print("------------------------Sector ");Serial.print(nfc_handler.currentblock/4, DEC);Serial.println("-------------------------");
             Serial.print("keys used:");
-          if (dormitory == 3)
+
+          if (nfc_handler.currentblock >= 5 * 4 && nfc_handler.currentblock <= 6 * 4)
           {
-            if (nfc_handler.currentblock >= 5 * 4 && nfc_handler.currentblock <= 6 * 4)
-            {
-              displayKeyDebug(nfc_handler.KeyA_D3_part2);
-              nfc.mifareclassic_AuthenticateBlock (nfc_handler.uid, nfc_handler.uidLength, nfc_handler.currentblock, nfc_handler.keyNumber, nfc_handler.KeyA_D3_part2);
-            }
-            else
-            {
-               displayKeyDebug(nfc_handler.KeyA_D3_part1);
-               nfc.mifareclassic_AuthenticateBlock (nfc_handler.uid, nfc_handler.uidLength, nfc_handler.currentblock, nfc_handler.keyNumber, nfc_handler.KeyA_D3_part1);
-            }
+            //Key display debug
+            dormitory == 3 ? displayKeyDebug(nfc_handler.KeyA_D3_part2) : displayKeyDebug(nfc_handler.KeyA_D4);
+            nfc_handler.success = dormitory == 3 ?
+              nfc.mifareclassic_AuthenticateBlock (nfc_handler.uid,
+                nfc_handler.uidLength,
+                nfc_handler.currentblock,
+                nfc_handler.keyNumber,
+                nfc_handler.KeyA_D3_part2) :
+              nfc.mifareclassic_AuthenticateBlock (nfc_handler.uid,
+                nfc_handler.uidLength,
+                nfc_handler.currentblock,
+                nfc_handler.keyNumber,
+                nfc_handler.KeyA_D4);
+
           }
-          else if (dormitory == 4)
+          else
           {
-            if (nfc_handler.success = dormitory == 4)
-              nfc.mifareclassic_AuthenticateBlock (nfc_handler.uid, nfc_handler.uidLength, nfc_handler.currentblock, nfc_handler.keyNumber, nfc_handler.KeyA_D4);
+            //Key display debug
+            dormitory == 3 ? displayKeyDebug(nfc_handler.KeyA_D3_part1) : displayKeyDebug(nfc_handler.KeyA_D4);
+            nfc_handler.success = dormitory == 3 ?
+              nfc.mifareclassic_AuthenticateBlock (nfc_handler.uid,
+                nfc_handler.uidLength,
+                nfc_handler.currentblock,
+                nfc_handler.keyNumber,
+                nfc_handler.KeyA_D3_part1) :
+              nfc.mifareclassic_AuthenticateBlock (nfc_handler.uid,
+                nfc_handler.uidLength,
+                nfc_handler.currentblock,
+                nfc_handler.keyNumber,
+                nfc_handler.KeyA_D4);
           }
           Serial.println("");
           if (nfc_handler.success)


Updated for compatibility with Mini

Updated for compatibility with Mini

- defined baud rate using macro
- included #ifdef condition to set clock rate for mini to support 8MHz
cock rate on 3.3V mini

--- sensors/sensors.ino
+++ sensors/sensors.ino
@@ -63,6 +63,10 @@
 #include <OneWire.h>
 #include <DallasTemperature.h>

+// GENERAL DEFITIONS
+// is it an arduino mini? - used to set clock rates
+#define ARDUINO_MINI  1
+#define BAUD_RATE 9600

 // Define pins for sensors
 // Digital
@@ -92,7 +96,11 @@
 // begin setup
 void setup() {
   // general setup
-  Serial.begin(9600);
+  #ifdef ARDUINO_MINI   // is it an arduino mini (it has half the clock rate of the nano)
+  Serial.begin(BAUD_RATE*2);
+  #else
+  Serial.begin(BAUD_RATE);
+  #endif

   // ISL29125 RGB PHOTOSENSOR
   // Initialize the ISL29125 with simple configuration so it starts sampling


Better contrast control, H;, BR; & BS; commands

--- DigitalVFO.ino
+++ DigitalVFO.ino
@@ -15,13 +15,17 @@
 #include <LiquidCrystal.h>
 #include <EEPROM.h>

-// uncommenting this next line turns on some debug
-//#define DEBUG   1
+// debug levels:
+//     0 - no debug
+//     1 - some debug
+//     2 - more debug
+//     etc
+#define DEBUG   1

 // Digital VFO program name & version
 const char *ProgramName = "DigitalVFO";
 const char *Version = "1.1";
-const char *MinorVersion = ".2";
+const char *MinorVersion = ".3";
 const char *Callsign = "vk4fawr";

 // display constants - below is for ubiquitous small HD44780 16x2 display
@@ -274,13 +278,17 @@
 // Show the credits on the LCD.
 //----------------------------------------

-void show_credits(void)
+void show_credits(bool minor)
 {
   lcd.clear();
   lcd.setCursor(0, 0);
   lcd.print(ProgramName);
   lcd.print(" ");
   lcd.print(Version);
+  if (minor)
+  {
+    lcd.print(MinorVersion);
+  }
   lcd.setCursor(NumCols-strlen(Callsign), 1);
   lcd.print(Callsign);
 }
@@ -291,18 +299,7 @@

 void banner(void)
 {
-#if DEBUG
-  Serial.printf(F("\n"));
-  Serial.printf(F("*************************************************\n"));
-  Serial.printf(F("*           %s %s%s (%s)          *\n"),
-                ProgramName, Version, MinorVersion, Callsign);
-  Serial.printf(F("*************************************************\n"));
-  Serial.printf(F("\n"));
-#else
-  Serial.printf(F("%s %s%s (%s)\n"), ProgramName, Version, MinorVersion, Callsign);
-#endif
-
-  show_credits();
+  show_credits(false);
   delay(900);    // wait a bit

   // do a fade out, clear screen then normal brightness
@@ -454,6 +451,9 @@
 // External command routines.
 //
 // External commands are:
+//     H;           send help text to console
+//     BR;          boot reload software via USB
+//     BS;          boot soft, restart program
 //     ID;          get device identifier string
 //     MSO;         set VFO mode to 'online'
 //     MSS;         set VFO mode to 'standby'
@@ -462,26 +462,72 @@
 //     FG;          get frequency
 //     CSn;         set cursor to index 'n'
 //     CG;          get cursor index
-//     DS+n;        increment frequency digit by 'n'
-//     DS-n;        decrement frequency digit by 'n'
+//     DS+n;        increment display selected digit by 'n'
+//     DS-n;        decrement display selected digit by 'n'
 //##############################################################################

 //----------------------------------------
-// Get the identifire string:
+// Get help:
+//     H;
+//----------------------------------------
+
+const char * xcmd_help(char *answer, char *cmd)
+{
+  strcpy(answer, "H;           send help text to console\n");
+  strcat(answer, "BR;          boot reload software via USB\n");
+  strcat(answer, "BS;          boot soft, restart program\n");
+  strcat(answer, "ID;          get device identifier string\n");
+  strcat(answer, "MO;          set VFO mode to 'online'\n");
+  strcat(answer, "MS;          set VFO mode to 'standby'\n");
+  strcat(answer, "MG;          get VFO mode\n");
+  strcat(answer, "FSnnnnnnnn;  set frequency to 'nnnnnnnn'\n");
+  strcat(answer, "FG;          get frequency\n");
+  strcat(answer, "CSn;         set cursor to index 'n'\n");
+  strcat(answer, "CG;          get cursor index\n");
+  strcat(answer, "DS+n;        increment display selected digit by 'n'\n");
+  strcat(answer, "DS-n;        decrement display selected digit by 'n'");
+  return answer;
+}
+
+//----------------------------------------
+// Boot:
+//     BR;  boot, reload software via USB
+//     BS;  boot soft, restart program
+//----------------------------------------
+
+const char * xcmd_boot(char *answer, char *cmd)
+{
+  if (strlen(cmd) != 3)
+    return "ERROR";
+
+  switch (cmd[1])
+  {
+    case 'R':
+      // hard reboot
+      return "Would do hard reboot";
+    case 'S':
+      // soft reboot
+      return "Would do soft reboot";
+  }
+
+  return "ERROR";
+}
+
+//----------------------------------------
+// Get the identifier string:
 //     ID;
 //----------------------------------------

-const char * xcmd_id(char *cmd)
+const char * xcmd_id(char *answer, char *cmd)
 {
   // if not legal, complain
   if (strcmp(cmd, "ID;"))
     return "ERROR";

   // generate ID string and return
-  strcpy(FreqBuffer, ProgramName);
-  strcat(FreqBuffer, " ");
-  strcat(FreqBuffer, Version);
-  return FreqBuffer;
+  strcpy(answer, Version);
+  strcat(answer, MinorVersion);
+  return answer;
 }

 //----------------------------------------
@@ -491,36 +537,30 @@
 //     MG;
 //----------------------------------------

-const char * xcmd_mode(char *cmd)
-{
+const char * xcmd_mode(char *answer, char *cmd)
+{
+  if (strlen(cmd) != 3)
+    return "ERROR";
+
   switch (cmd[1])
   {
     case 'G':
       // return VFO status
-      if (strlen(cmd) != 3)
-        return "ERROR";
       if (VfoMode == vfo_Standby)
         return "STANDBY";
       if (VfoMode == vfo_Online)
         return "ONLINE";
       break;
+    case 'O':
+      // set ONLINE mode
+      VfoMode = vfo_Online;
+      vfo_display_mode();
+      return "OK";
     case 'S':
-      if (strlen(cmd) != 4)
-        return "ERROR";
-      switch (cmd[2])
-      {
-        case 'O':
-          // set ONLINE mode
-          VfoMode = vfo_Online;
-          vfo_display_mode();
-          return "OK";
-        case 'S':
-          // set 'standby' mode
-          VfoMode = vfo_Standby;
-          vfo_display_mode();
-          return "OK";
-      }
-      break;
+      // set 'standby' mode
+      VfoMode = vfo_Standby;
+      vfo_display_mode();
+      return "OK";
   }

   return "ERROR";
@@ -532,7 +572,7 @@
 //     FG;          get frequency
 //----------------------------------------

-const char * xcmd_freq(char *cmd)
+const char * xcmd_freq(char *answer, char *cmd)
 {
   switch (cmd[1])
   {
@@ -575,7 +615,7 @@
 //     CG;   get cursor index
 //----------------------------------------

-const char * xcmd_cursor(char *cmd)
+const char * xcmd_cursor(char *answer, char *cmd)
 {
   switch (cmd[1])
   {
@@ -583,9 +623,9 @@
       // return cursor index
       if (strlen(cmd) == 3)
       {
-        FreqBuffer[0] = VfoSelectDigit + '0';
-        FreqBuffer[1] = '\0';
-        return FreqBuffer;
+        answer[0] = VfoSelectDigit + '0';
+        answer[1] = '\0';
+        return answer;
       }
       break;
     case 'S':
@@ -614,7 +654,7 @@
 //     DS-n;        decrement frequency digit by 'n'
 //----------------------------------------

-const char * xcmd_digit(char *cmd)
+const char * xcmd_digit(char *answer, char *cmd)
 {
   switch (cmd[1])
   {
@@ -668,7 +708,7 @@
 // 'cmd' is '\0' terminated.
 // Returns the command response string.
 //----------------------------------------
-const char * do_external_cmd(char *cmd, int index)
+const char * do_external_cmd(char *answer, char *cmd, int index)
 {
   char end_char = cmd[index];

@@ -678,25 +718,33 @@
   // if command too long it's illegal
   if (end_char != COMMAND_END_CHAR)
   {
-    return (char *) "ERROR";
-  }
+    return (char *) "TOO LONG";
+  }
+
+#if (DEBUG > 1)
+  Serial.printf(F("do_external_cmd: cmd='%s'\n"), cmd);
+#endif

   // process the command
   switch (cmd[0])
   {
+    case 'B':
+      return xcmd_boot(answer, cmd);
     case 'C':
-      return xcmd_cursor(cmd);
+      return xcmd_cursor(answer, cmd);
     case 'D':
-      return xcmd_digit(cmd);
+      return xcmd_digit(answer, cmd);
     case 'F':
-      return xcmd_freq(cmd);
+      return xcmd_freq(answer, cmd);
+    case 'H':
+      return xcmd_help(answer, cmd);
     case 'I':
-      return xcmd_id(cmd);
+      return xcmd_id(answer, cmd);
     case 'M':
-      return xcmd_mode(cmd);
-  }
-
-  return (char *) "ERROR";
+      return xcmd_mode(answer, cmd);
+  }
+
+  return xcmd_help(answer, cmd);
 }

 //##############################################################################
@@ -722,7 +770,7 @@
   struct MenuItem **items;    // array of pointers to MenuItem data
 };

-#ifdef DEBUG
+#if (DEBUG > 0)
 //----------------------------------------
 // dump a MenuItem to the console
 // only called from dump_menu()
@@ -824,38 +872,38 @@
     {
       // get next event and handle it
       byte event = event_pop();
-#ifdef DEBUG
+#if (DEBUG > 0)
       Serial.printf(F("menu_show loop: event=%s\n"), event2display(event));
 #endif

       switch (event)
       {
         case vfo_RLeft:
-#ifdef DEBUG
+#if (DEBUG > 0)
           Serial.printf(F("menu_show: vfo_RLeft\n"));
 #endif
           if (--item_num < 0)
             item_num = 0;
           break;
         case vfo_RRight:
-#ifdef DEBUG
+#if (DEBUG > 0)
           Serial.printf(F("menu_show: vfo_RRight\n"));
 #endif
           if (++item_num >= menu->num_items)
             item_num = menu->num_items - 1;
           break;
         case vfo_DnRLeft:
-#ifdef DEBUG
+#if (DEBUG > 0)
           Serial.printf(F("menu_show: vfo_DnRLeft (ignored)\n"));
 #endif
           break;
         case vfo_DnRRight:
-#ifdef DEBUG
+#if (DEBUG > 0)
           Serial.printf(F("menu_show: vfo_DnRRight (ignored)\n"));
 #endif
           break;
         case vfo_Click:
-#ifdef DEBUG
+#if (DEBUG > 0)
           Serial.printf(F("menu_show: vfo_Click\n"));
 #endif
           if (menu->items[item_num]->action != NULL)
@@ -870,18 +918,18 @@
             menu_show(menu->items[item_num]->menu, 0);
           }
           menu_draw(menu);    // redraw the menu header, item redrawn below
-#ifdef DEBUG
+#if (DEBUG > 0)
           Serial.printf(F("menu_show: end of vfo_Click handling\n"));
 #endif
           break;
         case vfo_HoldClick:
-#ifdef DEBUG
+#if (DEBUG > 0)
           Serial.printf(F("menu_show: vfo_HoldClick, exit menu\n"));
 #endif
           event_flush();
           return;             // back to the parent menu or main screen
         default:
-#ifdef DEBUG
+#if (DEBUG > 0)
           Serial.printf(F("menu_show: unrecognized event %d\n"), event);
 #endif
           break;
@@ -901,11 +949,11 @@
 void display_flash(void)
 {
   lcd.noDisplay();
-  delay(100);
+  delay(150);
   lcd.display();
-  delay(100);
+  delay(150);
   lcd.noDisplay();
-  delay(100);
+  delay(150);
   lcd.display();
 }

@@ -934,7 +982,7 @@

 void event_push(VFOEvent event)
 {
-#ifdef DEBUG
+#if (DEBUG > 0)
   Serial.printf(F("event_push: pushing %s\n"), event2display(event));
 #endif

@@ -981,6 +1029,10 @@
     queue_aft = 0;

   interrupts();
+
+#if (DEBUG > 0)
+  Serial.printf(F("event_push: popping %s\n"), event2display(event));
+#endif

   return event;
 }
@@ -1133,7 +1185,7 @@
   bool lead_zero = true;
   char prefix = '+';

-#ifdef DEBUG
+#if (DEBUG > 0)
   Serial.printf(F("display_sel_offset: value=%d, sel_col=%d, num_digits=%d, col=%d, row=%d\n"),
                 value, sel_col, num_digits, col, row);
 #endif
@@ -1257,13 +1309,13 @@
 {
   // sample the pin value
   re_down = digitalRead(re_pinPush);
-#ifdef DEBUG
+#if (DEBUG > 1)
     Serial.printf(F("pinPush_isr: re_down=0x%02X\n"), re_down);
 #endif

   if (re_down)
   {
-#ifdef DEBUG
+#if (DEBUG > 1)
     Serial.printf(F("pinPush_isr: button DOWN\n"));
 #endif

@@ -1273,7 +1325,7 @@
   }
   else
   {
-#ifdef DEBUG
+#if (DEBUG > 1)
     Serial.printf(F("pinPush_isr: button UP\n"));
 #endif

@@ -1329,7 +1381,7 @@
   byte pin_A = digitalRead(re_pinA);
   byte pin_B = digitalRead(re_pinB);

-#ifdef DEBUG
+#if (DEBUG > 1)
     Serial.printf(F("pinA_isr: pin_A=0x%02X, pin_B=0x%02X\n"), pin_A, pin_B);
 #endif

@@ -1366,7 +1418,7 @@
   byte pin_A = digitalRead(re_pinA);
   byte pin_B = digitalRead(re_pinB);

-#ifdef DEBUG
+#if (DEBUG > 1)
     Serial.printf(F("pinB_isr: pin_A=0x%02X, pin_B=0x%02X\n"), pin_A, pin_B);
 #endif

@@ -1511,7 +1563,7 @@
 // Print all EEPROM saved data to console.
 //----------------------------------------

-#ifdef DEBUG
+#if (DEBUG > 0)
 void dump_eeprom(void)
 {
   Frequency freq;
@@ -1601,7 +1653,7 @@
   // as in datasheet page 12 - modified to include calibration offset
   ULONG data = (frequency * 4294967296) / (180000000 - VfoClockOffset);

-#ifdef DEBUG
+#if (DEBUG > 1)
   Serial.printf(F("dds_update: frequency=%ld, VfoClockOffset=%d, data=%ld\n"),
                 frequency, VfoClockOffset, data);
 #endif
@@ -1622,7 +1674,7 @@

 void dds_standby(void)
 {
-#ifdef DEBUG
+#if (DEBUG > 0)
   Serial.printf(F("DDS into standby mode.\n"));
 #endif
   dds_update(0L);
@@ -1634,7 +1686,7 @@

 void dds_online(void)
 {
-#ifdef DEBUG
+#if (DEBUG > 0)
   Serial.printf(F("DDS into online mode, frequency=%dHz.\n"), VfoFrequency);
 #endif
   dds_update(VfoFrequency);
@@ -1672,8 +1724,8 @@

 void setup(void)
 {
-#ifdef DEBUG
-  Serial.printf(F("DEBUG is defined\n"));
+#if (DEBUG > 0)
+  Serial.printf(F("DEBUG is defined as %d\n"), DEBUG);
 #endif

   // initialize the BlankRow global to a blank string length of a display row
@@ -1744,11 +1796,24 @@
     delay(500);
   }

+#if (DEBUG > 0)
+  Serial.printf(F("\n"));
+  Serial.printf(F("*************************************************\n"));
+  Serial.printf(F("*           %s %s%s (%s)          *\n"),
+                ProgramName, Version, MinorVersion, Callsign);
+  Serial.printf(F("*************************************************\n"));
+  Serial.printf(F("\n"));
+#else
+  Serial.printf(F("%s %s%s (%s)\n"), ProgramName, Version, MinorVersion, Callsign);
+#endif
+
+  Serial.printf(F("Preparing ... \n"));
+
   // show program name and version number
   banner();

   // dump EEPROM values
-#ifdef DEBUG
+#if (DEBUG > 0)
   dump_eeprom();
 #endif

@@ -1757,6 +1822,7 @@

   // show the main screen and continue in loop()
   show_main_screen();
+  Serial.printf(F("Ready\n"));
 }

 //----------------------------------------
@@ -2030,7 +2096,7 @@
   event_flush();

   // show the credits
-  show_credits();
+  show_credits(true);

   // handle events in our own little event loop
   // we want to wait until some sort of click
@@ -2118,7 +2184,7 @@
       }

       // adjust display brightness so we can see the results
-      LcdBrightness = (index * 16) - 16;
+      LcdBrightness = index * 16;
       analogWrite(mc_Brightness, LcdBrightness);

       // show brightness value in row 1
@@ -2143,7 +2209,8 @@
   int old_contrast = LcdContrast;

   // convert contrast value to a display value in [0, 15]
-  int index = LcdContrast / 8;
+//  int index = LcdContrast / 8;
+  int index = LcdContrast / 10;

   if (index > 15)   // ensure in range
     index = 15;
@@ -2196,7 +2263,8 @@
       }

       // adjust display contrast so we can see the results
-      LcdContrast = index * 8;
+//      LcdContrast = index * 8;
+      LcdContrast = index * 10;
       analogWrite(mc_Contrast, LcdContrast);

       // show brightness value in row 1
@@ -2240,7 +2308,7 @@

 void holdclick_action(struct Menu *menu, int item_num)
 {
-#ifdef DEBUG
+#if (DEBUG > 1)
   Serial.printf(F("holdclick_action: entered\n"));
 #endif

@@ -2271,7 +2339,7 @@
           holdtime -= hold_step;
           if (holdtime < MinHoldClickTime)
             holdtime = MinHoldClickTime;
-#ifdef DEBUG
+#if (DEBUG > 1)
           Serial.printf(F("holdclick_action: vfo_RLeft, after holdtime=%d\n"), holdtime);
 #endif
           break;
@@ -2279,7 +2347,7 @@
           holdtime += hold_step;
           if (holdtime > MaxHoldClickTime)
             holdtime = MaxHoldClickTime;
-#ifdef DEBUG
+#if (DEBUG > 1)
           Serial.printf(F("holdclick_action: vfo_RRight, after holdtime=%d\n"), holdtime);
 #endif
           break;
@@ -2312,7 +2380,7 @@

 void doubleclick_action(struct Menu *menu, int item_num)
 {
-#ifdef DEBUG
+#if (DEBUG > 1)
   Serial.printf(F("doubleclick_action: entered, ReDClickTime=%dmsec\n"), ReDClickTime);
 #endif

@@ -2343,7 +2411,7 @@
           dctime -= dclick_step;
           if (dctime < MinDClickTime)
             dctime = MinDClickTime;
-#ifdef DEBUG
+#if (DEBUG > 1)
           Serial.printf(F("doubleclick_action: vfo_RLeft, after dctime=%d\n"), dctime);
 #endif
           break;
@@ -2351,7 +2419,7 @@
           dctime += dclick_step;
           if (dctime > MaxDClickTime)
             dctime = MaxDClickTime;
-#ifdef DEBUG
+#if (DEBUG > 1)
           Serial.printf(F("doubleclick_action: vfo_RRight, after dctime=%d\n"), dctime);
 #endif
           break;
@@ -2387,7 +2455,7 @@

 void calibrate_action(struct Menu *menu, int item_num)
 {
-#ifdef DEBUG
+#if (DEBUG > 1)
   Serial.printf(F("calibrate_action: entered, VfoClockOffset=%dmsec\n"), VfoClockOffset);
 #endif

@@ -2426,7 +2494,7 @@
           VfoClockOffset -= offset2bump[seldig];
           if (VfoClockOffset < MinClockOffset)
             VfoClockOffset = MinClockOffset;
-#ifdef DEBUG
+#if (DEBUG > 1)
           Serial.printf(F("calibrate_action: vfo_RLeft, after VfoClockOffset=%d\n"),
                         VfoClockOffset);
 #endif
@@ -2435,31 +2503,31 @@
           VfoClockOffset += offset2bump[seldig];
           if (VfoClockOffset > MaxClockOffset)
             VfoClockOffset = MaxClockOffset;
-#ifdef DEBUG
+#if (DEBUG > 1)
           Serial.printf(F("calibrate_action: vfo_RRight, after VfoClockOffset=%d\n"),
                         VfoClockOffset);
 #endif
           break;
         case vfo_DnRLeft:
-#ifdef DEBUG
+#if (DEBUG > 1)
           Serial.printf(F("calibrate_action: vfo_DnRLeft\n"));
 #endif
           ++seldig;
           if (seldig >= MaxOffsetDigits)
             seldig = MaxOffsetDigits - 1;
-#ifdef DEBUG
+#if (DEBUG > 1)
           Serial.printf(F("calibrate_action: vfo_DnRLeft, after seldig=%d\n"),
                         seldig);
 #endif
           break;
         case vfo_DnRRight:
-#ifdef DEBUG
+#if (DEBUG > 1)
           Serial.printf(F("calibrate_action: vfo_DnRLeft\n"));
 #endif
           --seldig;
           if (seldig < 0)
             seldig = 0;
-#ifdef DEBUG
+#if (DEBUG > 1)
           Serial.printf(F("calibrate_action: vfo_DnRRight, after seldig=%d\n"),
                         seldig);
 #endif
@@ -2578,8 +2646,10 @@

     if (ch == COMMAND_END_CHAR)   // if end of command, execute it
     {
+      char answer[512];
+
       CommandBuffer[CommandIndex] = '\0';
-      Serial.printf(F("%s;\n"), do_external_cmd(CommandBuffer, CommandIndex-1));
+      Serial.printf(F("%s\n"), do_external_cmd(answer, CommandBuffer, CommandIndex-1));
       CommandIndex = 0;
     }
   }


Made battery stuff optional compile

Made battery stuff optional compile

--- DigitalVFO.ino
+++ DigitalVFO.ino
@@ -15,6 +15,12 @@
 #include <LiquidCrystal.h>
 #include <EEPROM.h>

+//-----
+// Conditional compile flags
+//-----
+
+#define INC_BATTERY   1
+
 // debug bit masks:
 #define DEBUG_DDS     (1 << 0)
 #define DEBUG_FREQ    (1 << 1)
@@ -24,7 +30,9 @@
 #define DEBUG_RE      (1 << 5)
 #define DEBUG_INT     (1 << 6)
 #define DEBUG_DISP    (1 << 7)
+#if INC_BATTERY
 #define DEBUG_BATT    (1 << 8)
+#endif

 #define DEBUG         (DEBUG_BATT)
 //#define DEBUG         0
@@ -333,6 +341,10 @@
     Serial.println("    DEBUG_INT\tbit is set");
   if (debug & DEBUG_DISP)
     Serial.println("    DEBUG_DISP\tbit is set");
+#if INC_BATTERY
+  if (debug & DEBUG_BATT)
+    Serial.println("    DEBUG_BATT\tbit is set");
+#endif
 }

 //----------------------------------------
@@ -2979,11 +2991,12 @@
 // Standard Arduino loop() function.
 //----------------------------------------

-const float MaxVoltage = 8.0;   // battery voltage for "100% full"
-const float MinVoltage = 7.0;   // battery voltage for "0% full"
+const float MaxVoltage = 8.2;   // battery voltage for "100% full"
+const float MinVoltage = 6.4;   // battery voltage for "0% full"

 void loop(void)
 {
+#if INC_BATTERY
   // measure voltage every second
   // we will get a value of 1023 for 3.3 volts
   static UINT last_volts_time = -VoltageDelay;    // millis() value last time we measured
@@ -3012,7 +3025,8 @@
     }
     display_battery();
   }
-
+#endif
+
   // gather any commands from controller
   while (Serial.available())
   {
@@ -3086,7 +3100,9 @@

     // update the display
     display_sel_value(VfoFrequency, VfoSelectDigit, NumFreqChars, NumCols - NumFreqChars - 2, 0);
+#if INC_BATTERY
     display_battery();
+#endif

     // if online, update DDS-60 and write changes to EEPROM
 #if (DEBUG & DEBUG_FREQ)


Timeout for binary mode implemented

Timeout for binary mode implemented

--- PaperTapePuncher.ino
+++ PaperTapePuncher.ino
@@ -17,6 +17,10 @@
 #define PinTransportMotor 11
 #define PinStepSensor 12

+#define highTime 2
+#define lowTime 18
+#define waitTime 5000
+
 int pins[] = {PinBit0, PinBit1, PinBit2, PinBit3, PinBit4, PinBit5, PinBit6, PinBit7};

 enum writeMode {error, ascii, binary, hex, dec, baudot, human};
@@ -30,8 +34,6 @@

 unsigned long lastTime = 0;
 unsigned long now = 0;
-unsigned long highTime = 2;
-unsigned long lowTime = 18;
 bool isHigh = false;
 int value = 0;
 byte character = 0;
@@ -89,7 +91,7 @@
       case 'h':
       case 'H':
         mode = human;
-        Serial.println("Human readable mode - only ASCII allowed. Escape to exit");
+        Serial.println("Human readable mode - only ASCII allowed. Enter a char over 127 to exit.");
         break;
       case 'x':
       case 'X':
@@ -99,12 +101,13 @@
       case 'd':
       case 'D':
         mode = dec;
-        Serial.println("Decimal mode: Enter 3-digit numbers. Invalid input to quit");
+        Serial.println("Decimal mode: Enter 3-digit numbers. Invalid input to exit");
         break;
       case 'b':
       case 'B':
         mode = binary;
-        Serial.println("Binary mode- Reset to exit.");
+        Serial.print("Binary mode - Wait for timeout to exit.");
+        lastTime = millis();
         break;
       case 'a':
       case 'A':
@@ -256,6 +259,11 @@
       isHigh = true;
       lastTime = now;
     }
+    else if(mode == binary && now > (lastTime + waitTime))
+    {
+      mode = error;
+      Serial.println("Timeout");
+    }
   }
 }


Removed unused serial begin

Removed unused serial begin

--- nanowriter.ino
+++ nanowriter.ino
@@ -55,7 +55,6 @@
   PORTB |= B11111111;

   Keyboard.begin();
-  Serial.begin(9600);
 }

 char readButtons() {
@@ -84,7 +83,7 @@
   if (input & 1) {
     switch(input){
       case B000001:
-        toggleKey(KEY_LEFT_SHIFT);ute
+        toggleKey(KEY_LEFT_SHIFT);
         return 0;
       case B111101:
         resetState();


Sensor 2 toevoegen

Sensor 2 toevoegen

De ledstrip gaat nu pas aan als de trein bij sensor 2 aangekomen is

--- LightTrain.ino
+++ LightTrain.ino
@@ -47,18 +47,22 @@

 void loop() {
   int sensor1 = analogRead(A0);
+  int sensor2 = analogRead(A1);
   int aantal_leds;
-  boolean trein_aangekomen = false;
+  boolean trein_komt = false;
   int ms = 0;         // Aantal milliseconden dat de trein erover doet om sensor 1 te passeren.

   while (sensor1 < SENSOR_THRESHOLD) { // Sensor is laag, de trein komt langs
     ms++;
     delay(1);
-    trein_aangekomen = true;  // Er is een trein aangekomen
     sensor1 = analogRead(A0); // Herhaal deze loop totdat de waarde waar hoog is, dus totdat de trein voorbij is
+    trein_komt = true;  // Er komt een trein aan
   }
   aantal_leds = ms / delayval; // Het aantal ledjes dat de trein breedt is = hoelang de trein overover doet gedeeld door hoelang een ledje duurt
-  if (trein_aangekomen) {          // Als er een trein langsgekomen is doe het volgende:
+  if (trein_komt) {          // Als er een trein aankomt is doe het volgende:
+    while (sensor2 > SENSOR_THRESHOLD) { // Wacht totdat de trein bij het begin van de ledstrip is
+       sensor2 = analogRead(A1);
+    }
     for (int i = 0; i < NUMPIXELS + aantal_leds; i++) { // Beetje ingewikkeld, tel tot het aantal ledjes + het aantal ledjes dat de trein lang is
       int achterste_led = i - aantal_leds;    // Dit doe ik zo om ook het terugschakelen van de ledjes te regelen
       if (achterste_led >= 0) {               // Als de trein helemaal op de ledstrip is moeten er weer lampjes op de rust kleur worden gezet


delay 200

delay 200

--- MTM_MODULE.ino
+++ MTM_MODULE.ino
@@ -12,5 +12,5 @@
     digitalWrite(led, HIGH);  // turn the LED on (HIGH is the voltage level)
     delay(100);               // wait for a second
     digitalWrite(led, LOW);   // turn the LED off by making the voltage LOW
-    delay(100);               // wait for a second
+    delay(200);               // wait for a second
 }


added LCD and basic stats support

added LCD and basic stats support

--- TWANG.ino
+++ TWANG.ino
@@ -1,4 +1,6 @@
 // Required libs
+#include <EEPROM.h>
+#include <LiquidCrystal.h>
 #include "FastLED.h"
 #include "I2Cdev.h"
 #include "MPU6050.h"
@@ -55,6 +57,12 @@
 #define JOYSTICK_DEADZONE        10        // Angle to ignore
 int joystickTilt = 0;                      // Stores the angle of the joystick
 int joystickWobble = 0;                    // Stores the max amount of acceleration (wobble)
+
+// LCD and stats
+LiquidCrystal lcd(52, 53, 50, 51, 48, 49);
+byte stats_playthroughs = 0;
+int stats_besttime = 0;
+long gameStartTime = 0;

 // WOBBLE ATTACK
 #define ATTACK_WIDTH             70         // Width of the wobble attack, world is 1000 wide
@@ -104,6 +112,9 @@
 	//Serial.begin(9600);
 	//while (!Serial);

+	stats_playthroughs = EEPROM.read(0);
+	stats_besttime = EEPROM_readint(1);
+
 	// MPU
 	Wire.begin();
 	accelgyro.initialize();
@@ -112,6 +123,9 @@
 	FastLED.addLeds<LED_TYPE, DATA_PIN, LED_COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
 	FastLED.setBrightness(BRIGHTNESS);
 	FastLED.setDither(1);
+
+	lcd.begin(20, 4);
+	updateStats();

 	// Life LEDs
 	loadLevel();
@@ -284,6 +298,7 @@
 		// Left or right?
 		playerPosition = 200;
 		spawnEnemy(1, 0, 0, 0);
+		gameStartTime = millis();
 		break;
 	case 1:
 		// Slow moving enemy
@@ -439,7 +454,18 @@
 void levelComplete() {
 	stageStartTime = millis();
 	stage = WIN;
-	if (levelNumber == LEVEL_COUNT) stage = COMPLETE;
+	if (levelNumber == LEVEL_COUNT)
+	{
+		stage = COMPLETE;
+		++stats_playthroughs;
+		EEPROM.write(0, stats_playthroughs);
+		int newBest = (int)((millis() - gameStartTime) / 1000);
+		if (newBest > stats_besttime) {
+			stats_besttime = newBest;
+			EEPROM_writeint(1, stats_besttime);
+		}
+	}
+	updateStats();
 	lives = 3; //min(3, lives + 1);
 }

@@ -706,6 +732,29 @@
 			}
 		}
 	}
+}
+
+// ---------------------------------
+// -----------   LCD    ------------
+// ---------------------------------
+
+int EEPROM_readint(long address) {
+	return ((EEPROM.read(address) << 0) & 0xFF) + ((EEPROM.read(address + 1) << 8) & 0xFFFF);
+}
+
+void EEPROM_writeint(long address, int value) {
+	EEPROM.write(address, ((value >> 0) & 0xFF));
+	EEPROM.write(address + 1, ((value >> 8) & 0xFF));
+}
+
+void updateStats() {
+	lcd.setCursor(0, 1);
+	lcd.print("Playthroughs: ");
+	lcd.print(stats_playthroughs);
+
+	lcd.setCursor(0, 2);
+	lcd.print("Best time: ");
+	lcd.print(stats_besttime);
 }

 // ---------------------------------


Fixed a comment

Fixed a comment

--- Wallpaper_Changer/Wallpaper_Changer.ino
+++ Wallpaper_Changer/Wallpaper_Changer.ino
@@ -1,5 +1,5 @@
-//This DigiKeyboard Script downloads and sets a wallpaper through the Windows PowerShell. It has been tested successfully on Windows 10
-//and should probably work with Windows 7/8/8.1 etc.
+//This DigiKeyboard Script downloads and sets a wallpaper through the Windows PowerShell. It has been tested successfully
+//on Windows 10 and should probably work with Windows 7/8/8.1 etc.

 #include "DigiKeyboard.h"
 void setup() {


Fix zero-length blobs; tweak random stuff

--- blume.ino
+++ blume.ino
@@ -842,6 +842,10 @@
         continue;
       }
       for (byte c = RED; c <= BLUE; c++) {
+        if (size[c] == 0) {
+          color[c] = 0;
+          continue;
+        }
         float xDist = distance(x, xPos[c], WIDTH);
         float yDist = distance(y, yPos[c], HEIGHT);
         float dist = sqrt(xDist * xDist + yDist * yDist);
@@ -886,8 +890,8 @@
     rainbow ?
       settings.hue + random8(_size) :
       settings.hue,
-    rainbow ? 255 : 255 - random8(_size) / 2,
-    rainbow ? 255 : 255 - random8(255 - _size));
+    rainbow ? settings.saturation : max(settings.saturation, random8()),
+    rainbow ? 255 - random8(255 - settings.saturation) : 255 - random8(255 - _size));
 }
 void runRandom(bool initialize) {
   if (initialize) {


fixed Firmata update throttle with 12 sensors

--- Sensorizer.ino
+++ Sensorizer.ino
@@ -15,7 +15,7 @@

   // how many ticks it takes before sending a Firmata update.
   // this needs to be throttled because otherwise we overload the Serial buffer and shit freezes.
-  #define FIRMATA_UPDATE_RATE_THROTTLE 10
+  #define FIRMATA_UPDATE_RATE_THROTTLE 20

 // how many ticks it's been since the last Firmata update.
 int firmataThrottleCount = 0;


Updated TODO list

Updated TODO list

--- Synthduino.ino
+++ Synthduino.ino
@@ -1,49 +1,49 @@
-/* Synthduino - the Arduino Synthesizer program
- * v. 0.1
- * Milton Stanley, Milte Technologies
- *
- * REQUIRES the StandardCPlusPlus library for Arduino, found at
- * http://www.github.com/maniacbug/StandardCplusplus
- *
- */
-
-/* TO-DO
- *
- * 1) Convert pitches to format nXX, instead of NOTE_XX
- * 2) Add support for Constant declarations of notes - EIGHTH instead of 8
- * 3) Add enharmonics
- *   ------- 	All these following classes use memory format note->end, where end is an offset from
- *						the overall start time (instead of just duration), so
- 							{A4, 8}, {CS5, 8}, {E5, 8} becomes {A4, 8}, {CS5, 16}, {E5, 24}, converted to millis
- * 4) Build support for Melody class - vector<note>, with timing offsets
- * 5) Build support for Channel class - does the actual signalling to pin
- * 6) Possible add a mixer class, for handling multiple channels
- */
-
-#include "note.h"
-#include "pitches.h"
-
-/* HEADER SECTION
- * Declare your tempo and parts/pins (note parts/pins are recommended in the format below
- * Examples:
- * #define TEMPO = 120 // in bpm (beats per minute) - how many quarter notes per minute
- * #define BASS 12
- * Note bassline[] = { {NOTE_C3, 2}, {NOTE_DS3, 2}, {NOTE_F3, 1} };
- */
-
-#define TEMPO 120   // Tempo in bpm
-#define BASS 12  		// Bass will be output on pin 12
-
-Note bassLine[] = { {NOTE_C3, 2}, {NOTE_DS3, 2}, {NOTE_F3, 1} }; // The actual bass part
-
-// End header Section
-
-void setup(){
-	pinMode(BASS, OUTPUT);
-}
-
-void loop() {
-  for(int i=0; i<3; i++){
-    bassLine[i].play(12);
-  }
+/* Synthduino - the Arduino Synthesizer program
+ * v. 0.1
+ * Milton Stanley, Milte Technologies
+ *
+ * REQUIRES the StandardCPlusPlus library for Arduino, found at
+ * http://www.github.com/maniacbug/StandardCplusplus
+ *
+ */
+
+/* TODO
+ *
+ * 1) [DONE] Convert pitches to format nXX, instead of NOTE_XX
+ * 2) Add support for Constant declarations of notes - EIGHTH instead of 8
+ * 3) [DONE] Add enharmonics
+ *   ------- 	All these following classes use memory format note->end, where end is an offset from
+ *						the overall start time (instead of just duration), so
+ 							{A4, 8}, {CS5, 8}, {E5, 8} becomes {A4, 8}, {CS5, 16}, {E5, 24}, converted to millis
+ * 4) Build support for Melody class - vector<note>, with timing offsets
+ * 5) Build support for Channel class - does the actual signalling to pin
+ * 6) Possible add a mixer class, for handling multiple channels
+ */
+
+#include "note.h"
+#include "pitches.h"
+
+/* HEADER SECTION
+ * Declare your tempo and parts/pins (note parts/pins are recommended in the format below
+ * Examples:
+ * #define TEMPO = 120 // in bpm (beats per minute) - how many quarter notes per minute
+ * #define BASS 12
+ * Note bassline[] = { {NOTE_C3, 2}, {NOTE_DS3, 2}, {NOTE_F3, 1} };
+ */
+
+#define TEMPO 120   // Tempo in bpm
+#define BASS 12  		// Bass will be output on pin 12
+
+Note bassLine[] = { {NOTE_C3, 2}, {NOTE_DS3, 2}, {NOTE_F3, 1} }; // The actual bass part
+
+// End header Section
+
+void setup(){
+	pinMode(BASS, OUTPUT);
+}
+
+void loop() {
+  for(int i=0; i<3; i++){
+    bassLine[i].play(12);
+  }
 }


Update post.ino

Update post.ino

--- examples/post/post.ino
+++ examples/post/post.ino
@@ -23,6 +23,7 @@

   // SoftwareSerial (RX受信ピン番号,TX送信ピン番号)
   //TESP8266 httpClient(2,3);
+
 void setup() {
     // シリアルの通信速度(115.2kbps)
     Serial.begin(115200);


Fixed a typo, thanks to @thalaser.

Fixed a typo, thanks to @thalaser.

--- examples/J_scrolling_menu/J_scrolling_menu.ino
+++ examples/J_scrolling_menu/J_scrolling_menu.ino
@@ -90,10 +90,10 @@

     // Attaching a function to the lines is required for scrolling to work.
     line1.attach_function(1, blankFunction);
-    line1.attach_function(1, blankFunction);
-    line1.attach_function(1, blankFunction);
-    line1.attach_function(1, blankFunction);
-    line1.attach_function(1, blankFunction);
+    line2.attach_function(1, blankFunction);
+    line3.attach_function(1, blankFunction);
+    line4.attach_function(1, blankFunction);
+    line5.attach_function(1, blankFunction);

     // Set the number of lines the display has.
     /*
@@ -117,4 +117,4 @@
         menu.switch_focus();
 		menu.update();
     }
-}+}


Reverted from a test.

Reverted from a test.

--- VISTA.ino
+++ VISTA.ino
@@ -55,21 +55,16 @@
     acce.enableDefault();
     if(acce.last_status) notOkStop();
     else ok();
-
-    Serial.print(" - setting data rate to 1600Hz from 50Hz: ");
-    acce.writeReg(LSM303::CTRL_REG1_A, 0xA7);
+
+    Serial.print(" - setting data rate to 12.5Hz from 50Hz: ");
+    acce.writeReg(LSM303::CTRL_REG1_A, 0x37);
     if(acce.last_status) notOkStop();
     else ok();

-//    Serial.print(" - setting data rate to 12.5Hz from 50Hz: ");
-//    acce.writeReg(LSM303::CTRL_REG1_A, 0x37);
-//    if(acce.last_status) notOkStop();
-//    else ok();
-
-//    Serial.print(" - setting range to +-16g from +-2g: ");
-//    acce.writeReg(LSM303::CTRL_REG2_A, 0x20);
-//    if(acce.last_status) notOkStop();
-//    else ok();
+    Serial.print(" - setting range to +-16g from +-2g: ");
+    acce.writeReg(LSM303::CTRL_REG2_A, 0x20);
+    if(acce.last_status) notOkStop();
+    else ok();

   }else{
     notOkStop();
@@ -101,24 +96,27 @@
     delay(1000);
   }

-  //L3Ginit();
+  L3Ginit();
   LSM303init();
-  //LPSinit();
+  LPSinit();
 }

 void loop() {
-//  Serial.print(pres.pressureToAltitudeMeters(pres.readPressureMillibars(), 1006));
-//  Serial.print("\n");
-
+  Serial.println("Altimeter");
+  Serial.print(pres.pressureToAltitudeMeters(pres.readPressureMillibars(), 1006));
+  Serial.print("\n");
+
+  Serial.println("Accelerometer");
   acce.read();
   Serial.println(acce.a.x);
   Serial.println(acce.a.y);
   Serial.println(acce.a.z);

-//  gyro.read();
-//  Serial.println(gyro.g.x);
-//  Serial.println(gyro.g.y);
-//  Serial.println(gyro.g.z);
+  Serial.println("Gyroscope");
+  gyro.read();
+  Serial.println(gyro.g.x);
+  Serial.println(gyro.g.y);
+  Serial.println(gyro.g.z);

-  delay(1);
+  delay(100);
 }


Use LED_BUILTIN

Use LED_BUILTIN

Modified blink example to use LED_BUILTIN. In this way it works out of the box on each board

--- build/shared/examples/01.Basics/Blink/Blink.ino
+++ build/shared/examples/01.Basics/Blink/Blink.ino
@@ -2,28 +2,31 @@
   Blink
   Turns on an LED on for one second, then off for one second, repeatedly.

-  Most Arduinos have an on-board LED you can control. On the Uno and
-  Leonardo, it is attached to digital pin 13. If you're unsure what
-  pin the on-board LED is connected to on your Arduino model, check
+  Most Arduinos have an on-board LED you can control. On the UNO, MEGA and ZERO
+  it is attached to digital pin 13, on MKR1000 on pin 6.
+  If you're unsure what pin the on-board LED is connected to on your Arduino model, check
   the documentation at http://www.arduino.cc

   This example code is in the public domain.

   modified 8 May 2014
   by Scott Fitzgerald
- */
+
+  modified 2 Sep 2016
+  by Arturo Guadalupi
+*/

 // the setup function runs once when you press reset or power the board
 void setup() {
-  // initialize digital pin 13 as an output.
-  pinMode(13, OUTPUT);
+  // initialize digital pin LED_BUILTIN as an output.
+  pinMode(LED_BUILTIN, OUTPUT);
 }

 // the loop function runs over and over again forever
 void loop() {
-  digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
-  delay(1000);              // wait for a second
-  digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
-  delay(1000);              // wait for a second
+  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
+  delay(1000);                       // wait for a second
+  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
+  delay(1000);                       // wait for a second
 }


Add a voice allocator

Add a voice allocator

--- roto2.ino
+++ roto2.ino
@@ -14,11 +14,51 @@
 #include <SerialFlash.h>

 // GUItool: begin automatically generated code
-AudioSynthWaveformSine   sine1;          //xy=220,60
-AudioOutputI2S           i2s1;           //xy=420,64
-AudioConnection          patchCord1(sine1, 0, i2s1, 0);
-AudioConnection          patchCord2(sine1, 0, i2s1, 1);
-AudioControlSGTL5000     audioShield;
+AudioSynthWaveformSine   sine1;          //xy=339,52
+AudioSynthWaveformSine   sine2;          //xy=339,88
+AudioSynthWaveformSine   sine3;          //xy=339,124
+AudioSynthWaveformSine   sine4;          //xy=340,174
+AudioSynthWaveformSine   sine5;          //xy=340,209
+AudioSynthWaveformSine   sine6;          //xy=340,244
+AudioSynthWaveformSine   sine7;          //xy=340,291
+AudioSynthWaveformSine   sine8;          //xy=341,327
+AudioSynthWaveformSine   sine9;         //xy=341,412
+AudioSynthWaveformSine   sine10;         //xy=341,483
+AudioSynthWaveformSine   sine11;          //xy=342,363
+AudioSynthWaveformSine   sine12;         //xy=342,447
+AudioMixer4              mixer1;         //xy=459,325
+AudioMixer4              mixer2;         //xy=461,90
+AudioMixer4              mixer3;         //xy=461,208
+AudioMixer4              mixer4;         //xy=461,444
+AudioEffectEnvelope      envelope1;      //xy=591,90
+AudioEffectEnvelope      envelope2;      //xy=591,208
+AudioEffectEnvelope      envelope3;      //xy=593,326
+AudioEffectEnvelope      envelope4;      //xy=596,444
+AudioMixer4              mixer5;         //xy=759,274
+AudioOutputI2S           i2s1;           //xy=887,273
+AudioConnection          patchCord1(sine1, 0, mixer1, 0);
+AudioConnection          patchCord2(sine2, 0, mixer1, 1);
+AudioConnection          patchCord3(sine3, 0, mixer1, 2);
+AudioConnection          patchCord4(sine4, 0, mixer2, 0);
+AudioConnection          patchCord5(sine5, 0, mixer2, 1);
+AudioConnection          patchCord6(sine6, 0, mixer2, 2);
+AudioConnection          patchCord7(sine7, 0, mixer3, 0);
+AudioConnection          patchCord8(sine8, 0, mixer3, 1);
+AudioConnection          patchCord9(sine9, 0, mixer3, 2);
+AudioConnection          patchCord10(sine10, 0, mixer4, 0);
+AudioConnection          patchCord11(sine11, 0, mixer4, 1);
+AudioConnection          patchCord12(sine12, 0, mixer4, 2);
+AudioConnection          patchCord13(mixer1, envelope1);
+AudioConnection          patchCord14(mixer2, envelope2);
+AudioConnection          patchCord15(mixer3, envelope3);
+AudioConnection          patchCord16(mixer4, envelope4);
+AudioConnection          patchCord17(envelope1, 0, mixer5, 0);
+AudioConnection          patchCord18(envelope2, 0, mixer5, 1);
+AudioConnection          patchCord19(envelope3, 0, mixer5, 2);
+AudioConnection          patchCord20(envelope4, 0, mixer5, 3);
+AudioConnection          patchCord21(mixer5, 0, i2s1, 0);
+AudioConnection          patchCord22(mixer5, 0, i2s1, 1);
+AudioControlSGTL5000     audioShield;     //xy=132,494
 // GUItool: end automatically generated code

 void setup() {
@@ -26,11 +66,13 @@

   AudioMemory(8);
   audioShield.enable();
-  audioShield.volume(0.45);
-
-  sine1.frequency(220);
-  sine1.amplitude(0.4);
-
+  audioShield.volume(0.5);
+
+  initVoice(1);
+  initVoice(2);
+  initVoice(3);
+  initVoice(4);
+
   usbMIDI.setHandleNoteOff(OnNoteOff);
   usbMIDI.setHandleNoteOn(OnNoteOn);
   usbMIDI.setHandleVelocityChange(OnVelocityChange);
@@ -44,6 +86,105 @@
   usbMIDI.read(); // USB MIDI receive
 }

+void initVoice(byte voice) {
+  switch (voice) {
+    case 1:
+      initSine(&sine1);
+      initSine(&sine2);
+      initSine(&sine3);
+      initEnvelope(&envelope1);
+      initMixer(&mixer1);
+      break;
+    case 2:
+      initSine(&sine4);
+      initSine(&sine5);
+      initSine(&sine6);
+      initEnvelope(&envelope2);
+      initMixer(&mixer2);
+      break;
+    case 3:
+      initSine(&sine7);
+      initSine(&sine8);
+      initSine(&sine9);
+      initEnvelope(&envelope3);
+      initMixer(&mixer3);
+      break;
+    case 4:
+      initSine(&sine10);
+      initSine(&sine11);
+      initSine(&sine12);
+      initEnvelope(&envelope4);
+      initMixer(&mixer4);
+      break;
+  }
+}
+
+void initSine(AudioSynthWaveformSine *sine) {
+  sine->amplitude(1.0);
+}
+
+void initEnvelope(AudioEffectEnvelope *env) {
+  env->attack(0.2);
+  env->sustain(1.0);
+  env->release(0.1);
+}
+
+void initMixer(AudioMixer4 *mix) {
+  mix->gain(0, 0.083);
+  mix->gain(1, 0.083);
+  mix->gain(2, 0.083);
+  mix->gain(3, 0);
+}
+
+byte inuse;
+byte voices[127];
+
+byte findVoice() {
+  if (inuse != 0xFF) {
+    for (int i=0; i<4; i++) {
+      byte pos = 1<<i;
+      if ((inuse & pos) == 0) {
+        return i+1;
+      }
+    }
+  }
+
+  // Lowest notes have priority for now.
+  for (byte i=127; i>=0; i--) {
+    if (voices[i] != 0) {
+      returnVoice(i);
+      return i;
+    }
+  }
+}
+
+byte allocateVoice(byte note) {
+  byte voice = findVoice();
+
+  inuse |= (1 << (voice-1));
+
+  Serial.print("Voice=");
+  Serial.print(voice);
+  Serial.print(", inuse=");
+  Serial.print(inuse);
+  Serial.println();
+
+  voices[note] = voice;
+  return voice;
+}
+
+void returnVoice(byte note) {
+  byte voice = voices[note];
+  inuse &= ~(1 << (voice-1));
+
+  Serial.print("Voice=");
+  Serial.print(voice);
+  Serial.print(", inuse=");
+  Serial.print(inuse);
+  Serial.println();
+
+  voices[note] = 0;
+}

 void OnNoteOn(byte channel, byte note, byte velocity) {
   Serial.print("Note On, ch=");
@@ -54,8 +195,35 @@
   Serial.print(velocity, DEC);
   Serial.println();

-  sine1.frequency(note2freq(note));
-  sine1.amplitude(0.5);
+  byte voice = allocateVoice(note);
+  float fund = note2freq(note);
+
+  switch (voice) {
+    case 1:
+      sine1.frequency(fund);
+      sine2.frequency(fund * 0.5);
+      sine3.frequency(fund * 1.5);
+      envelope1.noteOn();
+      break;
+    case 2:
+      sine4.frequency(fund);
+      sine5.frequency(fund * 0.5);
+      sine6.frequency(fund * 1.5);
+      envelope2.noteOn();
+      break;
+    case 3:
+      sine7.frequency(fund);
+      sine8.frequency(fund * 0.5);
+      sine9.frequency(fund * 1.5);
+      envelope3.noteOn();
+      break;
+    case 4:
+      sine10.frequency(fund);
+      sine11.frequency(fund * 0.5);
+      sine12.frequency(fund * 1.5);
+      envelope3.noteOn();
+      break;
+  }
 }

 void OnNoteOff(byte channel, byte note, byte velocity) {
@@ -67,7 +235,25 @@
   Serial.print(velocity, DEC);
   Serial.println();

-  sine1.amplitude(0);
+  byte voice = voices[note];
+  switch (voice) {
+    case 1:
+      envelope1.noteOff();
+      returnVoice(note);
+      break;
+    case 2:
+      envelope2.noteOff();
+      returnVoice(note);
+      break;
+    case 3:
+      envelope3.noteOff();
+      returnVoice(note);
+      break;
+    case 4:
+      envelope4.noteOff();
+      returnVoice(note);
+      break;
+  }
 }

 void OnVelocityChange(byte channel, byte note, byte velocity) {


Canbus was being improperly initialized. This is now corrected.

--- GEVCU.ino
+++ GEVCU.ino
@@ -152,7 +152,7 @@
   pinMode(BLINKLED, OUTPUT);
   digitalWrite(BLINKLED, LOW);

-  canHandler = new CanHandler(0);
+  canHandler = new CanHandler(0,500); //use CAN0 and set it to 500k baud

    motorController = new DmocMotorController(canHandler); //instantiate a DMOC645 device controller as our motor controller
    motorController->handleTick();


Integrated sensor data aquisition in main loop

--- oktopus-autopilote/oktopus-autopilote.ino
+++ oktopus-autopilote/oktopus-autopilote.ino
@@ -5,10 +5,44 @@
 // Revision: v0.0.1
 // Licence: Apache License Version 2.0, January 2004 http://www.apache.org/licenses/

+#include "GPS.h"
+#include "Moisture.h"
+#include "Temperature.h"
+
+GPS gps;
+Moisture moistureSensor;
+Temperature temperatureSensor;
+
+String moisture = "Unknown";
+short temperature = 0;
+NMEAData gpsData;
+
 void setup() {
+  Serial.begin(115200);
+  gps.enable();
+  moistureSensor.enable();
+  temperatureSensor.enable();
+}

-}
+uint32_t timer = millis();

 void loop() {

+  gpsData = gps.getData();
+
+  // if millis() or timer wraps around, we'll just reset it
+  if (timer > millis())  timer = millis();
+
+  if (millis() - timer > 2000) {
+
+    timer = millis(); // reset the time
+
+    moisture = moistureSensor.getData();
+    temperature = temperatureSensor.getData();
+
+    gps.printData(gpsData);
+    moistureSensor.printData(moisture);
+    temperatureSensor.printData(temperature);
+  }
 }
+


Under the hardware-state-protocol we changed all arguments to zero. There was a 128 limit which was preventing websockets from stablishing a connection.

--- BackEnd/BackEnd.ino
+++ BackEnd/BackEnd.ino
@@ -689,7 +689,7 @@
     "hardware-state-protocol",
     callback_cat_protocol,
     0,
-    128,
+    0,
   }
   ,


SetTime: separated sending numbers and sending characters

--- SetTime/SetTime.ino
+++ SetTime/SetTime.ino
@@ -264,17 +264,24 @@
   return bitsOfDigit[n] << 1 | (dot ? 0 : 1);
 }

-void sendHHMM(int hh, int mm)
+void setDigits(int h1, int h2, int m1, int m2, int dots)
+{
+  insertBits(8, setHHMM + 3, 1, digit(h1, dots & 8));
+  insertBits(8, setHHMM + 4, 6, digit(h2, dots & 4));
+  insertBits(8, setHHMM + 6, 2, digit(m1, dots & 2));
+  insertBits(8, setHHMM + 8, 0, digit(m2, dots & 1));
+  insertBits(1, setHHMM + 9, 2, ~(dots >> 4));
+  insertBits(1, setHHMM + 9, 3, ~(dots >> 5));
+  sendBits(setHHMM, sizeof(setHHMM) * 8);
+}
+
+void sendHHMM(int hh, int mm, int dots)
 {
   int h1 = hh / 10;
   int h2 = hh % 10;
   int m1 = mm / 10;
   int m2 = mm % 10;
-  insertByte(setHHMM + 3, 1, digit(h1, 0));
-  insertByte(setHHMM + 4, 6, digit(h2, 0));
-  insertByte(setHHMM + 6, 2, digit(m1, 0));
-  insertByte(setHHMM + 8, 0, digit(m2, 0));
-  sendBits(setHHMM, sizeof(setHHMM) * 8);
+  setDigits(h1, h2, m1, m2, dots);
 }

 static void checkTime()


Better read active bus check

Better read active bus check

--- resilient_network/resilient_network.ino
+++ resilient_network/resilient_network.ino
@@ -148,7 +148,7 @@
 }

 void readActiveBus() {
-  while(bus[activeBus]->available()) {
+  while(activeBus != -1 && bus[activeBus]->available()) {
     // if(SERIAL_DEBUG) {
     //   Serial.print("a");
     //   Serial.println(activeBus);
@@ -163,7 +163,6 @@
       }
       parseMessage(activeBus, message);
       activeBus = -1;
-      break;
     }
   }
   if (millis()-listenStartTime > listenTimeout) {


modificato invio GET

modificato invio GET

--- nodeMCU/plant/functions.ino
+++ nodeMCU/plant/functions.ino
@@ -22,12 +22,15 @@

    String postStr= String(rnd);

-   String url = "/dato/acquisisci/" + postStr;
-   Serial.println(url);
+   String url = "GET /dato/acquisisci/" + postStr;
+     Serial.println(url);

-   client.print(url);
-//   client.print("\n\n");
-//   client.print(postStr);
+     client.print(url);
+     client.print("HTTP/1.0 \n\n");
+     Serial.println("HTTP/1.0 \n\n");
+
+     client.println();
+     client.stop();

    delay(1000);


Fix soil reading and add println for quick test

--- arduinoApp/gardenSketch/gardenSketch.ino
+++ arduinoApp/gardenSketch/gardenSketch.ino
@@ -56,8 +56,13 @@
     LDRValue = analogRead(lightSensorPin); // read light level from LDR
     airHumidity = airSensor.readHumidity(); // read humidity from DHT
     airTemperature = airSensor.readTemperature(); // read temperature from DHT
-    soilHumidity = sht1x.readHumidity(); // read temperature from SHT10
-    soilTemperature = sht1x.readTemperatureC(); // read humidity from SHT10
+    soilMoisture = soilSensor.readHumidity(); // read temperature from SHT10
+    soilTemperature = soilSensor.readTemperatureC(); // read humidity from SHT10
+    Serial.println(LDRValue);
+    Serial.println(airHumidity);
+    Serial.println(airTemperature);
+    Serial.println(soilMoisture);
+    Serial.println(soilTemperature);
   }

 }


fixed stats and changed stats formatting

--- TWANG.ino
+++ TWANG.ino
@@ -42,8 +42,8 @@
 // GAME
 enum Stage { SCREENSAVER, PLAY, COMPLETE, DEAD, WIN, GAMEOVER };

-long previousMillis = 0;                     // Time of the last redraw
-int levelNumber = 0;
+long previousMillis = 0;                   // Time of the last redraw
+int levelNumber =                      0;
 long lastInputTime = 0;
 #define TIMEOUT                        60000
 #define LEVEL_COUNT                    14
@@ -461,12 +461,12 @@
 		++stats_playthroughs;
 		EEPROM.write(0, stats_playthroughs);
 		int newBest = (int)((millis() - gameStartTime) / 1000);
-		if (newBest > stats_besttime) {
+		if (newBest < stats_besttime) {
 			stats_besttime = newBest;
 			EEPROM_writeint(1, stats_besttime);
 		}
-	}
-	updateStats();
+		updateStats();
+	}
 	lives = 3; //min(MAX_LIVES, lives + 1);
 }

@@ -758,8 +758,16 @@
 	lcd.print(stats_playthroughs);

 	lcd.setCursor(0, 2);
-	lcd.print("Best time: ");
-	lcd.print(stats_besttime);
+	lcd.print("Best time:    ");
+	int v = int(stats_besttime / 60);
+	if (v < 10)
+		lcd.print("0");
+	lcd.print(v);
+	lcd.print(":");
+	v = stats_besttime - v * 60;
+	if (v < 10)
+		lcd.print("0");
+	lcd.print(v);
 }

 // ---------------------------------


array of thresh

array of thresh

--- guitar-arduino.ino
+++ guitar-arduino.ino
@@ -26,7 +26,8 @@
 #define TUNING -12

-const int LASER_ANALOG_TH[] = {960, 920, 975, 711, 900, 975}; //for analog read of bpw34. 900-1023 means laser is blocked, 0-600 means laser hit diode
+//const int LASER_ANALOG_TH[] = {960, 920, 975, 711, 900, 975}; //for analog read of bpw34. 900-1023 means laser is blocked, 0-600 means laser hit diode
+int LASER_ANALOG_TH[] = {1024, 1024, 1024, 1024, 1024, 1024}; //for analog read of bpw34. 900-1023 means laser is blocked, 0-600 means laser hit diode
 #define LASER_ANALOG_EMPH 975 //for analog read of bpw34. 900-1023 means laser is blocked, 0-600 means laser hit diode
 #define LASER_ANALOG_THOLD_US 500 //[us] fastest accepted laser state change to prevent noise, fast strum may not be accepted
 //off topic: measured fastest cadence of strumming is 120ms(120000us)
@@ -492,9 +493,15 @@
 //    send_midi_debug(i, (int)((float)a / 8));
 //    delay(100);
 //    }
-    if (a > LASER_ANALOG_TH[i])
+    if (a > LASER_ANALOG_TH[i]+5)
       blocked = true;
-
+    else {
+      int delta = (int)((a - LASER_ANALOG_TH[i]) / 2);
+      if (delta < -4) delta = -4;
+      if (delta > 4) delta = 4;
+      LASER_ANALOG_TH[i] += delta; //update level of laser sensors dynamically
+    }
+
     if (last_alaser_status[i] != blocked) { //status changed
 //      send_midi_debug(i, (int)((float)a / 8));
       last_alaser_status[i] = blocked;


added servo state controller in arduino firmware

--- jsk_2016_01_baxter_apc/firmware/arm_manager.ino
+++ jsk_2016_01_baxter_apc/firmware/arm_manager.ino
@@ -21,21 +21,19 @@
 int16_t dig_P7;
 int16_t dig_P8;
 int16_t dig_P9;
-int8_t  dig_H1;
-int16_t dig_H2;
-int8_t  dig_H3;
-int16_t dig_H4;
-int16_t dig_H5;
-int8_t  dig_H6;

 ros::NodeHandle nh; //write with IDE
 // ros::NodeHandle_<ArduinoHardware, 1, 2, 512, 512> nh;

 std_msgs::Float64 float_msg;
 std_msgs::Bool bool_msg;
+std_msgs::Bool servo_state_msg;
+std_msgs::Int16 servo_angle_msg;

 ros::Publisher pressure_pub("vacuum_gripper/limb/right/pressure", &float_msg);
 ros::Publisher state_pub("gripper_grabbed/limb/right/state", &bool_msg);
+ros::Publisher servo_state_pub("vacuum_gripper/limb/right/servo_state_info", &servo_state_msg);
+ros::Publisher servo_angle_pub("vacuum_gripper/limb/right/servo_angle_info", &servo_angle_msg);

 unsigned long  publisher_timer = 0;

@@ -43,25 +41,42 @@

 void servoCb(const std_msgs::Int16& angle_msg)
 {
-    int angle;
-    angle = angle_msg.data;
-    if (angle < 0) angle = 0;
-    if (angle > 180) angle = 180;
-
-    myservo.write(angle);
-}
-
-ros::Subscriber<std_msgs::Int16> servo_sub("vacuum_gripper/limb/right/servo", &servoCb);
+    if (servo_state_msg.data == false) return;
+    if (angle_msg.data < 0) servo_angle_msg.data = 0;
+    else if (angle_msg.data > 180) servo_angle_msg.data = 180;
+    else servo_angle_msg.data = angle_msg.data;
+    myservo.write(servo_angle_msg.data);
+}
+
+void servo_toggleCb(const std_msgs::Bool& servo_toggle_msg)
+{
+    if (servo_toggle_msg.data) {
+        servo_state_msg.data = true;
+        if (!myservo.attached()) myservo.attach(5);
+        myservo.write(servo_angle_msg.data);
+    } else {
+        servo_state_msg.data = false;
+        if (myservo.attached()) myservo.detach();
+    }
+}
+
+ros::Subscriber<std_msgs::Int16> servo_angle_sub("vacuum_gripper/limb/right/servo_angle", &servoCb);
+ros::Subscriber<std_msgs::Bool> servo_state_sub("vacuum_gripper/limb/right/servo_state", &servo_toggleCb);

 void setup() {
+    servo_state_msg.data = false;
+    servo_angle_msg.data = 90;
     init_servo();
     pinMode(SS, OUTPUT);
     digitalWrite(SS, HIGH);
-    nh.getHardware()->setBaud(57600);
+    nh.getHardware()->setBaud(115200);
     nh.initNode();
-    nh.subscribe(servo_sub);
+    nh.subscribe(servo_angle_sub);
+    nh.subscribe(servo_state_sub);
     nh.advertise(pressure_pub);
     nh.advertise(state_pub);
+    nh.advertise(servo_state_pub);
+    nh.advertise(servo_angle_pub);

     SPI.begin();
     SPI.setClockDivider(SPI_CLOCK_DIV8);
@@ -86,6 +101,8 @@

         state_pub.publish(&bool_msg);
         pressure_pub.publish(&float_msg);
+        servo_state_pub.publish(&servo_state_msg);
+        servo_angle_pub.publish(&servo_angle_msg);

         publisher_timer = millis() + 100;
     }
@@ -95,6 +112,7 @@
 void init_servo()
 {
     myservo.attach(5);
+    myservo.write(servo_angle_msg.data);
 }

 void initBME()
@@ -142,12 +160,6 @@
     dig_P7 = (data[19] << 8) | data[18];
     dig_P8 = (data[21] << 8) | data[20];
     dig_P9 = (data[23] << 8) | data[22];
-    dig_H1 = data[24];
-    dig_H2 = (data[26] << 8) | data[25];
-    dig_H3 = data[27];
-    dig_H4 = (data[28] << 4) | (0x0F & data[29]);
-    dig_H5 = (data[30] << 4) | ((data[29] >> 4) & 0x0F);
-    dig_H6 = data[31];
 }

 void readData()


Remove bad file name so the library doesn't complain

Appears to have been moved to https://github.com/m5stack/M5Stack/tree/master/examples/Advanced/Display/Sprite/one_bit_Yin_Yang anyway

--- examples/Advanced/Display/Sprite/1_bit_Yin_Yang/1_bit_Yin_Yang.ino
+++ examples/Advanced/Display/Sprite/1_bit_Yin_Yang/1_bit_Yin_Yang.ino
@@ -1,95 +0,0 @@
-// This sketch draws a rotating Yin and Yang symbol. It illustrates
-// the drawimg and rendering of simple animated graphics using
-// a 1 bit per pixel (1 bpp) Sprite.
-
-// Note:  TFT_BLACK sets the pixel value to 0
-// Any other colour sets the pixel value to 1
-
-// A square sprite of side = 2 x RADIUS will be created
-// (80 * 80)/8 = 800 bytes needed for 1 bpp sprite
-//              6400 bytes for 8 bpp
-//             12800 bytes for 16 bpp
-#define RADIUS 40      // Radius of completed symbol = 40
-
-#define WAIT 0         // Loop delay
-
-// 1bpp Sprites are economical on memory but slower to render
-#define COLOR_DEPTH 1  // Colour depth (1, 8 or 16 bits per pixel)
-
-// Rotation angle increment and start angle
-#define ANGLE_INC 3
-int angle = 0;
-
-#include <M5Stack.h>
-
-TFT_eSprite img = TFT_eSprite(&M5.Lcd);
-
-
-// -------------------------------------------------------------------------
-void setup(void)
-{
-  M5.begin();
-  M5.Lcd.setRotation(0);
-  M5.Lcd.fillScreen(TFT_BLUE);
-
-  img.setColorDepth(COLOR_DEPTH);
-  img.createSprite(RADIUS*2+1, RADIUS*2+1);
-  img.fillSprite(TFT_BLACK);
-}
-// -------------------------------------------------------------------------
-// -------------------------------------------------------------------------
-void loop() {
-  // Draw Yin and Yang symbol circles into Sprite
-  yinyang(RADIUS, RADIUS, angle, RADIUS);
-
-  // Set the 2 pixel palette colours that 1 and 0 represent on the display screen
-  img.setBitmapColor(TFT_WHITE, TFT_BLACK);
-
-  // Push Sprite image to the TFT screen at x, y
-  img.pushSprite(M5.Lcd.width()/2 - RADIUS, 0); // Plot sprite
-
-  angle+=3;                   //Increment angle to rotate circle positions
-  if (angle > 359) angle = 0; // Limit angle range
-
-  // Slow things down
-  delay(WAIT);
-}
-// -------------------------------------------------------------------------
-
-
-// =========================================================================
-// Draw circles for Yin and Yang - rotate positions to create symbol
-// =========================================================================
-// x,y == coordinate center within Sprite
-// start_angle = 0 - 359
-// r = radius
-
-int yinyang(int x, int y, int start_angle, int r)
-{
-  int x1 = 0; // getCoord() will update these
-  int y1 = 0;
-
-  getCoord(x, y, &x1, &y1, r/2, start_angle); // Get x1 ,y1
-  img.fillCircle( x1,  y1, r/2, TFT_WHITE);
-  img.fillCircle( x1,  y1, r/8, TFT_BLACK);
-
-  getCoord(x, y, &x1, &y1, r/2, start_angle + 180);
-  img.fillCircle( x1,  y1, r/2, TFT_BLACK);
-  img.fillCircle( x1,  y1, r/8, TFT_WHITE);
-
-  img.drawCircle(x, y, r, TFT_WHITE);
-}
-
-// =========================================================================
-// Get coordinates of end of a vector, pivot at x,y, length r, angle a
-// =========================================================================
-// Coordinates are returned to caller via the xp and yp pointers
-#define RAD2DEG 0.0174532925
-void getCoord(int x, int y, int *xp, int *yp, int r, int a)
-{
-  float sx1 = cos( (a-90) * RAD2DEG );
-  float sy1 = sin( (a-90) * RAD2DEG );
-  *xp =  sx1 * r + x;
-  *yp =  sy1 * r + y;
-}
-


Additional debugging and detecting status extra wire.

--- test/PoE-test/voordeur-asis-2017/voordeur-asis-2017.ino
+++ test/PoE-test/voordeur-asis-2017/voordeur-asis-2017.ino
@@ -2,7 +2,7 @@
     to the existing setup late 2017.

 */
-#include "/Users/dirkx/.passwd.h"
+// #include "/Users/dirkx/.passwd.h"
 #include "MFRC522.h"

 // Wired ethernet.
@@ -30,8 +30,8 @@

 #define AARTLED_GPIO      (16)

-// #define WIRECHECK_GPIO	  (0)
-// #define WIRECHECK_REDLED  (HIGH)
+#define WIRECHECK_GPIO	  (5)
+#define WIRECHECK_REDLED  (HIGH)

 #define DOOR_OPEN_DELAY         (5*1000)   //  10 seconds -- how long to hold the relay engaged; in milli seconds.
 #define CACHE_FALLBACK_TIMEOUT  (500)       // 0.5 second  -- how long to wait for a reply before checking the cache.
@@ -715,6 +715,17 @@
       break;
   };

+#ifdef WIRECHECK_GPIO
+  {
+    static unsigned long last = 0;
+    if (millis() - last > 5000) {
+      char msg[256];
+      snprintf(msg,sizeof(msg),"%s: Wire pin: %d", pname, digitalRead(WIRECHECK_GPIO));
+                 Serial.println(msg);
+                 client.publish(log_topic, msg);
+    }
+  }
+#endif

   // catch any logic errors or strange cases where the door is open while we think
   // we are not doing anything.


Added reset and stack usage reporting

Added reset and stack usage reporting

--- Arduino/hardware/REV10/REV10SecureBHR/REV10SecureBHR.ino
+++ Arduino/hardware/REV10/REV10SecureBHR/REV10SecureBHR.ino
@@ -122,6 +122,9 @@
 static constexpr uint8_t RFM23B_INT_MASK = (1 << (PIN_RFM_NIRQ&7));
 // Mask for Port D input change interrupts.
 static constexpr uint8_t SERIALRX_INT_MASK = (1 << 0); // Serial RX
+
+// Counter containing current no. of resets.
+static uint8_t resetCount;

 ////// SCRATCHSPACE

@@ -165,7 +168,6 @@
 };
 static GlobalWorkSpace globalWorkSpace;

-
 /******************************************************************************
  * PERIPHERALS
  * Peripheral drivers and config
@@ -215,7 +217,7 @@
 // - Internal temp
 // - Boiler state
 // TODO: Consider removing entirely.
-constexpr uint8_t nTXStats = 2;
+constexpr uint8_t nTXStats = 4;
 static OTV0P2BASE::SimpleStatsRotation<nTXStats> ss1; // Configured for maximum different stats.

@@ -243,6 +245,7 @@
     // Handler routine not required/expected to 'clear' this interrupt.
     if((changes & RFM23B_INT_MASK) && !(pins & RFM23B_INT_MASK))
         { PrimaryRadio._handleInterruptNonVirtual(); }
+    OTV0P2BASE::MemoryChecks::fnCalled(1U);
 }

 // Previous state of port D pins to help detect changes.
@@ -373,6 +376,7 @@
     PrimaryRadio.poll();
     SecondaryRadio.poll();
     }
+  OTV0P2BASE::MemoryChecks::fnCalled(2U);
   return(false);
   }

@@ -400,6 +404,7 @@
         >(msg, sW);
     // Reenable interrupt line.
     PrimaryRadio.pauseInterrupts(false);
+    OTV0P2BASE::MemoryChecks::fnCalled(3U);
     return (success);
 }
 OTRadioLink::OTMessageQueueHandler< pollIO, V0P2_UART_BAUD,
@@ -453,6 +458,17 @@
         ss1.put(TemperatureC16);
         // Show boiler state for boiler hubs.
         ss1.put(V0p2_SENSOR_TAG_F("b"), (int) BoilerHub.isBoilerOn());
+        // Show reset counter. Low priority.
+        ss1.put(V0p2_SENSOR_TAG_F("R"), resetCount, true);
+//        // Send current stack, divided by 4 (). Low priority.
+//        // FIXME How would stack recording behaviour work? Do we want max stack:
+//        // - this minor cycle  (interesting things may happen outside this tx cycle)
+//        // - this tx cycle  (max stack usage may be missed, will need to change stack capture behaviour)
+//        // - ever  (redundant after it's been received once)
+//        // FIXME How do we deal with case where max stack > 255?
+        const size_t curMinSP = OTV0P2BASE::MemoryChecks::getMinSP();
+        const uint8_t txMinSP = (255 >= curMinSP) ? (uint8_t) curMinSP : 255U;
+        ss1.put(V0p2_SENSOR_TAG_F("SP"), txMinSP, true);
         // OPTIONAL items
         constexpr uint8_t privacyLevel = OTV0P2BASE::stTXalwaysAll;

@@ -527,6 +543,7 @@
         }
     }
     if(neededWaking) { OTV0P2BASE::flushSerialProductive(); OTV0P2BASE::powerDownSerial(); }
+    OTV0P2BASE::MemoryChecks::fnCalled(4U);
 }

@@ -571,7 +588,7 @@
             case 'S':
             {
                 Serial.print(F("Resets: "));
-                const uint8_t resetCount = eeprom_read_byte((uint8_t *)V0P2BASE_EE_START_RESET_COUNT);
+                resetCount = eeprom_read_byte((uint8_t *)V0P2BASE_EE_START_RESET_COUNT);
                 Serial.print(resetCount);
                 Serial.println();
 #if 1
@@ -769,12 +786,7 @@
         // May generate output to host on Serial.
         // Come back and have another go immediately until no work remaining.
         pollIO();
-//        const uint8_t startTime = OTV0P2BASE::getSubCycleTime();  // FIXME debug stuff
         if(messageQueue.handle(true, PrimaryRadio)) {
-//            OTV0P2BASE::serialPrintAndFlush(startTime);
-//            OTV0P2BASE::serialPrintAndFlush("\t");
-//            OTV0P2BASE::serialPrintAndFlush(OTV0P2BASE::getSubCycleTime());
-//            OTV0P2BASE::serialPrintlnAndFlush();
             continue; }
         // Normal long minimal-power sleep until wake-up interrupt.
         // Rely on interrupt to force quick loop round to I/O poll.
@@ -784,6 +796,8 @@
     // Reset and immediately re-prime the RTC-based watchdog.
     OTV0P2BASE::resetRTCWatchDog();
     OTV0P2BASE::enableRTCWatchdog(true);
+    // Capture loop call in profiler
+    OTV0P2BASE::MemoryChecks::fnCalled(0U);

     // START LOOP BODY
@@ -895,10 +909,10 @@
         }
     }

-    // End-of-loop processing, that may be slow.
-    // Ensure progress on queued messages ahead of slow work.  (TODO-867)
-    pollIO();; // Deal with any pending I/O.
-    messageQueue.handle(true, PrimaryRadio); // Deal with any pending I/O.
+//    // End-of-loop processing, that may be slow. XXX
+//    // Ensure progress on queued messages ahead of slow work.  (TODO-867)
+//    pollIO();; // Deal with any pending I/O.
+//    messageQueue.handle(true, PrimaryRadio); // Deal with any pending I/O.

     // Command-Line Interface (CLI) polling.
     // If a reasonable chunk of the minor cycle remains after all other work is done


Update pt_ex4_led_individually.ino

Update pt_ex4_led_individually.ino

--- pt_ex/pt_ex4_led_individually.ino
+++ pt_ex/pt_ex4_led_individually.ino
@@ -175,21 +175,13 @@
 void loop() {
   //Check each thread by priority

-  while (Serial.available() > 0) {
-      char c = Serial.read();
-      if (c != -1) {
-        Serial.println("recieve");
-        Serial.println(c);
-      }
-    }
-
-  /*thread8_entry(&thread8);
+  thread8_entry(&thread8);
   thread1_entry(&thread1);
   thread2_entry(&thread2);
   thread3_entry(&thread3);
   thread4_entry(&thread4);
   thread5_entry(&thread5);
   thread6_entry(&thread6);
-  thread7_entry(&thread7);*/
+  thread7_entry(&thread7);

 }


correct hsv values to be between 0-255

correct hsv values to be between 0-255

--- firmware/LO_mpr121_and_fastLED_test_cz/LO_mpr121_and_fastLED_test_cz.ino
+++ firmware/LO_mpr121_and_fastLED_test_cz/LO_mpr121_and_fastLED_test_cz.ino
@@ -37,7 +37,7 @@
   for (int i = 0; i < STATION_SEGMENTS; i++) {
     //uint32_t STATION_COLOR = HSV_to_RGB(i);
     for (int j = 0; j < SEGMENT_LED_COUNT; j++) {
-      leds[i].setHSV(STATION_HUE[i], STATION_SAT[i], STATION_BRI[i]);
+      leds[i].setHSV(int(STATION_HUE[i]*255), int(STATION_SAT[i]*255), int(STATION_BRI[i]*255));
     }
   }
   FastLED.show();


Don't bother with the LED

Don't bother with the LED

--- rf95_server/rf95_server.ino
+++ rf95_server/rf95_server.ino
@@ -13,11 +13,9 @@

 // Singleton instance of the radio driver
 RH_RF95 rf95;
-int led = 13;

 void setup()
 {
-    pinMode(led, OUTPUT);
   Serial.begin(9600);
   Serial.println("Hello World from Server!");
   if (!rf95.init())
@@ -38,7 +36,6 @@
     uint8_t len = sizeof(buf);
     if (rf95.recv(buf, &len))
     {
-      digitalWrite(led, HIGH);
       RH_RF95::printBuffer("request: ", buf, len);
       Serial.print("got request: ");
       Serial.println((char*)buf);
@@ -50,7 +47,6 @@
       rf95.send(data, sizeof(data));
       rf95.waitPacketSent();
       Serial.println("Sent a reply");
-       digitalWrite(led, LOW);
     }
     else
     {


Update Timer_Interrupt_Notes.ino

Update Timer_Interrupt_Notes.ino

Ambiguous date, made less ambiguous.

--- PulseSensorAmped_Arduino_1dot4/Timer_Interrupt_Notes.ino
+++ PulseSensorAmped_Arduino_1dot4/Timer_Interrupt_Notes.ino
@@ -1,5 +1,5 @@
 /*
-  These notes put together by Joel Murphy for Pulse Sensor Amped, Winter 2015
+  These notes put together by Joel Murphy for Pulse Sensor Amped, 2015

   The code that this section is attached to uses a timer interrupt
   to sample the Pulse Sensor with consistent and regular timing.


added a dev updater

added a dev updater

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

--- zimodem/zcommand.ino
+++ zimodem/zcommand.ino
@@ -1202,12 +1202,17 @@

   uint8_t buf[255];
   int bufSize = 254;
-#ifdef ZIMODEM_ESP32
-  if((!doWebGetBytes("www.zimmers.net", 80, "/otherprojs/guru-latest-version.txt", false, buf, &bufSize))||(bufSize<=0))
+#ifdef USE_DEVUPDATER
+  if((!doWebGetBytes("192.168.1.10", 8080, "/tmp/guru-latest-version.txt", false, buf, &bufSize))||(bufSize<=0))
     return ZERROR;
 #else
-  if((!doWebGetBytes("www.zimmers.net", 80, "/otherprojs/c64net-latest-version.txt", false, buf, &bufSize))||(bufSize<=0))
-    return ZERROR;
+#  ifdef ZIMODEM_ESP32
+    if((!doWebGetBytes("www.zimmers.net", 80, "/otherprojs/guru-latest-version.txt", false, buf, &bufSize))||(bufSize<=0))
+      return ZERROR;
+#  else
+    if((!doWebGetBytes("www.zimmers.net", 80, "/otherprojs/c64net-latest-version.txt", false, buf, &bufSize))||(bufSize<=0))
+      return ZERROR;
+#  endif
 #endif

   if((!isNumber)&&(vlen>2))


reformatted (I think this way is clearer)

--- PySerial/Robust_Prompting_PythonCode_and_ArduinoSketch/robust.ino
+++ PySerial/Robust_Prompting_PythonCode_and_ArduinoSketch/robust.ino
@@ -14,18 +14,25 @@
       char_input = Serial.read();

       switch (char_input) {
-      case '1':
-        Serial.println(analogRead(A0)); // if '1' is received, then send back analog read A0
-      break;
-      case '2':
-       digitalWrite(13,HIGH); // if '2' is received, turn on the led attached to 13
-      break;
-      case '3':
-       digitalWrite(13,LOW); // if '3' is received then turn off the led attached 13
-      break;
-      default:
-        delay(10);
-      break;
+
+        case '1':
+          // if '1' is received, then send back analog read A0
+          Serial.println(analogRead(A0));
+          break;
+
+        case '2':
+          // if '2' is received, turn on the led attached to 13
+          digitalWrite(13,HIGH);
+          break;
+
+        case '3':
+          // if '3' is received then turn off the led attached 13
+          digitalWrite(13,LOW);
+          break;
+
+        default:
+          delay(10);
+          break;
       }
   }


validate callback input and compare to current value

--- _72-homekit-accessories-Aircon/_72-homekit-accessories-Aircon.ino
+++ _72-homekit-accessories-Aircon/_72-homekit-accessories-Aircon.ino
@@ -110,11 +110,11 @@
     free(p);
     client.loop();
     /*
-    Serial.print("[MQTT] out topic : ");
-    Serial.print(topictosend);
-    Serial.print(" payload: ");
-    Serial.print(payloadtosend);
-    Serial.println(" published");
+      Serial.print("[MQTT] out topic : ");
+      Serial.print(topictosend);
+      Serial.print(" payload: ");
+      Serial.print(payloadtosend);
+      Serial.println(" published");
     */
     return true;

@@ -122,11 +122,11 @@
     free(p);
     client.loop();
     /*
-    Serial.print("[MQTT] out topic : ");
-    Serial.print(topictosend);
-    Serial.print(" payload: ");
-    Serial.print(payloadtosend);
-    Serial.println(" publish failed");
+      Serial.print("[MQTT] out topic : ");
+      Serial.print(topictosend);
+      Serial.print(" payload: ");
+      Serial.print(payloadtosend);
+      Serial.println(" publish failed");
     */
     return false;
   }
@@ -181,26 +181,16 @@

   if (receivedtopic == homekit_subscribe_topic)
   {
-    if (root.containsKey("ac_temp"))
-    {
-      if (ir_data.ac_temp != root["ac_temp"])
+    if (root.containsKey("ac_temp") && root.containsKey("ac_mode") && root.containsKey("ac_flow"))
+    {
+      if ((ir_data.ac_temp != root["ac_temp"]) || (ir_data.ac_flow != root["ac_flow"]) || (ir_data.ac_mode != root["ac_mode"]))
       {
         ir_data.ac_temp = root["ac_temp"];
-
-        if (ir_data.ac_mode == 1)
-        {
-          ir_data.haveData = true;
-          where_haveData_called = 1;
-        }
+        ir_data.ac_flow = root["ac_flow"];
+        ir_data.ac_mode = root["ac_mode"];
+        ir_data.haveData = true;
+        where_haveData_called = 1;
       }
-      ir_data.ac_flow = root["ac_flow"];
-    }
-
-    if (root.containsKey("ac_mode"))
-    {
-      ir_data.ac_mode = root["ac_mode"];
-      ir_data.haveData = true;
-      where_haveData_called = 2;
     }
   }
 }
@@ -215,10 +205,10 @@
     receivedpayload += (char)inpayload[i];
   }
   /*
-  Serial.print("[MQTT] intopic : ");
-  Serial.print(receivedtopic);
-  Serial.print(" payload: ");
-  Serial.println(receivedpayload);
+    Serial.print("[MQTT] intopic : ");
+    Serial.print(receivedtopic);
+    Serial.print(" payload: ");
+    Serial.println(receivedpayload);
   */
   parseMqttMsg(receivedpayload, receivedtopic);
 }
@@ -263,8 +253,8 @@
       else
       {
         /*
-        Serial.print("[MQTT] mqtt failed, rc=");
-        Serial.println(client.state());
+          Serial.print("[MQTT] mqtt failed, rc=");
+          Serial.println(client.state());
         */
       }
     }
@@ -375,13 +365,13 @@
   if (WiFi.status() != WL_CONNECTED)
   {
     /*
-    Serial.println();
-    Serial.print("[WIFI] Connecting to ");
-    Serial.println(WIFI_SSID);
+      Serial.println();
+      Serial.print("[WIFI] Connecting to ");
+      Serial.println(WIFI_SSID);
     */

     delay(10);
-    wifi_set_phy_mode(PHY_MODE_11N);
+    //wifi_set_phy_mode(PHY_MODE_11N);
     WiFi.setOutputPower(20);
     WiFi.mode(WIFI_STA);
     WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
@@ -391,27 +381,27 @@
     while (WiFi.status() != WL_CONNECTED)
     {
       /*
-      Serial.print(". ");
-      Serial.print(Attempt);
+        Serial.print(". ");
+        Serial.print(Attempt);
       */
       delay(100);
       Attempt++;
       if (Attempt == 150)
       {
         /*
-        Serial.println();
-        Serial.println("[WIFI] Could not connect to WIFI, restarting...");
-        Serial.flush();
+          Serial.println();
+          Serial.println("[WIFI] Could not connect to WIFI, restarting...");
+          Serial.flush();
         */
         ESP.restart();
         delay(200);
       }
     }
     /*
-    Serial.println();
-    Serial.print("[WIFI] connected");
-    Serial.print(" --> IP address: ");
-    Serial.println(WiFi.localIP());
+      Serial.println();
+      Serial.print("[WIFI] connected");
+      Serial.print(" --> IP address: ");
+      Serial.println(WiFi.localIP());
     */
   }
 }
@@ -431,11 +421,11 @@
 void setup()
 {
   /*
-  Serial.begin(115200);
-  Serial.println();
-  Serial.println("Starting....... ");
+    Serial.begin(115200);
+    Serial.println();
+    Serial.println("Starting....... ");
   */
-
+
   ir_data.ac_mode          = 0;
   ir_data.ac_temp          = AC_DEFAULT_TEMP;
   ir_data.ac_flow          = AC_DEFAULT_FLOW;
@@ -533,8 +523,8 @@
   }

   /*
-  if (now() != prevDisplay)
-  {
+    if (now() != prevDisplay)
+    {
     prevDisplay = now();
     if (timeStatus() == timeSet)
     {
@@ -544,7 +534,7 @@
     {
       Serial.println("[TIME] time not set");
     }
-  }
+    }
   */

   if (WiFi.status() == WL_CONNECTED)


update test code

update test code

--- arduino/opencr_arduino/opencr/libraries/OpenManipulator/example/Arduino/Test/kinematics/kinematics.ino
+++ arduino/opencr_arduino/opencr/libraries/OpenManipulator/example/Arduino/Test/kinematics/kinematics.ino
@@ -34,16 +34,32 @@
   manipulator.addTool(TOOL, COMP4, MATH::makeVector3(0.025, 0.0, 0.0), IDENTITY_MATRIX, 4, 1.0, 0.5);

   Eigen::MatrixXf jacobian = KINEMATICS::CHAIN::jacobian(&manipulator, TOOL);
-  LOG::INFO("Jacobian : ");
-  PRINT::MATRIX(jacobian);

   KINEMATICS::CHAIN::forward(&manipulator, COMP1);
   manipulator.checkManipulatorSetting();

   Pose target;
-  target.position = MATH::makeVector3(-0.043, 0.0, 0.086);
+  target.position = MATH::makeVector3(-0.035, 0.0, 0.0875);
+
   target.orientation = IDENTITY_MATRIX;
   std::vector<float> joint_angle = KINEMATICS::CHAIN::inverse(&manipulator, TOOL, target);
+  // std::vector<float> joint_angle = KINEMATICS::CHAIN::sr_inverse(&manipulator, TOOL, target);
+  // std::vector<float> joint_angle = KINEMATICS::CHAIN::position_only_inverse(&manipulator, TOOL, target);
+
+  int8_t index = 0;
+  std::map<Name, Component>::iterator it;
+  for(it = manipulator.getIteratorBegin(); it != manipulator.getIteratorEnd(); it++)
+  {
+    if(manipulator.getComponentJointId(it->first) != -1)
+    {
+      manipulator.setComponentJointAngle(it->first, joint_angle.at(index));
+      index++;
+    }
+  }
+
+  KINEMATICS::CHAIN::forward(&manipulator, COMP1);
+  manipulator.checkManipulatorSetting();
+
   LOG::INFO("Result of inverse : ");
   PRINT::VECTOR(joint_angle);
 }


kinda works

kinda works

--- DanceFeather/DanceFeather.ino
+++ DanceFeather/DanceFeather.ino
@@ -13,7 +13,7 @@

 #define ACC_SIZE 64
 #define FFT_SIZE 512
-#define HANN_SIZE 20
+#define HANN_SIZE 40
 #define FS (16000.0 / ACC_SIZE)
 #define F2 4.0f
 #define END_INDEX ((uint16_t) (F2 / (FS / FFT_SIZE)))
@@ -69,6 +69,7 @@
   sht30.begin();
   PDM.onReceive(onPDMdata);
   PDM.begin(1, 16000);
+  PDM.setGain(5);

   // init hann window
   for (int i = 0; i < HANN_SIZE ; i++) {
@@ -307,7 +308,9 @@

 void addToFFT(float val) {
+  // Serial.print("Val: "); Serial.println(val);
   val = abs(val); // rectify val
+  // val = val * val;
   float windowedVal = 0;
   for (int i = HANN_SIZE - 1; i > 0; i--) {
     incomingWindow[i] = incomingWindow[i - 1];
@@ -320,7 +323,9 @@
     fftBuffer[i] = fftBuffer[i-1];
   }

-  fftBuffer[0] = max(0, windowedVal - prevWindowedVal); // half recitify difference
+  float diff = max(0, windowedVal - prevWindowedVal);
+  fftBuffer[0] = diff;
+  Serial.print("Diff: "); Serial.println(diff);

   prevWindowedVal = windowedVal;

@@ -331,8 +336,8 @@
   fft_phase(FS, 0, F2, FFT_SIZE, fftBuffer, mag, phase, startIndex, endIndex);
   updatePhase(mag, phase, startIndex, endIndex);
   float hz = FS * _phaseRateAverage / 2 / PI;
-  Serial.print("endIndex: "); Serial.println(endIndex);
-  Serial.print("END_INDEX: "); Serial.println(END_INDEX);
+  // Serial.print("endIndex: "); Serial.println(endIndex);
+  // Serial.print("END_INDEX: "); Serial.println(END_INDEX);
   // Serial.print("BPM: "); Serial.println(hz * 60);
   //Serial.print("radsPerUpdate: "); Serial.println(_phaseRateAverage);

@@ -369,18 +374,16 @@
     }
     for (int i = 0; i < samplesRead; i++) {
       float newVal = tempBuffer[i];
+      //acc += newVal * newVal;
       acc += newVal;
       numInAcc++;
       if (numInAcc >= ACC_SIZE) {
           float value = acc / ACC_SIZE;
           acc = 0;
           numInAcc = 0;
-          //minwave = min(value, minwave);
-          //maxwave = max(value, maxwave);
-          addToFFT(value);
+          addToFFT(value * value);
+          // addToFFT(value);
       }
-      // minwave = min(tempBuffer[i], minwave);
-      // maxwave = max(tempBuffer[i], maxwave);

       //samples--;
     }


remove unused function

remove unused function

--- short-circuit-limiter/short-circuit-limiter.ino
+++ short-circuit-limiter/short-circuit-limiter.ino
@@ -50,7 +50,7 @@

   changeDisplayBacklight(true);
-  changeLimiterRelayState(false);
+  passFullCurrentThrough(false);
   changeMCBRelayState(false);

@@ -70,19 +70,11 @@
   //To clear the accmulated reading
   clamp.getIrmsFromIncrementalMeasurement();
   lcd.clear();
-  //changeDisplayBacklight(false);
-
-
-

   Serial.begin(115200);
-
   Serial.println("Setup complete");

   enterWindowBeforeMode(0);
-
-
-
 }

 double getCurrentMeasurement(){
@@ -223,16 +215,6 @@

 }

-void passFullCurrentThrough(bool state){
-  if(state){
-    changeLimiterRelayState(true);
-    changeDisplayBacklight(true);
-  } else {
-    changeLimiterRelayState(false);
-    changeDisplayBacklight(false);
-  }
-}
-
 void changeMCBRelayState(bool state){
   if(state){
     digitalWrite(PIN_RELAY_MCB, HIGH);
@@ -241,7 +223,7 @@
   }
 }

-void changeLimiterRelayState(bool state){
+void passFullCurrentThrough(bool state){
   if(state){
     digitalWrite(PIN_RELAY_LIMITER, HIGH);
   } else {


Add more context about the type parameters near where it is set.

--- printer.ino
+++ printer.ino
@@ -6,11 +6,21 @@
 #include <SoftwareSerial.h>
 #include <Bounce.h>

-// ------- Settings ---------------------------------------------------
+// ------- Settings for YOU to change if you want ---------------------

 byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x86, 0x67 }; // physical mac address

-const char *printerType = "A2-raw"; // controls the format of the data sent from the server
+// The printerType controls the format of the data sent from the server
+// If you're using a completely different kind of printer, change this
+// to correspond to your printer's PrintProcessor implementation in the
+// server.
+//
+// If you want to control the darkness of your printouts, append a dot and
+// a number, e.g. A2-raw.240 (up to a maximum of 255).
+//
+// If you want to flip the vertical orientation of your printouts, append
+// a number and then .flipped, e.g. A2-raw.240.flipped
+const char *printerType = "A2-raw";

 const char* host = "printer.gofreerange.com"; // the host of the backend server
 const unsigned int port = 80;


IAP mode

IAP mode

--- ESP/src/ESP.ino
+++ ESP/src/ESP.ino
@@ -1228,7 +1228,7 @@

 void startIAPMode() {
     WiFi.disconnect();
-    _setupAPMode("DCHDMI-Install", "installme!");
+    _setupAPMode("DCDigital-Install", "installme!");
     handler->setAuthentication("please", "installme!");
     isIAPMode = true;
 }


Add comment

Add comment

--- dee-oh-tee.ino
+++ dee-oh-tee.ino
@@ -1,3 +1,17 @@
+/**
+ * A simple library for drawing fun shapes with a laser that's attached to a pan/tilt
+ * servo. (Cat not included.)
+ *
+ * This type of servo works on angles, but I find it easier to think in Cartesian
+ * coordinates. Most of the functions in this library take x- and y-coordinates. The
+ * origin (center) is at x = 0, y = 0. There are USABLE_DEGREES / 2 units of space
+ * between the origin and the limits of each servo's range in either direction.
+ *
+ * Have fun!
+ *
+ * -- Adam Jensen <acjensen at gmail>
+ */
+
 #include <Servo.h>

 const int buttonPin = 10;


Upped Baud rate.

Upped Baud rate.

--- scr_arduino/scr_arduino.ino
+++ scr_arduino/scr_arduino.ino
@@ -139,6 +139,10 @@

 void setup()
 {
+
+  // Up Baud Rate
+  nh.getHardware()->setBaud(115200);
+
   // ROS Stuff
   nh.initNode();


Winch and conveyor unit tests enabled.

Winch and conveyor unit tests enabled.

--- src/SabertoothDriverROS/SabertoothDriverROS.ino
+++ src/SabertoothDriverROS/SabertoothDriverROS.ino
@@ -87,7 +87,7 @@

 //Conveyor and winch system constants
 const char CONVEYOR_SPEED = 20;
-const char WINCH_SPEED = 30;
+const char WINCH_SPEED = 15;

 int conveyorRotationTime = 0;
 long conveyorStopTime = 0;
@@ -654,17 +654,19 @@
 void unitTestConveyor()
 {
   // Test the conveyor:
-  // 2s "dumping" / forwards (clockwise), 2s "collecting" / backwards (counterclockwise).
-
-  driveClockwise(LEFT_CONVEYOR_MOTOR_ID, CONVEYOR_SPEED);
+  // 2s "dumping" / forwards (clockwise), 1s pause, 2s "collecting" / backwards (counterclockwise).
+
+  //driveClockwise(LEFT_CONVEYOR_MOTOR_ID, CONVEYOR_SPEED);
   driveClockwise(RIGHT_CONVEYOR_MOTOR_ID, CONVEYOR_SPEED);
   delaySeconds(2);
-  driveCounterclockwise(LEFT_CONVEYOR_MOTOR_ID, CONVEYOR_SPEED);
+  driveClockwise(RIGHT_CONVEYOR_MOTOR_ID, CONVEYOR_SPEED);
+  delaySeconds(1);
+  //driveCounterclockwise(LEFT_CONVEYOR_MOTOR_ID, CONVEYOR_SPEED);
   driveCounterclockwise(RIGHT_CONVEYOR_MOTOR_ID, CONVEYOR_SPEED);
   delaySeconds(2);
-  driveCounterclockwise(LEFT_CONVEYOR_MOTOR_ID, 0);
+  //driveCounterclockwise(LEFT_CONVEYOR_MOTOR_ID, 0);
   driveCounterclockwise(RIGHT_CONVEYOR_MOTOR_ID, 0);
-  delaySeconds(2);
+  delaySeconds(1);

 }

@@ -723,7 +725,6 @@
 }

-
 /**
  * Is called on starting the arduino.
  *
@@ -755,6 +756,8 @@

   stopAllMotors(false);
   //unitTest();
+  unitTestConveyor();
+  unitTestWinch();

   // Initialize the current wheel status message
   setupWheelStatus();


-Changed Serial output to ESP_LOGx macros.

--- dimmertask.ino
+++ dimmertask.ino
@@ -14,7 +14,7 @@
     setEmptyTimers();
   }

-  //setup channels
+  /* setup pwm on leds */
   channel[ 0 ].pin = LED0_PIN;
   channel[ 1 ].pin = LED1_PIN;
   channel[ 2 ].pin = LED2_PIN;
@@ -45,8 +45,6 @@

   while (1)
   {
-    //time_t startTimer = micros();
-
     struct timeval microSecondTime;

     gettimeofday( &microSecondTime, NULL );
@@ -103,7 +101,6 @@
                                             ledcMaxValue ) );
       }
     }
-    //Serial.println( micros() - startTimer );
     vTaskDelayUntil( &xLastWakeTime, dimmerTaskdelayTime / portTICK_PERIOD_MS );
   }
 }
@@ -117,12 +114,12 @@
   }
   ledcMaxValue = ( 0x00000001 << numberOfBits ) - 1;
   ledcNumberOfBits = numberOfBits;
-  //Serial.printf( "\nPWM frequency set to %.2f kHz\n", ledcActualFrequency / 1000);
-  //Serial.printf( "PWM bit depth set to %i bits\n", ledcNumberOfBits);
-  //Serial.printf( "Maximum raw value set to 0x%x or %i decimal\n\n", ledcMaxValue, ledcMaxValue);
+  ESP_LOGI( TAG, "PWM frequency set to %.2f kHz.", ledcActualFrequency / 1000);
+  ESP_LOGI( TAG, "PWM bit depth set to %i bits.", ledcNumberOfBits);
+  ESP_LOGI( TAG, "Maximum raw value set to 0x%x or %i decimal.", ledcMaxValue, ledcMaxValue);
 }

-static inline __attribute__((always_inline)) float mapFloat( float x, const float in_min, const float in_max, const float out_min, const float out_max)
+static inline __attribute__((always_inline)) float mapFloat( const float x, const float in_min, const float in_max, const float out_min, const float out_max)
 {
   return ( x - in_min ) * ( out_max - out_min ) / ( in_max - in_min ) + out_min;
 }


Can now calculate a gradient for a frame

--- arduino/arduino.ino
+++ arduino/arduino.ino
@@ -89,7 +89,7 @@

   //Apply red to green gradient
   for(int i=0; i<60; i++) {
-    strip->setPixelColor(i, 255*(60-i)/60, 255*i/60, 0);
+    strip->setPixelColor(i, 0, 0, 255);

   }

@@ -110,7 +110,8 @@
 }

 void applyProfile() {
-  currentFrameIndex = 0;
+  currentFrameIndex = -1;
+
   loadNextAnimationStep();

 }
@@ -130,9 +131,8 @@
   //Load current Frame;
   struct Frame* frame = NULL;
   struct ColorStop** colorStops = NULL;
-  loadFrame(0, &frame, &colorStops);
-
-  /*
+  loadFrame(currentFrameIndex, &frame, &colorStops);
+
   Serial.println("-------------------");
   Serial.print("colorStopCount: ");
   Serial.println(frame->colorStopCount);
@@ -156,8 +156,73 @@
   Serial.println(colorStops[1]->g);
   Serial.print("firstColorStop->b: ");
   Serial.println(colorStops[1]->b);
-  */
-
+
+  uint8_t r[60];
+  uint8_t g[60];
+  uint8_t b[60];
+
+  //Create start arrays
+  calculateGradient(colorStops, frame->colorStopCount, r, g, b, 60);
+
+  for(uint16_t i=0; i<60; i++) {
+    strip->setPixelColor(i, r[i], g[i], b[i]);
+
+  }
+
+  strip->show();
+
+}
+
+void calculateGradient(struct ColorStop** colorStops, uint8_t colorStopCount, uint8_t* r, uint8_t* g, uint8_t* b, uint16_t ledCount) {
+  int16_t diffR, diffG, diffB;
+  float percent = 0;
+  uint8_t currentColorStop = -1;
+
+  for(uint16_t led=0; led<ledCount; led++) {
+    if(led == 0 || led == colorStops[currentColorStop]->ledIndex) {
+      currentColorStop++;
+
+      diffR = colorStops[currentColorStop+1]->r - colorStops[currentColorStop]->r;
+      diffG = colorStops[currentColorStop+1]->g - colorStops[currentColorStop]->g;
+      diffB = colorStops[currentColorStop+1]->b - colorStops[currentColorStop]->b;
+
+      /*
+      Serial.println("current:");
+      Serial.println(colorStops[currentColorStop]->r);
+      Serial.println(colorStops[currentColorStop]->g);
+      Serial.println(colorStops[currentColorStop]->b);
+
+      Serial.println("next:");
+      Serial.println(colorStops[currentColorStop+1]->r);
+      Serial.println(colorStops[currentColorStop+1]->g);
+      Serial.println(colorStops[currentColorStop+1]->b);
+
+      Serial.println("diffs:");
+      Serial.println(diffR);
+      Serial.println(diffG);
+      Serial.println(diffB);
+      */
+
+    }
+
+    percent = ((float)led - (float)colorStops[currentColorStop]->ledIndex) / ((float)colorStops[currentColorStop+1]->ledIndex - (float)colorStops[currentColorStop]->ledIndex);
+    r[led] = colorStops[currentColorStop]->r + diffR * percent;
+    g[led] = colorStops[currentColorStop]->g + diffG * percent;
+    b[led] = colorStops[currentColorStop]->b + diffB * percent;
+
+    /*
+    Serial.print(led);
+    Serial.print(": ");
+    Serial.print(percent);
+    Serial.print(", ");
+    Serial.print(r[led]);
+    Serial.print(", ");
+    Serial.print(g[led]);
+    Serial.print(", ");
+    Serial.println(b[led]);
+    */
+
+  }
 }

 void loadFrame(uint8_t index, struct Frame** framePointer, struct ColorStop*** colorStopsPointer) {


Fixed compilation issue stdint.h

Fixed compilation issue stdint.h

--- arduino/arduino.ino
+++ arduino/arduino.ino
@@ -1,7 +1,7 @@
 #include <Adafruit_NeoPixel.h>
 #include <EEPROMex.h>
 #include <EEPROMVar.h>
-#include <stdint>
+#include <stdint.h>

 #define EEPROM_CURRENT_PROFILE_START       64
 #define EEPROM_CURRENT_PROFILE_ID           0 // 8 Byte


Update arduino.ino

Update arduino.ino

--- arduino/arduino.ino
+++ arduino/arduino.ino
@@ -21,7 +21,7 @@
   int tmpButtonState = digitalRead(pinNumber);
   // if it has not been clicked yet and it's down we can send the message
   if (tmpButtonState == HIGH && buttonClicked == false) {
-    Serial.printLn("Hello World");
+    Serial.println(F("Hello World"));
     digitalWrite(led, HIGH);
     delay(1000); // wait 1 s before sending the next message
     buttonClicked = true;


now sending ACK signal at the end of command processing