adding diversity to feature toggle. comment out #define USE_DIVERSITY to disable it.

--- src/rx5808-pro-diversity/rx5808-pro-diversity.ino
+++ src/rx5808-pro-diversity/rx5808-pro-diversity.ino
@@ -37,24 +37,28 @@

 // Feature Togglels
 //#define DEBUG
+#define USE_DIVERSITY
+

 #define spiDataPin 10
 #define slaveSelectPin 11
 #define spiClockPin 12

 // Receiver PINS
-#define receiverA_led A1
-#define rssiPinA A7
-
+#define receiverA_led A0
+#define rssiPinA A6
+
+#ifdef USE_DIVERSITY
 // Diversity
-#define receiverB_led A0
-#define rssiPinB A6
+#define receiverB_led A1
+#define rssiPinB A7
 #define useReceiverAuto 0
 #define useReceiverA 1
 #define useReceiverB 2
 // rssi strenth should be 2% greater than other receiver before switch.
 // this pervents flicker when rssi are close.
 #define DIVERSITY_CUTOVER 2
+#endif

 // this two are minimum required
 #define buttonSeek 2
@@ -89,7 +93,9 @@
 #define STATE_SEEK 1
 #define STATE_SCAN 2
 #define STATE_MANUAL 3
+#ifdef USE_DIVERSITY
 #define STATE_DIVERSITY 4
+#endif
 #define STATE_SAVE 5
 #define STATE_RSSI_SETUP 6

@@ -119,12 +125,13 @@
 #define EEPROM_ADR_RSSI_MIN_A_H 3
 #define EEPROM_ADR_RSSI_MAX_A_L 4
 #define EEPROM_ADR_RSSI_MAX_A_H 5
+#ifdef USE_DIVERSITY
 #define EEPROM_ADR_DIVERSITY 6
 #define EEPROM_ADR_RSSI_MIN_B_L 7
 #define EEPROM_ADR_RSSI_MIN_B_H 8
 #define EEPROM_ADR_RSSI_MAX_B_L 9
 #define EEPROM_ADR_RSSI_MAX_B_H 10
-
+#endif

 // Channels to sent to the SPI registers
 const uint16_t channelTable[] PROGMEM = {
@@ -164,7 +171,9 @@
 uint8_t channelIndex = 0;
 uint8_t rssi = 0;
 uint8_t rssi_scaled = 0;
+#ifdef USE_DIVERSITY
 uint8_t diversity_mode = useReceiverAuto;
+#endif
 uint8_t hight = 0;
 uint8_t state = START_STATE;
 uint8_t state_last_used=START_STATE;
@@ -190,10 +199,12 @@
 uint16_t rssi_max_a=0;
 uint16_t rssi_setup_min_a=0;
 uint16_t rssi_setup_max_a=0;
+#ifdef USE_DIVERSITY
 uint16_t rssi_min_b=0;
 uint16_t rssi_max_b=0;
 uint16_t rssi_setup_min_b=0;
 uint16_t rssi_setup_max_b=0;
+#endif
 uint16_t rssi_seek_found=0;
 uint16_t rssi_setup_run=0;

@@ -221,8 +232,10 @@
     //Receiver Setup
     pinMode(receiverA_led,OUTPUT);
     digitalWrite(buzzer, HIGH);
+#ifdef USE_DIVERSITY
     pinMode(receiverB_led,OUTPUT);
     digitalWrite(receiverA_led, LOW);
+#endif
 #ifdef DEBUG
     Serial.begin(115200);
     Serial.println(F("START:"));
@@ -263,6 +276,7 @@
         // save 16 bit
         EEPROM.write(EEPROM_ADR_RSSI_MAX_A_L,lowByte(RSSI_MAX_VAL));
         EEPROM.write(EEPROM_ADR_RSSI_MAX_A_H,highByte(RSSI_MAX_VAL));
+#ifdef USE_DIVERSITY
         // diversity
         EEPROM.write(EEPROM_ADR_DIVERSITY,diversity_mode);
         // save 16 bit
@@ -271,6 +285,7 @@
         // save 16 bit
         EEPROM.write(EEPROM_ADR_RSSI_MAX_B_L,lowByte(RSSI_MAX_VAL));
         EEPROM.write(EEPROM_ADR_RSSI_MAX_B_H,highByte(RSSI_MAX_VAL));
+#endif
     }

     // read last setting from eeprom
@@ -278,9 +293,11 @@
     channelIndex=EEPROM.read(EEPROM_ADR_TUNE);
     rssi_min_a=((EEPROM.read(EEPROM_ADR_RSSI_MIN_A_H)<<8) | (EEPROM.read(EEPROM_ADR_RSSI_MIN_A_L)));
     rssi_max_a=((EEPROM.read(EEPROM_ADR_RSSI_MAX_A_H)<<8) | (EEPROM.read(EEPROM_ADR_RSSI_MAX_A_L)));
+#ifdef USE_DIVERSITY
     diversity_mode = EEPROM.read(EEPROM_ADR_DIVERSITY);
     rssi_min_b=((EEPROM.read(EEPROM_ADR_RSSI_MIN_B_H)<<8) | (EEPROM.read(EEPROM_ADR_RSSI_MIN_B_L)));
     rssi_max_b=((EEPROM.read(EEPROM_ADR_RSSI_MAX_B_H)<<8) | (EEPROM.read(EEPROM_ADR_RSSI_MAX_B_L)));
+#endif
     force_menu_redraw=1;
 }

@@ -341,7 +358,9 @@
             TV.printPGM(10, 5+1*MENU_Y_SIZE, PSTR("Auto Search"));
             TV.printPGM(10, 5+2*MENU_Y_SIZE, PSTR("Band Scanner"));
             TV.printPGM(10, 5+3*MENU_Y_SIZE, PSTR("Manual Mode"));
+#ifdef USE_DIVERSITY
             TV.printPGM(10, 5+4*MENU_Y_SIZE, PSTR("Diversity"));
+#endif
             TV.printPGM(10, 5+5*MENU_Y_SIZE, PSTR("Save Setup"));
             // selection by inverted box
             switch (menu_id)
@@ -361,10 +380,15 @@
                     TV.draw_rect(8,3+3*MENU_Y_SIZE,100,12,  WHITE, INVERT);
                     state=STATE_MANUAL;
                 break;
+#ifdef USE_DIVERSITY
                 case 3: // Diversity
                     TV.draw_rect(8,3+4*MENU_Y_SIZE,100,12,  WHITE, INVERT);
                     state=STATE_DIVERSITY;
                 break;
+#else
+                case 3: // Skip
+                    menu_id++;
+#endif
                 case 4: // Save settings
                     TV.draw_rect(8,3+5*MENU_Y_SIZE,100,12,  WHITE, INVERT);
                     state=STATE_SAVE;
@@ -470,6 +494,12 @@
                     rssi_max_a=400; // set to max range
                     rssi_setup_min_a=400;
                     rssi_setup_max_a=0;
+#ifdef USE_DIVERSITY
+                    rssi_min_b=0;
+                    rssi_max_b=400; // set to max range
+                    rssi_setup_min_b=400;
+                    rssi_setup_max_b=0;
+#endif
                     rssi_setup_run=RSSI_SETUP_RUN;
                 }
                 TV.draw_rect(0,1*TV_Y_GRID,TV_X_MAX,9,  WHITE); // list frame
@@ -517,13 +547,17 @@
                 update_frequency_view=1;
                 force_seek=1;
             break;
+#ifdef USE_DIVERSITY
             case STATE_DIVERSITY:
                 // diversity menu is below this is just a place holder.
             break;
+#endif
             case STATE_SAVE:
                 EEPROM.write(EEPROM_ADR_TUNE,channelIndex);
                 EEPROM.write(EEPROM_ADR_STATE,state_last_used);
+#ifdef USE_DIVERSITY
                 EEPROM.write(EEPROM_ADR_DIVERSITY,diversity_mode);
+#endif
                 TV.select_font(font8x8);
                 TV.draw_rect(0,0,127,95,  WHITE);
                 TV.draw_line(0,14,127,14,WHITE);
@@ -613,6 +647,8 @@
     /*************************************/
     /*   Processing depending of state   */
     /*************************************/
+
+#ifdef USE_DIVERSITY
     if(state == STATE_DIVERSITY) {
         // simple menu
         char menu_id=diversity_mode;
@@ -699,6 +735,7 @@

         state=state_last_used;
     }
+#endif
     /*****************************************/
     /*   Processing MANUAL MODE / SEEK MODE  */
     /*****************************************/
@@ -926,6 +963,9 @@
                     // save 16 bit
                     EEPROM.write(EEPROM_ADR_RSSI_MAX_A_L,(rssi_max_a & 0xff));
                     EEPROM.write(EEPROM_ADR_RSSI_MAX_A_H,(rssi_max_a >> 8));
+
+
+#ifdef USE_DIVERSITY
                     rssi_min_b=rssi_setup_min_b;
                     rssi_max_b=rssi_setup_max_b;
                     // save 16 bit
@@ -934,7 +974,7 @@
                     // save 16 bit
                     EEPROM.write(EEPROM_ADR_RSSI_MAX_B_L,(rssi_max_b & 0xff));
                     EEPROM.write(EEPROM_ADR_RSSI_MAX_B_H,(rssi_max_b >> 8));
-
+#endif
                     state=EEPROM.read(EEPROM_ADR_STATE);
                     beep(1000);
                 }
@@ -1026,19 +1066,29 @@

 uint16_t readRSSI()
 {
+#ifdef USE_DIVERSITY
     return readRSSI(-1);
 }
 uint16_t readRSSI(uint8_t receiver)
 {
+#endif
     uint16_t rssi = 0;
     uint16_t rssiA = 0;
+
+#ifdef USE_DIVERSITY
     uint16_t rssiB = 0;
+#endif
     for (uint8_t i = 0; i < 10; i++)
     {
         rssiA += analogRead(rssiPinA);
+
+#ifdef USE_DIVERSITY
         rssiB += analogRead(rssiPinB);
+#endif
     }
     rssiA = rssiA/10; // average of 10 readings
+
+#ifdef USE_DIVERSITY
     rssiB = rssiB/10; // average of 10 readings
     // choosing which receiver RSSI to use.. do not change LED
     if(receiver == useReceiverA)
@@ -1088,6 +1138,9 @@
                 break;
         }
     }
+#else
+rssi=rssiA;
+#endif

     // special case for RSSI setup
@@ -1105,6 +1158,8 @@
             TV.print(110, SCANNER_LIST_Y_POS, "   ");
             TV.print(110, SCANNER_LIST_Y_POS, rssi_setup_max_a , DEC);
         }
+
+#ifdef USE_DIVERSITY
         if(rssiB < rssi_setup_min_b)
         {
             rssi_setup_min_b=rssiB;
@@ -1113,22 +1168,26 @@
         {
             rssi_setup_max_b=rssiB;
         }
-    }
-
+#endif
+    }
+#ifdef USE_DIVERSITY
     if(receiver == useReceiverA || state==STATE_RSSI_SETUP)
     {
+#endif
         rssi = constrain(rssiA, rssi_min_a, rssi_max_a);    //original 90---250
         rssi=rssi-rssi_min_a; // set zero point (value 0...160)
         rssi = map(rssi, 0, rssi_max_a-rssi_min_a , 1, 100);   // scale from 1..100%
+#ifdef USE_DIVERSITY
     }
     else {
         rssi = constrain(rssiB, rssi_min_b, rssi_max_b);    //original 90---250
         rssi=rssi-rssi_min_b; // set zero point (value 0...160)
         rssi = map(rssi, 0, rssi_max_a-rssi_min_b , 1, 100);   // scale from 1..100%
     }
+#endif
     return (rssi);
 }
-
+#ifdef USE_DIVERSITY
 void setReceiver(uint8_t receiver) {
     if(receiver == useReceiverA)
     {
@@ -1141,6 +1200,7 @@
         digitalWrite(receiverA_led, LOW);
     }
 }
+#endif

 // Private function: from http://arduino.cc/playground/Code/AvailableMemory
 int freeRam () {


Reset parameters to reasonable default values

--- main.ino
+++ main.ino
@@ -45,10 +45,10 @@
 #define MAX_PARAMETERS 7

 /* Holds the parameter that is currently changed using the rotary wheel. */
-uint8_t activeParameter = PARAMETER_SPEED;
+uint8_t activeParameter = PARAMETER_MODE;

 /* Holds the values of the different parameters. */
-uint8_t parameters[MAX_PARAMETERS] = { 2, 190, 255, 128, 5, 0, /*NUM_LEDS-1*/ 4 };
+uint8_t parameters[MAX_PARAMETERS] = { 0, 190, 255, 128, 10, 0, NUM_LEDS-1 };

 /* Maximum values of the different parameters, plus one. Zero denotes that a
  * variable can stretch the full range of 0-255. */


Added better warning LCD message when limit switches are triggered.

--- chicken_door_timer_v2.ino
+++ chicken_door_timer_v2.ino
@@ -13,6 +13,7 @@
 #include <avr/sleep.h>
 #include <avr/power.h>
 #include <avr/wdt.h>
+#include <util/delay.h>

 #include <LiquidCrystal.h>
 #include <Wire.h>
@@ -31,6 +32,12 @@
 #define DELAY_MS 10
 #define MAX_DELAY_MINUTES 100
 #define DOOR_RETRY_SECONDS 10
+
+#define DOOR_ERR_BEEP_TIME 450
+#define DOOR_ERR_MSG1_TIME 2000
+#define DOOR_ERR_MSG2_TIME 4000
+#define DOOR_ERR_MSG3_TIME 7500
+#define DORR_ERR_PAUSE_TIME 30000

 // Pins
 #define PIN_ENC_A     7
@@ -299,6 +306,13 @@
   power_all_enable();
 }

