Change OLED messages when in access point mode.

Show accespoint name and IP adress in OLED when in access point mode.

--- AP_routines.ino
+++ AP_routines.ino
@@ -99,12 +99,11 @@
   OLED.clear();
   OLED.setTextAlignment(TEXT_ALIGN_CENTER);
   OLED.setFont(ArialMT_Plain_10);
-  OLED.drawString(64,0, F("No WiFi found") );
-  OLED.drawString(64,8, F("Connect to AP:") );
-  OLED.setFont(ArialMT_Plain_24);
-  OLED.drawString(64,16,accessPointName);
-  OLED.setFont(ArialMT_Plain_10);
-  OLED.drawString(64,40, F("to setup this device") );
+  OLED.drawString(64,0, F("Connect to AP:") );
+  OLED.drawString(64,12,accessPointName);
+  OLED.drawString(64,26, F( "IP:" ) );
+  OLED.drawString(64,38,accessPointIP.toString() );
+  OLED.drawString(64,52, F("to setup this device") );
   OLED.display();

   WiFi.mode( WIFI_AP );


Changed the active state of geiger click relay.

--- Alicorn.ino
+++ Alicorn.ino
@@ -331,9 +331,9 @@

 void setRelays() {
     if (settings.geigerClicks)
+        digitalWrite(PIN_RELAY_GEIG, LOW);
+    else
         digitalWrite(PIN_RELAY_GEIG, HIGH);
-    else
-        digitalWrite(PIN_RELAY_GEIG, LOW);

     if (settings.gasSensor)
         digitalWrite(PIN_RELAY_GAS, LOW);


Some updated code... I think

Some updated code... I think

--- arduino/src/robotLEDControllerrev2/robotLEDControllerrev2.ino
+++ arduino/src/robotLEDControllerrev2/robotLEDControllerrev2.ino
@@ -38,7 +38,6 @@
 const int ledsNumber = 80; //number of leds on the strip
 CRGB leds[ledsNumber];
 boolean idleStart[ledsNumber];
-CRGB rainbow[ledsNumber];

 //color data
 uint32_t distanceColor = 0xFF00FF; //start off with the color being purple
@@ -88,7 +87,7 @@
   //clear the LED strip data
   FastLED.clear();

-  //Debugging
+  //debugging
   Serial.begin(9600);  //For debugging

   //set brightness
@@ -170,41 +169,44 @@
     //plays animation when shooting or collecting
     pass();
   }
-  else if (dataRecieved[0] == false && dataRecieved[1] == false && dataRecieved[2] == true && dataRecieved[3] == false){
-    //set lights to yellow
-    distanceColor = 0xFFFF00;
-  }
+  //  else if (dataRecieved[0] == false && dataRecieved[1] == false && dataRecieved[2] == true && dataRecieved[3] == false){
+  //    //set lights to yellow
+  //    distanceColor = 0xFFFF00;
+  //  }
   else if (dataRecieved[0] == false && dataRecieved[1] == false && dataRecieved[2] == true && dataRecieved[3] == true){
-    //signal to other robots
-    signal();
-  }
-  else if (dataRecieved[0] == false && dataRecieved[1] == true && dataRecieved[2] == true && dataRecieved[3] == false){
-    //set lights to green
-    distanceColor = 0x008000;
-  }
-  else if (dataRecieved[0] == true && dataRecieved[1] == false && dataRecieved[2] == false && dataRecieved[3] == false){
-    //sets the distance color to red
-    distanceColor = 0xFF0000;
-  }
-  else if (dataRecieved[0] == true && dataRecieved[1] == true && dataRecieved[2] == false && dataRecieved[3] == false){
-    //signal to other teams
+    //fireworks!!! (it used to be signal)
     celebration();
-  }
+  }
+  //  else if (dataRecieved[0] == false && dataRecieved[1] == true && dataRecieved[2] == true && dataRecieved[3] == false){
+  //    //set lights to green
+  //    distanceColor = 0x008000;
+  //  }
+  //  else if (dataRecieved[0] == true && dataRecieved[1] == false && dataRecieved[2] == false && dataRecieved[3] == false){
+  //    //sets the distance color to red
+  //    distanceColor = 0xFF0000;
+  //  }
+//  else if (dataRecieved[0] == true && dataRecieved[1] == true && dataRecieved[2] == false && dataRecieved[3] == false){
+//    //turn off lights temporarily while shooting
+//    FastLED.clear();
+//    delay(10);
+//    FastLED.show();
+//    delay(2500);
+//  }
   else if (dataRecieved[0] == true && dataRecieved[1] == false && dataRecieved[2] == true && dataRecieved[3] == false){
     //play animation during autonomous
     charging();
   }
-  else if (dataRecieved[0] == true && dataRecieved[1] == true && dataRecieved[2] == true && dataRecieved[3] == false){
-    //if the alliance color is blue
-    allianceColor = CRGB::Blue;
-  }
-  else if (dataRecieved[0] == true && dataRecieved[1] == true && dataRecieved[2] == false && dataRecieved[3] == true){
-    //if the alliance color is red
-    allianceColor = CRGB::Red;
-  }
+  //  else if (dataRecieved[0] == true && dataRecieved[1] == true && dataRecieved[2] == true && dataRecieved[3] == false){
+  //    //if the alliance color is blue
+  //    allianceColor = CRGB::Blue;
+  //  }
+  //  else if (dataRecieved[0] == true && dataRecieved[1] == true && dataRecieved[2] == false && dataRecieved[3] == true){
+  //    //if the alliance color is red
+  //    allianceColor = CRGB::Red;
+  //  }
   else if (dataRecieved[0] == false && dataRecieved[1] == true && dataRecieved[2] == false && dataRecieved[3] == true){
-    //rainbow after fireworks
-   // rainbow();
+    //rainbow during disabled
+    rainbow();
   }
   //for debugging
   //  Serial.print(dataRecieved[0]);
@@ -245,6 +247,36 @@
     delayMicroseconds(10000);
     while(true) delayMicroseconds(10000);
   }
+  //all other ifs to change variables
+  else if (dataRecieved[0] == true && dataRecieved[1] == true && dataRecieved[2] == true && dataRecieved[3] == false){
+    //if the alliance color is blue
+    allianceColor = CRGB::Blue;
+  }
+  else if (dataRecieved[0] == true && dataRecieved[1] == true && dataRecieved[2] == false && dataRecieved[3] == true){
+    //if the alliance color is red
+    allianceColor = CRGB::Red;
+  }
+  else if (dataRecieved[0] == false && dataRecieved[1] == false && dataRecieved[2] == true && dataRecieved[3] == false){
+    //set lights to yellow
+    distanceColor = 0xFFFF00;
+  }
+  else if (dataRecieved[0] == false && dataRecieved[1] == true && dataRecieved[2] == true && dataRecieved[3] == false){
+    //set lights to green
+    distanceColor = 0x008000;
+  }
+  else if (dataRecieved[0] == true && dataRecieved[1] == false && dataRecieved[2] == false && dataRecieved[3] == false){
+    //sets the distance color to red
+    distanceColor = 0xFF0000;
+  }
+  else if (dataRecieved[0] == true && dataRecieved[1] == true && dataRecieved[2] == false && dataRecieved[3] == false){
+    //turn off lights temporarily while shooting
+    FastLED.clear();
+    delay(10);
+    FastLED.show();
+    delay(2500);
+  }
+  //set the brightness back to full
+  FastLED.setBrightness(100);
 }

 void shootAndCollect(){
@@ -548,6 +580,7 @@
       leds[i] = distanceColor;
     }
   }
+  Serial.println("blah");
   FastLED.show();
   for(int timesPlayed = 0; timesPlayed < 20; timesPlayed++){
     //make the leds go down the strip
@@ -589,26 +622,42 @@
     Serial.println("hi");
   }
 }
-//void rainbow(){
-//  //makes a rainbow matrix
-//  FastLED.clear();
-//
-//  //start with rainbow
-//  for(int i = 0; i<79; i++){
-//    leds[i] = rainbow[i];
-//  }
-//
-//  for(int timesPlayed = 0; timesPlayed < 20; timesPlayed++){
-//    //make the leds go down the strip
-//    for(int i = 0; i < 19; i++){
-//      leds[i].r = leds[i+1].r;
-//      leds[i].g = leds[i+1].g;
-//      leds[i].b = leds[i+1].b;
-//    }
-//    leds[19].r = leds[0].r;
-//    leds[19].g = leds[0].g;
-//    leds[19].b = leds[0].b;
-//
+void rainbow(){
+  FastLED.setBrightness(20);
+  //makes a rainbow matrix
+  FastLED.clear();
+
+  //set up the rainbow
+  for(int i = 0; i<13;i++){ //red
+    leds[i] = CRGB::Red;
+  }
+  for(int i = 13; i<27;i++){ //orange
+    leds[i] = CRGB::Orange;
+  }
+  for(int i = 27; i<40;i++){ //yellow
+    leds[i] = CRGB::Yellow;
+  }
+  for(int i = 40; i<54;i++){ //green
+    leds[i] = CRGB::Green;
+  }
+  for(int i = 54; i<67;i++){ //blue
+    leds[i] = CRGB::Blue;
+  }
+  for(int i = 67; i<80;i++){ //violet
+    leds[i] = CRGB::Purple;
+  }
+
+  for(int timesPlayed = 0; timesPlayed < 80; timesPlayed++){
+    //make the leds go down the strip
+    for(int i = 0; i < 79; i++){
+      leds[i].r = leds[i+1].r;
+      leds[i].g = leds[i+1].g;
+      leds[i].b = leds[i+1].b;
+    }
+    leds[79].r = leds[0].r;
+    leds[79].g = leds[0].g;
+    leds[79].b = leds[0].b;
+
 //    for(int i = 39; i >= 21; i--){
 //      leds[i].r = leds[i-1].r;
 //      leds[i].g = leds[i-1].g;
@@ -633,22 +682,24 @@
 //    leds[60].r = leds[79].r;
 //    leds[60].g = leds[79].g;
 //    leds[60].b = leds[79].b;
-//    FastLED.show();
-//    delay(50);
-//  }
-//}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+    FastLED.show();
+    delay(30);
+  }
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+


Update OTA password infromation

Update OTA password infromation

--- bruh_mqtt_multisensor_github/bruh_mqtt_multisensor_github.ino
+++ bruh_mqtt_multisensor_github/bruh_mqtt_multisensor_github.ino
@@ -20,7 +20,7 @@
       - PubSubClient
       - ArduinoJSON

-	Update by Knutella 5-16-2017 Fixed MQTT disconnects when wifi drops by moving around Reconnect and adding a software reset of MCU
+  UPDATE 16 MAY 2017 by Knutella - Fixed MQTT disconnects when wifi drops by moving around Reconnect and adding a software reset of MCU

   UPDATE 23 MAY 2017 - The MQTT_MAX_PACKET_SIZE parameter may not be setting appropriately do to a bug in the PubSub library. If the MQTT messages are not being transmitted as expected please you may need to change the MQTT_MAX_PACKET_SIZE parameter in "PubSubClient.h" directly.

@@ -59,7 +59,7 @@

 /**************************** FOR OTA **************************************************/
 #define SENSORNAME "sensornode1"
-#define OTApassword "bruh"
+#define OTApassword "YouPassword" // change this to whatever password you want to use when you upload OTA
 int OTAport = 8266;


fixed typo

fixed typo

--- VernierAnalogSensorThreshold/VernierAnalogSensorThreshold.ino
+++ VernierAnalogSensorThreshold/VernierAnalogSensorThreshold.ino
@@ -31,7 +31,7 @@
   Serial.println("Data Set");
   Serial.print("Time");//long name
   Serial.print("\t"); //tab character
-  Serial.println ("Force"); //long nanme, change to match sensor
+  Serial.println ("Force"); //long name, change to match sensor
   Serial.print ("t"); //short name
   Serial.print("\t"); //tab character
   Serial.println("F");//short name, change to match sensor


Added raw result output to help with calibration

--- ardesp/waterelf_Spiffs_test/waterelf_Spiffs_test.ino
+++ ardesp/waterelf_Spiffs_test/waterelf_Spiffs_test.ino
@@ -786,6 +786,8 @@
   adc_low = Wire.read();       // ...them
   // now assemble them, remembering byte maths; a Union works well here too
   adc_result = (adc_high * 256) + adc_low;
+  Serial.print("Raw result: ");
+  Serial.println(adc_result);
   // we have a our Raw pH reading from the ADC; now figure out what the pH is
   float miliVolts = (((float)adc_result/4096)*vRef)*1000;
   float temp = ((((vRef*(float)pH7Cal)/4096)*1000)- miliVolts)/opampGain;


cleanup

cleanup


Added Neopixel Library

Added Neopixel Library

Added Neopixel Library
Changed Motor type and pin out
Added Serial.swap() but probably need to test this

--- FH_Tbot.ino
+++ FH_Tbot.ino
@@ -9,6 +9,10 @@
 #include <Ticker.h>
 #include "MotorController.h"
 #include "US100Ping.h"
+#include <Adafruit_NeoPixel.h>
+#ifdef __AVR__
+  #include <avr/power.h>
+#endif

 // WebPage
 #include "WebPage.h"
@@ -17,6 +21,23 @@
    #include "user_interface.h"
  }

+//////////////////////
+// RGB LEDs //
+//////////////////////
+// Parameter 1 = number of pixels in strip
+// Parameter 2 = Arduino pin number (most are valid)
+// Parameter 3 = pixel type flags, add together as needed:
+//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
+//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
+//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
+//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
+//   NEO_RGBW    Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
+#define PIN 3
+#define NUMPIXELS      6
+Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
+int delayval = 500; // delay for half a second
+
+

 //////////////////////
 // WiFi Definitions //
@@ -31,24 +52,24 @@
 /////////////////////
 // Pin Definitions //
 /////////////////////
