Delete MiniCCRx.ino

Delete MiniCCRx.ino

--- MiniCCRx.ino
+++ MiniCCRx.ino
@@ -1,136 +0,0 @@
-#include "EEPROM.h"
-#include "cc1101.h"
-
-// The LED is wired to the Arduino Output 4 (physical panStamp pin 19)
-#define LEDOUTPUT 4
-
-// The connection to the hardware chip CC1101 the RF Chip
-CC1101 cc1101;
-
-byte b;
-byte i;
-byte syncWord = 199;
-long counter = 0;
-byte chan = 0;
-
-// a flag that a wireless packet has been received
-boolean packetAvailable = false;
-
-void blinker() {
-  digitalWrite(LEDOUTPUT, HIGH);
-  delay(100);
-  digitalWrite(LEDOUTPUT, LOW);
-  delay(100);
-}
-
-/* Handle interrupt from CC1101 (INT0) gdo0 on pin2 */
-void cc1101signalsInterrupt(void) {
-  // set the flag that a package is available
-  packetAvailable = true;
-}
-
-void setup()
-{
-  Serial.begin(38400);
-  Serial.println("start");
-
-  // setup the blinker output
-  pinMode(LEDOUTPUT, OUTPUT);
-  digitalWrite(LEDOUTPUT, LOW);
-
-  // blink once to signal the setup
-  blinker();
-  // initialize the RF Chip
-  cc1101.init();
-
-  cc1101.setSyncWord(&syncWord, false);
-  cc1101.setCarrierFreq(CFREQ_433);
-  cc1101.disableAddressCheck(); //if not specified, will only display "packet received"
-  //cc1101.setTxPowerAmp(PA_LowPower);
-
-  //I ADDED THIS
-  cc1101.setChannel(0x05);
-
-  Serial.print("CC1101_PARTNUM "); //cc1101=0
-  Serial.println(cc1101.readReg(CC1101_PARTNUM, CC1101_STATUS_REGISTER));
-  Serial.print("CC1101_VERSION "); //cc1101=4
-  Serial.println(cc1101.readReg(CC1101_VERSION, CC1101_STATUS_REGISTER));
-  Serial.print("CC1101_MARCSTATE ");
-  Serial.println(cc1101.readReg(CC1101_MARCSTATE, CC1101_STATUS_REGISTER) & 0x1f);
-
-  attachInterrupt(0, cc1101signalsInterrupt, FALLING);
-
-  Serial.println("device initialized");
-}
-
-void ReadLQI()
-{
-  byte lqi = 0;
-  byte value = 0;
-  lqi = (cc1101.readReg(CC1101_LQI, CC1101_STATUS_REGISTER));
-  value = 0x3F - (lqi & 0x3F);
-  Serial.print("CC1101_LQI ");
-  Serial.println(value);
-}
-
-void ReadRSSI()
-{
-  byte rssi = 0;
-  byte value = 0;
-
-  rssi = (cc1101.readReg(CC1101_RSSI, CC1101_STATUS_REGISTER));
-
-  if (rssi >= 128)
-  {
-    value = 255 - rssi;
-    value /= 2;
-    value += 74;
-  }
-  else
-  {
-    value = rssi / 2;
-    value += 74;
-  }
-  Serial.print("CC1101_RSSI ");
-  Serial.println(value);
-}
-
-void loop()
-{
-  //TESTING
-  if (Serial.available()){
-    Serial.write(Serial.read());
-  }
-
-  if (packetAvailable) {
-    Serial.println("packet received");
-    // Disable wireless reception interrupt
-    detachInterrupt(0);
-
-    ReadRSSI();
-    ReadLQI();
-    // clear the flag
-    packetAvailable = false;
-
-    CCPACKET packet;
-
-    if (cc1101.receiveData(&packet) > 0) {
-      if (!packet.crc_ok) {
-        Serial.println("crc not ok");
-      }
-
-      if (packet.length > 0) {
-        Serial.print("packet: len ");
-        Serial.print(packet.length);
-        Serial.print(" data: ");
-        for (int j = 0; j < packet.length; j++) {
-          Serial.print(packet.data[j], HEX);
-          Serial.print(" ");
-        }
-        Serial.println(".");
-      }
-    }
-    // Enable wireless reception interrupt
-    attachInterrupt(0, cc1101signalsInterrupt, FALLING);
-  }
-}


Added smooth sampling of values, closes #5.

--- growdammit.ino
+++ growdammit.ino
@@ -100,21 +100,21 @@
   // read light sensor
   digitalWrite(LIGHT_ENABLE, HIGH);
   delay(100);
-  ambient_light = analogRead(A0);
+  ambient_light = analogSample();
   digitalWrite(LIGHT_ENABLE, LOW);
   delay(100);

   // read soil sensor
   digitalWrite(SOIL_ENABLE, HIGH);
   delay(100);
-  soil_moisture = analogRead(A0);
+  soil_moisture = analogSample();
   digitalWrite(SOIL_ENABLE, LOW);
   delay(100);

   // read humidity and temperature
-  humidity = weather.readHumidity();
+  humidity = humiditySample();
   dtostrf(humidity, 5, 2, humidity_cstr);
-  temperature = weather.readTemperature();
+  temperature = temperatureSample();
   dtostrf(temperature, 5, 2, temperature_cstr);

   unix_time = reset_time + (millis() / 1000);
@@ -213,3 +213,104 @@
   }
   return encodedString;
 }
+
+#define NUM_SAMPLES 100
+#define NUM_DISCARD 10
+unsigned int samples[NUM_SAMPLES];
+
+void bubble_sort(unsigned int samples[], unsigned int len) {
+  for (int i = 0; i < (len-1); i++) {
+    for (int j = 0; j < (len-(i+1)); j++) {
+      if(samples[j] > samples[j+1]) {
+        unsigned int t = samples[j];
+        samples[j] = samples[j+1];
+        samples[j+1] = t;
+      }
+    }
+  }
+}
+
+// read in 100 values, sort them, and
+// discard the largest and smallest 10
+// then take the average of the rest
+unsigned int analogSample()
+{
+  unsigned int i;
+  unsigned long average;
+
+  for (i = 0; i < NUM_SAMPLES; i++)
+  {
+    samples[i] = analogRead(A0);
+    delay(1);
+  }
+
+  bubble_sort(samples, NUM_SAMPLES);
+
+  for (i = NUM_DISCARD; i < (NUM_SAMPLES-NUM_DISCARD); i++)
+  {
+    average += samples[i];
+  }
+  average = average / (NUM_SAMPLES - (2*NUM_DISCARD));
+
+  return (unsigned int)average;
+}
+
+void bubble_sort(float samples[], unsigned int len) {
+  for (int i = 0; i < (len-1); i++) {
+    for (int j = 0; j < (len-(i+1)); j++) {
+      if(samples[j] > samples[j+1]) {
+        float t = samples[j];
+        samples[j] = samples[j+1];
+        samples[j+1] = t;
+      }
+    }
+  }
+}
+
+#define TEMP_SAMPLES 20
+#define TEMP_DISCARD 2
+float tsamples[TEMP_SAMPLES];
+
+float temperatureSample()
+{
+  unsigned int i;
+  float average;
+
+  for (i = 0; i < TEMP_SAMPLES; i++)
+  {
+    tsamples[i] = weather.readTemperature();
+    delay(1);
+  }
+
+  bubble_sort(tsamples, TEMP_SAMPLES);
+
+  for (i = TEMP_DISCARD; i < (TEMP_SAMPLES-TEMP_DISCARD); i++)
+  {
+    average += tsamples[i];
+  }
+  average = average / (TEMP_SAMPLES - (2*TEMP_DISCARD));
+
+  return average;
+}
+
+float humiditySample()
+{
+  unsigned int i;
+  float average;
+
+  for (i = 0; i < TEMP_SAMPLES; i++)
+  {
+    tsamples[i] = weather.readHumidity();
+    delay(1);
+  }
+
+  bubble_sort(tsamples, TEMP_SAMPLES);
+
+  for (i = TEMP_DISCARD; i < (TEMP_SAMPLES-TEMP_DISCARD); i++)
+  {
+    average += tsamples[i];
+  }
+  average = average / (TEMP_SAMPLES - (2*TEMP_DISCARD));
+
+  return average;
+}


Commented out DELAY in Setup

Commented out DELAY in Setup

--- GEVCU.ino
+++ GEVCU.ino
@@ -248,7 +248,7 @@
 }

 void setup() {
-        delay(5000);
+        //delay(5000);  //This delay lets you see startup.  But it breaks DMOC645 really badly.  You have to have comm way before 5 seconds.

         //initWiReach();
 	pinMode(BLINK_LED, OUTPUT);


Delay is now 1s

Delay is now 1s

--- carduino.ino
+++ carduino.ino
@@ -10,5 +10,5 @@

 void loop() {
   carduino.loop();
-  delay(500);
+  delay(1000);
 }


general changes

general changes

--- halleffect_slave/halleffect_slave.ino
+++ halleffect_slave/halleffect_slave.ino
@@ -1,16 +1,17 @@
+#include <nRF24L01.h>
+#include <RF24.h>
+#include <RF24_config.h>
 #include <SPI.h>
-#include <RF24.h>
 #include "printf.h"

 RF24 radio(9,10);

-// For best performance, use P1-P5 for writing and Pipe0 for reading as per the hub setting
-// Below is the settings from the hub/receiver listening to P0 to P5
-//const uint64_t pipes[6] = { 0x7365727631LL, 0xF0F0F0F0E1LL, 0xF0F0F0F0E2LL, 0xF0F0F0F0E3LL, 0xF0F0F0F0E4LL, 0xF0F0F0F0E5LL };
+// All pipes to be used by sensors here
+// P0 - Hub Pipe for writing. Read by all sensors
+// P1-P5 - Sensor pipes for writing by sensors. Hub reads on these.

-// Pipes are unique per slave unit.
-const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0x7365727631LL };
-
+// P0 is Hub Pipe to be read by sensors. P1 is specific sensor pipe; to be opened for writing.
+const uint64_t pipes[2] = { 0x7365727631LL, 0xF0F0F0F0E1LL };
 char receivePayload[32];
 uint8_t counter=0;

@@ -20,8 +21,7 @@
   Serial.begin(57600);
   printf_begin();
   printf("\n\r Hall Effect Slave");
-  //printf("ROLE: %s\n\r",role_friendly_name[role]);
-
+
   radio.begin();
   radio.enableDynamicPayloads() ;

@@ -30,8 +30,8 @@
   radio.setChannel(76);
   radio.setRetries(15,15);

-  radio.openWritingPipe(pipes[0]);
-  radio.openReadingPipe(1,pipes[1]);
+  radio.openReadingPipe(0,pipes[0]);
+  radio.openWritingPipe(pipes[1]);

   radio.setAutoAck( true ) ;
   radio.printDetails();


サンプル番号の修正

サンプル番号の修正

--- 2_example/example28_lcdkey/example28_lcdkey.ino
+++ 2_example/example28_lcdkey/example28_lcdkey.ino
@@ -1,5 +1,5 @@
 /*******************************************************************************
-Example 18: LCDへ表示する(HTTP版・時刻表示機能・NTP受信機能付き)
+Example 28: LCDへ表示する(HTTP版・時刻表示機能・NTP受信機能付き)
                                            Copyright (c) 2016-2017 Wataru KUNINO
 *******************************************************************************/

@@ -34,7 +34,7 @@

 void setup(){                               // 起動時に一度だけ実行する関数
     lcd.begin(16, 2);                       // 液晶の初期化(16桁×2行)
-    lcd.print("Example 18t LCD");           // 「Example 18」をLCDに表示する
+    lcd.print("Example 28 LCD");            // 「Example 28」をLCDに表示する
     lcd.setCursor(0,1);                     // カーソル位置を液晶の左上へ
     wifi_set_sleep_type(LIGHT_SLEEP_T);     // 省電力モード設定
     WiFi.mode(WIFI_STA);                    // 無線LANをSTAモードに設定


buildzip

buildzip

--- FireStep/FireStep.ino
+++ FireStep/FireStep.ino
@@ -30,7 +30,7 @@
     Serial.begin(19200); // long USB cables
 	char buf[100];
 	strcpy_P(buf, GIT_TAG);
-	Serial.println(GIT_TAG);
+	Serial.println(buf);

     // Bind in NeoPixel display driver
     machineThread.machine.pDisplay = &neoPixel;


Added check when switching directions.

Added check when switching directions.

Only switch direction if past max/min range AND direction going away
from normal range.

--- Pan_Tilt_laser/Pan_Tilt_laser.ino
+++ Pan_Tilt_laser/Pan_Tilt_laser.ino
@@ -126,11 +126,11 @@
 */
   }

-  if(random(1001) <= prob<<1 || pt->angle >= pt->maxAngle || pt->angle <= pt->minAngle){
-    pt->dir *= -1;/*
+  if(random(1001) <= prob << 1 || (pt->angle >= pt->maxAngle && pt->dir == 1) || pt->angle <= pt->minAngle && pt->dir == -1){
+    pt->dir *= -1;
     Serial.println(F("##############CHANGE#################"));
     Serial.println(pt->dir);
-    */
+
   }

   return pt->dir;
@@ -150,6 +150,7 @@

 int getMarkovSpeed(int oldSpeed){
 int val = random(101);
+Serial.println(F("Markov"));
 if(oldSpeed == 1){
   if(val < 20){
     return 2;
@@ -178,6 +179,7 @@
   }
 }
 else{
+
   return constrain(oldSpeed, 1, 3);
 }


update: added coman S and A

update: added coman S and A

--- jenny5-firmware/jenny5-firmware.ino
+++ jenny5-firmware/jenny5-firmware.ino
@@ -103,9 +103,21 @@
                       ++i;
                     }
                   }