+void tensDigitLCD(byte digit){
+  if(digit / 10 < 1){
+    lcd.print('0');
+  }
+  lcd.print((int)digit);
+}
+
 // Opens the door (with timeout)
 void openDoor(){
   lcd.clear();
@@ -397,41 +411,127 @@
 }

 // Alert user to press a button, otherwise the system will try to open/close the door to the proper position
+
+/*
+ * |00|01|02|03|04|05|06|07|08|09|10|11|12|13|14|15|  |00|01|02|03|04|05|06|07|08|09|10|11|12|13|14|15|
+ * |E |r |r |o |r |! |  |D |o |o |r |  |n |o |t |  |  |E |r |r |o |r |! |  |D |o |o |r |  |n |o |t |  |
+ * |C |l |o |s |e |d |  |a |t |  |n |i |g |h |t |. |  |o |p |e |n |  |d |u |r |. |  |d |a |y |. |  |  |
+ *
+ * |p |r |e |s |s |  |m |a |i |n |  |b |t |n |  |  |  |p |r |e |s |s |  |m |a |i |n |  |b |t |n |  |  |
+ * |t |o |  |p |r |e |v |e |n |t |  |f |r |o |m |- |  |t |o |  |p |r |e |v |e |n |t |  |f |r |o |m |- |
+ *
+ * |a |u |t |o |- |o |p |e |n |i |n |g |  |i |n |  |  |a |u |t |o |- |c |l |o |s |i |n |g |  |i |n |  |
+ * |x |x |  |s |e |c |o |n |d |s |. |  |  |  |  |  |  |x |x |  |s |e |c |o |n |d |s |. |  |  |  |  |  |
+ *
+ * |. |. |
+ */
+
+void drawDoorErrMsg1(bool notClosed){
+  lcd.clear();
+  lcd.setCursor(0, 0);
+  lcd.print("Error! Door not ");
+  lcd.setCursor(0, 1);
+  if(notClosed){
+    lcd.print("closed at night.");
+  } else{
+    lcd.print("open dur. day.  ");
+  }
+}
+
+void drawDoorErrMsg2(){
+  lcd.clear();
+  lcd.setCursor(0, 0);
+  lcd.print("Press main btn  ");
+  lcd.setCursor(0, 1);
+  lcd.print("to prevent from-");
+}
+
+void drawDoorErrMsg3(bool notClosed, byte seconds){
+  lcd.clear();
+  lcd.setCursor(0, 0);
+  if(notClosed){
+    lcd.print("auto-closing in ");
+  } else {
+    lcd.print("auto-opening in ");
+  }
+  lcd.setCursor(0, 1);
+  tensDigitLCD(seconds);
+  lcd.print(" seconds.");
+
+}
+
 void waitForUserResetOpen(){
-  lcd.clear();
-  lcd.setCursor(0, 0);
-  lcd.print("Door will ");
-  if(is_day_time && hit_bottom){
-    lcd.print("open");
-  } else if(!is_day_time && hit_top){
-    lcd.print("close");
-  }
-  lcd.setCursor(0, 1);
-  lcd.print("Unless press btn");
+
+  // determine time allowed for user to fix door before auto-fixing
+  bool notClosed = !is_day_time & hit_top;

   DateTime stopTime = rtc.now();
   DateTime fixTime;
   if(is_day_time && hit_bottom){
     fixTime = stopTime + TimeSpan(0, 0, 0, 6);
-  } else if(!is_day_time && hit_top){
+  } else if(notClosed){
     fixTime = stopTime + TimeSpan(0, 0, 0, 5);
   }

   bool pausedForUser = false;
+
+  bool beep1 = false;
+  bool msg1 = false;
+  bool msg2 = false;
+  bool msg3 = false;
+  bool msg_looped = false;

+  volatile int ms_count_beep = 0;
+  volatile int ms_count_msgs = 0;
+  volatile int ms_pause_time = 0;
+
   // while warning time not run out and user hasn't intervened
-  while(fixTime.unixtime() - rtc.now().unixtime() > 0 && !pausedForUser){
-    wdt_reset();
+  while((ms_pause_time < DORR_ERR_PAUSE_TIME) && !pausedForUser){
     menuButton.read();
     if(menuButton.wasReleased()){
       pausedForUser = true;
     }
-    tone(PIN_PIEZO, 2000, 50);
-    delay(400);
-    tone(PIN_PIEZO, 2000, 50);
-    delay(400);
-  }
-
+
+    if((ms_count_beep > DOOR_ERR_BEEP_TIME) && !beep1){
+      tone(PIN_PIEZO, 800, 50);
+      beep1 = true;
+    }
+    else if(ms_count_beep > DOOR_ERR_BEEP_TIME * 2 + 50){
+      tone(PIN_PIEZO, 2000, 50);
+      beep1 = false;
+      ms_count_beep = 0;
+    }
+
+    if(!msg1 && (ms_count_msgs > 0) &&
+        (ms_count_msgs < DOOR_ERR_MSG1_TIME)){
+      drawDoorErrMsg1(notClosed);
+      msg1 = true;
+    }
+    else if(!msg2 && (ms_count_msgs > DOOR_ERR_MSG1_TIME) &&
+              (ms_count_msgs < DOOR_ERR_MSG2_TIME)){
+      drawDoorErrMsg2();
+      msg2 = true;
+    }
+    else if(!msg3 && (ms_count_msgs > DOOR_ERR_MSG2_TIME) &&
+              (ms_count_msgs < DOOR_ERR_MSG3_TIME)){
+      drawDoorErrMsg3(notClosed, (DORR_ERR_PAUSE_TIME - ms_pause_time) / 1000);
+      msg3 = true;
+    }
+    else if(ms_count_msgs > DOOR_ERR_MSG3_TIME){
+      ms_count_msgs = 0;
+      msg1 = false;
+      msg2 = false;
+      msg3 = false;
+    }
+
+    _delay_ms(10);
+    ms_count_beep += 10;
+    ms_count_msgs += 10;
+    ms_pause_time += 10;
+    wdt_reset();
+  }
+
+  // TODO: fix this..
   // if user wants to operate on door or something.. Leave door open/close (for a fair while)
   if(pausedForUser){
     lcd.clear();
@@ -659,12 +759,7 @@

 }

-void tensDigitLCD(byte digit){
-  if(digit / 10 < 1){
-    lcd.print('0');
-  }
-  lcd.print((int)digit);
-}
+

 void updateLCD(){
  lcd.clear();


Removed Arduino source

Removed Arduino source

--- arduino_src/SerialLedSwInterface/SerialLedSwInterface.ino
+++ arduino_src/SerialLedSwInterface/SerialLedSwInterface.ino
@@ -1,156 +0,0 @@
-/*
-  This program uses the HIVE Led/Switch shield for arduino uno.
-  The program sends state of the switches over RS232 and
-  Can set/clear the leds
-  This example code is in the public domain.
- */
-
-#include <stdio.h>  // Use the sprinf to generate strings
-
-#define MAX_RECV_LINE_LENGTH 200
-#define MAX_COMMANDS 10
-
-String strIncompleteLine = "";   // a string to hold incoming data
-String strInputLine = "";        // a string to the recieved line
-boolean bStrComplete = false;    // whether the string is complete
-
-String strCommands[MAX_COMMANDS];
-
-// Give names to the input pins
-int sw0 = 14;
-int sw1 = 15;
-int sw2 = 16;
-
-// Give names to the output pins
-int led0 = 8;
-int led1 = 9;
-int led2 = 10;
-
-int i=0;
-char msg[100];
-int statusSw0 = 0;
-int statusSw1 = 0;
-int statusSw2 = 0;
-
-void setup() {
-    // make the Leds output width pulup
-  pinMode(led0,  OUTPUT );
-  pinMode(led1,  OUTPUT );
-  pinMode(led2,  OUTPUT );
-
-  // make the switches input width pulup
-  pinMode(sw0,  INPUT_PULLUP);
-  pinMode(sw1,  INPUT_PULLUP);
-  pinMode(sw2,  INPUT_PULLUP);
-
-  //Save Initial status
-  statusSw0 = digitalRead(sw0);
-  statusSw1 = digitalRead(sw1);
-  statusSw2 = digitalRead(sw2);
-
-  //Turn Leds off
-  digitalWrite(led0,1);
-  digitalWrite(led1,1);
-  digitalWrite(led2,1);
-
-  // initialize serial:
-  Serial.begin(9600);
-  // reserve MAX_RECV_LENGTH bytes for the inputString:
-  strIncompleteLine.reserve(MAX_RECV_LINE_LENGTH);
-  strInputLine.reserve(MAX_RECV_LINE_LENGTH);
-}
-
-//  strCommands - input string that contains a CVS string ($LED,1,0,1,0,1)
-//  strTab - has the splited input (strTab[0]="$LED",strTab[1]="1",strTab[2]="0")
-//  maxItems -  the maximum commands to parse
-//  Return the number of read items
-int SplitCommands(String  strCommands, String strTab[],int maxItems)
-{
-  //Start position looking for ','
-  int fisrtCommaPosition=0;
-  int lastCommaPosition=0;
-  int iItems=0;
-  do
-    { //Get the position of the next item
-        lastCommaPosition = strCommands.indexOf(',',fisrtCommaPosition);
-        if(lastCommaPosition != -1)
-        {   strTab[iItems]= strCommands.substring(fisrtCommaPosition,lastCommaPosition);
-            fisrtCommaPosition=lastCommaPosition+1;
-        }
-        else
-            //Prints the last element
-            strTab[iItems]= strCommands.substring(fisrtCommaPosition,strInputLine.length()-1);
-
-       iItems++;
-
-     } while((lastCommaPosition >=0) & (iItems<maxItems));
-
-  return iItems;
-}
-
-//Main loop do the work :)
-void loop()
-{
-     //Check if the state of the switches has changed
-    if ( (statusSw0!=digitalRead(sw0)) |
-         (statusSw1!=digitalRead(sw1)) |
-         (statusSw2!=digitalRead(sw2)) )
-      { //Transfer the new switch walues
-
-       //Store the new values
-       statusSw0 = digitalRead(sw0);
-       statusSw1 = digitalRead(sw1);
-       statusSw2 = digitalRead(sw2);
-
-       //Make the string to transfer
-       sprintf(msg,"$SW,%d,%d,%d",
-        digitalRead(sw0),digitalRead(sw1),
-        digitalRead(sw2));
-
-       //Transfer the serial data
-       Serial.println(msg);
-      }//end if
-
-    // print the string when a newline arrives:
-    if (bStrComplete)
-    { bStrComplete=false;
-      // Splits the incoming string into strCommands[0] .. [MAX_COMMANDS]
-      int nCommands=SplitCommands(strInputLine,strCommands,MAX_COMMANDS); // Parses the CVS string
-      // if cmd = $LED send the values to the leds
-      if (strCommands[0]=="$LED")
-        {    digitalWrite(led0,1);
-             digitalWrite(led1,1);
-             digitalWrite(led2,1);
-
-             if (strCommands[1]=="1")
-                digitalWrite(led0,0);
-             if (strCommands[2]=="1")
-                digitalWrite(led1,0);
-             if (strCommands[3]=="1")
-                digitalWrite(led2,0);
-        }//end of $LED
-
-    }//end of bStrComplete
-}// end Loop
-
-/*
-  SerialEvent occurs whenever a new data comes in the
- hardware serial RX.  This routine is run between each
- time loop() runs, so using delay inside loop can delay
- response.  Multiple bytes of data may be available.
- */
-void serialEvent() {
-  while (Serial.available()) {
-    // get the new byte:
-    char inChar = (char)Serial.read();
-    // add it to the inputString:
-    strIncompleteLine += inChar;
-    // if the incoming character is a newline, set a flag
-    // so the main loop can do something about it:
-    if ((inChar == '\n') || (inChar == '\r') ) {
-      strInputLine=strIncompleteLine;
-      bStrComplete = true;
-      strIncompleteLine="";
-    }
-  }
-}


Delete script.ino

Delete script.ino

--- script.ino
+++ script.ino
@@ -1,434 +0,0 @@
-#include <ArduinoJson.h>
-#include <Average.h>
-#include <dht11.h>
-#include <SPI.h>
-#include <Ethernet.h>
-#include <PubSubClient.h>
-#include <SD.h>
-
-const int xPin = A1;
-//#define X_pin 1  // analog pin connected to X output
-const int yPin = A2;
-//#define Y_pin 2  // analog pin connected to Y output
-const int Dht11BodyPin = 2;
-//#define DHT11_BODY 2
-const int Dht11AmbPin = 3;
-//#define DHT11_AMB 3
-const int soundPin = A0;
-//#define heating 24
-const int heatingPin = 24;
-//#define humid 26
-const int humidPin = 26;
-
-long randNumber; // This variable is used only to test the code without any sensor plugged
-const int chipSelect = 4;
-File dataLog;
-
-// Update these Value with the ones suitable for you
-byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // Ethernet MAC address (DO NOT TOUCH! IT IS STANDARDIZED!)
-byte raspberry_ip[] = {169, 254, 210, 16}; // Rasp Pi IP address
-byte arduino_ip[] = {169, 254, 210, 17}; // Arduino IP address
-char raspberry_ip_str[] = "169.254.210.16";
-char arduino_ip_str[] = "169.254.210.17";
-
-// Variable related to --> Joystick
-const byte size = 11;
-Average<int> array_X(size);
-Average<int> array_Y(size);
-const int sampleWindowAcc = 20;
-int startAcc;
-int k = 0;
-int k1 = 0;
-int xDev = 0;
-int yDev = 0;
-
-// Variable related to --> Cry_sensor
-const int sampleWindowS = 200; // Sample window width in ms (50ms = 20Hz --> 200ms --> 5Hz) for the microphone
-unsigned int sample;
-unsigned long startS; // Used to determine time starting in millis() for the microphone
-unsigned int signalMax = 0; // Used to save the maximum in "sampleWindowS"
-unsigned int signalMin = 1024; // Used to save the minimum in "sampleWindowS"
-int j = 0;
-
-
-// Variable related to --> DHT11
-const int sampleWindowDHT11_1 = 1000; // Sample window width in mS (50ms = 20Hz --> 200ms --> 5Hz) for DHT11
-const int sampleWindowDHT11_2 = 1000;
-unsigned long startDHT11_1; // Used to determine time starting in millis() for DHT11
-unsigned long startDHT11_2;
-dht11 DHT; // Object DHT11
-
-// Variable related to --> JSON
-const int len = 500;
-char buffer[len];
-//StaticJsonBuffer<len> jsonBuffer;
-DynamicJsonBuffer jsonBuffer;
-JsonObject& sensor = jsonBuffer.createObject();
-JsonObject& DHT11_1 = sensor.createNestedObject("DHT11_1");
-JsonObject& DHT11_2 = sensor.createNestedObject("DHT11_2");
-JsonObject& Acc = sensor.createNestedObject("Acc");
-//JsonArray& TimeAcc = Acc.createNestedArray("TimeAcc");
-JsonArray& Movement = Acc.createNestedArray("Movement");
-JsonObject& Microphone = sensor.createNestedObject("Microphone");
-//JsonArray& Time = Microphone.createNestedArray("Time");
-JsonArray& dB = Microphone.createNestedArray("dB");
-unsigned long startPrint;
-
-//// Variable related to --> Networking
-EthernetClient ethClient;
-PubSubClient mqttClient(ethClient);
-
-String unix_time;
-String local_time;
-
-boolean heating_state = LOW;
-boolean humid_state = LOW;
-
-void setup() {
-  if (!SD.begin(chipSelect)) {
-    Serial.println("Card failed, or not present");
-    // don't do anything more:
-    return;
-  }
-  else {
-    Serial.println("Card initialized");
-  }
-  pinMode(humidPin, OUTPUT);
-  pinMode(heatingPin, OUTPUT);
-  digitalWrite(heatingPin, heating_state);
-  digitalWrite(humidPin, humid_state);
-  startAcc = millis();
-  startS = millis();
-  startDHT11_1 = millis();
-  startDHT11_2 = millis();
-  startPrint = millis();
-  Microphone["ID"] = ("Microphone");
-  DHT11_1["ID"] = ("DHT11 Sensor1");
-  DHT11_2["ID"] = ("DHT11 Sensor2");
-  Acc["ID"] = ("Accelerometer");
-  for (int i = 0; i <= 5; i++) {
-    //TimeAcc.add(0);
-    Movement.add(0);
-    //Time.add(0);
-    dB.add(0);
-  }
-  Serial.begin(9600);
-  while (!Serial) {
-    // wait serial port initialization
-  }
-  mqttClient.setServer(raspberry_ip,1883);
-  mqttClient.setCallback(callback);
-
-  Ethernet.begin(mac, arduino_ip);
-  // Allow the hardware to sort itself out
-  delay(1500);
-}
-
-void loop() {
-  if (!mqttClient.connected())
-  {
-    reconnect();
-  }
-  mqttClient.loop();
-
-  readSound(Microphone);
-  readDHT11(DHT11_1);
-  readDHT11(DHT11_2);
-  readAcc(Acc);
-  digitalWrite(heatingPin, heating_state);
-  digitalWrite(humidPin, humid_state);
-  if (millis() - startPrint > 1010) {
-    sensor.printTo(Serial);
-    Serial.println();
-    startPrint = millis();
-  }
-}
-/*  ###################################
-    #              SENSORS            #
-    ###################################
-*/
-
-void readAcc(JsonObject & SubSensor) {
-  //Read from the accelerometer and do somethins...
-  mqttClient.publish("requesting", "unix");
-  mqttClient.publish("requesting", "local");
-  if (millis() - startAcc > sampleWindowAcc) {
-    array_X.push(analogRead(X_pin));
-    array_Y.push(analogRead(Y_pin));
-    k++;
-    startAcc = millis();
-  }
-  if (k >= 10) {
-    k = 0;
-    xDev = array_X.stddev();
-    yDev = array_Y.stddev();
-
-    SubSensor["Time"] = unix_time.toInt(); //Take hour from RPi
-    Movement.set(k1, (xDev + yDev) / 2);
-    k1++;
-    if (k1 > 5) {
-      k1 = 0;
-      SubSensor.printTo(buffer, sizeof(buffer));
-      mqttClient.publish("accelerometer", buffer); // Message published to the topic
-//      Serial.println(buffer);
-//      if (dataLog) {
-//        String r1 = SubSensor["ID"];
-//        dataLog.print("ID: ");
-//        dataLog.println(r1);
-//        dataLog.print("Value: ");
-//        int a = Acc["Movement"][0];
-//        Serial.println(a);
-//        Movement[0].printTo(buffer,sizeof(buffer))
-//        dataLog.print(Acc["Movement"][0]);
-//        dataLog.print(", ");
-//        dataLog.println(Acc[Movement][1]);
-//        dataLog.print(", ");
-//        dataLog.println(Movement[2]);
-//        dataLog.print(", ");
-//        dataLog.println(Movement[3]);
-//        dataLog.print(", ");
-//        dataLog.println(Movement[4]);
-//        dataLog.print("Time: ");
-//        dataLog.println(local_time);
-//        dataLog.println();
-//      }
-//      else {
-//        Serial.println("error opening datalog.txt");
-//      }
-    }
-
-  }
-}
-
-void readSound(JsonObject & SubSensor) {
-  unsigned int peakToPeak = 0;   // peak-to-peak level
-
-  sample = analogRead(soundPin);
-  if (sample < 1024)  // toss out spurious readings
-    if (sample > signalMax)
-      signalMax = sample;  // save just the max levels
-    else if (sample < signalMin)
-      signalMin = sample;  // save just the min levels
-
-  if (millis() - startS > sampleWindowS) {
-    peakToPeak = signalMax - signalMin;  // max - min = peak-peak amplitude
-    double volts = (peakToPeak * 3.3);  // convert to volts
-    signalMax = 0;
-    signalMin = 1024;
-    startS = millis();
-    //Time.set(j, 999); //prendi l'ora da rasp
-    SubSensor["Time"] = unix_time.toInt(); //Take hour from RPi
-    dB.set(j, volts);
-    j++;
-    if (j > 5) {
-      j = 0;
-      SubSensor.printTo(buffer, sizeof(buffer));
-      mqttClient.publish("temperature", buffer); // Message published to the topic
-    }
-  }
-}
-
-
-void readDHT11(JsonObject & SubSensor) {
-  if ((millis() - startDHT11_1 > sampleWindowDHT11_1) ||  (millis() - startDHT11_2 > sampleWindowDHT11_2)) {
-    mqttClient.publish("requesting", "unix");
-    mqttClient.publish("requesting", "local");
-    //    int temp = random(25, 35); // This variable is used only to test the code without any sensor plugged
-    //    int hum = random(10, 100); // This variable is used only to test the code without any sensor plugged
-    int PIN;
-    if (SubSensor["ID"] == "DHT11 Sensor1") {
-      startDHT11_1 = millis();
-      PIN = Dht11BodyPin;
-    }
-    else {
-      startDHT11_2 = millis();
-      PIN = Dht11AmbPin;
-    }
-    switch (DHT.read(PIN)) {
-      case DHTLIB_OK:
-        SubSensor["Status"] = "OK";
-        break;
-      case DHTLIB_ERROR_CHECKSUM:
-        SubSensor["Status"] = "Checksum error";
-        break;
-      case DHTLIB_ERROR_TIMEOUT:
-        SubSensor["Status"] = "Time out error";
-        break;
-      default:
-        SubSensor["Status"] = "Unknown error";
-        break;
-    }
-    int temp = DHT.temperature;
-    int hum = DHT.humidity;
-    SubSensor["Temp"] = temp;
-    SubSensor["Hum"] = hum;
-    SubSensor["Time"] = unix_time.toInt(); //Take hour from RPi
-    //    const char *DHT11_1 = sensor["DHT11_1"].asString();
-    //SubSensor.prettyPrintTo(Serial);
-    if (dataLog) {
-      String r1 = SubSensor["ID"];
-      //String r4 = SubSensor["Time"];
-      dataLog.print("ID: ");
-      dataLog.println(r1);
-      dataLog.print("Temperature: ");
-      dataLog.println(temp);
-      dataLog.print("Humidity: ");
-      dataLog.println(hum);
-      dataLog.print("Time: ");
-      dataLog.println(local_time);
-      dataLog.println();
-    }
-    else {
-      Serial.println("error opening datalog.txt");
-    }
-    SubSensor.printTo(buffer, sizeof(buffer));
-    mqttClient.publish("temperature", buffer); // Message published to the topic
-  }
-}
-
-/*  ###################################
-    #              ETHERNET           #
-    ###################################
-*/
-
-
-// This functions is called when a message arrived (it acts as an "Interrupt" if you get me ;)  )
-void callback(char* topic, byte* payload, unsigned int length)
-{
-  Serial.print("Message arrived on [");
-  Serial.print(topic);
-  Serial.print("]: ");
-  if (dataLog) {
-    dataLog.print("Message arrived on [");
-    dataLog.print(topic);
-    dataLog.print("]: ");
-  }
-  else {
-    Serial.println("error opening datalog.txt");
-  }
-  for (int i = 0; i < length; i++)
-  {
-    Serial.print((char)payload[i]); // payload is the message coming from the broker
-    dataLog.print((char)payload[i]);
-  }
-  dataLog.println();
-  dataLog.println();
-  dataLog.flush();
-  Serial.println();
-  if (strcmp (topic, "time_unix") == 0) {
-    unix_time = ((String)(char *)payload).substring(0, (length - 3));
-  }
-  else if ((strcmp(topic, "moisturizing") == 0) || (strcmp(topic, "heating") == 0)) {
-    String action = (char *)payload;
-    action = action.substring(0, length);
-    acting(topic, action);
-  }
-  else if (strcmp (topic, "time_local") == 0) {
-    local_time = ((String)(char *)payload);
-  }
-  else {
-    Serial.print("Topic ("); Serial.print(topic); Serial.println(") doesn't recognize!");
-  }
-}
-
-void reconnect()
-{
-  // Loop until we're reconnected
-  while (!mqttClient.connected())
-  {
-    Serial.println("Attempting MQTT connection...");
-    // Attempt to connect
-    if (mqttClient.connect(raspberry_ip_str))
-    {
-      Serial.println("Connected!");
-      // Once connected, publish an announcement...
-      //mqttClient.publish("outTopic","How r u, RPi?"); // Message published to the topic
-      // ... and resubscribe
-      //mqttClient.subscribe("time_unix");
-      //Serial.println("Message published and inTopic subscribed in reconnect()...");
-      mqttClient.subscribe("time_unix");
-      mqttClient.subscribe("time_local");
-      mqttClient.subscribe("heating");
-      mqttClient.subscribe("moisturizing");
-      dataLog = SD.open("datalog.txt", FILE_WRITE);
-    }
-    else
-    {
-      Serial.print("Failed, rc=");
-      Serial.println(mqttClient.state());
-      Serial.println(" try again in 5 seconds");
-      // Wait 5 seconds before retrying
-      dataLog.close();
-      delay(5000);
-    }
-  }
-}
-
-
-/*  ###################################
-    #              ACTING             #
-    ###################################
-*/
-
-
-void acting(char* topic, String action) {
-  Serial.println("Entry in acting funcionalities...");
-  if (strcmp(topic, "heating") == 0) {
-    if (action.equals("ON")) {
-      Serial.println("Heating ON");
-      heating_state = HIGH;
-      if (dataLog) {
-        dataLog.println("Heating ON");
-        dataLog.println();
-        dataLog.flush();
-      }
-      else {
-        Serial.println("error opening datalog.txt");
-      }
-      //HEATER ON
-    }
-    else {
-      Serial.println("Heating OFF");
-      heating_state = LOW;
-      if (dataLog) {
-        dataLog.println("Heating OFF");
-        dataLog.println();
-        dataLog.flush();
-      }
-      else {
-        Serial.println("error opening datalog.txt");
-      }
-      //HEATER OFF
-    }
-  }
-  if (strcmp(topic, "moisturizing") == 0) {
-    if (action == "ON") {
-      humid_state = HIGH;
-      Serial.println("Moisturizing ON");
-      if (dataLog) {
-        dataLog.println("Moisturizing ON");
-        dataLog.println();
-        dataLog.flush();
-      }
-      else {
-        Serial.println("error opening datalog.txt");
-      }
-      //HUMIDIFIER' ON
-    }
-    else {
-      humid_state = LOW;
-      Serial.println("Moisturizing OFF");
-      if (dataLog) {
-        dataLog.println("Moisturizing OFF");
-        dataLog.println();
-        dataLog.flush();
-      }
-      else {
-        Serial.println("error opening datalog.txt");
-      }
-      //HUMIDIFIER OFF
-    }
-  }
-}
-
-


Serial for pad

Serial for pad

--- serial.ino
+++ serial.ino
@@ -36,19 +36,19 @@
 {
   switch (serialInput[0])
   {
-    case 'r':
-    case 'R': // Rotation
-      if (serialInput[1] == 'L' || serialInput[1] == 'l') {
-        rotateLeft(serialInput[2] * 100 + serialInput[3] * 10 + serialInput[4]);
-        Serial.print("Step left! -> ");
-        Serial.println(serialInput[2] * 100 + serialInput[3] * 10 + serialInput[4]);
-      }
-      else {
-        rotateRight(serialInput[2] * 100 + serialInput[3] * 10 + serialInput[4]);
-        Serial.print("Step right! -> ");
-        Serial.println(serialInput[2] * 100 + serialInput[3] * 10 + serialInput[4]);
-      }
-      break;
+    //    case 'r':
+    //    case 'R': // Rotation
+    //      if (serialInput[1] == 'L' || serialInput[1] == 'l') {
+    //        rotateLeft(serialInput[2] * 100 + serialInput[3] * 10 + serialInput[4]);
+    //        Serial.print("Step left! -> ");
+    //        Serial.println(serialInput[2] * 100 + serialInput[3] * 10 + serialInput[4]);
+    //      }
+    //      else {
+    //        rotateRight(serialInput[2] * 100 + serialInput[3] * 10 + serialInput[4]);
+    //        Serial.print("Step right! -> ");
+    //        Serial.println(serialInput[2] * 100 + serialInput[3] * 10 + serialInput[4]);
+    //      }
+    //      break;

     case 'f':
     case 'F': // Front direction
@@ -105,7 +105,16 @@
     case 'l':
     case 'L':
       Serial.println("left on");
-      setLeftSpeed(30);
+      setLeftSpeed(serialInput[1] * 100 + serialInput[2] * 10 + serialInput[3]);
+      break;
+
+    case 'R':
+      Serial.println("right on");
+      setRightSpeed(serialInput[1] * 100 + serialInput[2] * 10 + serialInput[3]);
+      break;
+
+      case 'V':
+      Serial.println("PUG");
       break;

     default:


correct

correct

--- dreifachblinker.ino
+++ dreifachblinker.ino
@@ -18,7 +18,6 @@
   pinMode(ledPin1, OUTPUT);
   pinMode(ledPin2, OUTPUT);
   pinMode(ledPin3, OUTPUT);
-  pinMode(taster, INPUT);
 }

   void loop() {


"fix" serial to use the full internal buffer

--- examples/ESP_AsyncFSBrowser/ESP_AsyncFSBrowser.ino
+++ examples/ESP_AsyncFSBrowser/ESP_AsyncFSBrowser.ino
@@ -121,8 +121,9 @@
 extern "C" void system_set_os_print(uint8 onoff);
 extern "C" void ets_install_putc1(void* routine);

+//Use the internal hardware buffer
 static void _u0_putc(char c){
-  while(((U0S >> USTXC) & 0x7F) != 0);
+  while(((U0S >> USTXC) & 0x7F) == 0x7F);
   U0F = c;
 }

@@ -130,9 +131,6 @@
   Serial.begin(115200);
   ets_install_putc1((void *) &_u0_putc);
   system_set_os_print(1);
-}
-
-void initWiFi(){
 }

 void setup(){


I refactored the EsploraPulse.ino file a little.

--- Arduino/EsploraPulse/EsploraPulse.ino
+++ Arduino/EsploraPulse/EsploraPulse.ino
@@ -2,6 +2,7 @@

 const byte CH_TINKERKIT_INA = 8;
 const unsigned long READ_RATE = 50;
+const unsigned int BAUD_RATE = 9600;

 unsigned int readChannel(byte channel) {
   digitalWrite(A0, (channel & 1) ? HIGH : LOW);
@@ -12,7 +13,7 @@
 }

 void setup() {
-  Serial.begin(9600);
+  Serial.begin(BAUD_RATE);

 }


Set up PCB settings file.

Set up PCB settings file.

--- OpenStage/c_userSettings_MEGA_PCB.ino
+++ OpenStage/c_userSettings_MEGA_PCB.ino
@@ -8,8 +8,8 @@
 // * Enable/disable major OpenStage functions
 //
 #define DO_LCD      //Uncomment this line to enable enable LCD character display
-#define DO_GAMEPAD //Uncomment this line to enable PS3 DualShock as an input device
-#define PCB //This is uncommented if the user has an OpenStage PCB
+#define DO_GAMEPAD  //Uncomment this line to enable PS3 DualShock as an input device
+#define PCB         //This is uncommented if the user has an OpenStage PCB

 //------------------------------------------------------------------------------------------------
@@ -27,7 +27,7 @@

 //If using PC serial port, this is the ID of the MEGA's hardware serial line (e.g. Serial3)
 //If using an Uno, or another mic with no hardware serial, then this should be set to "Serial"
-#define HARDWARE_SERIAL_PORT Serial1
+#define HARDWARE_SERIAL_PORT Serial3
 HardwareSerial* SerialComms;  //pointer to stage comms serial object

 //The following is not a user setting
@@ -195,17 +195,7 @@
 // LEDs will light when the stage moves or an axis is reset,
 // *NOTE: Updating the stage LEDs for hat-stick motions requires fast digital writes as motor speed
 //        is set in a closed-loop based on hat-stick position. So we set the stage LEDs using
-//        direct port writes. The code expects the LEDS to be on the first 3 pins of port C of the
-//        Mega. You can use a different port (or even different pins on that port), but then you will
-//        have to change the code in pollPS3. Direct port writes on these pins are only implemented
-//        for the closed-loop hat-stick control code. Elsewhere we use conventional Arduino
-//        digitalWrites, as these are adequate.
-//
-// PC0: 37 (X axis)
-// PC1: 36 (Y axis)
-// PC2: 35 (Z axis)
-// PC3: 34 (a good idea to reserve this for a 4th axis, such as a PIFOC)
-//byte stageLEDs[4]={A3,A2,A1,A0};
+//        direct port writes. The code expects the LEDS to be on the first 3 pins of the port.
 byte stageLEDs[4]={A0,A1,A2,A3};

@@ -221,29 +211,24 @@

 // stepOut
 // One pulse at these pins moves the motor by one step (or one micro-step)
-byte stepOut[maxAxes]={44,31,47,28}; //Set these to the step out pins (ordered X, Y, and Z)
+byte stepOut[maxAxes]={44,31,47,28}; //Set these to the step out pins (ordered X, Y, Z, Z')

 // stepDir
 // These pins tell the Big Easy Driver to which they connect which direction to rotate the motor
-byte stepDir[maxAxes]={45,30,46,29}; //Ordered X, Y, and Z
+byte stepDir[maxAxes]={45,30,46,29}; //Ordered X, Y, Z, Z'

 // enable
 // If these pins are low, the motor is enabled. If high it's disabled. Disabling might decrease
 // electrical noise but will lead to errors in absolute positioning.
-byte enable[maxAxes]={39,36,7,23}; //Ordered X, Y, and Z
+byte enable[maxAxes]={39,36,7,23}; //Ordered X, Y, Z, Z'

 // The microstep pins.
 // These pins define the microstep size. The MS pins on all axes are wired together.
-
-//following are ch1 [FOLLOWING THREE DEFS WILL GO, IN FACT, WE SHOULD RE-DO ALL THE CODE THIS WAY]
-byte MS1=42;
-byte MS2=43;
-byte MS3=40;

 //Let's define an array with the microstepping pins
 byte MS[4][3]={
 	{42,43,40},  //channel 1, MS pins 1,2,3
-	{33,32,36},  //channel 2, MS pins 1,2,3
+	{33,32,35},  //channel 2, MS pins 1,2,3
 	{49,48,10},  //channel 3, MS pins 1,2,3
 	{26,27,24}   //channel 4, MS pins 1,2,3
 	};


lcd update

lcd update

--- _04-mqtt-lcd-dust-sensor/_04-mqtt-lcd-dust-sensor-esp-12/_04-mqtt-lcd-dust-sensor-esp-12.ino
+++ _04-mqtt-lcd-dust-sensor/_04-mqtt-lcd-dust-sensor-esp-12/_04-mqtt-lcd-dust-sensor-esp-12.ino
@@ -25,7 +25,7 @@
 #endif

 char* topic = "esp8266/arduino/s03";
-char* subtopic = "esp8266/#";
+char* subtopic = "#";
 char* hellotopic = "HELLO";

 LiquidCrystal_I2C lcd(0x27, 20, 4);
@@ -111,23 +111,51 @@
 };

+byte pirfill[8] = //icon for dustDensity droplet
+{
+  B00111,
+  B00111,
+  B00111,
+  B00111,
+  B00111,
+  B00111,
+  B00111,
+  B00111,
+};
+
+byte powericon[8] = //icon for dustDensity droplet
+{
+  B11000,
+  B00110,
+  B00011,
+  B01100,
+  B11000,
+  B00110,
+  B00011,
+  B01100,
+};
+
+
+
 PubSubClient client(wifiClient, server);

 void callback(const MQTT::Publish& pub) {
-  /*
+  if (DEBUG_PRINT) {
     Serial.print(pub.topic());
     Serial.print(" => ");
     Serial.println(pub.payload_string());
-  */
-  parseMqttMsg(pub.payload_string());
-}
-
-void parseMqttMsg(String payload) {
-
-  StaticJsonBuffer<200> jsonBuffer;
+  }
+
+  String receivedtopic = pub.topic();
+  parseMqttMsg(pub.payload_string(), receivedtopic);
+}
+
+void parseMqttMsg(String payload, String receivedtopic) {
+
+  StaticJsonBuffer<300> jsonBuffer;

   char json[] =
-    "{\"Humidity\":38.10,\"Temperature\":27.70,\"DS18B20\":28.31,\"PIRSTATUS\":1}";
+    "{\"Humidity\":38.10,\"Temperature\":27.70,\"DS18B20\":28.31,\"SENSORTEMP\":31.31,\"PIRSTATUS\":1}";

   payload.toCharArray(json, 200);

@@ -176,7 +204,7 @@
     NW  = root["NemoWeightAvg"];
   }

-  if ( TEMP_PIR )
+  if ( receivedtopic == "raspberrypi/doorpir" )
   {
     PIR = root["DOORPIR"];
   }
@@ -294,20 +322,21 @@
   lcd.createChar(2, picatura);
   lcd.createChar(3, dustDensityicon);
   lcd.createChar(4, dustDensityfill);
+  lcd.createChar(5, pirfill);
+  lcd.createChar(6, powericon);

   lcd.setCursor(0, 1);
   lcd.write(1);

-  /*
-  lcd.setCursor(0, 2);
-  lcd.write(1);
-  */
-
   lcd.setCursor(0, 2);
   lcd.write(2);

   lcd.setCursor(0, 3);
   lcd.write(3);
+
+  lcd.setCursor(8, 2);
+  lcd.write(6);
+

   H  = 0 ;
   T1 = 0 ;
@@ -407,6 +436,16 @@

 void displaypowerAvg()
 {
+  lcd.setCursor(10, 2);
+  if ( PW > 999 ) {
+    lcd.print(PW, 0);
+    lcd.print("W");
+  } else {
+    lcd.print(PW, 0);
+    lcd.print("W");
+    lcd.print(" ");
+    lcd.print(" ");
+  }

 }

@@ -417,7 +456,26 @@

 void displayPIR()
 {
-
+  if ( PIR == 1)
+  {
+    lcd.setCursor(19, 0);
+    lcd.write(5);
+    lcd.setCursor(19, 1);
+    lcd.write(5);
+    lcd.setCursor(19, 2);
+    lcd.write(5);
+    lcd.setCursor(19, 3);
+    lcd.write(5);
+  } else {
+    lcd.setCursor(19, 0);
+    lcd.print(" ");
+    lcd.setCursor(19, 1);
+    lcd.print(" ");
+    lcd.setCursor(19, 2);
+    lcd.print(" ");
+    lcd.setCursor(19, 3);
+    lcd.print(" ");
+  }
 }

 void displayTemperature()
@@ -449,38 +507,23 @@

 void displaydustDensity()
 {
-
-  lcd.setCursor(3, 1);
-  if ( 0   < dustDensity =< 0.1 ) {
+  int n = int(dustDensity / 0.05) ;
+
+  if (DEBUG_PRINT) {
+    Serial.print("===> dustDensity ");
+    Serial.print(dustDensity);
+    Serial.print(" ===>  ");
+    Serial.println(int(dustDensity / 0.05));
+  }
+
+  for ( int i = 0 ; i <= n ; i++) {
+    lcd.setCursor(2 + i, 3);
     lcd.write(4);
-    lcd.print("    ");
-  }
-  if ( 0.1 < dustDensity =< 0.2 ) {
-    lcd.write(4);
-    lcd.write(4);
-    lcd.print("   ");
-  }
-  if ( 0.2 < dustDensity =< 0.3 ) {
-    lcd.write(4);
-    lcd.write(4);
-    lcd.write(4);
-    lcd.print("  ");
-  }
-  if ( 0.3 < dustDensity =< 0.4 ) {
-    lcd.write(4);
-    lcd.write(4);
-    lcd.write(4);
-    lcd.write(4);
-    lcd.print(" ");
-  }
-  if ( 0.4 < dustDensity =< 0.5 ) {
-    lcd.write(4);
-    lcd.write(4);
-    lcd.write(4);
-    lcd.write(4);
-    lcd.write(4);
-  }
-
+  }
+
+  for ( int o = 0 ; o <= ( 10 - n) ; o++) {
+    lcd.print(" ");
+  }
 }

 void requestSharp()
@@ -495,6 +538,11 @@

   x = a;
   x = x << 8 | b;
+
+  if (DEBUG_PRINT) {
+    Serial.print("X ===>  ");
+    Serial.println(x);
+  }

   if (( x < 1024 ) && (x != OLD_x )) {
     float calcVoltage = x * (5.0 / 1024.0);


change animation func

change animation func

--- tests/Light/ButtonTest/ButtonTest.ino
+++ tests/Light/ButtonTest/ButtonTest.ino
@@ -47,7 +47,7 @@
 RgbColor yellow;

 AnimateFunc wipeStrip = colorWipe;
-AnimateFunc laserStrip = laserWipeEdge;
+AnimateFunc laserStrip = laserWipe;
 LaserWipePosition redLaserPos;
 LaserWipePosition greenLaserPos;
 LaserWipePosition blueLaserPos;


Update example

Update example

--- Photon/Plugins/DHT/examples/dht/dht.ino
+++ Photon/Plugins/DHT/examples/dht/dht.ino
@@ -11,6 +11,7 @@
 All text above must be included in any redistribution.

 Changelog:
+2017-10-28: Update for v2.
 2017-05-20: Initial DHT plugin creation.
 ********************************************************/

@@ -21,8 +22,6 @@

 void setup() {
     iot = IoT::getInstance();
-    iot->setControllerName("myPhoton");
-    iot->setPublishName("patriot");
     iot->begin();
     iot->addDevice(new DHT(D4, DHT11));
 }


wip runs all animations by default. i comm sadjlsdjkasdjsad pretty fucking useless commit

--- work-in-progress/work-in-progress.ino
+++ work-in-progress/work-in-progress.ino
@@ -14,8 +14,8 @@

 void loop() {
-//  jiggly.runAllAnimations(leds, NUM_LEDS, 40, 2000);
-  chimes();
+  jiggly.runAllAnimations(leds, NUM_LEDS, 40, 2000);
+//  chimes();
 }


Update Launchpad_Data_Processor.ino

Update Launchpad_Data_Processor.ino

Made a few extra changes to the Xbee config:
- There is now an extra 'ATCN' command to exit command mode, meaning it starts transmitting data much more quickly
- I've added a timeout on the initial '+++' so that if the Xbee doesn't provide an OK the first time around, after 5 seconds, the '+++' is repeated

The only other issue is straight after power up, where the Xbee won't respond first time around. Shouldn't be a big deal to solve, but at the moment, a reset of the launchpad is still required to get it through the configuration after power up.

--- Launchpad_Data_Processor/Launchpad_Data_Processor.ino
+++ Launchpad_Data_Processor/Launchpad_Data_Processor.ino
@@ -125,29 +125,50 @@
           Serial.println("Printed: atwr");
           break;
         }
+        case 3:
+        {
+          Serial2.println("atcn");
+          Serial.println("Printed: atcn");
+          break;
+        }
         default:
         {
           Serial.println("Xbee Config Error");
           break;
         }
       }
+
       delay(1000);
-
+      int timeCheck = millis()/1000;
+      while(Serial2.available() < 2)
+      {
+        Serial.println("")
+        if((millis()/1000 - timeCheck) > 5) break;
+      }
       if(Serial2.available() > 1)
       {
         char start_buf[10] = "";
         Serial2.readBytes(start_buf, Serial2.available());
-        Serial.println(String(start_buf));

-        if(String(start_buf) == "OK\r")
-          Serial.println("OK found Here");
-        else continue;
-      }
+        if(String(start_buf).equals("OK\r"))
+        {
+          Serial.print(String(start_buf));
+          Serial.println(" Found");
+        }
+        else
+        {
+          Serial.print("No OK received. Serial read was: ");
+          Serial.println(String(start_buf));
+          continue;
+        }
+      }
+      else continue;
+
       ok_count++;
       Serial.flush();
