fix status code, simplified code

fix status code, simplified code

--- plant-monitor/plant-monitor.ino
+++ plant-monitor/plant-monitor.ino
@@ -29,7 +29,7 @@
 Phant phant(server, publicKey, privateKey);

 // interval counters for measurement and post
-const int MEASUREMENT_RATE = 15000; // read sensor data every 30 sec
+const int MEASUREMENT_RATE = 30000; // read sensor data every 30 sec
 const int POST_RATE = 15 * 60000; // post data every 15 minutes
 elapsedMillis lastMeasurement;
 elapsedMillis lastPost;
@@ -61,8 +61,8 @@
     // read sensor data
     if (lastMeasurement > MEASUREMENT_RATE) {
       int bmeSensorStatus = readBMESensor();
-
-      int soil1SensorStatus = readSoilSensor1();
+      delay(200);
+      int soil1SensorStatus = readSoilSensor(soilSensor1, soil1);

       // calc overall sensor status
       sensorStatus = bmeSensorStatus; // TODO
@@ -107,7 +107,7 @@
 }

 // read BME280 sensor data
-byte readBMESensor() {
+int readBMESensor() {
   double currentTemperature = 0;
   digitalWrite(led, HIGH);
   currentTemperature = bme.readTemperature();
@@ -131,30 +131,26 @@
 }

 // read soil sensor data
-byte readSoilSensor1() {
-  unsigned int currentSoil1 = readSoilSensor(soilSensor1);
-  int soilDiff = currentSoil1 - soil1;
-  soil1 = (currentSoil1 + soil1) / 2;
-
-  if (soilDiff > 100) {
-    return 1; // indicate soil increase above threshold
-  } else if (soilDiff < 100){
-    return 2; // indicate soil decrease above threshold
-  } else {
-    return 0; // indicate normal reading
-  }
-}
-
-int readSoilSensor(int soilSensor) {
-    unsigned int val = 0;
+int readSoilSensor(int soilSensor, unsigned int &soilValue) {
+    unsigned int currentSoil = 0;
     digitalWrite(led, HIGH);
     digitalWrite(soilPower, HIGH); //turn sensor power on
     delay(10);
-    val = analogRead(soilSensor);
+    currentSoil = analogRead(soilSensor);
     digitalWrite(soilPower, LOW); //turn sensor power off
     delay(190);
     digitalWrite(led, LOW);
-    return val;
+
+    int soilDiff = currentSoil - soilValue;
+    soilValue = (currentSoil + soilValue) / 2;
+
+    if (soilDiff > 100) {
+      return 1; // indicate soil increase above threshold
+    } else if (soilDiff < 100){
+      return 2; // indicate soil decrease above threshold
+    } else {
+      return 0; // indicate normal reading
+    }
 }

 void dumpSerial() {


Cleanup and docs

Cleanup and docs

--- camera_box/camera_box.ino
+++ camera_box/camera_box.ino
@@ -79,6 +79,7 @@
     }
   }

+  // Begin reading values and outputting as JSON string
   Serial.print("{");

   read_accelerometer(); Serial.print(',');


Update smart_matrix_dmd_teensy_code.ino

Update smart_matrix_dmd_teensy_code.ino

Added changes to accept new cookie and V4 of Teensy shield

--- tools/smart_matrix_dmd_teensy_code/smart_matrix_dmd_teensy_code.ino
+++ tools/smart_matrix_dmd_teensy_code/smart_matrix_dmd_teensy_code.ino
@@ -4,6 +4,7 @@
     This example code is released into the public domain
 */

+#include <SmartLEDShieldV4.h> // this line must be first if using a V4 shield
 #include <SmartMatrix3.h>
 #include <usb_serial.h>

@@ -32,6 +33,13 @@
 int dataPos = 0;
 int dataExpected = 0;

+bool gotCommand = false;
+int commandPos = 0;
+
+const int USB_MARKER_LENGTH = 4;
+const int USB_COMMAND_LENGTH = 8;
+const uint8_t usbMarker[USB_MARKER_LENGTH] = {0xBA, 0x11, 0x00, 0x03};
+uint8_t usbCommand[USB_COMMAND_LENGTH];

 // the setup() method runs once, when the sketch starts
 void setup() {
@@ -71,25 +79,42 @@
     }
   }
   else if (bytesAvail) {
-    char val = Serial.read();
-    if ( val == 1 )
-    {
-      backgroundLayer.swapBuffers(true);
-      dataPos=0;
-      dataExpected = kMatrixWidth * kMatrixHeight * 3;
-      digitalWrite(ledPin, HIGH);
-    }
-    else {
+      char val = Serial.read();
+
+   if (gotCommand)
+   {
       buffer[dataPos++] = val;
       dataExpected--;
       if (dataExpected == 0) {
         swap = true;
       }
     }
+   else if (commandPos < USB_MARKER_LENGTH) {
+      usbCommand[commandPos] = val;
+      if (usbCommand[commandPos] == usbMarker[commandPos]) {
+        commandPos++;
+      }
+      else {
+        commandPos = 0;
+      }
+    }
+    else if (commandPos < USB_COMMAND_LENGTH) {
+      usbCommand[commandPos] = val;
+      commandPos++;
+      if (commandPos >= USB_COMMAND_LENGTH)
+      {
+      gotCommand = true;
+      backgroundLayer.swapBuffers(true);
+      dataPos=0;
+      dataExpected = kMatrixWidth * kMatrixHeight * 3;
+      }
+    }
   }

   if (swap) {
     frameCount++;
+    gotCommand = false;
+    commandPos = 0;
     char frameText[12];
     itoa(frameCount, frameText, 10);
     backgroundLayer.swapBuffers(true);
@@ -99,4 +124,3 @@
     frameOn = !frameOn;
   }
 }
-


weird spacing

weird spacing

--- master/master.ino
+++ master/master.ino
@@ -909,7 +909,7 @@
 		if (loopCount % 30 == 0){
 			if (tftEnabled){
 				debugTFT();
-			}
+			}
 		}

 		/* end debugging */


Version 1.04. Optimized data reading