-                  else{
-                    // unknowm command
+                else
+                  if (current_buffer[i] == 'S' || current_buffer[i] == 's'){// motor speed
+                    int motor_index, motor_speed;
+                    sscanf(tmp_str, "%d%d", &motor_index, &motor_speed);
+                    mc.set_motor_speed(motor_index, motor_speed);
+                    is_command_running = 1;
                   }
+                else
+                  if (current_buffer[i] == 'A' || current_buffer[i] == 'a'){// motor acceleration
+                    int motor_index, motor_acceleration;
+                    sscanf(tmp_str, "%d%d", &motor_index, &motor_acceleration);
+                    mc.set_motor_acceleration(motor_index, motor_acceleration);
+                    is_command_running = 1;
+                  }
+
               // remove the current executed command
               strcpy(current_buffer, current_buffer + j + 1);// not sure if this is good


Power Board - AC_OK and BAT_LOW (#1127)

Power Board - AC_OK and BAT_LOW (#1127)

* Power Board - AC_OK and BAT_LOW
* Read pins `11` and `12` and send along with other output.
* Move the configurable items to the top of file.

--- resources/arduino/PowerBoard/PowerBoard.ino
+++ resources/arduino/PowerBoard/PowerBoard.ino
@@ -3,6 +3,14 @@

 // POCS looks for this name.
 const char BOARD_NAME[] = "power_board";
+
+// Meanwell UPS AC and Battery pins.
+const int AC_OK = 12;
+const int BAT_LOW = 11;
+
+/******************************************/
+/* Shouldn't need to change anything below.
+/******************************************/

 // Set initial states for each relay. Change as needed.
 const bool DEFAULT_START_0 = HIGH;
@@ -11,9 +19,6 @@
 const bool DEFAULT_START_3 = HIGH;
 const bool DEFAULT_START_4 = HIGH;

-//conversion factor to compute Iload from sensed voltage. From Luc.
-//const float MULTIPLIER = 5 / 1023 * 2360 / 1200;
-
 // Relays
 const int RELAY_0 = A3; // 0_0 PROFET-0 Channel 0 (A3 = 17)
 const int RELAY_1 = 3;  // 1_0 PROFET-0 Channel 1
@@ -52,6 +57,10 @@
   pinMode(IS_1, INPUT);
   pinMode(IS_2, INPUT);

+  // Setup AC and Battery pins
+  pinMode(AC_OK, INPUT);
+  pinMode(BAT_LOW, INPUT);
+
   // Setup diagnosis enable pins
   pinMode(DEN_0, OUTPUT);
   pinMode(DEN_1, OUTPUT);
@@ -135,6 +144,9 @@
   int seconds_stamp = millis() / time_period;

   StaticJsonDocument<192> doc;
+
+  doc["ac_ok"] = digitalRead(AC_OK);
+  doc["battery_low"] = digitalRead(BAT_LOW);

   JsonArray relays = doc.createNestedArray("relays");
   relays.add(is_relay_on(RELAY_0));


Updated initialization and added functionality

--- FumeHoodMonitor/LCD.ino
+++ FumeHoodMonitor/LCD.ino
@@ -1,8 +1,8 @@
 #include "Adafruit_LiquidCrystal.h"

-#define REDLITE A3
-#define GREENLITE A4
-#define BLUELITE A5
+#define REDLITE 5
+#define GREENLITE 6
+#define BLUELITE A3

 Adafruit_LiquidCrystal lcd(0);
 int brightness = 255;
@@ -13,12 +13,8 @@
   pinMode(REDLITE, OUTPUT);
   pinMode(GREENLITE, OUTPUT);
   pinMode(BLUELITE, OUTPUT);
-  setBacklight(255,0,0);
-  delay(1000);
-  setBacklight(0,0,255);
-  delay(1000);
-  setBacklight(255,255,0);
-  delay(1000);
+  cycleBacklightColor();
+  setBacklight("green");
 }

 void writeLCD(String message){
@@ -35,25 +31,22 @@

 void writeLCD(float ambientTemp, float fluidTemp, String flameStatus){
   lcd.setCursor(0,0);
-  lcd.print("Fume Hood Monitor   ");
+  lcd.print(make20Characters("Fume Hood Monitor"));
   lcd.setCursor(0,1);
-  lcd.print("Ambient Temp: ");
-  lcd.print(ambientTemp, 2);
+  lcd.print(make20Characters("Air Temp: " + String(ambientTemp, 2) + String((char)223) + "F"));
   lcd.setCursor(0,2);
-  lcd.print("Fluid Temp: ");
-  lcd.print(fluidTemp, 2);
+  lcd.print(make20Characters("Fluid Temp: " + String(fluidTemp, 2) + String((char)223) + "F"));
   lcd.setCursor(0,3);
-  lcd.print("Flame: ");
-  lcd.print(flameStatus);
+  lcd.print(make20Characters("Flame: " + flameStatus));
 }

 void writeLCD(String timeString, float ambientTemp, float fluidTemp, String flameStatus){
   lcd.setCursor(0,0);
   lcd.print(make20Characters(timeString));
   lcd.setCursor(0,1);
-  lcd.print(make20Characters("Ambient Temp: " + String(ambientTemp, 2)));
+  lcd.print(make20Characters("Air Temp: " + String(ambientTemp, 2) + String((char)223) + "F"));
   lcd.setCursor(0,2);
-  lcd.print(make20Characters("Fluid Temp: " + String(fluidTemp, 2)));
+  lcd.print(make20Characters("Fluid Temp: " + String(fluidTemp, 2) + String((char)223) + "F"));
   lcd.setCursor(0,3);
   lcd.print(make20Characters("Flame: " + flameStatus));
 }
@@ -80,3 +73,46 @@
   analogWrite(GREENLITE, g);
   analogWrite(BLUELITE, b);
 }
+
+void setBacklight(String color) {
+  uint8_t r, g, b;
+  if      (color == "red")    {r = 255; g = 0;   b = 0;}
+  else if (color == "orange") {r = 255; g = 50;  b = 0;}
+  else if (color == "yellow") {r = 255; g = 255; b = 0;}
+  else if (color == "green")  {r = 0;   g = 255; b = 0;}
+  else if (color == "blue")   {r = 0;   g = 0;   b = 255;}
+  else                        {r = 255; g = 255; b = 255;}
+  setBacklight(r, g, b);
+}
+
+void cycleBacklightColor() {
+  uint8_t d = 1;
+  for (uint8_t i = 0; i < 255; i++) {
+    setBacklight(0, i, 0);
+    delay(d);
+  }
+  for (uint8_t i = 0; i < 255; i++) {
+    setBacklight(0, 254, i);
+    delay(d);
+  }
+  for (uint8_t i = 0; i < 255; i++) {
+    setBacklight(0, 254 - i, 254);
+    delay(d);
+  }
+  for (uint8_t i = 0; i < 255; i++) {
+    setBacklight(i, 0, 254);
+    delay(d);
+  }
+  for (uint8_t i = 0; i < 255; i++) {
+    setBacklight(254, 0, 254 - i);
+    delay(d);
+  }
+  for (uint8_t i = 0; i < 255; i++) {
+    setBacklight(254, i, 0);
+    delay(d);
+  }
+  for (uint8_t i = 0; i < 255; i++) {
+    setBacklight(254 - i, 254, 0);
+    delay(d);
+  }
+}


sending time,acc,temp,gyro CSV + GPS at 38400

--- serial/serial.ino
+++ serial/serial.ino
@@ -31,7 +31,7 @@
 //const int MPU=0x68;  // I2C address of the MPU-6050
 const int MPU=0x69;  // I2C address of the MPU-6050 for AD0=1
 int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;
-
+long time;

 void setup()
 {
@@ -56,17 +56,18 @@
   }

-  Serial.begin( 9600 );
-  Serial.print( "I2C test ...\n" );
+  Serial.begin( 38400 );
+  Serial.print( "\n\nid,timeMs,accX,accY,accZ,temp,gyroX,gyroY,gyroZ\n" );
 }

 void readIthGyro( int i )
 {
   digitalWrite( gyroSelectPins[i], 1 );  // select i-th gyro
-  delay(10);
+  delay(1);
   Wire.beginTransmission(MPU);
   Wire.write(0x3B);  // starting with register 0x3B (ACCEL_XOUT_H)
   Wire.endTransmission(false);
+  time = millis();
   Wire.requestFrom(MPU,14,true);  // request a total of 14 registers
   AcX=Wire.read()<<8|Wire.read();  // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)
   AcY=Wire.read()<<8|Wire.read();  // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
@@ -76,7 +77,7 @@
   GyY=Wire.read()<<8|Wire.read();  // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L)
   GyZ=Wire.read()<<8|Wire.read();  // 0x47 (GYRO_ZOUT_H) & 0x48 (GYRO_ZOUT_L)
   digitalWrite( gyroSelectPins[i], 0 ); // unselect
-  delay(10);
+  delay(1);
 }

 void loop()
@@ -85,16 +86,17 @@
   for( i = 0; i < NUM_GYROS; i++ )
   {
     readIthGyro( i );
-    Serial.print( i ); Serial.print(": ");
-    Serial.print("AcX = "); Serial.print(AcX);
-    Serial.print(" | AcY = "); Serial.print(AcY);
-    Serial.print(" | AcZ = "); Serial.println(AcZ);
-//  Serial.print(" | Tmp = "); Serial.print(Tmp/340.00+36.53);  //equation for temperature in degrees C from datasheet
-//  Serial.print(" | GyX = "); Serial.print(GyX);
-//  Serial.print(" | GyY = "); Serial.print(GyY);
-//  Serial.print(" | GyZ = "); Serial.println(GyZ);
+    Serial.print( i );
+    Serial.print(","); Serial.print(time);
+    Serial.print(","); Serial.print(AcX);
+    Serial.print(","); Serial.print(AcY);
+    Serial.print(","); Serial.print(AcZ);
+    Serial.print(","); Serial.print(Tmp/340.00+36.53);  //equation for temperature in degrees C from datasheet
+    Serial.print(","); Serial.print(GyX);
+    Serial.print(","); Serial.print(GyY);
+    Serial.print(","); Serial.println(GyZ);
   }
-  gps.process();
-  delay(333);
+  //gps.process();
+  //delay(50);
 }


added this serial output for debugging (making sure that it doesn't get stuck in the loop)

--- slave1/slave1.ino
+++ slave1/slave1.ino
@@ -144,6 +144,7 @@
 	slave1.imu.initCalibMagRoutine();
 	bool exit = false;
 	while(!exit){
+		Serial.println("calibMagfromMaster");
 		slave1.imu.calibMagRoutine();
 		uint8_t c = slave1.checkIfRequested();
 		switch(c){


moved sound sensor INO file to correct directory

--- Devices/SimpleSoundSensor/SimpleSoundSensor.ino
+++ Devices/SimpleSoundSensor/SimpleSoundSensor.ino
@@ -1,92 +0,0 @@
-/*
- Simple sound sensor code for http://connectthedots.msopentech.com end-to-end example of sending data to Microsoft Azure
- By: Microsoft Open Technologies, Inc.
- Date: January 27, 2015
-  -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
- Copyright (c) Microsoft Open Technologies, Inc.  All rights reserved.
-
- The MIT License (MIT)
-
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
-
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
-
- -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
- Based upon code from Sunfounder Microsophone Sensor Module  http://www.sunfounder.com/index.php?c=case_in&a=detail_&id=139&name= using a different but similar analog sound sensor purchased online.
-
- Modifications by Microsoft Open Technologies, Inc include adding self-describing fields in each output string, and changing
- output format to JSON string. Based upon the variables below, the JSON string would be something like the following, depending upon the values retrieved
- from the Weather Shield:
-
- {"dspl":"Hex Sound Sensor 01","Subject":"sound","DeviceGUID":"898A4B4F-80B7-4BA0-B4B1-186655336472","millis":80176,"seqno":79,"soundLvl":78}
-
- The dspl, Subject, deviceGUID data may be used by the Azure website and services to identify the device sending the data. The subsequent field names may be used to generate the labels on charts in the Azure website.
- -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
-*/
-// Constants used for the ConnectTheDots project
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-// SensorSubject value determines how Azure website will chart the data
-// DeviceDisplayName value will be the label for the curve on the chart
-// DeviceGUID ensures all the data from this sensor appears on the same chart
-// You can use Visual Studio to create DeviceGUID and copy it here. In VS, On the Tools menu, click Create GUID. The Create GUID
-// tool appears with a GUID in the Result box. Click Copy, and paste below.
-//
-char SensorSubject[] = "sound";
-char DeviceDisplayName[] = "Hex Sound Sensor 01";
-char DeviceGUID[] = "898A4B4F-80B7-4BA0-B4B1-186655336472";
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
-
-const int SOUND_PIN = A0;
-const int SAMPLE_FREQUENCY = 500;
-int high = 0;
-unsigned long hightime = millis();
-int sequenceNumber = 0;
-
-void setup() {
-  //pinMode(SOUND_PIN,INPUT);
-  Serial.begin(9600);
-}
-
-void loop() {
-  int value = analogRead(SOUND_PIN);
-  //int value = digitalRead(SOUND_PIN);
-  if (high < value) {
-    high = value;
-  }
-  if (millis() - hightime >= SAMPLE_FREQUENCY) {
-    Serial.print("{");
-    Serial.print("\"dspl\":");
-    Serial.print("\"");
-    Serial.print(DeviceDisplayName);
-    Serial.print("\"");
-    Serial.print(",\"Subject\":");
-    Serial.print("\"");
-    Serial.print(SensorSubject);
-    Serial.print("\"");
-    Serial.print(",\"DeviceGUID\":");
-    Serial.print("\"");
-    Serial.print(DeviceGUID);
-    Serial.print("\"");
-    Serial.print(",\"millis\":");
-    Serial.print(millis());
-    Serial.print(",\"seqno\":");
-    Serial.print(sequenceNumber++);
-    Serial.print(",\"soundLvl\":");
-    Serial.print(high);
-    Serial.println("}");
-
-    high = 0;
-    hightime = millis();
-  }
-}


Update HC-SR04.ino

Update HC-SR04.ino

--- Device/HC-SR04.ino
+++ Device/HC-SR04.ino
@@ -122,3 +122,5 @@
   }
   delay(5000);
 }
+
+//End of the Program


I've been having trouble with DHCP, so let's switch to using a static IP.

--- WifiConnection.ino
+++ WifiConnection.ino
@@ -16,7 +16,8 @@
 void initWifi() {

   /* Initialise the module */
-  Serial.print(F("wifi"));
+  Serial.print(F("wifi "));
+
   if (!cc3000.begin())
   {
     Serial.print(FAIL_MSG);
@@ -24,6 +25,24 @@
   }
   Serial.print(OK_MSG);

+#ifdef USE_DHCP
+  Serial.print(F("dhcp"));
+  cc3000.setDHCP();
+#endif
+
+#ifdef USE_STATIC_IP
+  Serial.print(F("static"));
+  uint32_t ipAddress = cc3000.IP2U32(172, 16, 25, 240);
+  uint32_t netMask = cc3000.IP2U32(255, 255, 255, 0);
+  uint32_t defaultGateway = cc3000.IP2U32(172, 16, 25, 1);
+  uint32_t dns = cc3000.IP2U32(172, 16, 25, 1);
+  if (!cc3000.setStaticIPAddress(ipAddress, netMask, defaultGateway, dns)) {
+    Serial.print(FAIL_MSG);
+    while(1);
+  }
+  Serial.print(OK_MSG);
+#endif
+
   ensureWifiConnection();

 }
@@ -39,11 +58,13 @@
     }
     Serial.print(OK_MSG);

+#ifdef USE_DHCP
     /* Wait for DHCP to complete */
     do
     {
       delay(100); // ToDo: Insert a DHCP timeout!
-    } while (!cc3000.checkDHCP());
+    } while (!cc3000.checkDHCP());
+#endif

     /* Display the IP address DNS, Gateway, etc. */
     //while (! displayConnectionDetails()) {


Fixing RC_Control_Interrupts, this check in is verified to work against the yellow bike

--- RC_Control_interrupts/RC_Control_interrupts.ino
+++ RC_Control_interrupts/RC_Control_interrupts.ino
@@ -9,6 +9,7 @@
 #include <SPI.h>

 //RC input values - pulse widths in microseconds
