also show ascii spurious data

also show ascii spurious data

--- rf95_ping/rf95_ping.ino
+++ rf95_ping/rf95_ping.ino
@@ -38,7 +38,7 @@
 	strcpy(ping.msg, "ping");
 	ping.count = 0;
 	ping.rssi = 0;
-	ping.initiator = 1; // FIXME CHANGE THIS TO SOMETHING UNIQUE
+	ping.initiator = 216; // FIXME CHANGE THIS TO SOMETHING UNIQUE
 	pong.replier = -1;

 	pong.initiator = -1;
@@ -97,13 +97,14 @@
 					Serial.println(line);
 				}
 			} else {
-				Serial.print(F("Got spurious message: "));
-
+				Serial.println(F("Got spurious message: "));
 				for(uint8_t i=0; i<len; i++) {
 					Serial.print(buf[i], HEX);
 					Serial.print(' ');
 				}
-
+				Serial.println(F(""));
+				for(uint8_t i=0; i<len; i++)
+					Serial.print((char)buf[i]);
 				Serial.println(F(""));
 			}
 		}


Delete T_DMULTV-Industruino.ino

Delete T_DMULTV-Industruino.ino

--- Examples/T_DMULTV-Industruino/T_DMULTV-Industruino.ino
+++ Examples/T_DMULTV-Industruino/T_DMULTV-Industruino.ino
@@ -1,208 +0,0 @@
-/* ------------------------------------------------------------------------------------------------------------------------------------------*
- * SE2R : T_DMULTV - Fonction de démultiplexage 5DI / 1 AI sur une entrée en tension                             (Compatible IFS) 07/09/2016 *
- * ------------------------------------------------------------------------------------------------------------------------------------------*
- *        T_DMULTV(float MES, float TNS[], float VNC[], boolean RES[], int CFG)                                                   07/09/2016 *
- *                MES : float, lecture en tension 0-10V vers un pourcentage (V10_p) de l'entrée analogique                                   *
- *                OHM : [00] Valeur de la résistance de charge de base                                                                       *
- *                      [01] Valeur de la résistance de charge de l'entrée digitale 1 du multiplexeur                                        *
- *                      [02] Valeur de la résistance de charge de l'entrée digitale 2 du multiplexeur                                        *
- *                      [03] Valeur de la résistance de charge de l'entrée digitale 3 du multiplexeur                                        *
- *                      [04] Valeur de la résistance de charge de l'entrée digitale 4 du multiplexeur                                        *
- *                      [05] Valeur de la résistance de charge de l'entrée digitale 5 du multiplexeur                                        *
- *                      [06] Somme des résistances de charge en ligne à chaque instant de [00] à [05]                                        *
- *                TNS : [00] Calcul de la tension en aval de la résistance de charge RES[0] selon la configuration des RES[1] à [5]          *
- *                      [01] Tension d'alimentation de référence : 24000 mV                                                                  *
- *                      [02] Différentiel de tension de compensation des imprécisions de résistances : 200 mV                                *
- *                      [03] Tension en aval de la résistance de charge RES[0] mesurée à vide pour une alimentation de référence 24Vdc       *
- *                      [04] Tension en aval de la résistance de charge RES[0] mesurée à vide en conditions réelles                          *
- *                      [05] Tension d'alimentation réelle recalculée à partir de TNS[3] et TNS[2]                                           *
- *                VNC : [00] Nombre de cycles de confirmation antirebond d'une transition d'une des entrées RES                              *
- *                      [01] Compteur de nombre de cycles de différence continue entre RES[1] et RES[6]                                      *
- *                      [02] Compteur de nombre de cycles de différence continue entre RES[2] et RES[7]                                      *
- *                      [03] Compteur de nombre de cycles de différence continue entre RES[3] et RES[8]                                      *
- *                      [04] Compteur de nombre de cycles de différence continue entre RES[4] et RES[9]                                      *
- *                      [05] Compteur de nombre de cycles de différence continue entre RES[5] et RES[10]                                     *
- *                RES : [00] Commande de mémorisation de la tension à vide du multiplexeur à la calibration                                  *
- *                      [01] Etat calculé de l'entrée digitale 1 du multiplexeur après traitement antirebond                                 *
- *                      ...                                                                                *
- *                      [05] Etat calculé de l'entrée digitale 5 du multiplexeur après traitement antirebond                                 *
- *                      [06] Etat calculé de l'entrée digitale 1 du multiplexeur avant traitement antirebond                                 *
- *                      ...                                                                                *
- *                      [10] Etat calculé de l'entrée digitale 5 du multiplexeur avant traitement antirebond                                 *
- *                CFG : Commande de forçage                                                                                *
- *                      <0  : les booléens RES[1] à [5] restent false quelle que soit la valeur de MPX[RNG]                                  *
- *                      0   : les booléens RES[1] à [5] restent figés à leur valeur courante                                                 *
- *                      1   : les booléens RES[1] à [5] suivent les valeurs de MES décodé suivant les valeurs de tensions                    *
- *                      2   : les booléens RES[1] à [5] restent true quelle que soit la valeur de MPX[RNG]                                   *
- *                      3   : les booléens RES[1] à [5] restent true quelle que soit la valeur de MPX[RNG]                                   *
- *                      >3  : les booléens RES[1] à [5] restent false quelle que soit la valeur de MPX[RNG]                                  *
- * ------------------------------------------------------------------------------------------------------------------------------------------*
- * Copyright SE2R under the APACHE Licence                                                                                *
- * ------------------------------------------------------------------------------------------------------------------------------------------*
- * 07/09/2016 : DD, SE2R : Testée et validée sur banc                                                                                *
- * ------------------------------------------------------------------------------------------------------------------------------------------*
- * Fonctions utilisées - Bibliothèque BMS                                                                                07/09/2016 *
- * Fonctions utilisées - Bibliothèque DIS                                                                                08/07/2016 *
- * ------------------------------------------------------------------------------------------------------------------------------------------*/
-
-// Déclaration des bibliothèques nécessaires à l'exécution du programme ---------------------------------------------------------------------*
-#include <Wire.h>					// Biblio   - Gestion des ports de communication
-#include <Indio.h>					// Biblio   - Industruino
-#include <DIS.h>					// Biblio   - SE2R - Fonctions de dialogue et d'affichage sur l'écran UC1701 Industruino
-static DIS DIS;						// Biblio   - Activation du constructeur de la bibliothèque de fonctions d'affichage
-static UC1701 lcd;
-#include <BMS.h>					// Biblio   - SE2R - Fonctions de contrôle et régulation
-static BMS BMS;						// Biblio   - Activation du constructeur de la bibliothèque de fonctions d'affichage
-
-// Déclaration des entrées et sorties -------------------------------------------------------------------------------------------------------*
-float EA1_MII_MPLX;					// Général  - Mesure de tension en sortie du multiplexeur 1
-float VTE_MPLX[7] ;					// Multi_V  - Calculs de tensions dans la chaîne de mesure
-int VNC_MPLX[6];					// Multi-V  - Compteurs de confirmation de transition
-boolean EM1_MII_MPLX[11];				// Général  - Etats des contacts en entrée du multiplexeur 1
-
-// Déclaration des variables nécessaires au fonctionnement de l'écran -----------------------------------------------------------------------*
-String TCM_PRES[11] = {					// EcranLCD - Table de chaînes de caractères de présentation
-  "                     ", // 00
-  "Haut, Enter : Accueil",
-  "EA1                  ",
-  "EM1                  ",
-  "EM2                  ",
-  "EM3                  ",
-  "EM4                  ",
-  "EM5                  ",
-  "- Bas :  Reglage 0  -",
-  "-  Reglage du Zero  -",
-  " "};                   // 10
-
-String TCM_UNIT[15] = {					// EcranLCD - Table de chaînes de caractères d'unités standard
-  "        ",  // 00
-  "oC      ",
-  "%       ",
-  "s       ",
-  "V       ",
-  "mV      ",  // 05
-  "",
-  "",
-  "",
-  "",
-  "",          // 10
-  "C.Ouvert ",
-  "   Shunt ",
-  "  Appris ",
-  " Apprend "} ;
-
-boolean FCO_PRUP[5];					// EcranLCD - Information de touche "Up" appuyée
-boolean FCO_PREN[5];					// EcranLCD - Information de touche "Enter" appuyée
-boolean FCO_PRDN[5];					// EcranLCD - Information de touche "Down" appuyée
-int VNT_MENU[2];					// EcranLCD - Table d'adressage des menus
-int VNC_MENU[30];					// EcranLCD - Table des numéros de menus
-int VNC_PRUP[31];					// EcranLCD - Table des numéros de menus de destination par la touche "Up"
-int VNC_PREN[30];					// EcranLCD - Table des numéros de menus de destination par la touche "Enter"
-int VNC_PRDN[30];					// EcranLCD - Table des numéros de menus de destination par la touche "Down"
-float VTT_SCRN[10];					// EcranLCD - Table des temporisations
-boolean FCM_MPX1[1];					// G_MODV1B - Mémoire de la demande d'apprentissage de la tension de base du multiplexeur 1
-
-void setup() {						// Initialisation principale -----------------------------------------------------------------------*
-I_INPS();
-I_DISP();
-Serial.begin(9600);
-}
-
-void loop() {						// Boucle d'exécution principale -------------------------------------------------------------------*
-P_INPS();
-P_DISP();
-}
-
-void I_INPS() {						// Initialisation des entrées ---------------------------------------------------------------- INIT *
-Indio.setADCResolution(14);				// Système  - Résolution des AI. Valeurs : 12bit@240Lps, 14bit@60Lps, 16bit@15Lps and 18bit@3.75Lps.
-Indio.analogReadMode(1, V10_p);			        // Système  - Affectation de la voie AI1 en tant que 0-10V   -> 0-100%
-VTE_MPLX[2] = 150;					// Offset de tension de détection en mV
-VTE_MPLX[3] = VTE_MPLX[1] * (1 - (10110 / 14715));
-VTE_MPLX[4] = VTE_MPLX[3];
-VNC_MPLX[0] = 3;					// Nombre de lectures consécutives de confirmation
-return;
-}
-
-void P_INPS() {                                         // Lecture des entrées ----------------------------------------------------------------------- EXEC *
-  int RES[6] = {10110, 150, 301, 604, 1210, 2340};
-  EA1_MII_MPLX = Indio.analogRead(1) ;
-  BMS.T_DMULTV(EA1_MII_MPLX, RES, VTE_MPLX, VNC_MPLX, EM1_MII_MPLX, 1);
-  Serial.print(VTE_MPLX[3]);
-  Serial.print("\t");
-  Serial.print(VTE_MPLX[4]);
-  Serial.print("\t");
-  Serial.print(EA1_MII_MPLX * 100);
-  Serial.print("\t");
-  Serial.print(VNC_MPLX[1]);
-  Serial.print("\t");
-  Serial.print(EM1_MII_MPLX[1]);
-  Serial.print("\t");
-  Serial.print(VNC_MPLX[2]);
-  Serial.print("\t");
-  Serial.print(EM1_MII_MPLX[2]);
-  Serial.print("\t");
-  Serial.print(VNC_MPLX[3]);
-  Serial.print("\t");
-  Serial.print(EM1_MII_MPLX[3]);
-  Serial.print("\t");
-  Serial.print(VNC_MPLX[4]);
-  Serial.print("\t");
-  Serial.print(EM1_MII_MPLX[4]);
-  Serial.print("\t");
-  Serial.print(VNC_MPLX[5]);
-  Serial.print("\t");
-  Serial.print(EM1_MII_MPLX[5]);
-  Serial.println("\t");
-  return;
-}
-
-void I_DISP() {						// Initialisation des paramètres afficheur --------------------------------------------------- INIT *
-VTT_SCRN[1] = 180;					// G_TOUCHx - Temporisation d'inactivité sur le rétroéclairage
-VTT_SCRN[2] = 240;					// G_TOUCHx - Temporisation d'inactivité de retour à l'écran principal
-VTT_SCRN[3] = 20;					// G_TOUCHx - Temporisation d'antirebond de la touche "Enter"
-VTT_SCRN[4] = 15;					// G_TOUCHx - Temporisation d'antiredond des touches "Up" et "Down"
-VNT_MENU[0] = 3;					// G_NAVIGM - Taille des tables d'index et de destinations
-VNT_MENU[1] = 1;					// G_NAVIGM - Initialisation du pointeur de destinations
-VNC_MENU[0] = 1;					// G_NAVIGM - Tables des adresses de menus
-VNC_MENU[1] = 1;
-VNC_MENU[2] = 2;
-VNC_MENU[3] = 3;
-			  				// G_NAVIGM - Tables des adresses de destination des actions sur les touches
-VNC_PRUP[1] =   1; VNC_PREN[1] =   2; VNC_PRDN[1] =   2;
-VNC_PRUP[2] =   1; VNC_PREN[2] =   1; VNC_PRDN[2] =   3;
-VNC_PRUP[3] =   3; VNC_PREN[3] =   2; VNC_PRDN[3] =   3;
-VNC_PRUP[4] =   2;
-
-pinMode(23, INPUT);					// EcranLCD - Spécifique 1286 - Touche flèche basse
-pinMode(24, INPUT);					// EcranLCD - Spécifique 1286 - Touche entrée
-pinMode(25, INPUT);					// EcranLCD - Spécifique 1286 - Touche flèche haute
-pinMode(26, OUTPUT);					// EcranLCD - Spécifique 1286 - Sortie de commande du rétroéclairage
-lcd.begin();						// EcranLCD - Initialisation de l'écran LCD
-lcd.clear();						// EcranLCD - Effacement de l'écran LCD
-}
-
-void P_DISP() {						// Gestion des menus de l'écran -------------------------------------------------------------- EXEC *
-  DIS.G_TOUCH2(VNC_MENU, VTT_SCRN, FCO_PRUP, FCO_PREN, FCO_PRDN);
-  if (VNC_MENU[0] ==  1) { lcd.setCursor(0, 0); lcd.clearLine(); }
-  DIS.G_MESS1L(VNC_MENU, 1, 1, 0, "    www.DG2R.com     ");
-  DIS.G_MESS1L(VNC_MENU, 1, 2, 0, "Controle & Regulation");
-  DIS.G_MESS1L(VNC_MENU, 1, 3, 0, "  Industruino  1286  ");
-  if (VNC_MENU[0] ==  1) { lcd.setCursor(0, 4); lcd.clearLine(); }
-  DIS.G_MESS1L(VNC_MENU, 1, 5, 0, "Multiplexeur  5DI/1AI");
-  DIS.G_MESS1L(VNC_MENU, 1, 6, 0, "A# TESTS     C# 00001");
-  DIS.G_MESS1L(VNC_MENU, 1, 7, 0, "V.1.00     07/09/2016");
-
-  DIS.G_MESS1L(VNC_MENU, 2, 0, 0, TCM_PRES[1]);
-  DIS.G_VISV1F(VNC_MENU, 2, 1, 0, EA1_MII_MPLX * 100, TCM_PRES[2], TCM_UNIT[5]);
-  DIS.G_VISV1B(VNC_MENU, 2, 2, 0, EM1_MII_MPLX[1], TCM_PRES[3], TCM_UNIT[11], TCM_UNIT[12]);
-  DIS.G_VISV1B(VNC_MENU, 2, 3, 0, EM1_MII_MPLX[2], TCM_PRES[4], TCM_UNIT[11], TCM_UNIT[12]);
-  DIS.G_VISV1B(VNC_MENU, 2, 4, 0, EM1_MII_MPLX[3], TCM_PRES[5], TCM_UNIT[11], TCM_UNIT[12]);
-  DIS.G_VISV1B(VNC_MENU, 2, 5, 0, EM1_MII_MPLX[4], TCM_PRES[6], TCM_UNIT[11], TCM_UNIT[12]);
-  DIS.G_VISV1B(VNC_MENU, 2, 6, 0, EM1_MII_MPLX[5], TCM_PRES[7], TCM_UNIT[11], TCM_UNIT[12]);
-  DIS.G_MESS1L(VNC_MENU, 2, 7, 0, TCM_PRES[8]);
-
-  DIS.G_MODV1B(VNC_MENU, 3, FCO_PRUP, FCO_PREN, FCO_PRDN, EM1_MII_MPLX, 0, FCM_MPX1, "- Multiplexage 5D1A -", "EA1 - Reglage du Zero", TCM_UNIT[13], TCM_UNIT[14], true);
-
-  DIS.G_NAVIGM(VNC_MENU, VNT_MENU, FCO_PRUP, FCO_PREN, FCO_PRDN , VNC_PRUP, VNC_PREN, VNC_PRDN);
-  return;
-}