Version 1.04. Optimized data reading

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

 unsigned long getTime (unsigned char readData[]) {
+	int i = 0;
 	unsigned long existingTime = 0;

-	existingTime = existingTime ^ readData[20];
-	existingTime = (existingTime << 8) ^ readData[21];
-	existingTime = (existingTime << 8) ^ readData[22];
-	existingTime = (existingTime << 8) ^ readData[23];
+	for(i = 0; i < 4; i++) {
+		existingTime = (existingTime << 8) ^ readData[i + 20];
+	}

 	Serial.print("Time used this month: ");
 	Serial.println(existingTime);


Finalize configuration saving/loading code.

Signed-off-by: Kalman Olah <aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d@kalmanolah.net>

--- src/sketch.ino
+++ src/sketch.ino
@@ -3,118 +3,66 @@
 #include <avr/sleep.h>
 #include <EEPROMex.h>

-/**
- * Configuration version, used for validating configuration integrity.
- * @type char*
- */
-const char* CONFIG_VERSION = "1";
-
-/**
- * Size of the configuration block memory pool.
- * @type int
- */
+// Configuration version, used for validating configuration integrity.
+#define CONFIG_VERSION "001"
+
+// Size of the configuration block memory pool.
 const int CONFIG_MEMORY_SIZE = 32;

-/**
- * EEPROM size. Bad things will happen if this isn't set correctly.
- * @type int
- */
+// EEPROM size. Bad things will happen if this isn't set correctly.
 const int CONFIG_EEPROM_SIZE = EEPROMSizeATmega328;

-/**
- * Configuration memory address, used to determine where to read and write
- * data.
- * @type int
- */
+// Config memory address, used to determine where to read and write data.
 int config_address = 0;

-/**
- * Configuration structure. Also contains the default configuration.
- */
+// Configuration structure. Also contains the default configuration.
 struct ConfigurationStruct {
-    /**
-     * Delay between loops, in milliseconds.
-     * @type int
-     */
+    // Character string indicating configuration version.
+    char version[4];
+
+    // Delay between loops, in milliseconds.
     int loop_delay;

-    /**
-     * Serial input buffer size, in bytes.
-     * @type int
-     */
+    // Serial input buffer size, in bytes.
     int serial_input_buffer_size;

-    /**
-     * Boolean indicating whether debug mode is enabled.
-     * @type bool
-     */
+    // Boolean indicating whether debug mode is enabled.
     bool debug;
-
-    /**
-     * Character string indicating configuration version.
-     * @type char[4]
-     */
-    char* version[4];
 } config = {
+    CONFIG_VERSION,
     50,
     32,
-    false,
-    (char*) CONFIG_VERSION
+    false
 };

-/**
- * Serial input structure.
- */
+// Serial input structure.
 struct SerialInputStruct {
-    /**
-     * Boolean indicating whether the input buffer is ready for processing.
-     * @type bool
-     */
+    // Boolean indicating whether the input buffer is ready for processing.
     bool ready;

-    /**
-     * Input buffer containing received serial data.
-     * @type String|char*
-     */
+    // Input buffer containing received serial data.
     String buffer;
 } serial_input = {
     false,
     ""
 };

-/**
- * Power button pin number.
- * @type int
- */
+// Power button pin number.
 const int POWER_BTN = 2;

-/**
- * Power LED pin number.
- * @type int
- */
+// Power LED pin number.
 const int POWER_LED = 13;

-/**
- * Byte containing states/state history of the power button.
- * @type byte
- */
+// Byte containing states/state history of the power button.
 byte POWER_BTN_STATES = B11111111;

-/**
- * Enum containing power states.
- * @type enum
- */
+// Enum containing power states.
 enum PowerState {
     SLEEPING,
     AWAKE
 };

-/**
- * Boolean indicating current power state.
- * 0 = sleeping / powered down
- * 1 = awake / fully powered
- * @type int
- */
+// Current power state
 int POWER_STATE = AWAKE;

 /**
@@ -146,7 +94,7 @@
  */
 void loop()
 {
-    determinePowerState();
+    // determinePowerState();
     determineSleepState();

     delay(config.loop_delay);
@@ -160,14 +108,19 @@
 void loadConfiguration() {
     // Ensure the version string matches our version string; if it doesn't, we
     // should just use the default configuration
-    if (EEPROM.readByte(config_address + sizeof(config) - 1) == *config.version[3]
-        && EEPROM.readByte(config_address + sizeof(config) - 2) == *config.version[2]
-        && EEPROM.readByte(config_address + sizeof(config) - 3) == *config.version[1]
-        && EEPROM.readByte(config_address + sizeof(config) - 4) == *config.version[0]) {
-        Serial.println("Configuration matched!");
-        EEPROM.readBlock(config_address, config);
+    char stored_version[4];
+    EEPROM.readBlock(config_address, stored_version);
+
+    if (strcmp(stored_version, config.version) == 0) {
+        int bytes_read = EEPROM.readBlock(config_address, config);
+
+        Serial.print("Loaded configuration; version: ");
+        Serial.print(stored_version);
+        Serial.print("; bytes read: ");
+        Serial.println(bytes_read);
     } else {
-        Serial.println("Configuration did not match!");
+        Serial.print("Not loading old configuration; version: ");
+        Serial.println(stored_version);
     }
 }

@@ -179,7 +132,13 @@
  */
 void saveConfiguration() {
     Serial.println("Saving configuration");
-    Serial.println(EEPROM.updateBlock(config_address, config));
+
+    int bytes_written = EEPROM.updateBlock(config_address, config);
+
+    Serial.print("Configuration saved; version: ");
+    Serial.print(config.version);
+    Serial.print("; bytes written: ");
+    Serial.println(bytes_written);
 }

 /**


Added default hostname 'aquacontrol'

Added default hostname 'aquacontrol'

--- aquacontrol2.ino
+++ aquacontrol2.ino
@@ -19,7 +19,7 @@

 String WIFIssid;
 String WIFIpassword;
-String WIFIhostname = "";
+String WIFIhostname;
 time_t WIFItimeout = 15; //number of seconds WiFi tries to connect before starting an accesspoint

 time_t bootTime;
@@ -104,6 +104,10 @@
   Serial.print( "\n\n" );

   readWifiDataFromEEPROM();
+
+  if ( WIFIhostname == "" ) {
+    WIFIhostname = "aquacontrol";
+  }

   //check if WiFi data is found
   if ( WIFIssid != "" ) {


Correctly reset denominator value

Correctly reset denominator value

--- ableton-midi-foot-controller.ino
+++ ableton-midi-foot-controller.ino
@@ -675,6 +675,7 @@
   if (realtimebyte == START) {
     playing = true;
     repeat = false;
+    fullDenominator = 0;
     changeMode(SONG_MODE);
   }


Update PulseSensor_Nucleo.ino

Update PulseSensor_Nucleo.ino

--- examples/PulseSensor_Nucleo/PulseSensor_Nucleo.ino
+++ examples/PulseSensor_Nucleo/PulseSensor_Nucleo.ino
@@ -6,6 +6,13 @@
    Here is a link to the tutorial that discusses this code
    >> Comming Soon! <<

+   Use this code as a basic example when targeting STM32 boards.
+   Open your Arduino > Preferences window, and add this to your Additional Boards Manager URLs:
+
+https://raw.githubusercontent.com/stm32duino/BoardManagerFiles/master/STM32/package_stm_index.json
+
+   Then, go to Tools > Board > Boards Manager to install the STM32 core.
+
    This example targets the Nucleo 64 F401RE
    If you are using a different Nucleo board, you may have to change some of the
    board parameters. Here are the drop-down selections that I used.


Add timestamp to pump reads if we have it, even if current GPS fix is bad.

--- teensy/teensy.ino
+++ teensy/teensy.ino
@@ -1423,6 +1423,10 @@

 void add_timestamp_to_string(String &the_string)
 {
+  Serial.print("COWABUNGA gps_valid    is "); Serial.println(gps_valid);
+  Serial.print("COWABUNGA timeStatus() is "); Serial.println(timeStatus());
+  Serial.print("COWABUNGA timeNotSet   is "); Serial.println(timeNotSet);
+
   the_string += F(",U:");
   append_formatted_value(the_string, hour());
   append_formatted_value(the_string, minute());
@@ -1451,7 +1455,8 @@
        latest_message_to_send += F(":");
        latest_message_to_send += FLOATHUB_PROTOCOL_VERSION;
        latest_message_to_send += F("$");
-       if(gps_valid || timeStatus() != timeNotSet)
+       //if(gps_valid || timeStatus() != timeNotSet)
+       if(timeStatus() != timeNotSet)
        {
          add_timestamp_to_string(latest_message_to_send);
        }
@@ -1483,7 +1488,8 @@
        latest_message_to_send += FLOATHUB_PROTOCOL_VERSION;
        latest_message_to_send += F("$");

-       if(gps_valid || timeStatus() != timeNotSet)
+       //if(gps_valid || timeStatus() != timeNotSet)
+       if(timeStatus() != timeNotSet)
        {
          add_timestamp_to_string(latest_message_to_send);
        }
@@ -1590,7 +1596,8 @@
   latest_message_to_send += F(":");
   latest_message_to_send += FLOATHUB_PROTOCOL_VERSION;
   latest_message_to_send += F("$");
-  if(gps_valid == true || timeStatus() != timeNotSet )
+  //if(gps_valid == true || timeStatus() != timeNotSet )
+  if(timeStatus() != timeNotSet )
   {
      add_timestamp_to_string(latest_message_to_send);
   }


pin changes

pin changes

--- sketches/monitor_nodown/monitor_nodown.ino
+++ sketches/monitor_nodown/monitor_nodown.ino
@@ -11,10 +11,10 @@
 #include <DHT.h>

 /* --- Definitions --- */
-#define DHT_INTERNAL_PIN 4
-#define DHT_EXTERNAL_PIN 5
-#define VOLTS_PIN A0
-#define AMPS_PIN A1
+#define DHT_INTERNAL_PIN A0
+#define DHT_EXTERNAL_PIN A1
+#define VOLTS_PIN A2
+#define AMPS_PIN A3
 #define DHT_TYPE DHT22

 /* --- Constants --- */


fixes for sd server example

fixes for sd server example

--- libraries/ESP8266WebServer/examples/SDWebServer/SDWebServer.ino
+++ libraries/ESP8266WebServer/examples/SDWebServer/SDWebServer.ino
@@ -87,12 +87,20 @@
     uint8_t obuf[WWW_BUF_SIZE];
     while (dataFile.available() > WWW_BUF_SIZE){
       dataFile.read(obuf, WWW_BUF_SIZE);
-      client.write(obuf, WWW_BUF_SIZE);
+      if(client.write(obuf, WWW_BUF_SIZE) != WWW_BUF_SIZE){
+        Serial.println("Sent less data than expected!");
+        dataFile.close();
+        return true;
+      }
     }
     //stream the last data left (size is at most WWW_BUF_SIZE bytes)
     uint16_t leftLen = dataFile.available();
     dataFile.read(obuf, leftLen);
-    client.write(obuf, leftLen);
+    if(client.write(obuf, leftLen) != leftLen){
+      Serial.println("Sent less data than expected!");
+      dataFile.close();
+      return true;
+    }

     dataFile.close();
     return true;
@@ -124,7 +132,7 @@
   while (WiFi.status() != WL_CONNECTED && i++ < 20) delay(500);

   //check if we have connected?
-  if(i == 20){
+  if(i == 21){
     Serial.print("Could not connect to");
     Serial.println(ssid);
     //stop execution and wait forever


ADC補正・ADC変換係数変更

ADC補正・ADC変換係数変更

--- 2_example/example39_temp/example39_temp.ino
+++ 2_example/example39_temp/example39_temp.ino
@@ -18,7 +18,6 @@

 void setup(){                               // 起動時に一度だけ実行する関数
     int waiting=0;                          // アクセスポイント接続待ち用
-    analogSetAttenuation(ADC_0db);          // アナログ入力のアッテネータ設定
     pinMode(PIN_AIN,INPUT);                 // アナログ入力の設定
     pinMode(PIN_EN,OUTPUT);                 // センサ用の電源を出力に
     Serial.begin(115200);                   // 動作確認のためのシリアル出力開始
@@ -42,9 +41,9 @@

     digitalWrite(PIN_EN,HIGH);              // センサ用の電源をONに
     delay(100);                             // 起動待ち時間
-    temp=(float)analogRead(PIN_AIN);        // AD変換器から値を取得
+    temp=(float)mvAnalogIn(PIN_AIN);        // AD変換器から値を取得
     digitalWrite(PIN_EN,LOW);               // センサ用の電源をOFFに
-    temp *= 1100. / 4095. /10.;             // 温度(相対値)へ変換
+    temp /= 10.;                            // 温度(相対値)へ変換
     temp += TEMP_OFFSET;                    // オフセットにより絶対値へ変換
     udp.beginPacket(SENDTO, PORT);          // UDP送信先を設定
     udp.print(DEVICE);                      // デバイス名を送信
@@ -54,6 +53,42 @@
     sleep();
 }

+float mvAnalogIn(uint8_t PIN){
+    int in0,in3;
+    float ad0,ad3;
+
+    analogSetPinAttenuation(PIN,ADC_11db);
+    in3=analogRead(PIN);
+
+    if( in3 > 2599 ){
+        ad3 = -1.457583e-7 * (float)in3 * (float)in3
+            + 1.510116e-3 * (float)in3
+            - 0.573300;
+    }else{
+        ad3 = 8.378998e-4 * (float)in3 + 1.891456e-1;
+    }
+    Serial.print("ADC (ATT=3;11dB) = ");
+    Serial.print(ad3,3);
+    Serial.print(" [V], ");
+    Serial.println(in3);
+    if( in3 < 200 ){
+        analogSetPinAttenuation(PIN,ADC_0db);
+        in0=analogRead(PIN);
+        ad0 = 2.442116e-4 * (float)in0 + 1.075584e-1;
+        Serial.print("ADC (ATT=0; 0dB) = ");
+        Serial.print(ad0,3);
+        Serial.print(" [V], ");
+        Serial.println(in0);
+        if( in3 >= 100 ){
+            ad3 = ad3 * ((float)in3 - 100.) / 100.
+                + ad0 * (200. - (float)in3) / 100.;
+        }else{
+            ad3 = ad0;
+        }
+    }
+    return ad3 * 1000.;
+}
+
 void sleep(){
     delay(200);                             // 送信待ち時間
     esp_deep_sleep(SLEEP_P);                // Deep Sleepモードへ移行


Modified to initialize and try to use the radio.

--- examples/AFSK-Send/AFSK-Send.ino
+++ examples/AFSK-Send/AFSK-Send.ino
@@ -14,9 +14,17 @@
   digitalWrite(2, LOW);
   digitalWrite(10, LOW);

+  Serial.println(F("Radio test connection"));
+  radio.testConnection();
+  Serial.println(F("Initialize"));
+  radio.initialize();
+  Serial.println(F("Frequency"));
+  radio.frequency(446000);
+  Serial.println(F("DDS Start"));
   dds.start();
+  Serial.println(F("AFSK start"));
   radio.afsk.start(&dds);
-  Serial.println("Starting...");
+  Serial.println(F("Starting..."));
 }

 void loop() {
@@ -46,7 +54,7 @@
     bool ret = radio.afsk.putTXPacket(packet);
     if(radio.afsk.txReady())
       if(radio.afsk.txStart()) {
-        Serial.println("PTT here.");
+        radio.setModeTransmit();
       }
     // Wait 2 seconds before we send our beacon again.
     Serial.println("tick");


fix a platform bug

fix a platform bug

--- examples/example-1/example-1.ino
+++ examples/example-1/example-1.ino
@@ -15,7 +15,7 @@
 Pin led = Pin(13, OUTPUT);

 //也允许只声明针脚却不声明用途,但最好之后在setup()中初始化
-Pin button = Pin(D1);
+Pin button = Pin(32);

 //声明一个呼吸灯
 Pin breath = Pin(9, OUTPUT);


Update wled06_usermod.ino

Update wled06_usermod.ino

--- usermods/Wemos_D1_mini+Wemos32_mini_shield/wled06_usermod.ino
+++ usermods/Wemos_D1_mini+Wemos32_mini_shield/wled06_usermod.ino
@@ -32,8 +32,7 @@
 //U8X8_SSD1306_128X64_NONAME_HW_I2C u8x8(U8X8_PIN_NONE, U8X8_PIN_SCL, U8X8_PIN_SDA); // Pins are Reset, SCL, SDA
 // --> Third choise of Heltec WiFi-Kit-8 OLED 128X32 0.91"
 //U8X8_SSD1306_128X32_UNIVISION_HW_I2C u8x8(U8X8_PIN_RESET, U8X8_PIN_SCL, U8X8_PIN_SDA); // Constructor for Heltec WiFi-Kit-8
-// gets called once at boot. Do all initialization that doesn't depend on
-// network here
+// gets called once at boot. Do all initialization that doesn't depend on network here
 void userSetup() {
   sensor.begin(); //Start Dallas temperature sensor
   u8x8.begin();


Implement long button press to freeze display, short press to change mode.

--- tiny_scope.ino
+++ tiny_scope.ino
@@ -111,22 +111,21 @@
  * Cycle through the ADC modes with each button push.
  */
 void setADCMode(){
-    enum {
-        BUTTON_ON,
-        BUTTON_OFF
-    };
-    static uint8_t modeButtonState = BUTTON_OFF;
     int adcMode = EEPROM.read(ADC_MODE_ADDR);
+    unsigned count = 0;

     if (digitalRead(MODE_BUTTON_PIN) == LOW){
-        if (modeButtonState == BUTTON_OFF){
-            modeButtonState = BUTTON_ON;
+        // Freeze display while button stays pressed
+        while (digitalRead(MODE_BUTTON_PIN) == LOW){
+            delay(50);
+            count++;
+        }
+        // Momentary push (0.5s) means adc mode switch; long push freeze only
+        if (count < 10){
             adcMode = (adcMode+1) % capture.adc.getModeCount();
             capture.adc.setMode(adcMode);
             EEPROM.write(ADC_MODE_ADDR, byte(adcMode));
         }
-    } else {
-        modeButtonState = BUTTON_OFF;
     }
 }


Add song mode

Add song mode

--- ableton-midi-foot-controller.ino
+++ ableton-midi-foot-controller.ino
@@ -72,7 +72,8 @@
 const byte UNCONFIGURED = 0;
 const byte NORMAL_MODE = 1;
 const byte INIT_MODE = 2;
-const byte modeCount = 3;
+const byte SONG_MODE = 3;
+const byte modeCount = 4;
 byte mode = UNCONFIGURED;

 byte initBank = 0;
@@ -103,6 +104,8 @@
 byte midiNoteToSend = -1;
 elapsedMillis midiNoteSendStart = 0;
 boolean startedMidiNoteSending = false;
+
+boolean playing = false;

 void OnNoteOn(byte channel, byte note, byte velocity) {
   digitalWrite(ledPin, HIGH);
@@ -164,9 +167,8 @@
   allLedsTest();
   lcd.clear();

-  mode = NORMAL_MODE;
+  changeMode(NORMAL_MODE);
   selectedSong = 0;
-  handleNormalMode(true);
 }

 void handleSongConfiguration(char* messageOriginal) {
@@ -344,15 +346,15 @@

 void sendMidiNote() {
-  if(midiNoteToSend!=-1) {
-    if(midiNoteSendStart > 100) {
+  if (midiNoteToSend != -1) {
+    if (midiNoteSendStart > 100) {
       usbMIDI.sendNoteOff(midiNoteToSend, 0, midiChannel);
       midiNoteToSend = -1;
       startedMidiNoteSending = false;
-    } else if(!startedMidiNoteSending) {
+    } else if (!startedMidiNoteSending) {
       usbMIDI.sendNoteOn(midiNoteToSend, 99, midiChannel);
       startedMidiNoteSending = true;
-    }
+    }
   }
 }

@@ -380,6 +382,38 @@
     case INIT_MODE:
       handleInitMode();
       break;
+    case SONG_MODE:
+      handleSongMode();
+      break;
+  }
+}
+
+void handleSongMode() {
+  if (playing) {
+    playButton.turnLedOn();
+  } else {
+    playButton.turnLedOff();
+  }
+
+  if (stopButton.isJustPressed()) {
+    stopButton.turnLedOn();
+  }
+
+  if (stopButton.isJustReleased()) {
+    midiNoteSendStart = 0;
+    midiNoteToSend = STOP_MIDI_NOTE;
+    stopButton.turnLedOff();
+    changeMode(NORMAL_MODE);
+  }
+
+  sendMidiNote();
+}
+
+void changeMode(byte newMode) {
+  mode = newMode;
+  resetLeds();
+  if (mode == NORMAL_MODE) {
+    handleNormalMode(true);
   }
 }

@@ -433,23 +467,16 @@
     }
   }

-  if(playButton.isJustPressed()) {
+  if (playButton.isJustPressed()) {
     playButton.turnLedOn();
   }

-  if(stopButton.isJustPressed()) {
-    stopButton.turnLedOn();
-  }
-
-  if(playButton.isJustReleased()) {
+
+
+  if (playButton.isJustReleased()) {
     midiNoteSendStart = 0;
     midiNoteToSend = selectedSong + (bank * numberOfChannelButtons) + SONG_OFFSET;
     playButton.turnLedOff();
-  }
-  if(stopButton.isJustReleased()) {
-    midiNoteSendStart = 0;
-    midiNoteToSend = STOP_MIDI_NOTE;
-    stopButton.turnLedOff();
   }

   sendMidiNote();
@@ -512,11 +539,11 @@
 void RealTimeSystem(byte realtimebyte) {
   if (realtimebyte == CLOCK) {
     counter++;
-    if (counter == 24) {
+    if (counter >= 23) {
       counter = 0;
       digitalWrite(bpmLed, HIGH);
     }
-    if (counter == 6) {
+    if (counter == 5) {
       digitalWrite(bpmLed, LOW);
     }
   }
@@ -526,9 +553,15 @@
     digitalWrite(bpmLed, HIGH);
   }

+  if (realtimebyte == START) {
+    playing = true;
+    changeMode(SONG_MODE);
+  }
+
   if (realtimebyte == STOP) {
     digitalWrite(bpmLed, LOW);
-  }
-}
-
-
+    playing = false;
+  }
+}
+
+


const argument.

const argument.

--- webservertask.ino
+++ webservertask.ino
@@ -715,6 +715,6 @@
   return true;
 }

-static inline __attribute__((always_inline)) bool htmlUnmodified( AsyncWebServerRequest * request, const char * date ) {
+static inline __attribute__((always_inline)) bool htmlUnmodified( const AsyncWebServerRequest * request, const char * date ) {
   return request->hasHeader( "If-Modified-Since" ) && request->header( "If-Modified-Since" ).equals( date );
 }


Added code for more status LEDs and a light sensor

--- RS485/UtilClient/UtilMaster/UtilMaster.ino
+++ RS485/UtilClient/UtilMaster/UtilMaster.ino
@@ -11,7 +11,12 @@

 RS485Socket rs485(2, 3, 4, (DEBUG_LEVEL != 0));

-#define PIN_STATUS_LED 12
+#define PIN_LIGHT_SENSE A0
+
+#define PIN_OUTPUT1     9
+#define PIN_RCVD_LED   10
+#define PIN_XMIT_LED   11
+#define PIN_POWER_LED  12
 #define PIN_DEBUG_LED  13

 #define NUM_SLAVES 1
@@ -39,16 +44,16 @@
 #if NUM_SLAVES > 1
   1,
 #endif
-#if NUM_SLAVES > 1
+#if NUM_SLAVES > 2
   2,
 #endif
-#if NUM_SLAVES > 1
+#if NUM_SLAVES > 3
   3,
 #endif
-#if NUM_SLAVES > 1
+#if NUM_SLAVES > 4
   4,
 #endif
-#if NUM_SLAVES > 1
+#if NUM_SLAVES > 5
   5
 #endif
 };
@@ -81,28 +86,59 @@
 {
   Serial.begin(9600);

-  pinMode(PIN_STATUS_LED, OUTPUT);
-  digitalWrite(PIN_STATUS_LED, HIGH);
+  pinMode(PIN_OUTPUT1, OUTPUT);
+  digitalWrite(PIN_OUTPUT1, LOW);
+
+  pinMode(PIN_RCVD_LED, OUTPUT);
+  digitalWrite(PIN_RCVD_LED, LOW);
+
+  pinMode(PIN_XMIT_LED, OUTPUT);
+  digitalWrite(PIN_XMIT_LED, LOW);
+
+  pinMode(PIN_POWER_LED, OUTPUT);
+  digitalWrite(PIN_POWER_LED, HIGH);

   pinMode(PIN_DEBUG_LED, OUTPUT);
   digitalWrite(PIN_DEBUG_LED, HIGH);

+  pinMode(PIN_LIGHT_SENSE, INPUT_PULLUP);
+
   rs485.setup();
   send_buffer = rs485.initBuffer(databuffer);
 }

 boolean debug_led = false;
+boolean output1 = false;
+boolean trigger = false;

 int cycle = 0;

 #define MODE   3
-#define PERIOD 1000
+#define PERIOD 100

 void loop()
 {
   long start = millis();
   int slave;
+
+  int light_value = analogRead(PIN_LIGHT_SENSE);
+  DEBUG_VALUELN(DEBUG_HIGH, F("light_value:"), light_value);
+  if (light_value > 120) {
+    output1 = true;
+    digitalWrite(PIN_OUTPUT1, HIGH);
+  } else if (light_value > 40 && light_value < 80) {
+    if (output1) {
+      //analogWrite(PIN_OUTPUT1, 64);
+      trigger = !trigger;
+      if (trigger) digitalWrite(PIN_OUTPUT1, HIGH);
+      else digitalWrite(PIN_OUTPUT1, LOW);
+    }
+    DEBUG_VALUELN(DEBUG_HIGH, "Light trigger:", trigger);
+  } else if (light_value < 40) {
+    output1 = false;
+    digitalWrite(PIN_OUTPUT1, LOW);
+  }

   update_state();


Moved ADXL362 simple read

Moved ADXL362 simple read

--- tinkering/sensorboard/ADXL362_SimpleRead/ADXL362_SimpleRead.ino
+++ tinkering/sensorboard/ADXL362_SimpleRead/ADXL362_SimpleRead.ino
@@ -1,54 +0,0 @@
-/*
- ADXL362_SimpleRead.ino -  Simple XYZ axis reading example
- for Analog Devices ADXL362 - Micropower 3-axis accelerometer
- go to http://www.analog.com/ADXL362 for datasheet
-
-
- License: CC BY-SA 3.0: Creative Commons Share-alike 3.0. Feel free
- to use and abuse this code however you'd like. If you find it useful
- please attribute, and SHARE-ALIKE!
-
- Created June 2012
- by Anne Mahaffey - hosted on http://annem.github.com/ADXL362
-
- Modified May 2013
- by Jonathan Ruiz de Garibay
-
-Connect SCLK, MISO, MOSI, and CSB of ADXL362 to
-SCLK, MISO, MOSI, and DP 10 of Arduino
-(check http://arduino.cc/en/Reference/SPI for details)
-
-*/
-
-#include <SPI.h>
-#include <ADXL362.h>
-
-ADXL362 xl;
-
-int16_t temp;
-int16_t XValue, YValue, ZValue, Temperature;
-
-void setup(){
-
-  Serial.begin(9600);
-  xl.begin(10);                   // Setup SPI protocol, issue device soft reset
-  xl.beginMeasure();              // Switch ADXL362 to measure mode
-
-  Serial.println("Start Demo: Simple Read");
-}
-
-void loop(){
-
-  // read all three axis in burst to ensure all measurements correspond to same sample time
-  xl.readXYZTData(XValue, YValue, ZValue, Temperature);
-  Serial.print("XVALUE=");
-  Serial.print(XValue);
-  Serial.print("\tYVALUE=");
-  Serial.print(YValue);
-  Serial.print("\tZVALUE=");
-  Serial.print(ZValue);
-  Serial.print("\tTEMPERATURE=");
-  Serial.println(Temperature);
-  delay(100);                // Arbitrary delay to make serial monitor easier to observe
-}
-


Arduino Master

Arduino Master

--- masters/arduinoMaster/master/src/master/master.ino
+++ masters/arduinoMaster/master/src/master/master.ino
@@ -2,17 +2,17 @@
 #include <RFM69.h>

 #define MASTERADDRESS 3
-#define CODELOCKADDRESS 2
-#define NETWORKADDRESS 0
-#define FREQUENCY     RF69_868MHZ
-#define ENCRYPTKEY    "TOPSECRETPASSWRD"
-#define USEACK        true // Request ACKs or not
-RFM69 radio;
+  #define CODELOCKADDRESS 2
+  #define NETWORKADDRESS 0
+  #define FREQUENCY     RF69_868MHZ
+  #define ENCRYPTKEY    "TOPSECRETPASSWRD"
+  #define USEACK        true // Request ACKs or not
+  RFM69 radio;

 /******P I N S********/
 const byte relay1 = 11;
-const byte relay2 = 12;
+const byte relay2 = 3;

 /*******C O D E******/
 const byte maxCodeLength = 8;
@@ -27,6 +27,7 @@
 {

   Serial.begin(9600);
+  Serial.print("ArduinoMaster");
   radio.initialize(FREQUENCY, MASTERADDRESS, NETWORKADDRESS);
   radio.encrypt(ENCRYPTKEY);
   pinMode(relay1, OUTPUT);
@@ -36,37 +37,23 @@

 void loop()
 {
- // RECEIVING
-
-  // In this section, we'll check with the RFM69HCW to see
-  // if it has received any packets:
-  if (radio.receiveDone()) // Got one!
+  if (radio.receiveDone())
   {
-    // Print out the information:
-    Serial.print(", message [");
-
-    // The actual message is contained in the DATA array,
-    // and is DATALEN bytes in size:
-    for (byte i = 0; i < radio.DATALEN; i++)
+    Serial.print("message [");
+    int premenna = 0;
+    for (int i = 0; i < radio.DATALEN; i++)
     {
+      readCode[i] = (char)radio.DATA[i];
       Serial.print((char)radio.DATA[i]);
-      readCode[i]=radio.DATA[i];
     }
-    // RSSI is the "Receive Signal Strength Indicator",
-    // smaller numbers mean higher power.
-
     Serial.print("], RSSI ");
     Serial.println(radio.RSSI);
-
-    // Send an ACK if requested.
-    // (You don't need this code if you're not using ACKs.)
-
     if (radio.ACKRequested())
     {
       radio.sendACK();
-      Serial.println("ACK sent");
+      Serial.println("Prijata sprava");
+      if (verifyCode())grantAccess();
     }
-
   }
 }

@@ -80,24 +67,24 @@

 boolean verifyCode()
 {
-  for(byte i=0;i<maxCodeLength;i++)
+  for(int i=0;i<maxCodeLength;i++)
   {
     if(readCode[i] != code[i])
     {
       Serial.println("ZLE");
-      return false;
-      resetCode();
+      return false;
     }
-    Serial.println("OK");
+    else
+    {
+      Serial.println("OK");
+    }
   }
-  return check;
-  resetCode();
+resetCode();
+return true;
 }
-
 void grantAccess()
 {
     digitalWrite(relay2, HIGH);
     delay(2000);
     digitalWrite(relay2, LOW);
-}
-
+}


Delete 2wbt_mobile.ino

Delete 2wbt_mobile.ino

--- 2wbt_mobile.ino
+++ 2wbt_mobile.ino
@@ -1,145 +0,0 @@
-
-/*
-* ArduMobile - An Autonomous Nagivating Mobile Robot
-*
-* Developed by Vasilis Tzivaras
-* contact me at vtzivaras(at)gmail.com
-*
-* Arduino UNO R3
-* HC-SR04 Ultrasonic Sensor
-* Motor Shield v2
-* Lipo Battery
-* 9V Battery
-* Two DC Motors
-*/
-
-#include <SoftwareSerial.h>
-#include <Servo.h>
-
-#define LMDirection 12
-#define RMDirection 13
-
-#define LMSpeed 3
-#define RMSpeed 11
-
-#define LMBrake 9
-#define RMBrake 8
-
-SoftwareSerial mySerial(0,1);
-String Data = "";
-
-int mobileSpeed = 0;
-
-void setup() {
-    Serial.begin(115200);
-    mySerial.begin(9600);
-
-    Serial.println("Welcome to ardu-explorer v1.0");
-
-    // Motor movement
-    pinMode(LMDirection, OUTPUT);
-    pinMode(RMDirection, OUTPUT);
-
-    // Motor brake
-    pinMode(LMBrake, OUTPUT);
-    pinMode(RMBrake, OUTPUT);
-}
-
-
-/*
- * Move forward at given speed
- */
-void moveForward(int forwardSpeed) {
-  //Left motor forward @ speed
-  digitalWrite(LMDirection, HIGH);        //Establishes forward direction of motor1
-  digitalWrite(LMBrake, LOW);             //Disengage the Brake for Channel A
-
-  //Right motor forward @ speed
-  digitalWrite(RMDirection, HIGH);        //Establishes forward direction of motor2
-  digitalWrite(RMBrake, LOW);             //Disengage the Brake for Channel B
-
-  analogWrite(RMSpeed, forwardSpeed);     //Spins the motor on Channel B at full speed
-  analogWrite(LMSpeed, forwardSpeed);     //Spins the motor on Channel A at half speed
-}
-
-/*
- * Move backward at given speed
- */
-void moveBackward(int backwardSpeed) {
-  //Motor ! backward @ half speed
-  digitalWrite(LMDirection, LOW);         //Establishes backward direction of Channel B
-  digitalWrite(LMBrake, LOW);             //Disengage the Brake for Channel B
-  analogWrite(LMSpeed, backwardSpeed);              //Spins the motor on Channel B at half speed
-
-  //Motor B backward @ half speed
-  digitalWrite(RMDirection, LOW);         //Establishes backward direction of Channel B
-  digitalWrite(RMBrake, LOW);             //Disengage the Brake for Channel B
-  analogWrite(RMSpeed, backwardSpeed);              //Spins the motor on Channel B at half speed
-}
-
-/*
- * Turn left at given speed
- */
-void turnLeft(int turnLSpeed) {
-  //Left motor forward @ speed
-  digitalWrite(LMDirection, HIGH);        //Establishes forward direction of motor1
-  digitalWrite(LMBrake, LOW);       //Disengage the Brake for Channel A
-  analogWrite(LMSpeed, turnLSpeed);            //Spins the motor on Channel A at half speed
-
-  //Right motor forward @ speed
-  digitalWrite(RMDirection, LOW);        //Establishes forward direction of motor2
-  digitalWrite(RMBrake, LOW);      //Disengage the Brake for Channel B
-  analogWrite(RMSpeed, turnLSpeed);      //Spins the motor on Channel B at full speed
-}
-
-/*
- * Turn right at given speed
- */
-void turnRight(int turnRSpeed) {
-  //Left motor forward @ speed
-  digitalWrite(RMDirection, HIGH);        //Establishes forward direction of motor1
-  digitalWrite(RMBrake, LOW);       //Disengage the Brake for Channel A
-  analogWrite(RMSpeed, turnRSpeed);            //Spins the motor on Channel A at half speed
-
-  //Right motor forward @ speed
-  digitalWrite(LMDirection, LOW);        //Establishes forward direction of motor2
-  digitalWrite(LMBrake, LOW);      //Disengage the Brake for Channel B
-  analogWrite(LMSpeed, turnRSpeed);      //Spins the motor on Channel B at full speed
-}
-
-void loop() {
-    while (mySerial.available() > 0) {
-        //Serial.println("Something is available");
-        char character = mySerial.read(); // Receive a single character from the software serial port
-        Data.concat(character); // Add the received character to the receive buffer
-
-        if (character == '\n') {
-            //Serial.print("Received: ");
-            //Serial.println(Data);
-            //mobileSpeed = mySerial.parseInt();
-            //Serial.println(mobileSpeed);
-
-            // Add your code to parse the received line here....
-            if (Data.substring(0, 1) == "D") {
-                Serial.println("Down");
-                moveForward(60);
-                //delay(30);
-            }else if (Data.substring(0, 1) == "U") {
-                Serial.println("Up");
-                moveBackward(60);
-                //delay(30);
-            }else if (Data.substring(0, 1) == "L") {
-                Serial.println("Left");
-                turnRight(60);
-                //delay(30);
-            }else if (Data.substring(0, 1) == "R") {
-                Serial.println("Right");
-                turnLeft(60);
-                //delay(30);
-            }
-
-            // Clear receive buffer so we're ready to receive the next line
-            Data = "";
-        }
-    }
-}


fixes for sd server example

fixes for sd server example

--- hardware/esp8266com/esp8266/libraries/ESP8266WebServer/examples/SDWebServer/SDWebServer.ino
+++ hardware/esp8266com/esp8266/libraries/ESP8266WebServer/examples/SDWebServer/SDWebServer.ino
@@ -87,12 +87,20 @@
     uint8_t obuf[WWW_BUF_SIZE];
     while (dataFile.available() > WWW_BUF_SIZE){
       dataFile.read(obuf, WWW_BUF_SIZE);
-      client.write(obuf, WWW_BUF_SIZE);
+      if(client.write(obuf, WWW_BUF_SIZE) != WWW_BUF_SIZE){
+        Serial.println("Sent less data than expected!");
+        dataFile.close();
+        return true;
+      }
     }
     //stream the last data left (size is at most WWW_BUF_SIZE bytes)
     uint16_t leftLen = dataFile.available();
     dataFile.read(obuf, leftLen);
-    client.write(obuf, leftLen);
+    if(client.write(obuf, leftLen) != leftLen){
+      Serial.println("Sent less data than expected!");
+      dataFile.close();
+      return true;
+    }

     dataFile.close();
     return true;
@@ -124,7 +132,7 @@
   while (WiFi.status() != WL_CONNECTED && i++ < 20) delay(500);

   //check if we have connected?
-  if(i == 20){
+  if(i == 21){
     Serial.print("Could not connect to");
     Serial.println(ssid);
     //stop execution and wait forever


changed colors from raspi

changed colors from raspi

--- circadian_hallway_cycle_colors/circadian_hallway_cycle_colors.ino
+++ circadian_hallway_cycle_colors/circadian_hallway_cycle_colors.ino
@@ -18,7 +18,7 @@

 //Evening colors defined here
 #define C1_R 200
-#define C1_G 0
+#define C1_G 10
 #define C1_B 0

 #define C2_R 225
@@ -33,8 +33,8 @@
 #define C4_G 30
 #define C4_B 0

-#define C5_R 200
-#define C5_G 00
+#define C5_R 150
+#define C5_G 10
 #define C5_B 0

 void setup()


Add support for DCD always on / follow remote carrier to menu and Hayes (at&c0/1)

--- MicroView/WiFiModem-Menu/WiFiModem-Menu.ino
+++ MicroView/WiFiModem-Menu/WiFiModem-Menu.ino
@@ -19,7 +19,6 @@
 // Defining HAYES enables Hayes commands and disables the 1) and 2) menu options for telnet and incoming connections.
 // This is required to ensure the compiled code is <= 30,720 bytes
 //#define HAYES
-//#define ENABLE_C64_DCD
 #include <MicroView.h>
 #include <elapsedMillis.h>
 #include <SoftwareSerial.h>
@@ -30,7 +29,7 @@

 ;  // Keep this here to pacify the Arduino pre-processor

-#define VERSION "0.06"
+#define VERSION "0.07b1"

 // Configuration 0v3: Wifi Hardware, C64 Software.

@@ -89,6 +88,7 @@
 #define ADDR_MODEM_S0_AUTOANS   14
 #define ADDR_MODEM_S2_ESCAPE    15
 #define ADDR_MODEM_DCD_INVERTED 16
+#define ADDR_MODEM_DCD          17

 #define ADDR_HOST_AUTO          99     // Autostart host number
 #define ADDR_HOSTS              100    // to 299 with ADDR_HOST_SIZE = 40 and ADDR_HOST_ENTRIES = 5
@@ -100,10 +100,8 @@
 boolean Modem_isConnected = false;
 boolean Modem_isRinging = false;
 boolean Modem_EchoOn = true;
-//boolean Modem_EchoOn = true;
 boolean Modem_VerboseResponses = true;
 boolean Modem_QuietMode = false;
-boolean Modem_isDcdInverted = false;
 boolean Modem_S0_AutoAnswer = false;
 char    Modem_S2_EscapeCharacter = '+';
 #endif    // HAYES
@@ -118,6 +116,8 @@
 #define TIMEDOUT  -1
 boolean baudMismatch = (BAUD_RATE != WiFly_BAUD_RATE ? 1 : 0);
 boolean Modem_flowControl = false;   // for &K setting.
+boolean Modem_isDcdInverted = false;
+boolean Modem_DCDFollowsRemoteCarrier = false;    // &C

 // PETSCII state
 boolean petscii_mode = EEPROM.read(ADDR_PETSCII);
@@ -142,6 +142,16 @@
     uView.begin(); // begin of MicroView
     uView.setFontType(0);
     uView.clear(ALL); // erase hardware memory inside the OLED controller
+
+    pinModeFast(C64_DCD, OUTPUT);
+    Modem_DCDFollowsRemoteCarrier = EEPROM.read(ADDR_MODEM_DCD);
+
+    if (Modem_DCDFollowsRemoteCarrier) {
+      digitalWriteFast(C64_DCD, Modem_ToggleCarrier(false));
+    }
+    else {
+      digitalWriteFast(C64_DCD, Modem_ToggleCarrier(true));
+    }

     BAUD_RATE = (EEPROM.read(ADDR_BAUD_LO) * 256 + EEPROM.read(ADDR_BAUD_HI));
     if (BAUD_RATE != 1200 && BAUD_RATE != 2400 && BAUD_RATE != 4800 && BAUD_RATE != 9600 && BAUD_RATE != 19200)
@@ -202,7 +212,7 @@
         // Force CTS to defaults on both sides to start, so data can get through
         digitalWriteFast(WIFI_CTS, LOW);
         digitalWriteFast(C64_CTS, HIGH);  // C64 is inverted
-
+
         //WifiSerial.begin(WiFly_BAUD_RATE);

   /*
@@ -246,10 +256,6 @@
         baudMismatch = (BAUD_RATE != WiFly_BAUD_RATE ? 1 : 0);

         wifly.close();
-
-#ifdef ENABLE_C64_DCD
-        digitalWriteFast(C64_DCD, true);    // true = no carrier
-#endif

 #ifndef HAYES
         Modem_flowControl = EEPROM.read(ADDR_MODEM_FLOW);
@@ -330,9 +336,11 @@
         C64Println(F("2. Change SSID"));
         sprintf_P(temp,PSTR("3. %s flow control"),Modem_flowControl == true ? "Disable" : "Enable");
         C64Println(temp);
-        C64Println(F("4. Autostart Options"));
-        C64Println(F("5. Direct Terminal Mode (Debug)"));
-        C64Println(F("6. Return to Main Menu"));
+        sprintf_P(temp,PSTR("4. %s DCD always on"),Modem_DCDFollowsRemoteCarrier == false ? "Disable" : "Enable");
+        C64Println(temp);
+        C64Println(F("5. Autostart Options"));
+        C64Println(F("6. Direct Terminal Mode (Debug)"));
+        C64Println(F("7. Return to Main Menu"));
         C64Println();
         C64Print(F("Select: "));

@@ -347,23 +355,34 @@
         case '2': ChangeSSID();
             break;

-#ifndef HAYES
         case '3':
             Modem_flowControl = !Modem_flowControl;
             updateEEPROMByte(ADDR_MODEM_FLOW,Modem_flowControl);
             break;

-        case '4': ConfigureAutoStart();
-            break;
-#endif
+        case '4':
+            Modem_DCDFollowsRemoteCarrier = !Modem_DCDFollowsRemoteCarrier;
+
+            if (Modem_DCDFollowsRemoteCarrier) {
+              digitalWriteFast(C64_DCD, Modem_ToggleCarrier(false));
+            }
+            else {
+              digitalWriteFast(C64_DCD, Modem_ToggleCarrier(true));
+            }
+
+            updateEEPROMByte(ADDR_MODEM_DCD,Modem_DCDFollowsRemoteCarrier);
+            break;
+
+        case '5': ConfigureAutoStart();
+            break;

 /*      case '4': ConfigureBaud();
             break;*/

-        case '5': RawTerminalMode();
+        case '6': RawTerminalMode();
             return;

-        case '6': return;
+        case '7': return;

         case 8:
             SetPETSCIIMode(false);
@@ -674,7 +693,7 @@
 #ifdef HAYES
     if (!powerup) {
         char at_settings[20];
-        sprintf_P(at_settings, PSTR("ATE%dV%dQ%d&K%dS0=%d"),Modem_EchoOn,Modem_VerboseResponses,Modem_QuietMode,Modem_flowControl,Modem_S0_AutoAnswer);
+        sprintf_P(at_settings, PSTR("ATE%dV%dQ%d&C%d&K%dS0=%d"),Modem_EchoOn,Modem_VerboseResponses,Modem_QuietMode,Modem_DCDFollowsRemoteCarrier,Modem_flowControl,Modem_S0_AutoAnswer);
         C64Print(F("Init string: "));    C64Println(at_settings);
     }
 #endif
@@ -827,9 +846,8 @@
 #else
         DisplayBothP(temp);
 #endif
-#ifdef ENABLE_C64_DCD
-        digitalWriteFast(C64_DCD, false);
-#endif
+        if (Modem_DCDFollowsRemoteCarrier)
+            digitalWriteFast(C64_DCD, Modem_ToggleCarrier(true));
     }
     else
     {
@@ -839,6 +857,8 @@
 #else
         DisplayBoth(F("Connect Failed!"));
 #endif
+        if (Modem_DCDFollowsRemoteCarrier)
+            digitalWriteFast(C64_DCD, Modem_ToggleCarrier(false));
         return;
     }

@@ -945,9 +965,8 @@
 #else
     DisplayBoth(F("Connection closed"));
 #endif
-#ifdef ENABLE_C64_DCD
-    digitalWriteFast(C64_DCD, false);
-#endif
+    if (Modem_DCDFollowsRemoteCarrier)
+        digitalWriteFast(C64_DCD, Modem_ToggleCarrier(false));
 }

 // Raw Terminal Mode.  There is no escape.
@@ -1283,12 +1302,14 @@
     pinModeFast(C64_RI, OUTPUT);
     pinModeFast(C64_DSR, OUTPUT);
     pinModeFast(C64_DTR, OUTPUT);
-    pinModeFast(C64_DCD, OUTPUT);
+    //pinModeFast(C64_DCD, OUTPUT);
     pinModeFast(C64_RTS, INPUT);

     digitalWriteFast(C64_RI, LOW);
     digitalWriteFast(C64_DSR, HIGH);
-    digitalWriteFast(C64_DTR, Modem_ToggleCarrier(false));
+
+    if (Modem_DCDFollowsRemoteCarrier == true)
+      digitalWriteFast(C64_DCD, Modem_ToggleCarrier(false));

     Modem_EscapeCount = 0;

@@ -1302,6 +1323,7 @@
     Modem_S0_AutoAnswer = EEPROM.read(ADDR_MODEM_S0_AUTOANS);
     Modem_S2_EscapeCharacter = EEPROM.read(ADDR_MODEM_S2_ESCAPE);
     Modem_isDcdInverted = EEPROM.read(ADDR_MODEM_DCD_INVERTED);
+    Modem_DCDFollowsRemoteCarrier = EEPROM.read(ADDR_MODEM_DCD);
     Modem_ResetCommandBuffer();

     C64Println();
@@ -1361,20 +1383,7 @@
     Modem_S2_EscapeCharacter = '+';
     Modem_isDcdInverted = false;
     Modem_flowControl = false;
-}
-
-
-int Modem_ToggleCarrier(boolean isHigh)
-{
-    int result = 0; //_isDcdInverted ? (isHigh ? LOW : HIGH) : (isHigh ? HIGH : LOW);
-    switch (Modem_isDcdInverted)
-    {
-    case 0: result = (int)(!isHigh); break;
-    case 1: result = (int)(isHigh); break;
-    case 2: result = LOW;
-    }
-
-    return result;
+    Modem_DCDFollowsRemoteCarrier = false;
 }

 void Modem_Disconnect()
@@ -1399,7 +1408,8 @@
     if (wifly.available() == -1)
         wifly.close();

-    digitalWriteFast(C64_DTR, Modem_ToggleCarrier(false));
+    if (Modem_DCDFollowsRemoteCarrier)
+        digitalWriteFast(C64_DCD, Modem_ToggleCarrier(false));
 }

 // Validate and handle AT sequence  (A/ was handled already)
@@ -1570,7 +1580,7 @@
         char numString[6];

         int localport = atoi(&Modem_CommandBuffer[8]);
-        if (localport >= 1 && localport <= 65535)
+        if (localport >= 0 && localport <= 65535)
         {
               setLocalPort(localport);
               Modem_PrintOK();
@@ -1754,6 +1764,33 @@
                 case '&':
                 switch(Modem_CommandBuffer[i++])
                 {
+                    case 'C':
+                    switch(Modem_CommandBuffer[i++])
+                    {
+                        case '0':
+                        Modem_DCDFollowsRemoteCarrier = false;
+                        digitalWriteFast(C64_DCD, Modem_ToggleCarrier(true));
+                        break;
+
+                        case '1':
+                        Modem_DCDFollowsRemoteCarrier = true;
+                        if (Modem_isConnected) {
+                            digitalWriteFast(C64_DCD, Modem_ToggleCarrier(true));
+                        }
+                        else {
+                            digitalWriteFast(C64_DCD, Modem_ToggleCarrier(false));
+                        }
+                        break;
+
+                        case '?':
+                        C64Serial.print(Modem_DCDFollowsRemoteCarrier);
+                        break;
+
+                        default:
+                        errors++;
+                    }
+                    break;
+
                     case 'F':
                     Modem_LoadDefaults();
                     break;
@@ -1789,7 +1826,7 @@
                     updateEEPROMByte(ADDR_MODEM_QUIET, Modem_QuietMode);
                     updateEEPROMByte(ADDR_MODEM_S0_AUTOANS, Modem_S0_AutoAnswer);
                     updateEEPROMByte(ADDR_MODEM_S2_ESCAPE, Modem_S2_EscapeCharacter);
-                    updateEEPROMByte(ADDR_MODEM_DCD_INVERTED, Modem_isDcdInverted);
+                    updateEEPROMByte(ADDR_MODEM_DCD, Modem_DCDFollowsRemoteCarrier);

                     /*if (wifly.save())
                         Modem_PrintOK();
@@ -1956,7 +1993,8 @@
     {
         Modem_PrintResponse("2", F("RING"));

-        digitalWriteFast(C64_DCD, Modem_ToggleCarrier(true));
+        if (Modem_DCDFollowsRemoteCarrier)
+            digitalWriteFast(C64_DCD, Modem_ToggleCarrier(true));

         digitalWriteFast(C64_RI, HIGH);
         delay(250);
@@ -1971,7 +2009,8 @@

     DisplayBothP(temp);

-    digitalWriteFast(C64_DTR, Modem_ToggleCarrier(true));
+    if (Modem_DCDFollowsRemoteCarrier)
+        digitalWriteFast(C64_DCD, Modem_ToggleCarrier(true));

     Modem_isConnected = true;
     Modem_isCommandMode = false;
@@ -2520,3 +2559,17 @@
         }
     }
 }
+
+int Modem_ToggleCarrier(boolean isHigh)
+{
+    int result = 0; //_isDcdInverted ? (isHigh ? LOW : HIGH) : (isHigh ? HIGH : LOW);
+    switch (Modem_isDcdInverted)
+    {
+    case 0: result = (int)(!isHigh); break;
+    case 1: result = (int)(isHigh); break;
+    case 2: result = LOW;
+    }
+
+    return result;
+}
+


added improved debugging and state machine for string handling

--- controller/firmware/firmware.ino
+++ controller/firmware/firmware.ino
@@ -1,4 +1,8 @@
 #include <Adafruit_MCP23017.h>
+
+// NOTE: dacb has edited the Adafruit library to include a call to
+// Wire.setClock after Wire.begin to increase the i2c clock to 1.7M
+// which is an allowed rate in the MCP23017 datasheet

 #undef DEBUG
 #define DEBUG
@@ -58,19 +62,27 @@
 typedef struct string {
 	uint8_t pin;
 	unsigned int value;
+	unsigned int baseline_value;
+	enum string_state {
+		IDLE = 0,
+		EVENT = 1,
+		RECOVER = 2
+	} state;
 } string_t;

 #define STRINGS 8
 string_t strings[STRINGS] = {
-	{ 0,  0 },
-	{ 1,  0 },
-	{ 2,  0 },
-	{ 3,  0 },
-	{ 6,  0 },
-	{ 7,  0 },
-	{ 8,  0 },
-	{ 9,  0 }
+	{ 0,  0, 0, IDLE },
+	{ 1,  0, 0, IDLE },
+	{ 2,  0, 0, IDLE },
+	{ 3,  0, 0, IDLE },
+	{ 6,  0, 0, IDLE },
+	{ 7,  0, 0, IDLE },
+	{ 8,  0, 0, IDLE },
+	{ 9,  0, 0, IDLE }
 };
+
+#define STRING_LEVEL_EVENT_PERCENT_CHANGE 30

 void setup() {
 	int i;
@@ -110,17 +122,18 @@
 	// read initial values in, assumes all strings are unobstructed
 	for (i = 0; i < STRINGS; ++i) {
 		strings[i].value = analogRead(strings[i].pin);
+		strings[i].baseline_value = strings[i].value;
 	}

 #ifdef DEBUG
 	Serial1.println("done");

-	Serial1.println("analog values for air strings:");
+	Serial1.println("analog baseline values for air strings:");
 	for (i = 0; i < STRINGS; ++i) {
 		Serial1.print("string ");
 		Serial1.print(i, DEC);
 		Serial1.print(": ");
-		Serial1.println(strings[i].value, DEC);
+		Serial1.println(strings[i].baseline_value, DEC);
 	}
 #endif
 }
@@ -137,7 +150,7 @@
 	gpioAB[1] = mcp1.readGPIOAB();

 	// process the encoders
-	for (i == 0; i < ENCODERS; ++i) {
+	for (i = 0; i < ENCODERS; ++i) {
 		if (encoders[i].mcpX == &mcp0) {
 			A = bitRead(gpioAB[0], encoders[i].pinA);
 			B = bitRead(gpioAB[0], encoders[i].pinB);
@@ -151,6 +164,12 @@
 		// like report the state change over midi
 		if (sw != encoders[i].sw) {
 			encoders[i].sw = sw;
+#ifdef DEBUG
+			Serial1.print("encoder ");
+			Serial1.print(i, DEC);
+			Serial1.print("switch state change: ");
+			Serial1.println(sw, DEC);
+#endif
 		}
 		// the encoder has changed state
 		// increase?
@@ -160,6 +179,12 @@
 				encoders[i].value += 1;
 				if (encoders[i].value > encoders[i].max_value)
 					encoders[i].value = encoders[i].max_value;
+#ifdef DEBUG
+				Serial1.print("encoder ");
+				Serial1.print(i, DEC);
+				Serial1.print("value change (+1): ");
+				Serial1.println(encoders[i].value, DEC);
+#endif
 			}
 		}
 		// decrease?
@@ -167,8 +192,15 @@
 			encoders[i].B = !encoders[i].B;
 			if (encoders[i].B && !encoders[i].A) {
 				encoders[i].value -= 1;
-			if (encoders[i].value < encoders[i].min_value)
-				encoders[i].value = encoders[i].min_value;
+				if (encoders[i].value < encoders[i].min_value)
+					encoders[i].value = encoders[i].min_value;
+#ifdef DEBUG
+				Serial1.print("encoder ");
+				Serial1.print(i, DEC);
+				Serial1.print("value change (-1): ");
+				Serial1.println(encoders[i].value, DEC);
+#endif
+			}
 		}
 	}

@@ -185,11 +217,49 @@
 		// like report the state change over midi
 		if (sw != buttons[i].sw) {
 			buttons[i].sw = sw;
+#ifdef DEBUG
+			Serial1.print("button ");
+			Serial1.print(i, DEC);
+			Serial1.print("state change: ");
+			Serial1.println(sw, DEC);
+#endif
 		}
 	}

 	// this needs to do something with the new value
 	for (i = 0; i < STRINGS; ++i) {
-		strings[i].value = analogRead(strings[i].pin);
+		event_magnitude = 0;
+		value = analogRead(strings[i].pin);
+		// if we have deviated more than STRING_LEVEL_EVENT_PERCENT_CHANGE% of baseline
+		// report a change
+		if (strings[i].state == IDLE && value < strings[i].baseline_value - (strings[i].baseline_value / STRING_LEVEL_EVENT_PERCENT_CHANGE)) {
+			strings[i].state = EVENT;
+			strings[i].value = value;
+#ifdef DEBUG
+			Serial1.print("string ");
+			Serial1.print(i, DEC);
+			Serial1.print("event begins");
+#endif
+		} else if (strings[i].state == EVENT) {
+			// if value begins to recover, put us in recover state
+			if (value > strings[i].value) {
+				int event_magnitude = strings[i].baseline_value - strings[i].value;
+				strings[i].state = RECOVER;
+#ifdef DEBUG
+				Serial1.print("string ");
+				Serial1.print(i, DEC);
+				Serial1.print("event with magnitude: ");
+				Serial1.println(event_magnitude, DEC);
+#endif
+			}
+		// if we are in recovery state and the analog voltage has reached baseline again IDLE the event
+		} else if (strings[i].state == RECOVER && value >  strings[i].baseline_value - (strings[i].baseline_value / STRING_LEVEL_EVENT_PERCENT_CHANGE)) {
+			strings[i].state = IDLE;
+#ifdef DEBUG
+			Serial1.print("string ");
+			Serial1.print(i, DEC);
+			Serial1.println("is idle again");
+#endif
+		}
 	}
 }


Make wait times shorter in the firmware

Make wait times shorter in the firmware

--- particle-gui/firmware/setup.ino
+++ particle-gui/firmware/setup.ino
@@ -229,8 +229,8 @@
                 statuses[1] == String("Deleted")) {
           Particle.disconnect();
      }
-    // Wait 5 seconds
-    delay(5000);
+    // Wait 2 seconds
+    delay(2000);
 /* RETRY CONNECTION WITH Wi-Fi - END */

@@ -247,8 +247,8 @@
         Particle.publish("sendSocketInformation", jsonSendSocketInformation, PRIVATE);
     }

-    // Wait 5 seconds
-    delay(5000);
+    // Wait 2 seconds
+    delay(2000);

     if (statuses[1] == String("Active")) {
         // Send reading data
@@ -262,8 +262,8 @@
         Particle.publish("sendSocketInformation", jsonSendSocketInformation, PRIVATE);
     }

-    // Wait 5 seconds
-    delay(5000);
+    // Wait 2 seconds
+    delay(2000);

     if (statuses[0] != String("Deleted")) {
         // Send auth data
@@ -274,8 +274,8 @@
         Particle.publish("getServerInformation", jsonGetServerInformation, PRIVATE);
     }

-    // Wait 5 seconds
-    delay(5000);
+    // Wait 2 seconds
+    delay(2000);

     if (statuses[1] != String("Deleted")) {
         // Send auth data
@@ -287,8 +287,8 @@

     }

-    // Wait 5 seconds
-    delay(5000);
+    // Wait 2 seconds
+    delay(2000);

 /* SEND AND GET INFORMATION FROM SERVER - END */
 }


Update ArduCAM_Mini_2MP_OV2640_functions.ino

--- ArduCAM/examples/mini/ArduCAM_Mini_2MP_OV2640_functions/ArduCAM_Mini_2MP_OV2640_functions.ino
+++ ArduCAM/examples/mini/ArduCAM_Mini_2MP_OV2640_functions/ArduCAM_Mini_2MP_OV2640_functions.ino
@@ -49,7 +49,7 @@
 Serial.println(F("ACK CMD ArduCAM Start! END"));
 // set the CS as an output:
 pinMode(CS, OUTPUT);
-digitalWrite(CS,HIGH);
+digitalWrite(CS, HIGH);
 // initialize SPI:
 SPI.begin();
   //Reset the CPLD


Manual offset example warning

Manual offset example warning

--- examples/Manual_Offset_Calibration/Manual_Offset_Calibration.ino
+++ examples/Manual_Offset_Calibration/Manual_Offset_Calibration.ino
@@ -1,3 +1,8 @@
+/*
+  !!! This example is too simple. It is better to make multiple
+  readings and calculate a more precise valie for offset calibration
+*/
+

 #include<CS5490.h>


Fixed upload bug for WiFi setup

Fixed upload bug for WiFi setup

--- files/template_photonik/template_photonik_wifi/template_photonik_wifi.ino
+++ files/template_photonik/template_photonik_wifi/template_photonik_wifi.ino
@@ -6,100 +6,105 @@
 Author: Jan Wirwahn
 Note: Sketch for SB-Photonik-WiFi
 */
-
 #include <Wire.h>
 #include <SPI.h>
-#include <EthernetV2_0.h>
+#include <Adafruit_CC3000.h>
 #include <DHT.h>
 #include <Barometer.h>
 #include <Digital_Light_TSL2561.h>
-#include <avr/wdt.h>
+//#include <avr/wdt.h>

 //SenseBox ID

 //Sensor IDs
+
+// WLAN parameters
+#define WLAN_SSID       "WiFi_Name"           // cannot be longer than 32 characters!
+#define WLAN_PASS       "WiFi_Password"
+// Security can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2
+#define WLAN_SECURITY   WLAN_SEC_WPA2
+
+// These are the interrupt and control pins
+#define ADAFRUIT_CC3000_IRQ   3
+#define ADAFRUIT_CC3000_VBAT  5
+#define ADAFRUIT_CC3000_CS    10
+#define IDLE_TIMEOUT_MS  3000
+// Use hardware SPI for the remaining pins
+// On an UNO, SCK = 13, MISO = 12, and MOSI = 11
+Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT,
+                                         SPI_CLOCK_DIVIDER); // you can change this clock speed
+//Server values
+#define WEBSITE "www.opensensemap.org"
+uint32_t ip = 2159055603;

 //Sensor pin settings
 #define UVPIN A0
 #define DHTPIN A1
 #define DHTTYPE DHT11
-//Ethernet shield settings
-#define W5200_CS 10
-#define SDCARD_CS 4
-
-//Network settings
-IPAddress ip(192,168,178,111);//If DHCP is disabled, specify an IP according to your network settings
-byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
-char server[] = "opensensemap.org";
-EthernetClient client;

 String currentSensorId = TEMPERATURESENSOR_ID;
-float temperature;
-float humidity;
-float pressure;
+float temperature, humidity, pressure;
+unsigned long lux;
+int analogUvLight,contLen;
+
+short phenomenonCount = 5; //1=temp,2=humi,3=pressure,4=lux,5=UV
+int sampleType = 1; //begin with temperature
+boolean uploadSuccess = true;
+String sensorSample,jsonData;

 DHT dht(DHTPIN, DHTTYPE);
 Barometer barometer;

-//Variables for time sync and upload intervall
-const unsigned long postingInterval = 10*1000*60; //1 minute
-unsigned long lastConnectionTime = 0;
-boolean lastConnected = false;
-boolean uploadSuccess = true;
-String sensorSample;
-int sampleType = 1; //1=temp,2=humi,3=pressure,4=lux,5=UV
-
-void setup(){
-  Wire.begin();
-  Serial.begin(9600);
-  //Setup chip select and deselect the SD card
-  pinMode(SDCARD_CS,OUTPUT);
-  digitalWrite(SDCARD_CS,HIGH);
-  delay(500);
-  // start the Ethernet connection
-  if (Ethernet.begin(mac) == 0) {
-    Serial.println("Failed to configure Ethernet using DHCP.");
-    //If DHCP is disabled, use static IP
-    Ethernet.begin(mac, ip);
-  }else Serial.println("DHCP setup successful.");
-  //Print the IP to serial port
-  Serial.print("My IP address: ");
-  for (byte thisByte = 0; thisByte < 4; thisByte++) {
-    // print the value of each byte of the IP address:
-    Serial.print(Ethernet.localIP()[thisByte], DEC);
-    Serial.print(".");
-  }
-  Serial.println("STARTING UP");
+void setup(void)
+{
+  Serial.begin(115200);
+  Serial.println(F("\nInitializing WiFi..."));
+  if (!cc3000.begin())
+  {
+    Serial.println(F("failed! Check your wiring?"));
+    while(1);
+  }
+
+  Serial.print(F("\nAttempting to connect to ")); Serial.println(WLAN_SSID);
+  if (!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) {
+    Serial.println(F("Failed!"));
+    while(1);
+  }
+
+  Serial.println(F("Connected!"));
+
+  /* Wait for DHCP to complete */
+  Serial.println(F("Requesting DHCP"));
+  while (!cc3000.checkDHCP())
+  {
+    delay(100); // ToDo: Insert a DHCP timeout!
+  }
+  ip = 0;
+  // Try looking up the website's IP address
+  Serial.print(WEBSITE); Serial.print(F(" -> "));
+  while (ip == 0) {
+    if (! cc3000.getHostByName(WEBSITE, &ip)) {
+      Serial.println(F("Couldn't resolve!"));
+    }
+    delay(500);
+  }
+  cc3000.printIPdotsRev(ip);
+  Serial.println("\nSTARTING UP");
   barometer.init();
   dht.begin();
   TSL2561.init();
 }

-void loop(){
-  // if there's incoming data from the net connection.
-  // send it out the serial port.  This is for debugging purposes only
-  if (client.available()) {
-    char c = client.read();
-    Serial.print(c);
-  }
-  // if there's no net connection, but there was one last time
-  // through the loop, then stop the client:
-  if (!client.connected() && lastConnected) {
-    Serial.println();
-    Serial.println();
-    Serial.println("...stopping client!");
-    client.stop();
-  }
-  //If last upload was successful, switch case to select the next sensor
+void loop(void)
+{
   if (uploadSuccess){
-    Serial.println();
-    delay(1000);
+    Serial.print("Reading sensor...");
     sensorSample = "";
     switch (sampleType)
     {
       case 1:
-        //temperature = dht.readTemperature();
-        temperature = barometer.bmp085GetTemperature(barometer.bmp085ReadUT());
+        temperature = dht.readTemperature();
+        //temperature = barometer.bmp085GetTemperature(barometer.bmp085ReadUT());
         sensorSample = floatToString(temperature,0);
         currentSensorId = TEMPERATURESENSOR_ID;
         break;
@@ -121,25 +126,75 @@
         currentSensorId = LUXSENSOR_ID;
         break;
       case 5:
-        analogLight = analogRead(UVPIN);
-        sensorSample = (String)calcUVIndex(analogLight);
+        analogUvLight = analogRead(UVPIN);
+        sensorSample = (String)calcUVIndex(analogUvLight);
         currentSensorId = UVSENSOR_ID;
         break;
     }
-  }
-  // if you're not already connected, and 60 seconds have passed since
-  // your last connection, then connect again and send data:
-  uploadSuccess = false;
-  if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) {
-    Serial.println("-----------------------------------");
-    Serial.print("Connecting and posting sensor sample (case ");
-    Serial.print(sampleType);
-    Serial.print(")...");
-    Serial.println();
-    postObservation(sensorSample, currentSensorId, SENSEBOX_ID);
-  }
-  // store the state of the connection for next time through the loop
-  lastConnected = client.connected();
+    Serial.println("done...................");
+  }
+
+  jsonData = "{\"value\":";
+  jsonData += sensorSample;
+  jsonData += "}";
+  Serial.println(jsonData);
+  contLen = jsonData.length();
+  Adafruit_CC3000_Client client = cc3000.connectTCP(ip, 8000);
+
+  if (client.connected()) {
+    /*
+    clientclient.print(F("GET "));
+    client.print(F("/"));
+    client.print(F(" HTTP/1.1\r\n"));
+    client.print(F("Host: ")); client.fastrprint(WEBSITE); .fastrprint(F("\r\n"));
+    www.print(F("\r\n"));
+    www.println();
+    */
+    client.print("POST /boxes/");
+    client.print(SENSEBOX_ID);
+    client.print("/");
+    client.print(currentSensorId);
+    client.print(" HTTP/1.1\r\n");
+    client.println("Host: opensensemap.org");
+    client.println("Content-Type: application/json");
+    client.print("Content-Length: ");
+    client.println(contLen);
+    client.println("Connection: close");
+    client.println();
+    client.print(jsonData);
+    client.println();
+    Serial.println("done!");
+    uploadSuccess = true;
+  } else {
+    Serial.println(F("Connection failed"));
+    uploadSuccess = false;
+    return;
+  }
+
+  Serial.println(F("-------------------------------------"));
+
+  /* Read data until either the connection is closed, or the idle timeout is reached. */
+  unsigned long lastRead = millis();
+  while (client.connected() && (millis() - lastRead < IDLE_TIMEOUT_MS)) {
+    while (client.available()) {
+      char c = client.read();
+      Serial.print(c);
+      lastRead = millis();
+    }
+  }
+  client.close();
+  Serial.println(F("-------------------------------------"));
+  if (uploadSuccess){
+    if (sampleType == phenomenonCount) {
+      sampleType = 1;
+    }else sampleType++;
+  }
+  /* You need to make sure to clean up after yourself or the CC3000 can freak out */
+  /* the next time your try to connect ... */
+  Serial.println(F("\n\nDisconnecting"));
+//  cc3000.disconnect();
+
+ delay(1000);
 }

 String floatToString(float number, int precision)
@@ -149,7 +204,7 @@
   //only temperature (case 1) has a decimal place
   //if (sampleType == 1) prec = 1; else prec = 0;
   char tempChar[10];
-  dtostrf(number, 3, precision, tempChar);
+  dtostrf(number, 1, precision, tempChar);
   stringNumber += tempChar;
   return stringNumber;
 }
@@ -169,53 +224,4 @@
   else if (analogValue<221) uvi = 10;
   else if (analogValue<240) uvi = 11;
   return uvi;
-}
-
-//Method for posting a measurement to OSM server
-void postObservation(String measurement, String sensorId, String boxId)
-{
-  //if (measurement=="") return;
-  wdt_enable(WDTO_8S);
-  //json must look like {"value":"12.5"}
-  String valueJson = "{\"value\":";
-  valueJson += measurement;
-  valueJson += "}";
-  Serial.println(valueJson);
-  //post observation to: http://opensensemap.org:8000/boxes/boxId/sensorId
-  // if you get a connection, report back via serial:
-  wdt_reset();
-  if (client.connect(server, 8000))
-  {
-    Serial.print("connected...");
-    Serial.println();
-    // Make a HTTP Post request:
-    client.print("POST /boxes/");
-    client.print(boxId);
-    client.print("/");
-    client.print(sensorId);
-    client.println(" HTTP/1.1");
-    // Send the required header parameters
-    client.println("Host:opensensemap.org");
-    client.println("Content-Type: application/json");
-    client.println("Connection: close");
-    client.print("Content-Length: ");
-    client.println(valueJson.length());
-    client.println();
-    client.print(valueJson);
-    client.println();
-    Serial.println("done!");
-    uploadSuccess = true;
-    //Change case
-    if (sampleType == 5) {
-      sampleType = 1;
-      // remember the time that the connection was made or attempted
-      lastConnectionTime = millis();
-    }else sampleType++;
-  }else
-  {
-    // stop the client if you couldn't make a connection !
-    Serial.println("failed...disconnecting.");
-    client.stop();
-  }
-  wdt_disable();
-}
+}


Workaround for backlight hum. Set to 255.

--- src/Arduino/_23cm-trx/loops.ino
+++ src/Arduino/_23cm-trx/loops.ino
@@ -204,7 +204,7 @@
       break;
       // ------------------------------------------------ Backlight brightness
       case 4: {
-        int turn = selectInt("Backlight", "  ", lcdBacklightBrightness , 10, 250, 10);
+        int turn = selectInt("Backlight", "  ", lcdBacklightBrightness , 5, 255, 10);
         if (turn == 0) { exit = true; }
         else { menuitem = constrain(menuitem + turn, 0, max_menu_items); }
       }


Flushed Motor Code

Flushed Motor Code

--- ElevatorGUI/ElevatorController_arduino/ArielsMotorCode/ArielsMotorCode.ino
+++ ElevatorGUI/ElevatorController_arduino/ArielsMotorCode/ArielsMotorCode.ino
@@ -82,6 +82,8 @@
         //Serial.println(micros()-t);
         Serial.println(x);
       }
