Change debug pin to on-board LED

Change debug pin to on-board LED

--- code/oakpowerboard/oakpowerboard.ino
+++ code/oakpowerboard/oakpowerboard.ino
@@ -21,7 +21,7 @@
 #define BTN_3 7
 #define BTN_4 6
 #define PULSE_PIN A0
-#define DEBUG_LED 10
+#define DEBUG_LED 1

 //#define DEBUG


feedback server bugfixing

feedback server bugfixing


tinkering with contrast to make display readable

--- tinkering/interface/lcdController/lcdController.ino
+++ tinkering/interface/lcdController/lcdController.ino
@@ -2,7 +2,7 @@
 Philips PCD8544 Controller and interface code.

 Basis of library pulled from: http://playground.arduino.cc/Code/PCD8544
-Mostly unmodified in first commit.
+Mostly unmodified except for pin mappings in first commit.
 */

 #define PIN_SCE   P1_5
@@ -143,13 +143,16 @@
   pinMode(PIN_DC, OUTPUT);
   pinMode(PIN_SDIN, OUTPUT);
   pinMode(PIN_SCLK, OUTPUT);
+  pinMode(PIN_BL, OUTPUT);
   digitalWrite(PIN_RESET, LOW);
   digitalWrite(PIN_RESET, HIGH);
+  analogWrite(PIN_BL, 255);
   LcdWrite(LCD_C, 0x21 );  // LCD Extended Commands.
   LcdWrite(LCD_C, 0xB1 );  // Set LCD Vop (Contrast).
   LcdWrite(LCD_C, 0x04 );  // Set Temp coefficent. //0x04
   LcdWrite(LCD_C, 0x14 );  // LCD bias mode 1:48. //0x13
   LcdWrite(LCD_C, 0x20 );  // LCD Basic Commands
+  LcdContrast(59);
   LcdWrite(LCD_C, 0x0C );  // LCD in normal mode.
 }

@@ -169,12 +172,20 @@
   digitalWrite(PIN_SCE, HIGH);
 }

+//Should stick to range 40-60.  Background pixels start to dim at 60
+void LcdContrast(byte contrast)
+{
+  LcdWrite(LCD_C, 0x21);//Commands follow
+  LcdWrite(LCD_C, 0x80 | contrast);
+  LcdWrite(LCD_C, 0x20); //back to display mode
+}
+
 void setup(void)
 {
   LcdInitialise();
   LcdClear();
   Serial.println("writing out");
-  LcdString("Hello World!");
+  LcdString("Hello World!!!!!!");
 }

 void loop(void)


correzione del simulatore

correzione del simulatore

--- Arduino/mqtt_simulatore_eth/mqtt_simulatore_eth.ino
+++ Arduino/mqtt_simulatore_eth/mqtt_simulatore_eth.ino
@@ -32,7 +32,7 @@
 // Update these with values suitable for your network.
 byte mac[]    = {  0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED };
 IPAddress ip(192, 168, 1, 230);
-IPAddress server(192, 168, 1, 174);
+IPAddress server(192, 168, 1, 248);

 void callback(char* topic, byte* payload, unsigned int length) {
   Serial.print("Message arrived [");
@@ -89,11 +89,11 @@

   puntoAcq = String(random(1,4));
-  temp = String(random(-40,50));
-  terUm = String(random(0, 1024));
-  AriaUm = String(random(0, 1024));
+  temp = String(random(-4,35));
+  terUm = String(random(0, 90));
+  AriaUm = String(random(0, 90));
   //YYYY-MM-dd hh:mm:ss
-  String MM = '0' + String(random(1,13));
+  String MM = '0' + String(4 ); // String(random(1,13));
   MM = MM.substring(MM.length() - 2, MM.length());
   String dd = '0' + String(random(1,32));
   dd = dd.substring(dd.length() - 2, dd.length());
@@ -120,7 +120,7 @@
     msg.toCharArray(buf, 64);
     client.publish("acqDati", buf);

-    delay(2000);
+    delay(10000);

 }
 }


add debug guard

add debug guard

missing debug guard

--- firmware/wibean-firmwarev2.ino
+++ firmware/wibean-firmwarev2.ino
@@ -159,7 +159,9 @@
   // pump commands come in CSV, e.g. 32,44,33,22,0,0,0,33
   // as onFor,offFor,onFor,offFor.... up to the max limit set by PumpControl
   // and they come in with units of 100ms per unit.
+#ifdef SERIAL_DEBUG
   Serial.println("pumpCommand!");
+#endif
   // did they send any parameters?
   if(command.length() == 0) {
     return -1;


Added code to handle matt QOS issues by retrying, also added reconnection code to reconnect to MQTT and WIFI

--- SensorReader/SensorReader.ino
+++ SensorReader/SensorReader.ino
@@ -156,6 +156,13 @@
       result = client.publish("arduino-tilt", message_buff);
       Serial.print("DEBUG :: arduino-tilt publish outcome 2 : ");
       Serial.println(result);
+      while ( status != WL_CONNECTED) {
+        connectToWifi();
+      }
+        if (!client.connected()) {
+    Serial.print("INFO :: We lost mqtt connection, reconnecting.... ");
+    connectToMQTT();
+  }
     }
   }
 }
@@ -194,6 +201,13 @@
     result = client.publish("arduino-rfid", message_buff);
     Serial.print("DEBUG :: arduino-rfid publish outcome 2 : ");
     Serial.println(result);
+    while ( status != WL_CONNECTED) {
+        connectToWifi();
+      }
+        if (!client.connected()) {
+    Serial.print("INFO :: We lost mqtt connection, reconnecting.... ");
+    connectToMQTT();
+  }
   }
 }

@@ -215,6 +229,13 @@
     result = client.publish("arduino-weather", message_buff);
     Serial.print("DEBUG :: arduino-weather publish outcome 2 : ");
     Serial.println(result);
+    while ( status != WL_CONNECTED) {
+        connectToWifi();
+      }
+      if (!client.connected()) {
+    Serial.print("INFO :: We lost mqtt connection, reconnecting.... ");
+    connectToMQTT();
+  }
   }
 }


Added setBoardState function. We need to test it.

--- ServerSketch/ServerSketch.ino
+++ ServerSketch/ServerSketch.ino
@@ -41,10 +41,12 @@
 #define NUM_OF_ANALOG_PINS 6
 #define NUM_OF_DIGITAL_PINS 14

+#define ANALOG_OUT_MAX_VALUE 255
+
 typedef struct Pin {
   char label[PIN_LABEL_SIZE];
   boolean is_analog;
-  boolean is_sensor;
+  boolean is_input;
   float value;
   boolean connections[TOTAL_NUM_OF_PINS];
 } Pin;
@@ -415,7 +417,6 @@
     Serial.print("Error. Unrecongnized message: ");
     Serial.println(sMsg);
   }
-
 }

 // **********************************
@@ -638,22 +639,24 @@
   for(int i=0; i<(TOTAL_NUM_OF_PINS-NUM_OF_ANALOG_PINS); i++)
   {
     g_aPins[i].is_analog = false;
-    g_aPins[i].is_sensor = false;
+    g_aPins[i].is_input = false;
   }

   // Initialize pins A0-A5 as analog in pins
   for(int i=NUM_OF_DIGITAL_PINS; i<TOTAL_NUM_OF_PINS; i++)
   {
     g_aPins[i].is_analog = true;
-    g_aPins[i].is_sensor = true;
-  }
-
+    g_aPins[i].is_input = true;
+  }
+
+  // Set the HW state
+  setBoardState();

   /*
   char label[25];
   boolean is_analog;
-  boolean is_sensor;
+  boolean is_input;
   float value;
   int connections[20];
 } Pin;
@@ -663,13 +666,37 @@
 */
 }

+void setBoardState()
+{
+  for(int i=0; i<TOTAL_NUM_OF_PINS; i++)
+  {
+      if( g_aPins[i].is_input )
+      {
+        pinMode(i, INPUT);
+      }
+      else
+      {
+        pinMode(i, OUTPUT);
+
+        if( g_aPins[i].is_analog )
+        {
+          analogWrite(i, int(g_aPins[i].value*ANALOG_OUT_MAX_VALUE) );
+        }
+        else
+        {
+          digitalWrite(i, int(g_aPins[i].value) );
+        }
+
+      }
+  }
+}

 /*
 {	"status":<OK,ERROR>,
 	"pins":{	"<0,1,…,13,A0,…,A5>":
 				{	"label":"<label text>",
 					"is_analog":"<true,false>",
-					"is_sensor":"<true,false>",
+					"is_input":"<true,false>",
 					"value":"<0.0,1.0>",
 					"connections":[<array of pins>],
 				},
@@ -682,10 +709,10 @@
 */

-//const PROGMEM TEST_STRING[] = "{\"status\":OK,\"pins\":{\"13\":{\"label\":\"LED ON 13\",\"is_analog\":\"false\",\"is_sensor\":\"false\",\"value\":\"0.0\",\"connections\":[]}},\"connections\":[]}\";
-// "{"status":OK,"pins":{"13":{"label":"LED ON 13","is_analog":"false","is_sensor":"false","value":"0.0","connections":[]}},"connections":[]}";
-
-//char g_acMessage[] = "{\"status\":OK,\"pins\":{\"13\":{\"label\":\"LED ON 13\",\"is_analog\":\"false\",\"is_sensor\":\"false\",\"value\":\"0.0\",\"connections\":[]}},\"connections\":[]}\"";
+//const PROGMEM TEST_STRING[] = "{\"status\":OK,\"pins\":{\"13\":{\"label\":\"LED ON 13\",\"is_analog\":\"false\",\"is_input\":\"false\",\"value\":\"0.0\",\"connections\":[]}},\"connections\":[]}\";
+// "{"status":OK,"pins":{"13":{"label":"LED ON 13","is_analog":"false","is_input":"false","value":"0.0","connections":[]}},"connections":[]}";
+
+//char g_acMessage[] = "{\"status\":OK,\"pins\":{\"13\":{\"label\":\"LED ON 13\",\"is_analog\":\"false\",\"is_input\":\"false\",\"value\":\"0.0\",\"connections\":[]}},\"connections\":[]}\"";

 unsigned long last_print = 0;
 aJsonStream serial_stream(&Serial);
@@ -783,7 +810,7 @@
   aJson.deleteItem(poMsg);
 }

-//char g_acMessage[] = "{\"status\":OK,\"pins\":{\"13\":{\"label\":\"LED ON 13\",\"is_analog\":\"false\",\"is_sensor\":\"false\",\"value\":\"0.0\",\"connections\":[]}},\"connections\":[]}\"";
+//char g_acMessage[] = "{\"status\":OK,\"pins\":{\"13\":{\"label\":\"LED ON 13\",\"is_analog\":\"false\",\"is_input\":\"false\",\"value\":\"0.0\",\"connections\":[]}},\"connections\":[]}\"";
 //char g_acMessage[] = "{ \"pwm\": { \"8\": 0, \"9\": 128 } }";

 //char *g_acMessage = NULL;
@@ -792,14 +819,14 @@
 //char g_acMessage[] = "{\"status\":\"OK\"}";
 //char g_acMessage[] = "{\"status\":\"ERROR\"}";
 char g_acMessage[] = "{\"status\":\"OTHER ERROR\"}";