-      Serial.print(ok_count);
-      Serial.println(" OK found");
-    }  while(ok_count < 3);
+      //Serial.print(ok_count);
+      //Serial.println(" OK found");
+    }  while(ok_count < 4);

     Serial.println("OK received. Configuration complete");

@@ -385,4 +406,3 @@
     return;
 }

-


make the serial output less debug-ish

make the serial output less debug-ish

--- MorseCodeDecoder.ino
+++ MorseCodeDecoder.ino
@@ -21,6 +21,7 @@

 int determineDotDash(unsigned long holdMillis);
 String getDotDashString(int input);
+String getDotDashSymbolString(int input);

 void setup() {
   pinMode(LED, OUTPUT);
@@ -50,7 +51,8 @@

     //print the results for now
     if (result == DOT || DASH) {
-      Serial.println(getDotDashString(result) + "(" + previousHold + ")");
+      //Serial.println(getDotDashString(result) + "(" + previousHold + ")");
+      Serial.print(getDotDashSymbolString(result));
     }
   }

@@ -85,3 +87,15 @@
   return toReturn;
 }

+/**
+ * Given DOT, DASH, or NOTHING, return a string with a symbol
+ */
+String getDotDashSymbolString(int input) {
+  String toReturn = "";
+  if (input == DOT) {
+    toReturn = "·";
+  } else if (input == DASH) {
+    toReturn = "-";
+  }
+  return toReturn;
+}