+
+      Serial.flush();
   }
 }


Delay CAN messages to 20 per second

Delay CAN messages to 20 per second

--- GyroSketch/GyroSketch.ino
+++ GyroSketch/GyroSketch.ino
@@ -62,6 +62,8 @@
 int8_t loY;
 int8_t hiZ;
 int8_t loZ;
+
+unsigned long lastTime = millis();

 // ================================================================
 // ===               INTERRUPT DETECTION ROUTINE                ===
@@ -280,8 +282,14 @@

         //Create package to send over CAN
         unsigned char CANbuf[8] = {hiDir, loDir, hiX, loX, hiY, loY, hiZ, loZ};
+
         //Send data over CAN
-        CAN.sendMsgBuf(CAN_ID, 0, 8, CANbuf); //send out the package above to the bus and tell other devices this is a standard frame from 0x00.
+        if (millis() - lastTime > 50) {
+          lastTime = millis();
+          CAN.sendMsgBuf(CAN_ID, 0, 8, CANbuf); //send out the package above to the bus and tell other devices this is a standard frame from 0x00.
+        } else {
+          Serial.println("No CAN message sent - time limit not exceded (this is okay)");
+        }

         // blink LED to indicate activity
         blinkState = !blinkState;


Added float example to StringConstructor

This example has been added according to #3264