-//,\"pins\":{\"13\":{\"label\":\"LED ON 13\",\"is_analog\":\"false\",\"is_sensor\":\"false\",\"value\":\"0.0\",\"connections\":[]}},\"connections\":[]}\"";
+//,\"pins\":{\"13\":{\"label\":\"LED ON 13\",\"is_analog\":\"false\",\"is_input\":\"false\",\"value\":\"0.0\",\"connections\":[]}},\"connections\":[]}\"";

 void loop()
 {

    if (millis() - last_print > 1000) {

-    //aJsonObject *msg = aJson.parse("{\"status\":OK,\"pins\":{\"13\":{\"label\":\"LED ON 13\",\"is_analog\":\"false\",\"is_sensor\":\"false\",\"value\":\"0.0\",\"connections\":[]}},\"connections\":[]}\"");
+    //aJsonObject *msg = aJson.parse("{\"status\":OK,\"pins\":{\"13\":{\"label\":\"LED ON 13\",\"is_analog\":\"false\",\"is_input\":\"false\",\"value\":\"0.0\",\"connections\":[]}},\"connections\":[]}\"");
 //    aJsonObject *msg = aJson.parse(g_acMessage);
     processMessage(g_acMessage);

@@ -827,7 +854,7 @@
   //if (serial_stream.available()) {
     // Something real on input, let's take a look.
     //aJsonObject *msg = aJson.parse(&serial_stream);
-    //aJsonObject *msg = aJson.parse("{\"status\":OK,\"pins\":{\"13\":{\"label\":\"LED ON 13\",\"is_analog\":\"false\",\"is_sensor\":\"false\",\"value\":\"0.0\",\"connections\":[]}},\"connections\":[]}\"");
+    //aJsonObject *msg = aJson.parse("{\"status\":OK,\"pins\":{\"13\":{\"label\":\"LED ON 13\",\"is_analog\":\"false\",\"is_input\":\"false\",\"value\":\"0.0\",\"connections\":[]}},\"connections\":[]}\"");
     // aJsonObject *msg = aJson.parse(g_acMessage);
     // processMessage(msg);
     // aJson.deleteItem(msg);


Increased logging on arduino more

Increased logging on arduino more

--- arduino/arduino.ino
+++ arduino/arduino.ino
@@ -65,16 +65,23 @@
   if(incomingByte != -1) {
     if(incomingByte == 58) {
       py_log("Parsing message");
+
       msg_length = Serial.read();
       command = Serial.read();

+      py_log("Length: " + String(msg_length));
+      py_log("Command: " + String(command));
+
       char message[msg_length];
-
       for(int i=0; i<msg_length; i++) {
         message[i] = Serial.read();
       }

+      py_log("Message Parsed");
+
       checksum = Serial.read();
+
+      py_log("checksum: " + String(checksum));

       py_log(String(message));
     } else {


Added setLCDTemperatureColor function to respond to changing temperatures

--- FumeHoodMonitor/LCD.ino
+++ FumeHoodMonitor/LCD.ino
@@ -3,13 +3,16 @@
 #define REDLITE 5
 #define GREENLITE 6
 #define BLUELITE A3
-
+bool backlightBlinkState = true;
+int backLightBlinkCycleCountLimit = 1;
+int backlightBlinkCycleCount = 0;
 Adafruit_LiquidCrystal lcd(0);
 int brightness = 255;

 void initializeLCD(){
   lcd.begin(20,4);
   writeLCD("Starting LCD...");
+  Serial.println("Starting LCD");
   pinMode(REDLITE, OUTPUT);
   pinMode(GREENLITE, OUTPUT);
   pinMode(BLUELITE, OUTPUT);
@@ -49,6 +52,18 @@
   lcd.print(make20Characters("Fluid Temp: " + String(fluidTemp, 2) + String((char)223) + "F"));
   lcd.setCursor(0,3);
   lcd.print(make20Characters("Flame: " + flameStatus));
+}
+
+void setLCDTemperatureColor() {
+  if (onFire) {
+    if (backlightBlinkState) setBacklight("red");
+    else setBacklight(0, 0, 0);
+    if (backlightBlinkCycleCount >= backLightBlinkCycleCountLimit){
+      backlightBlinkState = !backlightBlinkState;
+      backlightBlinkCycleCount = 0;
+    } else backlightBlinkCycleCount++;
+  } else if (airHigh || oilHigh) setBacklight("red");
+  else setBacklight("green");
 }

 String make20Characters(String str){


ファームウェアの修正

ファームウェアの修正

--- GPduinoR3/GPduinoR3.ino
+++ GPduinoR3/GPduinoR3.ino
@@ -49,7 +49,8 @@
 #define LOW_BATTERY    512

 // 四輪操舵のモード
-static int g_mode_4ws;
+static int g_steer_pol_f;
+static int g_steer_pol_b;

 // サーボの調整
 static int g_servo_pol[3]; // 極性
@@ -195,7 +196,8 @@
     g_lr = 0;
     cnt_runaway = 0;
     Vbat_MovingAve.init();
-    g_mode_4ws = 0;
+    g_steer_pol_f = 1;
+    g_steer_pol_b = 0;
 }

 // メインループ
@@ -312,15 +314,28 @@
      */
     case 'T':
         // 4WSモード
-        if(buff[3] == '1'){
-            g_mode_4ws = 1;
-        }
-        else if(buff[3] == '2'){
-            g_mode_4ws = -1;
-        }
-        else{
-            g_mode_4ws = 0;
-        }
+        switch(buff[3]){
+        case '0':// FRONT
+            g_steer_pol_f = 1;
+            g_steer_pol_b = 0;
+            break;
+        case '1':// COMMON
+            g_steer_pol_f = 1;
+            g_steer_pol_b = 1;
+            break;
+        case '2':// REVERSE
+            g_steer_pol_f = 1;
+            g_steer_pol_b = -1;
+            break;
+        case '3':// REAR
+            g_steer_pol_f = 0;
+            g_steer_pol_b = 1;
+            break;
+        default:
+            g_steer_pol_f = 1;
+            g_steer_pol_b = 0;
+            break;
+        }
         // 値の解釈
         if( HexToUint16(&buff[1], &val, 2) != 0 ) break;
         sval = (int)((signed char)val);
@@ -329,8 +344,8 @@
         if(drive_mode == MODE_CAR)
         {
             servo_ctrl(0, sval);
-            servo_ctrl(1, sval);
-            servo_ctrl(2, g_mode_4ws * sval);
+            servo_ctrl(1, g_steer_pol_f * sval);
+            servo_ctrl(2, g_steer_pol_b * sval);
         }
         // 戦車モードの場合
         else


IRRemote send

IRRemote send

--- main/main/main.ino
+++ main/main/main.ino
@@ -29,6 +29,9 @@
 void cmdRGB(String rgbValueStr);
 void cmdPlayRGB(String aniDuration);
 void onAnimateRGB(void);
+
+void IRRemoteSendGreePowerOn(String param);
+
 /*
  * Defintions
 */
@@ -80,6 +83,7 @@
   {"rgb", "rgb rrr,ggg,bbb to set a rgb LED color", cmdRGB},
   {"playrgb", "playrgb milli-seconds, rgb as animation", cmdPlayRGB},
 #endif //#ifdef __SUPPORT_RGBLED__
+  {"greeOn", "power on gree air conditioner via ir remote", IRRemoteSendGreePowerOn},
   {"endOfCmd", "end of commands", emptyFunc},
 };

@@ -530,7 +534,7 @@
  * https://github.com/arduino/ArduinoCore-samd/blob/master/cores/arduino/main.cpp
  *
  * GREE air conditioner ir-remote spec(Chinese) -- http://wenku.baidu.com/view/2197b3400b4e767f5bcfce34.html
- * Be aware that, in Uno and other ATMega based boards, long or unsigned long is 32bits
+ * !Be aware that, in Uno and other ATMega based boards, long or unsigned long is 32bits
  */

 /* define to enable reverted receive, the first bit start from highest,
@@ -542,20 +546,52 @@
 #define IR_REMOTE_START_TIMING_MIN    3800
 #define IR_REMOTE_START_TIMING_MAX    4800

+/*standard definition of start signal,
+ * refer to
+ * http://wenku.baidu.com/view/2197b3400b4e767f5bcfce34.html
+*/
+#define IR_REMOTE_STANDARD_START_TIMING_HIGH  4500
+#define IR_REMOTE_STANDARD_START_TIMING_LOW   9000
+
 /* continue pulse flag in micro-seconds */
 #define IR_REMOTE_CONTINUE_TIMING_MIN  18000
 #define IR_REMOTE_CONTINUE_TIMING_MAX  22000

+/* standard definition of continue signal in micro-seconds
+ *  refer to
+ *  http://wenku.baidu.com/view/2197b3400b4e767f5bcfce34.html
+ */
+#define IR_REMOTE_STANDARD_CONTINUE_TIMING_HIGH   20000
+#define IR_REMOTE_STANDARD_CONTINUE_TIMING_LOW    600
+
 /* a 'one' timing means to set a bit to 1, indicated by 1200micro-seconds high pulse */
 #define IR_REMOTE_ONE_TIMING_MIN      900
 #define IR_REMOTE_ONE_TIMING_MAX      1800

+/* standard definition of 'one' signal in micro-seconds
+ *  refer to
+ *  http://wenku.baidu.com/view/2197b3400b4e767f5bcfce34.html
+ */
+#define IR_REMOTE_STANDARD_ONE_TIMING_HIGH   1600
+#define IR_REMOTE_STANDARD_ONE_TIMING_LOW    600
+
 /* a 'zero' timing means to set a bit to 0, indicated by 600micro-seconds high pulse */
-#define IR_REMOTE_ZERO_TIMING_MIN     250
+#define IR_REMOTE_ZERO_TIMING_MIN     50
 #define IR_REMOTE_ZERO_TIMING_MAX     700
+
+/* standard definition of 'zero' signal in micro-seconds
+ *  refer to
+ *  http://wenku.baidu.com/view/2197b3400b4e767f5bcfce34.html
+ */
+#define IR_REMOTE_STANDARD_ZERO_TIMING_HIGH   600
+#define IR_REMOTE_STANDARD_ZERO_TIMING_LOW    600

 /* measurement time out, in case timeout, reset all status */
 #define IR_REMOTE_TIMEOUT         150000
+
+#define GREE_DATA0_BITS    28
+#define GREE_DATA0_FIXED_BITS_TYPE0   0x25
+#define GREE_DATA0_FIXED_BITS_TYPE1   0x27

 /* bitwise of receiving data */
 #define IR_REMOTE_DATA_WIDTH       32
@@ -564,10 +600,19 @@
 unsigned long dataStartTiming; /* start timing of measuring a data */
 bool isDataValid; /* detected a start flag referring @IR_REMOTE_START_TIMING */
 unsigned long irData; /* received data from IR */
+unsigned long irDataExtra; /* received extra data from IR */
 byte irDataIdx; /* current receiving idex of data */
 const int pinIRRemote = 11; /* hardware IR pin foot */
 unsigned long irDataLongCode; /* first data received while continue pulse flag received,
                                   and the next 32bits data will be stored in irData*/
+
+const int pinIRSendRemote = 3; /* pin for connecting IR sending remote */
+const long greeIRCodeSwitchOnD0 = 0x0200a29;
+const long greeIRCodeSweithOffD0 = 0x0200a21;
+const long greeIRCodeOffD1Type0 = 0x7002300;
+const long greeIRCodeOffD1Type1 = 0x70200000;
+const long greeIRCodeOnD1Type0 = 0xf0002300;
+const long greeIRCodeOnD1Type1 = 0xf0200000;

 void IRRemoteSetup()
 {
@@ -691,6 +736,7 @@
       irData = 0;
       dataStartTiming = pulseStartTiming;
       pulseStartTiming = 0;
+      irDataExtra = 0;
       return;
   }
   else if (isDataValid == true) {
@@ -704,7 +750,11 @@
 #ifdef __IRREMOTE_RECEIVE_REVERT__
        bitSet(irData, (IR_REMOTE_DATA_WIDTH -1 - irDataIdx));
 #else
-       bitSet(irData, irDataIdx);
+       if (irDataIdx >= 32){
+           bitSet(irDataExtra, irDataIdx - 32);
+        } else {
+           bitSet(irData, irDataIdx);
+        }
 #endif
     }
     else if((dur <= (IR_REMOTE_ZERO_TIMING_MAX)) &&
@@ -713,16 +763,25 @@
 #ifdef __IRREMOTE_RECEIVE_REVERT__
       bitClear(irData, (IR_REMOTE_DATA_WIDTH - 1 - irDataIdx));
 #else
-      bitClear(irData, irDataIdx);
+     if (irDataIdx >= 32){
+        bitClear(irDataExtra, irDataIdx - 32);
+      } else {
+        bitClear(irData, irDataIdx);
+      }
 #endif
     }
     else if ((dur <= (IR_REMOTE_CONTINUE_TIMING_MAX)) &&
     (dur >= (IR_REMOTE_CONTINUE_TIMING_MIN)))
     {
       irDataLongCode = irData;
+      Serial.print(irData, HEX);
       Serial.print("continues@");
-      Serial.println(irData, HEX);
+      Serial.println(irDataExtra, HEX);
       irDataIdx = 0; /* reset index to continue receive next data */
+      irDataExtra = 0;
+        /* must reset to receive next pulse */
+       pulseStartTiming = 0;
+       return;
     }
     else{
       Serial.print("unkn!");
@@ -736,15 +795,127 @@
   }

   /* if receive completed */
-  if (irDataIdx >= IR_REMOTE_DATA_WIDTH)
+  if (irDataIdx == IR_REMOTE_DATA_WIDTH)
   {
     Serial.print(irDataIdx);
     Serial.print("@data:");
-    Serial.println(irData, HEX);
+    Serial.print(irData, HEX);
+    Serial.print("@dataExtra:");
+    Serial.println(irDataExtra, HEX);
   }

   /* must reset to receive next pulse */
   pulseStartTiming = 0;
 }

-
+/* IRRemote controller to set a start signal according with definition
+ *
+ *  currently this implementation is based on the remote controller of GREE air conditioner
+ */
+void IRremoteSendStartSignal(void)
+{
+  /* set low signal according with GREE definiion */
+  digitalWrite(pinIRSendRemote, LOW);
+  delayMicroseconds(IR_REMOTE_STANDARD_START_TIMING_LOW);
+
+  /* set high signal according with GREE definiion */
+  digitalWrite(pinIRSendRemote, HIGH);
+  delayMicroseconds(IR_REMOTE_STANDARD_START_TIMING_HIGH);
+}
+
+/* IRRemote controller to set a continue signal according with definition
+ *
+ *  currently this implementation is based on the remote controller of GREE air conditioner
+ */
+void IRremoteSendContinueSignal(void)
+{
+  /* set low signal according with GREE definiion */
+  digitalWrite(pinIRSendRemote, LOW);
+  delayMicroseconds(IR_REMOTE_STANDARD_CONTINUE_TIMING_LOW);
+
+  /* set high signal according with GREE definiion */
+  digitalWrite(pinIRSendRemote, HIGH);
+  delayMicroseconds(IR_REMOTE_STANDARD_CONTINUE_TIMING_HIGH);
+
+}
+
+/* IRRemote controller to set a zero  signal according with definition
+ *
+ *  currently this implementation is based on the remote controller of GREE air conditioner
+ */
+void IRremoteSendZeroSignal(void)
+{
+  /* set low signal according with GREE definiion */
+  digitalWrite(pinIRSendRemote, LOW);
+  delayMicroseconds(IR_REMOTE_STANDARD_ZERO_TIMING_LOW);
+
+  /* set high signal according with GREE definiion */
+  digitalWrite(pinIRSendRemote, HIGH);
+  delayMicroseconds(IR_REMOTE_STANDARD_ZERO_TIMING_HIGH);
+
+}
+
+/* IRRemote controller to set an 'one' signal according with definition
+ *
+ *  currently this implementation is based on the remote controller of GREE air conditioner
+ */
+void IRremoteSendOneSignal(void)
+{
+  /* set low signal according with GREE definiion */
+  digitalWrite(pinIRSendRemote, LOW);
+  delayMicroseconds(IR_REMOTE_STANDARD_ONE_TIMING_LOW);
+
+  /* set high signal according with GREE definiion */
+  digitalWrite(pinIRSendRemote, HIGH);
+  delayMicroseconds(IR_REMOTE_STANDARD_ONE_TIMING_HIGH);
+
+}
+
+/*
+ * Send a data, maximum 32bits
+ * note:
+ * Send a start signal by 'IRremoteSendStartSignal' before invoking this function
+ */
+void IRRemoteSendData(unsigned long data, int num)
+{
+  int i, value;
+
+  for (i = 0; i < num; i++)
+  {
+    value = bitRead(data, i);
+    if (value == 0){
+      IRremoteSendZeroSignal();
+    } else
+    {
+      IRremoteSendOneSignal();
+    }
+  }
+}
+
+/* To switch GREE air conditioner on
+ * */
+void IRRemoteSendGreePowerOn(String param)
+{
+  /* send start signal */
+  IRremoteSendStartSignal();
+
+  IRRemoteSendData(greeIRCodeSwitchOnD0, GREE_DATA0_BITS);
+  IRRemoteSendData(GREE_DATA0_FIXED_BITS_TYPE0, 35 - GREE_DATA0_BITS);
+
+  IRremoteSendContinueSignal();
+  IRRemoteSendData(greeIRCodeOnD1Type0, 32);
+
+  /* send start signal */
+  IRremoteSendStartSignal();
+  /* send start signal */
+  IRremoteSendStartSignal();
+
+
+  IRRemoteSendData(greeIRCodeSwitchOnD0, GREE_DATA0_BITS);
+  IRRemoteSendData(GREE_DATA0_FIXED_BITS_TYPE1, 35 - GREE_DATA0_BITS);
+
+  IRremoteSendContinueSignal();
+  IRRemoteSendData(greeIRCodeOnD1Type1, 32);
+
+
+}


Added JSON support

Added JSON support

--- Lockitron/lockitron.ino
+++ Lockitron/lockitron.ino
@@ -24,6 +24,8 @@
 */
 const char password[] = "arduino";

+String response;
+int state = OPEN;

 const int buttonPin = 12;
@@ -36,7 +38,6 @@
 const int swA1 = 4;
 const int swA2 = 8;

-int locked = OPEN;

 int lock(int state){
       digitalWrite(boardLed, HIGH);
@@ -86,21 +87,23 @@
     String command = client.readString();
     command.trim();
     if (command == "status"){
-      client.print(locked);
+      response = String(state);
     }
     else if (command == "lock") {
-      locked = lock(CLOSE);
-      client.print(locked);
+      state = lock(CLOSE);
+      response = String(state);
     }
     else if (command == password) {
-      locked = lock(OPEN);
-      client.print(locked);
+      state = lock(OPEN);
+      response = String(state);
     }
     else{ // Error
-      client.print("2");
+      response = "2";
     }
+    client.print(String("{\"state\":"+response+"}"));
     client.stop();
   }
+

   if (digitalRead(buttonPin)) {
       /*


Telnet IAC kind of working

Telnet IAC kind of working

--- MicroView/WiFiCartTelnetTest/WiFiCartTelnetTest.ino
+++ MicroView/WiFiCartTelnetTest/WiFiCartTelnetTest.ino
@@ -34,6 +34,9 @@
 HardwareSerial& WifiSerial = Serial;
 WiFly wifly;

+// Telnet Stuff
+#define IAC 255
+
 // ----------------------------------------------------------

 char temp[100];
@@ -49,7 +52,7 @@

   pinMode(RTS, INPUT);

-  display2("Wi-Fi\nInit...");
+  display2("Wi-Fi \nInit...");

   boolean ok = wifly.begin(&WifiSerial, &C64Serial);

@@ -59,7 +62,7 @@
   }
   else
   {
-    display2("Failed!");
+    display2("Wi-Fi \nFailed!");
   }
 }

@@ -68,7 +71,7 @@
    C64Serial.println();
    C64Serial.println("Commodore 64 Wi-Fi Modem");
    C64Serial.println("Telnet Test");
-   C64Serial.print("Host: ");
+   C64Serial.print("host: ");
    C64Serial.setTimeout(1000);

    String readString = "";
@@ -110,7 +113,7 @@
    C64Serial.println(message);
 }

-void Telnet (String host)
+void Telnet(String host)
 {
    sprintf(temp, "\n\nOpening Telnet connection to %s", host.c_str() );
    display2(temp);
@@ -125,19 +128,20 @@
    }
    else
    {
-     display2("Connect\nFailed!");
+     display2("Connect \nFailed!");
+     return;
    }

-   TerminalMode();
-
-   wifly.close();
-
-
-   display2("Connection closed");
+   TerminalMode();
+
+
+
 }

 void TerminalMode()
-{
+{
+   C64Serial.println("\nDetermining Connection Type\n");
+   CheckTelnet();
    C64Serial.println("\nEntering Terminal Mode\n");

    while (wifly.available() != -1) // -1 means closed
@@ -152,4 +156,113 @@
         wifly.write( C64Serial.read() );
      }
    }
-}
+
+    wifly.close();
+    display2("Connection closed");
+}
+
+
+
+void CheckTelnet()     //  inquiry host for telnet parameters / negotiate telnet parameters with host
+{
+  int inpint, verbint, optint;                         //    telnet parameters as integers
+
+  // Wait for first character
+  inpint = PeekByte();
+  if (inpint != IAC)
+  {
+    C64Serial.println("Raw TCP Connection Detected");
+    return;   // Not a telnet session
+  }
+
+  C64Serial.println("Telnet Connection Detected");
+
+  // IAC handling
+//  SendTelnetParameters();    // Start off with negotiating
+
+  while (true)
+  {
+    inpint = PeekByte();       //      peek at next character
+
+    if (inpint != IAC)
+    {
+      C64Serial.print("Received inpint=");
+      C64Serial.println(inpint);
+      C64Serial.println("End of IAC Negotiation");
+      return;   // Let Terminal mode handle character
+    }
+
+    inpint = ReadByte();    // Eat IAC character
+    verbint = ReadByte();   // receive negotiation verb character
+
+    C64Serial.print("Received verbint=");
+    C64Serial.println(verbint);
+
+    if (verbint == - 1) continue;                //          if negotiation verb character is nothing break the routine  (should never happen)
+
+    switch (verbint) {                             //          evaluate negotiation verb character
+        case IAC:                                    //          if negotiation verb character is 255 (restart negotiation)
+          continue;                                     //            break the routine
+
+        case 251:                                    //          if negotiation verb character is 251 (will) or
+        case 252:                                    //          if negotiation verb character is 252 (wont) or
+        case 253:                                    //          if negotiation verb character is 253 (do) or
+        case 254:                                    //          if negotiation verb character is 254 (dont)
+          optint = ReadByte();                   //            receive negotiation option character
+
+           C64Serial.print("Received optint=");
+           C64Serial.println(optint);
+
+          if (optint == -1) continue;                   //            if negotiation option character is nothing break the routine
+
+
+          switch (optint) {
+
+            case 3:                                   // if negotiation option character is 3 (suppress-go-ahead)
+              SendTelnetDoWill(verbint, optint);
+              break;
+
+          default:                                     //        if negotiation option character is none of the above (all others)
+              SendTelnetDontWont(verbint, optint);
+            break;                                     //          break the routine
+      }
+    }
+  }
+}
+
+void SendTelnetDoWill(int verbint, int optint)
+{
+  wifly.write(IAC);                           // send character 255 (start negotiation)
+  wifly.write(verbint == 253 ? 253 : 251);    // send character 253 (do) if negotiation verb character was 253 (do) else send character 251 (will)
+  wifly.write(optint);
+}
+
+void SendTelnetDontWont(int verbint, int optint)
+{
+  wifly.write(IAC);                           // send character 255 (start negotiation)
+  wifly.write(verbint == 253 ? 252 : 254);    // send character 252 (wont) if negotiation verb character was 253 (do) else send character 254 (dont)
+  wifly.write(optint);
+}
+
+void SendTelnetParameters()
+{
+  wifly.write(IAC);                           // send character 255 (start negotiation)
+  wifly.write(254);                           // send character 254 (dont)
+  wifly.write(34);                            // linemode
+
+  wifly.write(IAC);                           // send character 255 (start negotiation)
+  wifly.write(254);                           // send character 253 (do)
+  wifly.write(1);                             // echo
+}
+
+int ReadByte()
+{
+    while (wifly.available() == 0) {}
+    return wifly.read();
+}
+
+int PeekByte()
+{
+    while (wifly.available() == 0) {}
+    return wifly.peek();
+}


Temporary version for LikeJar promotion movie with Maarten.

The display is default bright and the cooldown is turned off. Display
brightness is already implemented nicely in previous version. Cooldown
needs it's own pin.

--- LikeJar_5.ino
+++ LikeJar_5.ino
@@ -61,6 +61,7 @@
 byte reset = 6;
 byte resetWant = 6;
 const byte divide = 1;
+int coolDownTicksSet = 20;
 long likes;                     // The number of button presses.
 int num;
 int value;                    // The number displayed on the LEDs.
@@ -72,6 +73,7 @@
 long coolDownTicks = 0;       // Hold delay before a new button press is registered.
 long timer = 0;               // Tick counter, helps count.
 int ignorePress = 0;          // Ignore the button press when coming out of sleep.
+int moduloIndicator = 1;

 int dig1Min = 1;
 int dig1Max = 1;
@@ -79,10 +81,19 @@
 int dig2Max = 3;
 int dig3Min = 5;
 int dig3Max = 5;
-

 void setup()
 {
+
+reset = resetWant = 9;
+dig1Min = 0;
+dig1Max = 3;
+dig2Min = 4;
+dig2Max = 6;
+dig3Min = 7;
+dig3Max = 9;
+
+
   //Set all the LED pins as output.
   for (byte pinCount = 0; pinCount < 9; pinCount++)
   {
@@ -261,13 +272,13 @@
       else if (coolDownTicks == 0)
       {
         likes++;
-        coolDownTicks = 2000;
+        coolDownTicks = coolDownTicksSet;
         eeprom_write_block((const void*)&likes, (void*)0, sizeof(likes));
       }
       else
       {
         // Cooldown wasn't done, restart cooldown as 'punishment' for pressing too soon.
-        coolDownTicks = 3000;
+        coolDownTicks = coolDownTicksSet * 1,5;
       }
       // There was an interaction, reset the sleep timer.
       timer = 0;


Fixed Smoothing example

Fixed Smoothing example

"index" variable name create conflicts with Arduino Due where "index" is
a reserved word for Posix C.

--- build/shared/examples/03.Analog/Smoothing/Smoothing.ino
+++ build/shared/examples/03.Analog/Smoothing/Smoothing.ino
@@ -28,7 +28,7 @@
 const int numReadings = 10;

 int readings[numReadings];      // the readings from the analog input
-int index = 0;                  // the index of the current reading
+int readIndex = 0;              // the index of the current reading
 int total = 0;                  // the running total
 int average = 0;                // the average

@@ -45,18 +45,18 @@

 void loop() {
   // subtract the last reading:
-  total= total - readings[index];
+  total= total - readings[readIndex];
   // read from the sensor:
-  readings[index] = analogRead(inputPin);
+  readings[readIndex] = analogRead(inputPin);
   // add the reading to the total:
-  total= total + readings[index];
+  total= total + readings[readIndex];
   // advance to the next position in the array:
-  index = index + 1;
+  readIndex = readIndex + 1;

   // if we're at the end of the array...
-  if (index >= numReadings)
+  if (readIndex >= numReadings)
     // ...wrap around to the beginning:
-    index = 0;
+    readIndex = 0;

   // calculate the average:
   average = total / numReadings;


Delete unneeded file

Delete unneeded file

--- TeensyStripController-1.03.ino
+++ TeensyStripController-1.03.ino
@@ -1,397 +0,0 @@
-/********************************************************************************************************
- ** TeensyStrip Controller
- ** ----------------------
- **
- ** This Sketch turns a Teensy 3.1, 3.2 or later into a controller for WS2811/WS2812 based led strips.
- ** This strip controller was originally designed for use with the Direct Output Framework, but since
- ** the communication protocol is simple and communication uses the virtual com port of the Teensy
- ** it should be easy to controll the strips from other applications as well.
- **
- ** The most important part of the code is a slightly hacked version (a extra method to set the length of the
- ** strips dynamiccaly has been added) of Paul Stoffregens excellent OctoWS2811 LED Library.
- ** For more information on the lib check out:
- ** https://github.com/PaulStoffregen/OctoWS2811
- ** http://www.pjrc.com/teensy/td_libs_OctoWS2811.html
- **
- *********************************************************************************************************/
- /*
-    License:
-    --------
-    Permission is hereby granted, free of charge, to any person obtaining a copy
-    of this software and associated documentation files (the "Software"), to deal
-    in the Software without restriction, including without limitation the rights
-    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-    copies of the Software, and to permit persons to whom the Software is
-    furnished to do so, subject to the following conditions:
-    The above copyright notice and this permission notice shall be included in
-    all copies or substantial portions of the Software.
-    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-    THE SOFTWARE.
-
-  Required Connections
-  --------------------
-    pin 2:  LED Strip #1    OctoWS2811 drives 8 LED Strips.
-    pin 14: LED strip #2    All 8 are the same length.
-    pin 7:  LED strip #3
-    pin 8:  LED strip #4    A 100 ohm resistor should used
-    pin 6:  LED strip #5    between each Teensy pin and the
-    pin 20: LED strip #6    wire to the LED strip, to minimize
-    pin 21: LED strip #7    high frequency ringining & noise.
-    pin 5:  LED strip #8
-    pin 15 & 16 - Connect together, but do not use
-    pin 4 - Do not use
-    pin 3 - Do not use as PWM.  Normal use is ok.
-
-*/
-
-#include "OctoWS2811Ext.h" //A slightly hacked version of the OctoWS2811 lib which allows for dynamic setting of the number of leds is used.
-
-//Definiton of Major and Minor part of the firmware version. This value can be received using the V command.
-//If something is changed in the code the number should be increased.
-#define FirmwareVersionMajor 1
-#define FirmwareVersionMinor 3
-
-//Defines the max number of leds which is allowed per ledstrip.
-//This number is fine for Teensy 3.2, 3.1. For newer Teensy versions (they dont exists yet) it might be possible to increase this number.
-#define MaxLedsPerStrip 1100
-
-//Defines the Pinnumber to which the built in led of the Teensy is connected.
-//For Teensy 3.2, 3.1 this is pin 13, if you use a newer Teensy version (not available at the time of writing) you might need to change this number.
-#define LedPin 13
-
-// Defines the Pinnumber for the test button which is low when pressed
-#define TestPin 17
-
-//Memory buffers for the OctoWS2811 lib
-DMAMEM int displayMemory[MaxLedsPerStrip*6];
-int drawingMemory[MaxLedsPerStrip*6];
-
-//Variable used to control the blinking and flickering of the led of the Teensy
-elapsedMillis BlinkTimer;
-int BlinkMode;
-elapsedMillis BlinkModeTimeoutTimer;
-
-//Config definition for the OctoWS2811 lib
-const int config = WS2811_RGB | WS2811_800kHz; //Dont change the color order (even if your strip are GRB). DOF takes care of this issue (see config of ledstrip toy)
-
-OctoWS2811Ext leds(MaxLedsPerStrip, displayMemory, drawingMemory, config);
-
-word configuredStripLength=144;
-
-//Setup of the system. Is called once on startup.
-void setup() {
-  Serial.begin(9600); // This has no effect. USB bitrate (12MB) will be used anyway.
-
-  //Initialize the lib for the leds
-  leds.setStripLength(configuredStripLength);
-  leds.begin();
-  leds.show();
-
-  //Initialize the led pin
-  pinMode(LedPin,OUTPUT);
-
-  //Initialize and find value of the test pin
-  pinMode(TestPin,INPUT_PULLUP);
-  if (! digitalRead(TestPin)) {
-    // run test if button is grounded
-    Test();
-  }
-
-  SetBlinkMode(0);
-}
-
-//Main loop of the programm gets called again and again.
-void loop() {
-  // put your main code here, to run repeatedly:
-
-  //Check if data is available
-  if (Serial.available()) {
-
-    byte receivedByte = Serial.read();
-    switch (receivedByte) {
-      case 'L':
-        //Set length of strips
-        SetLedStripLength();
-        break;
-      case 'F':
-        //Fill strip area with color
-        Fill();
-        break;
-      case 'R':
-        //receive data for strips
-        ReceiveData();
-        break;
-      case 'O':
-        //output data on strip
-        OutputData();
-        break;
-      case 'C':
-        //Clears all previously received led data
-        ClearAllLedData();
-        break;
-      case 'V':
-        //Send the firmware version
-        SendVersion();
-        break;
-      case 'M':
-        //Get max number of leds per strip
-        SendMaxNumberOfLeds();
-        break;
-      default:
-        // no unknown commands allowed. Send NACK (N)
-        Nack();
-      break;
-    }
-
-
-    SetBlinkMode(1);
-
-
-  }
-  Blink();
-}
-
-
-//Sets the mode for the blinking of the led
-void SetBlinkMode(int Mode) {
-  BlinkMode=Mode;
-  BlinkModeTimeoutTimer=0;
-}
-
-//Controls the blinking of the led
-void Blink() {
-  switch(BlinkMode) {
-    case 0:
-      //Blinkmode 0 is only active after the start of the Teensy until the first command is received.
-      if(BlinkTimer<1500) {
-        digitalWrite(LedPin,0);
-      } else if(BlinkTimer<1600) {
-        digitalWrite(LedPin,1);
-      } else {
-        BlinkTimer=0;
-        digitalWrite(LedPin,0);
-      }
-    break;
-    case 1:
-      //Blinkmode 1 is activated when the Teensy receives a command
-      //Mode expires 500ms after the last command has been received resp. mode has been set
-      if(BlinkTimer>30) {
-        BlinkTimer=0;
-        digitalWrite(LedPin,!digitalRead(LedPin));
-      }
-      if(BlinkModeTimeoutTimer>500) {
-        SetBlinkMode(2);
-      }
-    break;
-    case 2:
-      //Blinkmode 2 is active while the Teensy is waiting for more commands
-      if(BlinkTimer<1500) {
-        digitalWrite(LedPin,0);
-      } else if(BlinkTimer<1600) {
-        digitalWrite(LedPin,1);
-      } else if(BlinkTimer<1700) {
-        digitalWrite(LedPin,0);
-      } else if(BlinkTimer<1800) {
-        digitalWrite(LedPin,1);
-      }else {
-        BlinkTimer=0;
-        digitalWrite(LedPin,0);
-      }
-      default:
-      //This should never be active
-      //The code is only here to make it easier to determine if a wrong Blinkcode has been set
-      if(BlinkTimer>2000) {
-        BlinkTimer=0;
-        digitalWrite(LedPin,!digitalRead(LedPin));
-      }
-      break;
-  }
-
-}
-
-
-//Outputs the data in the ram to the ledstrips
-void OutputData() {
-   leds.show();
-   Ack();
-}
-
-
-//Fills the given area of a ledstrip with a color
-void Fill() {
-  word firstLed=ReceiveWord();
-
-  word numberOfLeds=ReceiveWord();
-
-  int ColorData=ReceiveColorData();
-
-   if( firstLed<=configuredStripLength*8 && numberOfLeds>0 && firstLed+numberOfLeds-1<=configuredStripLength*8 ) {
-       word endLedNr=firstLed+numberOfLeds;
-       for(word ledNr=firstLed; ledNr<endLedNr;ledNr++) {
-         leds.setPixel(ledNr,ColorData);
-       }
-       Ack();
-   } else {
-     //Number of the first led or the number of leds to receive is outside the allowed range
-     Nack();
-   }
-
-
-}
-
-
-//Receives data for the ledstrips
-void ReceiveData() {
-  word firstLed=ReceiveWord();
-
-  word numberOfLeds=ReceiveWord();
-
-  if( firstLed<=configuredStripLength*8 && numberOfLeds>0 && firstLed+numberOfLeds-1<=configuredStripLength*8 ) {
-    //FirstLedNr and numberOfLeds are valid.
-    //Receive and set color data
-
-    word endLedNr=firstLed+numberOfLeds;
-    for(word ledNr=firstLed; ledNr<endLedNr;ledNr++) {
-      leds.setPixel(ledNr,ReceiveColorData());
-    }
-
-    Ack();
-
-  } else {
-    //Number of the first led or the number of leds to receive is outside the allowed range
-    Nack();
-  }
-}
-
-//Sets the length of the longest connected ledstrip. Length is restricted to the max number of allowed leds
-void SetLedStripLength() {
-   word stripLength=ReceiveWord();
-   if(stripLength<1 || stripLength>MaxLedsPerStrip) {
-     //stripLength is either to small or above the max number of leds allowed
-     Nack();
-   } else {
-     //stripLength is in the valid range
-     configuredStripLength=stripLength;
-     leds.setStripLength(stripLength);
-     leds.begin();  //Reinitialize the OctoWS2811 lib (not sure if this is needed)
-
-     Ack();
-   }
-}
-
-//Clears the data for all configured leds
-void  ClearAllLedData() {
-  for(word ledNr=0;ledNr<configuredStripLength*8;ledNr++) {
-    leds.setPixel(ledNr,0);
-  }
-  Ack();
-}
-
-
-//Sends the firmware version
-void SendVersion() {
-  Serial.write(FirmwareVersionMajor);
-  Serial.write(FirmwareVersionMinor);
-  Ack();
-}
-
-//Sends the max number of leds per strip
-void SendMaxNumberOfLeds() {
-  byte B=MaxLedsPerStrip>>8;
-  Serial.write(B);
-  B=MaxLedsPerStrip&255;
-  Serial.write(B);
-  Ack();
-}
-
-
-//Sends a ack (A)
-void Ack() {
-  Serial.write('A');
-}
-
-//Sends a NACK (N)
-void Nack() {
-  Serial.write('N');
-}
-
-//Receives 3 bytes of color data.
-int ReceiveColorData() {
-  while(!Serial.available()) {};
-  int colorValue=Serial.read();
-  while(!Serial.available()) {};
-  colorValue=(colorValue<<8)|Serial.read();
-  while(!Serial.available()) {};
-  colorValue=(colorValue<<8)|Serial.read();
-
-  return colorValue;
-
-
-}
-
-//Receives a word value. High byte first, low byte second
-word ReceiveWord() {
-  while(!Serial.available()) {};
-  word wordValue=Serial.read()<<8;
-  while(!Serial.available()) {};
-  wordValue=wordValue|Serial.read();
-
-  return wordValue;
-}
-
-// Colors for testing - assumes WS2812 color order of G, R, B
-/*
-#define RED    0x00FF00
-#define GREEN  0xFF0000
-#define BLUE   0x0000FF
-#define YELLOW 0xFFFF00
-#define PINK   0x10FF88
-#define ORANGE 0x45FF00
-#define WHITE  0xFFFFFF
-#define BLACK  0x000000
-*/
-
-// Less intense colors for testing - assumes WS2812 color order of G, R, B
-#define RED    0x001600
-#define GREEN  0x160000
-#define BLUE   0x000016
-#define YELLOW 0x141000
-#define PINK   0x001209
-#define ORANGE 0x041000
-#define WHITE  0x101010
-#define BLACK  0x000000
-
-
-void Test() {
-  int microsec = 3000000;  // change them all in 3 seconds
-
-  ColorWipe(RED, microsec);
-  ColorWipe(GREEN, microsec);
-  ColorWipe(BLUE, microsec);
-  ColorWipe(YELLOW, microsec);
-  ColorWipe(PINK, microsec);
-  ColorWipe(ORANGE, microsec);
-  ColorWipe(WHITE, microsec);
-  ColorWipe(BLACK, microsec);
-}
-
-void ColorWipe(int color, int wait)
-{
-  for (int i=0; i < leds.numPixels(); i++) {
-    leds.setPixel(i, color);
-  }
-
-  // wait before turning on LEDs and also turn on indicator LED
-  delayMicroseconds(100000);
-  digitalWrite(LedPin,1);
-  leds.show();
-
-  // wait for desginated timeout and then turn off indicator LED
-  delayMicroseconds(wait);
-  digitalWrite(LedPin,0);
-}


Stack usage optimization

Stack usage optimization

--- ZUNO_RM80_RadiationMonitor.ino
+++ ZUNO_RM80_RadiationMonitor.ino
@@ -268,8 +268,8 @@
 	if (Val==IntNA)
 		x0=LCD.writeFit(x0,y0,x1,"-",SMLCD_WRITE_TIGHT|SMLCD_WRITE_CENTERY);
 	else
-//		x0=LCD.writeFit(x0,y0,x1,int2Str(Val,DecimalPos),SMLCD_WRITE_TIGHT|SMLCD_WRITE_CENTERY);
-		x0=LCD.writeFit(x0,y0,x1,Val,SMLCD_WRITE_TIGHT|SMLCD_WRITE_CENTERY|SMLCD_WRITE_DECIMALPOS(DecimalPos));
+		x0=LCD.writeFit(x0,y0,x1,int2Str(Val,DecimalPos),SMLCD_WRITE_TIGHT|SMLCD_WRITE_CENTERY);
+		// x0=LCD.writeFit(x0,y0,x1,Val,SMLCD_WRITE_TIGHT|SMLCD_WRITE_CENTERY|SMLCD_WRITE_DECIMALPOS(DecimalPos)); // Requires 8 bytes more stack than the previous line
 	return x0; // Return next character position
 }

@@ -285,8 +285,8 @@
 // this range (including negative values) or if a decimal position is defined.
 void WriteCompact (xy_t x, xy_t y, int Val, unsigned char DecimalPos) {
 	if (DecimalPos!=0 || Val<1000 || Val>=10000) { // Normal writing
-//		LCD.writeS(x,y,int2Str(Val,DecimalPos),SMLCD_WRITE_TIGHT);
-		LCD.writeS(x,y,Val,SMLCD_WRITE_TIGHT|SMLCD_WRITE_DECIMALPOS(DecimalPos));
+		LCD.writeS(x,y,int2Str(Val,DecimalPos),SMLCD_WRITE_TIGHT);
+		// LCD.writeS(x,y,Val,SMLCD_WRITE_TIGHT|SMLCD_WRITE_DECIMALPOS(DecimalPos));  // Requires 8 bytes more stack than the previous line
 	} else { // Short writing (1.2k)
 		xy_t x=LCD.writeChrS(x,y,'0'+(Val/1000),SMLCD_WRITE_TIGHT);
 		x=LCD.writeChrS(x,'.',SMLCD_WRITE_TIGHT);


Fixed controls and added delay between waves

--- space/space.ino
+++ space/space.ino
@@ -21,10 +21,15 @@
 #define C   A2
 #define D   A3

-#define LEFT 11
-#define RIGHT 12
-#define FIRE 13
-#define FIRE2 A4
+#define BUTTON_SW 11
+#define BUTTON_NW A4
+#define BUTTON_SE 12
+#define BUTTON_NE 13
+
+#define LEFT BUTTON_SW
+#define RIGHT BUTTON_NW
+#define FIRE BUTTON_SE
+#define FIRE2 BUTTON_NE

 #define WIDTH 64

@@ -450,9 +455,13 @@
 // Phases
 ////////////////////////////////////////////////////////////

-#define PHASE_LOGO 1
-#define PHASE_GAME 2
-#define PHASE_GAMEOVER 3
+enum Phases
+{
+  PHASE_LOGO,
+  PHASE_GAME,
+  PHASE_NEXT_WAVE,
+  PHASE_GAMEOVER
+};
 uint8_t phase = PHASE_LOGO;

 ////////////////////////////////////////////////////////////
@@ -527,11 +536,11 @@
   }

   // draw cannon
-  if (lives && phase == PHASE_GAME)
+  if (lives && phase == PHASE_GAME || phase == PHASE_NEXT_WAVE)
     sprite_render(&cannon, cannonX, cannonY, buf, y, GREEN);

   // draw shoots
-  if (phase == PHASE_GAME)
+  if (phase == PHASE_GAME || phase == PHASE_NEXT_WAVE)
     for (int i = 0 ; i < SHOOTS ; ++i)
     {
       if (shootY[i] >= 0)
@@ -551,7 +560,7 @@
     sprite_render(&life, LIFE_X + (lifeWidth + 1) * i, LIFE_Y, buf, y, GREEN);

   // draw wave
-  if (phase == PHASE_GAME)
+  if (phase == PHASE_GAME || phase == PHASE_NEXT_WAVE)
   {
     sprite_render(&waveSprite, WAVE_X, WAVE_Y, buf, y, CYAN);
     render_digits(wave, 2, WAVE_X + 1 + sprite_width(&waveSprite), WAVE_Y, buf, y, WHITE);
@@ -719,7 +728,7 @@
     }
   }

-  if (step == 0 && phase == PHASE_GAME && curTime - moveTime >= 20)
+  if (step == 0 && (phase == PHASE_GAME || phase == PHASE_NEXT_WAVE) && curTime - moveTime >= 20)
   {
     moveTime = curTime;

@@ -751,14 +760,16 @@
       for (int i = 0 ; i < wave ; ++i)
         if (invaderType[i])
           haveInvaders = true;
-      if (!haveInvaders && !waveInvaders)
+      if (!haveInvaders && !waveInvaders && phase == PHASE_GAME)
       {
+        phase = PHASE_NEXT_WAVE;
         ++wave;
         invaderType[wave - 1] = 0;
         waveInvaders = wave * 10;
         // Impossible mission
         if (wave == MAX_WAVE)
           waveInvaders = 9999;
+        phaseTime = curTime;
       }

       // kill cannon
@@ -831,6 +842,11 @@
       shootY[i] = -1;
   }

+  if (step == 0 && phase == PHASE_NEXT_WAVE && curTime - phaseTime > 2000)
+  {
+    phase = PHASE_GAME;
+  }
+
   if (step == 0 && phase == PHASE_GAMEOVER && curTime - phaseTime > 3000)
   {
     phase = PHASE_LOGO;


Basic OLED layout

Basic OLED layout

--- experiments/esp8266_monitor/esp8266_monitor.ino
+++ experiments/esp8266_monitor/esp8266_monitor.ino
@@ -16,23 +16,29 @@

   // Initialise the display.
   display.init();
- // display.flipScreenVertically();
-  display.setFont(ArialMT_Plain_24);
+  display.flipScreenVertically();
+  display.setFont(ArialMT_Plain_16);

+  rx_payload.setMsgId(254);
+  rx_payload.setA(1234);
+  rx_payload.setB(5678);
+
+  display.clear();
+  display.drawString(0, 20, String(rx_payload.getMsgId()));
+  display.drawString(0, 45, String(rx_payload.getA()));
+  display.drawString(80, 45, String(rx_payload.getB()));
+  display.display();
 }

 void loop() {

   display.clear();

-  if (payload_state = 2) {
-    display.drawString(20, 0, String(rx_payload.getMsgId()));
-    display.drawString(20, 40, String(rx_payload.getA()));
-    display.drawString(40, 0, String(rx_payload.getB()));
-    payload_state = 0;
-  }
+  display.drawString(0, 0, String(millis()));
+  display.drawString(0, 20, String(rx_payload.getMsgId()));
+  display.drawString(0, 45, String(rx_payload.getA()));
+  display.drawString(80, 45, String(rx_payload.getB()));

-  display.drawString(0, 0, String(millis()));
   display.display();

   delay(10);
@@ -66,7 +72,7 @@
       // so the main loop can do something about it:
       if (serial_byte_count == rx_payload.getPayloadSize()) {
         serial_byte_count = 0;
-        payload_state = 2;
+        payload_state = 0;
         rx_payload.unserialize(input_string);
       }
     }


Moved to MiniMaestro

Moved to MiniMaestro

--- RobotBase.ino
+++ RobotBase.ino
@@ -1,13 +1,15 @@
 #include <BMSerial.h>
 #include <RoboClaw.h>
 #include <Wire.h>
-#include <Adafruit_PWMServoDriver.h>
+#include <PololuMaestro.h>

 #define LED_PIN 13
+#define SSC_RX_PIN 2
+#define SSC_TX_PIN 3

 // host communication //
-#define MAX_COMMAND 10
-#define BUF_SIZE 16
+#define MAX_COMMAND 16
+#define BUF_SIZE 18
 byte buf[BUF_SIZE];
 byte cmd = 0;
 byte bytes = 0;
@@ -34,7 +36,8 @@
 unsigned long driveCommandTimeout = 60000;

 // servos
-Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
+BMSerial ssc(SSC_RX_PIN, SSC_TX_PIN);
+MiniMaestro maestro(ssc);

 // propulsion vars
 #define MOTOR_COUNTER_START 3000
@@ -56,8 +59,6 @@
   // unused pins
   pinMode(LED_PIN, OUTPUT);
   digitalWrite(LED_PIN, LOW);
-  pinMode(2, INPUT_PULLUP);
-  pinMode(3, INPUT_PULLUP);
   pinMode(4, INPUT_PULLUP);
   pinMode(5, INPUT_PULLUP);
   pinMode(6, INPUT_PULLUP);
@@ -74,8 +75,7 @@
   pulsePin(AUX_PIN, 20);

   // servo controller
-  pwm.begin();
-  pwm.setPWMFreq(50);  // servos run at ~50 Hz updates
+  ssc.begin(38400);

   // host communication //
   Serial.begin(38400);
@@ -188,11 +188,11 @@
   else
   if (cmd == 'p') power();
   else
-  if (cmd == 's') servo();
+  if (cmd == 's') servo_maestro();
   else
   if (cmd == 'b') battery();
   else
-  if (cmd == 'v') Serial.println("v5");
+  if (cmd == 'v') Serial.println("v7");
   else
   if (cmd == 'r') _read();
   else
@@ -223,9 +223,9 @@
 //=======================================

 // 'drive' command. both motors in one command
-// ex: DD127127 - drive differential. full forward
-// ex: DD064064 - drive differential. stop
-// ex: DD000000 - drive differential. full backward
+// ex: DD127127 - full forward
+// ex: DD064064 - stop
+// ex: DD000000 - full backward
 void drive()
 {
   cmd = buf[1];
@@ -363,21 +363,57 @@

 //=======================================

-// ex: sp00110 - set servo 00 to the minimum position
-// ex: sp15470 - set servo 15 to the maximum position
-void servo()
-{
-  uint8_t n;
-  uint16_t pulse;
-
+// ex: sp002000 - set servo 00 to the min position
+// ex: sp159999 - set servo 15 to the max position
+void servo_maestro()
+{
+  uint8_t channel;
+  uint16_t value;
   cmd = buf[1];
+  channel = bctoi(2, 2);
+  value = bctoi16(4, 4);
+
+  if (cmd == 'p') // servo position
+  {
+    if (channel < 18) maestro.setTarget(channel, value); else err();
+  }
+  if (cmd == 's') // servo speed
+  {
+    if (channel < 18) maestro.setSpeed(channel, value); else err();
+  }
+  if (cmd == 'a') // servo accel
+  {
+    if (channel < 18) maestro.setAcceleration(channel, value); else err();
+  }
+  else
+  {
+    nak();
+  }
+}
+
+// ex: sp000500 - set servo 00 to the min position
+// ex: sp152500 - set servo 15 to the max position
+void servo_ssc32()
+{
+  uint8_t channel;
+  uint16_t pos, time;
+  cmd = buf[1];

   if (cmd == 'p') // servo pulse
   {
-    n = bctoi(2, 2);
-    pulse = bctoi16(4, 3);
-    if (n > 15) err();
-    else pwm.setPWM(n, 0, pulse);
+    channel = bctoi(2, 2);
+    pos = bctoi16(4, 4);
+    time = bctoi16(8, 4);
+    if (channel > 31) err();
+    else
+    {
+      ssc.print("#");
+      ssc.print(channel);
+      ssc.print("P");
+      ssc.print(pos);
+      if (time > 0) { ssc.print("T"); ssc.print(time); }
+      ssc.println("");
+    }
   }
   else
   {


COH-78: WIP

COH-78: WIP

--- COHEAT2015/20160316-COHEAT-M1/COHEAT-M1/COHEAT-M1.ino
+++ COHEAT2015/20160316-COHEAT-M1/COHEAT-M1/COHEAT-M1.ino
@@ -3,7 +3,7 @@
 //#define CONFIG_REV9 // REV9 as CC1 relay, cut 2 of the board.

 // IF DEFINED: entire comms model switches to secure.
-//#define ENABLE_OTSECUREFRAME_ENCODING_SUPPORT
+#define ENABLE_OTSECUREFRAME_ENCODING_SUPPORT

 #define DEBUG // Uncomment for debug output.

@@ -868,6 +868,7 @@
 // Assigns radio to PrimaryRadio alias.
 OTRadioLink::OTRadioLink &PrimaryRadio = RFM23B;

+// Quickly filter RX traffic to preserve queue space for stuff likely to be of interest.
 #if defined(ALLOW_CC1_SUPPORT_RELAY)
 // For a CC1 relay, ignore everything except FTp2_CC1PollAndCmd messages.
 // With care (not accessing EEPROM for example) this could also reject anything with wrong house code.
@@ -875,11 +876,14 @@
   {
 #ifndef ENABLE_OTSECUREFRAME_ENCODING_SUPPORT
   if((buflen < 8) || (OTRadioLink::FTp2_CC1PollAndCmd != buf[0])) { return(false); }
-  // TODO: filter for only this unit address/housecode as FHT8V.getHC{1,2}() are thread-safe.
+  // Filter for only this unit address/housecode as FHT8V.getHC{1,2}() are thread-safe.
+  if((FHT8V.getHC1() == buf[1]) || (FHT8V.getHC2() == buf[2])) { return(false); }
 #else
   // Expect secure frame with 2-byte ID and empty body.
   if((buflen < 28) || ((0x80|OTRadioLink::FTp2_CC1PollAndCmd) != buf[0])) { return(false); }
-  // TODO: filter for only this unit address/housecode as FHT8V.getHC{1,2}() are thread-safe.
+  // Filter for only this unit address/housecode as FHT8V.getHC{1,2}() are thread-safe.
+  if((buf[1] & 0xf) < 2) { return(false); }
+  if((FHT8V.getHC1() == buf[2]) || (FHT8V.getHC2() == buf[3])) { return(false); }
 #endif // ENABLE_OTSECUREFRAME_ENCODING_SUPPORT
   return(true); // Accept message.
   }


add favicon example

add favicon example

--- examples/Super/OnDemandConfigPortal/OnDemandConfigPortal.ino
+++ examples/Super/OnDemandConfigPortal/OnDemandConfigPortal.ino
@@ -144,11 +144,21 @@
   custom_html.setValue("test",4);
   custom_token.setValue("test",4);

+  // const char* icon = "
+  // <link rel='icon' type='image/png' sizes='16x16' href='data:image/png;base64,
+  // iVBORw0KGgoAAAANSUhEUgAAABAAAAAQBAMAAADt3eJSAAAAMFBMVEU0OkArMjhobHEoPUPFEBIu
+  // O0L+AAC2FBZ2JyuNICOfGx7xAwTjCAlCNTvVDA1aLzQ3COjMAAAAVUlEQVQI12NgwAaCDSA0888G
+  // CItjn0szWGBJTVoGSCjWs8TleQCQYV95evdxkFT8Kpe0PLDi5WfKd4LUsN5zS1sKFolt8bwAZrCa
+  // GqNYJAgFDEpQAAAzmxafI4vZWwAAAABJRU5ErkJggg==' />";
+
+
   // set custom html head content , inside <head>
-  const char* headhtml = "<meta name='color-scheme' content='dark light'><style></style><script></script>";
-  wm.setCustomHeadElement(headhtml);
-
-  // set custom html menu content , inside <head>
+  // examples of favicon, or meta tags etc
+  // const char* headhtml = "<link rel='icon' type='image/png' href='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAADQElEQVRoQ+2YjW0VQQyE7Q6gAkgFkAogFUAqgFQAVACpAKiAUAFQAaECQgWECggVGH1PPrRvn3dv9/YkFOksoUhhfzwz9ngvKrc89JbnLxuA/63gpsCmwCADWwkNEji8fVNgotDM7osI/x777x5l9F6JyB8R4eeVql4P0y8yNsjM7KGIPBORp558T04A+CwiH1UVUItiUQmZ2XMReSEiAFgjAPBeVS96D+sCYGaUx4cFbLfmhSpnqnrZuqEJgJnd8cQplVLciAgX//Cf0ToIeOB9wpmloLQAwpnVmAXgdf6pwjpJIz+XNoeZQQZlODV9vhc1Tuf6owrAk/8qIhFbJH7eI3eEzsvydQEICqBEkZwiALfF70HyHPpqScPV5HFjeFu476SkRA0AzOfy4hYwstj2ZkDgaphE7m6XqnoS7Q0BOPs/sw0kDROzjdXcCMFCNwzIy0EcRcOvBACfh4k0wgOmBX4xjfmk4DKTS31hgNWIKBCI8gdzogTgjYjQWFMw+o9LzJoZ63GUmjWm2wGDc7EvDDOj/1IVMIyD9SUAL0WEhpriRlXv5je5S+U1i2N88zdPuoVkeB+ls4SyxCoP3kVm9jsjpEsBLoOBNC5U9SwpGdakFkviuFP1keblATkTENTYcxkzgxTKOI3jyDxqLkQT87pMA++H3XvJBYtsNbBN6vuXq5S737WqHkW1VgMQNXJ0RshMqbbT33sJ5kpHWymzcJjNTeJIymJZtSQd9NHQHS1vodoFoTMkfbJzpRnLzB2vi6BZAJxWaCr+62BC+jzAxVJb3dmmiLzLwZhZNPE5e880Suo2AZgB8e8idxherqUPnT3brBDTlPxO3Z66rVwIwySXugdNd+5ejhqp/+NmgIwGX3Py3QBmlEi54KlwmjkOytQ+iJrLJj23S4GkOeecg8G091no737qvRRdzE+HLALQoMTBbJgBsCj5RSWUlUVJiZ4SOljb05eLFWgoJ5oY6yTyJp62D39jDANoKKcSocPJD5dQYzlFAFZJflUArgTPZKZwLXAnHmerfJquUkKZEgyzqOb5TuDt1P3nwxobqwPocZA11m4A1mBx5IxNgRH21ti7KbAGiyNn3HoF/gJ0w05A8xclpwAAAABJRU5ErkJggg==' />";
+  // const char* headhtml = "<meta name='color-scheme' content='dark light'><style></style><script></script>";
+  // wm.setCustomHeadElement(headhtml);
+
+  // set custom html menu content , inside menu item "custom", see setMenu()
   const char* menuhtml = "<form action='/custom' method='get'><button>Custom</button></form><br/>\n";
   wm.setCustomMenuHTML(menuhtml);


changing baudrate to 115200 with PR https://github.com/ros-drivers/rosserial/pull/263

--- example/SixLasersROS/SixLasersROS.ino
+++ example/SixLasersROS/SixLasersROS.ino
@@ -104,7 +104,7 @@
 void setup() {
   beginLidars();
   last = micros();
-  nh.initNode();
+  nh.initNode(115200);
   nh.advertise(distance_publisher);
 }


Update number styles

Update number styles


Experiment to try to use a servo on the same timer as the motors

--- alan/alan.ino
+++ alan/alan.ino
@@ -3,7 +3,27 @@
  Two motors attached to the motor shield.
  speaker/piezo for sound

- Arduino Uno has three timers; timer 0, timer 1, timer 2,
+ Arduino Uno has three timers; timer 0, timer 1, timer 2
+ Timers can be used without their output going to the pins, the PWM pins.
+
+  timer 0 (controls pin 5, 6)
+  timer 1 (controls pin 10, 9)
+  timer 2 (controls pin 3, 11)
+
+ Timing functions we use:
+
+  timer 0 - Arduino time functions; millis()
+  timer 1 - Generates the tones for sound
+  timer 2 - Generates the pulses for driving the motors a varying speeds
+
+ PWM (timer) pins we use:
+  timer 0 pin 5  - Unused
+  timer 0 pin 6  - Unused
+  timer 1 pin 9  - Brake for motor A. Can only be used for digitalRead() & digitalWrite()
+  timer 1 pin 10 - Unused.            Can only be used for digitalRead() & digitalWrite()
+  timer 2 pin 3  - Motor A to control speed.
+  timer 2 pin 11 - Motor B to control speed.
+
  Timer 0 is used by the arduino for millis().
  The motorshield uses timer 2, for pwm on pins 3 & 11.
  Since the standard arduino tone function uses timer 2 also,
@@ -16,6 +36,7 @@
  */

 #include <util/delay.h>
+
 #include <NewPing.h> // From https://code.google.com/p/arduino-new-ping/
 #include <NewTone.h> // From https://code.google.com/p/arduino-new-tone/

@@ -23,6 +44,7 @@
 // without stopping everything for a delay.
 #include "SimpleTimer.h"

+#include "ServoTimer2.h"

 #include "Sound.h"

@@ -88,11 +110,13 @@
 // although there is little point in doing so.
 SimpleTimer timer;

-// Creat the sound playing object.
+// Create the sound playing object.
 Sound snd(sound_pin);

+ServoTimer2 servo;
+
 void setup() {
-  Serial.begin(9600); // Open serial monitor at 9600 baud to see ping results.
+  Serial.begin(9600); // Open serial monitor at 9600 baud to see debugging messages.

   // Setup Channel A
@@ -121,6 +145,11 @@
   int timer_battery = timer.setInterval(battery_delay, batteryLevel);
   Serial.print("Battery tick started id=");
   Serial.println(timer_battery);
+
+  int timer_experimental = timer.setInterval(30000, experimental_servoMove);
+  Serial.print("Servo tick started id=");
+  Serial.println(timer_experimental);
+
 }

 void loop()
@@ -430,3 +459,18 @@
   }
 }

+void experimental_servoMove()
+{
+  // Can't move servo & motor at the same time.
+  motion_stop();
+
+  // Stop the motor pins being outputs.
+  pinMode(motorA_pwm, INPUT);
+  pinMode(motorB_pwm, INPUT);
+
+  servo.attach(19);
+  servo.write(1500);
+  delay(1000); // yeah it's experimental
+  servo.detach(); // Our modified detach() that frees the timer for the motors to use again.
+}
+


Changed the shfit out routine a little.

Changed the shfit out routine a little.

--- Arduino/SNES_4021_Emulation/SNES_4021_Emulation.ino
+++ Arduino/SNES_4021_Emulation/SNES_4021_Emulation.ino
@@ -65,12 +65,13 @@
     clocks = 0;
 }

-void clocking(){ //This is somehow fast enough for a lot of games.
-  //Write the least significant bit to the data line, then shift it.
-  if(saveddata & 1) WRITE_DATA_HIGH;
+void clocking(){
+  /* This is somehow fast enough for a lot of games.
+   * Write the least significant bit to the data line, then shift it.
+   * Write data low after the end of the 16th cycle, some games hate it when you don't.
+   * That might have something to do with SNES detecting if a controller is plugged in or not. */
+  clocks++;
+  if((saveddata & 1) && clocks < 16) WRITE_DATA_HIGH;
   else WRITE_DATA_LOW;
   saveddata = saveddata >> 1;
-  clocks++;
-  if (clocks > 15) WRITE_DATA_LOW; //Write data low after the end of the 16th cycle, some games hate it when you don't.
-  //That might have something to do with SNES detecting if a controller is plugged in or not.
 }


Always return an OK or ERR response for commands

Some commands don't return an OK or ERR response, as they respond
with other output (such as usage info or controller status).  This
makes it difficult for a client to know when the controller has
finished sending a multi-line response for a command.

This patch makes all commands end their response with a single
line containing either "OK" or ERR_*".  This effectively terminates
the command response.

--- firmware/removinator/removinator.ino
+++ firmware/removinator/removinator.ino
@@ -469,6 +469,9 @@

     // Return the status via serial.
     Serial.println(status_json);
+
+    // Terminate our serial response.
+    Serial.println(RESP_OK);
 }

 // getCardStatus()
@@ -537,6 +540,9 @@
     } else {
         Serial.println(RESP_DBG_OFF);
     }
+
+    // Terminate our serial response.
+    Serial.println(RESP_OK);
 }

 // debug_print()
@@ -619,4 +625,7 @@
     Serial.print(CMD_HELP);
     Serial.print("\t");
     Serial.println("Show usage information");
-}
+
+    // Terminate our serial response.
+    Serial.println(RESP_OK);
+}