Added DC Stepper Motor as physical component

--- src/CAN/CAN_SHA1_read/CAN_SHA1_read.ino
+++ src/CAN/CAN_SHA1_read/CAN_SHA1_read.ino
@@ -4,6 +4,12 @@
 #include <SPI.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <Stepper.h>
+
+
+#define STEPS 60 // number of steps per revolution of Internal shaft
+int stepsToTake; // 2048 = 1 revolution
+Stepper engine(STEPS, 8, 10, 9, 11); // simulate engine (stepper motor)

 const int HASH_LEN = 20;

@@ -89,6 +95,7 @@
     digitalWrite(RED, LOW);
     digitalWrite(BLUE, LOW);
     digitalWrite(GREEN, LOW);
+    engine.setSpeed(100);
 }

@@ -160,6 +167,8 @@
             Serial.println(totalReceived);
         }
     }
+
+    engine.step(1);
 }

@@ -417,6 +426,7 @@
         analogWrite(RED, redValue);
         analogWrite(GREEN, greenValue);
         analogWrite(BLUE, blueValue);
+        engine.setSpeed((redValue * 100) % 700);
     }
 }


New pins

New pins

Avoids wires crossimg over the GPS antenna

--- gsm_tracker/gsm_tracker.ino
+++ gsm_tracker/gsm_tracker.ino
@@ -13,10 +13,10 @@
 #define FONA_RX A4
 #define FONA_TX A5