--- build/shared/examples/08.Strings/StringConstructors/StringConstructors.ino
+++ build/shared/examples/08.Strings/StringConstructors/StringConstructors.ino
@@ -66,6 +66,14 @@
   // prints "123456" or whatever the value of millis() is:
   Serial.println(stringOne);

+  //using a float and the right decimal places:
+  stringOne = String(5.698, 3);
+  Serial.println(stringOne);
+
+  //using a float and less decimal places to use rounding:
+  stringOne = String(5.698, 2);
+  Serial.println(stringOne);
+
   // do nothing while true:
   while (true);


Clean-up

Clean-up

--- examples/Test_InputDebounce_Inheritance/Test_InputDebounce_Inheritance.ino
+++ examples/Test_InputDebounce_Inheritance/Test_InputDebounce_Inheritance.ino
@@ -19,8 +19,10 @@
 {
 public:
   MyInputDebounce(int8_t pinIn = -1, unsigned long debDelay = DEFAULT_INPUT_DEBOUNCE_DELAY, PinInMode pinInMode = PIM_INT_PULL_UP_RES)
-  : InputDebounce(pinIn, debDelay, pinInMode)
-  , _pinLED(-1)
+    : InputDebounce(pinIn, debDelay, pinInMode)
+    , _pinLED(-1)
+  {}
+  virtual ~MyInputDebounce()
   {}
   void setPinLED(int8_t pinLED)
   {


Arduino update

Arduino update

--- device/arduino/navi_v2ArduinoControl/navi_v2ArduinoControl.ino
+++ device/arduino/navi_v2ArduinoControl/navi_v2ArduinoControl.ino
@@ -2,7 +2,9 @@
 /*
 Magnometer: VIN: 3.3V  SDA: 20  SCL: 21
 Compass: VIN: 3.3V  RX: 11  TX: 12
-Sonars:
+sonar_value: Top from l to r: 24,26,28,30
+        botton from l to r: 22,23,25,27,29
+Motor - R: 9  L: 10

 */
 ///////////////////////////////////////////////
@@ -11,14 +13,15 @@
 #include <NewPing.h>
 #include <TinyGPS++.h>
 #include <SoftwareSerial.h>
+#include <Adafruit_HMC5883_U.h>
 #include <Adafruit_Sensor.h>
-#include <Adafruit_HMC5883_U.h>
+

 int gamemode = 1; // Enables the FRCmotor library

 //Magnometer
 Adafruit_HMC5883_Unified mag = Adafruit_HMC5883_Unified(12345);
-double compass_theta= 0;
+float heading= 0;

 //Compass
 static const int RXPin = 11, TXPin = 12;
@@ -31,27 +34,26 @@
 //Sonar
 #define SONAR_NUM     9 // Number of sensors.
 #define MAX_DISTANCE 200 // Maximum distance (in cm) to ping.
-#define PING_INTERVAL 33 // Milliseconds between sensor pings (29ms is about the min to avoid cross-sensor echo).
-unsigned long pingTimer[SONAR_NUM]; // Holds the times when the next ping should happen for each sensor.
-unsigned int cm[SONAR_NUM];         // Where the ping distances are stored.
-unsigned int sonars[SONAR_NUM];
+#define PING_INTERVAL 29 // Milliseconds between sensor pings (29ms is about the min to avoid cross-sensor echo).
+unsigned int sonar_value[SONAR_NUM] = {0,0,0,0,0,0,0,0,0};
+double lastPingTime;
 uint8_t currentSensor = 0;          // Keeps track of which sensor is active.

 NewPing sonar[SONAR_NUM] = {     // Sensor object array.
-  NewPing(22, 22, MAX_DISTANCE), // Each sensor's trigger pin, echo pin, and max distance to ping.
+  NewPing(24, 24, MAX_DISTANCE), // Each sensor's trigger pin, echo pin, and max distance to ping.
+  NewPing(26, 26, MAX_DISTANCE),
+  NewPing(28, 28, MAX_DISTANCE),
+  NewPing(30, 30, MAX_DISTANCE),
+  NewPing(22, 22, MAX_DISTANCE),
   NewPing(23, 23, MAX_DISTANCE),
-  NewPing(24, 24, MAX_DISTANCE),
   NewPing(25, 25, MAX_DISTANCE),
-  NewPing(26, 26, MAX_DISTANCE),
   NewPing(27, 27, MAX_DISTANCE),
-  NewPing(28, 28, MAX_DISTANCE),
-  NewPing(29, 29, MAX_DISTANCE),
-  NewPing(30, 30, MAX_DISTANCE)
+  NewPing(29, 29, MAX_DISTANCE)
 };

 //SerialRead/Write
 #define BUFSIZE 256
-#define SPEED_LIMIT 100.f
+#define SPEED_LIMIT 100
 #define RAMP_CONST 1 // Higher is faster

 const int safesize = BUFSIZE / 2;
@@ -60,7 +62,7 @@
 int available_bytes = 0;

 // Target and previous velocity arrays
-static float target_vel[] = {0.f , 0.f};
+static int target_vel[] = {0 , 0};

 //Motor Control
 FRCmotor leftMotor; //DECLARE LEFT MOTOR CONTROLLER
@@ -78,19 +80,30 @@

   ss.begin(GPSBaud);

-  pingTimer[0] = millis() + 75;           // First ping starts at 75ms, gives time for the Arduino to chill before starting.
-  for (uint8_t i = 1; i < SONAR_NUM; i++) // Set the starting time for each sensor.
-    pingTimer[i] = pingTimer[i - 1] + PING_INTERVAL;
-}
-
+  lastPingTime = millis() + 75;           // First ping starts at 75ms, gives time for the Arduino to chill before starting.
+}
+
+int prevMillis;
 void loop()
 {
+  prevMillis = millis();
+  Serial.print("Read: ");
   readSerial();
+  Serial.print(millis()-prevMillis);
+  prevMillis = millis();
+  Serial.print(" Move: ");
   moveMotor();
+  Serial.print(millis() - prevMillis);
+  prevMillis = millis();
+  Serial.print(" GPS: ");
   getGPS();
-  getSonars();
-  getCompass();
-  writeSerial();
+  Serial.print(millis() - prevMillis);
+  //prevMillis = millis();
+  //Serial.print(" Sonar: ");
+  getsonar_value();
+  Serial.println();
+  //getCompass();
+  //writeSerial();
 }

 void readSerial()