+const int LONG_DEADZONE_THRESHOLD = 10000; // used for syncing to determine if the last down time was the long down zone
 const int DEAD_ZONE = 75;
 const int MIDDLE = 1510;  // was 1322;
 // extremes of RC pulse width
@@ -36,8 +37,8 @@
 const int RC_INTERRUPT_PIN = 20;
 const int RC_INTERRUPT = 3;
 const int PIN_ORDER[8] = {0, RC_STEER_PIN, RC_CRUISE_PIN, RC_THROTTLE_PIN, RC_ESTOP_PIN, RC_RUDDER_PIN, RC_REVERSE_PIN, 0};
-const int STEER_OUT_PIN = 6; // Output to steer actuator
-const int BRAKE_OUT_PIN = 7;  // output to brake actuator
+const int STEER_OUT_PIN = 7; // Output to steer actuator
+const int BRAKE_OUT_PIN = 6;  // output to brake actuator
 const int SelectCD = 49; // Select IC 3 DAC (channels C and D)
 const int SelectAB = 53; // Select IC 2 DAC (channels A and B)

@@ -48,6 +49,8 @@
 volatile int rc_index = 0;
 volatile  unsigned long RC_results[7];
 volatile int rc_state = RC_WAIT;
+volatile boolean synced = false;
+volatile unsigned long last_fallingedge_time = 4294967295; // max long

 void setup()
 { //Set up pins
@@ -72,53 +75,61 @@
       rc_state = RC_WAIT;

       attachInterrupt(RC_INTERRUPT, ISR_rise, RISING);
+}
+void ISR_rise()
+{
+    noInterrupts();
+
+    if (rc_state != RC_WAIT)
+    {
+      if (!synced)
+      {
+        unsigned int elapsed = micros() - last_fallingedge_time;
+        if (elapsed > LONG_DEADZONE_THRESHOLD)
+        {
+          RC_results[rc_index] = micros();
+          synced = true;
+          rc_index = 1;
+        }
+      }
+      else
+      {
+        RC_results[rc_index] = micros();
+      }
       attachInterrupt(RC_INTERRUPT, ISR_fall, FALLING);
-}
-void ISR_rise()
+    }
+
+    interrupts();
+}
+void ISR_fall()
 {
     noInterrupts();
-    unsigned long time = micros();
-    for (register int i = 0; i < 8; i++)
+
+    if (rc_state != RC_WAIT)
     {
-        register int index = (rc_index+i)&7;
-        if (PIN_ORDER[index] == 0)
-            continue;
-        if (digitalRead(PIN_ORDER[index]) == HIGH)
+      if (!synced)
+      {
+        last_fallingedge_time = micros();
+      }
+      else
+      {
+        RC_results[rc_index] = micros() - RC_results[rc_index];
+        rc_index++;
+        if (rc_index == 7)
         {
-            rc_index = (rc_index+i) & 7;
-            RC_results[rc_index] = time;
-            rc_state = RC_PROCESSING;
-            if (rc_index == 1)   // first signal of group
-                RC_results[0] = RC_results[1];  // log starting time
-
+          rc_index = 1;
+          rc_state = RC_DONE;
         }
+      }
+      attachInterrupt(RC_INTERRUPT, ISR_rise, RISING);
     }
     interrupts();
 }
-void ISR_fall()
-{
-    noInterrupts();
-    if (PIN_ORDER[rc_index] != 0 && digitalRead(PIN_ORDER[rc_index]) == LOW)
-    {
-        unsigned int elapsed = RC_results[rc_index] - micros();
-        if (elapsed > MAX_RC)
-        {
-            RC_results[rc_index] = INVALID_DATA;
-            if (rc_index == 7)
-                rc_state = RC_DONE;
-        }
-        else if (elapsed < MIN_RC)
-        {
-            RC_results[rc_index] = elapsed;
-            if (rc_index == 7)
-                rc_state = RC_DONE;
-        }
-        else; // spurious interrupt; wait for the next.
-    }
-    interrupts();
-}
 void loop()  {
     unsigned long Start_us = micros();
+
+    startCapturingRCState();
+
     unsigned long local_results[7];
     while (rc_state != RC_DONE)
         ;
@@ -139,6 +150,14 @@

     processRC(local_results);
 }