Update MarqueeText.ino

Update MarqueeText.ino

--- examples/MarqueeText/MarqueeText.ino
+++ examples/MarqueeText/MarqueeText.ino
@@ -19,6 +19,10 @@

 // Marquee speed (lower nubmers = faster)
 const int ANIM_DELAY = 30;
+
+// Only un-comment one of the lines below
+#define L2R		//Left to right scroll
+//#define R2L		//Right to left scroll

 void setup() {
   // init the display
@@ -106,10 +110,18 @@
 	// Wait to let the human read the display
 	delay(ANIM_DELAY);

-	// Advance to next coordinate
-	if( --x < len * -8 ) {
-		x = LEDMATRIX_WIDTH;
-	}
+	#ifdef L2R
+	//For left to right scroll
+		if( ++x > LEDMATRIX_WIDTH ){
+		    x = -len*8;
+		}
+	#endif
+	#ifdef R2L
+	//For right to left scroll
+		if( --x < len * -8 ) {
+		    x = LEDMATRIX_WIDTH;
+		}
+	#endif
 }


Added begin to each Nanoshield_Loadcell instance.

--- examples/MultiWeight/MultiWeight.ino
+++ examples/MultiWeight/MultiWeight.ino
@@ -31,7 +31,10 @@
 void setup() {
   Serial.begin(9600);
   lc1.begin();
-  //lc2.begin();
+  lc2.begin();
+  lc3.begin();
+  lc4.begin();
+  lc5.begin();

   // Wait for calibration and set current value to zero weight (tare)
   while (!lc1.updated()


Testing include

Testing include

--- examples/TestExample/TestExample.ino
+++ examples/TestExample/TestExample.ino
@@ -1,3 +1,4 @@
+#include <ArduinoJson.h>
 #include <ArduinoOTA.h>
 #include <DNSServer.h>
 #include <ESP8266HTTPClient.h>


Update voltmeter.ino

Update voltmeter.ino

--- laddstation/sub-module/voltmeter.ino
+++ laddstation/sub-module/voltmeter.ino
@@ -4,7 +4,7 @@
  * This means that it will map input voltages between 0 and 5 volts into integer values between 0 and 1023.
  * This yields a resolution between readings of: 5 volts / 1024 units or, .0049 volts (4.9 mV) per unit
  * konstant 112 is calibrated depending on resistor
- *----------------------------------------------------------------------------/
+ *----------------------------------------------------------------------------*/
  int analogvalue;
  float temp;
  float batteryVoltage;


update commented out ip configuration

update commented out ip configuration

--- Wikiduino/Wikiduino.ino
+++ Wikiduino/Wikiduino.ino
@@ -15,8 +15,8 @@
 // Ethernet Configuration

 byte mac[] = { 0xEE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED   };
-//byte ip[] = { 10, 94, 54, 2   };
-//byte gateway[] = { 10, 94, 54, 1 };
+//IPAddress ip[] = { 10, 94, 54, 2   };
+//IPAddress gateway[] = { 10, 94, 54, 1 };
 IPAddress ip(10, 0, 3, 201 );
 IPAddress gateway( 10, 0, 3, 1 );
 IPAddress subnet( 255, 255, 255, 0 );


Various test addded

Various test addded

--- test/PoE-test/PowerBoard-Basisboard-v1.1/Basic-Tests/Basic-Tests.ino
+++ test/PoE-test/PowerBoard-Basisboard-v1.1/Basic-Tests/Basic-Tests.ino
@@ -1,19 +1,31 @@
 // https://wiki.makerspaceleiden.nl/mediawiki/index.php/Powernode_1.1
+//
 #define AART_LED        (GPIO_NUM_16)
 #define RELAY           (GPIO_NUM_5)
 #define CURRENT_COIL    (GPIO_NUM_15)
-#define SW2             (GPIO_NUM_2)
+#define SW1             (GPIO_NUM_2)
+#define SW2             (GPIO_NUM_39)
+#define OPTO1           (GPIO_NUM_34)
+#define OPTO12          (GPIO_NUM_35)

 void setup() {
-  Serial.begin(115200);
-  Serial.print("Booting ");
+
+  Serial.begin(9600);
+  delay(250);
+  Serial.print("\n\n\n\nBooting ");
   Serial.println(__FILE__);
   Serial.println(__DATE__ " " __TIME__);

-  // put your setup code here, to run once:
   pinMode(AART_LED, OUTPUT);
   pinMode(RELAY, OUTPUT);
-  pinMode(CURRENT_COIL, INPUT); // analog
+  pinMode(CURRENT_COIL, ANALOG); // analog
+
+#ifdef SW1
+  pinMode(SW1, INPUT);
+#endif
+#ifdef SW2
+  pinMode(SW2, INPUT);
+#endif
 }

 void loop() {
@@ -51,11 +63,39 @@

 #ifdef SW2
   {
-    static unsigned long lastStateSW2 = 0;
-    if (digitalRead(SW2) != lastStateSW2) {
+    static unsigned long last = 0;
+    if (digitalRead(SW2) != last) {
       Serial.printf("Current state SW2: %d\n", digitalRead(SW2));
-      lastStateSW2 = digitalRead(SW2);
+      last = digitalRead(SW2);
     };
   }
 #endif
+#ifdef SW1
+  {
+    static unsigned long last = 0;
+    if (digitalRead(SW1) != last) {
+      Serial.printf("Current state SW1: %d\n", digitalRead(SW1));
+      last = digitalRead(SW1);
+    };
+  }
+#endif
+
+#ifdef OPTO1
+  {
+     static unsigned last = 0;
+     if (millis() - last > 1000) {
+      last = millis();
+      Serial.printf("OPTO 1: %d\n", analogRead(OPTO1));
+     }
+  }
+#endif
+#ifdef OPTO2
+  {
+     static unsigned last = 0;
+     if (millis() - last > 1000) {
+      last = millis();
+      Serial.printf("OPTO 1: %d\n", analogRead(OPTO2));
+     }
+  }
+#endif
 }


Small fix to example

Small fix to example

--- examples/touchScreen/touchScreen.ino
+++ examples/touchScreen/touchScreen.ino
@@ -9,7 +9,7 @@
 #include <IoAbstraction.h>
 #include <ResistiveTouchScreen.h>
 #include <Adafruit_GFX.h>
-#include <Adafruit_ST7735.h>
+#include <Adafruit_ILI9341.h>

 #define YPOS_PIN 32
 #define XNEG_PIN 33


Update the example code

Update the example code

--- examples/JTAGTest/JTAGTest.ino
+++ examples/JTAGTest/JTAGTest.ino
@@ -23,9 +23,11 @@

 void loop()
 {
+	//PlayXSVFJTAGArduino p(Serial, SERIAL_RX_BUFFER_SIZE, 2, 12, 5, 4, 0, true);
 	PlayXSVFJTAGArduino p(Serial, SERIAL_RX_BUFFER_SIZE, 8, 9, 10, 11, 12);
 	//PlayXSVFJTAGAVR p(Serial, SERIAL_RX_BUFFER_SIZE);
-	//printAvailableRAM(Serial);
+	//p.printAvailableRAM();
+	// Currently, the PlayXSVFJTAGArduino object consumes 1042 bytes of RAM
 	p.play();
 }


first working implementation of read flash memory. nedds cleanup

--- firmware/firmware.ino
+++ firmware/firmware.ino
@@ -16,56 +16,232 @@
   License along with this library. If not, see <http://www.gnu.org/licenses/>.
 */

+#define DATAOUT 11//MOSI
+#define DATAIN  12//MISO
+#define SPICLOCK  13//sck
+
+#define SERIALDEBUG
+
+void transfer_bit(boolean b) {
+    #ifdef SERIALDEBUG
+    if(b)
+    Serial.print('1');
+    else
+    Serial.print('0');
+    #endif
+    digitalWrite(DATAOUT,b);
+    delayMicroseconds(1);
+    digitalWrite(SPICLOCK,HIGH);
+    delayMicroseconds(1);
+    digitalWrite(SPICLOCK,LOW);
+    delayMicroseconds(1);
+}
+
+void transfer_byte(byte b, const char* debugMsg = NULL) {
+    digitalWrite(SS, LOW);
+    delayMicroseconds(1);
+    #ifdef SERIALDEBUG
+    Serial.print("tx byte: ");
+    PrintHex8(&b,1);
+    #endif
+    for(int i=0;i<8;i++) {
+        #ifdef SERIALDEBUG
+        if(i==4)
+        Serial.print(" ");
+        #endif
+        transfer_bit(b & (1<<i));
+    }
+    #ifdef SERIALDEBUG
+    if(debugMsg == NULL)
+    debugMsg = "";
+    Serial.println(String(" //") + debugMsg);
+    #endif
+    digitalWrite(SS, HIGH);
+    delayMicroseconds(1);
+}
+
+boolean read_bit() {
+    digitalWrite(SPICLOCK,HIGH);
+    delayMicroseconds(1);
+    boolean in = digitalRead(DATAIN);
+    #ifdef SERIALDEBUG
+    if(in)
+    Serial.print('1');
+    else
+    Serial.print('0');
+    #endif
+    digitalWrite(SPICLOCK,LOW);
+    delayMicroseconds(1);
+    return in;
+}
+
+uint16_t read_word() {
+    digitalWrite(SS, LOW);
+    delayMicroseconds(1);
+    uint16_t w = 0;
+    #ifdef SERIALDEBUG
+    Serial.print("rx word: ");
+    #endif
+    for(int i=15;i>=0;i--) {
+        w |= (read_bit() << i);
+        #ifdef SERIALDEBUG
+        if(i%4 == 0)
+        Serial.print(" ");
+        #endif
+    }
+    #ifdef SERIALDEBUG
+    Serial.print(" -> ");
+    PrintHex16(&w,1);
+    Serial.println();
+    #endif
+    digitalWrite(SS, HIGH);
+    delayMicroseconds(1);
+    return w;
+}
+
+#define SS 10
+
 String inputString = "";         // a string to hold incoming data
 boolean stringComplete = false;  // whether the string is complete

+void PrintHex8(uint8_t *data, uint8_t length) // prints 8-bit data in hex with leading zeroes
+{
+    Serial.print("0x");
+    for (int i=0; i<length; i++) {
+        if (data[i]<0x10) {Serial.print("0");}
+        Serial.print(data[i],HEX);
+        Serial.print(" ");
+    }
+}
+
+void PrintHex16(uint16_t *data, uint8_t length) // prints 16-bit data in hex with leading zeroes
+{
+    Serial.print("0x");
+    for (int i=0; i<length; i++)
+    {
+        uint8_t MSB=byte(data[i]>>8);
+        uint8_t LSB=byte(data[i]);
+
+        if (MSB<0x10) {Serial.print("0");} Serial.print(MSB,HEX); Serial.print(" ");
+        if (LSB<0x10) {Serial.print("0");} Serial.print(LSB,HEX); Serial.print(" ");
+    }
+}
+
 void printIden() {
     Serial.println("Arduino MAX1464 Serial Terminal");
 }

+void myTransfer(uint8_t b, const char* debugMsg=NULL) {
+    transfer_byte(b,debugMsg);
+}
+
 void setup() {
-  // initialize serial:
-  Serial.begin(115200);
-  printIden();
-  // reserve 200 bytes for the inputString:
-  inputString.reserve(200);
+    // initialize SPI:
+    //  SPI.begin();
+
+    // initialize serial:
+    Serial.begin(115200);
+    printIden();
+    // reserve 200 bytes for the inputString:
+    inputString.reserve(200);
+
+    pinMode(DATAOUT, OUTPUT);
+    pinMode(DATAIN, INPUT);
+    pinMode(SPICLOCK,OUTPUT);
+    pinMode(SS,OUTPUT);
+
+    digitalWrite(DATAOUT,LOW);
+    digitalWrite(SPICLOCK,LOW);
+    digitalWrite(SS,HIGH); //disable device
+    delayMicroseconds(1);
+    myTransfer(0x09, "Enable 4-wire mode data read");
+}
+
+void readFirmware() {
+    uint8_t b;
+    b = 0x78;
+    myTransfer(b, "reset CPU"); //reset CPU
+    Serial.println();
+    for(uint16_t addr=0; addr<1; addr++) {
+        // set address
+        myTransfer(0x07);
+        for(int i=2;i>=0;i--){
+            byte msNibble;
+            msNibble = (addr >> (8*i)) & 0xff;
+            b = (msNibble << 4) | 6 + (i-2);
+            myTransfer(b, String(String("write address to be read to PFAR:") + String("0x") + String(addr,HEX)).c_str());
+        }
+        Serial.println();
+        myTransfer(0x38,"copying FLASH to DHR");
+        Serial.println();
+        uint16_t val = read_word(); //read
+        Serial.print("addr=");
+        PrintHex16(&addr,1);
+        Serial.print(" -> ");
+        PrintHex16(&val,1);
+        Serial.println('--------------');
+    }
+}
+
+void haltCPU() {
+    Serial.println("Halting CPU");
+    myTransfer(0x78);
+}
+
+void flashFirmware() {
+
+}
+
+void eraseFlashMemory() {
+    Serial.println("Erasing FLASH memory");
+    myTransfer(0x78);
+    myTransfer(0xe8);
 }

 /*
-  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.
- */
+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();
-    // if the incoming character is a newline, set a flag
-    // so the main loop can do something about it:
-    if (inChar == '\n') {
-      stringComplete = true;
-    }
-    else {
-      // add it to the inputString:
-      inputString += inChar;
-    }
-  }
+    while (Serial.available()) {
+        // get the new byte:
+        char inChar = (char)Serial.read();
+        // if the incoming character is a newline, set a flag
+        // so the main loop can do something about it:
+        if (inChar == '\n') {
+            stringComplete = true;
+        }
+        else {
+            // add it to the inputString:
+            inputString += inChar;
+        }
+    }
 }

 void loop() {
-  if (stringComplete) {
-    inputString.toUpperCase();
-    if(String("IDEN").startsWith(inputString)) {
-      printIden();
-    }
-    else {
-      Serial.print("Unknown input string: ");
-      Serial.println(inputString);
-    }
-
- // clear the string:
-    inputString = "";
-    stringComplete = false;
-  }
-}
+    if (stringComplete) {
+        inputString.toUpperCase();
+        if(String("IDEN").startsWith(inputString)) {
+            printIden();
+        }
+        else if(String("RFW").startsWith(inputString)) {
+            readFirmware();
+        }
+        else if(String("HALTCPU").startsWith(inputString)) {
+            haltCPU();
+        }
+        else if(String("!ERASEFLASHMEMORY!").equals(inputString)) {
+            eraseFlashMemory();
+        }
+        else {
+            Serial.print("Unknown input string: ");
+            Serial.println(inputString);
+        }
+
+        // clear the string:
+        inputString = "";
+        stringComplete = false;
+    }
+}