@@ -123,8 +136,10 @@

 void moveMotor()
 {
-  leftMotor.Set(int(target_vel[0] * 100));
-  rightMotor.Set(int(target_vel[1] * 100));
+  leftMotor.Set(-1*target_vel[0]);
+  rightMotor.Set(target_vel[1]);
+  //Serial.print(target_vel[0]);
+  //Serial.println(target_vel[1]);
 }

 void getGPS(){
@@ -134,39 +149,51 @@
   }
 }

-void getSonars(){
-  for (uint8_t i = 0; i < SONAR_NUM; i++) { // Loop through all the sensors.
-    if (millis() >= pingTimer[i]) {         // Is it this sensor's time to ping?
-      pingTimer[i] += PING_INTERVAL * SONAR_NUM;  // Set next time this sensor will be pinged.
-      if (i == 0 && currentSensor == SONAR_NUM - 1) oneSensorCycle(); // Sensor ping cycle complete, do something with the results.
-      sonar[currentSensor].timer_stop();          // Make sure previous timer is canceled before starting a new ping (insurance).
-      currentSensor = i;                          // Sensor being accessed.
-      cm[currentSensor] = 0;                      // Make distance zero in case there's no ping echo for this sensor.
-      sonar[currentSensor].ping_timer(echoCheck); // Do the ping (processing continues, interrupt will call echoCheck to look for echo).
-    }
-  }
-}
+void getsonar_value(){
+  if (millis() >= lastPingTime + PING_INTERVAL) {         // Is it this sensor's time to ping?
+    Serial.print(" Sonar Ping Time: ");
+    prevMillis = millis();
+    sonar[currentSensor].timer_stop();          // Make sure previous timer is canceled before starting a new ping (insurance).
+        Serial.print(millis()- prevMillis);
+
+    ++currentSensor;                            // Sensor being accessed.
+    if (currentSensor == SONAR_NUM) currentSensor = 0; // Sensor ping cycle complete, do something with the results.
+    sonar_value[currentSensor] = 0;                      // Make distance zero in case there's no ping echo for this sensor.
+    sonar[currentSensor].ping_timer(echoCheck); // Do the ping (processing continues, interrupt will call echoCheck to look for echo).
+    lastPingTime = millis();
+    Serial.print(millis()- prevMillis);
+  }
+}
+
 void echoCheck() { // If ping received, set the sensor distance to array.
   if (sonar[currentSensor].check_timer())
-    cm[currentSensor] = sonar[currentSensor].ping_result / US_ROUNDTRIP_CM;
-}
-void oneSensorCycle() {
-  for (uint8_t i = 0; i < SONAR_NUM; i++) {
-    sonars[i] = cm[i];
-  }
-}
+    sonar_value[currentSensor] = sonar[currentSensor].ping_result / US_ROUNDTRIP_CM;
+}
+
+
+
 void getCompass(){
   /* Get a new sensor event */
   sensors_event_t event;
   mag.getEvent(&event);
+
   //Calculate heading
-  compass_theta = atan2(event.magnetic.y, event.magnetic.x);
+  heading = atan2(event.magnetic.y, event.magnetic.x);
+
   //Magnetic field error in Piscataway
   //https://www.ngdc.noaa.gov/geomag-web/
   float declinationAngle = -0.22;
-  compass_theta += declinationAngle;
+  heading += declinationAngle;
+
+  if(heading < 0)
+    heading += 2*PI;
+
+  // Check for wrap due to addition of declination.
+  if(heading > 2*PI)
+    heading -= 2*PI;
+
   //Convert to degrees
-  compass_theta = compass_theta *180/M_PI;
+  heading = heading *180/M_PI;
 }

 char ftos [safesize];