+
+void startCapturingRCState()
+{
+  synced = false;
+  rc_index = 1;
+  rc_state = RC_PROCESSING;
+}
+
 void processRC (unsigned long *RC_results)
 {
     // 1st pulse is aileron (position 5 on receiver; controlled by Right left/right joystick on transmitter)
@@ -185,7 +204,7 @@
         moveVehicle(RC_results[3]);
     else
         moveVehicle(MIN_ACC_OUT);
-
+
     steer(RC_results[1]);

     /* 5th pulse is rudder (position 3 on receiver; controlled by Left left/right joystick on transmitter)
@@ -287,7 +306,7 @@
       3.63 V: max 227 counts
       255 counts = 4.08 V
       */
-      DAC_Write(0, acc);
+      DAC_Write(3, acc);
 }
 /*---------------------------------------------------------------------------------------*/
 /* DAC_Write applies value to address, producing an analog voltage.


Added safety turnoff after 100ms without messages

--- Motor_Controler.ino
+++ Motor_Controler.ino
@@ -1,6 +1,5 @@
 #define NO_PRINT 0
 #define PRINT_SPEED 1
-#define Something

 //mXeY - silnik X, pin enkodera Y
 #define m1e1 23
@@ -49,7 +48,7 @@
 silnik motor3{4, 26, 27, m1e1, m1e2, 0, 0};
 silnik motor4{5, 28, 29, m1e1, m1e2, 0, 1};
 silnik motor5{7, 6, 8, m1e1, m1e2, 0, 0};
-silnik motor6{10, 9, 11, m1e1, m1e2, 0, 1};
+silnik motor6{10, 9, 11, m1e1, m1e2, 0, 11};

 void initMotor(struct silnik motor)
 {
@@ -121,6 +120,7 @@
 int PWMSpeed[6] = {0, 0, 0, 0, 0, 0};
 boolean slopeRise1 = 1, slopeFall1 = 0, slopeRise2 = 1, slopeFall2 = 0, slopeRise3 = 1, slopeFall3 = 0, slopeRise4 = 1, slopeFall4 = 0;
 byte timeCounter = 0;
+volatile unsigned int timeOfLastMessageReceived = 0;
 unsigned long startingTime = 0;
 int slopeCounter1 = 0, slopeCounter2 = 0, slopeCounter3 = 0, slopeCounter4 = 0;
 byte Kp = 0;
@@ -150,148 +150,159 @@
   RPR = 10;

   Kp = 2;
+
+  pinMode(13, OUTPUT);
+  digitalWrite(13, LOW);
+  delay(1000);
+  digitalWrite(13, HIGH);
+
 }

 void loop()
 {
   if (newMessageReceived)
     handleNewMessage();
-
+
+  if(millis() - timeOfLastMessageReceived > 100)
+  {
+    for(int i=0; i<6; i++)
+      u[i] = 0;
+  }
   if (SmartDrive)
   {
-    slopeCounter1 = 0;
-    slopeCounter2 = 0;
-    slopeCounter3 = 0;
-    slopeCounter4 = 0;
-    startingTime = micros();
-    for(unsigned i = 0; i<5000; i++)
-    {
-      if (digitalRead(m1e1) && slopeRise1)
-      {
-          if(digitalRead(m1e2))
-              slopeCounter1--;
-          else
-              slopeCounter1++;
-          slopeRise1 = 0;
-          slopeFall1 = 1;
-      }
-
-      if (!digitalRead(m1e1) && slopeFall1)
-      {
-          if(digitalRead(m1e2))
-              slopeCounter1++;
-          else
-              slopeCounter1--;
-          slopeRise1 = 1;
-          slopeFall1 = 0;
-      }
-  //----------------------------------------------------------
-      if (digitalRead(m2e1) && slopeRise2)
-      {
-          if(digitalRead(m2e2))
-              slopeCounter2--;
-          else
-              slopeCounter2++;
-          slopeRise2 = 0;
-          slopeFall2 = 1;
-      }
-
-      if (!digitalRead(m2e1) && slopeFall2)
-      {
-          if(digitalRead(m2e2))
-              slopeCounter2++;
-          else
-              slopeCounter2--;
-          slopeRise2 = 1;
-          slopeFall2 = 0;
-      }
-  //----------------------------------------------------------
-      if (digitalRead(m3e1) && slopeRise3)
-      {
-          if(digitalRead(m3e2))
-              slopeCounter3--;
-          else
-              slopeCounter3++;
-          slopeRise3 = 0;
-          slopeFall3 = 1;
-      }
-
-      if (!digitalRead(m3e1) && slopeFall3)
-      {
-          if(digitalRead(m3e2))
-              slopeCounter3++;
-          else
-              slopeCounter3--;
-          slopeRise3 = 1;
-          slopeFall3 = 0;
-      }
-  //----------------------------------------------------------
-      if (digitalRead(m4e1) && slopeRise4)
-      {
-          if(digitalRead(m4e2))
-              slopeCounter4--;
-          else
-              slopeCounter4++;
-          slopeRise4 = 0;
-          slopeFall4 = 1;
-      }
-
-      if (!digitalRead(m4e1) && slopeFall4)
-      {
-          if(digitalRead(m4e2))
-              slopeCounter4++;
-          else
-              slopeCounter4--;
-          slopeRise4 = 1;
-          slopeFall4 = 0;
-      }
-    }
-
-    czas = micros() - startingTime;
-  //  Serial.print("#Enkoders, ");
-  //  Serial.print(slopeCounter1);
-  //  Serial.print(", ");
-  //  Serial.print(slopeCounter2);
-  //  Serial.print(", ");
-  //  Serial.print(slopeCounter3);
-  //  Serial.print(", ");
-  //  Serial.print(slopeCounter4);
-  //  Serial.print(", ");
-  //  Serial.println(); // oddzielenie pustą linią dla zwiększenia czytelności
-    v1 = slopeCounter1*((60000000)/(RPR*PPR*(long)czas));
-    v2 = slopeCounter2*((60000000)/(RPR*PPR*(long)czas));
-    v3 = slopeCounter3*((60000000)/(RPR*PPR*(long)czas));
-    v4 = slopeCounter4*((60000000)/(RPR*PPR*(long)czas));
-
-    e1 = u[0]-v1;
-    e2 = u[1]-v2;
-    e3 = u[2]-v3;
-    e4 = u[3]-v4;
-
-    PowerOnMotor1 += Kp*e1;
-    PowerOnMotor2 += Kp*e2;
-    PowerOnMotor3 += Kp*e3;
-    PowerOnMotor4 += Kp*e4;
-
-    if(PowerOnMotor1 > 40000)
-      PowerOnMotor1 = 40000;
-    else if(PowerOnMotor1< -40000)
-      PowerOnMotor1 = -40000;
-
-      if(PowerOnMotor2 > 40000)
-      PowerOnMotor2 = 40000;
-    else if(PowerOnMotor2 < -40000)
-      PowerOnMotor2 = -40000;
-
-      if(PowerOnMotor3 > 40000)
-      PowerOnMotor3 = 40000;
-    else if(PowerOnMotor3 < -40000)
-      PowerOnMotor3 = -40000;
-
-      if(PowerOnMotor4 > 40000)
-      PowerOnMotor4 = 40000;
-    else if(PowerOnMotor4 < -40000)
-      PowerOnMotor4 = -40000;
+//    slopeCounter1 = 0;
+//    slopeCounter2 = 0;
+//    slopeCounter3 = 0;
+//    slopeCounter4 = 0;
+//    startingTime = micros();
+//    for(unsigned i = 0; i<5000; i++)
+//    {
+//      if (digitalRead(m1e1) && slopeRise1)
+//      {
+//          if(digitalRead(m1e2))
+//              slopeCounter1--;
+//          else
+//              slopeCounter1++;
+//          slopeRise1 = 0;
+//          slopeFall1 = 1;
+//      }
+//
+//      if (!digitalRead(m1e1) && slopeFall1)
+//      {
+//          if(digitalRead(m1e2))
+//              slopeCounter1++;
+//          else
+//              slopeCounter1--;
+//          slopeRise1 = 1;
+//          slopeFall1 = 0;
+//      }
+//  //----------------------------------------------------------
+//      if (digitalRead(m2e1) && slopeRise2)
+//      {
+//          if(digitalRead(m2e2))
+//              slopeCounter2--;
+//          else
+//              slopeCounter2++;
+//          slopeRise2 = 0;
+//          slopeFall2 = 1;
+//      }
+//
+//      if (!digitalRead(m2e1) && slopeFall2)
+//      {
+//          if(digitalRead(m2e2))
+//              slopeCounter2++;
+//          else
+//              slopeCounter2--;
+//          slopeRise2 = 1;
+//          slopeFall2 = 0;
+//      }
+//  //----------------------------------------------------------
+//      if (digitalRead(m3e1) && slopeRise3)
+//      {
+//          if(digitalRead(m3e2))
+//              slopeCounter3--;
+//          else
+//              slopeCounter3++;
+//          slopeRise3 = 0;
+//          slopeFall3 = 1;
+//      }
+//
+//      if (!digitalRead(m3e1) && slopeFall3)
+//      {
+//          if(digitalRead(m3e2))
+//              slopeCounter3++;
+//          else
+//              slopeCounter3--;
+//          slopeRise3 = 1;
+//          slopeFall3 = 0;
+//      }
+//  //----------------------------------------------------------
+//      if (digitalRead(m4e1) && slopeRise4)
+//      {
+//          if(digitalRead(m4e2))
+//              slopeCounter4--;
+//          else
+//              slopeCounter4++;
+//          slopeRise4 = 0;
+//          slopeFall4 = 1;
+//      }
+//
+//      if (!digitalRead(m4e1) && slopeFall4)
+//      {
+//          if(digitalRead(m4e2))
+//              slopeCounter4++;
+//          else
+//              slopeCounter4--;
+//          slopeRise4 = 1;
+//          slopeFall4 = 0;
+//      }
+//    }
+//
+//    czas = micros() - startingTime;
+//  //  Serial.print("#Enkoders, ");
+//  //  Serial.print(slopeCounter1);
+//  //  Serial.print(", ");
+//  //  Serial.print(slopeCounter2);
+//  //  Serial.print(", ");
+//  //  Serial.print(slopeCounter3);
+//  //  Serial.print(", ");
+//  //  Serial.print(slopeCounter4);
+//  //  Serial.print(", ");
+//  //  Serial.println(); // oddzielenie pustą linią dla zwiększenia czytelności
+//    v1 = slopeCounter1*((60000000)/(RPR*PPR*(long)czas));
+//    v2 = slopeCounter2*((60000000)/(RPR*PPR*(long)czas));
+//    v3 = slopeCounter3*((60000000)/(RPR*PPR*(long)czas));
+//    v4 = slopeCounter4*((60000000)/(RPR*PPR*(long)czas));
+//
+//    e1 = u[0]-v1;
+//    e2 = u[1]-v2;
+//    e3 = u[2]-v3;
+//    e4 = u[3]-v4;
+//
+//    PowerOnMotor1 += Kp*e1;
+//    PowerOnMotor2 += Kp*e2;
+//    PowerOnMotor3 += Kp*e3;
+//    PowerOnMotor4 += Kp*e4;
+//
+//    if(PowerOnMotor1 > 40000)
+//      PowerOnMotor1 = 40000;
+//    else if(PowerOnMotor1< -40000)
+//      PowerOnMotor1 = -40000;
+//
+//      if(PowerOnMotor2 > 40000)
+//      PowerOnMotor2 = 40000;
+//    else if(PowerOnMotor2 < -40000)
+//      PowerOnMotor2 = -40000;
+//
+//      if(PowerOnMotor3 > 40000)
+//      PowerOnMotor3 = 40000;
+//    else if(PowerOnMotor3 < -40000)
+//      PowerOnMotor3 = -40000;
+//
+//      if(PowerOnMotor4 > 40000)
+//      PowerOnMotor4 = 40000;
+//    else if(PowerOnMotor4 < -40000)
+//      PowerOnMotor4 = -40000;

 //    if (u1 == 0)
 //      SetSpeed(motor1, 0);
@@ -320,19 +331,19 @@
       SetSpeed(motor5, u[4]);
       SetSpeed(motor6, u[5]);

-      delay(2000);
-      for(int i=0; i<6; i++)
-      {
-      Serial.print(u[i]);
-      Serial.print("   ");
-      }
-      Serial.println("zeroing...");
-      u[0]=0;
-      u[1]=0;
-      u[2]=0;
-      u[3]=0;
-      u[4]=0;
-      u[5]=0;
+//      delay(2000);
+//      for(int i=0; i<6; i++)
+//      {
+//      Serial.print(u[i]);
+//      Serial.print("   ");
+//      }
+//      Serial.println("zeroing...");
+//      u[0]=0;
+//      u[1]=0;
+//      u[2]=0;
+//      u[3]=0;
+//      u[4]=0;
+//      u[5]=0;

   }
@@ -363,6 +374,7 @@

 void serialEvent() {
+  digitalWrite(13, LOW);
   while (Serial.available())
   {
     // get the new byte:
@@ -384,89 +396,53 @@
     String buffer = "";
     buffer.reserve(10);
     String buffer2 = "";
+    String decomposedMessage[7];
+    for(int i = 0; i<7; i++)
+    {
+      decomposedMessage[i].reserve(10);
+      decomposedMessage[i] = "";
+    }
+
     buffer2.reserve(10);
     String bufferMotor = "";
     bufferMotor.reserve(10);
     for (int i=0; i<spaceBar; i++)
       buffer += inputString.charAt(i);

+    for(int indexPtr = 0, segmentPtr = 0; indexPtr<(inputString.length()-1) && segmentPtr<7; indexPtr++)
+    {
+      decomposedMessage[segmentPtr] +=  inputString.charAt(indexPtr);
+      if(inputString.charAt(indexPtr+1) == ' ')
+      {
+        segmentPtr++;
+        indexPtr++;
+      }
+    }
+
 //    spaceBar = inputString.indexOf(' ');
-    for (int i=spaceBar+1; i<(inputString.length()-1); i++)
-      buffer2 += inputString.charAt(i);
-
-    if (buffer == "Set" || buffer == "SetSpeed")
+//    for (int i=spaceBar+1; i<(inputString.length()-1); i++)
+//      buffer2 += inputString.charAt(i);
+
+    if(decomposedMessage[0] == "Set")
     {
-      spaceBar = buffer2.indexOf(' ');
-      for (int i=spaceBar+1; i<(buffer2.length()); i++)
-        bufferMotor += buffer2.charAt(i);
-
-      Serial.println("Set command detected!");
-      if(bufferMotor=="motor1"){
-      u[0]= buffer2.toInt();
-      if (u[0]>mios)
-          u[0] = mios;
-      else if (u[0]<-mios)
-          u[0]= -mios;
-
-      e1 = u[0]-v1;
+      timeOfLastMessageReceived = millis();
+      for (int i=0; i<6; i++)
+      {
+        int buffer = decomposedMessage[i+1].toInt();
+        if(buffer > 0)
+          u[i] = min(buffer, mios);
+        else
+          u[i] = max(buffer, -mios);
       }
-      else if(bufferMotor=="motor2"){
-      u[1]= buffer2.toInt();
-      if (u[1]>mios)
-          u[1]= mios;
-      else if (u[1]<-mios)
-          u[1]= -mios;
-
-      e2 = u[1]-v2;
+
+      for (int i=0; i<6; i++)
+      {
+        Serial.print(u[i]);
+        Serial.print(", ");
       }
-      else if(bufferMotor=="motor3"){
-       u[2]= buffer2.toInt();
-      if (u[2]>mios)
-          u[2]= mios;
-      else if (u[2]<-mios)
-          u[2] = -mios;
-
-      e3 = u[2]-v3;
-      }
-      else if(bufferMotor=="motor4"){
-       u[3]= buffer2.toInt();
-      if (u[3]>mios)
-          u[3]= mios;
-      else if (u[3]<-mios)
-          u[3]= -mios;
-
-      e4 = u[3]-v4;
-      }
-      else if(bufferMotor=="motor5"){
-       u[4]= buffer2.toInt();
-      if (u[4]>mios)
-          u[4]= mios;
-      else if (u[3]<-mios)
-          u[4]= -mios;
-      }
-      else if(bufferMotor=="motor6"){
-       u[5]= buffer2.toInt();
-      if (u[5]>mios)
-          u[5]= mios;
-      else if (u[5]<-mios)
-          u[5]= -mios;
-      }
-      else if(bufferMotor="all")
-      {
-        int uForAll = buffer2.toInt();
-        if (uForAll > mios)
-          uForAll = mios;
-        else if (uForAll < -mios)
-          uForAll = -mios;
-
-        for(uint8_t i = 0; i<6; i++)
-          u[i] = uForAll;
-
-      }
-
-
-      SmartDrive = 1;
+      Serial.println("");
     }
+
     else if (buffer == "SetKp")
     {
       Kp = buffer2.toInt();


fix last commit

fix last commit

remove "<" at the beginning of ExecuteCommand.ino

--- examples/05.ThingSpeak/ExecuteCommand/ExecuteCommand.ino
+++ examples/05.ThingSpeak/ExecuteCommand/ExecuteCommand.ino
@@ -1,4 +1,4 @@
-<#include <SoftwareSerial.h>
+#include <SoftwareSerial.h>
 #include <Esp8266.h>
 #include <IPDParser.h>
 #include <HttpRequest.h>


Delete FeatherChorder.ino from this location

I put it in the wrong place, just cleaning up my mistake

--- FeatherChorder.ino
+++ FeatherChorder.ino
@@ -1,468 +0,0 @@
-/*
- * Arduino code for a Bluetooth version of the Chorder.
- * @author: clc@clcworld.net
- * additional code by: priestdo@budgardr.org
- * This version tested on/with the Adafruit Feather 32u4 Bluefruit LE
- *
- * It is a new arduino based chorder inspired by the SpiffChorder
- * which can be found at http://symlink.dk/projects/spiffchorder/
- */
-
-#include <Arduino.h>
-#include <SPI.h>
-#if not defined (_VARIANT_ARDUINO_DUE_X_)
-#include <SoftwareSerial.h>
-#endif
-
-#include "Adafruit_BLE.h"
-#include "Adafruit_BluefruitLE_SPI.h"
-#include "Adafruit_BluefruitLE_UART.h"
-
-#include "BluefruitConfig.h"
-#include "KeyCodes.h"
-#include "ChordMappings.h"
-
-/*========================================================================
-    APPLICATION SETTINGS
-
-    FACTORYRESET_ENABLE       Perform a factory reset when running this sketch
-
-                              Enabling this will put your Bluefruit LE module
-                              in a 'known good' state and clear any config
-                              data set in previous sketches or projects, so
-                              running this at least once is a good idea.
-
-                              When deploying your project, however, you will
-                              want to disable factory reset by setting this
-                              value to 0.  If you are making changes to your
-                              Bluefruit LE device via AT commands, and those
-                              changes aren't persisting across resets, this
-                              is the reason why.  Factory reset will erase
-                              the non-volatile memory where config data is
-                              stored, setting it back to factory default
-                              values.
-
-                              Some sketches that require you to bond to a
-                              central device (HID mouse, keyboard, etc.)
-                              won't work at all with this feature enabled
-                              since the factory reset will clear all of the
-                              bonding data stored on the chip, meaning the
-                              central device won't be able to reconnect.
-    MINIMUM_FIRMWARE_VERSION  Minimum firmware version to have some new features
-    -----------------------------------------------------------------------*/
-    #define FACTORYRESET_ENABLE         0
-    #define MINIMUM_FIRMWARE_VERSION    "0.6.6"
-/*=========================================================================*/
-
-// Create the bluefruit object, either software serial...uncomment these lines
-/*
-SoftwareSerial bluefruitSS = SoftwareSerial(BLUEFRUIT_SWUART_TXD_PIN, BLUEFRUIT_SWUART_RXD_PIN);
-
-Adafruit_BluefruitLE_UART ble(bluefruitSS, BLUEFRUIT_UART_MODE_PIN,
-                      BLUEFRUIT_UART_CTS_PIN, BLUEFRUIT_UART_RTS_PIN);
-*/
-
-/* ...or hardware serial, which does not need the RTS/CTS pins. Uncomment this line */
-// Adafruit_BluefruitLE_UART ble(BLUEFRUIT_HWSERIAL_NAME, BLUEFRUIT_UART_MODE_PIN);
-
-/* ...hardware SPI, using SCK/MOSI/MISO hardware SPI pins and then user selected CS/IRQ/RST */
-Adafruit_BluefruitLE_SPI ble(BLUEFRUIT_SPI_CS, BLUEFRUIT_SPI_IRQ, BLUEFRUIT_SPI_RST);
-
-/* ...software SPI, using SCK/MOSI/MISO user-defined SPI pins and then user selected CS/IRQ/RST */
-//Adafruit_BluefruitLE_SPI ble(BLUEFRUIT_SPI_SCK, BLUEFRUIT_SPI_MISO,
-//                             BLUEFRUIT_SPI_MOSI, BLUEFRUIT_SPI_CS,
-//                             BLUEFRUIT_SPI_IRQ, BLUEFRUIT_SPI_RST);
-
-// A small helper
-void error(const __FlashStringHelper*err) {
-  Serial.println(err);
-  while (1);
-}
-
-// moved to KeyCodes.h
-
-// moved to ChordMappings.h
-
-
-class Button {
-  byte _pin;  // The button's I/O pin, as an Arduino pin number.
-
-public:
-  Button(byte pin) : _pin(pin) {
-    pinMode(pin, INPUT_PULLUP);      // Make pin an input and activate pullup.
-  }
-
-  bool isDown() const {
-    // TODO: this assumes we're using analog pins!
-    //return analogRead(_pin) < 0x100;
-    return (digitalRead(_pin) == LOW);
-  }
-};
-
-// power regulator enabale control pin
-const int EnPin =  5;
-
-// Pin numbers for the keyboard switches, using the Arduino numbering.
-static const Button switch_pins[7] = {
-  Button(6),  // Pinky
-  Button(A5),  // Ring
-  Button(A4),  // Middle
-  Button(A3),  // Index
-  Button(A2),  // Near Thumb
-  Button(A1),  // Center Thumb
-  Button(A0),  // Far Thumb
-};
-
-void setup(void)
-{
-  // Ensure software power reset pin in high
-   pinMode(EnPin, OUTPUT);      // Make pin an output,
-   digitalWrite(EnPin, HIGH);  // and activate pullup.
-  //while (!Serial);  // Required for Flora & Micro
-  delay(500);
-
-  Serial.begin(115200);
-  Serial.println(F("Adafruit Bluefruit HID Chorder"));
-  Serial.println(F("---------------------------------------"));
-
-  /* Initialise the module */
-  Serial.print(F("Initialising the Bluefruit LE module: "));
-
-  if ( !ble.begin(VERBOSE_MODE) )
-  {
-    error(F("Couldn't find Bluefruit, make sure it's in CoMmanD mode & check wiring?"));
-  }
-  Serial.println( F("OK!") );
-
-  if ( FACTORYRESET_ENABLE )
-  {
-    /* Perform a factory reset to make sure everything is in a known state */
-    Serial.println(F("Performing a factory reset: "));
-    if ( ! ble.factoryReset() ){
-      error(F("Factory reset failed!"));
-    }
-  }
-
-  /* Disable command echo from Bluefruit */
-  ble.echo(false);
-
-  Serial.println("Requesting Bluefruit info:");
-  /* Print Bluefruit information */
-  ble.info();
-
-  // This demo only works with firmware 0.6.6 and higher!
-  // Request the Bluefruit firmware rev and check if it is valid
-  if ( !ble.isVersionAtLeast(MINIMUM_FIRMWARE_VERSION) )
-  {
-    error(F("This sketch requires firmware version " MINIMUM_FIRMWARE_VERSION " or higher!"));
-  }
-
-  /* Enable HID Service */
-  Serial.println(F("Enable HID Services (including Control Key): "));
-  if (! ble.sendCommandCheckOK(F( "AT+BleKeyboardEn=On"  ))) {
-    error(F("Failed to enable HID (firmware >=0.6.6?)"));
-  }
-
-  /* Adding or removing services requires a reset */
-  Serial.println(F("Performing a SW reset (service changes require a reset): "));
-  if (! ble.reset() ) {
-    error(F("Couldn't reset??"));
-  }
-
-
-  String stringOne =  String(0x45, HEX);
-
-  Serial.println(stringOne);
-}
-
-
-enum State {
-  PRESSING,
-  RELEASING,
-};
-
-State state = RELEASING;
-byte lastKeyState = 0;
-
-enum Mode {
-  ALPHA,
-  NUMSYM,
-  FUNCTION
-};
-
-bool isCapsLocked = false;
-bool isNumsymLocked = false;
-keymap_t modKeys = 0x00;
-
-Mode mode = ALPHA;
-
-void send(char* character) {
-//  Uart.print(character);
-}
-
-void sendKey(byte keyState){
-  keymap_t theKey;
-  // Determine the key based on the current mode's keymap
-  if (mode == ALPHA) {
-    theKey = keymap_default[keyState];
-  } else if (mode == NUMSYM) {
-    theKey = keymap_numsym[keyState];
-  } else {
-    theKey = keymap_function[keyState];
-  }
-
-  switch (theKey)  {
-  // Handle mode switching - return immediately after the mode has changed
-  // Handle basic mode switching
-  case MODE_NUM:
-    if (mode == NUMSYM) {
-      mode = ALPHA;
-    } else {
-      mode = NUMSYM;
-    }
-    return;
-  case MODE_FUNC:
-    if (mode == FUNCTION) {
-      mode = ALPHA;
-    } else {
-      mode = FUNCTION;
-    }
-    return;
-  case MODE_RESET:
-    mode = ALPHA;
-    modKeys = 0x00;
-    isCapsLocked = false;
-    isNumsymLocked = false;
-    return;
-  case MODE_MRESET:
-    mode = ALPHA;
-    modKeys = 0x00;
-    isCapsLocked = false;
-    isNumsymLocked = false;
-    digitalWrite(EnPin, LOW);  // turn off 3.3v regulator enable.
-    return;
-  // Handle mode locks
-  case ENUMKEY_cpslck:
-    if (isCapsLocked){
-      isCapsLocked = false;
-      modKeys = 0x00;
-    } else {
-      isCapsLocked = true;
-      modKeys = 0x02;
-    }
-    return;
-  case MODE_NUMLCK:
-    if (isNumsymLocked){
-      isNumsymLocked = false;
-      mode = ALPHA;
-    } else {
-      isNumsymLocked = true;
-      mode = NUMSYM;
-    }
-    return;
-  // Handle modifier keys toggling
-  case MOD_LCTRL:
-    modKeys = modKeys ^ 0x01;
-    return;
-  case MOD_LSHIFT:
-    modKeys = modKeys ^ 0x02;
-    return;
-  case MOD_LALT:
-    modKeys = modKeys ^ 0x04;
-    return;
-  case MOD_LGUI:
-    modKeys = modKeys ^ 0x08;
-    return;
-  case MOD_RCTRL:
-    modKeys = modKeys ^ 0x10;
-    return;
-  case MOD_RSHIFT:
-    modKeys = modKeys ^ 0x20;
-    return;
-  case MOD_RALT:
-    modKeys = modKeys ^ 0x40;
-    return;
-  case MOD_RGUI:
-    modKeys = modKeys ^ 0x80;
-    return;
-  // Handle special keys
-  case MULTI_NumShift:
-    if (mode == NUMSYM) {
-      mode = ALPHA;
-    } else {
-      mode = NUMSYM;
-    }
-    modKeys = modKeys ^ 0x02;
-    return;
-  case MULTI_CtlAlt:
-    modKeys = modKeys ^ 0x01;
-    modKeys = modKeys ^ 0x04;
-    return;
-  /* Everything after this sends actual keys to the system; break rather than
-     return since we want to reset the modifiers after these keys are sent. */
-  case MACRO_000:
-    sendRawKey(0x00, 0x27);
-    sendRawKey(0x00, 0x27);
-    sendRawKey(0x00, 0x27);
-    break;
-  case MACRO_00:
-    sendRawKey(0x00, 0x27);
-    sendRawKey(0x00, 0x27);
-    break;
-  case MACRO_quotes:
-    sendRawKey(0x02, 0x34);
-    sendRawKey(0x02, 0x34);
-    sendRawKey(0x00, 0x50);
-    break;
-  case MACRO_parens:
-    sendRawKey(0x02, 0x26);
-    sendRawKey(0x02, 0x27);
-    sendRawKey(0x00, 0x50);
-    break;
-  case MACRO_dollar:
-    sendRawKey(0x02, 0x21);
-    break;
-  case MACRO_percent:
-    sendRawKey(0x02, 0x22);
-    break;
-  case MACRO_ampersand:
-    sendRawKey(0x02, 0x24);
-    break;
-  case MACRO_asterisk:
-    sendRawKey(0x02, 0x25);
-    break;
-  case MACRO_question:
-    sendRawKey(0x02, 0x38);
-    break;
-  case MACRO_plus:
-    sendRawKey(0x02, 0x2E);
-    break;
-  case MACRO_openparen:
-    sendRawKey(0x02, 0x26);
-    break;
-  case MACRO_closeparen:
-    sendRawKey(0x02, 0x27);
-    break;
-  case MACRO_opencurly:
-    sendRawKey(0x02, 0x2F);
-    break;
-  case MACRO_closecurly:
-    sendRawKey(0x02, 0x30);
-    break;
-  // Handle Android specific keys
-  case ANDROID_search:
-    sendRawKey(0x04, 0x2C);
-    break;
-  case ANDROID_home:
-    sendRawKey(0x04, 0x29);
-    break;
-  case ANDROID_menu:
-    sendRawKey(0x10, 0x29);
-    break;
-  case ANDROID_back:
-    sendRawKey(0x00, 0x29);
-    break;
-  case ANDROID_dpadcenter:
-    sendRawKey(0x00, 0x5D);
-    break;
-  case MEDIA_playpause:
-    sendControlKey("PLAYPAUSE");
-    break;
-  case MEDIA_stop:
-    sendControlKey("MEDIASTOP");
-    break;
-  case MEDIA_next:
-    sendControlKey("MEDIANEXT");
-    break;
-  case MEDIA_previous:
-    sendControlKey("MEDIAPREVIOUS");
-    break;
-  case MEDIA_volup:
-    sendControlKey("VOLUME+,500");
-    break;
-  case MEDIA_voldn:
-    sendControlKey("VOLUME-,500");
-    break;
-  // Send the key
-  default:
-    sendRawKey(modKeys, theKey);
-    break;
-  }
-
-  modKeys = 0x00;
-  mode = ALPHA;
-  // Reset the modKeys and mode based on locks
-  if (isCapsLocked){
-    modKeys = 0x02;
-  }
-  if (isNumsymLocked){
-    mode = NUMSYM;
-  }
-}
-
-void sendRawKey(char modKey, char rawKey){
-    // Format for Bluefruit Feather is MOD-00-KEY.
-    String keys = String(modKey, HEX) + "-00-" + String(rawKey, HEX);
-
-    ble.print("AT+BLEKEYBOARDCODE=");
-    ble.println(keys);
-    // Must send this to release the keys.
-    ble.println("AT+BLEKEYBOARDCODE=00-00");
-}
-
-void sendControlKey(String cntrlName){
-  // note: for Volume +/- and the few other keys that take a time to hold, simply add it into the string
-  // for example:
-  //    sendControlKey("VOLUME+,500")
-  // will send Volume up and hold it for half a second
-  ble.print("AT+BLEHIDCONTROLKEY=");
-  ble.println(cntrlName);
-}
-byte previousStableReading = 0;
-byte currentStableReading = 0;
-long lastDebounceTime = 0;  // the last time the output pin was toggled
-long debounceDelay = 10;    // the debounce time; increase if the output flickers
-
-void processReading(){
-    switch (state) {
-    case PRESSING:
-      if (previousStableReading & ~currentStableReading) {
-        state = RELEASING;
-        sendKey(previousStableReading);
-      }
-      break;
-
-    case RELEASING:
-      if (currentStableReading & ~previousStableReading) {
-        state = PRESSING;
-      }
-      break;
-    }
-}
-
-void loop() {
-  // Build the current key state.
-  byte keyState = 0, mask = 1;
-  for (int i = 0; i < 7; i++) {
-    if (switch_pins[i].isDown()) keyState |= mask;
-    mask <<= 1;
-  }
-
-  if (lastKeyState != keyState) {
-    lastDebounceTime = millis();
-  }
-
-  if ((millis() - lastDebounceTime) > debounceDelay) {
-    // whatever the reading is at, it's been there for longer
-    // than the debounce delay, so take it as the actual current state:
-    currentStableReading = keyState;
-  }
-
-  if (previousStableReading != currentStableReading) {
-    processReading();
-    previousStableReading = currentStableReading;
-  }
-
-  lastKeyState = keyState;
-}
-