Removed thermometer support because it works unreliably.

--- firmware/firmware.ino
+++ firmware/firmware.ino
@@ -1,6 +1,3 @@
-#include <OneWire.h>
-#include <DallasTemperature.h>
-
 #include <ESP8266WiFi.h>
 #include "Adafruit_MQTT.h"
 #include "Adafruit_MQTT_Client.h"
@@ -15,13 +12,6 @@
 #define DS18B20     5   // Pin of Dallas DS18B20 digital thermometer

 #define TMP_INTER   5  // Update interval of temperature given in minutes
-
-// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
-OneWire oneWire(DS18B20);
-// Pass our oneWire reference to Dallas Temperature.
-DallasTemperature temp_sensor(&oneWire);
-float temperature;
-unsigned long last_temp_millis = 0;

 unsigned int i = 0;
@@ -38,11 +28,8 @@
 // for some reason (only affects ESP8266, likely an arduino-builder bug).
 void MQTT_connect();

-
-
 void setup() {
   // Initialization
-  temp_sensor.begin();
   pinMode(LED, OUTPUT);

   Serial.begin(74880);
@@ -64,9 +51,7 @@

   // Setup MQTT subscription for onoff feed.
   mqtt.subscribe(&onoffsw);
-
-  // Initial temperature reading
-  updateTemperature();
+
 }

@@ -78,6 +63,7 @@

   while (mqtt.readSubscription(10000)) {

+    // Turn the strip on
     if (strcmp((char *)onoffsw.lastread, "{\"On\":1}") == 0 && !led_on) {

       led_on = true;
@@ -90,6 +76,7 @@
       }

     }
+    // Turn the strip off
     else if (strcmp((char *)onoffsw.lastread, "{\"On\":0}") == 0 && led_on) {

       led_on = false;
@@ -103,7 +90,7 @@
       i = 0;

     }
-    // Check if the brightness setting has been updated
+    // Update the brightness value
     else if (strncmp((char *)onoffsw.lastread, "{\"Brightness\":", 14) == 0 ) {

       Serial.print(F("Brightness: "));
@@ -135,32 +122,8 @@
       }

       brightness = new_brightness;
-
     }
   }
-
-  // Update temperature every TMP_INTER minutes
-  if (millis() - last_temp_millis > TMP_INTER*60000) {
-    updateTemperature();
-  }
-}
-
-
-void updateTemperature() {
-  Serial.print("Requesting temperature...");
-
-  temp_sensor.requestTemperatures(); // Send the command to get temperatures
-  Serial.println("DONE");
-  // After we got the temperatures, we can print them here.
-  // We use the function ByIndex, and as an example get the temperature from the first sensor only.
-  Serial.print("Temperature is: ");
-  Serial.println(temp_sensor.getTempCByIndex(0));
-
-  temperature = temp_sensor.getTempCByIndex(0);
-
-  temp_mqtt.publish(temperature);
-
-  last_temp_millis = millis();
 }


Add Service UUID advertising (iOS support)

Lots of apps (e.g. Blynk, RemoteXY) do not find the device during scanning on iOS, whereas other devices with the same service UUID are found. The origin of the problem is that in the advertisment, the service UUID is missing. This extra line fixes this problem.

--- cpp_utils/tests/BLETests/Arduino/BLE_uart/BLE_uart.ino
+++ cpp_utils/tests/BLETests/Arduino/BLE_uart/BLE_uart.ino
@@ -97,6 +97,7 @@
   pService->start();

   // Start advertising
+  pServer->getAdvertising()->addServiceUUID(pService->getUUID());
   pServer->getAdvertising()->start();
   Serial.println("Waiting a client connection to notify...");
 }


Update Sparkfun_ADJD-S311.ino

Update Sparkfun_ADJD-S311.ino

--- firmware/examples/Sparkfun_ADJD-S311.ino
+++ firmware/examples/Sparkfun_ADJD-S311.ino
@@ -29,11 +29,11 @@
 void loop(){
  RGBC color = colorSensor.read(); //read the color

- Serial.print(color.red);
+ Serial.print(map(color.red, 0, 1024, 0, 255));
  Serial.print(" | ");
- Serial.print(color.green);
+ Serial.print(color.green, 0, 1024, 0, 255));
  Serial.print(" | ");
- Serial.print(color.blue);
+ Serial.print(color.blue, 0, 1024, 0, 255));
  Serial.print(" | ");
  Serial.println(color.clear);


proper output of rfid ids

proper output of rfid ids