@@ -175,17 +202,17 @@
   memset(write_buffer,'\0',BUFSIZE);
   for(int x = 0; x<SONAR_NUM;x++)
   {
-    sprintf(ftos,"%f",sonars[x]);
+    dtostrf(sonar_value[x] / 50.0 ,20,10,ftos);
     strcat(write_buffer, ftos);
     strcat(write_buffer, ",");
   }
-  sprintf(ftos,"%f",latitude);
+  dtostrf(latitude,20,10,ftos);
   strcat(write_buffer, ftos);
   strcat(write_buffer, ",");
-  sprintf(ftos,"%f",longitude);
+  dtostrf(longitude,20,10,ftos);
   strcat(write_buffer, ftos);
   strcat(write_buffer, ",");
-  sprintf(ftos,"%f",compass_theta);
+  dtostrf(heading,20,10,ftos);
   strcat(write_buffer, ftos);
   strcat(write_buffer, "\n");
   Serial.write(write_buffer);


Added a few firmware comments.

Added a few firmware comments.

--- firmware/TLCserial/TLCserial.ino
+++ firmware/TLCserial/TLCserial.ino
@@ -59,10 +59,16 @@
      You can optionally pass an initial PWM value (0 - 4095) for all channels.*/
   Tlc.init();
   Tlc.set(0, 4095);