-#define GPS_RX 4
-#define GPS_TX 5
-
-#define BUZZER_PIN 6
+#define GPS_RX 11
+#define GPS_TX 12
+
+#define BUZZER_PIN 4
 #define FIX_LED 13

 #define GPS_INTERVAL_SECONDS 10


Wifi connection, cleaned up setup, OTA enabled

Added missing wifi setup call, missing OTA related bool, cleaned up setup area, added OTA startup functions to loop

--- Exhibit_MomentumTable.ino
+++ Exhibit_MomentumTable.ino
@@ -48,6 +48,7 @@
 unsigned long now           = 0 ;
 unsigned long prevMillis    = 0 ;
 unsigned long OTAUntilMillis = 0 ;
+bool OTARdyFlag = 0;
 uint8_t discSlipPrecond     = 0 ;
 uint8_t restartCount        = 0 ;
 char msg[50];
@@ -60,9 +61,10 @@
 pinMode(HALLSENSORPIN, INPUT_PULLUP);
 digitalWrite(STARTRELAYPIN, LOW);
 attachInterrupt(digitalPinToInterrupt(HALLSENSORPIN), sensorPulseCount, FALLING);
+Serial.begin(115200);
+wifiSetup();
 client.setServer(mqtt_server, 1883);
 client.setCallback(callback);
-Serial.begin(115200);
 /////////////////////////////
 delay(5000);
 //motionControlStart(); // remove when MQTT is active. testing only
@@ -85,6 +87,13 @@
     reconnect();
     }
     client.loop();
+    if (now < OTAUntilMillis && OTARdyFlag == 0) {
+      wifiSetupOTA();
+      OTARdyFlag = 1;
+    }
+    if (now < OTAUntilMillis && OTARdyFlag == 1) {
+      ArduinoOTA.handle();
+    }
 }


Defaulting multiFire to 3 events

Defaulting multiFire to 3 events

--- Flameduino/Flameduino.ino
+++ Flameduino/Flameduino.ino
@@ -30,7 +30,7 @@
 const bool debug = false;       //true = write to serial monitor, false = bypass
 const bool triggerHigh = true;  //true = HIGH to fire, false = LOW to fire
 const bool multiFire = true;    //true = fire [firingCount] times per period, false = fire once per period
-const int firingCount = 1;      //Numeber of sparks to fire per event
+const int firingCount = 3;      //Numeber of sparks to fire per event
 const int firingDwell = 2000;   //Ignition coil firing time in microseconds (2ms = 2000us)

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


Added temp sensor

Added temp sensor

--- seven-segment-float/src/seven-segment-float.ino
+++ seven-segment-float/src/seven-segment-float.ino
@@ -93,8 +93,9 @@
     displayNumber();
   }

-  testCaseAllNum();
+  //testCaseAllNum();
   //splitNumber(-99.99999);
+  displayTemperature();

 }

@@ -138,10 +139,10 @@
   for (i=0; i<4; i++)
     displayNum[i] = off;

-  if (n < 0.0) {
-    n = abs(n);
+  if (n < 0.0)
     negative = true;
-  }
+
+  n = abs(n);

   fractional = modf(n, &integral);
   fractional = round(fractional*10);
@@ -214,3 +215,25 @@
       testLoop = -100;
   }
 }
+
+//global variables for LM35 temperature sensor
+const int tempPin = 0;  //analog pin 0
+const long tempInterval = 1000;  //time to delay between refreshing the display, in ms
+long previousTempRefresh = 0; //previous temperature refresh
+
+void displayTemperature () {
+  unsigned long currentTempRefresh = millis();
+
+  if (currentTempRefresh - previousTempRefresh > tempInterval) {
+    previousTempRefresh = currentTempRefresh;
+
+    double tempC = (500.0 * analogRead(tempPin)) / 1204; //poll analog to read value from LM35
+    double tempF = c2f(tempC);
+
+    splitNumber(tempF);
+  }
+}
+
+double c2f (double c) {
+  return ((9*c)/5 + 32);
+}


buzzer now does not delay

buzzer now does not delay

--- short-circuit-limiter/short-circuit-limiter.ino
+++ short-circuit-limiter/short-circuit-limiter.ino
@@ -14,7 +14,7 @@
 #define PIN_RELAY_LIMITER 7

 #define BUZZER_BEEP_ON_TIME 20
-#define BUZZER_BEEP_OFF_TIME 300
+#define BUZZER_BEEP_OFF_TIME 200
 #define BUZZER_LONG_BEEP_TIME 2000

 #define CT_CALIBRATION_VALUE 60.6  // (100A / 0.05A) / 33 ohms
@@ -46,6 +46,8 @@
 CTSensor clamp(PIN_CT, CT_CALIBRATION_VALUE);

 double mcbTrippedCurrent;
+
+int beepsLeft = 0;

 void setup() {

@@ -134,7 +136,7 @@
       break;
    }

-
+  shortBeepRunner();
   displayToScreen(currentValue);

@@ -292,7 +294,7 @@

     currentState = STATE_WINDOW_BEFORE;
     Serial.println("Window Before");
-    shortBeepXTimes(2);
+    shortBeepXTimesNoDelay(2);
   }

@@ -331,7 +333,7 @@
     currentState = STATE_WINDOW_EXITED;
     changeDisplayBacklight(true);
     Serial.println("Exited window, bypass resistor");
-    shortBeepXTimes(1);
+    shortBeepXTimesNoDelay(1);
   }

   passFullCurrentThrough(true);
@@ -394,12 +396,41 @@
   return temperatureC;
 }

-void shortBeepXTimes(int times){
-  for(int i = 0; i < times; i++){
-    digitalWrite(PIN_BUZZER, HIGH);
-    delay(BUZZER_BEEP_ON_TIME);
-    digitalWrite(PIN_BUZZER, LOW);
-    delay(BUZZER_BEEP_OFF_TIME);
-  }
-
-}
+
+void shortBeepXTimesNoDelay(int times){
+  beepsLeft = times;
+}
+
+//We don't use delay from beeps to avoid holding up the controller
+void shortBeepRunner(){
+
+  static bool beepCurrentlyOn = false;
+  static unsigned long beepChangedTime = 0;
+
+  unsigned long currentTime = millis();
+
+  if(beepsLeft > 0){
+
+    if(beepCurrentlyOn){
+
+      if((currentTime - beepChangedTime) > BUZZER_BEEP_ON_TIME){
+          beepChangedTime = currentTime;
+          digitalWrite(PIN_BUZZER, LOW);
+          beepCurrentlyOn = false;
+          beepsLeft--;
+      }
+
+    } else {
+
+      if((currentTime - beepChangedTime) > BUZZER_BEEP_OFF_TIME){
+          beepChangedTime = currentTime;
+          digitalWrite(PIN_BUZZER, HIGH);
+          beepCurrentlyOn = true;
+      }
+    }
+
+  }
+
+
+}
+


Alarm and sampling checks take a minute, added reset commands.

Brightness is lowered in the sampling state as well. This is the last
Arduino commit unless some glaring error shows up.

--- arduino/impetus/impetus.ino
+++ arduino/impetus/impetus.ino
@@ -14,10 +14,8 @@

   display.begin(9600);
   display.write(0x76);