+
+// stepper without PWM/speed input pins, don't use D0
+const int motorLeftA  = D5;
+const int motorLeftB  = D6;
+const int motorRightA = D2;
+const int motorRightB = D1;
+
+motorController motors(motorLeftA,motorLeftB,motorRightA,motorRightB);
+
 /*
-// stepper without PWM/speed input pins, don't use D0
-const int motorLeftA  = D2;
-const int motorLeftB  = D3;
-const int motorRightA = D4;
-const int motorRightB = D5;
-
-motorController motors(motorLeftA,motorLeftB,motorRightA,motorRightB);
+// stepper with direction and speed pins, don't use D0 for speed
+const int motorLeftDir  = D2;
+const int motorLeftSpd  = D1;
+const int motorRightDir = D5;
+const int motorRightSpd = D6;
+
+motorController motors(motorLeftDir,D5,motorLeftSpd,motorRightDir,D4,motorRightSpd);
 */
-
-// stepper with direction and speed pins, don't use D0 for speed
-const int motorLeftDir  = D3;
-const int motorLeftSpd  = D2;
-const int motorRightDir = D7;
-const int motorRightSpd = D8;
-
-motorController motors(motorLeftDir,D5,motorLeftSpd,motorRightDir,D4,motorRightSpd);
-
 /*
 // stepper with 2 motor pins and a enable pin per motor, don't use D0 for speed
 const int motorLeftA    =  D1;
@@ -85,7 +106,7 @@
   else
   {
     Stop();
-                                        // Serial.println("Connection lost STOP!!!!!!");
+    // Serial.println("Connection lost STOP!!!!!!");
   }
 }

@@ -97,10 +118,26 @@
   HeartBeatTicker.attach_ms(500, CheckHeartBeat);
   Stop();
   //motors.setTrim(1.0,1.0);            // this setting is optional, it compensates for speed difference of motors eg (0.95,1.0), and it can reduce maximum speed of both eg (0.75,0.75);
-  motors.setSteeringSensitivity(0.25);  // this setting is optional
+  //motors.setSteeringSensitivity(0.5);  // this setting is optional
   motors.setPWMFrequency(50);           // this setting is optional, depending on power supply and H-Bridge this option will alter motor noise and torque.
-  motors.setMinimumSpeed(0.05);         // this setting is optional, default is 0.1(10%) to prevent motor from stalling at low speed
-}
+  //motors.setMinimumSpeed(0.25);         // this setting is optional, default is 0.1(10%) to prevent motor from stalling at low speed
+
+  pixels.begin();
+  pixels.show(); // Initialize all pixels to 'off'
+     //////////////////////////
+ for(int i=0;i<NUMPIXELS;i++){
+
+    // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
+    pixels.setPixelColor(i, pixels.Color(0,150,0)); // Moderately bright green color.
+
+    pixels.show(); // This sends the updated pixel color to the hardware.
+
+    delay(delayval); // Delay for a period of time (in milliseconds).
+
+  }
+  /////////////////////////////////////////////
+
+  }

 void loop()
 {
@@ -126,6 +163,7 @@
   {
     return;
   }
+
   // Read the first line of the request
   String req = client.readStringUntil('\r');
   //Serial.println(req);
@@ -194,11 +232,12 @@

 void initHardware()
 {
-  Serial.begin(9600);
+  Serial.begin(115200);
   delay(100);
   Serial.println(F("\r\n"));
   Serial.println(F("            FH@Tbot Serial Connected\r\n"));
   Serial.println(F("  Type \"FHTbot.com\" into your browser to connect. \r\n"));
-  //ping.begin(D6,D7,9600);
+  Serial.swap();
+  //ping.begin(D7,D8,9600);
   ping.begin(Serial);
 }


All with Gamma-correction

All with Gamma-correction

--- Goggles.ino
+++ Goggles.ino
@@ -66,12 +66,12 @@
   changeMode = true;
 }

-void juggle(uint32_t colour) {
+void juggle(int colour[]) {
   for(int i = 0; i < 1; i++) {
     rollLeft(colour);
     rollRight(colour);
   }
-/*  for(int i = 0; i < 2; i++) {
+  for(int i = 0; i < 2; i++) {
     rollLeft(colour);
   }
   for(int i = 0; i < 1; i++) {
@@ -80,10 +80,10 @@
   }
   for(int i = 0; i < 2; i++) {
     rollRight(colour);
-  }*/
+  }
 }