Lagt till tidnu.

Lagt till tidnu.

--- DHT22_uploader.ino
+++ DHT22_uploader.ino
@@ -310,12 +310,19 @@

       if (SPIFFS.exists("/upload_later.txt")) {
         boolean set_clock = true;
+        // Set time from file
+        time_from_file();
+
+        // Create the URL
+        String the_time = tid(now());
+        the_time.replace(" ", "%20");
+
         String file_url;
         f = SPIFFS.open("/upload_later.txt", "r");
         while (f.available()) {
           //Read line by line from the file
           file_url = f.readStringUntil('\n');
-          upload_url_to_page(client, file_url, set_clock);
+          upload_url_to_page(client, file_url + "&tidnu=" + String(the_time), set_clock);
           set_clock = false;
         }
         f.close();


add third analog channel for solar panel volts


reverted from testing log interval

reverted from testing log interval

--- src/main/arduino/temploggerBLE/temploggerBLE.ino
+++ src/main/arduino/temploggerBLE/temploggerBLE.ino
@@ -41,7 +41,7 @@
 /**
  * configuration parameters
  */
-#define LOGGING_FREQUENCY_MINUTES               1
+#define LOGGING_FREQUENCY_MINUTES              10
 #define BLE_REMAINS_ON_AFTER_POWER_ON_MINUTES  15
 #define TIME_ZONE_OFFSET_HOURS                 -4
 #define I2C_BUS_POWER                           2


Fixed calculation of UV intensity

Fixed calculation of UV intensity

--- files/template_home_wifi/template_home_wifi.ino
+++ files/template_home_wifi/template_home_wifi.ino
@@ -65,7 +65,7 @@
   sleep(1);
   if (Wire.available()) lsb = Wire.read();
   uvValue = (msb << 8) | lsb;
-  return uvValue * 5;
+  return uvValue * 5.625;
 }

 int printHexToStream(const uint8_t *data, uint8_t length, Print &stream) // prints 8-bit data in hex


Changed headline

Changed headline

--- arduino_script/arduino_script.ino
+++ arduino_script/arduino_script.ino
@@ -1,15 +1,6 @@
-/* Analog Read to LED
- * ------------------
- *
- * turns on and off a light emitting diode(LED) connected to digital
- * pin 13. The amount of time the LED will be on and off depends on
- * the value obtained by analogRead(). In the easiest case we connect
- * a potentiometer to analog pin 2.
- *
- * Created 1 December 2005
- * copyleft 2005 DojoDave <http://www.0j0.org>
- * http://arduino.berlios.de
- *
+/*
+ * Arduino Sensor Request
+ * by Jannis Jahr, 2017
  */

 int potPin = 2;    // select the input pin for the potentiometer (Analog)


remove leaks

remove leaks

--- arduino_server/arduino_server.ino
+++ arduino_server/arduino_server.ino
@@ -132,6 +132,7 @@

         prepareBuffer;
         wsGetHandshakeAnswer(&hs, buffer, &frameSize);
+        freeHandshake(&hs);
         sendAndLog(client, buffer, frameSize);
         state = WS_STATE_NORMAL;
         initNewFrame;
@@ -155,6 +156,7 @@

           prepareBuffer;
           wsMakeFrame(recievedString, dataSize, buffer, &frameSize, WS_TEXT_FRAME);
+          free(recievedString);
           sendAndLog(client, buffer, frameSize);
           initNewFrame;
         }


strings from flash memory (program code)

--- musicbox/musicbox.ino
+++ musicbox/musicbox.ino
@@ -29,7 +29,7 @@

 // Delays [ms]
 #define BLANK_DELAY    2500
-#define BLINK_DELAY      25
+#define BLINK_DELAY      20
 #define HOLD_DELAY     1500
 #define PAUSE_DELAY    1000
 #define READ_DELAY       50
@@ -112,7 +112,7 @@

   Serial.begin(14400);
   while (!Serial && millis() < nextIdleTick + 2000);
-  Serial.println("MusicBox setup");
+  Serial.println(F("MusicBox setup"));

   initializeCard();
   initializePlayer();
@@ -143,17 +143,17 @@
     Serial.println(F("SD failed, or not present"));
     while (1);  // don't do anything more
   }
-  Serial.println("SD initialized");
-
-  File root = SD.open("/");
+  Serial.println(F("SD initialized"));
+
+  File root = SD.open(F("/"));
   while (true) {
     File entry = root.openNextFile();
     if (!entry) break;
     Serial.print(entry.name());
     if (entry.isDirectory()) {
-      Serial.println("/");
+      Serial.println(F("/"));
     } else {
-      Serial.print("\t\t");
+      Serial.print(F("\t\t"));
       Serial.println(entry.size(), DEC);
     }
   }
@@ -183,13 +183,13 @@

   trellis.begin(0x70);
   //trellis.readSwitches(); // ignore already pressed switches