+
+  // Set the differential transceiver to receive mode.
   digitalWrite(2, LOW);
   pinMode(2, OUTPUT);
+
+  // Setup the DMX interrupts / parsing code.
   DMXSerial.init(DMXReceiver);
   Tlc.set(1, 4095);
+
+  // Chill out.
   delay(500);
   Tlc.set(2, 4095);
 }


Tighten error handling a bit

Tighten error handling a bit

--- firmware/environmental-array.ino
+++ firmware/environmental-array.ino
@@ -35,7 +35,7 @@
 int co2SensorAddr   = 0x69;  // 0x68
 int serial0DataRate = 9600;
 int i2cDataRate     = CLOCK_SPEED_100KHZ; // CLOCK_SPEED_400KHZ
-const int MaxErrCnt = 10;
+const int MaxErrCnt = 8;
 const int CycleTimeS = 10;
 const char DataSource [] = "EnvSensorArray_1";

@@ -159,6 +159,7 @@
                 "! MS5637 FAIL! - PROM=[%04X,%04X,%04X,%04X,%04X,%04X,%04X]",
                 vals[0], vals[1], vals[2], vals[3], vals[4], vals[5], vals[6]);
             Particle.publish(DataSource, g_printbuf, 60, PRIVATE);
+            globalErrorCount++;
             delay(500);
         }
     }


Corrected Pins for Dilduino Hacker Port

Corrected Pins for Dilduino Hacker Port

--- Mod/E-Stim/TCDS__BASIC_POTENTIOMETER/TCDS__BASIC_POTENTIOMETER.ino
+++ Mod/E-Stim/TCDS__BASIC_POTENTIOMETER/TCDS__BASIC_POTENTIOMETER.ino
@@ -12,8 +12,8 @@

 // constants won't change. Used here to
 // set pin numbers:
-const int ledPin =  11;      // the number of the LED pin
-
+const int ledPin =  6;      // This is the Analog input
+const int inputPin = A8;
 // Variables will change:
 int ledState = LOW;             // ledState used to set the LED
 long previousMillis = 0;        // will store last time LED was updated
@@ -26,12 +26,21 @@
   // set the digital pin as output:
   pinMode(ledPin, OUTPUT);
   Serial.begin(9600);
+    pinMode(5, OUTPUT);
+
+    //Set up the multiplexer to choose the correct style of inputs on hacker port
+  pinMode(8, OUTPUT);
+  pinMode(12, OUTPUT);
+  digitalWrite(8, LOW);
+  digitalWrite(12, LOW);
+  pinMode(A8, INPUT);
+
 }

 void loop()
 {

-   int sensorValue = analogRead(A0);
+   int sensorValue = analogRead(inputPin); //Hooked up to potentiometer
    Serial.println(sensorValue);

   unsigned long currentMillis = millis();


Attempt to fix side scrolling

Attempt to fix side scrolling

--- libraries/BLE/examples/ble_uart_project_with_dfu_template/ble_uart_project_with_dfu_template.ino
+++ libraries/BLE/examples/ble_uart_project_with_dfu_template/ble_uart_project_with_dfu_template.ino
@@ -480,8 +480,11 @@
         Serial.println(F("Evt Pipe Status"));
         if (lib_aci_is_pipe_available(&aci_state, PIPE_UART_OVER_BTLE_UART_TX_TX) && (false == timing_change_done))
         {
-          lib_aci_change_timing_GAP_PPCP(); // change the timing on the link as specified in the nRFgo studio -> nRF8001 conf. -> GAP.
+          lib_aci_change_timing_GAP_PPCP();
+
+          // change the timing on the link as specified in the nRFgo studio -> nRF8001 conf. -> GAP.
           // Used to increase or decrease bandwidth
+
           timing_change_done = true;
         }
         break;
@@ -561,8 +564,9 @@
         Serial.println(aci_evt->params.pipe_error.error_code, HEX);

         //Increment the credit available as the data packet was not sent.
-        //The pipe error also represents the Attribute protocol Error Response sent from the peer and that should not be counted
-        //for the credit.
+        //The pipe error also represents the Attribute protocol Error Response
+        //sent from the peer and that should not be counted for the credit.
+
         if (ACI_STATUS_ERROR_PEER_ATT_ERROR != aci_evt->params.pipe_error.error_code)
         {
           aci_state.data_credit_available++;


Added flashing for Teensy LED in test mode

The Teensy amber LED is flashed while the test mode goes through each of the 8 colors. This gives a visual indication of test mode, even if no LED strips light.

--- TeensyStripController.ino
+++ TeensyStripController.ino
@@ -95,14 +95,14 @@
   //Initialize the led pin
   pinMode(LedPin,OUTPUT);

-  SetBlinkMode(0);
-
   //Initialize and find value of the test pin
   pinMode(TestPin,INPUT_PULLUP);
   if (! digitalRead(TestPin)) {
     // run test if button is grounded
     Test();
   }
+
+  SetBlinkMode(0);
 }

 //Main loop of the programm gets called again and again.
@@ -384,6 +384,13 @@
   for (int i=0; i < leds.numPixels(); i++) {
     leds.setPixel(i, color);
   }
+
+  // wait before turning on LEDs and also turn on indicator LED
+  delayMicroseconds(100000);
+  digitalWrite(LedPin,1);
   leds.show();
+
+  // wait for desginated timeout and then turn off indicator LED
   delayMicroseconds(wait);
+  digitalWrite(LedPin,0);
 }


Renamed the sketch

Renamed the sketch