-void rollRight(uint32_t colour) {
+void rollRight(int colour[]) {
   for(int i = RIGHT_NOSE; i < PIXELS + RIGHT_NOSE; i++) {
     lightOne(i % PIXELS, 0, colour);
     delay(DELAY);
@@ -92,7 +92,7 @@
   blankAll();
 }

-void rollLeft(uint32_t colour) {
+void rollLeft(int colour[]) {
   for(int i = LEFT_NOSE + PIXELS; i > LEFT_NOSE; i--) {
     lightOne(i % PIXELS, PIXELS, colour);
     delay(DELAY);
@@ -101,15 +101,14 @@
   blankAll();
 }

-void lightOne(int index, int offset, uint32_t colour) {
+void lightOne(int index, int offset, int colour[]) {
   for(int i = offset; i < PIXELS + offset; i++) {
-    uint32_t c = 0;
     pixels.setPixelColor(i, 0);
     if(i == index + offset) {
       pixels.setPixelColor(i,
-                           pgm_read_byte(&gamma8[255]),
-                           pgm_read_byte(&gamma8[127]),
-                           pgm_read_byte(&gamma8[0]));
+                           pgm_read_byte(&gamma8[colour[0]]),
+                           pgm_read_byte(&gamma8[colour[1]]),
+                           pgm_read_byte(&gamma8[colour[2]]));
     }
   }
   pixels.show();


Memory organised

Memory organised

--- Sources/Shrimp/Shrimp.ino
+++ Sources/Shrimp/Shrimp.ino
@@ -24,13 +24,15 @@

 // Variables to use for the interval
 unsigned long previousMillis = 0;
-unsigned long logDelay;                           // Log delay in milliseconds
-long logInterval = 0;                            // Log interval in milliseconds
+unsigned long previousLogMillis = 0;
+unsigned long logDelay = 0;                       // Log delay in milliseconds
+int logInterval = 0;                             // Log interval in milliseconds

 // Variables
 dht11 DHT11;
 EDB db(&writer, &reader);
 long travelTime; // Total travel time in s
+boolean travelTimeSet = false;
 int maxLogs = 252;
 String msg;
 boolean logData = false;
@@ -54,9 +56,56 @@
     return EEPROM.read(address);
 }

+void EEPROMWritelong(int address, long value) {
+      //Decomposition from a long to 4 bytes by using bitshift.
+      //One = Most significant -> Four = Least significant byte
+      byte four = (value & 0xFF);
+      byte three = ((value >> 8) & 0xFF);
+      byte two = ((value >> 16) & 0xFF);
+      byte one = ((value >> 24) & 0xFF);
+
+      //Write the 4 bytes into the eeprom memory.
+      EEPROM.write(address, four);
+      EEPROM.write(address + 1, three);
+      EEPROM.write(address + 2, two);
+      EEPROM.write(address + 3, one);
+}
+
+long EEPROMReadlong(long address) {
+      //Read the 4 bytes from the eeprom memory.
+      long four = EEPROM.read(address);
+      long three = EEPROM.read(address + 1);
+      long two = EEPROM.read(address + 2);
+      long one = EEPROM.read(address + 3);
+
+      //Return the recomposed long by using bitshift.
+      return ((four << 0) & 0xFF) + ((three << 8) & 0xFFFF) + ((two << 16) & 0xFFFFFF) + ((one << 24) & 0xFFFFFFFF);
+}
+
+//This function will write a 2 byte integer to the eeprom at the specified address and address + 1
+void EEPROMWriteInt(int address, int value) {
+     byte lowByte = ((value >> 0) & 0xFF);
+     byte highByte = ((value >> 8) & 0xFF);
+
+     EEPROM.write(address, lowByte);
+     EEPROM.write(address + 1, highByte);
+}
+
+//This function will read a 2 byte integer from the eeprom at the specified address and address + 1
+unsigned int EEPROMReadInt(int address) {
+     byte lowByte = EEPROM.read(address);
+     byte highByte = EEPROM.read(address + 1);
+
+     return ((lowByte << 0) & 0xFF) + ((highByte << 8) & 0xFF00);
+}
+
 void setup() {
-    if (EEPROM.read(0)) logInterval = (long) EEPROM.read(0);
-    if (EEPROM.read(1)) logData = (boolean) EEPROM.read(1);
+    if (EEPROMReadInt(0)) logInterval = (int) EEPROMReadInt(0);
+    if (EEPROM.read(2)) logData = (boolean) EEPROM.read(2);
+    if (EEPROMReadlong(3)) previousLogMillis = (long) EEPROMReadlong(3);
+    if (EEPROM.read(7)) travelTimeSet = (boolean) EEPROM.read(7);
+    if (EEPROMReadInt(8)) logDelay = (int) EEPROMReadInt(8);
+    if (EEPROMReadlong(10)) travelTime = (long) EEPROMReadlong(10);

     // Initialize pins
     pinMode(ledPin, OUTPUT);
@@ -67,7 +116,7 @@
     Serial.begin(9600);

     if (db.count()) db.open(db.count());
-    else db.create(3, TABLE_SIZE, sizeof(myrec));
+    else db.create(14, TABLE_SIZE, sizeof(myrec));
 }

 void loop() {
@@ -101,10 +150,14 @@

     unsigned long currentMillis = millis();

-    if(currentMillis - previousMillis >= logInterval * 1000 && logData) {
+    if (currentMillis - previousMillis >= logInterval * 1000 && logData) {
         previousMillis = currentMillis;

         readDHT11();
+    }
+
+    if (travelTimeSet && currentMillis - previousLogMillis >= logDelay) {
+        setLogInterval();
     }
 }

@@ -121,21 +174,30 @@

 void clearData() {
     db.clear();
+    for ( int i = 0 ; i < EEPROM.length() ; i++ ) EEPROM.write(i, 0);
 }

 void setTravelTime() {
     Serial.println("set travel time in sec");
     while (Serial.available() == 0) { }
-
     travelTime = Serial.parseInt();
-    setLogInterval();
+
+    while (Serial.available() ==0) { }
+    logDelay = Serial.parseInt();
+    previousLogMillis = millis();
+    travelTimeSet = true;
+
+    EEPROMWritelong(3, previousLogMillis);
+    EEPROM.write(7,travelTimeSet);
+    EEPROMWriteInt(8,logDelay);
+    EEPROMWritelong(10, travelTime);
 }

 void setLogInterval() {
     logInterval = travelTime / maxLogs;
     logData = true;
-    EEPROM.write(0,logInterval);
-    EEPROM.write(1,logData);
+    EEPROMWriteInt(0,logInterval);
+    EEPROM.write(2,logData);
 }

 void readDHT11() {


Final push for WWW

Final push for WWW

--- proj/hypercube/HCS/HCS.ino
+++ proj/hypercube/HCS/HCS.ino
@@ -202,7 +202,7 @@

   // Handle switching between outer shell animations. Don't do this if we're
   // already switching the inner shell though, don't want to figure that out
-  EVERY_N_SECONDS(2) {
+  EVERY_N_SECONDS(90) {
     oAnimCounter = (oAnimCounter + 1) % numAnimation;
     //if((oAnimCounter == 7 || oAnimCounter == 9) && oPaletteCounter == 5) {
     //  oAnimCounter++;
@@ -217,7 +217,7 @@

   // Same deal for the inner shell
   //
-  EVERY_N_SECONDS(1) {
+  EVERY_N_SECONDS(66) {
     iAnimCounter = (iAnimCounter + 1) % numAnimation;
     //if((iAnimCounter == 7 || iAnimCounter == 9) && iPaletteCounter == 5) {
     //  iAnimCounter++;
@@ -247,41 +247,41 @@

   // Add the random strobe to this list of animations since we aren't going to use it
   // for the overlays
-  //switch (iAnimCounter) {
-  //  case 0:
-  //    chase_straight(INNER, false);
-  //    break;
-  //  case 1:
-  //    shell_wrap(INNER, false, 0);
-  //    break;
-  //  case 2:
-  //    chase_mod(INNER, 0, false);
-  //    break;
-  //  case 3:
-  //    chase_spiral_static(INNER, 16, false);
-  //    break;
-  //  case 4:
-  //    shell_wrap(INNER, false, 1);
-  //    break;
-  //  case 5:
-  //    chase_mod(INNER, 1, false);
-  //    break;
-  //  case 6:
-  //    chase_spiral_mod(INNER, false);
-  //    break;
-  //  case 7:
-  //    shell_wrap(INNER, false, 2);
-  //    break;
-  //  case 8:
-  //    chase_mod(INNER, 2, false);
-  //    break;
-  //  case 9:
-  //    shell_wrap(INNER, false, 3);
-  //    break;
-  //  case 10:
-  //    fill_shell(INNER);
-  //    break;
-  //}
+  switch (iAnimCounter) {
+    case 0:
+      chase_straight(INNER, false);
+      break;
+    case 1:
+      shell_wrap(INNER, false, 0);
+      break;
+    case 2:
+      chase_mod(INNER, 0, false);
+      break;
+    case 3:
+      chase_spiral_static(INNER, 16, false);
+      break;
+    case 4:
+      shell_wrap(INNER, false, 1);
+      break;
+    case 5:
+      chase_mod(INNER, 1, false);
+      break;
+    case 6:
+      chase_spiral_mod(INNER, false);
+      break;
+    case 7:
+      shell_wrap(INNER, false, 2);
+      break;
+    case 8:
+      chase_mod(INNER, 2, false);
+      break;
+    case 9:
+      shell_wrap(INNER, false, 3);
+      break;
+    case 10:
+      fill_shell(INNER);
+      break;
+  }
   switch (oAnimCounter) {
     case 0:
       chase_straight(OUTER, true);


added instuctions: board manager & board selecting


Example: SerialControlledSDWriter: fix comments

--- examples/02-Utility/SerialControlledSDWriter/SerialControlledSDWriter.ino
+++ examples/02-Utility/SerialControlledSDWriter/SerialControlledSDWriter.ino
@@ -43,8 +43,8 @@
 AudioOutputI2S_F32            i2s_out(audio_settings);  //Digital audio output to the DAC.  Should always be last.

 //Connect to outputs
-AudioConnection_F32           patchcord1(i2s_in, 0, i2s_out, 0);    //Left mixer to left output
-AudioConnection_F32           patchcord2(i2s_in, 1, i2s_out, 1);    //Right mixer to right output
+AudioConnection_F32           patchcord1(i2s_in, 0, i2s_out, 0);    //Left input to left output
+AudioConnection_F32           patchcord2(i2s_in, 1, i2s_out, 1);    //Right input to right output

 //Connect to SD logging
 AudioConnection_F32           patchcord3(i2s_in, 0, audioSDWriter, 0);   //connect Raw audio to left channel of SD writer


Add code to configure trex to shutdown motors if no commands sent for timeout (#37)

--- Arduino/victoria_teensy_ros_node/victoria_teensy_ros_node.ino
+++ Arduino/victoria_teensy_ros_node/victoria_teensy_ros_node.ino
@@ -53,6 +53,11 @@
 HardwareSerial trex = HardwareSerial();
 bool trex_err;

+// Timeout, in seconds, for commands to the
+// motor controller, after which the motors
+// will stop until the next command is sent.
+double motor_controller_cmd_timeout;
+
 // Last motor speed set on motors.
 double motor_left_speed;
 double motor_right_speed;
@@ -166,7 +171,10 @@
     ros_param_helper.getParam("publish_teensy_debug_info_freq_hz", 1);

   cmd_vel_timeout_threshold =
-    ros_param_helper.getParam("cmd_vel_timeout_threshold", .5);
+    ros_param_helper.getParam("cmd_vel_timeout_threshold", 0.5);
+
+  motor_controller_cmd_timeout =
+    ros_param_helper.getParam("motor_controller_cmd_timeout", 0.5);

   ticks_per_radian =
     ros_param_helper.getParam("victoria_ticks_per_radian", 9072);
@@ -477,7 +485,17 @@

   // Start serial port to TRex
   trex.begin(19200);
-  return true;
+  while (!trex) { }
+
+  // Set serial timeout to motor_controller_cmd_timeout
+  trex.write(0xAF); // Set configuration parameter
+  trex.write(0x07); // Serial timeout parameter
+  byte timeout = max(127, motor_controller_cmd_timeout * 10);
+  trex.write(timeout); // timeout in 10ths of a second
+  trex.write(0x55); // constant format byte 1
+  trex.write(0x2A); // constant format byte 2
+  while (!trex.available()) {}
+  return (trex.read() == 0x00);
 }

 // Callback for blink


added compiling info to serial output

added compiling info to serial output

--- Firmware/Mutatio/Mutatio.ino
+++ Firmware/Mutatio/Mutatio.ino
@@ -49,6 +49,12 @@
   delay(200); //wait for power to stabilize
   Serial.begin(115200);
   memset(measurementdata, 0, sizeof(measurementdata));
+  Serial.print( F("Compiled: "));
+  Serial.print( F(__DATE__));
+  Serial.print( F(", "));
+  Serial.print( F(__TIME__));
+  Serial.print( F(", "));
+  Serial.println( F(__VERSION__));
   Serial.println(F("\r\nMutatio grid frequency tracker, part of netzsin.us project"));

   EEPROM.begin(256); //eeprom emulation on flash, the ESP8266 has no actual EERPOM
@@ -106,7 +112,7 @@
   attachInterrupt(MEASUREMENTPIN, pininterrupt, CHANGE); //trigger both rising and falling

-
+

   config.useDHCP = true;
@@ -135,8 +141,8 @@
       initOTAupdate();
       SDwriteLogfile("WIFI connected");

-     // plotly_init(true); //!!! comment this line if not using plotly server
-
+      // plotly_init(true); //!!! comment this line if not using plotly server
+
     }
     ArduinoOTA.handle();

@@ -185,8 +191,8 @@
         latestindex = i;
         measurementdata[i].flag |= 0x02; //data printed, can now be saved to SD
         printMeasurement(i);
-
-        if(sdWatchdog >0) //not using SD or SD failed
+
+        if (sdWatchdog > 0) //not using SD or SD failed
         {
           datareadindex = i; //update the read index (is usually done in SD function after saving the value)
         }
@@ -240,11 +246,11 @@
     if (measurementdata[latestindex].flag > 0 && (measurementdata[latestindex].flag & 0x08) == 0 && WiFi.status() == WL_CONNECTED && serverFailed == 0 && !config.sendAllData) //not yet sent and we have a wifi connection
     {
       //plotly_plot(measurementdata[latestindex]);
-
-        if (sendMeasurementToServer(measurementdata[latestindex]) == 0) //send successful?
-        {
+
+      if (sendMeasurementToServer(measurementdata[latestindex]) == 0) //send successful?
+      {
         measurementdata[latestindex].flag |= 0x08; //mark as sent out
-        }
+      }
     }

     issampling = true;


expand receive code and change 433MHz module

--- RF_ATtiny85_Lastenaufzug/RF_ATtiny85_Lastenaufzug.ino
+++ RF_ATtiny85_Lastenaufzug/RF_ATtiny85_Lastenaufzug.ino
@@ -108,7 +108,7 @@
   digitalWrite(S2, HIGH);
   digitalWrite(RO, HIGH); // Pin auf HIGH Setzen

-  RemoteReceiver::init(1, 0, 3, checkCode, 0); //RemoteReceiver::init(type, interrupt-pin, min-Repeats, callback-function, PulseWidth);
+  RemoteReceiver::init(0, 0, 3, checkCode, 0); //RemoteReceiver::init(type, interrupt-pin, min-Repeats, callback-function, PulseWidth);

   //only for tests
   /*
@@ -207,19 +207,19 @@
   getboolstates();
   */

-  if (receivedCode == 531272) {
+  if (receivedCode == 531272 || receivedCode == 531363) {
     task2 = millis();
     //Serial.println("Switch Relais 1 ON");
     SWRelais("ON");
     SecRelais1("ON");

-  } else if (receivedCode == 531380) {
+  } else if (receivedCode == 531380 || receivedCode == 531364) {
     //Serial.println("Switch Relais 2 ON");
     task2 = millis();
     SWRelais("ON");
     SecRelais2("ON");

-  } else if ( receivedCode == 531276 || receivedCode == 531436 || receivedCode == 531384) {
+  } else if ( receivedCode == 531276 || receivedCode == 531436 || receivedCode == 531384 || receivedCode == 531368) {
     //Serial.println("Switch Relais 1 and 2 OFF");
     SecRelais2("OFF");
     SecRelais1("OFF");


Fix comments

Fix comments

Header comment got loused up in the last commit

--- examples/test/test.ino
+++ examples/test/test.ino
@@ -1,10 +1,14 @@
 /***************************************************
-  This is a example sketch demonstrating bitmap drawing
-  capabilities of the SSD1351 library  for the 1.5"
-  16-bit Color OLED with SSD1351 driver chip
+  This is a example sketch demonstrating graphic drawing
+  capabilities of the SSD1351 library for the 1.5"
+  and 1.27" 16-bit Color OLEDs with SSD1351 driver chip

   Pick one up today in the adafruit shop!
   ------> http://www.adafruit.com/products/1431
+  ------> http://www.adafruit.com/products/1673
+
+  If you're using a 1.27" OLED, change SSD1351HEIGHT in Adafruit_SSD1351.h
+ 	to 96 instead of 128

   These displays use SPI to communicate, 4 or 5 pins are required to
   interface


upated PachubeClientString to fix interval bug

--- libraries/Ethernet/examples/PachubeClientString/PachubeClientString.ino
+++ libraries/Ethernet/examples/PachubeClientString/PachubeClientString.ino
@@ -45,7 +45,7 @@
 // initialize the library instance:
 EthernetClient client;

-long lastConnectionTime = 0;        // last time you connected to the server, in milliseconds
+unsigned long lastConnectionTime = 0;        // last time you connected to the server, in milliseconds
 boolean lastConnected = false;      // state of the connection last time through the main loop
 const unsigned long postingInterval = 10000;  //delay between updates to Pachube.com


Vref takes longer to settle

Vref takes longer to settle

--- Mk2/LoRa/LoRa_Garden_TX/LoRa_Garden_TX.ino
+++ Mk2/LoRa/LoRa_Garden_TX/LoRa_Garden_TX.ino
@@ -124,12 +124,10 @@
   digitalWrite(PIN_SENSOR_VCC, HIGH);

   tx_payload.setMsgId(++msg_id);
-
-  uint16_t vcc = readVcc();
-  tx_payload.setVcc(vcc);
   tx_payload.setCpuTemperature(readCpuTemperature());
-
-  // Read the temperature.
+  tx_payload.setVcc(readVcc());
+
+  // Read the external temperature.
   tx_payload.setTemperature(readTemperature());

   tx_payload.setChargeMa(readSolarCurrent());
@@ -243,7 +241,7 @@

   // put ADC back
   ADCSRA = old_ADCSRA;
-  ADCSRA |= _BV(ADEN);  // enable the ADC
+  //ADCSRA |= _BV(ADEN);  // enable the ADC

   //digitalWrite(LED_DEBUG, HIGH);

@@ -252,20 +250,17 @@
 /**
  * Read the internal voltage.
  */
-uint16_t readVcc()
-{
+uint16_t readVcc() {
   // Read 1.1V reference against AVcc
   // set the reference to Vcc and the measurement to the internal 1.1V reference
   ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
-
-  _delay_ms(2); // Wait for Vref to settle
+  ADCSRA |= _BV(ADEN);  // enable the ADC
+
+  _delay_ms(10); // Wait for Vref to settle
   ADCSRA |= _BV(ADSC); // Start conversion
   while (bit_is_set(ADCSRA,ADSC)); // measuring

-  uint8_t low  = ADCL; // must read ADCL first - it then locks ADCH
-  uint8_t high = ADCH; // unlocks both
-
-  uint16_t result = (high<<8) | low;
+  uint16_t result = ADCL | (ADCH << 8); // combine bytes

   result = 1125300L / result; // Calculate Vcc (in mV); 1125300 = 1.1*1023*1000
   return result; // Vcc in millivolts
@@ -276,22 +271,26 @@
   int avg = 0;
   double t;

+
   // The internal temperature has to be used
   // with the internal reference of 1.1V.
   // Set the internal reference and mux.
   ADMUX = (_BV(REFS1) | _BV(REFS0) | _BV(MUX3));
+  ADCSRA |= _BV(ADEN);  // enable the ADC
+  _delay_ms(10); // Wait for Vref to settle

   // Average a bit shiftable amount of readings.
   for (uint8_t i; i < 8; i++) {
     sum += readCpuTemperatureRaw();
   }
+
   avg = sum / 8;

   // subtract 273 for celsius
   // subtract the extra offest.
   // the 1.22 is a fixed coefficient k (http://www.atmel.com/Images/Atmel-8108-Calibration-of-the-AVR's-Internal-Temperature-Reference_ApplicationNote_AVR122.pdf)
   //@link https://playground.arduino.cc/Main/InternalTemperatureSensor
-  t = (avg - 333.5) / 1.22;
+  t = (avg - 324.5) / 1.22;

   // The returned temperature is in degrees Celsius.
   return round(t);
@@ -304,7 +303,7 @@
   // Detect end-of-conversion
   while (bit_is_set(ADCSRA,ADSC));

-  // Reading register "ADCW" takes care of how to read ADCL and ADCH.
+  // read ADCL and ADCH.
   return (ADCL | (ADCH << 8)); // combine bytes
 }


remove function which prints 1000 chars.  add 50 'U' chars to every OSCCAL printout.

--- CalibrateATtiny85OSCCAL.ino
+++ CalibrateATtiny85OSCCAL.ino
@@ -123,12 +123,8 @@
       printOSCCAL();
       break;

-    case '0':
-      printNx100Chars(10);
-      break;
-
     default:
-      ss.println(ch);
+      ss.print(ch);
       break;
   }
 }
@@ -136,15 +132,7 @@
 void printOSCCAL()
 {
   ss.print("OSCCAL: ");
-  ss.println(OSCCAL);
+  ss.print(OSCCAL);
+  ss.println(" UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU.");
 }

-void printNx100Chars(uint16_t n)
-{
-  for (uint16_t i=0; i<n; i++)
-  {
-    ss.print("********* ********* ********* ********* ********* ********* ********* ********* ********* *********!");
-  }
-  ss.println(n*100);
-}
-


Changed pins & sleep off for now

Changed pins & sleep off for now

--- tracker/tracker.ino
+++ tracker/tracker.ino
@@ -72,8 +72,8 @@
 #define PIN_TX 6          // PD6
 #define PIN_PERIF_POWER 7 // PD7

-#define PIN_LDR_LEFT  2 // PC2
-#define PIN_LDR_RIGHT 3 // PC3
+#define PIN_LDR_LEFT  0 // PC0
+#define PIN_LDR_RIGHT 1 // PC1
 #define THRESHOLD_LDR_HORZ 50
 #define MOVE_INTERVAL_MILLIS 60

@@ -176,13 +176,13 @@

         // Send a transmission
         char msg[16];
-        sprintf(msg, "%d,wd=%d,mv=%u", msgId, ledState, readVcc());
+        sprintf(msg, "%d,wd=%u,mv=%lu", msgId, light_level, readVcc());
         vw_send((uint8_t *)msg, strlen(msg));
         vw_wait_tx(); // Wait until the whole message is gone
         ++msgId;

         // Watchdog will wake us up in 8 seconds time.
-        goToSleep(SLEEP_FLAG_IDLE);
+        //goToSleep(SLEEP_FLAG_IDLE);
     }
 }


add suppot for robot control app

add suppot for robot control app

--- CS26410.ino
+++ CS26410.ino
@@ -1,33 +1,50 @@
+
+//included librarys
 #include <SharpIR.h>
 #include <NewPing.h>
 #include <Servo.h>

-#define LDRLeft A0
-#define LDRCenter A1
-#define LDRRight A2
-#define LDRTop A4
-#define SharpIr A3
+//analog pin definitions
+#define LDRLeft         A0
+#define LDRCenter       A1
+#define LDRRight        A2
+#define LDRTop          A4
+#define SharpIr         A3

-#define SerialRx 0
-#define SerialTx 1
-#define IrRx 2
-#define IrTx 3
-#define PB1 4
-#define Dright 5
-#define Dleft 6
-#define LEDRed 7
-#define Ping1 8
-#define Ping2 9
-#define Ping3 10
-#define Ping4 11
-#define SharpIrEnable 12
-#define turret 13
+//digital pin definitions
+#define SerialRx        0
+#define SerialTx        1
+#define IrRx            2
+#define IrTx            3
+#define PB1             4
+#define Dright          5
+#define Dleft           6
+#define LEDRed          7
+#define Ping1           8
+#define Ping2           9
+#define Ping3           10
+#define Ping4           11
+#define SharpIrEnable   12
+#define turret          13

-#define DrightStop 68
-#define DleftStop 83
-#define TurretCenter 84
+//calibration values
+#define DrightStop      68
+#define DleftStop       83
+#define TurretCenter    84

+//app control deffinition
+#define Forward         48
+#define Backward	49
+#define Turret_Left	50
+#define Turret_Right	51
+#define Pivot_Left	52
+#define Pivot_Right	53
+#define Stop	        54
+#define Function_1	55
+#define Function_2	56
+#define Function_3      57

+//object instantition
 Servo Driveleft;
 Servo Driveright;
 Servo Turret;
@@ -36,6 +53,46 @@
 NewPing sonar2(Ping2, Ping2, 200);
 NewPing sonar3(Ping3, Ping3, 200);
 NewPing sonar4(Ping4, Ping4, 200);
+
+void remote(int input) {
+  case(input) {
+      case Forward:
+          //move forward
+          break;
+      case Backwards:
+          //move backwards
+          break:
+      case Turret_Left:
+          //move turret left
+          break:
+      case Turret_Right:
+          //move Turret right
+          break;
+      case Pivot_Left:
+          //pivot robot left
+          break;
+      case Pivot_Right:
+          //pivot robot right
+          break:
+      case Stop:
+          //stop robot
+          break;
+      case Function_1:
+          //implement function 1
+          break:
+      case Function_2:
+          //implement function 2
+          break:
+      case Function_2:
+          //implement function 2
+          break:
+      default:
+          //stuff perhaps
+          break;
+  }
+
+
+

 void setup() {

@@ -67,3 +124,5 @@
 }

+
+


Created the subroutine that prints to the LCD

--- src/LCDPrint/LCDPrint.ino
+++ src/LCDPrint/LCDPrint.ino
@@ -57,3 +57,21 @@
     return "Error";
   }
 }
+
+void printToLCD(DeviceAddress address, String sensorName) {
+  String tempC = getTemp(address);
+
+  if(sensorName.length() == 3) { //ie name is red
+    lcd.clear();
+    lcd.print(topLine);
+    lcd.setCursor(0, 1);
+    lcd.print(sensorName + ":   " + tempC);
+  } else {
+    lcd.clear();
+    lcd.print(topLine);
+    lcd.setCursor(0, 1);
+    lcd.print(sensorName + ": " + tempC;
+  }
+
+}
+


Update ArrayOfLedArrays.ino

Update ArrayOfLedArrays.ino

Typo in comment, said four strips on three pins

--- examples/Multiple/ArrayOfLedArrays/ArrayOfLedArrays.ino
+++ examples/Multiple/ArrayOfLedArrays/ArrayOfLedArrays.ino
@@ -1,5 +1,5 @@
 // ArrayOfLedArrays - see https://github.com/FastLED/FastLED/wiki/Multiple-Controller-Examples for more info on
-// using multiple controllers.  In this example, we're going to set up four NEOPIXEL strips on three
+// using multiple controllers.  In this example, we're going to set up three NEOPIXEL strips on three
 // different pins, each strip getting its own CRGB array to be played with, only this time they're going
 // to be all parts of an array of arrays.


example: loop: return immediately if input string is not complete

--- examples/MAX1464-Arduino-library/MAX1464-Arduino-library.ino
+++ examples/MAX1464-Arduino-library/MAX1464-Arduino-library.ino
@@ -91,94 +91,95 @@
 }

 void loop() {
-    if (stringComplete) {
-        if(writingToFlash) {
-            if(String("!ABORTWRITEFLASHMEMORY!").equals(inputString)) {
+    if(!stringComplete)
+        return;
+
+    if(writingToFlash) {
+        if(String("!ABORTWRITEFLASHMEMORY!").equals(inputString)) {
+            writingToFlash = false;
+            Serial.println("\nAbort writing to flash memory...");
+        }
+        else if(!max1464.writeHexLineToFlashMemory(inputString)) {
+            Serial.print("\nIllegal line ");
+            Serial.println(inputString);
+        }
+        else {
+            Serial.print(".");
+            hexLinesWritten++;
+            if(hexLinesWritten>80) {
+                hexLinesWritten = 0;
+                Serial.println();
+            }
+            if(max1464.hasEOFBeenReached()) {
                 writingToFlash = false;
-                Serial.println("\nAbort writing to flash memory...");
-            }
-            else if(!max1464.writeHexLineToFlashMemory(inputString)) {
-                Serial.print("\nIllegal line ");
-                Serial.println(inputString);
-            }
-            else {
-                Serial.print(".");
-                hexLinesWritten++;
-                if(hexLinesWritten>80) {
-                    hexLinesWritten = 0;
-                    Serial.println();
-                }
-                if(max1464.hasEOFBeenReached()) {
-                    writingToFlash = false;
-                    Serial.println();
-                }
-            }
-            clearInputString();
-            return;
-        }
-
-        inputString.toUpperCase();
-        inputString = strtok((char *)inputString.c_str(), " ");
-
-        if(String("IDEN").startsWith(inputString)) {
-            printIden();
-        }
-        else if(String("RFW").startsWith(inputString)) {
-            char *partition_cp = strtok(NULL, " ");
-            uint8_t partition = 0;
-            if(partition_cp != NULL) {
-                partition = atoi(partition_cp);
-            }
-            max1464.readFlashPartition((FLASH_PARTITION)partition);
-        }
-        else if(String("HALTCPU").startsWith(inputString)) {
-            Serial.println("Halting CPU");
-            max1464.haltCpu();
-        }
-        else if(String("RESETCPU").startsWith(inputString)) {
-            Serial.println("Resetting CPU");
-            max1464.resetCpu();
-        }
-        else if(String("RP").startsWith(inputString)) {
-            char *port_cp = strtok(NULL, " ");
-            if(port_cp != NULL) {
-                uint8_t port = atoi(port_cp);
-                Serial.print("CPU port ");
-                Serial.print(port_cp);
-                Serial.print(" == ");
-                uint16_t value = max1464.readCpuPort((CPU_PORT)port);
-                Serial.print(value, HEX);
                 Serial.println();
             }
         }
-        else if(String("STEP").startsWith(inputString)) {
-            Serial.println("stepping");
-            max1464.singleStepCpu();
+        clearInputString();
+        return;
+    }
+
+    inputString.toUpperCase();
+    inputString = strtok((char *)inputString.c_str(), " ");
+
+    if(String("IDEN").startsWith(inputString)) {
+        printIden();
+    }
+    else if(String("RFW").startsWith(inputString)) {
+        char *partition_cp = strtok(NULL, " ");
+        uint8_t partition = 0;
+        if(partition_cp != NULL) {
+            partition = atoi(partition_cp);
         }
-        else if(String("RELEASECPU").startsWith(inputString)) {
-            Serial.println("Releasing CPU");
-            max1464.releaseCpu();
+        max1464.readFlashPartition((FLASH_PARTITION)partition);
+    }
+    else if(String("HALTCPU").startsWith(inputString)) {
+        Serial.println("Halting CPU");
+        max1464.haltCpu();
+    }
+    else if(String("RESETCPU").startsWith(inputString)) {
+        Serial.println("Resetting CPU");
+        max1464.resetCpu();
+    }
+    else if(String("RP").startsWith(inputString)) {
+        char *port_cp = strtok(NULL, " ");
+        if(port_cp != NULL) {
+            uint8_t port = atoi(port_cp);
+            Serial.print("CPU port ");
+            Serial.print(port_cp);
+            Serial.print(" == ");
+            uint16_t value = max1464.readCpuPort((CPU_PORT)port);
+            Serial.print(value, HEX);
+            Serial.println();
         }
-        else if(String("!ERASEFLASHMEMORY!").equals(inputString)) {
-            Serial.println("Erasing FLASH memory");
-            max1464.eraseFlashMemory();
+    }
+    else if(String("STEP").startsWith(inputString)) {
+        Serial.println("stepping");
+        max1464.singleStepCpu();
+    }
+    else if(String("RELEASECPU").startsWith(inputString)) {
+        Serial.println("Releasing CPU");
+        max1464.releaseCpu();
+    }
+    else if(String("!ERASEFLASHMEMORY!").equals(inputString)) {
+        Serial.println("Erasing FLASH memory");
+        max1464.eraseFlashMemory();
+    }
+    else if(String("!WRITEFLASHMEMORY!").equals(inputString)) {
+        char *partition_cp = strtok(NULL, " ");
+        uint8_t partition = 0;
+        if(partition_cp != NULL) {
+            partition = atoi(partition_cp);
         }
-        else if(String("!WRITEFLASHMEMORY!").equals(inputString)) {
-            char *partition_cp = strtok(NULL, " ");
-            uint8_t partition = 0;
-            if(partition_cp != NULL) {
-                partition = atoi(partition_cp);
-            }
-            writingToFlash = true;
-            hexLinesWritten = 0;
-            max1464.beginWritingToFlashPartition((FLASH_PARTITION)partition);
-            Serial.println("Writing to flash memory...");
-        }
-        else {
-            Serial.print("Unknown input string: ");
-            Serial.println(inputString);
-        }
+        writingToFlash = true;
+        hexLinesWritten = 0;
+        max1464.beginWritingToFlashPartition((FLASH_PARTITION)partition);
+        Serial.println("Writing to flash memory...");
+    }
+    else {
+        Serial.print("Unknown input string: ");
+        Serial.println(inputString);
+    }

-        clearInputString();
-    }
+    clearInputString();
 }


Delete _4-20mA_Data_Logger_init.ino

Delete _4-20mA_Data_Logger_init.ino

--- _4-20mA_Data_Logger_init.ino
+++ _4-20mA_Data_Logger_init.ino
@@ -1,503 +0,0 @@
-
-
-
-
-
-
-
-/*
-4-20mA Data Logger initialization program
-Run this once in order to save space
-*/
-//Includes
-
-  #include <Time.h>
-  #include <ADS1115_lite.h>
-  #include <SPI.h>
-  #include <SD.h>
-  #include <RtcDateTime.h>
-  #include <RtcDS3231.h>
-  #include <EEPROM.h>
-
-  String line = "==================================================================";
-  int numFailure;
-  //ADS1115 class definitions
-    ADS1115_lite adc0(ADS1115_DEFAULT_ADDRESS);
-    ADS1115_lite adc1(ADS1115_ADDRESS_ADDR_VDD);
-
-  //Serial Read tags - delete if not doing Serial Reads, Also delete fucntions SerialMonitor and SerialEvent
-    #define SERIAL_BUFFER_SIZE 20
-    String sSerialBuffer; //Create a global string that is added to character by character to create a final serial read
-    String sLastSerialLine; //Create a global string that is the Last full Serial line read in from sSerialBuffer
-
-  //RTC class definition
-    RtcDS3231 RTC;
-
-  //SDCard
-    String DataFolderLocation = "Data";
-    String DataFileLocation = DataFolderLocation + "/Data0.CSV";
-    unsigned long DataMaxFileSize = 10000000; //Maximum file size in bytes,
-    int DataFileNumber; //Create a int that will reference the Data file number on the SD card e.g.: 4 would work on the file on : SDCARD/Data/Data4.CSV
-
-
-  struct ADCChan{
-    uint16_t Raw;
-    float Calib; //Calibration factor to multiply things by
-    float ActualLo; //Low value for EngUnits scaling
-    float ActualHi;//Low value for EngUnits scaling
-    float Current; //Current scaled engineering units from ActualLo and Actual Hi.  This is compared against Actual and Deadband to determine when to update Actual
-    float Actual; //scaled engineering units from ActualLo and Actual Hi
-    float Deadband; //Swinging door deadband to determine how often to save values
-    float mA; //Swinging door deadband to determine how often to save values
-  };
-  struct ADCChan Ch0;
-  struct ADCChan Ch1;
-  struct ADCChan Ch2;
-  struct ADCChan Ch3;
-  float DeadbandRange = 500.0; //divide this number into the range to initialize deadband (ActualHi - ActualLo) / Deadband Range).  Suggested value 500-1000
-
-  File file;
-  String FileName;
-
-//SETUPSETUPSETUPSETUPSETUPSETUPSETUPSETUPSETUPSETUPSETUPSETUP
-void setup() {
-
-  //Setup Serial
-    //In case the user uses the default setting in Arduino, give them a message to change BAUD rate
-      Serial.begin(9600);
-      Serial.println(F("Set Serial baud rate to 250000"));
-      Serial.flush ();   // wait for send buffer to empty
-      delay (2);    // let last character be sent
-      Serial.end ();      // close serial
-      Serial.begin(250000);
-      Serial.println("");
-
-  //Set serial read buffer size to reserve the space to concatnate all bytes recieved over serial
-    sSerialBuffer.reserve(SERIAL_BUFFER_SIZE);
-
-
-    DrawLine(); //==================================================================
-
-
-  //I2C start
-    Wire.begin();
-
-
-    Serial.print(F("Configuring ADC0:"));
-    adc0.setGain(ADS1115_REG_CONFIG_PGA_0_256V);
-    adc0.setSampleRate(ADS1115_REG_CONFIG_DR_8SPS);
-    adc0.setMux(ADS1115_REG_CONFIG_MUX_DIFF_0_1);
-    if (!adc0.testConnection()) {
-        Serial.println(F("FAILURE!!!"));
-        numFailure++;
-    } else {
-        Serial.println(F("SUCCESS"));
-    }
-
-    Serial.print(F("Configuring ADC1:"));
-    adc1.setGain(ADS1115_REG_CONFIG_PGA_0_256V);
-    adc1.setSampleRate(ADS1115_REG_CONFIG_DR_8SPS);
-    adc1.setMux(ADS1115_REG_CONFIG_MUX_DIFF_0_1);
-    if (!adc1.testConnection()) {
-        Serial.println(F("FAILURE!!!"));
-        numFailure++;
-    } else {
-        Serial.println(F("SUCCESS"));
-    }
-
-
-    DrawLine(); //==================================================================
-    Serial.println(F("Configuring RTC"));
-
-  //RTC
-    RTC.Begin();
-    //Get the compiled time to determine if you should set the Date Time
-    RtcDateTime compiled = RtcDateTime(__DATE__, __TIME__);
-
-    Serial.print(F("Checking Connectivity:"));
-    if (!RTC.IsDateTimeValid()) {// Common Cuases: the battery on the device is low or even missing and the power line was disconnected
-        Serial.println(F("FAILURE!!!"));
-        numFailure++;
-    } else {
-        Serial.println(F("SUCCESS"));
-    }
-
-    //Set anncillary features on RTC
-        Serial.println(F("Enabling RTC, turning off 32Khz pin and square wave pin"));
-        if (!RTC.GetIsRunning()) {RTC.SetIsRunning(true);} // RTC was not actively running
-        RtcDateTime now = RTC.GetDateTime();
-        if (now < compiled) {RTC.SetDateTime(compiled);} //Update RTC with the compiled time
-        RTC.Enable32kHzPin(false);
-        RTC.SetSquareWavePin(DS3231SquareWavePin_ModeNone);
-
-    //print Date time
-    Serial.print(F("Current Date/Time, verify if correct: "));
-    Serial.println(getDateString());
-
-    DrawLine(); //==================================================================
-
-    Serial.print(F("Starting SD Card:"));
-  //SD Card initialization
-    if (!SD.begin(10)) {
-        Serial.println(F("FAILURE!!!"));
-        numFailure++;
-    } else {
-        Serial.println(F("SUCCESS"));
-        Serial.println(F("Creating menu files:"));
-        SDCreateMenuFiles();
-    }
-
-
-    DrawLine(); //==================================================================
-        Serial.print(F("Initialization complete: "));
-    if (numFailure==0) {
-        Serial.println(F("SUCCESS"));
-    } else {
-        Serial.println(F("MORE THAN ONE FAILURE"));
-    }
-    DrawLine(); //==================================================================
-    Serial.println(F("type (e)to write EEPROM.  This is not done automatically to prevent excess writing of the EEPROM"));
-    Serial.println(F("The Date/Time will now print forever..."));
-    Serial.println();
-
-
-}
-//SETUPSETUPSETUPSETUPSETUPSETUPSETUPSETUPSETUPSETUPSETUPSETUP
-
-
-
-
-
-
-
-
-//MAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOP
-//MAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOP
-void loop() {
-  delay(1000);
-
-  //Wait for Serial data to Update EEPROM
-
-      if (sLastSerialLine.equalsIgnoreCase("e")==true) {
-        //If anything comes over serial comm send EEPROM data
-          Serial.println();
-          DrawLine(); //==================================================================
-          Serial.println(F("Initializing EEPROM:"));
-          UpdateEEPROM();
-          DrawLine(); //==================================================================
-          Serial.println();
-        sLastSerialLine = ""; //Clear out buffer, This should ALWAYS be the last line in this if..then
-      }
-
-    Serial.print(F("Date and Time is currently: "));
-    Serial.println(getDateString());
-}
-//MAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOP
-//MAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOPMAINLOOP
-
-//==============================================================================================
-void EndProgram(String ErrorMessage ) {
-
-  //An unrecoverable error occured
-  //Loop forever and display the error message
-  while(1) {
-    Serial.print(F("Firmware encounted non-recoverable error: "));
-    Serial.println(ErrorMessage);
-    Serial.println(F("Cycle power to restart"));
-    delay(5000);
-  }
-}
-void DrawLine() {
-  //Menu line separator.
-    Serial.println(line);
-}
-
-//==============================================================================================
-String getDateString() {
-
-    RtcDateTime now = RTC.GetDateTime();
-    String CurrentDateString;
-    String stemp;
-    int temp;
-      CurrentDateString = now.Year();  CurrentDateString += "/";
-
-        stemp = now.Month();
-        temp = stemp.toInt();
-        if (temp < 10) {CurrentDateString += "0";}
-      CurrentDateString += stemp;  CurrentDateString += "/";
-
-        stemp = now.Day();
-        temp = stemp.toInt();
-        if (temp < 10) {CurrentDateString += "0";}
-      CurrentDateString += stemp;  CurrentDateString += " ";
-
-        stemp = now.Hour();
-        temp = stemp.toInt();
-        if (temp < 10) {CurrentDateString += "0";}
-      CurrentDateString += now.Hour();  CurrentDateString += ":";
-
-        stemp = now.Minute();
-        temp = stemp.toInt();
-        if (temp < 10) {CurrentDateString += "0";}
-      CurrentDateString += stemp;  CurrentDateString += ":";
-
-        stemp = now.Second();
-        temp = stemp.toInt();
-        if (temp < 10) {CurrentDateString += "0";}
-      CurrentDateString += stemp;
-
-    return CurrentDateString;
-}
-//=================================================================================================
-void SDCreateMenuFiles() {
-  //Make the menu directory
-    SD.mkdir("Menu");
-
-  //Make the Welcome Menu:
-   FileName = "Menu/_01_Wel.txt";
-    Serial.print(F("Creating/Overwriting File:"));
-    Serial.println(FileName);
-    SD.remove(FileName);
-    file = SD.open(FileName, FILE_WRITE);
-      file.println(line);
-      file.println(F("4Chan 4-20mA Data Logger"));
-      file.println("");
-      file.println(F("Send the text '?' for help (all commands must preceed a LF or CR character"));
-      file.println(line);
-    file.close();
-
-  //Make the Welcome Menu:
-    FileName = "Menu/_10_Main.txt";
-    Serial.print(F("Creating/Overwriting File:"));
-    Serial.println(FileName);
-    SD.remove(FileName);
-    file = SD.open(FileName, FILE_WRITE);
-
-      file.println(line);
-      file.println(F("MAIN MENU"));
-      file.println(F(""));
-      file.println(F("FUNCTIONAL DESCRIPTION:"));
-      file.println(F("\tRecords 4 channels of 4-20mA data to a CSV file on attached SD card if any channel changes more than than the channels programmed deadband (up or down)."));
-      file.println(F("\tThis is not an industrial appliance, please treat accordingly:.  There is no input protection; don't touch them.  Don't drop, etc."));
-      file.println(F("\tPowered by (2) 2100mAh 18650 batteries. ~47mA of power for ~85h/3d8h on battery power. Low battery indicator indicates ~5% charge or ~4h remaining"));
-      file.println(F("\tBatteries charge using any standard 5V mobile phone charger capable of at least 1.0A.  ~4h to charge to 80%, ~5h to charge to 100%. Turn off when not in use(obviously!)"));
-      file.println(F("\tDo not remove both batteries at once or battery protection circuit will latch off and require resetting"));
-      file.println(F("\tUnit always takes samples when powered on.  Powering the unit on is accomplished via the switch which applies battery power to the unit, or"));
-      file.println(F("\t   when computer is plugged into the USB data port.  Battery charging can occur when the unit is switched off."));
-      file.println(F("\t"));
-      file.println();
-      file.println(F("COMMANDS:"));
-      file.println(F("Note that all commands follow a CSV syntax: {letter} OR {letter},{number},...,{number}.  All commands are accessisible from all 'menus'"));
-      file.println(F("\t1. (c)onfig - channel config and calibration"));
-      file.println(F("\t2. (f)ile managemant and data - Prints data from storage device"));
-      file.println(F("\t3. (t)ime,(YYYY),(MM),(DD),(HH),(MM),(SS) - Update RTC (Real time clock): e.g. t,2017,3,5,00,12,30 to set time to March 5th, 2016 @ 00:12:30"));
-      file.println();
-      file.println(F("For additional information please contact Terry Myers m:215.262.4148"));
-      file.println(line);
-
-    file.close();
-
-  //Channel Config Screen 1of2
-    FileName = "Menu/_20_Cfg.txt";
-    Serial.print(F("Creating/Overwriting File:"));
-    Serial.println(FileName);
-    SD.remove(FileName);
-    file = SD.open(FileName, FILE_WRITE);
-
-      file.println(line);
-      file.println(F("CHANNEL CONFIGURATION"));
-      file.println(F(""));
-      file.println(F("Current Channel Configuration:"));
-      file.println(       F("\t\t\tEngUnits\tEngUnits\tEngUnits\tEngUnits\t\t\tCalibration"));
-      file.println(F("Ch\tRaw(mA)\t\tCurrent\t\tActual\t\tLow\t\tHigh\t\tDeadband\tFactor"));
-                     //1   4.0923  192.0029        0.0000   100.00000    1.0001
-    file.close();
-
-
-  //Channel Config Screen 2of2
-    FileName = "Menu/_21_Cfg.txt";
-    Serial.print(F("Creating/Overwriting File:"));
-    Serial.println(FileName);
-    SD.remove(FileName);
-    file = SD.open(FileName, FILE_WRITE);
-      file.println(F("COMMANDS:"));
-      file.println(F("\t1. (c)hannel onfig,(0-3)Channel,(Low), (High), (Deadband), (Calibration Factor) - configure a channel"));
-      file.println(F("\t\te.g. c,2,0,2200,1,1.002, configure channel 2 to have EngUnits from 0 to 2200, a deadband of 1.0, and a calibration factor of 1.002"));
-      file.println(F("\t2. (l)ive channel readouts.  Toggle on/off by typing (l)"));
-      file.println();
-
-
-      file.println(F("MEASUREMENT DESCRIPTION:"));
-      file.println(F("\tA 4-20mA signal is measured via a 10R shunt resistor with 16 bits of precision (~15 bits of noise free resolution) with a 0.2% accuracy between 23C-35C"));
-      file.println(F("\tScaling Schema for each channel:  0-25.6mA(Max) actual is 0-.256V across resistor is converted to: 0-32767 * Calibration Factor -> 0-25.6mA -> EngUnits Low - EngUnits High -> Current"));
-      file.println(F("\tAll Current values are compared with their Deadband.  If ANY channel changes more than the Deadband (up or down), the Current value is copied into the Actual value"));
-      file.println(F("\t   and a time stamped record is stored on the SD card for ALL channels in a CSV with the format: YYYY/MM/DD HH/MM/SS,Ch0.Actual,Ch1.Actual,Ch2.Actual,Ch3.Actual"));
-      file.println(F("\tSuggested Deadband value is 1/500 of the range.  e.g. Lo = 0, Hi = 250, deadband = (250 - 0)/500 = 0.5.  Recommend not more than 1/200 (not enough resolution)and not less than 1/1000 (into noise range)"));
-      file.println(F("\tMeasurements are taken on all channels about twice a second"));
-      file.println();
-
-      file.println(F("CALIBRATION:"));
-      file.println(F("\tCalibraton factor is applied to the raw signal to get Raw(mA) displayed and used by this device."));
-      file.println(F("\te.g. Current Calibration Factor = 1.01.  If the Raw(mA) displayed (measured by this device) = 4.100, but 4.000 is measured with an external accurate instrument(e.g. loop calibrator),"));
-      file.println(F("\t     then change Calibration Factor to 0.98537 = measured / displayed * Current Calibration Factor = 4.0 / 4.1 * 1.01"));
-      file.println(line);
-
-    file.close();
-
-
-
-  //File Management
-    FileName = "Menu/_30_File.txt";
-    Serial.print(F("Creating/Overwriting File:"));
-    Serial.println(FileName);
-    SD.remove(FileName);
-    file = SD.open(FileName, FILE_WRITE);
-
-      file.println(line);
-      file.println(F("FILE MANAGEMENT AND DATA"));
-      file.println();
-      file.println(F("COMMANDS:"));
-      file.println(F("\t1. (dir) - list directory information"));
-      file.println(F("\t2. (del),(File Number) - deletes the file.  e.g. del,3 deletes the file DATA3.CSV"));
-     // file.println(F("\t3. (deltree) - deletes all files without a confirmation"));
-      file.println(F("\t3. (s)et file number, (File Number) - sets the current working file: e.g. s,5 sets the device to start writing to file DATA5.CSV.  If full it would create a DATA6.CSV, etc."));
-      file.println(F("\t4. (p)rint file,(Number) - print the entire contents of the file to the Serial monitor. e.g. p,0 will print file DATA0.CSV"));
-      file.println(F("\t    Note that each 1MB (1,048,576bytes) takes ~53sec to print here."));
-      file.println(F("\t    You can also of course take the SD card out and put it into your computer directly for MUCH faster data transfer."));
-      file.println();
-      file.println(line);
-
-    file.close();
-
-
-}
-
-
-//==============================================================================================
-void serialEvent() {
-  while (Serial.available()) {
-
-    char inChar = (char)Serial.read();// get the new byte:
-
-    if (inChar == '\n' || inChar == '\r' ) {//if the incoming character is a LF or CR finish the string
-      sLastSerialLine = sSerialBuffer; //Transfer the entire string into the last serial line
-      sSerialBuffer = ""; // clear the string buffer to prepare it for more data:
-      break;
-    }
-
-    sSerialBuffer += inChar;// add it to the inputString:
-  }
-}
-
-//=================================================================================================
-void EEPROM_WriteString(int Address_Start, String s) {
-  //Write the length of the string to Address_Start, then write the characters of the string starting at Address_Start+1
-  //Note that this is a lite function with no error checking.  It should check to ensure you aren't going to go over the max size of the EEPROM
-  //a=Address
-  //s=String
-  EEPROM.write(Address_Start,s.length());
-  for (int i=1;i<=s.length()+1;i++) {
-      EEPROM.write(Address_Start+i,s[i]);
-    }
-}
-
-//=================================================================================================
-void EEPROM_PrintString(int Address_Start) {
-  //Pass in an address where the length of the string is stored.  Address_Start+1 starts the string
-  //Note that this is a lite function with no error checking.  It is assumed you are NOT going to go outside of the bounds of the EEPROM size
-    int l = EEPROM.read(Address_Start); //Get length
-    for (int i=1;i<=l;i++) {
-      Serial.print(char(EEPROM.read(i)));
-    }
-}
-//=================================================================================================
-void UpdateEEPROM() {
-
-  //Read the debug boolean and set the debug flag
-    int address = 2; //Temporary EEPROM address pointer
-    int DataFileNumber=0;
-    EEPROM.put(address,DataFileNumber); address++; //Set the first file to 0
-    address = 10; //Repoint EEPROM pointer
-    Ch0.Calib = 1.0; //initialize value
-    EEPROM.put(address,Ch0.Calib);
-    EEPROM.get(address,Ch0.Calib);
-    Serial.print(F("Ch0.Calib initialized to:")); Serial.println(Ch0.Calib,6); address = address + 4;
-    Ch0.ActualLo = 0.0; //initialize value
-    EEPROM.put(address,Ch0.ActualLo);
-    EEPROM.get(address,Ch0.ActualLo);
-    Serial.print(F("Ch0.ActualLo initialized to:")); Serial.println(Ch0.ActualLo,6); address = address + 4;
-    Ch0.ActualHi = 100.0; //initialize value
-    EEPROM.put(address,Ch0.ActualHi);
-    EEPROM.get(address,Ch0.ActualHi);
-    Serial.print(F("Ch0.ActualHi initialized to:")); Serial.println(Ch0.ActualHi,6); address = address + 4;
-    Ch0.Deadband = (Ch0.ActualHi - Ch0.ActualLo)/DeadbandRange; //initialize value
-    EEPROM.put(address,Ch0.Deadband);
-    EEPROM.get(address,Ch0.Deadband);
-    Serial.print(F("Ch0.Deadband initialized to:")); Serial.println(Ch0.Deadband,6); address = address + 4;
-
-
-
-    Ch1.Calib = 1.0; //initialize value
-    EEPROM.put(address,Ch1.Calib);
-    EEPROM.get(address,Ch1.Calib);
-    Serial.print(F("Ch1.Calib initialized to:")); Serial.println(Ch1.Calib,6); address = address + 4;
-    Ch1.ActualLo = 0.0; //initialize value
-    EEPROM.put(address,Ch1.ActualLo);
-    EEPROM.get(address,Ch1.ActualLo);
-    Serial.print(F("Ch1.ActualLo initialized to:")); Serial.println(Ch1.ActualLo,6);address = address + 4;
-    Ch1.ActualHi = 100.0; //initialize value
-    EEPROM.put(address,Ch1.ActualHi);
-    EEPROM.get(address,Ch1.ActualHi);
-    Serial.print(F("Ch1.ActualHi initialized to:")); Serial.println(Ch1.ActualHi,6);address = address + 4;
-    Ch1.Deadband = (Ch1.ActualHi - Ch1.ActualLo)/DeadbandRange; //initialize value
-    EEPROM.put(address,Ch1.Deadband);
-    EEPROM.get(address,Ch1.Deadband);
-    Serial.print(F("Ch1.Deadband initialized to:")); Serial.println(Ch1.Deadband,6); address = address + 4;
-
-
-    Ch2.Calib = 1.0; //initialize value
-    EEPROM.put(address,Ch2.Calib);
-    EEPROM.get(address,Ch2.Calib);
-    Serial.print(F("Ch2.Calib initialized to:")); Serial.println(Ch2.Calib,6);address = address + 4;
-    Ch2.ActualLo = 0.0; //initialize value
-    EEPROM.put(address,Ch2.ActualLo);
-    EEPROM.get(address,Ch2.ActualLo);
-    Serial.print(F("Ch2.ActualLo initialized to:")); Serial.println(Ch2.ActualLo,6);address = address + 4;
-    Ch2.ActualHi = 100.0; //initialize value
-    EEPROM.put(address,Ch2.ActualHi);
-    EEPROM.get(address,Ch2.ActualHi);
-    Serial.print(F("Ch2.ActualHi initialized to:")); Serial.println(Ch2.ActualHi,6);address = address + 4;
-    Ch2.Deadband = (Ch2.ActualHi - Ch2.ActualLo)/DeadbandRange; //initialize value
-    EEPROM.put(address,Ch2.Deadband);
-    EEPROM.get(address,Ch2.Deadband);
-    Serial.print(F("Ch2.Deadband initialized to:")); Serial.println(Ch2.Deadband,6); address = address + 4;
-
-
-    Ch3.Calib = 1.0; //initialize value
-    EEPROM.put(address,Ch3.Calib);
-    EEPROM.get(address,Ch3.Calib);
-    Serial.print(F("Ch3.Calib initialized to:")); Serial.println(Ch3.Calib,6);  address = address + 4;
-    Ch3.ActualLo = 0.0; //initialize value
-    EEPROM.put(address,Ch3.ActualLo);
-    EEPROM.get(address,Ch3.ActualLo);
-    Serial.print(F("Ch3.ActualLo initialized to:")); Serial.println(Ch3.ActualLo,6);  address = address + 4;
-    Ch3.ActualHi = 100.0; //initialize value
-    EEPROM.put(address,Ch3.ActualHi);
-    EEPROM.get(address,Ch3.ActualHi);
-    Serial.print(F("Ch3.ActualHi initialized to:")); Serial.println(Ch3.ActualHi,6);  address = address + 4;
-    Ch3.Deadband = (Ch3.ActualHi - Ch3.ActualLo)/DeadbandRange; //initialize value
-    EEPROM.put(address,Ch3.Deadband);
-    EEPROM.get(address,Ch3.Deadband);
-    Serial.print(F("Ch3.Deadband initialized to:")); Serial.println(Ch3.Deadband,6); address = address + 4;
-
-}
-
-void SerialPrintFile(String s) {
-    //Print an entire file to the Serial stream
-    file = SD.open(s);
-    while (file.available()) {
-      Serial.write(file.read());
-    }
-    file.close();
-}
-


Simplified definition of motors to avoid repeating the same declarations of labels etc.

--- ROVMain/ROVMain.ino
+++ ROVMain/ROVMain.ino
@@ -38,18 +38,17 @@
  * MOTOR DEFINITIONS.
  * =============================================================================
  */
-// Labels that will be used to identify the thrust and action commands for individual engines and actuators.
-const char* ENGINE_LABEL_1 = "motorPortHor"; // Port engine giving horizontal thrust.
-const char* ENGINE_LABEL_2 = "motorStbdHor"; // Starboard engine giving horizontal thrust.
-const char* ENGINE_LABEL_3 = "motorPortVer"; // Port engine giving vertical thrust.
-const char* ENGINE_LABEL_4 = "motorStbdVer"; // Starboard engine giving vertical thrust.
-
-// Motor instances.
-BrushlessDCMotor engine1, engine2, engine3, engine4; // Interfaces to the brushless motors.
-
-// Motor pin assignments.
-const int MOTOR_1_PIN = 9; // Pin to which the first motor is connected.
-const int RELAY_1_PIN = 8; // Relay that reverses the direction of this motor is attached to this pin.
+// These values correspond to the currently selected electronic speed controller (ESC) - Turningy EA-25a.
+#define MOTOR_ARM_PULSE_WIDTH 11000 // Pulse width in microseconds corresponding to zero throttle; used to arm the motors.
+#define MOTOR_MAX_PULSE_WIDTH 2200 // Maximum pulse width of the motor in microseconds.
+#define MOTOR_MIN_PULSE_WIDTH 800 // Minimum pulse width of the motor.
+#define THROTTLE_STEPS 100 // How many levels of throttle we want to have.
+
+// Pins are pairs of close-by pins with PWM and digital ones.
+BrushlessDCMotor engine1 = BrushlessDCMotor("motorPortHor", THROTTLE_STEPS, MOTOR_MAX_PULSE_WIDTH, MOTOR_MIN_PULSE_WIDTH, 9, 8);
+BrushlessDCMotor engine2 = BrushlessDCMotor("motorStbdHor", THROTTLE_STEPS, MOTOR_MAX_PULSE_WIDTH, MOTOR_MIN_PULSE_WIDTH, 6, 7);
+BrushlessDCMotor engine3 = BrushlessDCMotor("motorPortVer", THROTTLE_STEPS, MOTOR_MAX_PULSE_WIDTH, MOTOR_MIN_PULSE_WIDTH, 5, 4);
+BrushlessDCMotor engine4 = BrushlessDCMotor("motorStbdVer", THROTTLE_STEPS, MOTOR_MAX_PULSE_WIDTH, MOTOR_MIN_PULSE_WIDTH, 3, 2);

 /* =============================================================================
  * MISC ACTUATOR DEFINITIONS.
@@ -64,10 +63,8 @@
  * SENSOR DEFINITIONS.
  * =============================================================================
  */
-// Commands that will be sent to the Arduino to request data from sensors.
-const char* DEPTH_SENSOR_LABEL = "depthReading"; // Used to request data from the depth sensor.
-
-DepthSensor depthSensor;
+DepthSensor depthSensor = DepthSensor("depthReading",15); // For now a mock sensor.
+DepthSensor depthSensor2 = DepthSensor("depthReading2",16); // Another mock sensor to make sure the message concatenation works well.

 /* =============================================================================
  * TELECOMMAND PROTOCOL DEFINITION.
@@ -87,7 +84,7 @@
 const char DATA_DELIMITER[2] = ","; // Splits the command name and value. For some reason has to be size 2.

 Module* actuators[] = {&engine1, &engine2, &engine3, &engine4};
-Module* sensors[] = {&depthSensor};
+Module* sensors[] = {&depthSensor, &depthSensor2};

 /* =============================================================================
  * FUNCTIONS DEFINITIONS.
@@ -96,18 +93,20 @@
 void setup(void)
 /* Prepare to listen to commands over serial and start everything up. */
 {
-//TODO: do some system checks, like battery level, connections etc.
-
-//TODO: add more motors.
-	engine1 = BrushlessDCMotor(ENGINE_LABEL_1, 100, 2200, 800, MOTOR_1_PIN, RELAY_1_PIN); // These pule widths correspond to the currently selected electronic speed controller (ESC) - Turningy EA-
-	Serial.begin(engine1.serialBaudRate); // Start serial comms at the same baud rate as the engines.
+	//TODO: do some system checks, like battery level, connections etc.
+
+	// Start serial comms at the same baud rate as the engines.
+	Serial.begin(engine1.serialBaudRate);

-	engine1.setPulseWidth(1100); // Arm the motor by setting the control at zero throttle position.
-	delay(25000);
+	// Arm the motors by setting the control at zero throttle position.
+	engine1.setPulseWidth(MOTOR_ARM_PULSE_WIDTH);
+	engine2.setPulseWidth(MOTOR_ARM_PULSE_WIDTH);
+	engine3.setPulseWidth(MOTOR_ARM_PULSE_WIDTH);
+	engine4.setPulseWidth(MOTOR_ARM_PULSE_WIDTH);
+	delay(25000); // Keep the throttle in zero position for a while to arm the motors.
 	Serial.println("Armed the motors.");
-
-//TODO: initialise all the sensors etc.
-	depthSensor = DepthSensor("depthReading",15);
+
+	//TODO: do whatever else operations we want to do at start-up.

 	Serial.println("ROV listening to commands."); //TODO: could add VERSION, ROVMODEL etc. consts somewhere so we know what ROV we're using.
 }


Update timer_interrupt_dual_comp_registers.ino

--- interrupts/timer_interrupt_dual_comp_registers.ino
+++ interrupts/timer_interrupt_dual_comp_registers.ino
@@ -44,7 +44,7 @@
   TCCR1A = 0; // reset the Timer/Counter Control Register A for Timer 1
   TCCR1B = 0; // reset the Timer/Counter Control Register B for Timer 1

-  // enable 1/256 prescaling
+  // enable 1/1024 prescaling
   TCCR1B |= (1 << CS10);
   TCCR1B |= (1 << CS12);


Fix for MDNS reponder

Fix for MDNS reponder

https://github.com/toblum/McLighting/issues/85

--- Arduino/McLighting/McLighting.ino
+++ Arduino/McLighting/McLighting.ino
@@ -333,7 +333,8 @@
   // ***************************************************************************
   // Setup: MDNS responder
   // ***************************************************************************
-  MDNS.begin(HOSTNAME);
+  bool mdns_result = MDNS.begin(HOSTNAME);
+
   DBG_OUTPUT_PORT.print("Open http://");
   DBG_OUTPUT_PORT.print(WiFi.localIP());
   DBG_OUTPUT_PORT.println("/ to open McLighting.");
@@ -565,6 +566,11 @@
   });

   server.begin();
+
+  // Start MDNS service
+  if (mdns_result) {
+    MDNS.addService("http", "tcp", 80);
+  }

   #ifdef ENABLE_STATE_SAVE
     // Load state string from EEPROM


Comentarios en el código de arduino

Comentarios en el código de arduino

--- arduino/Alarma/Alarma.ino
+++ arduino/Alarma/Alarma.ino
@@ -116,7 +116,7 @@

 void checkSensors() {

-
+  //Comienzo el chequeo de cada uno de los sensores
   if (digitalRead(BEDROOM_3_WINDOW_SENSOR) == HIGH) {
     if (bedroom3Window) {
       bedroom3Window = false;
@@ -222,6 +222,9 @@

     }
   }
+  //Finalizo el chequeo de cada uno de los sensores
+
+  //Si la alarama se dispara aviso a la interfaz gráfica y ejecuto el método
   if (alarmTriggered) {
     Serial.println(ALARM_TRIGGERED_CODE_EVENT);
     alarmTriggered = false;
@@ -229,6 +232,8 @@
   }
 }

+//Este método es llamado cuando la alarma se dispara
+// y hace que las luces de la casa destellen con semiperiodo de 120ms durante 1 minuto
 void alarm() {
   long time = 0;
   while (time < 120) {


elf now pushes data to citsci.wegrow.social cloud server :-)

--- ardesp/waterelf/waterelf.ino
+++ ardesp/waterelf/waterelf.ino
@@ -29,7 +29,7 @@
 ESP8266WebServer webServer(80);
 String apSSIDStr = "WaterElf-" + String(ESP.getChipId());
 const char* apSSID = apSSIDStr.c_str();
-String svrAddr = ""; // address of a local server
+String svrAddr = ""; // address of a local server TODO delete?

 /////////////////////////////////////////////////////////////////////////////
 // page generation stuff ////////////////////////////////////////////////////
@@ -124,6 +124,7 @@
 #define monitorDBG false
 #define netDBG false
 #define miscDBG false
+#define citsciDBG true

 /////////////////////////////////////////////////////////////////////////////
 // temperature sensor stuff /////////////////////////////////////////////////
@@ -626,7 +627,7 @@
   String toSend = genServerConfForm();
   webServer.send(200, "text/html", toSend);
 }
-void handle_svrchz() {
+void handle_svrchz() { // TODO delete?
   dln(netDBG, "serving page at /svrchz");
   String toSend = pageTop;
   toSend += ": data sharing configured";
@@ -777,31 +778,57 @@
     dln(monitorDBG, "Found pH sensor");
   }
 }
+
+/*
+construct and post (via GET, to confuse you), sensor data like this:
+
+GET /collect/WaterElf-10865861 HTTP/1.1
+User-Agent: WaterElf/0.000001
+Host: citsci.wegrow.social:8000
+Accept: application/json
+Content-Type: application/json
+Content-Length: 146
+
+{ "timestamp": 39653, "airTemp": 25.90, "humidity": 49.40, "light": 8, "pH": 11.12, "waterLevel1": 257, "waterLevel2": 257, "waterLevel3": 257 }
+
+
+GET /collect/9999 HTTP/1.1
+User-Agent: curl/7.35.0
+Host: localhost:8000
+Accept: application/json
+Content-Type: application/json
+Content-Length: 92
+
+{"timestamp": 22200, "airTemp": 55, "humidity": 44, "lux": 1494, "pH": 6.4, "waterTemp": 14}
+*/
 void postSensorData(monitor_t *monitorData) {
-  //dln(monitorDBG, "\npostSensorData");
-
-  // create a JSON form
+  dln(citsciDBG, "\npostSensorData");
   String jsonBuf = "";
+  String citsciAddr = "citsci.wegrow.social";
   formatMonitorEntry(monitorData, &jsonBuf, true);
-  String envelope = "POST /fishydata HTTP/1.1\n";
-  envelope += "Content-Type: application/json\n";
+  String envelope =
+    "GET /collect/"; envelope += apSSIDStr; envelope += " HTTP/1.1\r\n";
+  envelope += "User-Agent: WaterElf/0.000001\r\n";
+  envelope += "Host: "; envelope += citsciAddr; envelope += ":8000\r\n";
+  envelope += "Accept: application/json\r\n";
+  envelope += "Content-Type: application/json\r\n";
   envelope += "Content-Length: " ;
-  envelope += jsonBuf.length();
-  envelope += "\nConnection: close\n\n";
+  envelope += jsonBuf.length() + 2; // + 2 for the cr/nls
+  envelope += "\r\n\r\n";
   envelope += jsonBuf;
-  //dln(monitorDBG, envelope);
+  dln(citsciDBG, envelope);

-  WiFiClient couchClient;
-  if(couchClient.connect(svrAddr.c_str(), 5984)) {
-    dbg(netDBG, svrAddr);
-    dln(monitorDBG, " - connected as couch server");
-    couchClient.print(envelope);
+  WiFiClient citsciClient;
+  if(citsciClient.connect(citsciAddr.c_str(), 8000)) {
+    dbg(netDBG, citsciAddr);
+    dln(citsciDBG, " - connected to citsci server");
+    citsciClient.print(envelope);
   } else {
-    dbg(netDBG, svrAddr);
-    dln(monitorDBG, " - no couch server");
-  }
-
-  dln(monitorDBG, "");
+    dbg(netDBG, citsciAddr);
+    dln(citsciDBG, " - no citsci server");
+  }
+
+  dln(citsciDBG, "");
   return;
 }
 void formatMonitorEntry(monitor_t *m, String* buf, bool JSON) {


Avoid double time sync and premature drift calculation

--- time.ino
+++ time.ino
@@ -27,6 +27,7 @@

 void set_time(time_t t) {
     next_sync_threshold = t + sync_interval;
+    update_time();
     if (time_has_been_set) {
         measured_time_drift += current_timestamp - t;
     } else {
@@ -38,6 +39,7 @@

 void set_time_requester(request_time_function_t requester) {
     time_requester = requester;
+    next_sync_threshold = current_timestamp + sync_interval;
     (*requester)();
 }


use debug() for most debug outputs - some cleanup, too

--- GeheimTuer.ino
+++ GeheimTuer.ino
@@ -107,12 +107,12 @@
     factor: 1,
     add: 1,
     minPWM: 0,
-    maxPWM: 25,
+    maxPWM: 255,
     startPWM: 0,
     useStartPWM: true, // first element always sets initial PWM value
     brake: false
   },
-  { // accelerate to full-ish speed and keep running
+  { // accelerate and keep running
     maxMillis: 2300,
     stepMillis: 5,
     factor: 1,
@@ -141,7 +141,7 @@
     add: -1,
     minPWM: 32,
     maxPWM: 64,
-    startPWM: 64,
+    startPWM: 0,
     useStartPWM: false,
     brake: false
   },
@@ -151,30 +151,6 @@
 };

 /*
-const struct accelProfile accelProfileHigh[] = {
-{ // slow start
-    maxMillis: 350,
-    stepMillis: 50,
-    factor: 1,
-    add: 5,
-    minPWM: 0,
-    maxPWM: 30,
-    startPWM: 0,
-    useStartPWM: true, // first element always sets initial PWM value
-    brake: false
-  },
-  { // accelerate to full-ish speed and keep running
-    maxMillis: 3000,
-    stepMillis: 50,
-    factor: 1.05,
-    add: 0,
-    minPWM: 0,
-    maxPWM: 180,
-    startPWM: 0,
-    useStartPWM: false,
-    brake: false
-  },
-/+
   { // coast
     maxMillis: 1000,
     stepMillis: 50,
@@ -197,33 +173,6 @@
     useStartPWM: true,
     brake: true
   },
-+/
-  { // slow down before end-stop
-    maxMillis: 1000,
-    stepMillis: 100,
-    factor: 0.9,
-    add: 0,
-    minPWM: 64,
-    maxPWM: 255,
-    startPWM: 0,
-    useStartPWM: false,
-    brake: false
-  },
-  { // seek end-stop
-    maxMillis: 5000,
-    stepMillis: 100,
-    factor: 1,
-    add: -1,
-    minPWM: 32,
-    maxPWM: 64,
-    startPWM: 64,
-    useStartPWM: true,
-    brake: false
-  },
-  {
-    maxMillis: 0
-  }
-};
 */

 const struct accelProfile *accelProfile; // pointer to current profile
@@ -343,7 +292,7 @@
     setLeds1(red, ledBlink);
   }

-// TODO: on-board status LEDs, independent of ws2812 stripe
+// TODO: on-board status LEDs, independent of ws2812
 digitalWrite(13, LOW);
 pinMode(13, OUTPUT);

@@ -366,7 +315,7 @@
   // assume that none of the following intervals overflow

 /*
-  Serial.print(F("Elapsed millis: "));
+  debug(currentMillis, F("Elapsed millis: "));
   Serial.println(elapsedMillis);
 */

@@ -386,16 +335,16 @@
   // The WAM's overheating!
   if ((motorDiagA == LOW || motorDiagB == LOW) && doorState != doorError) {
     motorFree();
-    Serial.print(currentMillis);
-    Serial.print(F(" Motor driver error condition - door disabled\r\n"));
+    debug(currentMillis, F("Motor driver error condition - door disabled\r\n"));
     setLeds1(red, ledFade);
     doorState = doorError;
   }
+

 // remote debugging aid
 // TODO: formalize the commands
 if (Serial.available()) {
-  switch (char c = Serial.read()) {
+  switch (Serial.read()) {
     case 'x':
         swTrigger = LOW; break;
     case 'X':
@@ -421,18 +370,18 @@
   }
 }

+
   switch(doorState) {
     case doorClosed:
       // wait until a button is pressed or the front switch opens
       if (swFront == HIGH || swTrigger == LOW) {
-        Serial.print(currentMillis);
         if (swFront == HIGH) {
           // maybe someone tried to pull the door open
           // TODO: or the door slams too fast into the end-stop and rebounds. align profile & inertial reality
-          Serial.print(F(" Front switch triggered - opening door\r\n"));
+          debug(currentMillis, F("Front switch triggered - opening door\r\n"));
           initDrive(backward, accelProfileLow);
         } else {
-          Serial.print(F(" Button switch triggered - opening door\r\n"));
+          debug(currentMillis, F("Button switch triggered - opening door\r\n"));
           initDrive(backward, accelProfileHigh);
 // TODO: think again. re-arming swTrigger disables deglitching
 // any short HIGH pulse resets swTrigger to LOW
@@ -446,8 +395,7 @@
     case doorOpen:
       // hold the door open if button pressed during openInterval
       if (swTrigger == LOW) {
-        Serial.print(currentMillis);
-        Serial.print(F(" Button switch triggered - door blocked\r\n"));
+        debug(currentMillis, F("Button switch triggered - door blocked\r\n"));
         motorFree();
         setLeds1(red, ledSolid);
         doorState = doorBlocked;
@@ -457,14 +405,13 @@

       openMillis += elapsedMillis;
       if (openMillis >= openInterval || swBack == HIGH) {
-        Serial.print(currentMillis);
         if (swBack == HIGH) {
-          // maybe someone tried to pull the door close
+          // maybe someone tried to pull the door closed
           // TODO: or the door slams too fast into the end-stop and rebounds. align profile & inertial reality
-          Serial.print(F(" Back switch triggered - closing door\r\n"));
+          debug(currentMillis, F("Back switch triggered - closing door\r\n"));
           initDrive(forward, accelProfileLow);
         } else {
-          Serial.print(F(" openInterval timeout - closing door\r\n"));
+          debug(currentMillis, F("openInterval timeout - closing door\r\n"));
           initDrive(forward, accelProfileHigh);
         }
         setLeds2(white, black, 3, ledForward);
@@ -476,9 +423,8 @@
       // are we there yet?
       if (swBack == LOW) {
         motorBrake();
-        Serial.print(currentMillis);
-        Serial.print(F(" Back switch triggered - door open\r\n"));
-        Serial.print(F("Total ms: "));
+        debug(currentMillis, F("Back switch triggered - door open\r\n"));
+        debug(currentMillis, F("Total ms: "));
         Serial.println(driveTotalMillis);
         openMillis = 0;
         setLeds1(green, ledFade);
@@ -490,9 +436,8 @@
     case doorClosing:
       if (doorState == doorClosing && swFront == LOW) {
         motorBrake();
-        Serial.print(currentMillis);
-        Serial.print(F(" Front switch triggered - door closed\r\n"));
-        Serial.print(F("Total ms: "));
+        debug(currentMillis, F("Front switch triggered - door closed\r\n"));
+        debug(currentMillis, F("Total ms: "));
         Serial.println(driveTotalMillis);
         setLeds1(green, ledFade);
         doorState = doorClosed;
@@ -502,16 +447,15 @@
       // stop if button pressed while in motion
       if (swTrigger == LOW) {
         motorFree(); // TODO: motorBrake() might be better for an emergency stop. doesn't make much different in our case, the belt skips and the door stops in both cases
-        Serial.print(currentMillis);
-        Serial.print(F(" Button switch triggered - door blocked\r\n"));
+        debug(currentMillis, F("Button switch triggered - door blocked\r\n"));
         setLeds1(red, ledSolid);
         doorState = doorBlocked;
 swTrigger = HIGH;
         break;
       }

+      driveTotalMillis += elapsedMillis;
       driveStepMillis += elapsedMillis;
-      driveTotalMillis += elapsedMillis;
       if (driveStepMillis >= accelProfile[accelProfileIdx].stepMillis) {
         driveMillis += driveStepMillis;
         driveStepMillis = 0;
@@ -523,9 +467,8 @@
           // end-stop not reached at end of profile, someone might be in the way
           if (accelProfile[++accelProfileIdx].maxMillis == 0) {
             motorFree();
-            Serial.print(currentMillis);
-            Serial.print(F(" End of profile - door blocked\r\n"));
-            Serial.print(F("Total ms: "));
+            debug(currentMillis, F("End of profile - door blocked\r\n"));
+            debug(currentMillis, F("Total ms: "));
             Serial.println(driveTotalMillis);
             setLeds1(red, ledBlink);
             doorState = doorBlocked;
@@ -549,8 +492,7 @@
             drivePWM = accelProfile[accelProfileIdx].startPWM;
           }

-          Serial.print(currentMillis);
-          Serial.print(F(" accelProfileIdx: "));
+          debug(currentMillis, F("accelProfileIdx: "));
           Serial.println(accelProfileIdx);
         }

@@ -558,8 +500,7 @@
         drivePWM = min(accelProfile[accelProfileIdx].maxPWM, max(accelProfile[accelProfileIdx].minPWM,
                         (drivePWM + accelProfile[accelProfileIdx].add) * accelProfile[accelProfileIdx].factor));

-        Serial.print(currentMillis);
-        Serial.print(F(" Drive PWM: "));
+        debug(currentMillis, F("Drive PWM: "));
         Serial.println(drivePWM);

         analogWrite(motorPWMPin, round(drivePWM*drivePWMscale));
@@ -569,16 +510,15 @@
     case doorBlocked:
       // wait until a button is pressed
       if (swTrigger == LOW) {
-        Serial.print(currentMillis);
         // close door only if end-stop is active
         if (swBack == LOW) {
-          Serial.print(F(" Button switch triggered - closing door\r\n"));
+          debug(currentMillis, F("Button switch triggered - closing door\r\n"));
 //          initDrive(forward, accelProfileLow);
           initDrive(forward, accelProfileHigh);
           ledMode = ledForward;
           doorState = doorClosing;
         } else {
-          Serial.print(F(" Button switch triggered - opening door\r\n"));
+          debug(currentMillis, F("Button switch triggered - opening door\r\n"));
           initDrive(backward, accelProfileLow);
           ledMode = ledBackward;
           doorState = doorOpening;
@@ -596,9 +536,10 @@
 if (motorDiagA == HIGH && motorDiagB == HIGH) {
   setLeds1(red, ledSolid);
   doorState = doorBlocked;
-digitalWrite(13, LOW);
-}
-digitalWrite(13, HIGH);
+  digitalWrite(13, LOW);
+} else {
+  digitalWrite(13, HIGH);
+}
       break;
   }

@@ -685,6 +626,13 @@
 }

 //__attribute__((always_inline))
+inline void debug(const unsigned long timestamp, const __FlashStringHelper *const string) {
+  Serial.print(timestamp);
+  Serial.write(' ');
+  Serial.print(string);
+}
+
+//__attribute__((always_inline))
 inline void debounce(const int swPin, bool *const swVal, uint16_t *const swDebounce) {
   // similiar to what digitalRead() does, assumes that swPin has no timer output assigned
   // this still leads to several indirect lookups per sample. direct PINx access might be faster
@@ -718,10 +666,6 @@
   switch(dir) {
     case forward:
       motorForward(); break;
-/*
-  digitalWrite(motorInAPin, LOW);
-  digitalWrite(motorInBPin, LOW);
-*/
     case backward:
       motorBackward(); break;
   }


bleeeh

bleeeh

--- LEDDisplay.ino
+++ LEDDisplay.ino
@@ -19,11 +19,10 @@

 // possible values for a pixel;
-#define BLACK  0
-#define GREEN  1
-#define RED    2
-#define ORANGE 3
-
+const int BLACK  =0;
+const int GREEN  =1;
+const int RED    =2;
+const int ORANGE =3;

 #define cls          ht1632_clear

@@ -208,6 +207,8 @@
   delay(1000);
 }

+// Not tested yet
+#define BIT_OVERRIDE(number,n,val) number & ~(1 << n) | (val << n);

 /*
    plot a point on the display, with the upper left hand corner
@@ -223,7 +224,7 @@
   if (color != BLACK && color != GREEN && color != RED && color != ORANGE)
     return;

-  byte nChip = 1 + x / 16 + (y > 7 ? 2 : 0) ;
+  byte nChip = 1 + x / 16 + (y >= 8 ? 2 : 0) ;
   x = x % 16;
   y = y % 8;
   byte addr = (x << 1) + (y >> 2);
@@ -756,26 +757,6 @@

 void loop ()
 {
-   // cls; // clear screen
-   // plot(x, y, color); put a certain pixel on (BLACK = OFF)
-   // plot_rect(x_left_upper, y_left_upper, x_right_down, y_right_down, color); // fill a rectangle
-   // vertical_bar(x_position, width, height); colored bard vertically (Orange - green - red)
-   // plot_char('A', x, y, color); // charachters should be uppercase! x, y = upper left corner; returns the width of the character plotted
-   // plot_int( number_to_display, x, y, number_of_chars, color); if to little space to display: drops higher numbers
-
-/*
-plot_char('8',0,0,GREEN);
-delay(2500);
-plot_char('8',0,0,BLACK);
-plot_char('6',0,0,GREEN);
-delay(2500);
-plot_char('6',0,0,BLACK);
-plot_char('9',0,0,GREEN);
-delay(2500);
-plot_char('9',0,0,BLACK);
-*/
-
-
   // read the input on analog pin 0:
   int sensorValue = analogRead(A0);
   // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
@@ -802,21 +783,5 @@
   plot_int(ufvoltage,0,0,2,BLACK);
   plot_int(voltage,13,0,2,BLACK);

-
-
-  /*
-  for(char c = '0'; c <= '9'; c ++){
-    plot_char(c, 0, 0, GREEN);
-    delay(250);
-    plot_char(c, 0, 0, BLACK);
-
-  }
-  */
-
-
-
-
-
-
-
-}
+}
+


Added button to state machine

Added button to state machine

--- Monitor.ino
+++ Monitor.ino
@@ -11,7 +11,7 @@
 /* Digital */
 #define BUTTON 2
 #define ONEWIRE 3
-
+#define RELAY 4

 /* Hardware SPI */
 #define SD_CLK SCK
@@ -58,7 +58,7 @@
 DC  | Green            | 9
 Rest| S-Green          | 7
 CS  | S-Brown          | 8
-NC  | S-Orange         | NC (button)
+Butt| S-Orange         | 2 (button)
 */

 /* Screen */
@@ -68,6 +68,9 @@
 float motorTempC;
 float sensorVoltOne;
 int sensorVoltOneI;
+
+boolean relayEnabled = false;
+int lastButtonState = LOW;

 // Used by the Fatal state
@@ -199,6 +202,39 @@
   addBarGraphDataPoint(sensorVoltOneI);
 }

+/* Only trigger on a state change to HIGH */
+boolean readButtonState() {
+  boolean result = false;
+  int buttonState = digitalRead(BUTTON);
+
+  if (HIGH == buttonState && LOW == lastButtonState) {
+    result = true;
+  }
+
+  lastButtonState = buttonState;
+
+  return result;
+}
+
+/* Change the relay enabled state */
+void changeRelayEnabledState(boolean newState) {
+  relayEnabled = newState;
+
+  if (relayEnabled) {
+    Serial.println(F("Relay enabled"));
+    digitalWrite(RELAY, HIGH);
+  } else {
+    Serial.println(F("Relay disabled"));
+    digitalWrite(RELAY, LOW);
+  }
+}
+
+/* Helper Function to toggle based on the state variable */
+void toggleRelayEnabledState() {
+  changeRelayEnabledState( !relayEnabled );
+}
+
+
 /* Show an error and stop */
 void showFatal(const char* buf){
   onscreenNoticeMessage[0] = '\0';
@@ -215,6 +251,7 @@
   Serial.println(onscreenNoticeMessage);
   changeState(STATE_NOTICE);
 }
+

 /* Operate the OLED display */
 void draw() {
@@ -229,16 +266,17 @@
     case STATE_NOTICE:
       u8g.setColorIndex(1);
       u8g.setFont(u8g_font_6x10r);
-      u8g.drawFrame(0, 0, DISPLAY_WIDTH, 34);
-      u8g.drawStr( 40, 12, F("Notice:"));
+      u8g.drawFrame(0, 0, DISPLAY_WIDTH, DISPLAY_HEIGHT);
+      u8g.drawStr( 41, 12, F("Notice:"));
       u8g.drawStr( 6, 24, onscreenNoticeMessage);
+      u8g.drawStr( 26, 61, F("Press button."));
       break;
     case STATE_SPLASH:
       u8g.setColorIndex(1);
       u8g.setFont(u8g_font_6x10r);
-      u8g.drawStr( 36, 26, F("PHANTOM"));
-      u8g.drawStr( 16, 38, F("FULL-THROTTLE"));
-      u8g.drawStr( 16, 50,  F("SUPERCHARGER"));
+      u8g.drawStr( 27, 22, F("   PHANTOM   "));
+      u8g.drawStr( 27, 34, F("FULL-THROTTLE"));
+      u8g.drawStr( 29, 46,  F("SUPERCHARGER"));
       break;
     case STATE_NORMAL:
       u8g.setColorIndex(1);
@@ -249,34 +287,43 @@
       u8g.print(F("C   CPU "));
       u8g.print(controllerTempC, 1);
       u8g.print(F("C"));
-      if (isBoosting()) {
-        u8g.setPrintPos(40, 20);
-        u8g.print(F("Boosting"));
+
+      if (relayEnabled) {
+
+        if (isBoosting()) {
+          u8g.setPrintPos(40, 20);
+          u8g.print(F("Boosting"));
+        } else {
+          u8g.setPrintPos(10, 20);
+          u8g.print(F("Last Boost: "));
+          u8g.print(getLastBoostDurationMillis()/1000.0, 2);
+          u8g.print(F(" s"));
+        }
+
+        for(int i=0; i<BARGRAPH_DATA_SZ; i++) {
+          int h = getBarGraphDataPointInPast(i);
+          int x = i*2;
+          int yStart = DISPLAY_HEIGHT - h;
+          u8g.drawVLine(DISPLAY_WIDTH-x, yStart, h);
+          u8g.drawVLine(DISPLAY_WIDTH-x+1, yStart, h);
+        }
+
+
+        u8g.setColorIndex(0);
+        u8g.drawRBox(30, 36, 72, 28, 2);
+
+        u8g.setColorIndex(1);
+        u8g.drawRFrame(30, 36, 72, 28, 2);
+
+        u8g.setFont(u8g_font_helvB24n);
+        u8g.setPrintPos(34, 63);
+        u8g.print(sensorVoltOne, 1);
+
       } else {
-        u8g.setPrintPos(10, 20);
-        u8g.print(F("Last Boost: "));
-        u8g.print(getLastBoostDurationMillis()/1000.0, 2);
-        u8g.print(F(" s"));
+
+        u8g.setPrintPos(34, 63);
+        u8g.print(F("Disabled"));
       }
-
-      for(int i=0; i<BARGRAPH_DATA_SZ; i++) {
-        int h = getBarGraphDataPointInPast(i);
-        int x = i*2;
-        int yStart = DISPLAY_HEIGHT - h;
-        u8g.drawVLine(DISPLAY_WIDTH-x, yStart, h);
-        u8g.drawVLine(DISPLAY_WIDTH-x+1, yStart, h);
-      }
-
-
-      u8g.setColorIndex(0);
-      u8g.drawRBox(30, 36, 72, 28, 2);
-
-      u8g.setColorIndex(1);
-      u8g.drawRFrame(30, 36, 72, 28, 2);
-
-      u8g.setFont(u8g_font_helvB24n);
-      u8g.setPrintPos(34, 63);
-      u8g.print(sensorVoltOne, 1);

       break;
   }
@@ -290,7 +337,9 @@

   pinMode(SD_CS, OUTPUT);
   pinMode(OLED_CS, OUTPUT);
-
+  pinMode(BUTTON, INPUT);
+
+  changeRelayEnabledState(false);
   changeState(STATE_SPLASH);

   // Setup bar graph
@@ -299,7 +348,7 @@

 void loopNormal() {
   readVoltSensors();
-
+
   long time = millis();

   if (time - TEMP_READ_INTERVAL_MS > lastTempUpdate) {
@@ -333,7 +382,11 @@
   do {
     draw();
   } while( u8g.nextPage() );
-
+
+  /* Load button state */
+  boolean buttonPressed = readButtonState();
+
+
   /* State updates */
   switch(displayState){
     case STATE_SPLASH:
@@ -352,6 +405,9 @@
       /* Remain in splash for 2 seconds */
       delay(2000);

+      /* Enable relay */
+      changeRelayEnabledState(true);
+
       break;
     case STATE_FATAL:
       while(1) {
@@ -359,14 +415,17 @@
       }
       break;
     case STATE_NOTICE:
-      /* Return to Normal. */
-      changeState(STATE_NORMAL);
-
-      /* Show notices for 4 seconds */
-      delay(4000);
+      if (buttonPressed) {
+        /* Return to Normal. */
+        changeState(STATE_NORMAL);
+      }

       break;
     case STATE_NORMAL:
+      if (buttonPressed) {
+        toggleRelayEnabledState();
+      }
+
       loopNormal();
       break;
    }


Fixed I2C encoder library import problem.

--- calf_teensy/calf_teensy.ino
+++ calf_teensy/calf_teensy.ino
@@ -1,3 +1,4 @@
+#include <Wire.h>
 #include <Servo.h>
 #include "AnalogChannel.h"
 #include "PWMChannel.h"


Included distance and angle calculating as a separate function

--- LIDAR_withPIDs/LIDAR_withPIDs.ino
+++ LIDAR_withPIDs/LIDAR_withPIDs.ino
@@ -218,3 +218,13 @@
     delay(10);
   }
 }
+
+void calcDistAngle(double dist0, double dist1) {
+  double angle = atan((dist0 - dist1) / LIDARspacing);
+  double centerDist = ((dist0 + dist1) * cos(angle)) / 2;
+  double distAngle [2];
+  distAngle[0] = angle;
+  distAngle[1] = centerDist;
+  return distAngle;
+}
+


Updated example.

Updated example.

--- firmware/examples/mdns.ino
+++ firmware/examples/mdns.ino
@@ -1,18 +1,19 @@
-#import "MDNS.h"
+// This #include statement was automatically added by the Spark IDE.
+#include "MDNS.h"

 #define HTTP_PORT 80

 MDNS mdns;

-String html = "
Ok!
";
-
 TCPServer server = TCPServer(HTTP_PORT);

 void setup() {
+    server.begin();
+
     bool success = mdns.setHostname("core-1");

     if (success) {
-        success = mdns.setService("_http._tcp", HTTP_PORT, "Core 1");
+        success = mdns.setService("tcp", "http", HTTP_PORT, "Core 1");
     }

     if (success) {
@@ -36,8 +37,7 @@
     TCPClient client = server.available();

     if (client){
-        client.println(html);
-        client.println();
+        client.println("
Ok!
\n\n");
         client.flush();
         client.stop();
     }