--- frontend/frontend.ino
+++ frontend/frontend.ino
@@ -147,8 +147,10 @@
     if (key) {
       if (key == '#' || key == '*') {
         Serial.print("UNLOCK,");
+        char tmp[16];
         for (byte i = 0; i<mfrc522.uid.size; i++) {
-          Serial.print(mfrc522.uid.uidByte[i],HEX);
+          sprintf(tmp,"%.2X",mfrc522.uid.uidByte[i]);
+          Serial.print(tmp);
         }
         Serial.print(",");
         Serial.print(buffer);


Update the authentication example using an MQTT::Connect object directly

--- examples/mqtt_auth/mqtt_auth.ino
+++ examples/mqtt_auth/mqtt_auth.ino
@@ -45,8 +45,8 @@
     Serial.println("WiFi connected");
   }

-  client.set_auth("testeruser", "testpass");
-  if (client.connect("arduinoClient")) {
+  if (client.connect(MQTT::Connect("arduinoClient")
+	             .set_auth("testeruser", "testpass"))) {
     client.publish("outTopic","hello world");
     client.subscribe("inTopic");
   }


per-segment speed in /go2 command (NOT TESTED)

--- arduino/motor_driver/motor_driver.ino
+++ arduino/motor_driver/motor_driver.ino
@@ -436,6 +436,7 @@

 void oscEvent(OscMessage &m) {
   m.plug("/go", oscGo);
+  m.plug("/go2", oscGo2);
   m.plug("/home", oscHome);
   m.plug("/maxspeed", oscSetMaxSpeed);
   m.plug("/maxaccel", oscSetMaxAccel);
@@ -443,12 +444,25 @@

 void oscGo(OscMessage &m) {
-  // /go/nwPos,nePos,sePos,swPos long ints
+  // /go/motor0pos,motor1pos,motor2pos,motor3pos long ints
   if (state != OK) return;

   double value = m.getFloat(MOTOR_ID);
   pidSetpoint = value;
-}
+  pidSetMaxSpeed(MAX_SPEED);
+}
+
+
+void oscGo2(OscMessage &m) {
+  if (state != OK) return;
+
+  double pos = m.getFloat(MOTOR_ID*2);
+  double spd = m.getFloat(MOTOR_ID*2+1);
+  pidSetpoint = pos;
+  pidSetMaxSpeed(spd);
+}
+
+

 void oscHome(OscMessage &m) {
   int motor = m.getInt(0);
@@ -461,7 +475,8 @@
 void oscSetMaxSpeed(OscMessage &m) {
   int motor = m.getInt(0);
   if (motor==MOTOR_ID) {
-    pidSetMaxSpeed(m.getFloat(1));
+    MAX_SPEED = m.getFloat(1);
+    pidSetMaxSpeed(MAX_SPEED);
   }
 }


deleted no-value R04

deleted no-value R04

--- arduino_motor/compass/R04_Compass/R04_Compass.ino
+++ arduino_motor/compass/R04_Compass/R04_Compass.ino
@@ -1,75 +0,0 @@
-/* Robot Compass
-
- The robot has an on-board compass module, with
- which it can tell the direction the robot is
- facing. This sketch will make sure the robot
- goes towards a certain direction.
-
- Beware, magnets will interfere with the compass
- readings.
-
- Circuit:
- * Arduino Robot
-
- created 1 May 2013
- by X. Yang
- modified 12 May 2013
- by D. Cuartielles
-
- This example is in the public domain
- */
-
-
-//built-in examples, hence no need to install addtional library
-
-
-
-// include the robot library
-#include <ArduinoRobot.h>
-
-int speedLeft;
-int speedRight;
-int compassValue;
-int direc = 180;  //Direction the robot is heading
-
-void setup() {
-  // initialize the modules
-  Robot.begin();
-  Robot.beginTFT();
-  Robot.beginSD();
-  Robot.displayLogos();
-}
-
-void loop() {
-  // read the compass orientation
-  compassValue = Robot.compassRead();
-
-  // how many degrees are we off
-  int diff = compassValue-direc;
-
-  // modify degress
-  if(diff > 180)
-    diff = -360+diff;
-  else if(diff < -180)
-    diff = 360+diff;
-
-  // Make the robot turn to its proper orientation
-  diff = map(diff, -180, 180, -255, 255);
-
-  if(diff > 0) {
-    // keep the right wheel spinning,
-    // change the speed of the left wheel
-    speedLeft = 255-diff;
-    speedRight = 255;
-  } else {
-    // keep the right left spinning,
-    // change the speed of the left wheel
-    speedLeft = 255;
-    speedRight = 255+diff;
-  }
-  // write out to the motors
-  Robot.motorsWrite(speedLeft, speedRight);
-
-  // draw the orientation on the screen
-  Robot.drawCompass(compassValue);
-}


Added a heartbeat.

Added a heartbeat.

--- src/arbotix_sketch/arbotix_sketch.ino
+++ src/arbotix_sketch/arbotix_sketch.ino
@@ -15,6 +15,8 @@

 const float ANGLE_CONVERSION = 4096.0/360.0;

+int heartbeat = 1;
+
 void setup()
 {
   Serial.begin(9600);
@@ -25,12 +27,22 @@
   aft_thruster.attach(12);
   port_thruster.attach(14);
   stbd_thruster.attach(13);
+
+  aft_thruster.write(90);
+  port_thruster.write(90);
+  stbd_thruster.write(90);
+
+  pinMode(0, OUTPUT);
+  digitalWrite(0, heartbeat);
 }

 void loop()
 {
   if(Serial.available() > PACKET_SIZE && Serial.read() == '-')
   {
+    heartbeat = !heartbeat;
+    digitalWrite(0, heartbeat);
+
     for(int i = 0; i < PACKET_SIZE; i++)
     {
       packet[i] = Serial.read();
@@ -49,3 +61,4 @@
     stbd_thruster.write(stbd_power * POWER_CONVERSION + 90);
   }
 }
+


Solar Traxker Code

Solar Traxker Code

--- solar_tracker_v1.00.ino
+++ solar_tracker_v1.00.ino
@@ -1,6 +1,6 @@
 /**
- * @author      Ioannis Katsikavelas <>
-                Dimitrios Tsoukantanas <d.tsoukantanas@yahoo.com
+ * @author      Ioannis Katsikavelas <ioankats93@gmail.com>
+                Dimitrios Tsoukantanas <d.tsoukantanas@yahoo.com>
  * @copyright   2015 - Ioannis Katsikavelas - Dimitrios Tsoukantanas
  * @license     {@link http://choosealicense.com/licenses/mit/ | MIT License}
  */
@@ -150,4 +150,4 @@
      delay(1000);

 }
-
+


-Refactored.

-Refactored.

--- ntptask.ino
+++ ntptask.ino
@@ -1,13 +1,20 @@
 void ntpTask( void * pvParameters )
 {
-  String NTPpoolAdress = COUNTRY_CODE_ISO_3166;
+  const char * NTPpool         = "pool.ntp.org";
+  const char * defaultTimezone = "CET-1CEST,M3.5.0/2,M10.5.0/3";
+  char NTPpoolAdress[20];

-  NTPpoolAdress += ".pool.ntp.org";
+  if ( COUNTRY_CODE_ISO_3166 )
+  {
+    snprintf( NTPpoolAdress, sizeof( NTPpoolAdress ), "%s.%s", COUNTRY_CODE_ISO_3166, NTPpool );
+  }
+  else
+  {
+    snprintf( NTPpoolAdress, sizeof( NTPpoolAdress ), "0.%s", NTPpool );
+  }

-  Serial.println( "Getting time from " + NTPpoolAdress );
-
-  configTzTime( readStringNVS( "timezone", "CET-1CEST,M3.5.0/2,M10.5.0/3" ).c_str(),
-                NTPpoolAdress.c_str(), "0.pool.ntp.org", "1.pool.ntp.org" );
+  configTzTime( readStringNVS( "timezone", defaultTimezone ).c_str(),
+                NTPpoolAdress );

   time_t now;
   struct tm timeinfo;


Increases loop speed by speeding up ADC reads

--- GVG200.ino
+++ GVG200.ino
@@ -1205,13 +1205,13 @@
   uint16_t scaledValue;
   for(int i=0;i<64;i++) {
     write_analog_address(i);
-    delayMicroseconds(50);
+    //delayMicroseconds(10);
     scaledValue = analogRead(A0);
     if(i==0) scaledValue = constrain(map(scaledValue,ME1_bottom,ME1_top,0,255),0,255);
     else if(i==1) scaledValue = constrain(map(scaledValue,ME2_bottom,ME2_top,0,255),0,255);
     else if(i==2) scaledValue = constrain(map(scaledValue,joystick_bottom,joystick_top,0,255),0,255);
     else if(i==3) scaledValue = constrain(map(scaledValue,joystick_left,joystick_right,0,255),0,255);
-    else scaledValue = map(scaledValue,0,960,255,0);
+    else scaledValue = constrain(map(scaledValue,0,960,255,0),0,255);

     if(i<2 && (scaledValue==255 || scaledValue==0)) {
       // We need to acctually show the 0/255 for T bars
@@ -1365,6 +1365,21 @@
 }

 void setup() {
+
+  // defines for setting and clearing register bits
+  #ifndef cbi
+  #define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
+  #endif
+  #ifndef sbi
+  #define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
+  #endif
+
+  // set prescale to 16 (faster ADC)
+  sbi(ADCSRA,ADPS2) ;
+  cbi(ADCSRA,ADPS1) ;
+  cbi(ADCSRA,ADPS0) ;
+
+
   Serial.begin(115200);
   randomSeed(analogRead(A1));


Some changes to arduino code

Some changes to arduino code

--- arduino/alarm/alarm.ino
+++ arduino/alarm/alarm.ino
@@ -1,29 +1,30 @@
 const int gate_pin = 5;
 String light_state;

-boolean serialEvent();
+void serialEvent();
 void alarm();

 void alarm() {
-  boolean stop_alarm = false;
+  boolean alarm_stopped = false;
   for (int i = 1; i < 256; i++) {
-    if (stop_alarm) {
+    if (light_state != "alarm") {
+      boolean alarm_stopped = true;
       break;
     }
     analogWrite(gate_pin, i);
-    for (int j = 0; j < 7059; j++) {
+    for (int j = 0; j < 100; j++) {
       if (Serial.available() > 0) {
-        stop_alarm = serialEvent();
+        serialEvent();
       }
       delay(1);
     }
   }
-  if (!(stop_alarm)) {
+  if (!(alarm_stopped)) {
     light_state = "on";
   }
 }

-boolean serialEvent() {
+void serialEvent() {
   String serial_data = Serial.readString();
   Serial.flush();
   if (serial_data == "i") {
@@ -39,10 +40,10 @@
   } else if (serial_data == "a" && light_state == "off") {
     light_state = "alarm";
     alarm();
-  } else {
-    return false;
-  }
-  return true;
+  } //else {
+  //   return false;
+  // }
+  // return true;
 }

 void setup() {


arduino code update

arduino code update

no current sensor used
maxUpSteps Update

--- arduino/medox/medox.ino
+++ arduino/medox/medox.ino
@@ -36,7 +36,7 @@

 #define    currentThreeshold 5    //current where pump gets a bill
 #define    currentOffset     2    //offset for current sensor
-#define    maxUpSteps        20   //maximum number of steps pump should move
+#define    maxUpSteps        350   //maximum number of steps pump should move 50 ----> 1 revolation
 #define    step72            10   //steps required to rotate 72 degrees

 //servo constants
@@ -236,13 +236,14 @@
   for (int i = 0; i < steps; i++){ //move the required steps
     moveOneStep(); //moves 72 degree to select next warehouse
   }
+  selectedWarehouse = warehouseNumber;
 }

 //get one bill using pump
 void getBill(){
   int steps = 0; //for storing steps to return to initial position again
   digitalWrite(pump, HIGH); //activates the pump
-  while(getCurrent() < currentThreeshold && steps < maxUpSteps){ //go down until gets one bill
+  while(/*getCurrent() < currentThreeshold &&*/ steps < maxUpSteps){ //go down until gets one bill
     stepDown(); //move one step down
   }
   delay(getBillDelay); //to wait until bill catched for sure


uncommented debug print

uncommented debug print

--- embedded/qubo_arduino/qubo_arduino.ino
+++ embedded/qubo_arduino/qubo_arduino.ino
@@ -1,5 +1,6 @@
 /* sgillen - this will be all the arduino code for qubo */

+#define DEBUG

 #include <Wire.h>
 #include "MS5837.h"
@@ -78,8 +79,8 @@

   #ifdef DEBUG
-  //Serial.print("Attempting to set freq ");
-  //Serial.println(freq);
+  Serial.print("Attempting to set freq ");
+  Serial.println(freq);
   #endif
   freq *= 0.9;  // Correct for overshoot in the frequency setting (see issue #11).
   float prescaleval = 25000000;
@@ -93,9 +94,9 @@
   uint8_t oldmode2 = read8(PCA9685_MODE1 + 1);

   #ifdef DEBUG
-  //Serial.println("old mode was");
-  //Serial.println(oldmode);
-  //Serial.println(oldmode2);
+  Serial.println("old mode was");
+  Serial.println(oldmode);
+  Serial.println(oldmode2);
   #endif

   uint8_t newmode = 0x21;
@@ -109,10 +110,10 @@
   oldmode2 = read8(PCA9685_MODE1 + 1);

   #ifdef DEBUG
-  //Serial.println("new mode is");
-  //Serial.println(oldmode);
-  //Serial.println(oldmode2);
-  //Serial.println("PCA initialized");
+  Serial.println("new mode is");
+  Serial.println(oldmode);
+  Serial.println(oldmode2);
+  Serial.println("PCA initialized");
   #endif

   thrustersOff();
@@ -137,7 +138,7 @@

     thrusterCommands[i] = strtok(NULL, ","); //remember buffer is global, strok still remembers that we are reading from it
     #ifdef DEBUG
-    //    Serial.println(thrusterCommands[i]);
+    Serial.println(thrusterCommands[i]);
     #endif

   }
@@ -186,8 +187,8 @@
     buffer[serialBufferPos] = Serial.read();

     #ifdef DEBUG
-    // Serial.print("buffer is: ");
-    // Serial.println(buffer);
+     Serial.print("buffer is: ");
+     Serial.println(buffer);
     #endif

     // Check if we've reached exclamation
@@ -226,11 +227,11 @@

     else {
       #ifdef DEBUG
-      /*
+
       Serial.print("Buffer pos ");
       Serial.println(serialBufferPos);
       Serial.println(buffer[serialBufferPos]);
-      */
+
       #endif
       serialBufferPos++;
     }
@@ -254,7 +255,7 @@
         #endif
         if (!timedout) {
           #ifdef DEBUG
-          //Serial.println("Overflow Timed out, thrusters off");
+          Serial.println("Overflow Timed out, thrusters off");
           #endif
           thrustersOff();
           timedout = true;
@@ -265,7 +266,7 @@
     else if (( current_time - alive) >= ALIVE_TIMEOUT ) {
       if (!timedout) {
         #ifdef DEBUG
-        //Serial.println("Timed out, thrusters off");
+        Serial.println("Timed out, thrusters off");
         #endif
         thrustersOff();
         timedout = true;


Fixed an issue where the ArduBreakout.ino example

There was an unprintable characted in 3 lines, which broke compilation (at least on Unix systems)

--- examples/ArduBreakout/ArduBreakout.ino
+++ examples/ArduBreakout/ArduBreakout.ino
@@ -367,7 +367,7 @@
   for(int i = 0; i < n; i++)
   {
     delay(15);
-    pad = arduboy.pressed(A_BUTTON) || arduboy.pressed(B_BUTTON);
+    pad = arduboy.pressed(A_BUTTON) || arduboy.pressed(B_BUTTON);
     if(pad == 1 && oldpad == 0)
     {
       oldpad3 = 1; //Forces pad loop 3 to run once
@@ -510,7 +510,7 @@
     arduboy.drawLine(56 + (index*8), 28, 56 + (index*8) + 6, 28, 1);
     delay(150);

-    if (arduboy.pressed(LEFT_BUTTON) || arduboy.pressed(B_BUTTON))
+    if (arduboy.pressed(LEFT_BUTTON) || arduboy.pressed(B_BUTTON))
     {
       index--;
       if (index < 0)


Improving FSM example CosaBlinkRGB.

Improving FSM example CosaBlinkRGB.

1. Introducting variable timeout period.
2. Adding an instance to increase control complexity without additional code.

--- examples/CosaBlinkRGB/CosaBlinkRGB.ino
+++ examples/CosaBlinkRGB/CosaBlinkRGB.ino
@@ -30,22 +30,28 @@
 #include "Cosa/Pins.h"
 #include "Cosa/Watchdog.h"

-// The state machine: Blink RGB with six color states
+// The state machine: Blink RGB LED with six color states
 class BlinkRGB : public FSM {
+
 public:
-  // Timeout before going to next color state
-  static const uint16_t TIMEOUT = 128;
-
   // The output pins
   OutputPin redLedPin;
   OutputPin greenLedPin;
   OutputPin blueLedPin;

-  BlinkRGB(uint8_t redLedPinNr, uint8_t greenLedPinNr, uint8_t blueLedPinNr) :
+  // Timeout period
+  uint16_t timeout;
+
+  // Construct the state machine for the RGB led sequencing
+  BlinkRGB(uint16_t ms = 512,
+	   uint8_t redLedPinNr = 5,
+	   uint8_t greenLedPinNr = 6,
+	   uint8_t blueLedPinNr= 7) :
     FSM(redState),
     redLedPin(redLedPinNr, 1),
     greenLedPin(greenLedPinNr),
-    blueLedPin(blueLedPinNr, 1)
+    blueLedPin(blueLedPinNr, 1),
+    timeout(ms)
   {}

   // State functions; red => yellow => green => cyan => blue => meganta
@@ -53,7 +59,7 @@
   {
     BlinkRGB* rgb = (BlinkRGB*) fsm;
     rgb->blueLedPin.toggle();
-    fsm->set_timer(TIMEOUT);
+    fsm->set_timer(rgb->timeout);
     fsm->set_state(yellowState);
     return (1);
   }
@@ -62,7 +68,7 @@
   {
     BlinkRGB* rgb = (BlinkRGB*) fsm;
     rgb->greenLedPin.toggle();
-    fsm->set_timer(TIMEOUT);
+    fsm->set_timer(rgb->timeout);
     fsm->set_state(greenState);
     return (1);
   }
@@ -71,7 +77,7 @@
   {
     BlinkRGB* rgb = (BlinkRGB*) fsm;
     rgb->redLedPin.toggle();
-    fsm->set_timer(TIMEOUT);
+    fsm->set_timer(rgb->timeout);
     fsm->set_state(cyanState);
     return (1);
   }
@@ -80,7 +86,7 @@
   {
     BlinkRGB* rgb = (BlinkRGB*) fsm;
     rgb->blueLedPin.toggle();
-    fsm->set_timer(TIMEOUT);
+    fsm->set_timer(rgb->timeout);
     fsm->set_state(blueState);
     return (1);
   }
@@ -89,7 +95,7 @@
   {
     BlinkRGB* rgb = (BlinkRGB*) fsm;
     rgb->greenLedPin.toggle();
-    fsm->set_timer(TIMEOUT);
+    fsm->set_timer(rgb->timeout);
     fsm->set_state(magentaState);
     return (1);
   }
@@ -98,22 +104,24 @@
   {
     BlinkRGB* rgb = (BlinkRGB*) fsm;
     rgb->redLedPin.toggle();
-    fsm->set_timer(TIMEOUT);
+    fsm->set_timer(rgb->timeout);
     fsm->set_state(redState);
     return (1);
   }
 };

-// The state machine; possible to create any number of copies
-BlinkRGB fsm(5, 6, 7);
+// The state machines
+BlinkRGB led1(512, 5, 6, 7);
+BlinkRGB led2(256, 8, 9, 10);

 void setup()
 {
   // Start the watchdog (16 ms timeout, push timeout events)
   Watchdog::begin(16, SLEEP_MODE_IDLE, Watchdog::push_timeout_events);

-  // Start the state machine
-  fsm.begin();
+  // Start the state machines
+  led1.begin();
+  led2.begin();
 }

 void loop()


Add missing sendHaierAC() to MQTT example code. (#434)

Forgot to add the actual sending part for HaierAC part of the IRMQTTServer
example code.

--- examples/IRMQTTServer/IRMQTTServer.ino
+++ examples/IRMQTTServer/IRMQTTServer.ino
@@ -500,6 +500,11 @@
       irsend.sendFujitsuAC(reinterpret_cast<uint8_t *>(state), stateSize);
       break;
 #endif
+#if SEND_HAIER_AC
+    case HAIER_AC:
+      irsend.sendHaierAC(reinterpret_cast<uint8_t *>(state));
+      break;
+#endif
   }
 }


Attempt to readback commands from progmem

--- src/gateway/gateway.ino
+++ src/gateway/gateway.ino
@@ -12,6 +12,7 @@
 #include "config.h"
 #include "../common/defines.h"
 #include <EEPROM.h>
+#include <avr/pgmspace.h>

 #include <RFM69.h>
 #include <SPI.h>
@@ -21,6 +22,7 @@
 #include "topicStorage.h"
 #include "controls.h"

+#define LCOMMAND 10

 uint8_t mac[] = {  0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED }; // get real mac
 uint8_t server[] = { 192, 168, 0, 1 };
@@ -28,15 +30,11 @@

 const uint8_t HEADER = sizeof(RadioHeader);

-const PROGMEM char commands[][9] = {
+const PROGMEM char commands[][LCOMMAND] = {
   { "state" },
   { "set" },
   { "timestamp" },
 }
-
-// Values stored as 2 nibbles.  First nibble is the nodeid, second
-// nibble is the sensorid.  NodeId 15 (F) is reserved (gateway).
-// TODO possible expansion to uint16_t to support many more nodes and sensors

 RFM69 radio;
 EthernetClient ethClient;
@@ -101,9 +99,14 @@
   ts.writeRegistration(header, reg);
   client.subscribe(registration.topic);
   for (int i = 0; i < ; i++) {
-    char[TOPIC_LENGTH] topic;
+    char[TOPIC_LENGTH + LCOMMAND + 1] topic;
+    char command[LCOMMAND] = {0};
+    for (i = 0; i < LCOMMAND; i++) {
+      strcpy_P(command, commands[i]);
+    }
     strcpy(topic, registration.topic);
-    strcat(topic, commands[i]);
+    strcat(topic, "/");
+    strcat(topic, command);
     client.subscribe(topic);
   } else {
     Serial.println(F("Unable to register, out of space"));


Modificada calculo de media entrada analogica


[BUG] Fix incorrect #define usage. (#597)

Originally reported in https://github.com/letscontrolit/ESPEasy/issues/2230

MITSUBISHI_AC -> SEND_MITSUBISHI_AC
SEND_MWM_ -> SEND_MWM

Fixes #596

--- examples/IRMQTTServer/IRMQTTServer.ino
+++ examples/IRMQTTServer/IRMQTTServer.ino
@@ -777,7 +777,7 @@
       irsend.sendDaikin2(reinterpret_cast<uint8_t *>(state));
       break;
 #endif
-#if MITSUBISHI_AC
+#if SEND_MITSUBISHI_AC
     case MITSUBISHI_AC:
       irsend.sendMitsubishiAC(reinterpret_cast<uint8_t *>(state));
       break;
@@ -847,7 +847,7 @@
       irsend.sendPanasonicAC(reinterpret_cast<uint8_t *>(state));
       break;
 #endif
-#if SEND_MWM_
+#if SEND_MWM
     case MWM:
       irsend.sendMWM(reinterpret_cast<uint8_t *>(state), stateSize);
       break;


replace snake_case variables to match camelCase variable naming scheme in most recent firmware.

--- firmware/PCB_V02/PCB_V02.ino
+++ firmware/PCB_V02/PCB_V02.ino
@@ -33,7 +33,7 @@

 // 0bEDC*BAFG
 //7 segment digits.
-const byte all_digits[10] = {
+const byte allDigits[10] = {
   0b11111110,0b11010111,0b00110010,0b10010010, //-,1,2,3
   0b11010100,0b10011000,0b00011100,0b11010011, //4,5,6,7
   0b00010000,0b10010000};                    //8,9
@@ -63,8 +63,8 @@
 int dataPin = 4;

 int motorPin = 5;
-int motor_on = 750; //number of milliseconds the motor vibrates
-int motor_off = 100; //pause between pulses
+int motorOn = 750; //number of milliseconds the motor vibrates
+int motorOff = 100; //pause between pulses

 int buttonPin = 2;

@@ -73,7 +73,7 @@
 int greenLED = 11; //pwm
 int digitLED = 6; //pwm. 7 segment brightness

-boolean USB_connected = false;
+boolean usbConnected = false;
 volatile unsigned long time = 0;

 int motorCount = 1;
@@ -81,7 +81,7 @@
 volatile int motorState = LOW;
 boolean motorCommand = false;

-aJsonStream serial_stream(&Serial);
+aJsonStream serialStream(&Serial);

 void setup() {
   //set pins to output so you can control the shift register
@@ -107,13 +107,13 @@
 void loop() {

   //handle motor control
-  if (motorState == HIGH && (millis() - time) >= motor_on && motorCommand) {
+  if (motorState == HIGH && (millis() - time) >= motorOn && motorCommand) {
     motorState = LOW;
     digitalWrite(motorPin, motorState);
     time = millis();
   }

-  if (motorState == LOW && (millis() - time) >= motor_off
+  if (motorState == LOW && (millis() - time) >= motorOff
                           && motorPulse > 0 && motorCommand) {
     motorState = HIGH;
     digitalWrite(motorPin, motorState);
@@ -125,24 +125,24 @@
     }
   }

-  if ((millis()-time) >= motor_on && !motorCommand) {
+  if ((millis()-time) >= motorOn && !motorCommand) {
     motorState = LOW;
     digitalWrite(motorPin, motorState);
     motorPulse = motorCount;
   }

-  if (serial_stream.available()) {
-    serial_stream.skip();
-  }
-
-  if (serial_stream.available()) {
-    USB_connected = true;
-    aJsonObject *msg = aJson.parse(&serial_stream);
+  if (serialStream.available()) {
+    serialStream.skip();
+  }
+
+  if (serialStream.available()) {
+    usbConnected = true;
+    aJsonObject *msg = aJson.parse(&serialStream);
     processMessage(msg);
     aJson.deleteItem(msg);
   }

-  if (!USB_connected) {
+  if (!usbConnected) {
     for (int c = 0; c < 6; c++) {
       sendDigit(circle[c]);
       delay(50);
@@ -169,7 +169,7 @@
   int iValue = value->valueint;

   if (sName == "gear") {
-    sendDigit(all_digits[iValue]);
+    sendDigit(allDigits[iValue]);
     return;
   }

@@ -183,23 +183,23 @@
   }

   if (sName == "color") {
-    int LED_value = iValue;
+    int valueLED = iValue;

-    if (LED_value >= 0 && LED_value <= 85) {
-      analogWrite(redLED, -1*LED_value*255/85+255);
-      analogWrite(greenLED, LED_value*255/85);
+    if (valueLED >= 0 && valueLED <= 85) {
+      analogWrite(redLED, -1*valueLED*255/85+255);
+      analogWrite(greenLED, valueLED*255/85);
       analogWrite(blueLED, 0);
     }

-    if (LED_value > 85 && LED_value <= 170) {
-      analogWrite(greenLED, -1*(LED_value-85)*255/85+255);
-      analogWrite(blueLED, (LED_value-85)*255/85);
+    if (valueLED > 85 && valueLED <= 170) {
+      analogWrite(greenLED, -1*(valueLED-85)*255/85+255);
+      analogWrite(blueLED, (valueLED-85)*255/85);
       analogWrite(redLED, 0);
     }

-    if (LED_value > 170 && LED_value <= 255) {
-      analogWrite(blueLED, -1*(LED_value-170)*255/85+255);
-      analogWrite(redLED, (LED_value-170)*255/85);
+    if (valueLED > 170 && valueLED <= 255) {
+      analogWrite(blueLED, -1*(valueLED-170)*255/85+255);
+      analogWrite(redLED, (valueLED-170)*255/85);
       analogWrite(greenLED, 0);
     }
     return;


Changed magic numbers for servor neutral to Constants defined in motors.cpp

--- arduino/OpenROV/OpenROV.ino
+++ arduino/OpenROV/OpenROV.ino
@@ -29,14 +29,14 @@
 int index = 0;                  // the index of the current reading
 int total = 0;                  // the running total
 int average = 0;                // the average
-int c_tilt = 90;
-int c_motorp = 90;
-int c_motors = 90;
-int c_motorv = 90;
-int tilt_val = 90;
-int p = 90;
-int v = 90;
-int s = 90;
+int c_tilt = MIDPOINT;
+int c_motorp = MIDPOINT;
+int c_motors = MIDPOINT;
+int c_motorv = MIDPOINT;
+int tilt_val = MIDPOINT;
+int p = MIDPOINT;
+int v = MIDPOINT;
+int s = MIDPOINT;

 void setup(){


UI delays removed L steps adjusted

UI delays removed
L steps adjusted

--- hal100/hal100.ino
+++ hal100/hal100.ino
@@ -143,9 +143,7 @@
 	LmoveStage1();                                    // send command to nano to move motor "L" to L step value
 	EraseDisplayC(), EraseDisplayL();                 // clear previous values L and C at display
 	displayC(), displayL();                           // display current values L and C at display
-	tuningDisplay();                                  // flashing tuning - this to be changed to start at CmoveStage1 and finish after LmoveStage1
-	displayTunedFreqTopScreen();                      // emulation of Green Tuned after motors in place
-	mechSetPosition(round (valueRotateL), round (valueRotateC));
+  mechSetPosition(round (valueRotateL), round (valueRotateC));
 	// End STAGE 1 tuning process
 }

@@ -169,52 +167,19 @@
 }

 void incLCorr(float diff) {
-	valueLcorr = valueLcorr + diff;
-	SetFrequencyStage1();
-
+    if (tuningFreqCalc != 0.0) {
+      valueLcorr = valueLcorr + diff;
+      SetFrequencyStage1();
+    }
 }

 void incCCorr(float diff) {
-	valueCorr = valueCorr + diff;
-	SetFrequencyStage1();
-}
-
-
-void LtoCCW() {                                   // when L pressed - moves motor L 1 step CCW and displays left arrows
-  TFTscreen.stroke(255, 255, 0);
-  TFTscreen.setTextSize(1);
-  TFTscreen.text("<<<", 7, 60);
-  delay(1000);
-  TFTscreen.stroke(0, 20, 30);
-  TFTscreen.text("<<<", 7, 60);
-}
-
-void LtoCW() {                                   // when l pressed - moves motor L 1 step CW and displays left arrows
-  TFTscreen.stroke(255, 255, 0);
-  TFTscreen.setTextSize(1);
-  TFTscreen.text(">>>", 55, 60);
-  delay(1000);
-  TFTscreen.stroke(0, 20, 30);
-  TFTscreen.text(">>>", 55, 60);
-}
-
-void CtoCCW() {                                   // when C pressed - moves motor L 1 step CCW and displays left arrows
-  TFTscreen.stroke(255, 255, 0);
-  TFTscreen.setTextSize(1);
-  TFTscreen.text("<<<", 67, 60);
-  delay(1000);
-  TFTscreen.stroke(0, 20, 30);
-  TFTscreen.text("<<<", 67, 60);
-}
-
-void CtoCW() {                                   // when c pressed - moves motor L 1 step CW and displays left arrows
-  TFTscreen.stroke(255, 255, 0);
-  TFTscreen.setTextSize(1);
-  TFTscreen.text(">>>", 112, 60);
-  delay(1000);
-  TFTscreen.stroke(0, 20, 30);
-  TFTscreen.text(">>>", 112, 60);
-}
+    if (tuningFreqCalc != 0.0) {
+      valueCorr = valueCorr + diff;
+      SetFrequencyStage1();
+    }
+}
+

 void eraseFreqTopScreen() {                      // erases frequency value from top of display
   TFTscreen.stroke(0, 20, 30);
@@ -367,16 +332,16 @@
           SetFrequency();
           break;
         case 'C':                           // will be used for "C" motor move 1 step CCW
-          CtoCCW();
+          incCCorr(-1);
           break;
         case 'c':                           // will be used for "C" motor move 1 step CW
-          CtoCW();
+          incCCorr(1);
           break;
         case 'L':                           // used for "L" motor move 1 step CCW
-          LtoCCW();
+          incLCorr(-0.001);
           break;
         case 'l':                           // used for "L" motor move 1 step CW
-          LtoCW();
+          incLCorr(0.001);
           break;
         case '*':                           // erase entered frequency
           eraseFrequency();


set min push interval to 2 secs

set min push interval to 2 secs

--- sketches/EnerginoYun/EnerginoYun.ino
+++ sketches/EnerginoYun/EnerginoYun.ino
@@ -141,8 +141,8 @@
   // Make sure that update period is not too high
   // when pushing data to Xively (one sample every
   // 5 seconds should be a reasonable lower boud)
-  if ((settings.feedid != 0) && (settings.period < 5000)) {
-    resetSleep(5000);
+  if ((settings.feedid != 0) && (settings.period < 2000)) {
+    resetSleep(2000);
   }

   // Start profiling


added interrupt

added interrupt

--- gestureDetection/gestureDetection.ino
+++ gestureDetection/gestureDetection.ino
@@ -39,27 +39,35 @@
  */

-#include<Wire.h>
+#include "I2Cdev.h"
+#include "MPU6050_6Axis_MotionApps20.h"
+#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
+    #include "Wire.h"
+#endif
 #define relax(a) (((a)<(650))? (true):(false)) //whehter a finger is in relax state
-enum state {forward_drive, backup, left_turn, right_turn, catapult_throw}; //catapult_throw should be an interrupt, not a state
+MPU6050 mpu;
+int8_t threshold;
 const int MPU=0x68;  // I2C address of the MPU-6050
 int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;
 bool indexRelax, middleRelax, ringRelax;
+
+void ISR_interrupt(){
+  /*upon an interrupt, send catapult throw command*/
+  /*right now, we can turn on LED to indicate this event*/
+  digitalWrite(13,HIGH);
+}
 void setup(){
   Wire.begin();
-  Wire.beginTransmission(MPU);
-  Wire.write(0x6B);  // PWR_MGMT_1 register
-  Wire.write(0);     // set to zero (wakes up the MPU-6050)
-  Wire.endTransmission(true);
-  Wire.beginTransmission(MPU);
-  Wire.write(0x1C);  // Accel_config register
-  Wire.write(0x08);  // set to 08 (full_range +-4g)
-  Wire.endTransmission(true);
-  Wire.beginTransmission(MPU);
-  Wire.write(0x24);  // Accel_config register
-  Wire.write(0x09);  // set to 08 (full_range +-4g)
-  Wire.endTransmission(true);
+  mpu.initialize();
+  mpu.dmpInitialize();
+  mpu.setIntMotionEnabled(1);
+  mpu.setMotionDetectionThreshold(2);
+  mpu.setMotionDetectionDuration(1);
   pinMode(7,OUTPUT);
+  pinMode(13, OUTPUT);
+  digitalWrite(13,LOW);
+  pinMode(2,OUTPUT);
+  attachInterrupt(digitalPinToInterrupt(2),ISR_interrupt,FALLING);
   Serial.begin(9600);
 }
 void loop(){
@@ -69,7 +77,7 @@
   Wire.beginTransmission(MPU);
   Wire.write(0x3B);  // starting with register 0x3B (ACCEL_XOUT_H)
   Wire.endTransmission(false);
-  Wire.requestFrom(MPU,6,true);  // request a total of 14 registers
+  Wire.requestFrom(MPU,6,true);  // request a total of 6 registers
   digitalWrite(7, LOW);
   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)


showing 'up' between calibration disks

showing 'up' between calibration disks

--- Tonino.ino
+++ Tonino.ino
@@ -1,6 +1,6 @@
-// Moppette_xxx.ino
+// Tonino_1_0_6.ino
 //----------------
-// Arduino code for Moppete using
+// Arduino code for Tonino (my-tonino.com) using
 //    - DFRduino Nano
 //    - Adafruit 0.56" 7-segment LCD backpack display
 //      see http://learn.adafruit.com/adafruit-led-backpack/0-dot-56-seven-segment-backpack
@@ -46,7 +46,7 @@
 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 // ------------------------------------------------------------------------------------------

-#define VERSION "1 0 5"
+#define VERSION "1 0 6"

 #include <tonino.h>
 #include <tonino_lcd.h>
@@ -309,10 +309,12 @@
         delay(500);
         if (tSerial.checkCommands()) return false;
       }
+      display.up();
       while (colorSense.isLight()) {
         delay(500);
         if (tSerial.checkCommands()) return false;
       }
+      display.calibration2();
       delay(500);

       // scan for calibration plate 2


Small fixes to the menu

Small fixes to the menu

Now it supports n elements.

--- Weight.ino
+++ Weight.ino
@@ -73,10 +73,16 @@
 float lastValue = 0;
 unsigned int useFastWeight = 0;

+//MENU
+char* EMPTY = "                ";
+char* menu[] = {"Calibrate       " ,"Tare           "};
+unsigned int lastItem = 1;
+unsigned int menuMarker = 0;
+
+
 //GUI VARIABLES
 unsigned int printGUI = 0;
-unsigned int menuMarker = 0;
-unsigned int lastItem = 1;
+

 void setup() {
   Serial.begin(BAUD_RATE);
@@ -280,11 +286,25 @@
   if (!printGUI){
     return;
   }
-  printMenuMarker(menuMarker % 2);
-  lcd.setCursor(1, 0);
-  lcd.print("Calibrate       ");
-  lcd.setCursor(1, 1);
-  lcd.print("Tare       ");
+  int up = menuMarker % 2;
+  printMenuMarker(up);
+  if (!up) {
+    lcd.setCursor(1, 0);
+    lcd.print(menu[menuMarker]);
+    if (menuMarker < lastItem) {
+      lcd.setCursor(1, 1);
+      lcd.print(menu[menuMarker + 1]);
+    } else {
+      lcd.setCursor(1, 1);
+      lcd.print(EMPTY);
+    }
+  } else {
+    lcd.setCursor(1, 0);
+    lcd.print(menu[menuMarker - 1]);
+    lcd.setCursor(1, 1);
+    lcd.print(menu[menuMarker]);
+  }
+
 }

 void doTare() {


synch with poe version

synch with poe version

--- sketches/EnerginoYun/EnerginoYun.ino
+++ sketches/EnerginoYun/EnerginoYun.ino
@@ -58,7 +58,7 @@
 #define FEEDID        0                                   // replace your feed ID
 #define FEEDSURL      "https://api.xively.com/v2/feeds/"  // replace your remote service IP address

-#define RELAYPIN      3
+#define RELAYPIN      2
 #define CURRENTPIN    A0
 #define VOLTAGEPIN    A1

@@ -113,15 +113,11 @@
 void setup() {
   // Set serial port
   Serial.begin(115200);
-  // Use the led 13 to notify that the
-  // setup completed
-  pinMode(13,OUTPUT);
-  digitalWrite(13, HIGH);
+  // Default on
+  pinMode(RELAYPIN, OUTPUT);
+  digitalWrite(RELAYPIN, LOW);
   // Init bridge library
   Bridge.begin();
-  // Default on
-  pinMode(RELAYPIN,OUTPUT);
-  digitalWrite(RELAYPIN, LOW);
   // Loading setting
   eeprom_read_block((void*)&settings, (void*)0, sizeof(settings));
   if (strcmp(settings.magic, MAGIC) != 0) {
@@ -133,8 +129,10 @@
   // listen on port
   server.listenOnLocalhost();
   server.begin();
-  // Setup ok
-  digitalWrite(13, LOW);
+  // Use the led 13 to notify that the
+  // setup completed
+  pinMode(13,OUTPUT);
+  digitalWrite(13, HIGH);
 }

 void loop() {
@@ -313,9 +311,11 @@
     }
     else if (cmd == 'S') {
       if (value > 0) {
+        Serial.println("@switch: high");
         digitalWrite(RELAYPIN, HIGH);
       }
       else {
+        Serial.println("@switch: low");
         digitalWrite(RELAYPIN, LOW);
       }
     }
@@ -392,10 +392,10 @@
     if (subCommand == "switch") {
       char c = client.read();
       if (c == '0') {
-        digitalWrite(RELAYPIN, 0);
+        digitalWrite(RELAYPIN, LOW);
       }
       if (c == '1') {
-        digitalWrite(RELAYPIN, 1);
+        digitalWrite(RELAYPIN, HIGH);
       }
       sendReply(client,subCommand,digitalRead(RELAYPIN));
       return;


Power the soil sensor with PIN_SENSOR_VCC

--- LoRa/LoRa_Garden_TX/LoRa_Garden_TX.ino
+++ LoRa/LoRa_Garden_TX/LoRa_Garden_TX.ino
@@ -81,6 +81,14 @@
   onewireSensors.begin();
   onewireSensors.getAddress(deviceAddress, 0);

+  // Connect the light sensor to ground.
+  // The light sensor is a voltage source.
+  // So to insure that there is not a voltage higher than vcc
+  // on the external ADC, it's ground is connected via the pin
+  // which is high impedance on startup.
+  pinMode(PIN_SENSOR_GND, OUTPUT);
+  digitalWrite(PIN_SENSOR_GND, LOW);
+
   // Begin the external ADC.
   ads.begin();
 }
@@ -95,12 +103,8 @@
   // Read the temperature while the aref settles.
   tx_payload.setTemperature(readTemperature());

-  // Connect the light sensor to ground.
-  pinMode(PIN_SENSOR_GND, OUTPUT);
-  digitalWrite(PIN_SENSOR_GND, LOW);
-
   // Power up the soil sensor.
-  digitalWrite(PIN_SENSOR_GND, HIGH);
+  digitalWrite(PIN_SENSOR_VCC, HIGH);

   tx_payload.setChargeMa(readSolarCurrent());
   tx_payload.setChargeMv(readSolarVolts());
@@ -108,13 +112,8 @@
   tx_payload.setSoil(readSoil(vcc));

   // Power down the soil sensor.
-  digitalWrite(PIN_SENSOR_GND, LOW);
-
-  // Disconnect the light sensor.
-  // This insures that there is not a voltage higher than vcc
-  // on the external ADC, as the light sensor is a voltage source.
-  pinMode(PIN_SENSOR_GND, INPUT);
-
+  digitalWrite(PIN_SENSOR_VCC, LOW);
+
   // Build the payload buffer.
   uint8_t payload_buf[tx_payload.size()];
   tx_payload.serialize(payload_buf);


Arduino generate actual ring tone pattern

--- Payphone/Arduino/Payphone/Payphone.ino
+++ Payphone/Arduino/Payphone/Payphone.ino
@@ -60,6 +60,9 @@
 #define RINGER 11

 #define HOOK_TIMEOUT 5
+#define RING_ON_TIME 400
+#define RING_OFF_TIME 200
+

 int8_t incoming;
 volatile uint8_t newHookState = 0;
@@ -67,6 +70,9 @@
 uint8_t hookState = 0;
 uint32_t hookTimeOut = 0;
 uint8_t followState = 1;
+uint8_t ringingState = 0;
+uint32_t ringingTimmer = 0;
+uint8_t ringingStage = 0;

 void setup()
@@ -123,7 +129,30 @@
         hookTimeOut = millis();
         hookState = newHookState;
         Serial.print(hookState ? OFF_HOOK : ON_HOOK);
-    }
+    }
+
+    if (ringingState) {
+        switch (ringingState) {
+            case 1:
+                if ((millis() - ringingTimmer) > RING_ON_TIME) {
+                    ringingTimmer = millis();
+                    analogWrite(RINGER, 0);
+                    ringingState = 0;
+                }
+                break;
+
+            case 0:
+                if ((millis() - ringingTimmer) > RING_OFF_TIME) {
+                    ringingTimmer = millis();
+                    analogWrite(RINGER, 128);
+                    ringingState = 1;
+                }
+                break;
+
+            default:
+                break;
+        }
+    }
 }

 void hook()
@@ -138,39 +167,14 @@

 void ringStart()
 {
+    ringingState = true;
+    ringingTimmer = millis();
     analogWrite(RINGER,128);
+    ringingStage = 1;
 }

 void ringStop()
 {
+    ringingState = false;
     analogWrite(RINGER, 0);
-}
-
-
-/*
-void keypadEvent(KeypadEvent key){
-  switch (keypad.getState()){
-    case PRESSED:
-      switch (key){
-        case '#': digitalWrite(ledPin,!digitalRead(ledPin)); break;
-        case '*':
-          digitalWrite(ledPin,!digitalRead(ledPin));
-        break;
-      }
-      break;
-    case RELEASED:
-      switch (key){
-        case '*':
-          digitalWrite(ledPin,!digitalRead(ledPin));
-          blink = false;
-        break;
-      }
-      break;
-    case HOLD:
-      switch (key){
-        case '*': blink = true; break;
-      }
-      break;
-  }
-}
-*/+}


Comments.

Comments.

--- Prototype/Node/Node.ino
+++ Prototype/Node/Node.ino
@@ -7,12 +7,11 @@
 	- node_id    xy-1
 	- version    0

-- Subtypes of this prototype: SerialNode.
+- Subtypes of this prototype: Serial.

 - Depends on JeeLib Ports InputParser, but not all of ports compiles on t85.

 XXX: SoftwareSerial support 20, 16, 8Mhz only. Does not compile for m8.
-XXX: write different versions for t85, m8

 See
 - AtmegaEEPROM
@@ -36,7 +35,6 @@
 	Reload from EEPROM (reset changes)::

 		0 W
-

   */


Correct MOSI/MISO pins and update to persist frame count in EEPROM

--- LoraNode1/LoraNode1.ino
+++ LoraNode1/LoraNode1.ino
@@ -12,8 +12,8 @@
  *  GND        GND
  *  VCC        VCC
  *  GPIO15     NSS
- *  GPIO12     MOSI
- *  GPIO13     MIS0
+ *  GPIO13     MOSI
+ *  GPIO12     MIS0
  *  GPIO14     SCK
  *  GPIO5      DIO0
  *  GPIO4      DIO1
@@ -26,15 +26,18 @@
  *  GPIO2 - must be high to boot
  *  GPIO3 - Serial RX
  *  ADC
+ *  On an ESP12e also:
+ *  GPIO10 - Can be used if sketch flashed with DIO mode
+ *  GPIO9 - Can be used if you have a DIO ESP such as a "real" NodeMCU 1.0
  *
  * Author: Ant Elder
  * License: Apache License v2
  */
-
 #include <ESP8266WiFi.h>
 #include <lmic.h>
 #include <hal/hal.h>
 #include <SPI.h>
+#include <EEPROM.h>

 ADC_MODE(ADC_VCC); // enables reading the ESP8266 supply voltage

@@ -47,21 +50,47 @@
     .dio = {5, 4, LMIC_UNUSED_PIN},
 };

-// LoRaWAN end-device address (DevAddr) see http://thethingsnetwork.org/wiki/AddressSpace
-static const u4_t DEVADDR = 0x03FF0701 ; // <-- Change this address for every node!
-
+// Create these with ttnctl or the TTN Dashboard at https://staging.thethingsnetwork.org/
+// LoRaWAN end-device address
+static const u4_t DEVADDR = 0x762C6511;
+// LoRaWAN NwkSKey, network session key
+static const PROGMEM u1_t NWKSKEY[16] = { 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11 };
+// LoRaWAN AppSKey, application session key
+static const u1_t PROGMEM APPSKEY[16] = { 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0xD1, 0x11, 0x11, 0x11, 0x11, 0x11 };
+
 volatile boolean dio0Triggered;
+
+// The LORAWAN session state is saved in EEPROM
+// Here just the frame sequence number is saved as its ABP with a Single Channel Gateway,
+// See http://forum.thethingsnetwork.org/t/new-backend-how-to-connect/1983/91
+#define INITED_FLAG 0x12344321 // <<<< Change this to have the frame sequence restart from zero
+typedef struct {
+  uint32 inited;
+  u4_t seqnoUp;
+} LORA_STATE;
+LORA_STATE loraState;

 void setup() {
   Serial.begin(115200); Serial.println();

+  EEPROM.begin(sizeof(loraState));
+  EEPROM.get(0, loraState);
+  if (loraState.inited != INITED_FLAG) {
+     loraState.inited = INITED_FLAG;
+     loraState.seqnoUp = 0;
+  }
+
   lmicInit();
-  // LMIC bug? the EV_TXCOMPLETE event seems to takes ages to happen, but DIO0 high indicates TX complete
+  // the EV_TXCOMPLETE event takes ages to happen, but DIO0 high indicates TX complete
+  // See https://github.com/matthijskooijman/arduino-lmic/issues/16
   attachInterrupt(digitalPinToInterrupt(lmic_pins.dio[0]), dio0ISR, RISING);

-  String vcc = String(ESP.getVcc());
+  LMIC.seqnoUp = loraState.seqnoUp;
+
+  String vcc = String(ESP.getVcc()); // Needs ESP SDK 1.5.3, see https://github.com/esp8266/Arduino/issues/1961
   do_send(vcc);
 }
+

 // loop runs until the TX Complete event puts the ESP to sleep
 void loop() {
@@ -107,20 +136,16 @@
 }

 void goToSleep() {
+
+  loraState.seqnoUp = LMIC.seqnoUp;
+  EEPROM.put(0, loraState);
+  EEPROM.end();
+  Serial.print("loraState.seqnoUp = "); Serial.println(loraState.seqnoUp);
+
   Serial.print("Up time "); Serial.print(millis());
   Serial.print(", going to sleep for "); Serial.print(SLEEP_SECONDS); Serial.println(" secs");
   ESP.deepSleep(SLEEP_SECONDS*1000000, RF_DISABLED);
 }
-
-// LoRaWAN NwkSKey, network session key
-// This is the default Semtech key, which is used by the prototype TTN
-// network initially.
-static const PROGMEM u1_t NWKSKEY[16] = { 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C };
-
-// LoRaWAN AppSKey, application session key
-// This is the default Semtech key, which is used by the prototype TTN
-// network initially.
-static const u1_t PROGMEM APPSKEY[16] = { 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C };

 void lmicInit() {
   Serial.print("LMIC Init started at "); Serial.print(millis()); Serial.print("...");
@@ -170,7 +195,7 @@
     LMIC_setLinkCheckMode(0);

     // Set data rate and transmit power (note: txpow seems to be ignored by the library)
-    LMIC_setDrTxpow(DR_SF7,14);
+    LMIC_setDrTxpow(DR_SF7, 20);

   // only use channel 0 for the single channel gateway
   LMIC_disableChannel(1);


working prototype

working prototype

--- Turnstyle/Turnstyle.ino
+++ Turnstyle/Turnstyle.ino
@@ -13,26 +13,28 @@
 #define DETECTION_THRESH 50 // Distance cutoff for passing
 #define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.

-NewPing sonar_1(TRIGGER_PIN_1, ECHO_PIN_1, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
-NewPing sonar_2(TRIGGER_PIN_2, ECHO_PIN_2, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
+NewPing sonar_1(TRIGGER_PIN_1, ECHO_PIN_1, MAX_DISTANCE); // NewPing setup of closer sensor.
+NewPing sonar_2(TRIGGER_PIN_2, ECHO_PIN_2, MAX_DISTANCE); // NewPing setup of farther sensor.

 // RGB
 rgb_lcd lcd;

 // MADGEWICK
 Madgwick filter;
-unsigned long microsPerReading, microsPrevious;
+unsigned long microsPerReading, microsPrevious, microsBetweenReads, microsLastRead;
 float accelScale, gyroScale;

 // THRESHOLDS
 const int thresh = 60;       // < 60 cm to sensor is considered passing through.
-const float openAngle = 10;  // door is considered open at 10 degrees.
+const float openAngle = 20;  // door is considered open at 20 degrees.
+boolean doorOpen = false;

 // INDICATOR
 const int ledPin =  13;      // the number of the LED pin

 // POPULATION
 int population = 0;
+unsigned long closeTrigger = 0, farTrigger = 0;

 // SETUP
 void setup() {
@@ -57,6 +59,8 @@
   // initialize variables to pace updates to correct rate
   microsPerReading = 1000000 / 25;
   microsPrevious = micros();
+  microsBetweenReads = 1000000 / 2; // must wait half a second between consecutive reads
+  microsLastRead = micros();

   // get initial angle of the door
   // startAngle = measureYaw();
@@ -76,9 +80,37 @@
     float difference = measureYaw() - 180;
     doorAngle = abs(difference);

-    ping_1 = sonar_1.ping_cm();
-    ping_2 = sonar_2.ping_cm();
-    printinfo(doorAngle, ping_1, ping_2);
+    if (doorAngle < openAngle) {
+      closeDoor();
+      Serial.println("Door not open");
+    } else if (microsNow - microsLastRead < microsBetweenReads) {
+      Serial.println("Movement Detected");
+    } else {
+      openDoor();
+      ping_1 = sonar_1.ping_cm();
+      ping_2 = sonar_2.ping_cm();
+
+      if (detect(ping_2)) {
+        if (closeTrigger > 0) {
+          incrementPopulation();
+        } else if (!detect(ping_1)) {
+          farTrigger = microsNow;
+        }
+      } else if (detect(ping_1)) {
+        if (farTrigger > 0) {
+          decrementPopulation();
+        } else if (!detect(ping_2)) {
+          closeTrigger = microsNow;
+        }
+      } else {
+        if (farTrigger > 0 && microsNow - farTrigger > 2 * microsBetweenReads) {
+          farTrigger = 0;
+        } else if (closeTrigger > 0 && microsNow - closeTrigger > 2 * microsBetweenReads) {
+          closeTrigger = 0;
+        }
+      }
+      printinfo(doorAngle, ping_1, ping_2);
+    }

     // increment previous time, so we keep proper pace
     microsPrevious = microsPrevious + microsPerReading;
@@ -107,6 +139,46 @@
   return filter.getYaw();
 }

+void incrementPopulation() {
+  population++;
+  updatePopulationAndMoveCursor();
+  lcd.write("Welcome!        ");
+}
+
+void decrementPopulation() {
+  if (population > 0) {
+    population--;
+  }
+  updatePopulationAndMoveCursor();
+  lcd.write("Have a nice day!");
+}
+
+void openDoor() {
+  if (!doorOpen) {
+    lcd.setRGB(0, 255, 0);
+    doorOpen = true;
+  }
+}
+
+void closeDoor() {
+  if (doorOpen) {
+    lcd.setRGB(255, 255, 255);
+    doorOpen = false;
+  }
+}
+
+// Update population and move cursor to where the message will be written
+void updatePopulationAndMoveCursor() {
+  lcd.setCursor(12, 0);
+  lcd.write("    ");
+  lcd.setCursor(12, 0);
+  lcd.print(population);
+  lcd.setCursor(0, 1);
+  farTrigger = 0;
+  closeTrigger = 0;
+  microsLastRead = micros();
+}
+
 float convertRawAcceleration(int aRaw) {
   // since we are using 2G range
   // -2g maps to a raw value of -32768
@@ -123,6 +195,10 @@

   float g = (gRaw * 250.0) / 32768.0;
   return g;
+}
+
+boolean detect(int pingValue) {
+  return pingValue < thresh && pingValue > 0;
 }

 void printinfo(float doorAngle, int ping_1, int ping_2) {


Added extra boot sequence initialisers to sychronise the programs

--- GVG200.ino
+++ GVG200.ino
@@ -1421,8 +1421,11 @@
   // Let's wait for the pi to catch up
   writeDisplay("Waiting for boot...");
   wait:
-  while(!Serial.available());
-  if(!(Serial.read()=='!')) goto wait; // eww a goto! this IS embedded C after all!
+  while(!Serial.available()) {
+    Serial.println("?"); // helloooo we're booted and waiting
+    delay(200);
+  }
+  if(!(Serial.read()=='?')) goto wait; // eww a goto! this IS embedded C after all!
   writeDisplay("\x15"); // clear display

@@ -1471,6 +1474,9 @@
   booting = 0;
   writeDisplay("\x15\x0E");
   delay(10);
+
+  Serial.println("!"); // We've booted, you can now send us commands
+  while(Serial.available()) Serial.read(); // flush out all the junk they've sent us
 }

 void waitSerial() {


Improved formatting of file output

Improved formatting of file output

--- fed-arduino/fed-arduino.ino
+++ fed-arduino/fed-arduino.ino
@@ -99,9 +99,9 @@
     while (1);
   }
   else {
-    dataFile.print(currentTime());
     dataFile.println(F("Time,Pellet #1 Count,Pellet #2 Count"));
     dataFile.close();
+    logData();
   }
   delay(500);


Minor tweaks to motor control

Minor tweaks to motor control

--- fed-arduino/fed-arduino.ino
+++ fed-arduino/fed-arduino.ino
@@ -67,8 +67,8 @@

   //motor shield stuff
   gMotorShield.begin();
-  motor1->setSpeed(30);
-  motor2->setSpeed(30);
+  motor1->setSpeed(20);
+  motor2->setSpeed(20);

   //SD card init stuff
   Wire.begin();
@@ -256,14 +256,14 @@
     power_twi_enable();
     if (motorNum == 0)
     {
-      motor1->step(STEPS_TO_INCREMENT/2,FORWARD,DOUBLE);
-      motor1->step(STEPS_TO_INCREMENT,BACKWARD,DOUBLE);
+      motor1->step(STEPS_TO_INCREMENT/2,BACKWARD,DOUBLE);
+      motor1->step(STEPS_TO_INCREMENT,FORWARD,DOUBLE);
       motor1->release();
     }
     else if (motorNum == 1)
     {
-      motor2->step(STEPS_TO_INCREMENT/2,FORWARD,DOUBLE);
-      motor2->step(STEPS_TO_INCREMENT,BACKWARD,DOUBLE);
+      motor2->step(STEPS_TO_INCREMENT/2,BACKWARD,DOUBLE);
+      motor2->step(STEPS_TO_INCREMENT,FORWARD,DOUBLE);
       motor2->release();
     }
     power_twi_disable();


Version 1.03. Added class check.

Version 1.03. Added class check.

--- module/module.ino
+++ module/module.ino
@@ -58,7 +58,12 @@
 	}
 	else {
 		existingTime = getTime(readData);
-		if(existingTime >= quota) {
+		if(readData[8] != 0xDD) {
+			Serial.println("You are not authorized to use the machine.");
+			Serial.println();
+			delay(5000);
+		}
+		else if(existingTime >= quota) {
 			Serial.println("You have reached your quota for this month.");
 			Serial.println();
 			delay(5000);


Working double envelope

Working double envelope

Main oscillator by pitch, octaves by rolling, filter by y stick
Play note using the Z button

Thanks to @brandoninvergo for the blending of different oscillators

--- nuncha/nuncha.ino
+++ nuncha/nuncha.ino
@@ -2,12 +2,10 @@
 #include "Nunchuck.h"
 #include <Wire.h>
 #include <MozziGuts.h>
+#include <LowPassFilter.h>
+#include <ADSR.h>

-#define CONTROL_RATE 64 // powers of 2 please
-
-#define LEFT 0
-#define RIGHT 1
-#define UP 2
+#define CONTROL_RATE 128 // powers of 2 please

 int bumpy_input = 0;
 int constrain_input = 0;
@@ -16,13 +14,11 @@

 #include <Oscil.h> // oscillator template
 #include <tables/sin2048_int8.h> // sine table for oscillator
-#include <tables/triangle2048_int8.h> // triangle table for oscillator
-#include <tables/triangle_analogue512_int8.h> // saw table for oscillator

 // use: Oscil <table_size, update_rate> oscilName (wavetable), look in .h file of table #included above
 Oscil <SIN2048_NUM_CELLS, AUDIO_RATE> aSin(SIN2048_DATA);
-Oscil <TRIANGLE2048_NUM_CELLS, AUDIO_RATE> aTri(TRIANGLE2048_DATA);
-Oscil <TRIANGLE_ANALOGUE512_NUM_CELLS, AUDIO_RATE> aSaw(TRIANGLE_ANALOGUE512_DATA);
+Oscil <SIN2048_NUM_CELLS, AUDIO_RATE> aRight(SIN2048_DATA);
+Oscil <SIN2048_NUM_CELLS, AUDIO_RATE> aLeft(SIN2048_DATA);

 // Average the input signals
 #include <RollingAverage.h>
@@ -39,18 +35,30 @@
 int xStick;
 int yStick;

+LowPassFilter lpf;
+
+ADSR <CONTROL_RATE, CONTROL_RATE> envelope;
+ADSR <CONTROL_RATE, CONTROL_RATE> envelope2;
+
 unsigned char volumeLeft;
 unsigned char volumeRight;
 unsigned char volumePitch;

+int pressed = 0;
+int unpressed = 0;
 int play = 0;
+
+unsigned int duration, attack, decay, sustain, release_ms;
+
+byte gain = 0;
+byte gain2 = 0;

 void setup(){
   uint8_t error;

   error = Nunchuck.begin ();

-  //Serial.begin(19200);
+  //Serial.begin(9600);

   /*if ( error )
   {
@@ -63,60 +71,92 @@

   // set the frequency
   aSin.setFreq(0);
-  aTri.setFreq(0);
-  aSaw.setFreq(0);
+  aRight.setFreq(0);
+  aLeft.setFreq(0);
+
+  attack = 50;
+  decay = 50;
+  sustain = 100;
+  release_ms = 500;
+  envelope.setADLevels(255, 100);
+  envelope.setTimes(attack,decay,sustain,release_ms);
+
+  envelope2.setADLevels(255, 100);
+  envelope2.setTimes(attack,decay,sustain,release_ms);
+
+  lpf.setResonance(1);
+
+  lpf.setCutoffFreq(128);
 }

 void updateControl(){
-   // read the input device
+   Nunchuck.update();

-   Nunchuck.update();
-
-   //Serial.print(Nunchuck . getRaw()->yStick);
-   //Serial.print(' ');
-   //Serial.println((int)volume);
-
-   if ( Nunchuck.getZButton() )
-   {
+   if( Nunchuck.getZButton() )
+   {
+     pressed++;
+     if( pressed >= 1 )
+     {
+       envelope.noteOn();
+       envelope2.noteOn();
+       pressed = 0;
+     }
+   }
+
      constrain_input = constrain(Nunchuck . getRoll(), -180, -1);
-     bumpy_input = map(-constrain_input, 0, 180, 0, 800);
-     constrain_input = constrain(-constrain_input, 0, 100);
-     volumeLeft = map(constrain_input, 0, 100, 0, 255);
+     bumpy_input = map(-constrain_input, 0, 180, 11, 0);
      rollLeft = rollLAverage.next(bumpy_input);
+
      constrain_input = constrain(Nunchuck . getRoll(), 0, 180);
-     bumpy_input = map(constrain_input, 0, 180, 0, 800);
-     constrain_input = constrain(constrain_input, 0, 100);
-     volumeRight = map(constrain_input, 0, 100, 0, 255);
+     bumpy_input = map(constrain_input, 0, 180, 11, 0);
      rollRight = rollRAverage.next(bumpy_input);
-     constrain_input = constrain(Nunchuck . getPitch(), 100, 130);
-     bumpy_input = map(constrain_input, 100, 174, 0, 800);
-     constrain_input = constrain(constrain_input, 100, 144);
-     volumePitch = map(constrain_input, 100, 144, 0, 150);
+
+     constrain_input = constrain(Nunchuck . getPitch(), 18, 174);
+     bumpy_input = map(constrain_input, 100, 150, 440, 880);
      pitch = pitchAverage.next(bumpy_input);

      constrain_input = constrain(Nunchuck . getRaw()->yStick, 31, 129);
      bumpy_input = map(-constrain_input, -129, -31, 200, 1000);
      yStick = yAverage.next(bumpy_input);

-     aSin.setFreq(pitch);
-     aTri.setFreq(rollRight);
-     aSaw.setFreq(rollLeft);
-
-     play = 1;
-   }
-
-   else{play = 0;}
+     aSin.setFreq((int)pitch);
+     if (rollRight == 0 )
+     {
+       aRight.setFreq(0);
+     }
+     else
+     {
+       aRight.setFreq((int)((2*pitch) + rollRight*73));
+       //aRight.setFreq((int)((2*pitch) - rollRight*73));
+     }
+     if (rollLeft == 0 )
+     {
+       aLeft.setFreq(0);
+     }
+     else{
+       aLeft.setFreq( (int)((pitch/2)+ 18*rollLeft));
+       //aLeft.setFreq( (int)((pitch/2)- 18*rollLeft));
+     }
+   envelope.update();
+   envelope2.update();
+
+   gain = envelope.next();
+   gain2 = envelope2.next();
 }

 int updateAudio(){
-  if (play)
-  {
-    int synth = (((int)aSaw.next() * volumeLeft) + ((int)aTri.next() * volumeRight) + ((int)aSin.next() * volumePitch))>>8;
+    int synth;
+
+    if( rollRight == 0 )
+    {
+      synth = lpf.next(((long)gain * aSin.next() + (int)gain2 * aLeft.next()) >> 9 );
+    }
+    else
+    {
+      synth = lpf.next(((long)gain * aSin.next() + (int)gain2 * aRight.next()) >> 9);
+    }
     return synth;
-  }
-
-  return 0;
 }

 void loop(){


Blank the display after 10 minutes of inactivity

--- pingpong/pingpong.ino
+++ pingpong/pingpong.ino
@@ -5,6 +5,7 @@
 #define LATCH 4
 #define CLK   3
 #define DATA  2
+#define INACTIVEMILLIS 600000 // 10 minutes

 // Seven Segment Display Handling
 byte DigitBytes[10]= {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x67};
@@ -127,6 +128,8 @@
 int gameOver = 0;
 int victoryBlinkCounter = 0;

+unsigned long lastActivityTime;
+
 boolean p1Win = false;
 boolean p2Win = false;
 boolean blinkToggle = true;
@@ -146,6 +149,7 @@
   p1Button.init();
   p2Button.init();
   victorySong.init();
+  lastActivityTime = millis();
 }

@@ -153,6 +157,12 @@
 {
   int p1Event, p2Event;

+  Serial.println(millis() - lastActivityTime);
+
+  if ((millis() - lastActivityTime) > INACTIVEMILLIS) {
+    shutDownLights();
+  }
+
   if (gameOver) {
     victoryBlinkCounter++;

@@ -169,6 +179,7 @@

   p1Event = p1Button.handle();
   if (!gameOver && p1Event == BUTTON_SHORT) {
+    lastActivityTime = millis();
     p1Score++;
     numServes++;
     showScore();
@@ -176,6 +187,7 @@
   }

   if (gameOver && p1Event == BUTTON_LONG) {
+    lastActivityTime = millis();
     resetGame();
     currentServe = 0;
     numServes = 0;
@@ -184,6 +196,7 @@

   p2Event = p2Button.handle();
   if (!gameOver && p2Event == BUTTON_SHORT) {
+    lastActivityTime = millis();
     p2Score++;
     numServes++;
     showScore();
@@ -191,6 +204,7 @@
   }

   if (gameOver && p2Event == BUTTON_LONG) {
+    lastActivityTime = millis();
     resetGame();
     currentServe = 1;
     numServes = 0;
@@ -230,6 +244,14 @@
   } else {
     showP1Score(p1Score, false);
   }
+}
+
+void shutDownLights()
+{
+  digitalWrite(LATCH, LOW);
+  shiftOut(DATA, CLK, MSBFIRST, 0x00);
+  shiftOut(DATA, CLK, MSBFIRST, 0x00);
+  digitalWrite(LATCH, HIGH);
 }

 void checkForWinner()


minor changes in ASB firmware

minor changes in ASB firmware


Transmitter and Reciver combined

Transmitter and Reciver combined

--- Master.ino
+++ Master.ino
@@ -12,8 +12,8 @@
 #define greenLED 3 //bacon & green led port
 #define blueLED 4 //acknowledgement & blue led port
 #define thErrON 0.9 //threshold multipler HIGH leds
-#define thErrOFF 2 //threshold multipler LOW leds
-#define setupWaitTime 0 //(ms) delay at setup time
+#define thErrOFF 1.3 //threshold multipler LOW leds
+#define setupWaitTime 1 //(ms) delay at setup time
 #define fbTime 1000 //(ms) feedback led on time
 #define cycTime 1000 //(ms) feedback led off time
 #define sync "MODE_sync" // keyword for start sync seq (transmitter side)
@@ -21,6 +21,9 @@
 #define partyM "MODE_party" // keyword for party mode (eastern egg)
 #define crdM "MODE_credits" // keyword to show contributors
 #define initDelay 500 //(ms) synchronization sequence delay
+#define redONtime 5 //(ms)
+#define redOFFtime 5 //(ms)
+#define trnsDELAY 0 //(ms)

 void flashDotOrDash(int color, bool dotOrDash);
 void synchronization();
@@ -83,9 +86,9 @@
     }
   Serial.print("Getting enviroment values"); //get env
   tcs.getRawData(&r, &g, &b, &c); //store environment values
-  th_Val[0].r_t = (r * thErrOFF);
-  th_Val[0].g_t = (g * thErrOFF);
-  th_Val[0].b_t = (b * thErrOFF);
+  th_Val[0].r_t = ((float) r * thErrOFF);
+  th_Val[0].g_t = ((float) g * thErrOFF);
+  th_Val[0].b_t = ((float) b * thErrOFF);
   Serial.print("\nWaiting for threshold sequence or type ");
   Serial.print(sync);
   Serial.println(" to send threshold sequence");
@@ -101,7 +104,6 @@
        }
   }
   tcs.getRawData(&r, &g, &b, &c); //get env info
-  Serial.print(".");
   //R00
   if(r < th_Val[0].r_t) //go back if red is lower then OFF threshold
   {
@@ -111,9 +113,9 @@
   Serial.print("Getting threshold values");
   Serial.print(".");
   //set threshold for red HIGH
-  th_Val[1].r_t = (r * thErrON);
-  th_Val[1].g_t = (g * thErrOFF);
-  th_Val[1].b_t = (b * thErrOFF);
+  th_Val[1].r_t = ((float) r * thErrON);
+  th_Val[1].g_t = ((float) g * thErrOFF);
+  th_Val[1].b_t = ((float) b * thErrOFF);
   while(r > th_Val[0].r_t) //wait until red is LOW
   {
     tcs.getRawData(&r, &g, &b, &c); //get env info
@@ -126,9 +128,9 @@
   }
   delay(setupWaitTime);
   //set threshold for green high
-  th_Val[2].r_t = (r * thErrOFF);
-  th_Val[2].g_t = (g * thErrON);
-  th_Val[2].b_t = (b * thErrOFF);
+  th_Val[2].r_t = ((float) r * thErrOFF);
+  th_Val[2].g_t = ((float) g * thErrON);
+  th_Val[2].b_t = ((float) b * thErrOFF);
   while(g > th_Val[0].g_t) //wait until green is LOW
   {
     tcs.getRawData(&r, &g, &b, &c);
@@ -141,9 +143,9 @@
   }
   delay(setupWaitTime);
   //set threshold for blue high
-  th_Val[3].r_t = (r * thErrOFF);
-  th_Val[3].g_t = (g * thErrOFF);
-  th_Val[3].b_t = (b * thErrON);
+  th_Val[3].r_t = ((float) r * thErrOFF);
+  th_Val[3].g_t = ((float) g * thErrOFF);
+  th_Val[3].b_t = ((float) b * thErrON);
   while(b > th_Val[0].b_t)
   {
     tcs.getRawData(&r, &g, &b, &c); //wait until blue is LOW
@@ -156,9 +158,9 @@
   }
   delay(setupWaitTime);
   //set threshold for red-green high
-  th_Val[4].r_t = (r * thErrON);
-  th_Val[4].g_t = (g * thErrON);
-  th_Val[4].b_t = (b * thErrOFF);
+  th_Val[4].r_t = ((float) r * thErrON);
+  th_Val[4].g_t = ((float) g * thErrON);
+  th_Val[4].b_t = ((float) b * thErrOFF);
   while((r > th_Val[0].r_t) | (g > th_Val[0].g_t)) //wait until red and green is LOW
   {
     tcs.getRawData(&r, &g, &b, &c);
@@ -171,9 +173,9 @@
   }
   delay(setupWaitTime);
   //set threshold for red-blue high
-  th_Val[5].r_t = (r * thErrON);
-  th_Val[5].g_t = (g * thErrOFF);
-  th_Val[5].b_t = (b * thErrON);
+  th_Val[5].r_t = ((float) r * thErrON);
+  th_Val[5].g_t = ((float) g * thErrOFF);
+  th_Val[5].b_t = ((float) b * thErrON);
   while((r > th_Val[0].r_t) | (b > th_Val[0].b_t)) //wait until red and blue is LOW
   {
     tcs.getRawData(&r, &g, &b, &c);
@@ -186,9 +188,9 @@
   }
   delay(setupWaitTime);
   //set threshold for green-blue high
-  th_Val[6].r_t = (r * thErrOFF);
-  th_Val[6].g_t = (g * thErrON);
-  th_Val[6].b_t = (b * thErrON);
+  th_Val[6].r_t = ((float) r * thErrOFF);
+  th_Val[6].g_t = ((float) g * thErrON);
+  th_Val[6].b_t = ((float) b * thErrON);
   while((g > th_Val[0].g_t) | (b > th_Val[0].b_t)) //wait until green and blue is LOW
   {
     tcs.getRawData(&r, &g, &b, &c);
@@ -201,13 +203,13 @@
   }
   delay(setupWaitTime);
   //set threshold for red-green-blue high
-  th_Val[7].r_t = (r * thErrON);
-  th_Val[7].g_t = (g * thErrON);
-  th_Val[7].b_t = (b * thErrON);
-  while((g > th_Val[0].g_t) | (b > th_Val[0].b_t) | (r > th_Val[0].r_t)) //wait until red, green and blue is LOW
-  {
-    tcs.getRawData(&r, &g, &b, &c);
-  }
+  th_Val[7].r_t = ((float) r * thErrON);
+  th_Val[7].g_t = ((float) g * thErrON);
+  th_Val[7].b_t = ((float) b * thErrON);
+  while((g > th_Val[0].g_t) | (b > th_Val[0].b_t) | (r > th_Val[0].r_t)) //wait until red, green and blue is HIGH
+  {
+    tcs.getRawData(&r, &g, &b, &c);
+  }
   Serial.println("Done");
   //print env values
   for(int j = 0; j < 8; j++)
@@ -227,6 +229,8 @@
 void loop()
 {
   bool err = 0;
+loopSTART:
+  //send start bacon
   digitalWrite(greenLED, HIGH);
   delay(fbTime);
   digitalWrite(greenLED, LOW);
@@ -262,6 +266,11 @@
     tcs.getRawData(&r, &g, &b, &c);

   detect_rgb(r, g, b, th_Val, buff[9], buff[10], buff[11]);
+
+  digitalWrite(redLED, HIGH);
+  delay(redONtime);
+  digitalWrite(redLED, LOW);
+  delay(redOFFtime);

   checkParity(buff[2], buff[4], buff[5], buff[6], buff[8], buff[9], buff[10], buff[11], buff[0], buff[1], buff[3], buff[7], err);

@@ -276,6 +285,7 @@
        Serial.print("\n");
        writtenCH = 0;
      }
+     goto loopSTART;
   }

   if (Serial.available() > 0)
@@ -286,15 +296,18 @@
       synchronization();
     else
     {
+      //Serial.print("\n");
       for(int j=0; j<inputHOLD.length(); ++j)
         {
-          Serial.print(inputHOLD[j] + ": ");
+          Serial.print(inputHOLD[j]);
           flashSequence(inputHOLD[j]);
         }
+        flashSequence('\n');
+       Serial.print("\n");
     }
-    digitalWrite(r, LOW);
-    digitalWrite(g, LOW);
-    digitalWrite(b, LOW);
+    digitalWrite(redLED, LOW);
+    digitalWrite(greenLED, LOW);
+    digitalWrite(blueLED, LOW);
   }
 }

@@ -304,12 +317,16 @@
   encodeASCII(sequence, buff[2],buff[4],buff[5],buff[6],buff[8],buff[9],buff[10],buff[11]);
   addParity(buff[2],buff[4],buff[5],buff[6],buff[8],buff[9],buff[10],buff[11], buff[0],buff[1],buff[3],buff[7]);

-
+
   Serial.print(sequence); //for testing **********************************************
   Serial.print(": ");

   tcs.getRawData(&r, &g, &b, &c);
   while(g < th_Val[2].g_t)
+  {
+    tcs.getRawData(&r, &g, &b, &c);
+  }
+  while(g > th_Val[0].g_t)
   {
     tcs.getRawData(&r, &g, &b, &c);
   }
@@ -320,11 +337,7 @@
     if(!first)
     {
       tcs.getRawData(&r, &g, &b, &c); //store environment values
-      while(b < th_Val[3].b_t)
-      {
-        tcs.getRawData(&r, &g, &b, &c); //store environment values
-      }
-      while(b < th_Val[3].b_t)
+      while(b > th_Val[0].b_t)
       {
         tcs.getRawData(&r, &g, &b, &c); //store environment values
       }
@@ -335,15 +348,31 @@
       flashDotOrDash(redLED, buff[j]);
       j++;

-      flashDotOrDash(3, buff[j]);
+      flashDotOrDash(greenLED, buff[j]);
       j++;

-      flashDotOrDash(4, buff[j]);
+      flashDotOrDash(blueLED, buff[j]);
       j++;
-
-    delay(1000);
-  }
-  Serial.println();
+      if(j < 12)
+      {
+        while(b < th_Val[3].b_t)
+         {
+            tcs.getRawData(&r, &g, &b, &c); //store environment values
+         }
+      }
+      else
+      {
+        while(r < th_Val[1].r_t)
+         {
+            tcs.getRawData(&r, &g, &b, &c); //store environment values
+         }
+      }
+      flashDotOrDash(redLED, false);
+      flashDotOrDash(blueLED, false);
+      flashDotOrDash(greenLED, false);
+    delay(trnsDELAY);
+  }
+  Serial.println(); //for testing **************************************

 }

@@ -352,34 +381,38 @@
     digitalWrite(redLED, HIGH);
     delay(initDelay);
     digitalWrite(redLED, LOW);
+    delay(initDelay);

     digitalWrite(greenLED, HIGH);
     delay(initDelay);
     digitalWrite(greenLED, LOW);
+    delay(initDelay);

     digitalWrite(blueLED, HIGH);
     delay(initDelay);
     digitalWrite(blueLED, LOW);
-
+    delay(initDelay);

     digitalWrite(redLED, HIGH);
     digitalWrite(greenLED, HIGH);
     delay(initDelay);
     digitalWrite(redLED, LOW);
     digitalWrite(greenLED, LOW);
-
+    delay(initDelay);
+
     digitalWrite(redLED, HIGH);
     digitalWrite(blueLED, HIGH);
     delay(initDelay);
     digitalWrite(redLED, LOW);
     digitalWrite(blueLED, LOW);
-
+    delay(initDelay);
+
     digitalWrite(greenLED, HIGH);
     digitalWrite(blueLED, HIGH);
     delay(initDelay);
     digitalWrite(greenLED, LOW);
     digitalWrite(blueLED, LOW);
-
+    delay(initDelay);

     digitalWrite(redLED, HIGH);
     digitalWrite(g, HIGH);
@@ -387,9 +420,7 @@
     delay(initDelay);
     digitalWrite(redLED, LOW);
     digitalWrite(greenLED, LOW);
-    digitalWrite(blueLED, LOW);
-    delay(initDelay);
-
+    digitalWrite(blueLED, LOW);
 }

 void flashDotOrDash(int color, bool dotOrDash)