-  Serial.println("Trellis initialized");
+  Serial.println(F("Trellis initialized"));
 }

 void initializeTimer() {
   Timer1.initialize(1000);
   Timer1.attachInterrupt(timerIsr);
-  Serial.println("Timer initialized");
+  Serial.println(F("Timer initialized"));
 }

 void onEnterIdle(unsigned int delay) {
@@ -222,7 +222,7 @@

   // Rollover millis since start
   if (nextReadTick > now + ROLLOVER_GAP) {
-    Serial.println("Rollover timer ticks!");
+    Serial.println(F("Rollover timer ticks!"));
     nextReadTick = now + 1;
     nextIdleTick = now + 1;
     nextTimeoutTick = nextTimeoutTick == 0 ? 0 : now + IDLE_TIMEOUT;
@@ -287,7 +287,7 @@
 }

 void tickIdleTimeout() {
-  Serial.println("Timeout!");
+  Serial.println(F("Timeout!"));
   onTimeout();

   attachInterrupt(digitalPinToInterrupt(TRELLIS_INT_PIN), trellisIsr, LOW);
@@ -376,7 +376,7 @@
     switch (state) {
       case PLAY_SELECTED:
       case PLAY_PAUSED:
-        Serial.print("Stopped #"); Serial.println(playingAlbum);
+        Serial.print(F("Stopped #")); Serial.println(playingAlbum);
         blinkLED(BLUE_LED_PIN);
         stopPlaying();
         onStopPlaying();
@@ -385,7 +385,7 @@
       case IDLE_LIGHT_UP:
       case IDLE_TURN_OFF:
       case IDLE_WAIT_OFF:
-        Serial.println("Force timeout");
+        Serial.println(F("Force timeout"));
         blinkLED(BLUE_LED_PIN);
         delay(300);
         blinkLED(BLUE_LED_PIN);
@@ -401,11 +401,11 @@
   if (headphone != headphoneFirstMeasure && (audioLevel > HEADPHONE_THRESHOLD) != headphoneFirstMeasure) {
     // confirmed change
     onHeadphoneInserted(audioLevel < HEADPHONE_THRESHOLD);
-    Serial.print("Confirmed change, headphone "); Serial.println(headphoneFirstMeasure);
+    Serial.print(F("Confirmed change, headphone ")); Serial.println(headphoneFirstMeasure);
   } else if ((audioLevel < HEADPHONE_THRESHOLD) != headphoneFirstMeasure) {
     // there seems to be a change
     headphoneFirstMeasure = (audioLevel < HEADPHONE_THRESHOLD);
-    Serial.print("Possible change, headphone "); Serial.println(headphoneFirstMeasure);
+    Serial.print(F("Possible change, headphone ")); Serial.println(headphoneFirstMeasure);
   }

   return READ_DELAY;
@@ -415,7 +415,7 @@
   // No keys when paused
   if (state == PLAY_PAUSED) {
     // nop
-    Serial.println("Still paused");
+    Serial.println(F("Still paused"));

   // Same key pressed again
   } else if (state == PLAY_SELECTED && playingAlbum == index) {
@@ -438,35 +438,35 @@
   blinkSelected(playingAlbum);
   openNewAlbum(playingAlbum);
   if (playNextTrack()) {
-    Serial.print("Playing album #"); Serial.println(playingAlbum);
+    Serial.print(F("Playing album #")); Serial.println(playingAlbum);
     state = PLAY_SELECTED;
   } else {
-    Serial.print("Failed album #"); Serial.println(playingAlbum);
+    Serial.print(F("Failed album #")); Serial.println(playingAlbum);
     onStopPlaying();
   }
 }

 void onTryNextTrack() {
   if (playNextTrack()) {
-    Serial.print("Playing next track album #"); Serial.println(playingAlbum);
+    Serial.print(F("Playing next track album #")); Serial.println(playingAlbum);
     blinkSelected(playingAlbum);
     state = PLAY_SELECTED;
   } else {
-    Serial.print("Ended album #"); Serial.println(playingAlbum);
+    Serial.print(F("Ended album #")); Serial.println(playingAlbum);
     onStopPlaying();
   }
 }

 void onPause(bool pause) {
   if (pause) {
-    Serial.println("Pause");
+    Serial.println(F("Pause"));
     trellis.blinkRate(HT16K33_BLINK_HALFHZ);
     player.pausePlaying(true);
     enableAmplifier(false);
     nextTimeoutTick = millis() + PAUSE_TIMEOUT;
     state = PLAY_PAUSED;
   } else {
-    Serial.println("Resume");
+    Serial.println(F("Resume"));
     trellis.blinkRate(HT16K33_BLINK_1HZ);
     enableAmplifier(!headphone);
     player.pausePlaying(false);
@@ -505,7 +505,7 @@
   } else {
     volume = max(SPEAKER_VOLUME_MAX, min(volume, SPEAKER_VOLUME_MIN));
   }
-  Serial.print("Set Volume "); Serial.println(volume);
+  Serial.print(F("Set Volume ")); Serial.println(volume);
   player.setVolume(volume, volume);
 }

@@ -519,7 +519,7 @@

 boolean openNewAlbum(byte index) {
   int albumNr = index + 1;
-  String albumTemplate = "ALBUM";
+  String albumTemplate = F("ALBUM");
   String albumName = albumTemplate + albumNr;
   if (album && album.isDirectory()) album.close();
   album = SD.open(albumName);
@@ -533,7 +533,7 @@
   String albumName = album.name();
   String dirPath = albumName + '/';
   String filePath = dirPath + track.name();
-  Serial.print("Next track: "); Serial.println(filePath);
+  Serial.print(F("Next track: ")); Serial.println(filePath);
   track.close();

   player.startPlayingFile(filePath.c_str());


removed long delay before I forget it's there

--- particle/examples/local-compile/local-compile.ino
+++ particle/examples/local-compile/local-compile.ino
@@ -98,7 +98,6 @@
   }

   Serial.flush();
-  delay(2000);
   readData();

   if(!pseudopod.isConfigured()) {
@@ -125,7 +124,6 @@
       pseudopod.sendPins();
     }
   }
-
 }

 void connectToServer() {


ChangeBC127Baudrate: now starts by trying both baudrates.

--- examples/07-Bluetooth/ChangeBC127Baudrate/ChangeBC127Baudrate.ino
+++ examples/07-Bluetooth/ChangeBC127Baudrate/ChangeBC127Baudrate.ino
@@ -1,76 +1,131 @@
 /*
-*  ChangeBC127Baudrate
-*
-* Created: Ira Ray Jenkins, Creare, August 2021
-* Purpose: Demonstrate changing the baudrate of the BC127 module.
-*          The BC127 "RESTORE" command will reset the chip to default settings.
-*
+  ChangeBC127Baudrate
+
+  Created: Ira Ray Jenkins, Creare, August 2021
+           Extended by Chip Audette, August 2021
+
+  Purpose: Demonstrate changing the baudrate of the BC127 module.
+
+  WARNING: Be aware that this change in baud rate will persist on the BC127, even
+  after cycling the power. Being at a different baud rate will prevent you from a
+  ccessing the Bluetooth module from any other Tympan program.
+
+  Therefore, if you change the BC127 baud rate, be sure that your other programs are
+  set to use the new speed.  Or, if you want to change back to the "normal" BC127
+  speed, use this program again to change the baud rate to the factory default of 9600.
+
+  MIT License.  Use at your own risk.  Have fun!
+
 */

 #include <Arduino.h>
+#include <Tympan_Library.h>
+BLE        ble(&Serial1);

 // USER PARAMETERS
-#if 1
-  //switch from slow (factory) to fast
-  const int CURRENT_BAUD = 9600;  // how fast we are
-  const int NEW_BAUD = 115200;    // how fast we want to be
-#else
-  //switch from fast back to slow (factory)
-  const int CURRENT_BAUD = 115200;  // how fast we are
-  const int NEW_BAUD = 9600;    // how fast we want to be
-#endif
+const int TARGET_BAUDRATE = 115200;    //try 115200 (fast!) or 9600 (factory original)
 const int FIRMWARE_VERSION = 7; // what Melody firmware we are dealing with

-usb_serial_class *USB_Serial;
-HardwareSerial *BT_Serial;

-void echoIncomingUSBSerial(void)
-{
-    while (USB_Serial->available()) BT_Serial->write(USB_Serial->read());
+// //////////////////////////////////////////// Helper functions
+
+const int baudrate1 = 9600;   //here is one possible starting baudrate for the BLE module
+const int baudrate2 = 115200; //here is the other possible starting baudrate for the BLE module
+int cur_baudrate;  // this is the baudrate that we've set Serial1 to be
+void setSerial1BaudRate(int new_baud) {
+  Serial1.flush();
+  Serial1.end();
+  delay(500);
+  Serial1.begin(new_baud);
+  delay(500);
+  cur_baudrate = new_baud;
 }

-void echoIncomingBTSerial(void)
-{
-    while (BT_Serial->available()) USB_Serial->write(BT_Serial->read());
+//If the baudrate to the BLE modue matches that baudrate that the BLE module expects,
+//we should be able to ask its status and get a valid reply.  So, we don't get a valid
+//reply, the baudrate of Serial1 probably does not match.
+int checkStatusBLE(void) {
+  int ret_val = ble.status(true);
+  Serial.println("checkStatusBLE: reply code to status = " + String(ret_val));
+  if (ret_val != BC127::SUCCESS) {
+    Serial.println("checkStatusBLE: status() returned error: " + String(ret_val));
+  }
+  return ret_val;
 }

-void setup()
-{
-    Serial.begin(CURRENT_BAUD);  // Teensy Serial -> PC
-    Serial1.begin(CURRENT_BAUD); // BC127 Serial -> Teensy
+// Echo what's coming in on USB Serial out to Bluetooth Serial
+void echoIncomingUSBSerial(void) {
+  while (Serial.available()) Serial1.write(Serial.read());
+}

-    delay(500);
-    Serial.println("ChangeBC127Baudrate...");
-    delay(500);
-
+// Echo what's coming in on Bluetooth Serial out to USB Serial
+void echoIncomingBTSerial(void) {
+  while (Serial1.available()) {
+    char c = Serial1.read();
+    if (c == '\r') c = '\n'; //translate carriage return to newline
+    Serial.write(c);
+  }
+}
+
+
+// ///////////////////////////////////////////////////  Arduino setup() and loop()
+
+void setup() {
+  //Serial.begin(115200);  //on Teensy (and Tympan), you don't need to do this.
+
+  //tell the BLE class what firmware we think that is actually on the BC127
+  ble.set_BC127_firmware_ver(FIRMWARE_VERSION);
+
+  //Start Serial1 to the BT module
+  Serial.println("setup(): Starting Serial1 at " + String(baudrate1));
+  setSerial1BaudRate(baudrate1);
+
+  //check on ble module...
+  int ret_val = checkStatusBLE();
+  if (ret_val != BC127::SUCCESS) {
+
+    //try a different baud rate
+    Serial.println("setup(): Trying again but at " + String(baudrate2));
+    setSerial1BaudRate(baudrate2);
+    cur_baudrate = baudrate2;
+
+    //check on ble module again...
+    ret_val = checkStatusBLE();
+    if (ret_val == BC127::SUCCESS) {
+
+      // we were successful at the new baud rate, so stick with it!
+      Serial.println("Success! The module was at " + String(baudrate2));
+
+    } else {
+      //Failed.  So, return Serial1 to original baud rate
+      Serial.println("Returning to Serial1 to original baud rate...this whole thing probably will not work");
+      setSerial1BaudRate(baudrate1);
+      cur_baudrate = baudrate1;
+    }
+  }
+
+  if (cur_baudrate != TARGET_BAUDRATE) {
+    //let's try commanding the BC127 to the new baud rate anyway
+    Serial.println("Change baudrate on the BC127 to "  + String(TARGET_BAUDRATE) + "...");
     char cmdBuffer[100];
-
     if (FIRMWARE_VERSION > 5)  {
-        sprintf(cmdBuffer, "SET UART_CONFIG=%u OFF 0\rWRITE\rRESTORE\r", NEW_BAUD);
+      sprintf(cmdBuffer, "SET UART_CONFIG=%u OFF 0\rWRITE\rRESTORE\r", TARGET_BAUDRATE);  //restore? or do we want reset?
     } else  {
-        sprintf(cmdBuffer, "SET BAUD=%u\rWRITE\rRESTORE\r", NEW_BAUD);
+      sprintf(cmdBuffer, "SET BAUD=%u\rWRITE\rRESTORE\r", TARGET_BAUDRATE);  //restore?  or do we want reset?
     }
-
-    Serial.println("Change baudrate on the BC127...");
-    Serial1.write(cmdBuffer);
-    delay(500);
+    Serial1.write(cmdBuffer);  delay(500);
     echoIncomingBTSerial();

-    Serial.println("Ending and flushing...");
-    Serial.flush();
-    Serial.end();
-    Serial1.flush();
-    Serial1.end();
-    delay(500);
+    Serial.println("Switching Serial1 to new baud rate..." + String(TARGET_BAUDRATE));
+    setSerial1BaudRate(TARGET_BAUDRATE);
+    cur_baudrate = TARGET_BAUDRATE;
+  }

-    Serial.println("Re-opening with new baudrates...(this should not appear?)");
-    Serial.begin(NEW_BAUD);
-    Serial1.begin(NEW_BAUD);
-    Serial.println("Openned with new baudrates...");
+  Serial.println("Begin echoing commands with BC127.  Try BC127 commands like STATUS or VERSION...(carriage return!)");
 }

-void loop()
-{
-    echoIncomingUSBSerial();
-    echoIncomingBTSerial();
+void loop() {
+  echoIncomingUSBSerial();
+  echoIncomingBTSerial();
+  delay(5);
 }


indent

indent

--- vibrate_alarm_clock_2.ino
+++ vibrate_alarm_clock_2.ino
@@ -193,9 +193,9 @@

   if((currentState == NORMAL)
-    && !vibrate){
+  && !vibrate){
     //Only sleep if no alarm is set. If in other modes like setting, give max performance.
-    LowPower.powerDown(SLEEP_15Ms, ADC_OFF, BOD_OFF);
+     LowPower.powerDown(SLEEP_15Ms, ADC_OFF, BOD_OFF);

   }

@@ -745,3 +745,4 @@

+


Update my_fc.ino

Update my_fc.ino

--- M4/my_fc/my_fc.ino
+++ M4/my_fc/my_fc.ino
@@ -1,5 +1,5 @@
 #include <Wire.h>
-#include "FXAS21002C.h"
+#include <FXAS21002C.h>
 #include <Servo.h>

@@ -16,7 +16,7 @@
 //PID gain and limit settings
 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 float pid_p_gain_roll = 1.3;               //Gain setting for the roll P-controller (1.3)
-float pid_i_gain_roll = 0.05;              //Gain setting for the roll I-controller (0.3)
+float pid_i_gain_roll = 0.5;              //Gain setting for the roll I-controller (0.3)
 float pid_d_gain_roll = 15;                //Gain setting for the roll D-controller (15)
 int pid_max_roll = 400;                    //Maximum output of the PID-controller (+/-)

@@ -25,9 +25,9 @@
 float pid_d_gain_pitch = pid_d_gain_roll;  //Gain setting for the pitch D-controller.
 int pid_max_pitch = pid_max_roll;          //Maximum output of the PID-controller (+/-)

-float pid_p_gain_yaw = 4.0;                //Gain setting for the pitch P-controller. //4.0
+float pid_p_gain_yaw = 3;                //Gain setting for the pitch P-controller. //4.0
 float pid_i_gain_yaw = 0.02;               //Gain setting for the pitch I-controller. //0.02
-float pid_d_gain_yaw = 0.0;                //Gain setting for the pitch D-controller.
+float pid_d_gain_yaw = 0;                //Gain setting for the pitch D-controller.
 int pid_max_yaw = 400;                     //Maximum output of the PID-controller (+/-)

@@ -76,8 +76,11 @@
 float pid_i_mem_pitch, pid_pitch_setpoint, gyro_pitch_input, pid_output_pitch, pid_last_pitch_d_error;
 float pid_i_mem_yaw, pid_yaw_setpoint, gyro_yaw_input, pid_output_yaw, pid_last_yaw_d_error;

-uint32_t lastWrite,lastUpdate;
-
+uint32_t lastWrite,lastUpdate,compute_time;
+
+int cal_int;
+double gyro_roll_cal, gyro_pitch_cal, gyro_yaw_cal;
+byte highByte, lowByte;
 /**
  * Modes:
  * 0 = standby -> send no pulse or idle
@@ -93,6 +96,8 @@
   pinMode(13, OUTPUT);
   digitalWrite(13, LOW);

+                                              //Give the gyro time to start.
+
   Serial.begin(115200);
   Wire1.begin();

@@ -114,9 +119,21 @@
   gyro.getGres();

   //calibrate gyro
-  digitalWrite(13, HIGH);
-  gyro.calibrate();
-  digitalWrite(13, LOW);
+  for (cal_int = 0; cal_int < 2000 ; cal_int ++){              //Take 2000 readings for calibration.
+    if(cal_int % 15 == 0)digitalWrite(13, !digitalRead(13));   //Change the led status to indicate calibration.
+    gyro_signalen();                                           //Read the gyro output.
+    gyro_roll_cal += gyro_roll;                                //Ad roll value to gyro_roll_cal.
+    gyro_pitch_cal += gyro_pitch;                              //Ad pitch value to gyro_pitch_cal.
+    gyro_yaw_cal += gyro_yaw;                                  //Ad yaw value to gyro_yaw_cal.
+    delayMicroseconds(1000);                                   //Wait 1000us.
+    delay(3);                                                  //Wait 3 milliseconds before the next loop.
+  }
+
+  //Now that we have 2000 measures, we need to devide by 2000 to get the average gyro offset.
+  gyro_roll_cal /= 2000;                                       //Divide the roll total by 2000.
+  gyro_pitch_cal /= 2000;                                      //Divide the pitch total by 2000.
+  gyro_yaw_cal /= 2000;                                        //Divide the yaw total by 2000.
+

   pid_i_mem_roll = 0;
   pid_last_roll_d_error = 0;
@@ -146,6 +163,7 @@

       calculate_pid();
       updateServo(); //update pwn signals
+      compute_time=micros()-lastUpdate;
     }

     if(micros() - lastWrite >= 500000)
@@ -159,12 +177,19 @@
       Serial.print(",");
       Serial.print(gyro_yaw);
       Serial.print(",");
-      Serial.print(front_left);
-      Serial.print(",");
-      Serial.print(checksum);
-      Serial.print(",");
-      Serial.print(checksumIn);
-      Serial.print(",");
+      Serial.print(pid_output_pitch);
+      Serial.print(",");
+      Serial.print(pid_output_roll);
+      Serial.print(",");
+      Serial.print(pid_output_yaw);
+      Serial.print(",");
+      Serial.print(target_pitch);
+      Serial.print(",");
+      Serial.print(target_roll);
+      Serial.print(",");
+      Serial.print(target_yaw);
+      Serial.print(",");
+      Serial.print(compute_time);
       Serial.println("*00\n");
     }

@@ -289,8 +314,8 @@
     for(it=startIndex;it<=stopIndex;it++) {
       if(buffer[it] == ',' || buffer[it] == '*') {
         strncpy (tempBuffer, buffer+startIndex, it-startIndex );
-        double roll_tmp = max(0,min(20,strtod(tempBuffer,NULL)));
-        target_roll = (roll_tmp - 10)*10;
+        double roll_tmp = max(0,min(200,strtod(tempBuffer,NULL)));
+        target_roll = (roll_tmp - 100)*0.4;
         break;
       }
     }
@@ -300,8 +325,8 @@
     for(it=startIndex;it<=stopIndex;it++) {
       if(buffer[it] == ',' || buffer[it] == '*') {
         strncpy (tempBuffer, buffer+startIndex, it-startIndex );
-        double pitch_tmp = max(0,min(20,strtod(tempBuffer,NULL)));
-        target_pitch = (pitch_tmp - 10)*10;
+        double pitch_tmp = max(0,min(200,strtod(tempBuffer,NULL)));
+        target_pitch = (pitch_tmp - 100)*0.4;
         break;
       }
     }
@@ -311,8 +336,8 @@
     for(it=startIndex;it<=stopIndex;it++) {
       if(buffer[it] == ',' || buffer[it] == '*') {
         strncpy (tempBuffer, buffer+startIndex, it-startIndex );
-        double yaw_tmp = max(0,min(20,strtod(tempBuffer,NULL)));
-        target_yaw = (yaw_tmp - 10)*10;
+        double yaw_tmp = max(0,min(200,strtod(tempBuffer,NULL)));
+        target_yaw = (yaw_tmp - 100)*0.4;
         break;
       }
     }
@@ -393,14 +418,17 @@
 }

 void gyro_signalen(){
+
   gyro.readGyroData();
-  gyro_pitch = (M_pi/180)*gyro.gyroData.x*gyro.gRes;
+  gyro_pitch = gyro.gyroData.x*gyro.gRes;
   gyro_pitch *= -1;
-  gyro_roll = (M_pi/180)*gyro.gyroData.y*gyro.gRes;
+  if(cal_int == 2000)gyro_pitch -= gyro_pitch_cal;
+  gyro_roll = gyro.gyroData.y*gyro.gRes;
   gyro_roll *= -1;
-  gyro_yaw = (M_pi/180)*gyro.gyroData.z*gyro.gRes;
+  if(cal_int == 2000)gyro_roll -= gyro_roll_cal;
+  gyro_yaw = gyro.gyroData.z*gyro.gRes;
   gyro_yaw *= -1;
-
+  if(cal_int == 2000)gyro_yaw -= gyro_yaw_cal;
 }

 void calculate_pid(){
@@ -440,5 +468,3 @@

   pid_last_yaw_d_error = pid_error_temp;
 }
-
-


Capture: use pin 3 for input, not 2

Capture: use pin 3 for input, not 2

--- Capture/Capture.ino
+++ Capture/Capture.ino
@@ -1,4 +1,4 @@
-int in = 2;
+int in = 3;
 int debug = 4;

 static const int sampleLength = 52;


add 1 more tilt sw

add 1 more tilt sw

--- _03-hx711-scale/_03-hx711-scale-v2-battery-external-Interrupt-02/_03-hx711-scale-pro-mini/_03-hx711-scale-pro-mini.ino
+++ _03-hx711-scale/_03-hx711-scale-v2-battery-external-Interrupt-02/_03-hx711-scale-pro-mini/_03-hx711-scale-pro-mini.ino
@@ -8,6 +8,7 @@

 // tilt switch
 const int wakeUpPin     = 2;
+const int wakeUpPin2    = 3;
 const int espResetPin   = 9;
 const int ledPowerPin   = 10;

@@ -47,6 +48,7 @@
   Wire.onReceive(receiveEvent);

   pinMode(wakeUpPin, INPUT_PULLUP);
+  pinMode(wakeUpPin2, INPUT_PULLUP);

   pinMode(ledPowerPin, OUTPUT);
   //pinMode(espnemoIsOnPadPin, OUTPUT);
@@ -67,6 +69,7 @@
   Serial.println("Initializing scale : done");

   attachInterrupt(0, WakeUp, CHANGE);
+  attachInterrupt(1, WakeUp, CHANGE);

   sleepNow();

@@ -86,11 +89,13 @@
   set_sleep_mode(SLEEP_MODE_PWR_DOWN);
   sleep_enable();
   attachInterrupt(0, WakeUp, CHANGE);
+  attachInterrupt(1, WakeUp, CHANGE);

   sleep_mode();

   sleep_disable();
   detachInterrupt(0);
+  detachInterrupt(1);

   Serial.println("Wake up at sleepNow");
   Serial.println(millis() - startMills);
@@ -98,7 +103,7 @@
   MeasuredIsSent = LOW;
   mqttMsgSent = LOW;
   IsEspReseted = LOW;
-
+
   Attempt = 0;
   nofchecked = 0;
   ave.push(0);
@@ -150,11 +155,11 @@
     Serial.print(" ==> no ==> ");
     Serial.print(nofchecked);
     Serial.print(" ==> avg ==> ");
-    Serial.print(ave.mean());
+    Serial.print(ave.mean());
     Serial.print(" ==> max - min ==> ");
-    Serial.print( ave.maximum() - ave.minimum() );
+    Serial.print( ave.maximum() - ave.minimum() );
     Serial.print(" ==> stddev ==> ");
-    Serial.println(ave.stddev());
+    Serial.println(ave.stddev());

     if ( Measured > 500 ) {
       ave.push(Measured);
@@ -199,8 +204,8 @@

   }

-
-  if (  IsEspReseted == HIGH )
+
+  if (  IsEspReseted == HIGH )
   {
     Attempt++;
     if ( Attempt == 20 )
@@ -251,9 +256,9 @@
   myArray[3] = int(VccValue) & 0xFF;

   Wire.write(myArray, 4);
-
+
   MeasuredIsSent = HIGH;
-
+
 }

 void receiveEvent(int howMany)


Update SabreMaster.ino

Update SabreMaster.ino

Changed the attenuation handling for key up and key down in the setVolume method. Not tested yet.

--- SabreMaster.ino
+++ SabreMaster.ino
@@ -228,16 +228,16 @@
 {
 	if (value == INCREASE)
 	{
+		if (dac.Attenuation > 0)
+		{
+			dac.setVolume(dac.Attenuation -= 1);
+		}
+	}
+	else
+	{
 		if (dac.Attenuation < 99)
 		{
-			dac.setVolume(dac.Attenuation += 1);
-		}
-	}
-	else
-	{
-		if (dac.Attenuation > 0)
-		{
-			dac.setVolume(dac.Attenuation -= 1);
+			dac.setVolume(dac.Attenuation += 1);
 		}
 	}
 	gui.printLargeAttenuation(99 - dac.Attenuation, 13);


Lots of minor fixes, made sure SW and HW work together; need to add a dedicated LED module to make things tidy

--- ROVMain/ROVMain.ino
+++ ROVMain/ROVMain.ino
@@ -20,7 +20,7 @@
  * 26 Sep 2015 - 2.1.2 - Alek Lidtke - put arming modules into a dedicated function to not freeze the GUI when doing so.
  */

-//#define DEBUG_PRINTOUT
+//#define DEBUG_PRINTOUT // this will cause issues with arming modules as the GUI expects a delay in ms to be returned upon sending "armModules,1"; either fix or don't use the GUI in conjuction with this flag

 // Custom includes.
 #include "Module.h"
@@ -56,13 +56,13 @@

 // Pins are pairs of close-by pins with PWM and digital ones.
 BrushlessDCMotor engine1 = BrushlessDCMotor("motorPortHor", THROTTLE_STEPS, MOTOR_MAX_PULSE_WIDTH,
-	MOTOR_MIN_PULSE_WIDTH, MOTOR_ARM_PULSE_WIDTH, 9, 8);
+	MOTOR_MIN_PULSE_WIDTH, MOTOR_ARM_PULSE_WIDTH, 3, 2); // orange // 1st-pwm, 2nd-digital
 BrushlessDCMotor engine2 = BrushlessDCMotor("motorStbdHor", THROTTLE_STEPS, MOTOR_MAX_PULSE_WIDTH,
-	MOTOR_MIN_PULSE_WIDTH, MOTOR_ARM_PULSE_WIDTH, 6, 7);
+	MOTOR_MIN_PULSE_WIDTH, MOTOR_ARM_PULSE_WIDTH, 5, 4); // green
 BrushlessDCMotor engine3 = BrushlessDCMotor("motorPortVer", THROTTLE_STEPS,MOTOR_MAX_PULSE_WIDTH,
-	MOTOR_MIN_PULSE_WIDTH, MOTOR_ARM_PULSE_WIDTH, 5, 4);
+	MOTOR_MIN_PULSE_WIDTH, MOTOR_ARM_PULSE_WIDTH, 6, 7); // white
 BrushlessDCMotor engine4 = BrushlessDCMotor("motorStbdVer", THROTTLE_STEPS, MOTOR_MAX_PULSE_WIDTH,
-	MOTOR_MIN_PULSE_WIDTH, MOTOR_ARM_PULSE_WIDTH, 3, 2);
+	MOTOR_MIN_PULSE_WIDTH, MOTOR_ARM_PULSE_WIDTH, 9, 8); // blue

 /* =============================================================================
  * MISC ACTUATOR AND COMMAND DEFINITIONS.
@@ -91,7 +91,7 @@
  * =============================================================================
  */
 // Input and output data buffers.
-#define DATABUFFERSIZE 80
+#define DATABUFFERSIZE 180
 char inputDataBuffer[DATABUFFERSIZE+1]; // Where the received command will be temporarily held. Add 1 for NULL terminator at the end.
 String outputDataBuffer = ""; // We'll store a message here before sending it.

@@ -112,7 +112,12 @@
 /* Prepare to listen to commands over serial and start everything up. */
 {
 	armModulesModule.setValue(0); // Don't arm the modules by default, wait for a command.
-	refreshRate.setValue(10); // Set default delay in milliseconds in the main loop/
+	refreshRate.setValue(10); // Set default delay in milliseconds in the main loop
+	forwardLED.setValue(0);
+
+	// set modes for pins used by simple switch modules
+	pinMode(ON_LED_PIN, OUTPUT);
+	pinMode(FORWARD_LED_PIN, OUTPUT);

 	//TODO: do some system checks, like battery level, connections etc.

@@ -141,6 +146,16 @@
 	{
 		armModules(); // This function handles everything.
 		armModulesModule.setValue(0); // We're done arming now.
+	}
+
+	// LED switch
+	if (forwardLED.getValue() == 1)
+	{
+		digitalWrite(FORWARD_LED_PIN, HIGH);
+	}
+	else
+	{
+		digitalWrite(FORWARD_LED_PIN, LOW);
 	}

 	// Send readings from all the sensors over serial after this has been requested by a command.
@@ -211,14 +226,13 @@
 {
   // Get the first data token.
   char * token;
-  token = strtok (inputDataBuffer, DATA_DELIMITER);
+  token = strtok(inputDataBuffer, DATA_DELIMITER);

   // Parse the entire inputDataBuffer of tokens (commands and their value arguments).
   int nextActuatorIndex = -1; // Index of the actuator value for which is sent in this part of the telecommand.

   while (token != NULL)
   {
-
   	// If next actuator index < 0 we have no value to read now
   	if (nextActuatorIndex >= 0)
   	{
@@ -247,7 +261,7 @@
 	}

 	// Continue to the new token.
-	token = strtok (NULL, DATA_DELIMITER);
+	token = strtok(NULL, DATA_DELIMITER);
   }
 }


Pinout changed for final PCB

Pinout changed for final PCB

--- RC_Transmitter.ino
+++ RC_Transmitter.ino
@@ -1,8 +1,9 @@
 // Micro RC Project. a tiny little 2.4GHz RC unit!
 // 3.3V, 8MHz Pro Mini, 2.4GHz NRF24L01 radio module
 // SSD 1306 128 x 63 0.96" OLED
-
-float codeVersion = 0.9;
+// Custom PCB from OSH Park
+
+float codeVersion = 1.0;

 //
 // =======================================================================================================
@@ -93,8 +94,8 @@
 byte rightJoystickButtonState;

 // Buttons
-#define BUTTON_LEFT 0
-#define BUTTON_RIGHT 1
+#define BUTTON_LEFT 1
+#define BUTTON_RIGHT 10

 byte leftButtonState;
 byte rightButtonState;
@@ -113,6 +114,7 @@
 // OLED display
 U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_FAST);  // I2C / TWI  FAST instead of NONE = 400kHz I2C!
 int activeScreen = 0; // the currently displayed screen number (0 = splash screen)
+boolean displayLocked = true;

 //
 // =======================================================================================================
@@ -123,7 +125,7 @@
 void setupRadio() {
   radio.begin();
   radio.setChannel(1);
-  radio.setPALevel(RF24_PA_HIGH);
+  radio.setPALevel(RF24_PA_LOW); // Set Power Amplifier (PA) level to one of four levels: RF24_PA_MIN, RF24_PA_LOW, RF24_PA_HIGH and RF24_PA_MAX
   radio.setDataRate(RF24_250KBPS);
   radio.setAutoAck(true);                  // Ensure autoACK is enabled
   radio.enableAckPayload();
@@ -175,8 +177,8 @@
 #endif

   // LED setup
-  greenLED.begin(5); // Green LED on pin 5
-  redLED.begin(6); // Red LED on pin 6
+  greenLED.begin(6); // Green LED on pin 5
+  redLED.begin(5); // Red LED on pin 6

   // Pinmodes (all other pinmodes are handled inside libraries)
   pinMode(JOYSTICK_BUTTON_LEFT, INPUT_PULLUP);
@@ -191,7 +193,7 @@
   setupPowerfunctions();

   // Display setup
-  u8g.setRot180(); // flip screen, if required
+  //u8g.setRot180(); // flip screen, if required
   u8g.setFontRefHeightExtendedText();
   u8g.setDefaultForegroundColor();
   u8g.setFontPosTop();
@@ -224,13 +226,13 @@
     drawDisplay();
   }

-  // right button (integrated in Joystick)
+  // Right button (integrated in Joystick)
   if (DRE(digitalRead(JOYSTICK_BUTTON_RIGHT), rightJoystickButtonState)) {
     data.mode2 = !data.mode2;
     drawDisplay();
   }

-  // left button S2: Channel selection
+  // Left button S2: Channel selection
   if (DRE(digitalRead(BUTTON_LEFT), leftButtonState)) {
     vehicleNumber ++;
     if (vehicleNumber > maxVehicleNumber) vehicleNumber = 1;
@@ -239,7 +241,7 @@
     drawDisplay();
   }

-  // right button S3: Change transmission mode. Radio <> IR
+  // Right button S3: Change transmission mode. Radio <> IR
   if (DRE(digitalRead(BUTTON_RIGHT), rightButtonState)) {
     IrMode = !IrMode;
     drawDisplay();
@@ -252,10 +254,29 @@
 // =======================================================================================================
 //
 void readJoysticks() {
-  data.axis1 = map(analogRead(A0), 0, 1023, 0, 100); // Aileron (Steering for car)
-  data.axis2 = map(analogRead(A1), 0, 1023, 0, 100); // Elevator
-  data.axis3 = map(analogRead(A2), 0, 1023, 0, 100); // Throttle
-  data.axis4 = map(analogRead(A3), 0, 1023, 0, 100); // Rudder
+
+  // save previous joystick positions
+  byte previousAxis1 = data.axis1;
+  byte previousAxis2 = data.axis2;
+  byte previousAxis3 = data.axis3;
+  byte previousAxis4 = data.axis4;
+
+  // Read current joystick positions
+  data.axis1 = map(analogRead(A1), 0, 1023, 0, 100); // Aileron (Steering for car)
+  data.axis2 = map(analogRead(A0), 0, 1023, 0, 100); // Elevator
+  data.axis3 = map(analogRead(A3), 0, 1023, 0, 100); // Throttle
+  data.axis4 = map(analogRead(A2), 0, 1023, 0, 100); // Rudder
+
+  // Only allow display refresh, if no value has changed!
+  if (previousAxis1 != data.axis1 ||
+      previousAxis2 != data.axis2 ||
+      previousAxis3 != data.axis3 ||
+      previousAxis4 != data.axis4) {
+    displayLocked = true;
+  }
+  else {
+    displayLocked = false;
+  }
 }

 //
@@ -329,8 +350,8 @@
     }
   }

-  // if the transmission was not confirmed after > 150ms...
-  if (millis() - previousSuccessfulTransmission > 150) {
+  // if the transmission was not confirmed (from the receiver) after > 200ms...
+  if (millis() - previousSuccessfulTransmission > 200) {
     greenLED.on();
     transmissionState = false;
     memset(&payload, 0, sizeof(payload)); // clear the payload array, if transmission error
@@ -346,22 +367,24 @@
 #endif
   }

-  // refresh transmission state on the display, if changed
-  if (transmissionState != previousTransmissionState) {
-    previousTransmissionState = transmissionState;
-    drawDisplay();
-  }
-
-  // refresh Rx Vcc on the display, if changed more than +/- 0.05V
-  if (payload.vcc - 0.05 >= previousRxVcc || payload.vcc + 0.05 <= previousRxVcc) {
-    previousRxVcc = payload.vcc;
-    drawDisplay();
-  }
-
-  // refresh Rx V Batt on the display, if changed more than +/- 0.2V
-  if (payload.batteryVoltage - 0.5 >= previousRxVbatt || payload.batteryVoltage + 0.5 <= previousRxVbatt) {
-    previousRxVbatt = payload.batteryVoltage;
-    drawDisplay();
+  if (!displayLocked) {
+    // refresh transmission state on the display, if changed
+    if (transmissionState != previousTransmissionState) {
+      previousTransmissionState = transmissionState;
+      drawDisplay();
+    }
+
+    // refresh Rx Vcc on the display, if changed more than +/- 0.05V
+    if (payload.vcc - 0.05 >= previousRxVcc || payload.vcc + 0.05 <= previousRxVcc) {
+      previousRxVcc = payload.vcc;
+      drawDisplay();
+    }
+
+    // refresh Rx V Batt on the display, if changed more than +/- 0.2V
+    if (payload.batteryVoltage - 0.5 >= previousRxVbatt || payload.batteryVoltage + 0.5 <= previousRxVbatt) {
+      previousRxVbatt = payload.batteryVoltage;
+      drawDisplay();
+    }
   }

@@ -402,7 +425,7 @@

 void checkBattery() {

-  txBatt = analogRead(BATTERY_DETECT_PIN) / 103.33; // 1023steps / 9.9V = 103.33
+  txBatt = (analogRead(BATTERY_DETECT_PIN) / 103.33) + 0.7; // 1023steps / 9.9V = 103.33 + 0.7 diode drop!
   txVcc = readVcc() / 1000.0 ;

   if (txBatt >= 4.4) {


Removed MQTT

Removed MQTT

Removed the Adafruti MQTT librari as connectivity to adafruit.io seems to be problematic.  Return to this later.
Tidied up some code - mostly cosmetic.

--- WeatherStation.ino
+++ WeatherStation.ino
@@ -36,8 +36,6 @@
 #include <NtpClientLib.h>
 #include <Adafruit_Sensor.h>
 #include <Adafruit_BME280.h>
-#include "Adafruit_MQTT.h"
-#include "Adafruit_MQTT_Client.h"
 #include <SparkFunTSL2561.h>
 #include <Wire.h>
 #include <SPI.h>
@@ -90,52 +88,7 @@
 #define PHANT_DOMAIN        "data.sparkfun.com"
 #define PHANT_PAGE          "/input/zDA9M8dQlahOqo4bx5Dd"
 #define PHANT_PORT          80
-
-//
-//  Stuff required for Adafruit IO.
-//
 WiFiClient _wifiClient;
-#define AIO_SERVER      "io.adafruit.com"
-#define AIO_SERVERPORT  1883
-
-// Store the MQTT server, client ID, username, and password in flash memory.
-// This is required for using the Adafruit MQTT library.
-const char MQTT_SERVER[] PROGMEM = AIO_SERVER;
-// Set a unique MQTT client ID using the AIO key + the date and time the sketch
-// was compiled (so this should be unique across multiple devices for a user,
-// alternatively you can manually set this to a GUID or other random value).
-const char MQTT_CLIENTID[] PROGMEM = AIO_KEY __DATE__ __TIME__;
-const char MQTT_USERNAME[] PROGMEM = AIO_USERNAME;
-const char MQTT_PASSWORD[] PROGMEM = AIO_KEY;
-
-// Setup the MQTT client class by passing in the WiFi client and MQTT server and login details.
-Adafruit_MQTT_Client mqtt(&_wifiClient, MQTT_SERVER, AIO_SERVERPORT, MQTT_CLIENTID, MQTT_USERNAME, MQTT_PASSWORD);
-const char WINDSPEED_FEED[] PROGMEM = AIO_USERNAME "/feeds/windspeed";
-Adafruit_MQTT_Publish _windSpeedFeed = Adafruit_MQTT_Publish(&mqtt, WINDSPEED_FEED);
-
-const char WIND_DIRECTION[] PROGMEM = AIO_USERNAME "/feeds/winddirection";
-Adafruit_MQTT_Publish _windDirectionFeed = Adafruit_MQTT_Publish(&mqtt, WIND_DIRECTION);
-
-const char UVLIGHT_FEED[] PROGMEM = AIO_USERNAME "/feeds/uvlight";
-Adafruit_MQTT_Publish _uvLightFeed = Adafruit_MQTT_Publish(&mqtt, UVLIGHT_FEED);
-
-const char RAINFALL_FEED[] PROGMEM = AIO_USERNAME "/feeds/rainfall";
-Adafruit_MQTT_Publish _rainFallFeed = Adafruit_MQTT_Publish(&mqtt, RAINFALL_FEED);
-
-const char HUMIDITY_FEED[] PROGMEM = AIO_USERNAME "/feeds/humidity";
-Adafruit_MQTT_Publish _humidityFeed = Adafruit_MQTT_Publish(&mqtt, HUMIDITY_FEED);
-
-const char GROUND_TEMPERATURE_FEED[] PROGMEM = AIO_USERNAME "/feeds/groundTemperature";
-Adafruit_MQTT_Publish _groundTemperatureFeed = Adafruit_MQTT_Publish(&mqtt, GROUND_TEMPERATURE_FEED);
-
-const char DAYLIGHT_FEED[] PROGMEM = AIO_USERNAME "/feeds/daylight";
-Adafruit_MQTT_Publish _daylightFeed = Adafruit_MQTT_Publish(&mqtt, DAYLIGHT_FEED);
-
-const char AIR_TEMPERATURE_FEED[] PROGMEM = AIO_USERNAME "/feeds/airtemperature";
-Adafruit_MQTT_Publish _airTemperatureFeed = Adafruit_MQTT_Publish(&mqtt, AIR_TEMPERATURE_FEED);
-
-const char AIR_PRESSURE_FEED[] PROGMEM = AIO_USERNAME "/feeds/airpressure";
-Adafruit_MQTT_Publish _airPressureFeed = Adafruit_MQTT_Publish(&mqtt, AIR_PRESSURE_FEED);

 //
 //  Used for debugging, determine the output state of the onboard LED.
@@ -196,71 +149,6 @@
 }

 //
-//  Function to connect and reconnect as necessary to the MQTT server.
-//  Should be called in the loop function and it will take care if connecting.
-//
-void MQTT_connect()
-{
-    int8_t result;
-
-    if (mqtt.connected())
-    {
-        return;
-    }
-
-    Debugger::DebugMessage("Connecting to MQTT... ");
-    while ((result = mqtt.connect()) != 0)
-    {
-        switch (result)
-        {
-            case 1:
-                Debugger::DebugMessage("Wrong protocol");
-                break;
-            case 2:
-                Debugger::DebugMessage("ID rejected");
-                break;
-            case 3:
-                Debugger::DebugMessage("Server unavailable");
-                break;
-            case 4:
-                Debugger::DebugMessage("Bad user/password");
-                break;
-            case 5:
-                Debugger::DebugMessage("Not authenticated");
-                break;
-            case 6:
-                Debugger::DebugMessage("Failed to subscribe");
-                break;
-            default:
-                String message = "Couldn't connect to server, code: ";
-                char buffer[20];
-                message += itoa(result, buffer, 10);
-                Debugger::DebugMessage(message);
-                break;
-        }
-        Debugger::DebugMessage("Retrying MQTT connection in 5 seconds...");
-        mqtt.disconnect();
-        delay(5000);
-    }
-    Debugger::DebugMessage("MQTT Connected!");
-}
-
-//
-//  Check if the data was sent to Adafruit IO OK
-//
-void CheckMQTTLoggingResult(bool result, String readingType)
-{
-    if (result)
-    {
-        Debugger::DebugMessage("MQTT Success: " + readingType);
-    }
-    else
-    {
-        Debugger::DebugMessage("MQTT Failed: " + readingType);
-    }
-}
-
-//
 //  Update the RTC with the time from the Internet.
 //
 void UpdateRTCWithInternetTime(DS3231 *rtc)
@@ -328,16 +216,19 @@
     delete(dateTime);
 }

+//
+//  Take sensor readings an push the data to the Internet.
+//
 void ReadAndPublishData()
 {
-    char _buffer[20];
-    String _message;
+    char buffer[20];
+    String message;

     digitalWrite(PIN_ONBOARD_LED, HIGH);
-    _message = "Reading sensor data (";
-    _message += itoa(_readingNumber, _buffer, 10);
-    _message += ")";
-    Debugger::DebugMessage(_message);
+    message = "Reading sensor data (";
+    message += itoa(_readingNumber, buffer, 10);
+    message += ")";
+    Debugger::DebugMessage(message);
     _sensors->ReadAllSensors();
     Debugger::LogLuminosityData(_sensors->GetLuminosityReading());
     Debugger::LogTemperatureHumidityAndPressureData(_sensors->GetAirTemperature(), _sensors->GetHumidity(), _sensors->GetAirPressure());
@@ -345,30 +236,19 @@
     //Debugger::LogUltravioletData(_sensors->GetUltravioletLightStrength());
     Debugger::LogRainfall(0, _pluviometerCountToday * 0.2794);
     //
-    _message = "Wind speed pulse count: ";
-    _message += itoa(_lastFiveSecondWindSpeedCount, _buffer, 10);
-    Debugger::DebugMessage(_message);
-    //
-    _message = "Wind speed: ";
-    _message += Debugger::FloatToAscii(_buffer, (_lastFiveSecondWindSpeedCount * 1.492) / 5, 2);
-    _message += "mph";
-    Debugger::DebugMessage(_message);
+    message = "Wind speed pulse count: ";
+    message += itoa(_lastFiveSecondWindSpeedCount, buffer, 10);
+    Debugger::DebugMessage(message);
+    //
+    message = "Wind speed: ";
+    message += Debugger::FloatToAscii(buffer, (_lastFiveSecondWindSpeedCount * 1.492) / 5, 2);
+    message += "mph";
+    Debugger::DebugMessage(message);
     //
     //  Now post to the Internet.
     //
     Debugger::DebugMessage("Posting to Internet.");
     PostDataToPhant();
-    //MQTT_connect();
-    //CheckMQTTLoggingResult(_airPressureFeed.publish(_sensors->GetAirPressure() / 100), "Air Pressure");
-    //CheckMQTTLoggingResult(_airTemperatureFeed.publish(_sensors->GetAirTemperature()), "Air Temperature");
-    //CheckMQTTLoggingResult(_daylightFeed.publish(_sensors->GetLuminosityReading()), "Daylight");
-    //CheckMQTTLoggingResult(_groundTemperatureFeed.publish(_sensors->GetGroundTemperatureReading()), "Ground Temperature");
-    //CheckMQTTLoggingResult(_humidityFeed.publish(_sensors->GetHumidity()), "Humidity");
-    //CheckMQTTLoggingResult(_rainFallFeed.publish(_sensors->GetTotalRainfallToday()), "Rainfall");
-    //CheckMQTTLoggingResult(_windSpeedFeed.publish(_sensors->GetWindSpeed()), "Wind Speed");
-    //CheckMQTTLoggingResult(_windDirectionFeed.publish(_sensors->GetWindDirectionAsString()), "Wind Direction");
-    //CheckMQTTLoggingResult(_uvLightFeed.publish(_sensors->GetUltravioletLightStrength()), "Ultraviolet Light");
-    //Debugger::DebugMessage("Posting complete'");
     digitalWrite(PIN_ONBOARD_LED, LOW);
 }

@@ -424,7 +304,7 @@
 //
 void setup()
 {
-    Serial.begin(9600);
+    Serial.begin(115200);
     Serial.println();
     Serial.println();
     Wire.begin();