-  display.write('t');
-  display.write('e');
-  display.write('s');
-  display.write('t');
+  display.write(0x7A);
+  display.write(0b11111111);

   i2c_init(); //Initialise the i2c bus
   PORTC = (1 << PORTC4) | (1 << PORTC5);//enable pullups
@@ -37,14 +35,21 @@
   while (Serial.available()) {
     char in = (char) Serial.read();
     if (in == 's') {
-      if (sample) {
-        sample = false;
-        alarm = true;
-        temp = 0;
-        vol = 0;
-        cycle = 0;
-      }
-      Serial.write('a'); // Ack, stop sending.
+      display.write(0x7A);
+      display.write(0b11111111);
+      sample = false;
+      alarm = true;
+      temp = 0;
+      vol = 0;
+      cycle = 0;
+    } else if (in == 'R') { // RESET
+      cycle = vol = 0;
+      temp = 0;
+      sample = alarm = false;
+      display.write(0x79);
+      display.write((byte) 0);
+      display.write(0x7A);
+      display.write(0b11111111);
     } else {
       display.write(in);
     }
@@ -133,11 +138,18 @@
       cycle++;
     else
       cycle = 0;
-    if (cycle > 10) {
+    if (cycle > 10 && alarm)
+      buzz = true; // Don't buzz, but still be able to reset.
+    if (cycle == 60) {
       if (alarm)
         alarm = false;
-      else
+      else {
         sample = true;
+        display.write(0x7A);
+        display.write(0b01111111);
+        if (Serial)
+          Serial.println("S");
+      }
       cycle = 0;
     }
   }


added speed calculation to arduino hall sensor code

--- arduino/rpm_serial_hall.ino
+++ arduino/rpm_serial_hall.ino
@@ -1,32 +0,0 @@
-}/*
-Arduino Hall Effect Sensor Project
-by Arvind Sanjeev
-Please check out  http://diyhacking.com for the tutorial of this project.
-DIY Hacking
-*/
-
- volatile byte revs;
- unsigned int rpm;
- unsigned long timeold;
- void setup()
- {
-   Serial.begin(9600);
-   attachInterrupt(0, magnet_detect, RISING);//Initialize the intterrupt pin (Arduino digital pin 2)
-   revs = 0;
-   rpm = 0;
-   timeold = 0;
- }
- void loop()//Measure RPM
- {
-   if (revs >= 5) {
-     rpm = revs/((millis() - timeold)/1000/60)
-     timeold = millis();
-     revs = 0;
-     Serial.println(rpm,DEC);
-   }
- }
- void magnet_detect()//This function is called whenever a magnet/interrupt is detected by the arduino
- {
-   revs++;
-   Serial.println("detect");+
- }


Delete Mario_Ring.ino

Delete Mario_Ring.ino

--- Mario_Ring/Mario_Ring.ino
+++ Mario_Ring/Mario_Ring.ino
@@ -1,284 +0,0 @@
-/*Arduino Mario Bros Tunes
-  With Piezo Buzzer and PWM
-
- Connect the positive side of the Buzzer to pin 13,
-  by: Dipto Pratyaksa
-  last updated: 31/3/13
-*/
-
-/*************************************************
- * Public Constants
- *************************************************/
-
-#define NOTE_B0  31
-#define NOTE_C1  33
-#define NOTE_CS1 35
-#define NOTE_D1  37
-#define NOTE_DS1 39
-#define NOTE_E1  41
-#define NOTE_F1  44
-#define NOTE_FS1 46
-#define NOTE_G1  49
-#define NOTE_GS1 52
-#define NOTE_A1  55
-#define NOTE_AS1 58
-#define NOTE_B1  62
-#define NOTE_C2  65
-#define NOTE_CS2 69
-#define NOTE_D2  73
-#define NOTE_DS2 78
-#define NOTE_E2  82
-#define NOTE_F2  87
-#define NOTE_FS2 93
-#define NOTE_G2  98
-#define NOTE_GS2 104
-#define NOTE_A2  110
-#define NOTE_AS2 117
-#define NOTE_B2  123
-#define NOTE_C3  131
-#define NOTE_CS3 139
-#define NOTE_D3  147
-#define NOTE_DS3 156
-#define NOTE_E3  165
-#define NOTE_F3  175
-#define NOTE_FS3 185
-#define NOTE_G3  196
-#define NOTE_GS3 208
-#define NOTE_A3  220
-#define NOTE_AS3 233
-#define NOTE_B3  247
-#define NOTE_C4  262
-#define NOTE_CS4 277
-#define NOTE_D4  294
-#define NOTE_DS4 311
-#define NOTE_E4  330
-#define NOTE_F4  349
-#define NOTE_FS4 370
-#define NOTE_G4  392
-#define NOTE_GS4 415
-#define NOTE_A4  440
-#define NOTE_AS4 466
-#define NOTE_B4  494
-#define NOTE_C5  523
-#define NOTE_CS5 554
-#define NOTE_D5  587
-#define NOTE_DS5 622
-#define NOTE_E5  659
-#define NOTE_F5  698
-#define NOTE_FS5 740
-#define NOTE_G5  784
-#define NOTE_GS5 831
-#define NOTE_A5  880
-#define NOTE_AS5 932
-#define NOTE_B5  988
-#define NOTE_C6  1047
-#define NOTE_CS6 1109
-#define NOTE_D6  1175
-#define NOTE_DS6 1245
-#define NOTE_E6  1319
-#define NOTE_F6  1397
-#define NOTE_FS6 1480
-#define NOTE_G6  1568
-#define NOTE_GS6 1661
-#define NOTE_A6  1760
-#define NOTE_AS6 1865
-#define NOTE_B6  1976
-#define NOTE_C7  2093
-#define NOTE_CS7 2217
-#define NOTE_D7  2349
-#define NOTE_DS7 2489
-#define NOTE_E7  2637
-#define NOTE_F7  2794
-#define NOTE_FS7 2960
-#define NOTE_G7  3136
-#define NOTE_GS7 3322
-#define NOTE_A7  3520
-#define NOTE_AS7 3729
-#define NOTE_B7  3951
-#define NOTE_C8  4186
-#define NOTE_CS8 4435
-#define NOTE_D8  4699
-#define NOTE_DS8 4978
-
-#define melodyPin 13
-//Mario main theme melody
-int melody[] = {
-  NOTE_E7, NOTE_E7, 0, NOTE_E7,
-  0, NOTE_C7, NOTE_E7, 0,
-  NOTE_G7, 0, 0,  0,
-  NOTE_G6, 0, 0, 0,
-
-  NOTE_C7, 0, 0, NOTE_G6,
-  0, 0, NOTE_E6, 0,
-  0, NOTE_A6, 0, NOTE_B6,
-  0, NOTE_AS6, NOTE_A6, 0,
-
-  NOTE_G6, NOTE_E7, NOTE_G7,
-  NOTE_A7, 0, NOTE_F7, NOTE_G7,
-  0, NOTE_E7, 0, NOTE_C7,
-  NOTE_D7, NOTE_B6, 0, 0,
-
-  NOTE_C7, 0, 0, NOTE_G6,
-  0, 0, NOTE_E6, 0,
-  0, NOTE_A6, 0, NOTE_B6,
-  0, NOTE_AS6, NOTE_A6, 0,
-
-  NOTE_G6, NOTE_E7, NOTE_G7,
-  NOTE_A7, 0, NOTE_F7, NOTE_G7,
-  0, NOTE_E7, 0, NOTE_C7,
-  NOTE_D7, NOTE_B6, 0, 0
-};
-//Mario main them tempo
-int tempo[] = {
-  12, 12, 12, 12,
-  12, 12, 12, 12,
-  12, 12, 12, 12,
-  12, 12, 12, 12,
-
-  12, 12, 12, 12,
-  12, 12, 12, 12,
-  12, 12, 12, 12,
-  12, 12, 12, 12,
-
-  9, 9, 9,
-  12, 12, 12, 12,
-  12, 12, 12, 12,
-  12, 12, 12, 12,
-
-  12, 12, 12, 12,
-  12, 12, 12, 12,
-  12, 12, 12, 12,
-  12, 12, 12, 12,
-
-  9, 9, 9,
-  12, 12, 12, 12,
-  12, 12, 12, 12,
-  12, 12, 12, 12,
-};
-//Underworld melody
-int underworld_melody[] = {
-  NOTE_C4, NOTE_C5, NOTE_A3, NOTE_A4,
-  NOTE_AS3, NOTE_AS4, 0,
-  0,
-  NOTE_C4, NOTE_C5, NOTE_A3, NOTE_A4,
-  NOTE_AS3, NOTE_AS4, 0,
-  0,
-  NOTE_F3, NOTE_F4, NOTE_D3, NOTE_D4,
-  NOTE_DS3, NOTE_DS4, 0,
-  0,
-  NOTE_F3, NOTE_F4, NOTE_D3, NOTE_D4,
-  NOTE_DS3, NOTE_DS4, 0,
-  0, NOTE_DS4, NOTE_CS4, NOTE_D4,
-  NOTE_CS4, NOTE_DS4,
-  NOTE_DS4, NOTE_GS3,
-  NOTE_G3, NOTE_CS4,
-  NOTE_C4, NOTE_FS4, NOTE_F4, NOTE_E3, NOTE_AS4, NOTE_A4,
-  NOTE_GS4, NOTE_DS4, NOTE_B3,
-  NOTE_AS3, NOTE_A3, NOTE_GS3,
-  0, 0, 0
-};
-//Underwolrd tempo
-int underworld_tempo[] = {
-  12, 12, 12, 12,
-  12, 12, 6,
-  3,
-  12, 12, 12, 12,
-  12, 12, 6,
-  3,
-  12, 12, 12, 12,
-  12, 12, 6,
-  3,
-  12, 12, 12, 12,
-  12, 12, 6,
-  6, 18, 18, 18,
-  6, 6,
-  6, 6,
-  6, 6,
-  18, 18, 18, 18, 18, 18,
-  10, 10, 10,
-  10, 10, 10,
-  3, 3, 3
-};
-
-void setup(void)
-{
-  pinMode(13, OUTPUT);//buzzer
-  pinMode(10, OUTPUT);//led indicator when singing a note
-
-}
-void loop()
-{
-  //sing the tunes
-  sing(1);
-  sing(1);
-  sing(2);
-}
-int song = 0;
-
-void sing(int s) {
-  // iterate over the notes of the melody:
-  song = s;
-  if (song == 2) {
-    Serial.println(" 'Underworld Theme'");
-    int size = sizeof(underworld_melody) / sizeof(int);
-    for (int thisNote = 0; thisNote < size; thisNote++) {
-
-      // to calculate the note duration, take one second
-      // divided by the note type.
-      //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
-      int noteDuration = 1000 / underworld_tempo[thisNote];
-
-      buzz(melodyPin, underworld_melody[thisNote], noteDuration);
-
-      // to distinguish the notes, set a minimum time between them.
-      // the note's duration + 30% seems to work well:
-      int pauseBetweenNotes = noteDuration * 1.30;
-      delay(pauseBetweenNotes);
-
-      // stop the tone playing:
-      buzz(melodyPin, 0, noteDuration);
-
-    }
-
-  } else {
-
-    Serial.println(" 'Mario Theme'");
-    int size = sizeof(melody) / sizeof(int);
-    for (int thisNote = 0; thisNote < size; thisNote++) {
-
-      // to calculate the note duration, take one second
-      // divided by the note type.
-      //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
-      int noteDuration = 1000 / tempo[thisNote];
-
-      buzz(melodyPin, melody[thisNote], noteDuration);
-
-      // to distinguish the notes, set a minimum time between them.
-      // the note's duration + 30% seems to work well:
-      int pauseBetweenNotes = noteDuration * 1.30;
-      delay(pauseBetweenNotes);
-
-      // stop the tone playing:
-      buzz(melodyPin, 0, noteDuration);
-
-    }
-  }
-}
-
-void buzz(int targetPin, long frequency, long length) {
-  digitalWrite(10, HIGH);
-  long delayValue = 1000000 / frequency / 2; // calculate the delay value between transitions
-  //// 1 second's worth of microseconds, divided by the frequency, then split in half since
-  //// there are two phases to each cycle
-  long numCycles = frequency * length / 1000; // calculate the number of cycles for proper timing
-  //// multiply frequency, which is really cycles per second, by the number of seconds to
-  //// get the total number of cycles to produce
-  for (long i = 0; i < numCycles; i++) { // for the calculated length of time...
-    digitalWrite(targetPin, HIGH); // write the buzzer pin high to push out the diaphram
-    delayMicroseconds(delayValue); // wait for the calculated delay value
-    digitalWrite(targetPin, LOW); // write the buzzer pin low to pull back the diaphram
-    delayMicroseconds(delayValue); // wait again or the calculated delay value
-  }
-  digitalWrite(10, LOW);
-
-}


Update RS485_UnoR3_Slave.ino

Update RS485_UnoR3_Slave.ino

--- rs485/RS485_UnoR3_Slave.ino
+++ rs485/RS485_UnoR3_Slave.ino
@@ -26,8 +26,11 @@
     lcd.begin(16, 2);
     lcd.setRGB(colorR, colorG, colorB);
     lcd.print("Receiving from Master...");
+  //This line apply to get function & register from master
+  //modbus_configure(&Serial, baud, SERIAL_8N2: 8bits, non-parity-2 bit stop, scan rate, pin2, HOLDING_REGS_SIZE, holdingRegs);
+  modbus_configure(&Serial, 9600, SERIAL_8N2, 1, 2, HOLDING_REGS_SIZE, holdingRegs);