Optimized scrollCredits() a little.

Optimized scrollCredits() a little.

--- arduboy-game/arduboy-game.ino
+++ arduboy-game/arduboy-game.ino
@@ -262,27 +262,24 @@
   scrollCredits(4, false);
 }

-void scrollCredits(int y, bool quit) {
+void scrollCredits(byte y, bool quit) {
   /**
      Recursive function for scrolling
      credits up screen
   */
   byte padding = 7;
-  byte textSize = 1;
-  int origY = y;
+  byte origY = y;
   arduboy.clear();

   for (unsigned short i = 0; i < NUM_CREDITS; i++) {
     if (i == 0) {
-      textSize = 2;
       y = y - 4;
     } else {
-      textSize = 1;
       y = origY;
     }

     strcpy_P(textBuf, (char*)pgm_read_word(&(credits[i])));
-    printText(textBuf, 2, y + padding, textSize);
+    printText(textBuf, 2, y + padding, (i == 0 ? 2 : 1));
     arduboy.display();
     padding = padding + 15;
     if ( i + 1 == NUM_CREDITS && y + padding < 0) {
@@ -290,10 +287,9 @@
     }
   }
   delay(1000);
-  y = y - 15;

   if (!quit) {
-    scrollCredits(y, quit);
+    scrollCredits(y - 15, quit);
   }
 }


update sketch

update sketch

--- testing/arduino/self-driving.ino
+++ testing/arduino/self-driving.ino
@@ -4,22 +4,16 @@
 const uint8_t trigPin = 9;
 const uint8_t echoPin = 10;

+const uint8_t ledPin = 11;
+
 const uint8_t motorPin1_1 = 4;
 const uint8_t motorPin1_2 = 5;
-const uint8_t motorPin1_speed = 3;
-const uint8_t motorPin1_A = A7;

 const uint8_t motorPin2_1 = 7;
 const uint8_t motorPin2_2 = 8;
-const uint8_t motorPin2_speed = 6;
-const uint8_t motorPin2_A = A6;

-/*
-const uint8_t motorPin3_1 = 10;
-const uint8_t motorPin3_2 = 11;
-const uint8_t motorPin3_speed = 9;
-const uint8_t motorPin3_A = A5;
-*/
+
+const uint8_t motorEnablePin = 3;

 const uint8_t rangeLimit = 15;

@@ -32,23 +26,16 @@
     pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
     pinMode(echoPin, INPUT); // Sets the echoPin as an Input

+
+    pinMode(motorEnablePin, OUTPUT);
+    analogWrite(motorEnablePin, 255);
+
     // Motor
     pinMode(motorPin1_1, OUTPUT);
     pinMode(motorPin1_2, OUTPUT);
-    pinMode(motorPin1_speed, OUTPUT);
-    pinMode(motorPin1_A, INPUT);

     pinMode(motorPin2_1, OUTPUT);
     pinMode(motorPin2_2, OUTPUT);
-    pinMode(motorPin2_speed, OUTPUT);
-    pinMode(motorPin2_A, INPUT);
-
-    /*
-    pinMode(motorPin3_1, OUTPUT);
-    pinMode(motorPin3_2, OUTPUT);
-    pinMode(motorPin3_speed, OUTPUT);
-    pinMode(motorPin3_A, INPUT);
-    */

     Serial.begin(9600); // Starts the serial communication
 }