--- Temperature_Read_Test.ino
+++ Temperature_Read_Test.ino
@@ -1,266 +0,0 @@
-
-
-/***************************************************
-  This is an example for the Adafruit Thermocouple Sensor w/MAX31855K
-
-  Designed specifically to work with the Adafruit Thermocouple Sensor
-  ----> https://www.adafruit.com/products/269
-
-  These displays use SPI to communicate, 3 pins are required to
-  interface
-  Adafruit invests time and resources providing this open source code,
-  please support Adafruit and open-source hardware by purchasing
-  products from Adafruit!
-
-  Written by Limor Fried/Ladyada for Adafruit Industries.
-  BSD license, all text above must be included in any redistribution
- ****************************************************/
-
-#include <SPI.h>
-#include "Adafruit_MAX31855.h"
-#include <Bridge.h>
-#include <Console.h>
-#include <PID_AutoTune_v0.h>
-#include <PID_v1.h>
-
-// So we can save and retrieve settings
-#include <EEPROM.h>
-
-// IO Pins for thermocouple
-#define DO   3
-#define CS   4
-#define CLK  5
-//Keys for the Bridge interface
-#define DEGF "degF"
-#define DEGC "degC"
-#define TARGEF "targetF"
-
-#define KP "kp"
-#define SP "sp"
-#define KI "ki"
-#define KD "kd"
-// Output Relay
-#define RelayPin 7
-
-// ************************************************
-// PID Variables and constants
-// ************************************************
-
-//Define Variables we'll be connecting to
-double Setpoint;
-double Input;
-double Output;
-
-volatile long onTime = 0;
-
-// pid tuning parameters
-double Kp;
-double Ki;
-double Kd;
-
-// EEPROM addresses for persisted data
-const int SpAddress = 0;
-const int KpAddress = 8;
-const int KiAddress = 16;
-const int KdAddress = 24;
-
-Adafruit_MAX31855 thermocouple(CLK, CS, DO);
-//Specify the links and initial tuning parameters
-PID myPID(&Input, &Output, &Setpoint, Kp, Ki, Kd, DIRECT);
-
-// 10 second Time Proportional Output window
-int WindowSize = 10000;
-unsigned long windowStartTime;
-
-// ************************************************
-// Auto Tune Variables and constants
-// ************************************************
-byte ATuneModeRemember=2;
-
-double aTuneStep=500;
-double aTuneNoise=1;
-unsigned int aTuneLookBack=20;
-
-boolean tuning = false;
-
-PID_ATune aTune(&Input, &Output);
-
-const int logInterval = 10000; // log every 10 seconds
-long lastLogTime = 0;
-
-// ************************************************
-// States for state machine
-// ************************************************
-enum operatingState { OFF = 0, SETP, RUN, TUNE_P, TUNE_I, TUNE_D, AUTO};
-operatingState opState = OFF;
-
-String setTemp = "";
-
-void setup() {
-  Bridge.begin();
-  Console.begin();
-  // Initialize Relay Control:
-  pinMode(RelayPin, OUTPUT);    // Output mode to drive relay
-  digitalWrite(RelayPin, LOW);  // make sure it is off to start
-
-  // Initialize the PID and related variables
-  LoadParameters();
-
-  // wait for MAX chip to stabilize
-  delay(500);
-  //Timer code, not sure if need
-  // Run timer2 interrupt every 15 ms
-  //TCCR4A = 0;
-  //TCCR4B = 1<<CS42 | 1<<CS41 | 1<<CS40;
-
-  //Timer2 Overflow Interrupt Enable
-  //TIMSK4 |= 1<<TOIE4;
-}
-
-// ************************************************
-// Timer Interrupt Handler
-//MIGHT NEED TO DO WORK HERE, MIGHT NEED DIFFERENT TIMER
-// ************************************************
-/*SIGNAL(TIMER1_OVF_vect)
-{
-  if (opState == OFF)
-  {
-    digitalWrite(RelayPin, LOW);  // make sure relay is off
-  }
-  else
-  {
-    //DriveOutput();
-  }
-}*/
-
-void loop() {
-  char tempSetBuf[4];
-   if (Bridge.get("setTemp", tempSetBuf, 4) > 0) {
-     setTemp = String(tempSetBuf);
-     //Console.println(setTemp);
-     //Bridge.put("targetF=", setTemp);
-   }
-
-   double c = thermocouple.readCelsius();
-   if (isnan(c)) {
-     //Console.println("Something wrong with thermocouple!");
-   } else {
-
-     //We're getting good data.  Make is so the bridge can see it
-     double tempF = thermocouple.readFarenheit();
-     if (!setTemp.equals("")) {
-       Bridge.put(TARGEF, setTemp);
-     }
-     Bridge.put(DEGF, doubleToString(tempF, 2));
-
-   }
-   delay(1000);
-
-}
-
-void Off() {
-  myPID.SetMode(MANUAL);
-  digitalWrite(RelayPin, LOW);
-}
-
-// ************************************************
-// Save any parameter changes to EEPROM
-// ************************************************
-void SaveParameters()
-{
-   if (Setpoint != EEPROM_readDouble(SpAddress))
-   {
-      EEPROM_writeDouble(SpAddress, Setpoint);
-   }
-   if (Kp != EEPROM_readDouble(KpAddress))
-   {
-      EEPROM_writeDouble(KpAddress, Kp);
-   }
-   if (Ki != EEPROM_readDouble(KiAddress))
-   {
-      EEPROM_writeDouble(KiAddress, Ki);
-   }
-   if (Kd != EEPROM_readDouble(KdAddress))
-   {
-      EEPROM_writeDouble(KdAddress, Kd);
-   }
-}
-
-// ************************************************
-// Load parameters from EEPROM
-// ************************************************
-void LoadParameters()
-{
-  // Load from EEPROM
-   Setpoint = EEPROM_readDouble(SpAddress);
-   Kp = EEPROM_readDouble(KpAddress);
-   Ki = EEPROM_readDouble(KiAddress);
-   Kd = EEPROM_readDouble(KdAddress);
-
-   // Use defaults if EEPROM values are invalid
-   if (isnan(Setpoint))
-   {
-     Setpoint = 60;
-   }
-   if (isnan(Kp))
-   {
-     Kp = 500;
-   }
-   if (isnan(Ki))
-   {
-     Ki = 0.5;
-   }
-   if (isnan(Kd))
-   {
-     Kd = 0.1;
-   }
-}
-
-
-// ************************************************
-// Write floating point values to EEPROM
-// ************************************************
-void EEPROM_writeDouble(int address, double value)
-{
-   byte* p = (byte*)(void*)&value;
-   for (int i = 0; i < sizeof(value); i++)
-   {
-      EEPROM.write(address++, *p++);
-   }
-}
-
-// ************************************************
-// Read floating point values from EEPROM
-// ************************************************
-double EEPROM_readDouble(int address)
-{
-   double value = 0.0;
-   byte* p = (byte*)(void*)&value;
-   for (int i = 0; i < sizeof(value); i++)
-   {
-      *p++ = EEPROM.read(address++);
-   }
-   return value;
-}
-
-//Helpers for String to double conversions
-String doubleToString(double input,int decimalPlaces){
-  if(decimalPlaces!=0){
-    String string = String((int)(input*pow(10,decimalPlaces)));
-    if(abs(input)<1){
-      if(input>0)
-        string = "0"+string;
-      else if(input<0)
-        string = string.substring(0,1)+"0"+string.substring(1);
-    }
-    return string.substring(0,string.length()-decimalPlaces)+"."+string.substring(string.length()-decimalPlaces);
-    } else {
-      return String((int)input);
-  }
-}
-
-double stringToDouble(String input) {
-    char floatbuf[8];
-    input.toCharArray(floatbuf, sizeof(floatbuf));
-    return atof(floatbuf);
-}


Modified node to use freqMhzToRegVal() fn instead of table

--- src/delta5node/delta5node.ino
+++ src/delta5node/delta5node.ino
@@ -99,22 +99,6 @@
 int ioBufferSize = 0;
 int ioBufferIndex = 0;

-// Define vtx frequencies in mhz and their hex code for setting the rx5808 module
-int vtxFreqTable[] = {
-  5865, 5845, 5825, 5805, 5785, 5765, 5745, 5725, // Band A
-  5733, 5752, 5771, 5790, 5809, 5828, 5847, 5866, // Band B
-  5705, 5685, 5665, 5645, 5885, 5905, 5925, 5945, // Band E
-  5740, 5760, 5780, 5800, 5820, 5840, 5860, 5880, // Band F
-  5658, 5695, 5732, 5769, 5806, 5843, 5880, 5917  // Band C / Raceband
-};
-uint16_t vtxHexTable[] = {
-  0x2A05, 0x299B, 0x2991, 0x2987, 0x291D, 0x2913, 0x2909, 0x289F, // Band A
-  0x2903, 0x290C, 0x2916, 0x291F, 0x2989, 0x2992, 0x299C, 0x2A05, // Band B
-  0x2895, 0x288B, 0x2881, 0x2817, 0x2A0F, 0x2A19, 0x2A83, 0x2A8D, // Band E
-  0x2906, 0x2910, 0x291A, 0x2984, 0x298E, 0x2998, 0x2A02, 0x2A0C, // Band F
-  0x281D, 0x288F, 0x2902, 0x2914, 0x2987, 0x2999, 0x2A0C, 0x2A1E  // Band C / Raceband
-};
-
 // Defines for fast ADC reads
 #define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
 #define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
@@ -186,20 +170,21 @@
 	delayMicroseconds(100);
 }

+// Calculate rx5808 register hex value for given frequency in MHz
+uint16_t freqMhzToRegVal(uint16_t freqInMhz) {
+  uint16_t tf, N, A;
+  tf = (freqInMhz - 479) / 2;
+  N = tf / 32;
+  A = tf % 32;
+  return (N<<7) + A;
+}
+
 // Set the frequency given on the rx5808 module
 void setRxModule(int frequency) {
 	uint8_t i; // Used in the for loops

-	uint8_t index; // Find the index in the frequency lookup table
-	for (i = 0; i < sizeof(vtxFreqTable); i++) {
-		if (frequency == vtxFreqTable[i]) {
-			index = i;
-			break;
-		}
-	}
-
-	uint16_t vtxHex; // Get the hex value to send to the rx module
-	vtxHex = vtxHexTable[index];
+	// Get the hex value to send to the rx module
+	uint16_t vtxHex = freqMhzToRegVal(frequency);

 	// bit bash out 25 bits of data / Order: A0-3, !R/W, D0-D19 / A0=0, A1=0, A2=0, A3=1, RW=0, D0-19=0
 	SERIAL_ENABLE_HIGH();


AT command improvements / fixes

AT command improvements / fixes

--- MicroView/WiFiModem-Menu/WiFiModem-Menu.ino
+++ MicroView/WiFiModem-Menu/WiFiModem-Menu.ino
@@ -87,8 +87,7 @@
 // Misc Values
 #define TIMEDOUT  -1
 boolean baudMismatch = (BAUD_RATE != WiFly_BAUD_RATE ? 1 : 0);
-//boolean Modem_flowControl = false;   // for &K setting.  Not currently stored in EEPROM
-boolean Modem_flowControl = EEPROM.read(ADDR_MODEM_FLOW);
+boolean Modem_flowControl = false;   // for &K setting.

 // PETSCII state
 boolean petscii_mode = EEPROM.read(ADDR_PETSCII);
@@ -1233,7 +1232,7 @@
 boolean Modem_isCommandMode = true;
 boolean Modem_isConnected = false;
 boolean Modem_isRinging = false;
-boolean Modem_EchoOn = EEPROM.read(ADDR_MODEM_ECHO);
+boolean Modem_EchoOn = true;
 //boolean Modem_EchoOn = true;
 boolean Modem_VerboseResponses = true;
 boolean Modem_QuietMode = false;
@@ -1262,6 +1261,11 @@
     Modem_EscapeCount = 0;

     Modem_LoadDefaults();
+
+    // Load saved settings
+    Modem_EchoOn = EEPROM.read(ADDR_MODEM_ECHO);
+    Modem_flowControl = EEPROM.read(ADDR_MODEM_FLOW);
+
     Modem_ResetCommandBuffer();

     C64Println();
@@ -1317,6 +1321,7 @@
     Modem_S0_AutoAnswer = false;
     Modem_S2_EscapeCharacter = '+';
     Modem_isDcdInverted = false;
+    Modem_flowControl = false;
 }

@@ -1362,6 +1367,7 @@
 void Modem_ProcessCommandBuffer()
 {
     boolean petscii_mode_guess = false;
+    byte errors = 0;
     // Simple PETSCII/ASCII detection

     if (((Modem_CommandBuffer[0] == 'A') && (Modem_CommandBuffer[1] == 'T')))
@@ -1562,12 +1568,10 @@
             {
                 case 'Z':
                 Modem_LoadDefaults();
-                Modem_PrintOK();
                 break;

                 case 'I':
                 ShowInfo(false);
-                Modem_PrintOK();
                 break;

                 case 'A':
@@ -1586,8 +1590,12 @@
                     break;

                     case '?':
+                    C64Serial.print(Modem_EchoOn);
                     //C64PrintIntln(EEPROM.read(ADDR_MODEM_ECHO));
                     break;
+
+                    default:
+                    errors++;
                 }
                 break;

@@ -1608,6 +1616,13 @@
                     case '1':
                     Modem_QuietMode = true;
                     break;
+
+                    case '?':
+                    C64Serial.print(Modem_QuietMode);
+                    break;
+
+                    default:
+                    errors++;
                 }
                 break;

@@ -1627,7 +1642,14 @@
                             case '1':
                             Modem_S0_AutoAnswer = 1;
                             break;
-                        }
+
+                            case '?':
+                            C64Serial.print(Modem_S0_AutoAnswer);
+                            break;
+
+                            default:
+                            errors++;
+                            }
                         break;
                     }
                     break;
@@ -1646,6 +1668,13 @@
                     case '1':
                     Modem_VerboseResponses = true;
                     break;
+
+                    case '?':
+                    C64Serial.print(Modem_VerboseResponses);
+                    break;
+
+                    default:
+                    errors++;
                 }
                 break;

@@ -1659,6 +1688,7 @@
                     case '1':
                     // TODO
                     break;
+
                 }
                 break;

@@ -1666,15 +1696,7 @@
                 switch(Modem_CommandBuffer[i++])
                 {
                     case 'F':
-                    if (strstr(Modem_LastCommandBuffer, ("&F")) != NULL)      // not working...
-                    {
-                        Modem_LoadDefaults();
-                        Modem_PrintOK();
-                    }
-                    else
-                    {
-                        C64Println(F("Send command again to verify"));
-                    }
+                    Modem_LoadDefaults();
                     break;

                     case 'K':
@@ -1687,6 +1709,13 @@
                         case '1':
                         Modem_flowControl = true;
                         break;
+
+                        case '?':
+                        C64Serial.print(Modem_flowControl);
+                        break;
+
+                        default:
+                        errors++;
                     }
                     break;

@@ -1697,13 +1726,22 @@
                     case 'W':
                     updateEEPROMByte(ADDR_MODEM_ECHO,Modem_EchoOn);
                     updateEEPROMByte(ADDR_MODEM_FLOW,Modem_flowControl);
-                    if (wifly.save())
+                    /*if (wifly.save())
                         Modem_PrintOK();
                     else
-                        Modem_PrintERROR();
+                        Modem_PrintERROR();*/
+                    if (!(wifly.save()))
+                        errors++;
                     break;
                 }
                 break;
+
+                case '\n':
+                case '\r':
+                break;
+
+                default:
+                errors++;
             }
         }

@@ -1782,7 +1820,10 @@
             Modem_S0_AutoAnswer = atoi(temp);
         }*/

-        Modem_PrintOK();
+        if (errors)
+            Modem_PrintERROR();
+        else
+            Modem_PrintOK();
     }
     else
     {


Update TI_Stellaris_LaunchPad.ino

Update TI_Stellaris_LaunchPad.ino

--- examples/BoardsAndShields/TI_Stellaris_LaunchPad/TI_Stellaris_LaunchPad.ino
+++ examples/BoardsAndShields/TI_Stellaris_LaunchPad/TI_Stellaris_LaunchPad.ino
@@ -27,13 +27,15 @@
  *
  *      for Windows:
  *                     1. Open cmd.exe
- *                     2. write : (your way to blynk-ser.bat folder) example: "cd C:\blynk-library-0.3.1\blynk-library-0.3.1\scripts"
- *                     3. write : "blynk-ser.bat -c COM4" (where COM4 is port with your Arduino)
- *                     4. And press "Enter" , press "Enter" and press "Enter"
+ *                     2. Write (put your path to the blynk-ser.bat folder):
+ *                          cd C:\blynk-library\scripts
+ *                     3. Write (COM4 is port with your Arduino):
+ *                          blynk-ser.bat -c COM4
+ *                     4. And press "Enter", press "Enter" and press "Enter"
  *
  *      for Linux and OSX:
  *
- *                    ./blynk-ser.sh (may need to run with sudo)
+ *                    bash ./blynk-ser.sh (may need to run with sudo)
  *
  *    You can specify port, baud rate, and server endpoint like this:
  *      ./blynk-ser.sh -c <serial port> -b <baud rate> -s <server address> -p <server port>