-  modbus_configure(&Serial, 9600, SERIAL_8N2, 1, 2, HOLDING_REGS_SIZE, holdingRegs);
+  //this line apply to send response to Master modbus_update_comms(9600, SERIAL_8N2, ID_slave: 1);
   modbus_update_comms(9600, SERIAL_8N2, 1);

   pinMode(LED, OUTPUT);


Fixed variable error in WifiTwitterClient

--- WiFi/examples/WifiTwitterClient/WifiTwitterClient.ino
+++ WiFi/examples/WifiTwitterClient/WifiTwitterClient.ino
@@ -13,7 +13,7 @@
  Circuit:
  * WiFi shield attached to pins 10, 11, 12, 13

- created 4 Mar 2012
+ created 8 Mar 2012
  by Tom Igoe

  This code is in the public domain.
@@ -25,7 +25,7 @@
 char ssid[] = "YourNetwork"; //  your network SSID (name)
 char pass[] = "password";    // your network password (use for WPA, or use as key for WEP)
 int keyIndex = 0;            // your network key Index number (needed only for WEP)
-
+int status = WL_IDLE_STATUS; // status of the wifi connection

 // initialize the library instance:
 WiFiClient client;


Add Particle Cloud variable to read KWh meter remotely

--- code/oakpowerboard/oakpowerboard.ino
+++ code/oakpowerboard/oakpowerboard.ino
@@ -11,18 +11,10 @@
 #include "roboto_thin_20.h"
 #include "images.h"

-
 #include "eepromanything.h"

 #define PULSES_PER_KWH 375
 #define WH_PER_PULSE (1000.0F / PULSES_PER_KWH)
-
-struct config_t
-{
-  int state;
-  float consumption_total;
-  int pulse_count_current_kwh;
-} storage;

 #define BTN_1 9
 #define BTN_2 8
@@ -33,9 +25,17 @@

 #define EEPROM_READ_ADDR 0

+struct config_t
+{
+  int state;
+  double consumption_total;
+  int pulse_count_current_kwh;
+} storage;
+
+double particle_total_kwh = 0;
 char consumption_total_str[10] = "00000.00";

-float consumption_current = 0.0F;
+double particle_consumption_current = 0;
 char consumption_current_str[6] = "Wait";

 long time_since_last_pulse = millis();
@@ -63,63 +63,40 @@
 };

 bool isConnected = false;
-
 bool b1_pressed = false;
 bool b2_pressed = false;
 bool b3_pressed = false;
 bool b4_pressed = false;
 bool pulse_triggered = false;

-void toggle_b1() {
-  b1_pressed = true;
-}
-
-void toggle_b2() {
-  b2_pressed = true;
-}
-
-void toggle_b3() {
-  b3_pressed = true;
-}
-
-void toggle_b4() {
-  b4_pressed = true;
-}
-
-void trigger_pulse() {
-  pulse_triggered = true;
-}
+void toggle_b1() { b1_pressed = true; }
+void toggle_b2() { b2_pressed = true; }
+void toggle_b3() { b3_pressed = true; }
+void toggle_b4() { b4_pressed = true; }
+void trigger_pulse() { pulse_triggered = true; }

 void setup() {
+  Particle.variable("total", particle_total_kwh);
+  Particle.variable("current", particle_consumption_current);
   EEPROM_readAnything(EEPROM_READ_ADDR, storage);
-  if(storage.state != 0xF7) {
-    storage.state = 0xF7;
-    storage.consumption_total = 56712.0f;
-    storage.pulse_count_current_kwh = 0;
+  if(storage.state != 0xFA) {
+    storage.state = 0xFA;
+    storage.consumption_total = 56713.0f;
+    storage.pulse_count_current_kwh = 370;
     EEPROM_writeAnything(EEPROM_READ_ADDR, storage);
   }
+
   dtostrf(storage.consumption_total, 6, 2, consumption_total_str);
-
+
   ui.setTargetFPS(30);
   ui.setActiveSymbole(activeSymbole);
   ui.setInactiveSymbole(inactiveSymbole);
   ui.setIndicatorPosition(TOP);
-
-  // Defines where the first frame is located in the bar.
   ui.setIndicatorDirection(LEFT_RIGHT);
-
-  // You can change the transition that is used
-  // SLIDE_LEFT, SLIDE_RIGHT, SLIDE_TOP, SLIDE_DOWN
   ui.setFrameAnimation(SLIDE_LEFT);
-
   ui.setTimePerFrame(7000);
-  // Add frames
   ui.setFrames(frames, 2);
-
-  // Add overlays
   ui.setOverlays(overlays, 1);
-
-  // Inital UI takes care of initalising the display too.
   ui.init();

   display.flipScreenVertically();
@@ -173,9 +150,10 @@
           EEPROM_writeAnything(EEPROM_READ_ADDR, storage);
         }
         yield();
-        consumption_current = get_consumption_from_time_since_last_pulse(time_since_last_pulse);
-        dtostrf(storage.consumption_total + ((((float)storage.pulse_count_current_kwh) * WH_PER_PULSE) / 1000.0F), 6, 2, consumption_total_str);
-        dtostrf(consumption_current, 4, 0, consumption_current_str);
+        particle_consumption_current = get_consumption_from_time_since_last_pulse(time_since_last_pulse);
+        particle_total_kwh = storage.consumption_total + ((((float)storage.pulse_count_current_kwh) * WH_PER_PULSE) / 1000.0F);
+        dtostrf(particle_total_kwh, 6, 2, consumption_total_str);
+        dtostrf(particle_consumption_current, 4, 0, consumption_current_str);
         time_since_last_pulse = millis();
         pulse_triggered = false;
         yield();
@@ -218,7 +196,7 @@
 float get_consumption_from_time_since_last_pulse(long timeSinceLastPulse) {
   long time = millis();
   long dsecs = (time - timeSinceLastPulse) / 100;
-  if(dsecs < 5) { //5 dsecs = 0.5 sec: the highest supported interval for this sketch.
+  if(dsecs < 4) { //4 dsecs = 0.4 sec: the highest supported interval for this sketch.
     time_since_last_pulse = time;
     return 0.0F;
   }


Implement MQTT availability topic for HomeAssistant

--- src/light.ino
+++ src/light.ino
@@ -30,7 +30,7 @@
     // MQTT discovery for Home Assistant
     if (cfg.mqtt_ha_use_discovery && !cfg.mqtt_ha_is_discovered) {
       static const int BUFFER_SIZE =
-          JSON_OBJECT_SIZE(8) + 128; // '128' is an arbritrary number. Increase
+          JSON_OBJECT_SIZE(9) + 128; // '128' is an arbritrary number. Increase
                                      // if required by the payload
       StaticJsonBuffer<BUFFER_SIZE> mqttJsonBuffer;
       JsonObject &md_root = mqttJsonBuffer.createObject();
@@ -43,6 +43,7 @@
       md_root[KEY_COLORTEMP] = true;
       md_root[KEY_BRIGHTNESS] = true;
       md_root[KEY_WHITE] = true;
+      md_root["availability_topic"] = cfg.mqtt_lwt_topic;

       // Build the payload
       char md_buffer[md_root.measureLength() + 1];


updated read-light-current

updated read-light-current

- renamed address character

--- software/read-light-current/read-light-current.ino
+++ software/read-light-current/read-light-current.ino
@@ -15,6 +15,8 @@
 #define VCC 3572  // vcc in mV
 #define ADC 3

+unsigned char i2c_address = 35;
+
 void setup()
 {
     pinMode(LED, OUTPUT);
@@ -26,12 +28,12 @@

 void loop()
 {
-  Wire.beginTransmission(35); // transmit to device #35 (0x23)
+  Wire.beginTransmission(i2c_address); // transmit to device #35 (0x23)
                               // device address is specified in datasheet
   Wire.write(byte(0x10));            // sends instruction byte
   Wire.endTransmission();    // stop transmitting

-  Wire.requestFrom(35,2);    // request 6 bytes from slave device #2
+  Wire.requestFrom(i2c_address,2);    // request 2 bytes from slave device #2

 //  while(Wire.available())    // slave may send less than requested
 //  {


daily filename logging

daily filename logging

--- homemonitor_yun/homemonitor_yun.ino
+++ homemonitor_yun/homemonitor_yun.ino
@@ -8,8 +8,11 @@

 dht DHT;

-//#define DO_LOGGING
-#define FILE_PATH ("/mnt/sd/datalog.txt")
+// Uncomment DO_LOGGING to enable logging data to SD card
+#define DO_LOGGING
+
+
+#define FILE_DIRECTORY "/mnt/sd/"

 // Pins 2/3 are hardwired for I2C on the Arduino Yun
 #define DHT22_PIN 4
@@ -19,11 +22,17 @@

 Process date; // process used to get the date
 String dateTimeString; // string holding process returned date and time
+String datestring; // Used by file writer/LCD for formatting
+
+#define MAX_FILEPATH_LENGTH 50
+static char filePath[MAX_FILEPATH_LENGTH];
+String filename;

 // Used for main loop timing purposes
 int last_second = -1;
 int last_minute = -1;
 int last_hour = -1;
+int last_day = -1;
 int last_sensor_read_time = -1;

 // Sensor results arrays
@@ -37,8 +46,11 @@
 {
   Bridge.begin();
   Console.begin();
+#ifdef DO_LOGGING
   FileSystem.begin();
-
+  filename.reserve(MAX_FILEPATH_LENGTH);
+  datestring.reserve(20);
+#endif
   lcd.init();
   lcd.backlight();

@@ -66,18 +78,30 @@
   Console.println("Temp/Humidity Logging using DHT sensors");
   Console.print("DHT LIBRARY VERSION: ");
   Console.println(DHT_LIB_VERSION);
-#ifdef DO_LOGGING
-  Console.println("Logging Enabled");
-  Console.print("Logging to");
-  Console.println(FILE_PATH);
-#else
-  Console.println("Logging Disabled");
-#endif

   // Update time  from server, and there-after every X
   updateTimeFromServer(); // ~1.16s
   Console.print("Current time Set to: ");
   displayCurrentTime();
+
+#ifdef DO_LOGGING
+  Console.println("Logging Enabled");
+  Console.print("Logging to");
+  Console.println(FILE_DIRECTORY);
+
+  // Set filename to record to
+  getFilename();
+  Console.print("Filename set to: ");
+  Console.println(filePath);
+  lcd.print("Filename set to:");
+  lcd.setCursor(0, 1);
+  lcd.print(filename.substring(8)); // Assuming 8 chars is length of FILE_DIRECTORY
+  delay(2000);
+
+#else
+  Console.println("Logging Disabled");
+#endif
+
   Console.println("------");
 }

@@ -99,6 +123,24 @@

     updateLCD();
   }
+
+  //// EVERY DAY (Update Filename here before writing etc.)
+  if (day() != last_day)
+  {
+    last_day = day();
+#ifdef DO_LOGGING
+    getFilename();
+    Console.print("Filename set to: ");
+    Console.println(filePath);
+
+    lcd.clear();
+    lcd.print("Filename set to:");
+    lcd.setCursor(0, 1);
+    lcd.print(filename.substring(8)); // Assuming 8 chars is length of FILE_DIRECTORY
+    delay(2000);
+#endif
+  }
+

   //// EVERY 10 SECONDS
   // Read sensors every 10 seconds
@@ -179,49 +221,105 @@
     }
 }

+#ifdef DO_LOGGING
+
+// Restriction on filename length is 8 chars not including extension for FAT?
+// Readings_018.txt is what seems to get generated, so maybe 12 chars
+void getFilename()
+{
+  filename = FILE_DIRECTORY;
+  filename += 'R';
+
+  filename += year();
+  filename += '_';
+
+  if (month() < 10) {filename += '0';}
+  filename += month();
+  filename += '_';
+
+  if (day() < 10) {filename += '0';}
+  filename += day();
+
+  filename += ".txt";
+
+  // Push to filePath char array
+  filename.toCharArray(filePath, MAX_FILEPATH_LENGTH);
+}
+
 // Store data on file : TODO Save to separate file each day
 void logToFile()
 {
-  File dataFile = FileSystem.open(FILE_PATH, FILE_APPEND);
-    if (dataFile) {
-      dataFile.print(dateTimeString);
-      dataFile.print("\t");
-      dataFile.print(humidity[0],1);
-      dataFile.print("\t");
-      dataFile.print(temp[0],1);
-      dataFile.print("\t");
-      dataFile.print(humidity[1],1);
-      dataFile.print("\t");
-      dataFile.print(temp[1],1);
-      dataFile.print("\t");
-      dataFile.print(humidity[2],1);
-      dataFile.print("\t");
-      dataFile.print(temp[2],1);
-      dataFile.println();
-
-      dataFile.close();
-
-      Console.print("Logged: ");
-      Console.print(dateTimeString);
-      Console.print("\t");
-      Console.print(humidity[0],1);
-      Console.print("\t");
-      Console.print(temp[0],1);
-      Console.print("\t");
-      Console.print(humidity[1],1);
-      Console.print("\t");
-      Console.print(temp[1],1);
-      Console.print("\t");
-      Console.print(humidity[2],1);
-      Console.print("\t");
-      Console.print(temp[2],1);
-      Console.println();
-    }
-    else
-    {
-      Console.println("error opening logfile");
-    }
-}
+  File dataFile = FileSystem.open(filePath, FILE_APPEND);
+  datestring = "";
+  datestring += year();
+  datestring += '/';
+  if (month() < 10) {datestring += '0';}
+  datestring += month();
+  datestring += '/';
+
+  if (day() < 10) {datestring += '0';}
+  datestring += day();
+  datestring += ' ';
+
+  if (hour() < 10) {datestring += '0';}
+  datestring += hour();
+  datestring += ':';
+
+  if (minute() < 10) {datestring += '0';}
+  datestring += minute();
+
+  if (dataFile) {
+    dataFile.print(datestring);
+    dataFile.print("\t");
+    dataFile.print(humidity[0],1);
+    dataFile.print("\t");
+    dataFile.print(temp[0],1);
+    dataFile.print("\t");
+    dataFile.print(humidity[1],1);
+    dataFile.print("\t");
+    dataFile.print(temp[1],1);
+    dataFile.print("\t");
+    dataFile.print(humidity[2],1);
+    dataFile.print("\t");
+    dataFile.print(temp[2],1);
+    dataFile.println();
+
+    dataFile.close();
+
+    Console.print("Logged to ");
+    Console.print(filePath);
+    Console.print(": ");
+
+    Console.print(datestring);
+    Console.print("\t");
+    Console.print(humidity[0],1);
+    Console.print("\t");
+    Console.print(temp[0],1);
+    Console.print("\t");
+    Console.print(humidity[1],1);
+    Console.print("\t");
+    Console.print(temp[1],1);
+    Console.print("\t");
+    Console.print(humidity[2],1);
+    Console.print("\t");
+    Console.print(temp[2],1);
+    Console.println();
+  }
+  else
+  {
+    Console.print("Error opening ");
+    Console.println(filePath);
+
+    lcd.clear();
+    lcd.print("SD Write Error");
+    lcd.setCursor(0,1);
+    lcd.print(filePath);
+    lcd.print("SD Write Error");
+
+    delay(2000);
+  }
+}
+#endif

 void updateLCD()


sometimes status jumping to timed out, need to check

--- _64-esp8266-atmega328p-i2c8x8-mma-8452-dash-button/a-02-atmega328p/a-02-atmega328p.ino
+++ _64-esp8266-atmega328p-i2c8x8-mma-8452-dash-button/a-02-atmega328p/a-02-atmega328p.ino
@@ -77,7 +77,7 @@
 void button_down_isr()
 {
   bbutton_downp_isr = true;
-  startMiils = millis();
+  //startMiils = millis();
   detachInterrupt(digitalPinToInterrupt(BUTTON_INT));
   attachInterrupt(digitalPinToInterrupt(BUTTON_INT), button_up_isr, RISING);
 }
@@ -112,6 +112,7 @@
   Serial.println("going to sleep....");
   Serial.flush();

+  startMiils = millis();
   bbutton_up_isr = bbutton_downp_isr = haveData = dataUpdated = false;
   device_pro.button = device_pro.esp8266 = 0;
   device_pro.hash = calc_hash(device_pro);


Clean up ugly hacks for easyracelaptimer option

--- CoreIR.ino
+++ CoreIR.ino
@@ -21,12 +21,7 @@
 //#define debug

 // EasyRaceLapTimer support ---- TESTING
-  #define easytimer
-
-
-#ifdef easytimer
-  const int easylap_on = 0;
-#endif
+//  #define easytimer

 //check which arduino board we are using and build accordingly
 #if defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny167__) || defined(__AVR_ATtiny85__)
@@ -42,7 +37,7 @@
   //define nothing
 #endif

-#if defined(easytimer)
+#ifdef easytimer
   #include "Easytimer.h"
 #endif

@@ -108,10 +103,9 @@
   #ifdef debug
     Serial.print("Building code from: ");
   #endif
-  if (easylap_on == 1){
+  #if defined(easytimer)
     geteasylapcode();
-  }
-  else {
+  #else
     if (digitalRead(bridgePinIn)) {
       #ifdef debug
         Serial.println("Main ID:");
@@ -127,7 +121,7 @@
       interval = 1000; // Blink LED slower for alt id
       makeOutputCode(tx_alt_id); // use standard ID otherwise
     }
-  }
+  #endif

   // Set up for blinking the status LED
   pinMode(ledPin, OUTPUT);
@@ -137,7 +131,7 @@
   #ifdef atmega
   //serial data stuff for coreir-uplink support
   // send data only when you receive data:
-  if (easylap_on == 1) {
+  #ifdef easytimer
     if (Serial.available() > 0) {
       // read the incoming byte:
       incomingString = Serial.readString();
@@ -157,8 +151,7 @@
         incomingString = "";
         }
       }
-    }
-    else {
+    #else
       if (Serial.available() > 0) {
       // read the incoming byte:
       incomingString = Serial.readString();
@@ -178,19 +171,18 @@
         incomingString = "";
         }
       }
-    }
+    #endif
     #endif