@@ -77,9 +64,8 @@
 }

-void SetMotor(int pinSpeed, int pin1, int pin2, int speed)
+void SetMotor(int pin1, int pin2, int speed)
 {
-    analogWrite(pinSpeed, abs(speed));
     if (speed < 0)
     {
         analogWrite(pin1, 0);
@@ -107,18 +93,16 @@
     if(spinCompleted && range > 0 && range > rangeLimit)
     {
         // drive
-        SetMotor(motorPin1_speed, motorPin1_1, motorPin1_2, 255);
-        SetMotor(motorPin2_speed, motorPin2_1, motorPin2_2, 255);
-        //SetMotor(motorPin3_speed, motorPin3_1, motorPin3_2, 0);
+        SetMotor(motorPin1_1, motorPin1_2, 255);
+        SetMotor(motorPin2_1, motorPin2_2, 255);
     }
     else
     {
         spinCompleted = false;

         // rotate
-        SetMotor(motorPin1_speed, motorPin1_1, motorPin1_2, 255);
-        SetMotor(motorPin2_speed, motorPin2_1, motorPin2_2, 0);
-        //SetMotor(motorPin3_speed, motorPin3_1, motorPin3_2, 0);
+        SetMotor(motorPin1_1, motorPin1_2, 255);
+        SetMotor(motorPin2_1, motorPin2_2, 0);

         if(range > (rangeLimit * 2))
         {


freeMemory.ino: add introductory comment

--- libraries/MemoryFree/examples/freeMemory/freeMemory.ino
+++ libraries/MemoryFree/examples/freeMemory/freeMemory.ino
@@ -1,4 +1,8 @@
 /*
+ * freeMemory.ino: This sketch demonstrates the use of the freeMemory()
+ * function to measure the amount of free memory available in the system,
+ * before and after using 'malloc' to allocate some memory.
+ *
  * Copyright (c) 2016 Intel Corporation.  All rights reserved.
  * See the bottom of this file for the license terms.
  */


add comments

add comments

add comments on orientation bug

--- b_Parser.ino
+++ b_Parser.ino
@@ -331,7 +331,8 @@
           setting.p.lcd = buf[13];
           break;
         case 9: // orientation
-          // there's a bug in v4.0.0 firmware that prevents from setting orientation to AUTO
+          // orientation can be set only by using this command.
+          // there's a orientation byte in bulk setting transfer but it will be ignored. (default firmware's bug)
           setting.p.setup.orientation = buf[13];
           break;
         case 11: // default mode
@@ -377,7 +378,7 @@
           setting.p.setup.auto_power_down = buf[21];
           setting.p.setup.led = buf[22];
           setting.p.setup.quick_capture = buf[23];
-          setting.p.setup.orientation = buf[24];
+          setting.p.setup.orientation = buf[24]; // this byte is ignored by camera (default firmware's bug)
           setting.p.setup.lcd_brightness = buf[25];
           setting.p.setup.lcd_sleep = buf[26];
           setting.p.setup.lcd_lock = buf[27];


Add comment to the NUIDRead.

Add comment to the NUIDRead.

--- examples/ReadNUID/ReadNUID.ino
+++ examples/ReadNUID/ReadNUID.ino
@@ -50,7 +50,7 @@
     if ( ! rfid.PICC_IsNewCardPresent())
         return;

-    // Lee tarjeta
+    // Verifica si el NUID ha sido leído
     if ( ! rfid.PICC_ReadCardSerial())
         return;


configured interrupt pin properly

configured interrupt pin properly

--- gestureDetection/gestureDetection.ino
+++ gestureDetection/gestureDetection.ino
@@ -66,8 +66,7 @@
   pinMode(7,OUTPUT);
   pinMode(13, OUTPUT);
   digitalWrite(13,LOW);
-  pinMode(2,OUTPUT);
-  attachInterrupt(digitalPinToInterrupt(2),ISR_interrupt,FALLING);
+  attachInterrupt(0,ISR_interrupt,FALLING);
   Serial.begin(9600);
 }
 void loop(){


Drew's font fully integrated with title screen. Fixed drawRect calls for the new dimensions. `Sketch uses 27,896 bytes (97%)`

--- arduboy-game/arduboy-game.ino
+++ arduboy-game/arduboy-game.ino
@@ -163,10 +163,10 @@
 //  drawBitmap(4, 51, titleMenuOptions, 0);

-  drawChrs(4, 51, titleScreenText1, 20);
-  drawChrs(30, 51, titleScreenText2, 20);
-  drawChrs(76, 51, titleScreenText3, 20);
-  arduboy.drawRect(2, 48, 29, 12, 1);
+  drawChrs(4, 51, titleScreenText1, 30);
+  drawChrs(34, 51, titleScreenText2, 30);
+  drawChrs(79, 51, titleScreenText3, 30);
+  arduboy.drawRect(2, 48, 28, 12, 1);
   arduboy.display();

 //  playMusic(5);
@@ -223,15 +223,15 @@
   */
   switch (selectedItem) {
     case TITLE_SETTINGS:
-      arduboy.drawRect(76, 48, 51, 12, 0);
-      arduboy.drawRect(30, 48, 45, 12, 1);
+      arduboy.drawRect(77, 48, 50, 12, 0);
+      arduboy.drawRect(32, 48, 42, 12, 1);
       arduboy.display();
       return TITLE_CREDITS;
       break;

     case TITLE_CREDITS:
-      arduboy.drawRect(30, 48, 45, 12, 0);
-      arduboy.drawRect(2, 48, 29, 12, 1);
+      arduboy.drawRect(32, 48, 42, 12, 0);
+      arduboy.drawRect(2, 48, 28, 12, 1);
       arduboy.display();
       return  TITLE_PLAY_GAME;
       break;
@@ -248,15 +248,15 @@
   */
   switch (selectedItem) {
     case TITLE_PLAY_GAME:
-      arduboy.drawRect(2, 48, 29, 12, 0);
-      arduboy.drawRect(30, 48, 45, 12, 1);
+      arduboy.drawRect(2, 48, 28, 12, 0);
+      arduboy.drawRect(32, 48, 42, 12, 1);
       arduboy.display();
       return TITLE_CREDITS;
       break;

     case TITLE_CREDITS:
-      arduboy.drawRect(30, 48, 45, 12, 0);
-      arduboy.drawRect(76, 48, 51, 12, 1);
+      arduboy.drawRect(32, 48, 42, 12, 0);
+      arduboy.drawRect(77, 48, 50, 12, 1);
       arduboy.display();
       return TITLE_SETTINGS;
       break;


`HI SCORES -> HIGH SCORES`

`HI SCORES -> HIGH SCORES`

--- arduboy-game/arduboy-game.ino
+++ arduboy-game/arduboy-game.ino
@@ -271,8 +271,10 @@
   char hiScore[7];

   arduboy.clear();
-  printText("HI SCORES", 8, 1, 2);
-
+
+  printText("HIGH", 0, 1, 2);
+  printText("SCORES", 58, 1, 2);
+
   for (byte i = 0; i < NUM_HIGH_SCORES; i++) {
     strncpy(hiInitials, highScoreTable + ((9 * i) * sizeof(char)), 3);
     hiInitials[3] = '\0';


Removed misleading comment

Removed misleading comment

--- arduboy-game/arduboy-game.ino
+++ arduboy-game/arduboy-game.ino
@@ -65,7 +65,6 @@
 //  }
 //};

-// TODO highScoreTable should be replaced with table in EEPROM
 char highScoreTable[27] = "AAA000300BBB000200CCC000100";

 unsigned long inGameAButtonLastPress, inGameBButtonLastPress, inGameLastDeath, score;


a few tweaks to the trigger example

a few tweaks to the trigger example

- report battery level once every 5 mins
- drop minimum battery voltage to 3.14V from 3.2V

--- esp8266/trigger/trigger.ino
+++ esp8266/trigger/trigger.ino
@@ -39,9 +39,9 @@
   // get the current count position from eeprom
   byte battery_count = EEPROM.read(0);

-  // we only need this to happen once every minute,
+  // we only need this to happen once every 5 minutes,
   // so we use eeprom to track the count between resets.
-  if(battery_count >= 30) {
+  if(battery_count >= 150) {
     // reset counter
     battery_count = 0;
     // report battery level to Adafruit IO
@@ -110,12 +110,12 @@
   // analog read level is 10 bit 0-1023 (0V-1V).
   // our 1M & 220K voltage divider takes the max
   // lipo value of 4.2V and drops it to 0.758V max.
-  // this means our min analog read value should be 590 (3.2V battery)
-  // and the max analog read value should be 774 (4.2V battery).
+  // this means our min analog read value should be 580 (3.14V)
+  // and the max analog read value should be 774 (4.2V).
   int level = analogRead(A0);

   // convert battery level to percent
-  level = map(level, 590, 774, 0, 100);
+  level = map(level, 580, 774, 0, 100);

   // turn on wifi if we aren't connected
   if(WiFi.status() != WL_CONNECTED)


Refactor LCD code to reduce code duplication.

--- src/CuringChamberControl.ino
+++ src/CuringChamberControl.ino
@@ -94,6 +94,7 @@
 void updateState (ControlledValue &variable);
 void getCurrentRuntime (int &days, int &hours, int &minutes, int &seconds);
 void updateAverages (float temp, float humidity);
+void writeDataToLCD (int column, int row, float temp, float humidity);
 void printTime ();

@@ -220,16 +221,7 @@

     lcd.setCursor(0,0);
     lcd.print ("Now:  ");
-    lcd.setCursor(6,0);
-    lcd.print (temperature.current);
-    lcd.setCursor(10,0);
-    lcd.print ((char)223);
-    lcd.setCursor(11,0);
-    lcd.print ("C ");
-    lcd.setCursor (13,0);
-    lcd.print (humidity.current);
-    lcd.setCursor (15,0);
-    lcd.print ("%      ");
+    writeDataToLCD (6, 0, temperature.current, humidity.current);

     lcd.setCursor(0,1);
     switch (_lcdLine) {
@@ -238,43 +230,16 @@
           lcd.print ("No averages yet");
         } else {
           lcd.print ("Hour: ");
-          lcd.setCursor (6,1);
-          lcd.print (_averageTempLastHour);
-          lcd.setCursor (10,1);
-          lcd.print ((char)223);
-          lcd.setCursor(11,1);
-          lcd.print ("C ");
-          lcd.setCursor (13,1);
-          lcd.print (_averageHumidityLastHour);
-          lcd.setCursor(15,1);
-          lcd.write("%");
+          writeDataToLCD (6, 1, _averageTempLastHour, _averageHumidityLastHour);
         }
         break;
       case 1:
         lcd.print ("Week: ");
-        lcd.setCursor (6,1);
-        lcd.print (_averageTempLastDay);
-        lcd.setCursor (10,1);
-        lcd.print ((char)223);
-        lcd.setCursor(11,1);
-        lcd.print ("C ");
-        lcd.setCursor (13,1);
-        lcd.print (_averageHumidityLastDay);
-        lcd.setCursor(15,1);
-        lcd.write("%");
+        writeDataToLCD (6, 1, _averageTempLastDay, _averageHumidityLastDay);
         break;
       case 2:
         lcd.print ("Month:");
-        lcd.setCursor (6,1);
-        lcd.print (_averageTempLastMonth);
-        lcd.setCursor (10,1);
-        lcd.print ((char)223);
-        lcd.setCursor(11,1);
-        lcd.print ("C ");
-        lcd.setCursor (13,1);
-        lcd.print (_averageHumidityLastMonth);
-        lcd.setCursor(15,1);
-        lcd.write("%");
+        writeDataToLCD (6, 1, _averageTempLastMonth, _averageHumidityLastMonth);
         break;
     }
     _lcdLine++;
@@ -376,6 +341,27 @@
   Serial.print ("\t");
   Serial.print (seconds);
   Serial.print ("\t");
+}
+
+
+void writeDataToLCD (int column, int row, float temp, float humidity)
+{
+  // The format is "##.#°C ##%" and takes 10 columns total
+  if (column > 6) {
+    lcd.setCursor (0,row);
+    lcd.write ("!Bad LCD column!");
+  } else {
+    lcd.setCursor (column,row);
+    lcd.print (_averageTempLastMonth);
+    lcd.setCursor (column+4,row);
+    lcd.print ((char)223); // The degree symbol
+    lcd.setCursor(column+5,row);
+    lcd.print ("C ");
+    lcd.setCursor (column+7,row);
+    lcd.print (_averageHumidityLastMonth);
+    lcd.setCursor(column+9,row);
+    lcd.write("%");
+  }
 }


Update mobicle.ino

Update mobicle.ino

--- firmware/examples/mobicle.ino
+++ firmware/examples/mobicle.ino
@@ -6,16 +6,19 @@

 //Bus Scan (186)
 // [1] - chunk: 0=1-32, 1=33-64, 2=65-96, 3=97-127
+//-----------

 //Packet of packets (187)
 // [1] 1st packet length
 // [2-[[1]+1]] 1st packet
+//-----------

 //i2c_read - i2c_write (188)
 // [1] - Address: i2c chip address
 // [2] - Write length: number of subsequent bytes to be written
 // [3] - Bytes to be read back
 // [4] - (val(2)+2) - Bytes to be written
+//-----------

 //i2c_write_mask (189)
 // [1] - Address: i2c chip address
@@ -31,6 +34,7 @@
 //set only relay 1 to on
 // i2c_write_mask:  i2c address:    Mask op:    Masked Offsets: Read command length:    Read command bytes: Read bytes: Write command length:   Write command bytes:    Bytes to read after write
 // 1:               32:             0:          16:             1:                      10:                 1:          2:                      10:1:                   0
+//------------

 //Delay (190)
 // [1] MSB


fixed an incorrect extreme condition on-off timer control

--- QmoteRHTlogger_w_Daikin/QmoteRHTlogger_w_Daikin.ino
+++ QmoteRHTlogger_w_Daikin/QmoteRHTlogger_w_Daikin.ino
@@ -382,8 +382,8 @@

       // the following conditions will ignore the ON-OFF timer
       if(
-         (((float) curHeatIndex) >= ((float) HEAT_INDEX_TOO_HIGH)) ||                                       // heat index too high
-         (((float) currentTemp) <= ((float) TEMP_TOO_LOW)) ||                                               // temperature too low
+         (isOn == MODE_OFF && ((float) curHeatIndex) >= ((float) HEAT_INDEX_TOO_HIGH)) ||                   // heat index too high
+         (isOn != MODE_OFF && ((float) currentTemp) <= ((float) TEMP_TOO_LOW)) ||                           // temperature too low
          (isOn == MODE_COOLING && ((float) currentTemp) < ((float) TEMP_LOW) && currentRh > RH_LOW) ||      // cooling -> dehumidifier
          (isOn == MODE_DEHUMIDIFIER &&                                                                      // dehumidifier -> cooling
           ((((float) currentTemp) > ((float) TEMP_LOW) && currentRh < RH_LOW) ||


added motorTestState

added motorTestState

--- CandyMachine.ino
+++ CandyMachine.ino
@@ -9,7 +9,7 @@
 */
 #include <Keypad.h>
 #include <FiniteStateMachine.h>
-#define NUMBER_OF_STATES 1
+#define NUMBER_OF_STATES 3
 const byte ROWS = 4; //four rows
 const byte COLS = 4; //three columns
 char keys[ROWS][COLS] = {
@@ -24,19 +24,21 @@

 Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
 byte ledPin = 13;
+byte motorPin = 12;

 boolean blink = false;
 boolean ledPin_state;

 State Standby = State(standbyState);
 State Processing = State(processingState);
+State MotorTest = State(motorTestState);

 FSM ArduinoStateMachine = FSM(Standby);

 void setup(){
 	Serial.begin(9600);
-	Serial.println("start");
 	pinMode(ledPin, OUTPUT);              // Sets the digital pin as output.
+	pinMode(motorPin, OUTPUT);				//dummy motor
 	digitalWrite(ledPin, HIGH);           // Turn the LED on.
 	ledPin_state = digitalRead(ledPin);   // Store initial LED state. HIGH when LED is on.
 	keypad.addEventListener(keypadEvent); // Add an event listener for this keypad
@@ -44,19 +46,27 @@
 }

 void loop(){
-	ArduinoStateMachine.update();
+	ArduinoStateMachine.update(); //starts the function that's part of the state
 }

 void standbyState(){
-	handleKeyboard();
+	checkKeyboard();
 }
 void processingState(){
 	delay(2000);
 	ArduinoStateMachine.transitionTo(Standby);
 }
+void motorTestState(){
+	digitalWrite(motorPin, HIGH);
+	//delay(1000);
+	digitalWrite(motorPin, LOW);
+	//ArduinoStateMachine.transitionTo(Standby);
+	checkKeyboard();
+}

-void handleKeyboard(){
-	char key = keypad.getKey();
+//function that reads does some debugging and show-off for the keyboard
+void checkKeyboard(){
+	char key = keypad.getKey(); //vital to the workings of the keyboard

 	if (key) {
 		Serial.println(key);
@@ -78,6 +88,12 @@
 		else if (key == '5'){
 			ArduinoStateMachine.transitionTo(Processing);
 		}
+		else if (key == '1'){
+			ArduinoStateMachine.transitionTo(MotorTest);
+		}
+		else if (key == '2'){
+			ArduinoStateMachine.transitionTo(Standby);
+		}
 		break;

 	case RELEASED:


using EnableInterrupt lib

using EnableInterrupt lib

--- TICC/TICC.ino
+++ TICC/TICC.ino
@@ -59,12 +59,14 @@

   PICcount = 0;
   pinMode(COARSEint, INPUT);
+  pinMode(STOP_A, INPUT);
+  pinMode(STOP_B, INPUT);
   pinMode(STOPAint, INPUT);
   pinMode(STOPBint, INPUT);

   enableInterrupt(COARSEint, coarseTimer, RISING);
-  enableInterrupt(STOPAint, catch_stopA, RISING);
-  enableInterrupt(STOPBint, catch_stopB, RISING);
+  enableInterrupt(STOP_A, catch_stopA, RISING);
+  enableInterrupt(STOP_B, catch_stopB, RISING);

 //  attachInterrupt(digitalPinToInterrupt(COARSEint), coarseTimer, FALLING); // falling edge avoids timing issue
 //  attachInterrupt(digitalPinToInterrupt(STOPAint), catch_stopA, RISING);
@@ -129,7 +131,7 @@
         // done with chip, so get ready for next reading
         channels[i].ready_next(); // Re-arm for next measurement, clear TDC INTB

-        channels[i].ts = (channels[i].PICstop * (uint64_t)PICTICK_PS) - channels[i].tof;
+        channels[i].ts = (channels[i].PICstop * PICTICK_PS) - channels[i].tof;

         if (channels[i].totalize++ > 1) {  // first few readings likely to be bogus
 //          print_unsigned_picos_as_seconds(PICcount);Serial.print(" ");
@@ -201,7 +203,7 @@
   }

   AVG_CYCLES = 0x00;  // 0x00 for 1 measurement cycle
-  NUM_STOP = 0x00;    // SHOULD BE 0x00 for 1 stop but that doesn't work
+  NUM_STOP = 0x01;    // SHOULD BE 0x00 for 1 stop but that doesn't work

   reg_byte = CALIBRATION2_PERIODS | AVG_CYCLES | NUM_STOP;
   write(CONFIG2, reg_byte);
@@ -211,8 +213,8 @@
  //write(CLOCK_CNTR_STOP_MASK_L, 0x01); // was 0x00 // hold off no clocks before enabling STOP
  //write(COARSE_CNTR_OVF_H, 0x0F);  //was 0xF0  -- only doing this because STOP doesn't raise INTB
  //write(COARSE_CNTR_OVF_L, 0x00);
- //write(CLOCK_CNTR_OVF_H, 0xF0);   // was 0xF0
- //write(CLOCK_CNTR_OVF_L, 0x00);  // was 0x00
+ write(CLOCK_CNTR_OVF_H, 0x03);   // was 0xF0
+ write(CLOCK_CNTR_OVF_L, 0x00);  // was 0x00

 }

@@ -220,7 +222,7 @@
 void tdc7200Channel::ready_next() {
 // needs to set the enable bit (START_MEAS in CONFIG1)
 // clears interrupt bits
- byte FORCE_CAL = 0x00;      // 0x80 forces cal even if timeout; 0x00 means no cal if measurement interrupted
+ byte FORCE_CAL = 0x80;      // 0x80 forces cal even if timeout; 0x00 means no cal if measurement interrupted
  byte PARITY_EN = 0x00;      // parity on would be 0x40
  byte TRIGG_EDGE = 0x00;     // TRIGG rising edge; falling edge would be 0x20
  byte STOP_EDGE = 0x00;      // STOP rising edge; falling edge would be 0x10


added handshaking capability to arduino2.ino code

--- working_directory/arduino_codes/arduino2/arduino2.ino
+++ working_directory/arduino_codes/arduino2/arduino2.ino
@@ -19,9 +19,13 @@
 int pick_command = 97; // "a"
 int place_command= 98; // "b"
 int move_command = 99; // "c"
+int handshake_command = 104; //"h"
+
 char OKAY_CHARACTER = 'O';
 char DONE_CHARACTER = 'D';
 char NOT_OKAY_CHARACTER = 'N';
+char ARDUINO_NUMBER = '2';
+
 int DELAY = 3000;

 Servo rotation_servo;
@@ -59,6 +63,9 @@
       // _blink_();
       Serial.write(OKAY_CHARACTER);

+      if(command == handshake_command) {
+        Serial.write(ARDUINO_NUMBER);
+      }
       if(command == move_command) {
         move(parameter);
         Serial.write(DONE_CHARACTER);


Small changes

Small changes

--- SensorimotorController/SenseAndMove/SuperSensor.ino
+++ SensorimotorController/SenseAndMove/SuperSensor.ino
@@ -1,7 +1,12 @@
 #include <Wire.h>

+
+// Integrated Sensor Gy9250
+
+// Compass Sensor
 #define HMC5883_ADDRESS 0x1E

+// Barometric and temperature sensor.
 //Define o endereco I2C do BMP085 - 0x77 ou 119 em decimal
 #define BMP085_ADDRESS 0x77
 // Define o endereco do HMC5883 - 0x1E ou 30 em decimal
@@ -90,7 +95,7 @@
   //Serial.begin(9600);
   Wire.begin();

-  Serial.println("Initializing BMP085 (Pressure and Temp)");
+  Serial.println("BMP085 (Pressure and Temp)");
   // Inicializa o BMP085
   bmp085Calibration();
 }


fiddled around, got temp published but only once per boot!

--- ardesp/mqtt_test/mqtt_test.ino
+++ ardesp/mqtt_test/mqtt_test.ino
@@ -8,6 +8,8 @@

 #include <ESP8266WiFi.h>
 #include <PubSubClient.h>
+#include <OneWire.h>
+#include <DallasTemperature.h>

 const char *ssid =	"UnionSt Coworking 4G1";		// cannot be longer than 32 characters!
 const char *pass =	"welcometounionst4g1";		//
@@ -21,6 +23,14 @@

 WiFiClient wclient;
 PubSubClient client(wclient, server);
+
+/////////////////////////////////////////////////////////////////////////////
+// temperature sensor stuff /////////////////////////////////////////////////
+OneWire ds(2); // DS1820 on pin 2 (a 4.7K resistor is necessary)
+DallasTemperature tempSensor(&ds);  // pass through reference to library
+float waterCelsius;
+boolean GOT_TEMP_SENSOR = false; // we'll change later if we detect sensor
+DeviceAddress tempAddr; // array to hold device address

 void setup()
 {
@@ -45,15 +55,30 @@
     Serial.println("WiFi connected");
     Serial.println(WiFi.localIP());
   }
-
-  if (client.connect("arduinoClient")) {
-    client.publish("outTopic","hello world!!");
-    client.subscribe("inTopic");
+
+  tempSensor.begin();     // start the onewire temperature sensor
+  if(tempSensor.getDeviceCount()==1) {
+    GOT_TEMP_SENSOR = true;
+    tempSensor.getAddress(tempAddr, 0);
+    tempSensor.setResolution(tempAddr, 12); // 12 bit res (DS18B20 does 9-12)
   }
 }

 void loop()
 {
   client.loop();
+    tempSensor.requestTemperatures(); // send command to get temperatures
+  waterCelsius = tempSensor.getTempC(tempAddr);
+  Serial.print("Temp: ");
+  Serial.print(waterCelsius);
+  Serial.println(" C, ");
+
+  if (client.connect("arduinoClient")) {
+    char BUFFER[10];
+    char *wc;
+    wc = dtostrf(waterCelsius,4,2,BUFFER);
+  client.publish("outTopic",wc);
+  }
+  delay(500);
 }


Cleanup

Cleanup

--- crossbow.ino
+++ crossbow.ino
@@ -1,19 +1,3 @@
-/*
-
-TODO
-
-* Watchdog to go back to IDLE if frame did not completed in reasonable timer
-* Watchdog to force PPM output to LOW if RC_DATA was not received in 500ms aka filsafe
-* Telemetry feedback from RX to TX
-* Some kind of alarm when RSSI goes LOW
-* ability for RX and TX to change frequency
-* serial passtrough (?)
-FIXME
-
-* RX canTransmit is always false. For unknown reason first received frame does not enables it
-
-*/
-
 // #define LORA_HARDWARE_SERIAL
 #define LORA_HARDWARE_SPI


Changed retry delay to 5 seconds.

Changed retry delay to 5 seconds.

--- KISSLoRa-demo_app/KISSLoRa-demo_app.ino
+++ KISSLoRa-demo_app/KISSLoRa-demo_app.ino
@@ -200,11 +200,11 @@
   */
   if (OVERRIDE || strcmp(appEui_from_RN2483, "0000000000000000") == 0)
   {
-    ttn.join(appEUI, appKey, RETRIES, 1);
+    ttn.join(appEUI, appKey, RETRIES, 5000);  //retry "RETRIES" times, wait 5000 ms between retries
   }
   else
   {
-    ttn.join(RETRIES, 1);
+    ttn.join(RETRIES, 5000);//retry "RETRIES" times, wait 5000 ms between retries
   }
   joined_network = 1;
   set_rgb_led(0,0,0);


Included timestamps in the MAVLink msgs, fixed rates.

--- aeroprobe.ino
+++ aeroprobe.ino
@@ -11,13 +11,13 @@
 #include "mavlink/ceaufmg/mavlink.h"

-#define ALPHA_PERIOD_MS 5
-#define QBAR_PERIOD_MS 100
-#define PRESS_PERIOD_MS 10
-#define TEMP_PERIOD_MS 500
+#define ALPHA_PERIOD_US 30000
+#define QBAR_PERIOD_US 100000L
+#define PRESS_PERIOD_US 100000L
+#define TEMP_PERIOD_US 1000000L

-#define PRESS_CONV_MS 5
-#define TEMP_CONV_MS 5
+#define PRESS_CONV_US 4500
+#define TEMP_CONV_US 4500

 class HX711 {
@@ -75,58 +75,72 @@

 void loop() {
-  static uint32_t last_alpha_meas = 0;
-  static uint32_t last_qbar_meas = 0;
-  static uint32_t last_press_meas = 0;
-  static uint32_t last_temp_meas = 0;
+  static uint64_t last_alpha_meas = 0;
+  static uint64_t last_qbar_meas = 0;
+  static uint64_t last_press_meas = 0;
+  static uint64_t last_temp_meas = 0;
   static bool converting_temp = false;
   static bool converting_press = false;
+  static uint8_t micros_overflow_count = 0;
+  static uint32_t last_clock = 0;

-  uint32_t now = millis();
+  uint32_t clock = micros();
+
+  // Detect micros overflow
+  if ((last_clock & 0x80000000L) && !(clock & 0x80000000L))
+      micros_overflow_count++;
+  last_clock = clock;
+  uint64_t now = ((uint64_t)micros_overflow_count << 32) | clock;

   // Temperature measurement
-  if (!converting_temp && (now - last_temp_meas) > TEMP_PERIOD_MS) {
+  if (!converting_temp && (now - last_temp_meas) > TEMP_PERIOD_US) {
     bmp180.triggerTemperatureMeasurement();
     converting_temp = true;
     last_temp_meas = now;
-  } else if (converting_temp && (now - last_temp_meas) > TEMP_CONV_MS) {
+    return;
+  } else if (converting_temp && (now - last_temp_meas) > TEMP_CONV_US) {
     converting_temp = false;
     int32_t temp = bmp180.readTemperature();
-    mavlink_msg_data_int_send(MAVLINK_COMM_0, 0,
+    mavlink_msg_data_int_send(MAVLINK_COMM_0, last_temp_meas,
                               CEAFDAS_DATA_SOUCE_TEMPERATURE_RAW, temp);
+    return;
   }

   // Pressure measurement
   if (!converting_temp && !converting_press &&
-      (now - last_press_meas) > PRESS_PERIOD_MS) {
+      (now - last_press_meas) > PRESS_PERIOD_US) {
     bmp180.triggerPressureMeasurement();
     converting_press = true;
     last_press_meas = now;
-  } else if (converting_press && (now - last_press_meas) > PRESS_CONV_MS) {
+    return;
+  } else if (converting_press && (now - last_press_meas) > PRESS_CONV_US) {
     converting_press = false;
     int32_t press = bmp180.readPressure();
-    mavlink_msg_data_int_send(MAVLINK_COMM_0, 0,
+    mavlink_msg_data_int_send(MAVLINK_COMM_0, last_press_meas,
                               CEAFDAS_DATA_SOUCE_PRESSURE_RAW, press);
+    return;
   }

   // Dynamic pressure measurement
-  if (now - last_qbar_meas > QBAR_PERIOD_MS) {
+  if (now - last_qbar_meas > QBAR_PERIOD_US) {
     uint32_t qbar = hx711.read();

-    mavlink_msg_data_int_send(MAVLINK_COMM_0, 0,
+    mavlink_msg_data_int_send(MAVLINK_COMM_0, last_qbar_meas,
                               CEAFDAS_DATA_SOUCE_QBAR_RAW, qbar);
     last_qbar_meas = now;
+    return;
   }

   // Aerodynamic angles measurement
-  if (now - last_alpha_meas > ALPHA_PERIOD_MS) {
+  if (now - last_alpha_meas > ALPHA_PERIOD_US) {
     uint16_t alpha = analogRead(A1);
     uint16_t beta = analogRead(A0);

-    mavlink_msg_data_int_send(MAVLINK_COMM_0, 0,
+    mavlink_msg_data_int_send(MAVLINK_COMM_0, now,
                               CEAFDAS_DATA_SOUCE_ALPHA_RAW, alpha);
-    mavlink_msg_data_int_send(MAVLINK_COMM_0, 0,
+    mavlink_msg_data_int_send(MAVLINK_COMM_0, now,
                               CEAFDAS_DATA_SOUCE_BETA_RAW, beta);
     last_alpha_meas = now;
+    return;
   }
 }


Cleanup: Removed unused function

Cleanup: Removed unused function

--- nRF51822-BLEMIDI/nRF51822-BLEMIDI.ino
+++ nRF51822-BLEMIDI/nRF51822-BLEMIDI.ino
@@ -391,47 +391,3 @@
   while (--num_nibbles);
 }

-/* TAKEN FROM USBH_MIDI Library */
-/* https://github.com/YuuichiAkagawa/USBH_MIDI */
-/* look up a MIDI message size from spec */
-/*Return                                 */
-/*  0 : undefined message                */
-/*  0<: Vaild message size(1-3)          */
-uint8_t lookupMsgSize(uint8_t midiMsg)
-{
-    uint8_t msgSize = 0;
-    if( midiMsg < 0xf0 ) midiMsg &= 0xf0;
-    switch(midiMsg) {
-       //3 bytes messages
-        case 0xf2 : //system common message(SPP)
-        case 0x80 : //Note off
-        case 0x90 : //Note on
-        case 0xa0 : //Poly KeyPress
-        case 0xb0 : //Control Change
-        case 0xe0 : //PitchBend Change
-            msgSize = 3;
-            break;
-            //2 bytes messages
-        case 0xf1 : //system common message(MTC)
-        case 0xf3 : //system common message(SongSelect)
-        case 0xc0 : //Program Change
-        case 0xd0 : //Channel Pressure
-            msgSize = 2;
-            break;
-            //1 bytes messages
-        case 0xf8 : //system realtime message
-        case 0xf9 : //system realtime message
-        case 0xfa : //system realtime message
-        case 0xfb : //system realtime message
-        case 0xfc : //system realtime message
-        case 0xfe : //system realtime message
-        case 0xff : //system realtime message
-            msgSize = 1;
-            break;
-            //undefine messages
-        default :
-            break;
-    }
-    return msgSize;
-}
-


Added some instructions to the sketch

Added some instructions to the sketch

--- AnimatedGIFs.ino
+++ AnimatedGIFs.ino
@@ -25,6 +25,31 @@
  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  */
+
+ /*
+  * This example displays 32x32 GIF animations loaded from a SD Card connected to the Teensy 3.1
+  * The GIFs must be 32x32 pixels exactly
+  * Wiring is on the default Teensy 3.1 SPI pins, and chip select can be on any GPIO,
+  * set by defining SD_CS in the code below
+  * Function     | Pin
+  * DOUT         |  11
+  * DIN          |  12
+  * CLK          |  13
+  * CS (default) |  15
+  *
+  * This code first looks for .gif files in the /gifs/ directory
+  * (customize below with the GIF_DIRECTORY definition) then plays random GIFs in the directory,
+  * looping each GIF for DISPLAY_TIME_SECONDS
+  *
+  * This example is meant to give you an idea of how to add GIF playback to your own sketch.
+  * For a project that adds GIF playback with other features, take a look at
+  * Light Appliance:
+  * https://github.com/CraigLindley/LightAppliance
+  *
+  * If you find any 32x32 GIFs that won't play properly, please attach them to a new
+  * Issue post in the GitHub repo here:
+  * https://github.com/pixelmatix/AnimatedGIFs/issues
+  */

 #include <math.h>
 #include <stdlib.h>
@@ -118,29 +143,3 @@
         }
     }
 }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-


Add clean left and right click support.

Add clean left and right click support.

--- arduinoHm/arduinoHm.ino
+++ arduinoHm/arduinoHm.ino
@@ -4,6 +4,7 @@
 // Button values are reversed because of pullup resistors
 int pedalUp = 1;
 int pedalDown = 0;
+boolean leftPedalWasDown = false;
 boolean rightPedalWasDown = false;

 void setup() {
@@ -11,6 +12,7 @@
   pinMode(2,INPUT_PULLUP);
   pinMode(3,INPUT_PULLUP);
   Serial1.setTimeout(10);
+  Serial.setTimeout(10);

   //while (!Serial1) {
     //; // wait for serial port to connect. Needed for Leonardo only
@@ -19,6 +21,7 @@

   //Serial1.setTimeout(1);
   Serial1.begin(57600);
+  Serial.begin(57600);
   Mouse.begin();

   for(int i = 0; i<500; i++){
@@ -40,7 +43,7 @@

   // Get initial value
   while(true) {
-    while (xCarryOver != 0 || yCarryOver !=0) {
+    while (xCarryOver != 0 || yCarryOver !=0){
       int x = absMax(xCarryOver, maxMove);
       int y = absMax(yCarryOver, maxMove);

@@ -50,25 +53,53 @@
       yCarryOver -= y;
     }

-    //Temporary pedal logic
-    if(readLeftPedal() == pedalDown){
-      while (readLeftPedal() == pedalDown){
-        delay(10);
+    // Todo: turn left and right click logic into a single reusable function that takes previous state and pedal read function pointer
+    if(!leftPedalWasDown){
+      if(readLeftPedal() == pedalDown){
+        delay(250);
+
+        if(readLeftPedal() == pedalUp){
+          logger("Left button click.");
+          // A quick release is interpreted as a click
+          Mouse.click();
+        } else {
+          logger("Left button hold.");
+          Mouse.press();
+          leftPedalWasDown = true;
+        }
       }

-      Mouse.click();
+    } else {
+      if(readLeftPedal() == pedalUp) {
+        logger("Left button release");
+        Mouse.release();
+        leftPedalWasDown = false;
+      }
     }

-    if(readRightPedal() == pedalDown && rightPedalWasDown == false){
-      Mouse.press();
-      rightPedalWasDown = true;
+    if(!rightPedalWasDown){
+      if(readRightPedal() == pedalDown){
+        delay(300);
+
+        if(readRightPedal() == pedalUp){
+          logger("Right button click.");
+          // A quick release is interpreted as a click
+          Mouse.click(MOUSE_RIGHT);
+        } else {
+          logger("Right button hold.");
+          Mouse.press(MOUSE_RIGHT);
+          rightPedalWasDown = true;
+        }
+      }
+
+    } else {
+      if(readRightPedal() == pedalUp) {
+        logger("Rigth button release.");
+        Mouse.release(MOUSE_RIGHT);
+        rightPedalWasDown = false;
+      }
     }
-
-    if(readRightPedal() == pedalUp && rightPedalWasDown == true){
-      Mouse.release();
-      rightPedalWasDown = false;
-    }
-
+

     if (Serial1.find("c")) {
       // We've received the start of a control code
@@ -77,7 +108,7 @@
       switch (ctrlCode) {
         case 0:
           // Request for device info
-          Serial1.println("hm0.0.1");
+         Serial1.println("hm0.0.1");
           break;
         case 1:
           // Received code to move mouse
@@ -103,6 +134,12 @@
   }
 }

+void logger(String message) {
+  Serial.println(message);
+
+
+}
+
 int readLeftPedal() {
   return digitalRead(2);
 }