-  if (easylap_on == 1){
+  #ifdef easytimer
       irsend.sendRaw(buffer,NUM_BITS,38);
       delay(17 + random(0, 5));
-    }
-    else {
+   #else
       //Send the IR signal, then wait the appropriate amount of time before re-sending
       irsend.sendRaw(outputcode, codeLen, khz);
       delay(7 + random(2, 5));
-    }
+    #endif

   // -----Status LED blink code start -----
     unsigned long currentMillis = millis();


fixed getting LocalIP

fixed getting LocalIP

--- liveimu/liveimu.ino
+++ liveimu/liveimu.ino
@@ -1,6 +1,6 @@
 #include "Particle.h"
-
-#include "Adafruit_10DOF_IMU/Adafruit_10DOF_IMU.h"
+#include<Wire.h>
+//#include "Adafruit_10DOF_IMU/Adafruit_10DOF_IMU.h"

 SYSTEM_THREAD(ENABLED);

@@ -14,11 +14,14 @@
 // Sensors

 /* Assign a unique ID to the sensors */
-Adafruit_10DOF dof;
-Adafruit_LSM303_Accel_Unified accel(30301);
-Adafruit_LSM303_Mag_Unified mag(30302);
-Adafruit_BMP085_Unified bmp(18001);
-float seaLevelPressure = SENSORS_PRESSURE_SEALEVELHPA;
+// Adafruit_10DOF dof;
+// Adafruit_LSM303_Accel_Unified accel(30301);
+// Adafruit_LSM303_Mag_Unified mag(30302);
+// Adafruit_BMP085_Unified bmp(18001);
+// float seaLevelPressure = SENSORS_PRESSURE_SEALEVELHPA;
+
+const int MPU_addr=0x68;  // I2C address of the MPU-6050
+int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;

 enum State { STATE_REQUEST, STATE_REQUEST_WAIT, STATE_CONNECT, STATE_SEND_DATA, STATE_RETRY_WAIT };
 State state = STATE_REQUEST;
@@ -34,7 +37,13 @@
 	Particle.function("devices", devicesHandler);

 	// Initialize sensors
-	sensorsInitialized = (accel.begin() && mag.begin() && bmp.begin());
+	// sensorsInitialized = (accel.begin() && mag.begin() && bmp.begin());
+	Wire.begin();
+	Wire.beginTransmission(MPU_addr);
+	Wire.write(0x6B);  // PWR_MGMT_1 register
+	Wire.write(0);     // set to zero (wakes up the MPU-6050)
+	Wire.endTransmission(true);
+
 }

 void loop() {
@@ -95,8 +104,39 @@
 		break;
 	}
 }
-
-void sendData(void) {
+void sendData(void){
+	Wire.beginTransmission(MPU_addr);
+	Wire.write(0x3B);  // starting with register 0x3B (ACCEL_XOUT_H)
+	Wire.endTransmission(false);
+	Wire.requestFrom(MPU_addr,14,true);  // request a total of 14 registers
+	AcX=Wire.read()<<8|Wire.read();  // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)
+	AcY=Wire.read()<<8|Wire.read();  // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
+	AcZ=Wire.read()<<8|Wire.read();  // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)
+	Tmp=Wire.read()<<8|Wire.read();  // 0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L)
+	GyX=Wire.read()<<8|Wire.read();  // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L)
+	GyY=Wire.read()<<8|Wire.read();  // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L)
+	GyZ=Wire.read()<<8|Wire.read();  // 0x47 (GYRO_ZOUT_H) & 0x48 (GYRO_ZOUT_L)
+
+	Serial.print(","); Serial.print(GyX);
+	Serial.print(","); Serial.print(GyY);
+	Serial.print(","); Serial.println(GyZ);
+	// Use printf and manually added a \n here. The server code splits on LF only, and using println/
+	// printlnf adds both a CR and LF. It's easier to parse with LF only, and it saves a byte when
+	// transmitting.
+	client.printf("%.3f,%.3f,%.3f,%.3f,%.2f,%.1f\n",
+			AcX, AcY, AcZ,
+			GyX, GyY, Tmp/340.00+36.53);
+
+	// roll,pitch,heading,altitude,pressure,temperature
+	// Example:
+	// 0.000,-0.449,-49.091,263.317,982.02,27.5
+	// -0.224,-0.224,-48.955,262.719,982.09,27.5
+	// 0.000,-0.449,-48.704,262.719,982.09,27.5
+	// 0.000,-0.449,-48.704,262.890,982.07,27.5
+}
+
+
+void sendData_old(void) {
 	// Called periodically when connected via TCP to the server to update data.
 	// Unlike Particle.publish you can push a very large amount of data through this connection,
 	// theoretically up to about 800 Kbytes/sec, but really you should probably shoot for something


Removed unnecessary comment line from hellodotstar.ino

--- arduino/hellodotstar/hellodotstar.ino
+++ arduino/hellodotstar/hellodotstar.ino
@@ -39,9 +39,6 @@
   delay(1000);
 }
 void loop() {
-  // and so on . . .
-
-
   // Start off with LEDs set to random colors
   for (int i = 0; i < NUMPIXELS; i++) {
     frame[i] = colors[random(3)];   // Save the color in the frame


Added blink actions to help indicate code working.

--- Arduino/victoria_teensy_circuit_test_ros_node/victoria_teensy_circuit_test_ros_node.ino
+++ Arduino/victoria_teensy_circuit_test_ros_node/victoria_teensy_circuit_test_ros_node.ino
@@ -49,6 +49,11 @@
 bool imu_err = false;
 bool mag_err = false;

+#define BLINK_DURATION 2000
+#define BLINK_PIN 13 // Teensy digital pin 13 for LED
+int blink_state;
+unsigned long next_blink_time;
+
 char debug_str[80];

 std_msgs::String ros_debug_msg;
@@ -79,11 +84,13 @@
   } else {
     mag_err = true;
   }
-
-  mag.enableDefault();

   // Start serial port to TRex
   trex.begin(19200);
+
+  next_blink_time = millis();
+  blink_state = LOW;
+  pinMode(BLINK_PIN, OUTPUT);

   // Initialize ros node
   ros_nh.initNode();
@@ -142,5 +149,16 @@
   // Send all the ROS messages
   ros_nh.spinOnce();

+  // Indicate to outside world that something is going on
+  if (millis() > next_blink_time) {
+    if (blink_state == LOW) {
+      blink_state = HIGH;
+    } else {
+      blink_state = LOW;
+    }
+    digitalWrite(BLINK_PIN, blink_state);
+    next_blink_time = millis() + BLINK_DURATION;
+  }
+
   // TODO: control the rate that messages are published?
 }


Faster myHaum and gas calibration

Faster myHaum and gas calibration

Had to calibrate the gas sensor because it was always feeling gas when the parameters weren't set right. Meanwhile, we found a hack in which the ESP WiFi module connects automatically to the last WiFi it was set onto. The results amazed everyone, it connected to WiFi almost instantaneously, with no waiting screen.

--- temp/temp.ino
+++ temp/temp.ino
@@ -127,24 +127,31 @@

   lcd.setCursor(0,0); lcd.print("Resetting...             ");
-  for( loadTime = 2 ; loadTime < 10; ++loadTime)
+  for( loadTime = 2 ; loadTime < 6; ++loadTime)
     loadScreen(loadTime);

   char bufferr[300];
   wifiSEND.sendCommand(F("AT"), bufferr, sizeof(bufferr)); delay(50);
   if(DEBUG)
     Serial.println(bufferr);
+
+  for( loadTime = 6 ; loadTime < 7; ++loadTime)
+    loadScreen(loadTime);
+

   wifiSEND.sendCommand(F("AT+CWJAP?"), bufferr, sizeof(bufferr));
-  delay(2000);
+  delay(100);
   if(DEBUG){
     Serial.println(bufferr);
     Serial.println(ESP8266_SSID);
   }

-  if(bufferr[0]!=ESP8266_SSID[0] || bufferr[1]!=ESP8266_SSID[1] || bufferr[2]!=ESP8266_SSID[2]){
+  for( loadTime = 7 ; loadTime < 10; ++loadTime)
+    loadScreen(loadTime);
+
+  if(bufferr[0]!=ESP8266_SSID[0] || bufferr[1]!=ESP8266_SSID[1] || bufferr[2]!=ESP8266_SSID[2]){          // test if the ESP is already connected to previous WiFi
   wifiSEND.sendCommand(F("AT+RST"), bufferr, sizeof(bufferr));                 // reset WiFi module
-  delay(1000);
+  delay(2000);
   wifiSEND.setupAsWifiStation(ESP8266_SSID, ESP8266_PASS, &Serial);            // connect to the WiFi with the set ssid and password
   delay(5000);
   }
@@ -181,7 +188,7 @@

   if(DEBUG) Serial.print("Gas value is ");                                 // read gas and alarm if gas levels are too high ( over 45% = gas leaks, over 50% = hazardous environment )
   if(DEBUG) Serial.println(analogRead(GASpin));
-  if(analogRead(GASpin)>350){
+  if(analogRead(GASpin)>450){
       if(analogRead(GASpin)>500){
         lcd.setCursor(0,0);
         lcd.print(" WARNING! GAS");