Switch to "MPU9150.h" Reduce output frequency to 100ms (program was stopping before at 50ms, maybe due as well to usb port on computer side...)

--- Arduino/MPU9150_MS5611_IMU/MPU9150_MS5611_IMU.ino
+++ Arduino/MPU9150_MS5611_IMU/MPU9150_MS5611_IMU.ino
@@ -91,10 +91,10 @@

 #include <Wire.h>
 #include "I2Cdev.h" //from https://github.com/sparkfun/MPU-9150_Breakout.git
-#include "MPU6050_9Axis_MotionApps41.h"//from https://github.com/sparkfun/MPU-9150_Breakout.git
+#include "MPU9150.h"
 #include <MS561101BA.h>

-#define OUTPUT_RATE_ms 50 // 20Hz
+#define OUTPUT_RATE_ms 100 // 20Hz

 #define MOVAVG_SIZE 32

@@ -113,8 +113,11 @@
 #define ACCEL_RANGE_G 2.0f
 #define MAG_RANGE_mG 12290.0f// milliGauss (1229 microTesla per 2^12 bits, 10 mG per microTesla)

-// Declare device MPU6050 class
-MPU6050 mpu(0x69);
+// class default I2C address is 0x68
+// specific I2C addresses may be passed as a parameter here
+// AD0 low = 0x68 (default for InvenSense evaluation board)
+// AD0 high = 0x69
+MPU9150 accelGyroMag(0x69);

 // global constants for 9 DoF fusion and AHRS (Attitude and Heading Reference System)
 #define GyroMeasError PI * (40.0f / 180.0f)       // gyroscope measurement error in rads/s (shown as 3 deg/s)
@@ -133,13 +136,13 @@
 #define Ki 0.0f

 int16_t a1, a2, a3, g1, g2, g3, m1, m2, m3;     // raw data arrays reading
-uint16_t count = 0;  // used to control display output rate
-uint16_t delt_t = 0; // used to control display output rate
-uint8_t MagRate;     // read rate for magnetometer data
+uint16_t last_output_ms = 0;  // used to control display output rate
+uint16_t delt_t_ms = 0; // used to control display output rate
+uint8_t BaroRate;     // read rate for magnetometer data

 float pitch, yaw, roll;
-float deltat = 0.0f;        // integration interval for both filter schemes
-uint64_t lastUpdate = 0; // used to calculate integration interval
+float deltat_s = 0.0f;        // integration interval for both filter schemes
+uint64_t lastUpdate_us = 0; // used to calculate integration interval
 uint64_t time_boot_us = 0;        // used to calculate integration interval

 float ax_g, ay_g, az_g, gx_degps, gy_degps, gz_degps, mx, my, mz; // variables to hold latest sensor data values
@@ -149,7 +152,7 @@
 uint8_t system_id = 100;
 uint8_t component_id = 200;
 uint32_t time_boot_ms;
-uint32_t last_mag_read_ms;
+uint32_t last_baro_read_ms;

 //MS5611
 MS561101BA baro = MS561101BA();
@@ -174,17 +177,17 @@

   // initialize MPU6050 device
   Serial.println(F("Initializing I2C devices..."));
-  mpu.initialize();
+  accelGyroMag.initialize();

   // verify connection
   Serial.println(F("Testing device connections..."));
-  Serial.println(mpu.testConnection() ? F("MPU9150 connection successful") : F("MPU9150 connection failed"));
+  Serial.println(accelGyroMag.testConnection() ? F("MPU9150 connection successful") : F("MPU9150 connection failed"));

 // Set up the accelerometer, gyro, and magnetometer for data output

-   mpu.setRate(7); // set gyro rate to 8 kHz/(1 + rate) shows 1 kHz, accelerometer ODR is fixed at 1 KHz
-
-   MagRate = 100; // set magnetometer read rate in Hz; 10 to 100 (max) Hz are reasonable values
+   accelGyroMag.setRate(7); // set gyro rate to 8 kHz/(1 + rate) shows 1 kHz, accelerometer ODR is fixed at 1 KHz
+
+   BaroRate = 100;

 // Digital low pass filter configuration.
 // It also determines the internal sampling rate used by the device as shown in the table below.
@@ -203,17 +206,17 @@
  * 5        | 10Hz      | 13.8ms | 10Hz      | 13.4ms | 1kHz
  * 6        | 5Hz       | 19.0ms | 5Hz       | 18.6ms | 1kHz
  */
-  mpu.setDLPFMode(4); // set bandwidth of both gyro and accelerometer to ~20 Hz
+  accelGyroMag.setDLPFMode(4); // set bandwidth of both gyro and accelerometer to ~20 Hz

 // Full-scale range of the gyro sensors:
 // 0 = +/- 250 degrees/sec, 1 = +/- 500 degrees/sec, 2 = +/- 1000 degrees/sec, 3 = +/- 2000 degrees/sec
-  mpu.setFullScaleGyroRange(0); // set gyro range to 250 degrees/sec
+  accelGyroMag.setFullScaleGyroRange(0); // set gyro range to 250 degrees/sec

 // Full-scale accelerometer range.
 // The full-scale range of the accelerometer: 0 = +/- 2g, 1 = +/- 4g, 2 = +/- 8g, 3 = +/- 16g
-  mpu.setFullScaleAccelRange(0); // set accelerometer to 2 g range
-
-  mpu.setIntDataReadyEnabled(true); // enable data ready interrupt
+  accelGyroMag.setFullScaleAccelRange(0); // set accelerometer to 2 g range
+
+  //accelGyroMag.setIntDataReadyEnabled(true); // enable data ready interrupt

   // Suppose that the CSB pin is connected to GND.
   // You'll have to check this on your breakout schematics
@@ -239,73 +242,73 @@
 }

 void loop()
-{
-    temperature = baro.getTemperature(MS561101BA_OSR_4096);
-    press = baro.getPressure(MS561101BA_OSR_4096);
-    pushAvg(press);
-    press = getAvg(movavg_buff, MOVAVG_SIZE);
-    altitude = getAltitude(press, temperature);
+{
+
+    if (fabs(millis()-last_baro_read_ms)>1./BaroRate)
+    {
+      last_baro_read_ms = millis();
+      getBaroData();
+    }
     automaticGyroRangeSelection();
     automaticAccelRangeSelection();
-    if(mpu.getIntDataReadyStatus() == 1) { // wait for data ready status register to update all data registers
-           // read the raw sensor data
-            mpu.getAcceleration  ( &a1, &a2, &a3  );
-            a2 = -a2;// Invert y to get NED classical convention
-            a1 = a1 + ACC_1_OFFSET;
-            a2 = a2 + ACC_2_OFFSET;
-            a3 = a3 + ACC_3_OFFSET;
-            ax_g = a1*ACCEL_RANGE_G*pow(2.0, n_accel_range)/pow(2.0, 15);
-            ay_g = a2*ACCEL_RANGE_G*pow(2.0, n_accel_range)/pow(2.0, 15);
-            az_g = a3*ACCEL_RANGE_G*pow(2.0, n_accel_range)/pow(2.0, 15);
-
-            mpu.getRotation  ( &g1, &g2, &g3  );
-            g1 = -g1;
-            g3 = -g3;
-            g1 = g1 + GYRO_1_OFFSET;
-            g2 = g2 + GYRO_2_OFFSET;
-            g3 = g3 + GYRO_3_OFFSET;
-            gx_degps = g1*GYRO_RANGE_DEGPS*pow(2.0, n_gyro_range)/pow(2.0, 15);
-            gy_degps = g2*GYRO_RANGE_DEGPS*pow(2.0, n_gyro_range)/pow(2.0, 15);
-            gz_degps = g3*GYRO_RANGE_DEGPS*pow(2.0, n_gyro_range)/pow(2.0, 15);
-//  The gyros and accelerometers can in principle be calibrated in addition to any factory calibration but they are generally
-//  pretty accurate. You can check the accelerometer by making sure the reading is +1 g in the positive direction for each axis.
-//  The gyro should read zero for each axis when the sensor is at rest. Small or zero adjustment should be needed for these sensors.
-//  The magnetometer is a different thing. Most magnetometers will be sensitive to circuit currents, computers, and
-//  other both man-made and natural sources of magnetic field. The rough way to calibrate the magnetometer is to record
-//  the maximum and minimum readings (generally achieved at the North magnetic direction). The average of the sum divided by two
-//  should provide a pretty good calibration offset. Don't forget that for the MPU9150, the magnetometer x- and y-axes are switched
-//  compared to the gyro and accelerometer!
-        if (fabs(last_mag_read_ms-millis())>1./MagRate)
-            {
-            mpu.getMag  ( &m1, &m2, &m3 );
-            last_mag_read_ms = millis();
-            m2 = -m2;
-            // Apply calibration offsets on raw measurements that correspond to your environment and magnetometer
-            m1 = m1 + MAG_1_OFFSET;
-            m2 = m2 + MAG_2_OFFSET;
-            m3 = m3 + MAG_3_OFFSET;
-            // Sensors x (y)-axis of the accelerometer is aligned with the y (x)-axis of the magnetometer;
-            // the magnetometer z-axis (+ down) is opposite to z-axis (+ up) of accelerometer and gyro!
-            // We have to make some allowance for this orientationmismatch in feeding the output to the quaternion filter.
-            mx = m2*MAG_RANGE_mG/pow(2, 12); //Warning!!
-            my = m1*MAG_RANGE_mG/pow(2, 12);
-            mz = m3*MAG_RANGE_mG/pow(2, 12);
-            }
-         }
+
+    if(accelGyroMag.getIntDataReadyStatus() == 1)// wait for data ready status register to update all data registers
+    {
+      // read the raw sensor data
+        accelGyroMag.getMotion9(&a1, &a1, &a3, &g1, &g2, &g3, &m1, &m2, &m3);
+
+        a2 = -a2;// Invert y to get NED classical convention
+        a1 = a1 + ACC_1_OFFSET;
+        a2 = a2 + ACC_2_OFFSET;
+        a3 = a3 + ACC_3_OFFSET;
+        ax_g = a1*ACCEL_RANGE_G*pow(2.0, n_accel_range)/pow(2.0, 15);
+        ay_g = a2*ACCEL_RANGE_G*pow(2.0, n_accel_range)/pow(2.0, 15);
+        az_g = a3*ACCEL_RANGE_G*pow(2.0, n_accel_range)/pow(2.0, 15);
+
+        g1 = -g1;
+        g3 = -g3;
+        g1 = g1 + GYRO_1_OFFSET;
+        g2 = g2 + GYRO_2_OFFSET;
+        g3 = g3 + GYRO_3_OFFSET;
+        gx_degps = g1*GYRO_RANGE_DEGPS*pow(2.0, n_gyro_range)/pow(2.0, 15);
+        gy_degps = g2*GYRO_RANGE_DEGPS*pow(2.0, n_gyro_range)/pow(2.0, 15);
+        gz_degps = g3*GYRO_RANGE_DEGPS*pow(2.0, n_gyro_range)/pow(2.0, 15);
+        //  The gyros and accelerometers can in principle be calibrated in addition to any factory calibration but they are generally
+        //  pretty accurate. You can check the accelerometer by making sure the reading is +1 g in the positive direction for each axis.
+        //  The gyro should read zero for each axis when the sensor is at rest. Small or zero adjustment should be needed for these sensors.
+        //  The magnetometer is a different thing. Most magnetometers will be sensitive to circuit currents, computers, and
+        //  other both man-made and natural sources of magnetic field. The rough way to calibrate the magnetometer is to record
+        //  the maximum and minimum readings (generally achieved at the North magnetic direction). The average of the sum divided by two
+        //  should provide a pretty good calibration offset. Don't forget that for the MPU9150, the magnetometer x- and y-axes are switched
+        //  compared to the gyro and accelerometer!
+
+        m2 = -m2;
+        // Apply calibration offsets on raw measurements that correspond to your environment and magnetometer
+        m1 = m1 + MAG_1_OFFSET;
+        m2 = m2 + MAG_2_OFFSET;
+        m3 = m3 + MAG_3_OFFSET;
+        // Sensors x (y)-axis of the accelerometer is aligned with the y (x)-axis of the magnetometer;
+        // the magnetometer z-axis (+ down) is opposite to z-axis (+ up) of accelerometer and gyro!
+        // We have to make some allowance for this orientationmismatch in feeding the output to the quaternion filter.
+        mx = m2*MAG_RANGE_mG/pow(2, 12); //Warning x and y are inverted!!
+        my = m1*MAG_RANGE_mG/pow(2, 12);
+        mz = m3*MAG_RANGE_mG/pow(2, 12);
+
+    }

-  time_boot_us = micros();
-  time_boot_ms = millis();
-  deltat = ((time_boot_us - lastUpdate)/1000000.0f); // set integration time by time elapsed since last filter update
-  lastUpdate = time_boot_us;
-
-  // Pass gyro rate as rad/s
-   MadgwickQuaternionUpdate(ax_g, ay_g, az_g, gx_degps*PI/180.0f, gy_degps*PI/180.0f, gz_degps*PI/180.0f, mx, my, mz);
-// MahonyQuaternionUpdate(ax_g, ay, az, gx_degps*PI/180.0f, gy_degps*PI/180.0f, gz_degps*PI/180.0f, my, mx, mz);
-
+    time_boot_us = micros();
+    time_boot_ms = millis();
+    deltat_s = ((time_boot_us - lastUpdate_us)/1000000.0f); // set integration time by time elapsed since last filter update
+    lastUpdate_us = time_boot_us;
+
+    // Pass gyro rate as rad/s
+    MadgwickQuaternionUpdate(ax_g, ay_g, az_g, gx_degps*PI/180.0f, gy_degps*PI/180.0f, gz_degps*PI/180.0f, mx, my, mz);
+    // MahonyQuaternionUpdate(ax_g, ay, az, gx_degps*PI/180.0f, gy_degps*PI/180.0f, gz_degps*PI/180.0f, my, mx, mz);
+
     // Serial print and/or display at output rate independent of data rates
-    delt_t = millis() - count;
-    if (delt_t > OUTPUT_RATE_ms) {
-
+    delt_t_ms = fabs(millis() - last_output_ms);
+    if (delt_t_ms > OUTPUT_RATE_ms) {
+       last_output_ms = millis();
     // Define output variables from updated quaternion---these are Tait-Bryan angles, commonly used in aircraft orientation.
     // In this coordinate system, the positive z-axis is down toward Earth.
     // Yaw is the angle between Sensor x-axis and Earth magnetic North (or true North if corrected for local declination, looking down on the sensor positive yaw is counterclockwise.
@@ -375,7 +378,7 @@
       Serial.print(", ");
       Serial.println(roll*180.0f / PI, 2);

-      Serial.print("rate = "); Serial.print((float)1.0f/deltat, 2); Serial.println(" Hz");
+      Serial.print("rate = "); Serial.print((float)1.0f/deltat_s, 2); Serial.println(" Hz");

       Serial.print(" temp: ");
       Serial.print(temperature);
@@ -398,62 +401,57 @@
       // stabilization control of a fast-moving robot or quadcopter. Compare to the update rate of 200 Hz
       // produced by the on-board Digital Motion Processor of Invensense's MPU6050 6 DoF and MPU9150 9DoF sensors.
       // The 3.3 V 8 MHz Pro Mini is doing pretty well!
-
-      count = millis();
     }
+}
+void getBaroData()
+{
+    temperature = baro.getTemperature(MS561101BA_OSR_4096);
+    press = baro.getPressure(MS561101BA_OSR_4096);
+    pushAvg(press);
+    press = getAvg(movavg_buff, MOVAVG_SIZE);
+    altitude = getAltitude(press, temperature);
 }
 void automaticGyroRangeSelection()
 {
-  if ((fabs(gx_degps)<0.2*GYRO_RANGE_DEGPS)&&(fabs(gy_degps)<0.2*GYRO_RANGE_DEGPS)&&(fabs(gz_degps)<0.2*GYRO_RANGE_DEGPS))
-  {
-    n_gyro_range = 0;
+  for (int i =0; i<=2; i++)
+  {
+    if (max(max(fabs(gx_degps),fabs(gy_degps)),fabs(gz_degps)) <0.2*GYRO_RANGE_DEGPS*pow(2, i))
+    {
+      n_gyro_range = i;
+    }
+    else
+    {
+      n_gyro_range = i+1;
+    }
   }
-  else   if ((fabs(gx_degps)<0.2*GYRO_RANGE_DEGPS*2)&&(fabs(gy_degps)<0.2*GYRO_RANGE_DEGPS*2)&&(fabs(gz_degps)<0.2*GYRO_RANGE_DEGPS*2))
-  {
-    n_gyro_range = 1;
-  }
-  else   if ((fabs(gx_degps)<0.2*GYRO_RANGE_DEGPS*4)&&(fabs(gy_degps)<0.2*GYRO_RANGE_DEGPS*4)&&(fabs(gz_degps)<0.2*GYRO_RANGE_DEGPS*4))
-  {
-    n_gyro_range = 2;
-  }
-  else
-  {
-    n_gyro_range = 3;
-  }
-

   if (n_gyro_range!=n_gyro_range_old)
   {
     // Full-scale range of the gyro sensors:
     // 0 = +/- 250 degrees/sec, 1 = +/- 500 degrees/sec, 2 = +/- 1000 degrees/sec, 3 = +/- 2000 degrees/sec
-    mpu.setFullScaleGyroRange(n_gyro_range); // set gyro range to 250 degrees/sec
+    accelGyroMag.setFullScaleGyroRange(n_gyro_range); // set gyro range to 250 degrees/sec
     n_gyro_range_old = n_gyro_range;
   }
 }
 void automaticAccelRangeSelection()
 {
-  if ((fabs(ax_g)<0.2*ACCEL_RANGE_G)&&(fabs(ay_g)<0.2*ACCEL_RANGE_G)&&(fabs(az_g)<0.2*ACCEL_RANGE_G))
-  {
-    n_accel_range = 0;
-  }
-  else   if ((fabs(ax_g)<0.2*ACCEL_RANGE_G*2)&&(fabs(ay_g)<0.2*ACCEL_RANGE_G*2)&&(fabs(az_g)<0.2*ACCEL_RANGE_G*2))
-  {
-    n_accel_range = 1;
-  }
-  else   if ((fabs(ax_g)<0.2*ACCEL_RANGE_G*4)&&(fabs(ay_g)<0.2*ACCEL_RANGE_G*4)&&(fabs(az_g)<0.2*ACCEL_RANGE_G*4))
-  {
-    n_accel_range = 2;
-  }
-  else
-  {
-    n_accel_range = 3;
+  for (int i =0; i<=2; i++)
+  {
+    if (max(max(fabs(ax_g),fabs(ay_g)),fabs(az_g)) <0.2*ACCEL_RANGE_G*pow(2, i))
+    {
+      n_accel_range = i;
+    }
+    else
+    {
+      n_accel_range = i+1;
+    }
   }

   if (n_accel_range!=n_accel_range_old)
   {
   // Full-scale accelerometer range.
 // The full-scale range of the accelerometer: 0 = +/- 2g, 1 = +/- 4g, 2 = +/- 8g, 3 = +/- 16g
-    mpu.setFullScaleAccelRange(n_accel_range);
+    accelGyroMag.setFullScaleAccelRange(n_accel_range);
     n_accel_range_old = n_accel_range;
   }
 }
@@ -563,10 +561,10 @@
             qDot4 = 0.5f * (q1 * gz + q2 * gy - q3 * gx) - beta * s4;

             // Integrate to yield quaternion
-            q1 += qDot1 * deltat;
-            q2 += qDot2 * deltat;
-            q3 += qDot3 * deltat;
-            q4 += qDot4 * deltat;
+            q1 += qDot1 * deltat_s;
+            q2 += qDot2 * deltat_s;
+            q3 += qDot3 * deltat_s;
+            q4 += qDot4 * deltat_s;
             norm = sqrt(q1 * q1 + q2 * q2 + q3 * q3 + q4 * q4);    // normalise quaternion
             norm = 1.0f/norm;
             q[0] = q1 * norm;
@@ -657,10 +655,10 @@
             pa = q2;
             pb = q3;
             pc = q4;
-            q1 = q1 + (-q2 * gx - q3 * gy - q4 * gz) * (0.5f * deltat);
-            q2 = pa + (q1 * gx + pb * gz - pc * gy) * (0.5f * deltat);
-            q3 = pb + (q1 * gy - pa * gz + pc * gx) * (0.5f * deltat);
-            q4 = pc + (q1 * gz + pa * gy - pb * gx) * (0.5f * deltat);
+            q1 = q1 + (-q2 * gx - q3 * gy - q4 * gz) * (0.5f * deltat_s);
+            q2 = pa + (q1 * gx + pb * gz - pc * gy) * (0.5f * deltat_s);
+            q3 = pb + (q1 * gy - pa * gz + pc * gx) * (0.5f * deltat_s);
+            q4 = pc + (q1 * gz + pa * gy - pb * gx) * (0.5f * deltat_s);

             // Normalise quaternion
             norm = sqrt(q1 * q1 + q2 * q2 + q3 * q3 + q4 * q4);


initialize neopixel library

initialize neopixel library

--- weather-clock.ino
+++ weather-clock.ino
@@ -9,7 +9,10 @@
   #include <avr/power.h>
 #endif

-// using json = nlohmann::json;
+#define PIN 6
+
+// initializes the ring with arguments(number of pixels, input pin, type of pixels)
+Adafruit_NeoPixel pixels = Adafruit_NeoPixel(24, PIN, NEO_GRB + NEO_KHZ800);

 char ssid[] = WIFI_NAME; //  your network SSID (name)
 char pass[] = WIFI_PASS;    // your network password (use for WPA, or use as key for WEP)
@@ -33,6 +36,8 @@
 WiFiClient client;

 void setup() {
+  pixels.begin(); // This initializes the NeoPixel library.
+
   //Initialize serial and wait for port to open:
   Serial.begin(9600);
   while (!Serial) {
@@ -72,24 +77,8 @@
 }

 void loop() {
-  // if there are incoming bytes available
-  // from the server, read them and print them:
-  // uint8_t json[1000];
-  // for(int i=0; i < 1000; i++) {
-  //   json[i] = 50;
-  // }
-
-  // while (client.available()) {
-    // client.read(json, 1000);
-    // StaticJsonBuffer<10000000000> jsonBuffer;
-    // JsonObject& httpRes = jsonBuffer.parseObject(c);
-    // const char* temp = httpRes["hourly"];
-    // Serial.println(client.available());
-
-  // }
-  // for(byte x = 0; x < sizeof(c); x++){
-  //   json[x] = c[x];
-  // }
+  pixels.setPixelColor(0, 245,51,255);
+  pixels.show();

   while(client.available()) {


Update source of Shrimp

Update source of Shrimp

Shrimp kan nu de temperatuur loggen naar de console

--- Sources/Shrimp/Shrimp.ino
+++ Sources/Shrimp/Shrimp.ino
@@ -1,22 +1,26 @@
 // Pins
 const int ledPin = 13;
 const int buttonPin = 2;
-const int thermometerPin = 0;
+const int thermometerPin = A0;

 // Variables
 int travelTime = 0; // Total travel time in s
 int logInterval = 0; // Hoe vaak willen we loggen?
+int temperature = 0;

 void setup() {
   // Initialize pins
   pinMode(ledPin, OUTPUT);
-  pinMode(buttonPin, INPUT);
-  pinMode(thermometerPin, INPUT);

-
+  Serial.begin(9600);
+  digitalWrite(ledPin, LOW);
 }

 void loop() {
   // put your main code here, to run repeatedly:
+  temperature = analogRead(thermometerPin);
+  Serial.println(temperature, DEC);
+  delay(1);
+

 }


Added comment to demo

Added comment to demo

--- examples/FirebaseDemo_ESP8266/FirebaseDemo_ESP8266.ino
+++ examples/FirebaseDemo_ESP8266/FirebaseDemo_ESP8266.ino
@@ -87,6 +87,7 @@

   // set bool value
   Firebase.setBool("truth", false);
+  // handle error
   if (Firebase.failed()) {
       Serial.print("setting /truth failed:");
       Serial.println(Firebase.error());


Updated Arduino example

Updated Arduino example

--- examples/JsonGeneratorExample/JsonGeneratorExample.ino
+++ examples/JsonGeneratorExample/JsonGeneratorExample.ino
@@ -11,7 +11,7 @@

     JsonHashTable<3> h;

-    h.add("pi", 3.14);
+    h.add("pi", 3.14159265358979323846, 4);

     JsonArray<3> a;
     a.add(1);


update

update

--- ASA/ASA/ASA.ino
+++ ASA/ASA/ASA.ino
@@ -1,5 +1,3 @@
-#!usr/bin/env
-# -*- coding: utf-8 -*-
 /*
 Jhonatan da Silva
 Last Updated version :


Update SparkCore.ino

Update SparkCore.ino

--- firmware/examples/Transports/SparkCore/SparkCore.ino
+++ firmware/examples/Transports/SparkCore/SparkCore.ino
@@ -24,8 +24,24 @@
 void setup()
 {
   Serial.begin(9600);
-  delay(10000); // Allow board to settle
+  delay(5000); // Allow board to settle
   Blynk.begin(auth);
+}
+
+// Attach a Button widget to the Virtual pin 1 - and send sweet tweets!
+BLYNK_WRITE(1) {
+    if (param.asInt()) { // On button down...
+        Blynk.tweet("My Particle project is tweeting using @blynk_app and this is awesome!\n @Particle #IoT #blynk");
+    }
+}
+
+// Attach a Slider widget to the Virtual pin 2 - and control the built-in RGB led!
+BLYNK_WRITE(2) {
+    RGB.control(true);
+
+    byte rgb[3];
+    HsvToRgb(param.asDouble()/255, 1, 1, rgb);
+    RGB.color(rgb[0], rgb[1], rgb[2]);
 }

 void loop()
@@ -33,3 +49,28 @@
   Blynk.run();
 }

+// *** Utility functions
+
+void HsvToRgb(double h, double s, double v, byte rgb[]) {
+    double r, g, b;
+
+    int i = int(h * 6);
+    double f = h * 6 - i;
+    double p = v * (1 - s);
+    double q = v * (1 - f * s);
+    double t = v * (1 - (1 - f) * s);
+
+    switch(i % 6){
+        case 0: r = v, g = t, b = p; break;
+        case 1: r = q, g = v, b = p; break;
+        case 2: r = p, g = v, b = t; break;
+        case 3: r = p, g = q, b = v; break;
+        case 4: r = t, g = p, b = v; break;
+        case 5: r = v, g = p, b = q; break;
+    }
+
+    rgb[0] = r * 255;
+    rgb[1] = g * 255;
+    rgb[2] = b * 255;
+}
+


Update Air_monitor.ino

Update Air_monitor.ino

Updated code pieces, OLED character placement, comments and pooling rates

--- Air_monitor.ino
+++ Air_monitor.ino
@@ -71,7 +71,7 @@
 int pin = 8;
 unsigned long duration;
 unsigned long starttime;
-unsigned long sampletime_ms = 1000;
+unsigned long sampletime_ms = 5000;
 unsigned long lowpulseoccupancy = 0;
 float ratio = 0;
 float concentration = 0;
@@ -87,7 +87,6 @@
   DDRB |= 0x21;
   PORTB |= 0x21;

-
   SeeedOled.setNormalDisplay();          // Set normal display
   SeeedOled.clearDisplay();               // clear the screen and set start position to top left corner
   SeeedOled.drawBitmap(LCAlogo, 1024);  // 1024 = 128 Pixels * 64 Pixels / 8
@@ -99,7 +98,7 @@
   starttime = millis();

   Serial.println("Air Quality Gizmo by LMO");
-  Serial.println("Humidity %, Temperature C, PM ug/m^3, VOC mg/L, Hydrocarbs mg/m^3.");
+  Serial.println("Time s, Humidity %, Temperature C, PM ug/m^3, VOC mg/L, Hydrocarbs mg/m^3");

   dht.begin();

@@ -126,58 +125,65 @@
     starttime = millis();
   }

-  float h = dht.readHumidity();
+  float h = dht.readHumidity(); //sensor pooling time of 2 seconds (both temp and humi)
   float t = dht.readTemperature();

   {
-    Serial.print(h);
+    Serial.print(millis()/1000);
     Serial.print(",");
-    Serial.print(t);
+    Serial.print(h,1);
     Serial.print(",");
-    Serial.print(concentration / 500);
+    Serial.print(t,1);
     Serial.print(",");
-    Serial.print(vol);
+    Serial.print(concentration / 500,3);
     Serial.print(",");
-    Serial.print(vol_Formol);
-    Serial.println(".");
+    Serial.print(vol,3);
+    Serial.print(",");
+    Serial.print(vol_Formol,3);
+    Serial.println("");
   }
   {
     SeeedOled.clearDisplay();
     SeeedOled.setTextXY(1, 1);
     SeeedOled.putString("Particulates:");
     SeeedOled.setTextXY(2, 1);
-    SeeedOled.putFloat(concentration / 500);
+    SeeedOled.putFloat((concentration / 500),3);
     SeeedOled.setTextXY(2, 8);
     SeeedOled.putString("ug/m^3");

     SeeedOled.setTextXY(3, 1);
     SeeedOled.putString("Hydrocarbons:");
     SeeedOled.setTextXY(4, 1);
-    SeeedOled.putFloat(vol_Formol/1000);
+    SeeedOled.putFloat(vol_Formol,3);
     SeeedOled.setTextXY(4, 8);
-    SeeedOled.putString("mg/dm^3");
+    SeeedOled.putString("mg/m^3");

     SeeedOled.setTextXY(5, 1);
     SeeedOled.putString("Volatile OC:");
     SeeedOled.setTextXY(6, 1); // location to display variable
-    SeeedOled.putFloat(vol); // variable to display
+    SeeedOled.putFloat(vol,3); // variable to display
     SeeedOled.setTextXY(6, 8);
     SeeedOled.putString("mg/L");

     delay(2000);

     SeeedOled.clearDisplay();
+    SeeedOled.setTextXY(1, 1);
+    SeeedOled.putString("Elapsed Time");
     SeeedOled.setTextXY(2, 1);
+    SeeedOled.putFloat(millis()/60000,0);
+    SeeedOled.setTextXY(2, 7);
+    SeeedOled.putString("minutes");
+    SeeedOled.setTextXY(3, 1);
     SeeedOled.putString("Humidity:");
-    SeeedOled.setTextXY(3, 1);
-    SeeedOled.putFloat(h);
-    SeeedOled.setTextXY(3, 7);
+    SeeedOled.setTextXY(4, 1);
+    SeeedOled.putFloat(h,1);
+    SeeedOled.setTextXY(4, 7);
     SeeedOled.putString("%");
-
     SeeedOled.setTextXY(5, 1);
     SeeedOled.putString("Temperature:");
     SeeedOled.setTextXY(6, 1);
-    SeeedOled.putFloat(t);
+    SeeedOled.putFloat(t,1);
     SeeedOled.setTextXY(6, 7);
     SeeedOled.putString("C");
   }


Add build() example to GPS_Hardware_Serial_Timing.ino

--- examples/GPS_HardwareSerial_Timing/GPS_HardwareSerial_Timing.ino
+++ examples/GPS_HardwareSerial_Timing/GPS_HardwareSerial_Timing.ino
@@ -4,6 +4,9 @@
 // elements to keep track of how long it has been since time and fix data have been
 // received. This approach lets you keep an up to date clock based on GPS time at
 // any time in between GPS fixes.
+//
+// It also shows how to take advantage of the build() function to generate test sentences.
+// The additional code is within #ifdef NMEA_EXTENSIONS and #endif tags.
 //
 // This code shows how to listen to the GPS module via polling. Best used with
 // Feathers or Flora where you have hardware Serial and no interrupt
@@ -26,6 +29,13 @@

 // Connect to the GPS on the hardware port
 Adafruit_GPS GPS(&GPSSerial);
+
+#ifdef NMEA_EXTENSIONS
+// Create another GPS object to hold the state of the boat, with no communications,
+// so don't call Boat.begin() in setup.
+// We will build some fake sentences from the Boat data to feed to GPS for testing.
+Adafruit_GPS Boat(&GPSSerial);
+#endif

 // Set GPSECHO to 'false' to turn off echoing the GPS data to the Serial console
 // Set to 'true' if you want to debug and listen to the raw GPS sentences
@@ -119,9 +129,9 @@
     Serial.println(s, 3);
     Serial.print("Fix: "); Serial.print((int)GPS.fix);
     Serial.print(" quality: "); Serial.println((int)GPS.fixquality);
-    Serial.print("Times [s] since last fix: "); Serial.print(GPS.secondsSinceFix(),3);
-    Serial.print(",  GPS time: "); Serial.print(GPS.secondsSinceTime(),3);
-    Serial.print(",  GPS date: "); Serial.println(GPS.secondsSinceDate(),3);
+    Serial.print("Time [s] since last fix: "); Serial.println(GPS.secondsSinceFix(),3);
+    Serial.print("    since last GPS time: "); Serial.println(GPS.secondsSinceTime(),3);
+    Serial.print("    since last GPS date: "); Serial.println(GPS.secondsSinceDate(),3);
     if (GPS.fix) {
       Serial.print("Location: ");
       Serial.print(GPS.latitude, 4); Serial.print(GPS.lat);
@@ -132,5 +142,36 @@
       Serial.print("Altitude: "); Serial.println(GPS.altitude);
       Serial.print("Satellites: "); Serial.println((int)GPS.satellites);
     }
+#ifdef NMEA_EXTENSIONS
+    char latestBoat[200] = "";
+    updateBoat();                                 //create some test data in Boat
+    Boat.build(latestBoat,"GN","RMC");            //make a sentence from Boat data
+    Serial.print("\nbuild() test output -->");    //
+    Serial.print(latestBoat);                     //
+    GPS.resetSentTime();                          //make timing look like it came in on GPS
+    GPS.parse(latestBoat);                        //parse the test data and store in GPS
+#endif
   }
 }
+
+#ifdef NMEA_EXTENSIONS
+void updateBoat(){  //fill up the boat values with some test data to use in build()
+  double t = millis() / 1000.;
+  double theta = t / 100.;             //slow
+  double gamma = theta * 10;           //faster
+  Boat.latitude = 4400 + sin(theta)*60;
+  Boat.lat = 'N';
+  Boat.longitude = 7600 + cos(theta)*60;
+  Boat.lon = 'W';
+  Boat.fixquality = 2;
+  Boat.speed = 3 + sin(gamma);
+  Boat.hour = abs(cos(theta)) * 24;
+  Boat.minute = 30 + sin(theta/2) * 30;
+  Boat.seconds = 30 + sin(gamma) * 30;
+  Boat.milliseconds = 500+ sin(gamma) * 500;
+  Boat.year = 1+abs(sin(theta)) * 25;
+  Boat.month = 1+abs(sin(gamma)) * 11;
+  Boat.day = 1+ abs(sin(gamma)) * 26;
+  Boat.satellites = abs(cos(gamma)) * 10;
+}
+#endif


Move LEDs to a single Jeenode port

Move LEDs to a single Jeenode port

Using the JeeLab BlinkPlug as a model, the two LEDs now run from a
single Jeenod port with a custom "plug".

Minor other cleanup.

--- sketches/control/single_bench/single_bench.ino
+++ sketches/control/single_bench/single_bench.ino
@@ -4,16 +4,22 @@
  * operational time.
  *
  * The MaxMs that actually control the light pattern for one group
- * of LED clusters (Blasters) are preloaded with their light
- * scripts. The MaxMs are connected over an I2C and have device ids
- * preset also. Note that the RTC has device id 0x68 whcih cannot
- * be changed.
+ * of LED clusters (Blasters) are preloaded with their light scripts.
+ * The MaxMs are connected over an I2C and have device ids preset
+ * also. Note that the RTC has device id 0x68 whcih cannot be changed.
  *
- * TODO finish description of operation
+ * There is an RTC plug on Jeenode port 1, the MaxMs are on the I2C
+ * bus on port 2, and optionally there are 2 status LEDs on port 4
+ * being independently controlled with the DIO and AIO pins. LED1
+ * flashes once for the MAXM1 task, twice for the MAXM2 task to show
+ * the correct task ran; LED2 flashes once per minute to show the
+ * sketch is working.
  */

-#define DEBUG_FLASH
-/* #define DEBUG_TRACE */
+// Uncomment for LEDs flashing for debug
+#define DEBUG_FLASH 1
+// Uncomment for debug traces on the serial line
+#define DEBUG_TRACE 1

 #include <JeeLib.h>
 #include <Wire.h> // needed to avoid a linker error :(
@@ -25,11 +31,15 @@
 // Start and end hours of operation
 const unsigned char start_hh = 9;
 const unsigned char start_mm = 0;
-const unsigned char stop_hh = 21;
+const unsigned char stop_hh = 17;
 const unsigned char stop_mm = 0;

 // Seconds after starting first MaxM to start second
 const byte maxm2_offset = 30;
+
+// LEDs
+const byte led1 = 1;
+const byte led2 = 2;

 // boilerplate for low-power waiting
 ISR(WDT_vect) { Sleepy::watchdogEvent(); }
@@ -80,19 +90,33 @@
     return (hh * 60) + mm;
 }

+void doFlash(const Port ledPort, const byte ledNum, const byte cnt) {
 #ifdef DEBUG_FLASH
-void doFlash(const Port ldnum, const byte cnt) {
+    /* Serial.print("Flash LED "); */
+    /* Serial.print(ledNum); */
+    /* Serial.print(" "); */
+    /* Serial.print(cnt); */
+    /* Serial.println(" times"); */
+    /* Serial.flush(); */
+
     byte cntr = cnt;
     while (cntr > 0) {
         cntr--;
-        ldnum.digiWrite(1);
-        Sleepy::loseSomeTime(50);
-        ldnum.digiWrite(0);
+        if (ledNum == 1) {
+          ledPort.digiWrite(1);
+          Sleepy::loseSomeTime(50);
+          ledPort.digiWrite(0);
+        } else {
+          ledPort.digiWrite2(1);
+          Sleepy::loseSomeTime(50);
+          ledPort.digiWrite2(0);
+        }
+
         if (cntr < 1) break;
         Sleepy::loseSomeTime(250);
     }
-}
-#endif
+#endif
+}

 // RTC on port 1
 PortI2C RTCbus (1);
@@ -103,16 +127,8 @@
 DeviceI2C maxm1 (MaxMbus, maxm1Dev);
 DeviceI2C maxm2 (MaxMbus, maxm2Dev);

-#ifdef DEBUG_FLASH
-// LEDs are on ports 3 and 4
-// LED1 flashes once for the MAXM1 task, twice for the MAXM2 task
-Port led1 (3);
-// LED2 flashes once per 10 seconds in a minute (1..6)
-Port led2 (4);
-
-byte led1_on = 0;
-byte led2_on = 0;
-#endif
+// LEDs are on port 4
+Port ledPort (4);

 int is_operational = 0;

@@ -140,14 +156,12 @@
     start_min = toMin(start_hh, start_mm);
     stop_min = toMin(stop_hh, stop_mm);

-#ifdef DEBUG_FLASH
-    led1.mode(OUTPUT);
-    led2.mode(OUTPUT);
-#endif
-
-    // The MaxMs should be programmed to not start on poweroff
+    ledPort.mode(OUTPUT);
+    ledPort.mode2(OUTPUT);
+
+    // The MaxMs are supposed to be programmed to not start on poweron
     // but turn thenm off just to be sure
-
+    //TODO check for errors; and then do what?
     maxm1.send();
     maxm1.write('o');
     maxm1.stop();
@@ -182,10 +196,7 @@
             Serial.flush();
 #endif
             if (is_operational == 1) {
-#ifdef DEBUG_FLASH
-                doFlash(led1, 1);
-#endif
-                // TODO need correct amount to reschedule
+                doFlash(ledPort, led1, 1);
 #ifdef DEBUG_TRACE
                 Serial.println("MAXM1");
                 Serial.flush();
@@ -211,9 +222,7 @@
             maxm2.write(0);
             maxm2.stop();

-#ifdef DEBUG_FLASH
-            doFlash(led1, 2);
-#endif
+            doFlash(ledPort, led1, 2);
             break;

         // Check if within operational time
@@ -226,26 +235,21 @@
             int sec_til_loop = loop_interval - (now.get() % loop_interval);

             // Check if should be operational and set flag
-#ifdef DEBUG_TRACE
-            Serial.println("Lights are ");
-            Serial.flush();
-#endif
             long cur_min = toMin(now.hour(), now.minute());
             if ((cur_min >= start_min) && (cur_min < stop_min))  {
                 is_operational = 1;
 #ifdef DEBUG_TRACE
-                Serial.print("operational");
+                Serial.println("Lights are operational");
                 Serial.flush();
 #endif
             } else {
                 is_operational = 0;
 #ifdef DEBUG_TRACE
-                Serial.println("sleeping");
+                Serial.println("Lights are sleeping");
                 Serial.flush();
 #endif
             }

-#ifdef DEBUG_FLASH
             // Flash LED2 one for every minute in ten if "operational"
             // otherwise only 1 flash
             int num_flash = 1;
@@ -254,8 +258,7 @@
                 // num_flash = (now.get() % 600);
                 // num_flash = num_flash / 60;
             // }
-            doFlash(led2, num_flash);
-#endif
+            doFlash(ledPort, led2, num_flash);

             // Check reschedule amount aganst RTC
             scheduler.timer(OPER_TIME, sec_til_loop * 10);


Use on-chip clock for most timing

Use on-chip clock for most timing

Because of the repeated freeze-ups of the RTC, use the on-chip clock for
most of the timing loops. Only synchronize the two every 10 or mor
minutes. The on-chip clock runs slow about 1 second/minute.

--- sketches/control/single_bench/single_bench.ino
+++ sketches/control/single_bench/single_bench.ino
@@ -19,7 +19,7 @@
 // Uncomment for LEDs flashing for debug
 #define DEBUG_FLASH
 // Uncomment for debug traces on the serial line
-#define DEBUG_TRACE
+// #define DEBUG_TRACE

 #include <JeeLib.h>
 #include <Wire.h> // needed to avoid a linker error :(
@@ -40,8 +40,15 @@
 // const byte maxm2_offset = 15;

 // Length of time check cycle in seconds
-const byte check_cycle = 60;
-// const byte check_cycle = 15;
+const word check_cycle = 60;
+// const word check_cycle = 15;
+
+// Number of time check cycles before refreshing the millis()-based
+// RTC from real RTC. For example with the time check cycle is 60
+// (once per minute), set the RTC_refresh_cycle to 720 to refresh
+// every 12 hours.
+// const int mRTC_refresh_cycle = 720;
+const int mRTC_refresh_cycle = 5;

 // LEDs
 const byte led1 = 1;
@@ -104,8 +111,11 @@
 // LEDs on port 4
 Port ledPort (4);

-// 1 = lights working, 0 = lights not
-byte is_operational = 0;
+// millis()-based RTC
+RTC_Millis millisRTC;
+
+// Currest millisRTC cycle
+int cur_mRTC_cycle = 0;

 // Set to 1 when the MaxMs are awake (active)
 byte maxms_awake = 0;
@@ -119,15 +129,15 @@
 //    wake time of the next period.
 // 3. This implies that the periods cannot overlap.
 Wakeperiod wps[] = {
-    {1, hm2min(19, 59), hm2min(20, 18)},
-    {1, hm2min(21, 31), hm2min(21, 32)},
-    {1, hm2min(21, 34), hm2min(21, 36)},
-    {1, hm2min(21, 39), hm2min(21, 42)},
-    {1, hm2min(22, 17), hm2min(22, 20)},
-    {1, hm2min(22, 22), hm2min(22, 24)},
-    {2, hm2min(6, 40), hm2min(6, 58)},
-    {2, hm2min(7, 40), hm2min(8, 3)},
-    {2, hm2min(11, 40), hm2min(19, 59)},
+    /* {3, hm2min(8, 30), hm2min(8, 32)}, */
+    /* {3, hm2min(8, 34), hm2min(8, 36)}, */
+    /* {3, hm2min(8, 37), hm2min(8, 38)}, */
+    /* {3, hm2min(8, 40), hm2min(8, 42)}, */
+    /* {3, hm2min(9, 1), hm2min(9, 8)}, */
+    /* {3, hm2min(9, 22), hm2min(9, 24)}, */
+    /* {3, hm2min(9, 30), hm2min(9, 38)}, */
+    {3, hm2min(11, 6), hm2min(11, 13)},
+    {3, hm2min(11, 20), hm2min(10, 24)},
 };
 byte num_wps = sizeof(wps) / sizeof(wps[0]);

@@ -195,6 +205,10 @@
     if (t1.second() == t2.second()) {
         doFlash(ledPort, 1 + 2, 8);
     }
+
+    // Initialize millisRTC for time check task
+    millisRTC.begin(t2);
+    cur_mRTC_cycle = mRTC_refresh_cycle;

 #ifdef DEBUG_TRACE
     // Dump wps array
@@ -221,8 +235,8 @@
         case MAXM1:
             if (!maxms_awake) break;

-            scheduler.timer(MAXM1, maxm1_cycle * 10);
-            scheduler.timer(MAXM2, maxm2_offset * 10);
+            scheduler.timer(MAXM1, (word) (maxm1_cycle * 10));
+            scheduler.timer(MAXM2, (word) (maxm2_offset * 10));
             doFlash(ledPort, led1, 1);
             maxmRun(maxm1);
             // maxm1.send();
@@ -258,18 +272,62 @@

         // Check if awake or asleep
         case CHK_TIME:
+            // Reset millis()-based RTC from real one if the time
+            // cycles have elapsed
+            if (--cur_mRTC_cycle < 0) {
+#ifdef DEBUG_TRACE
+                DateTime t_mrtc = millisRTC.now();
+                Serial.print("mRTC time: ");
+                Serial.print(t_mrtc.year());
+                Serial.print('-');
+                Serial.print(t_mrtc.month());
+                Serial.print('-');
+                Serial.print(t_mrtc.day());
+                Serial.print(' ');
+                Serial.print(t_mrtc.hour());
+                Serial.print(':');
+                Serial.print(t_mrtc.minute());
+                Serial.print(':');
+                Serial.println(t_mrtc.second());
+                Serial.flush();
+                DateTime t_rtc = RTC.now();
+                Serial.print("RTC time: ");
+                Serial.print(t_rtc.year());
+                Serial.print('-');
+                Serial.print(t_rtc.month());
+                Serial.print('-');
+                Serial.print(t_rtc.day());
+                Serial.print(' ');
+                Serial.print(t_rtc.hour());
+                Serial.print(':');
+                Serial.print(t_rtc.minute());
+                Serial.print(':');
+                Serial.println(t_rtc.second());
+                Serial.flush();
+#endif
+                millisRTC.adjust(RTC.now());
+                cur_mRTC_cycle = mRTC_refresh_cycle;
+#ifdef DEBUG_TRACE
+                Serial.println("mRTC refreshed");
+                Serial.flush();
+#endif
+            }
+
             // Get time
-            DateTime now = RTC.now();
+            DateTime now = millisRTC.now();

             // Check every check_cycle seconds
-            int sec_til_check = check_cycle - (now.get() % check_cycle);
+            word sec_til_check = check_cycle - (now.get() % check_cycle);
+            // Never check sooner than 2 seconds. A perhaps futile attempt
+            // to prevent RTC clock from being interrogated too often
+            if (sec_til_check < 2) sec_til_check = 2;
             // TODO if sec_til_check is shorter than the check cycle by
             // more than a couple seconds, then reschedule and break so
             // the lights start their cycle with the CHK_TIME cycle.
             scheduler.timer(CHK_TIME, sec_til_check * 10);

 #ifdef DEBUG_TRACE
-            Serial.print("RTC time: ");
+            Serial.print("mRTC time: ");
             Serial.print(now.year());
             Serial.print('-');
             Serial.print(now.month());


Loop timing and activity LED added

Loop timing and activity LED added

--- Vsens/src/sketch.ino
+++ Vsens/src/sketch.ino
@@ -6,6 +6,7 @@

 // +V from battery is connected to analog pin 0
 #define measurePin A0
+#define activityLED 13

 // *** declare constants
 const float ref5V = 5.0;    // reference: 5.0V on measurePin == 1023.0
@@ -28,15 +29,19 @@
 int sumSamples = 0;         // sum of samples
 int cntSamples = 0;         // sample counter
 float voltage = 0.0;
+long startTime;
+long elapsedTime;

 void setup()
 {
-    Serial.begin(9600);     // Initialise serial port
+  pinMode(activityLED, OUTPUT);    // An LED to signal activity
+  Serial.begin(9600);     // Initialise serial port
 }

 void loop()
 {
-  cntSamples = 0;
+  startTime = millis();
+  digitalWrite(activityLED, HIGH)
   sumSamples = 0;

   // Add up the pre-defined number of samples for Sample Averaging
@@ -51,4 +56,9 @@

   Serial.print(voltage);
   Serial.println (" V");
+  digitalWrite(activityLED, LOW);
+  elapsedTime = millis() - startTime;
+
+  // Wait until 5sec have passed.
+  delay(abs(5000 - elapsedTime));
 }


Add an EC keyed certificat to BearSSL Server example (#6202)

Needed for future automated performance test suite use, to allow
selecting between EC and RSA signed keys for the server's cert.


Update sketch.ino

Update sketch.ino

--- Code/sketch.ino
+++ Code/sketch.ino
@@ -1,40 +1,39 @@
-#include "Motors.h"
-#include "Sensors.h"
-#include <LiquidCrystal.h>
+#include "Motors.h" //Подсоединяем Motors.h
+#include "Sensors.h" //Подсоединяем Sensors.h
+#include <LiquidCrystal.h> //Подсоединяем библиотеку управления экраном (80*14)

-#define LEFT_SENSOR_PIN  A0
+#define LEFT_SENSOR_PIN  A0 //Думаю понятно (если нет, то мне нечем помочь)
 #define RIGHT_SENSOR_PIN A1

-#define STATE_STOP 0
+#define STATE_STOP 0 //Просто константы
 #define STATE_FORWARD 1
 #define STATE_LEFT 2
 #define STATE_RIGHT 3
 #define STATE_BACKWARD 4

-Motors motors;
+Motors motors; //Объявление классов
 Sensors sensors;

-int DIR_1 = 4;
+int DIR_1 = 4; //PIN'Ы
 int DIR_2 = 7;
 int SPEED_1 = 5;
 int SPEED_2 = 6;

-int ledPin = 9;
 int potPin = A4;

-LiquidCrystal lcd(2, 3, 10, 11, 12, 13);
+LiquidCrystal lcd(2, 3, 10, 11, 12, 13); //Инициализация экрана

-String currentStateString = "";
+String currentStateString = ""; //Опционально. Для удобства.

-int state;
+int state; //Текущее состояние

 void setup() {

-  motors.attach(DIR_1, DIR_2, SPEED_1, SPEED_2);
+  motors.attach(DIR_1, DIR_2, SPEED_1, SPEED_2); //Подключение моторчиков

-  state = STATE_STOP;
+  state = STATE_STOP; //Изначально машина стоит, значит состояние STATE_STOP

-  lcd.begin(16, 2);
+  lcd.begin(16, 2);
   lcd.print("Hello");

   Serial.begin(9600);
@@ -45,15 +44,15 @@

 void loop() {

- sensors.attach(LEFT_SENSOR_PIN, RIGHT_SENSOR_PIN);
+ sensors.attach(LEFT_SENSOR_PIN, RIGHT_SENSOR_PIN); //Подключение сенсоров

- int PP = analogRead(potPin);
- PP = PP / 4;
+ int PP = analogRead(potPin); //Считывание показания потенциометра [0..1024]
+ PP = PP / 4; //Потому что MAX = 255 ИЛИ (1024/4)

 // int state = sensors.getAction();

  switch(state) {
-   case STATE_STOP:
+   case STATE_STOP: //Если стоит, то едем вперед
      if (sensors.getRight() && sensors.getLeft()) {
        state = STATE_FORWARD;
      }
@@ -61,23 +60,23 @@
    case STATE_FORWARD:
       motors.forward(PP);
       printString("OK, LET'S GO!");
-      if (!sensors.getRight() && sensors.getLeft()) {
+      if (!sensors.getRight() && sensors.getLeft()) { //Уперлись правым сенсором в трек
         state = STATE_RIGHT;
-      } else if (sensors.getRight() && !sensors.getLeft()) {
+      } else if (sensors.getRight() && !sensors.getLeft()) { //Уперлись левым сенсором в трек
         state = STATE_LEFT;
-      } else {
+      } else if (!sensors.getRight() && !sensors.getLeft()) { //Иначе под нами пустота
         state = STATE_BACKWARD;
       }
       break;
-    case STATE_LEFT:
+    case STATE_LEFT: //Аналогичный принцип. Едем налево
       motors.accelerateLeft(PP);
       printString("GO LEFT!");
       break;
-    case STATE_RIGHT:
+    case STATE_RIGHT: //Направо
       motors.accelerateRight(PP);
       printString("GO RIGHT!");
       break;
-    case STATE_BACKWARD:
+    case STATE_BACKWARD: //До сих пор непонятно?
       motors.backward();
       printString("TEAM, FALL BACK!!!");
       if (sensors.getRight() && sensors.getLeft()) {
@@ -86,11 +85,10 @@
       break;
   }

-  Serial.println(PP);
-  analogWrite(ledPin, PP);
+  Serial.println(PP);
 }

-void printString(String str) {
+void printString(String str) { //Функция для вывода строки на экран
   if (str == currentStateString) {
     return;
   }


Update arduino_md03_v_5_0.ino

Update arduino_md03_v_5_0.ino

added pin for batt meter

--- arduino/arduino_md03_v_5_0/arduino_md03_v_5_0.ino
+++ arduino/arduino_md03_v_5_0/arduino_md03_v_5_0.ino
@@ -35,6 +35,7 @@
 const int motorPinDir1 = 2;
 const int motorPinDir2 = 4;
 const int motorPinDir3 = 5;
+const int battVoltPin = A3;
 boolean direct1 = LOW; // Stores what direction the motor should run in
 boolean direct2 = LOW; // Stores what direction the motor should run in
 boolean direct3 = LOW; // Stores what direction the motor should run in


permit to server to turnoff the led

permit to server to turnoff the led

--- scripts-arduino/bp_led_lp.ino
+++ scripts-arduino/bp_led_lp.ino
@@ -6,7 +6,7 @@

 // ######## DEF ########
 #define LONGPRESS_LEN    40         // Min nr of loops for a long press
-#define DELAY            20        // Delay per loop in ms
+#define DELAY            20         // Delay per loop in ms
 #define DELAY_BLINK      50000
 // ######## VAR ########
 int buttonState = 0;                // variable for reading the pushbutton status
@@ -45,9 +45,13 @@
 void loop(){
     int eventResult = handle_button();
     int serialReadTemp = Serial.read();
-    if(serialReadTemp == 51) //51 is Hexa symbol for 3
+    if(serialReadTemp == 51)            // 51 is Hexa symbol for 3
     {
         turnBlink();
+    }
+    else if(serialReadTemp == 48)       // 48 is Hexa symbol for 0
+    {
+      turnOff();
     }
     switch(eventResult){
         case EV_NONE:               // if nothing append
@@ -114,13 +118,13 @@
             if(serialReadTemp != VAL_END_SYNC){
                 int serialReadTemp = Serial.read();

-                if (serialReadTemp == 52){
+                if (serialReadTemp == 52){      // 52 is Hexa Symbol for 4
                     isSync = true;
                 }
-                digitalWrite(LED_PIN, HIGH);   // turn the LED on (HIGH is the voltage level)
-                delay(100);               // wait for a second
-                digitalWrite(LED_PIN, LOW);    // turn the LED off by making the voltage LOW
-                delay(100);               // wait for a second
+                digitalWrite(LED_PIN, HIGH);    // turn the LED on
+                delay(100);                     // wait for a second
+                digitalWrite(LED_PIN, LOW);     // turn the LED off
+                delay(100);                     // wait for a second
             }
         }
         else{


-Return request for authorization on unauthorized upload request.

--- webserver.ino
+++ webserver.ino
@@ -60,8 +60,7 @@
   {
     if ( !server.authenticate( www_username, www_password ) )
     {
-      server.requestAuthentication();
-      return;
+      return server.requestAuthentication();
     }
     else
     {
@@ -73,8 +72,7 @@
   {
     if ( !server.authenticate( www_username, www_password ) )
     {
-      server.requestAuthentication();
-      return;
+      return server.requestAuthentication();
     }
     else
     {
@@ -84,8 +82,7 @@
   {
     if ( !server.authenticate( www_username, www_password ) )
     {
-      server.requestAuthentication();
-      return;
+      return server.requestAuthentication();
     }

     static File fsUploadFile;
@@ -98,8 +95,7 @@
     }
     if ( filename.length() > 30 )
     {
-      Serial.println( "Upload filename too long!" );
-      return;
+      return server.send( 400, textPlainHeader, "Upload filename too long!" );
     }
     if ( upload.status == UPLOAD_FILE_START )
     {


-Increase TaskDelay from 1ms to 2ms.

-Increase TaskDelay from 1ms to 2ms.

-Fixed 2 cahnnelNumbers out-of-bound.

--- webserver.ino
+++ webserver.ino
@@ -11,7 +11,7 @@
   while (1)
   {
     server.handleClient();
-    vTaskDelay( 1 / portTICK_PERIOD_MS);
+    vTaskDelay( 5 / portTICK_PERIOD_MS );
   }
 }

@@ -264,7 +264,7 @@
     if ( server.hasArg( "channel" ) ) {
       channelNumber = server.arg( "channel" ).toInt();
       Serial.println(channelNumber);
-      if ( channelNumber < 0 || channelNumber > NUMBER_OF_CHANNELS ) {
+      if ( channelNumber < 0 || channelNumber >= NUMBER_OF_CHANNELS ) {
         server.send( 400,  textplainHEADER, "Invalid channel." );
         return;
       }
@@ -284,7 +284,7 @@
     int channelNumber;
     if ( server.hasArg( "channel" ) ) {
       channelNumber = server.arg( "channel" ).toInt();
-      if ( channelNumber < 0 || channelNumber > NUMBER_OF_CHANNELS ) {
+      if ( channelNumber < 0 || channelNumber >= NUMBER_OF_CHANNELS ) {
         server.send( 400, textplainHEADER, "Invalid channel." );
         return;
       }


DHT11 added

DHT11 added

--- client/RGB_control/RGB_control.ino
+++ client/RGB_control/RGB_control.ino
@@ -7,6 +7,8 @@
  * asdf
  */

+#include <math.h>
+#include <DHT.h>
 #include <Arduino.h>
 #include <ESP8266WiFi.h>
 #include <ESP8266mDNS.h>
@@ -27,6 +29,12 @@
               b1Pin = D3;

 //const uint8_t ledPins[] = {r1Pin, g1Pin, b1Pin};
+
+#define DHTPIN D4
+#define DHTTYPE DHT11
+
+DHT dht(DHTPIN, DHTTYPE);
+

 WiFiClient espClient;
 PubSubClient mqttClient(espClient);
@@ -38,6 +46,9 @@
 bool otaInProgress = false;

 String domain = "RGB-LED-control";
+
+float humidity = NAN;
+float temperature = NAN;

 String subscriptions[] = {
@@ -152,6 +163,12 @@
   {
     long rssi = WiFi.RSSI();
     String response = String(domain + "/ack/" + thisMAC+"?rssi="+rssi);
+    if(!isnan(temperature)){
+      response+="&temperature="+String(temperature);
+    }
+    if(!isnan(humidity)){
+      response+="&humidity="+String(humidity);
+    }
     Serial.println(response);
     mqttClient.publish(response.c_str(), "ack");
   }
@@ -280,6 +297,7 @@
   mqttClient.setServer(mqtt_server, 1883);
   mqttClient.setCallback(callback);
   mqttTryReconnect();
+  dht.begin();
 }

 unsigned int loopCounter = 1;
@@ -305,6 +323,12 @@
     long rssi = WiFi.RSSI();
     Serial.print("RSSI: ");
     Serial.println(rssi);
+    temperature = dht.readTemperature();
+    humidity = dht.readHumidity();
+    Serial.print("Temperature: ");
+    Serial.println(temperature);
+    Serial.print("Humidty: ");
+    Serial.println(humidity);
   }
   if (WiFi.status() != WL_CONNECTED) {
     parseRGB("#000000");


little improvement, nothing fancy

little improvement, nothing fancy

--- Margoulineur2000.ino
+++ Margoulineur2000.ino
@@ -19,6 +19,7 @@

 #define MENUELEMENTS 4 //number of elements in the menu

+#define ENCODERSTEPS 2
 #define VALMIN 0 //min value of the new balance in the write sequence.
 #define VALMAX 99999 //maw value of the new balance in the write sequence

@@ -118,15 +119,15 @@
     {
        myEnc.write(0);
     }
-    Serial.println(newPosition / 4);
-    cycleMenu = (abs(newPosition) / 4) / MENUELEMENTS;
+    Serial.println(newPosition / ENCODERSTEPS);
+    cycleMenu = (abs(newPosition) / ENCODERSTEPS) / MENUELEMENTS;
     lcd.clear();
   }
 }

 void loop(void)
 {
- byte relativePosition = (abs(oldPosition) / 4) - (cycleMenu * MENUELEMENTS);
+ byte relativePosition = (abs(oldPosition) / ENCODERSTEPS) - (cycleMenu * MENUELEMENTS);
   lcd.setCursor(0,0);
   lcd.print(menuStrings[relativePosition][0]);
   lcd.setCursor(0,1);
@@ -164,14 +165,14 @@
     newPosition = myEnc.read();
     if ((newPosition != oldPosition) )
     {
-      if (newPosition < VALMIN * 4)
-        {
-          myEnc.write(VALMIN * 4);
+      if (newPosition < VALMIN * ENCODERSTEPS)
+        {
+          myEnc.write(VALMIN * ENCODERSTEPS);
           newPosition = 0;
         }
-        else if (newPosition > VALMAX * 4)
-        {
-          myEnc.write(VALMAX * 4);
+        else if (newPosition > VALMAX * ENCODERSTEPS)
+        {
+          myEnc.write(VALMAX * ENCODERSTEPS);
           newPosition = 40;
         }
         else
@@ -179,16 +180,16 @@
           lcd.clear();
           lcd.print("New balance :");
           lcd.setCursor(0,1);
-          lcd.print(newPosition / 4);
+          lcd.print(newPosition / ENCODERSTEPS);

           oldPosition = newPosition;
-          Serial.println(newPosition / 4);
+          Serial.println(newPosition / ENCODERSTEPS);
          }
     }
   }
   myEnc.write(0);
   oldPosition = -1;
-  return (newPosition / 4);
+  return (newPosition / ENCODERSTEPS);
 }

 void nfc_write()


updated basic switch code

updated basic switch code

--- examples-ltc/7.LTCVolume1/2_BasicSwitch/BasicSwitch.ino
+++ examples-ltc/7.LTCVolume1/2_BasicSwitch/BasicSwitch.ino
@@ -13,9 +13,6 @@

   if (pressed == 1){
       on(0);
-      pause(300);
-      off(0);
-      pause(300);
     } else {
       off(0);
     }


Ver 0.2

Ver 0.2

For Arduino
Add sonar support
Add servo support
Add compass support

--- sources/wheel/wheel.ino
+++ sources/wheel/wheel.ino
@@ -1,15 +1,56 @@
+/**************************************************************************************************************************
+   Operater-Bot
+   wheel.ino
+   Last Modified - 2017/5/14
+   by nicholaslu
+   Control Motos and direction
+   Remove double slash to let gofunctions to decide running time
+
+    Arduino GND -> GY271/HMC5883L GND
+    Arduino 3.3V -> GY271/HMC5883L VCC
+    Arduino A4 (SDA) -> GY271/HMC5883L SDA
+    Arduino A5 (SCL) -> GY271/HMC5883L SCL
+
+    Reference:  https://www.dipmicro.com/store/GY271-MOD
+
+**************************************************************************************************************************/
+#include <Wire.h> //I2C Arduino Library
+#include <Servo.h>
+
+#define HMC5883L_ADDR 0x1E //0011110b, I2C 7bit address of HMC5883
+#define ECHOPIN 12 // Sonar
+#define TRIGPIN 13
+
+Servo snServo; // create servo object
+
+// L298P
+// speed is the default PWM speed
 int E1 = 5;
 int M1 = 4;
 int E2 = 6;
 int M2 = 7;
 int speed = 100;
-int incomingByte = 0; //for incoming serial data
+int incomingByte = 0; // for incoming serial data
+int i = 1;
+bool haveHMC5883L = false;

 void setup()
 {
   pinMode(M1, OUTPUT);
   pinMode(M2, OUTPUT);
+  pinMode(ECHOPIN, INPUT);
+  pinMode(TRIGPIN, OUTPUT);
+  snServo.attach(11); // attaches the servo on pin 11 to the servo object
+  snServo.write(0);
+  delay(500);
+  snServo.write(180);
+  delay(500);
+  snServo.write(90);
   Serial.begin(9600); // 9600 bps
+  Wire.begin();
+  // lower I2C clock
+  TWBR = 78;  // 25 kHz
+  TWSR |= _BV (TWPS0);  // change prescaler
 }

 void loop()
@@ -18,80 +59,251 @@
   {
     incomingByte = Serial.read();
     if ('f' == incomingByte) {
-      goForward();
+      goForward(1000);
     }
     if ('g' == incomingByte) {
-      goForwardFast();
+      goForwardFast(1000);
     }
     if ('b' == incomingByte) {
-      goBackward();
+      goBackward(1000);
+    }
+    if ('e' == incomingByte) {
+      goBackwardFast(1000);
     }
     if ('s' == incomingByte) {
-      stopMoto();
+      stopMoto(1000);
     }
     if ('r' == incomingByte) {
-      turnRight();
+      turnRight(500);
     }
     if ('l' == incomingByte) {
-      turnLeft();
-    }
-  }
-}
-
-  void goForward()
+      turnLeft(500);
+    }
+  }
+  /*
+    getDistance();
+    getHead();
+  */
+  if (i == 1) walk();
+  i = 0;
+  stopMoto(1);
+}
+
+void goForward(int i)
+{
+  digitalWrite(M1, HIGH);
+  digitalWrite(M2, HIGH);
+  analogWrite(E1, speed);
+  analogWrite(E2, speed);
+  //delay(i);
+  //stopMoto();
+}
+
+void goForwardFast(int i)
+{
+  digitalWrite(M1, HIGH);
+  digitalWrite(M2, HIGH);
+  digitalWrite(E1, HIGH);
+  digitalWrite(E2, HIGH);
+  //delay(i);
+  //stopMoto();
+}
+
+void goBackward(int i)
+{
+  digitalWrite(M1, LOW);
+  digitalWrite(M2, LOW);
+  analogWrite(E1, speed);
+  analogWrite(E2, speed);
+  //delay(i);
+  //stopMoto();
+}
+
+void goBackwardFast(int i)
+{
+  digitalWrite(M1, LOW);
+  digitalWrite(M2, LOW);
+  digitalWrite(E1, HIGH);
+  digitalWrite(E2, HIGH);
+  //delay(i);
+  //stopMoto();
+}
+
+void stopMoto(int i)
+{
+  digitalWrite(M1, HIGH);
+  digitalWrite(M2, HIGH);
+  analogWrite(E1, 0);
+  analogWrite(E2, 0);
+  //delay(i);
+  //stopMoto();
+}
+
+// According to my test, it gonna turn almost 90 degrees while i = 500m
+void turnLeft(int i)
+{
+  digitalWrite(M1, HIGH);
+  digitalWrite(M2, LOW);
+  digitalWrite(E1, HIGH);
+  digitalWrite(E2, HIGH);
+  //delay(i);
+  //stopMoto();
+}
+
+void turnRight(int i)
+{
+  digitalWrite(M1, LOW);
+  digitalWrite(M2, HIGH);
+  digitalWrite(E1, HIGH);
+  digitalWrite(E2, HIGH);
+  //delay(i);
+  //stopMoto();
+}
+
+float getHead()
+{
+  float angle;
+  bool detect = detectHMC5883L();
+
+  if (!haveHMC5883L)
   {
-    digitalWrite(M1, HIGH);
-    digitalWrite(M2, HIGH);
-    analogWrite(E1, speed);
-    analogWrite(E2, speed);
-    delay(1000);
-  }
-
-  void goForwardFast()
+    if (detect)
+    {
+      haveHMC5883L = true;
+      Serial.println("HMC5883L detected");
+      // Put the HMC5883 IC into the correct operating mode
+      Wire.beginTransmission(HMC5883L_ADDR); //open communication with HMC5883
+      Wire.write(0x02); //select mode register
+      Wire.write(0x00); //continuous measurement mode
+      Wire.endTransmission();
+    }
+    else
+    {
+      Serial.println("HMC5883L not detected");
+      delay(2000);
+      return;
+    }
+  }
+  else
   {
-    digitalWrite(M1, HIGH);
-    digitalWrite(M2, HIGH);
-    digitalWrite(E1, HIGH);
-    digitalWrite(E2, HIGH);
-    delay(1000);
-  }
-
-  void goBackward()
-  {
-    digitalWrite(M1, LOW);
-    digitalWrite(M2, LOW);
-    digitalWrite(E1, HIGH);
-    digitalWrite(E2, HIGH);
-    delay(500);
-    stopMoto();
-  }
-
-  void stopMoto()
-  {
-    digitalWrite(M1, HIGH);
-    digitalWrite(M2, HIGH);
-    analogWrite(E1, 0);
-    analogWrite(E2, 0);
-    delay(1000);
-  }
-
-  void turnLeft()
-  {
-    digitalWrite(M1, HIGH);
-    digitalWrite(M2, LOW);
-    digitalWrite(E1, HIGH);
-    digitalWrite(E2, HIGH);
-    delay(500);
-    stopMoto();
-  }
-
-  void turnRight()
-  {
-    digitalWrite(M1, LOW);
-    digitalWrite(M2, HIGH);
-    digitalWrite(E1, HIGH);
-    digitalWrite(E2, HIGH);
-    delay(500);
-    stopMoto();
-  }
-
+    if (!detect) {
+      haveHMC5883L = false;
+      Serial.println("HMC5883L lost");
+      delay(2000);
+      return;
+    }
+  }
+
+  int x, y, z; //triple axis data
+
+  //Tell the HMC5883 where to begin reading data
+  Wire.beginTransmission(HMC5883L_ADDR);
+  Wire.write(0x03); //select register 3, X MSB register
+  Wire.endTransmission();
+
+  //Read data from each axis, 2 registers per axis
+  Wire.requestFrom(HMC5883L_ADDR, 6);
+  if (6 <= Wire.available()) {
+    x = Wire.read() << 8; //X msb
+    x |= Wire.read(); //X lsb
+    z = Wire.read() << 8; //Z msb
+    z |= Wire.read(); //Z lsb
+    y = Wire.read() << 8; //Y msb
+    y |= Wire.read(); //Y lsb
+  }
+
+  //Print out values of each axis
+  angle = atan2(y , x) * 180 / PI;
+  Serial.println(angle);
+  //  Serial.print("x: ");
+  //  Serial.print(x);
+  //  Serial.print("  y: ");
+  //  Serial.print(y);
+  //  Serial.print("  z: ");
+  //  Serial.println(z);
+  return angle;
+}
+
+bool detectHMC5883L()
+{
+  // read identification registers
+  Wire.beginTransmission(HMC5883L_ADDR); //open communication with HMC5883
+  Wire.write(10); //select Identification register A
+  Wire.endTransmission();
+  Wire.requestFrom(HMC5883L_ADDR, 3);
+  if (3 == Wire.available()) {
+    char a = Wire.read();
+    char b = Wire.read();
+    char c = Wire.read();
+    if (a == 'H' && b == '4' && c == '3')
+      return true;
+  }
+
+  return false;
+}
+
+float getDistance()
+{
+  digitalWrite(TRIGPIN, LOW);
+  delayMicroseconds(2);
+  digitalWrite(TRIGPIN, HIGH);
+  delayMicroseconds(10);
+  digitalWrite(TRIGPIN, LOW);
+  float distance = pulseIn(ECHOPIN, HIGH);
+  distance = distance / 58;
+  Serial.println(distance);
+  delay(200);
+  if (distance > 100) {
+    digitalWrite(13, HIGH);
+    delay(100);
+  }
+  else {
+    digitalWrite(13, LOW);
+    delay(100);
+  }
+  return distance;
+}
+
+void walk()
+{
+  float curHead, oriHead, curDist, deviation;
+  float guess = 10;
+  oriHead = getHead();
+  curDist = getDistance();
+  delay(100);
+  while (curDist > 1000) {
+    curDist = getDistance();
+    delay(100);
+  }
+  while (curDist >= 15) {
+    curHead = getHead();
+    deviation = abs(curHead) - abs(oriHead);
+    if (deviation <= 10) {
+      goForward(1);
+    }
+    else {
+      stopMoto(1);
+      while (abs(curHead) - abs(oriHead) > 10)
+      {
+        if (guess > 0) {
+          turnRight(1);
+          delay(abs(guess) * 10);
+        }
+        if (guess < 0) {
+          turnLeft(1);
+          delay(abs(guess) * 10);
+        }
+        curHead = getHead();
+        if (abs(curHead) - abs(oriHead) >= deviation) {
+          guess = -guess;
+        }
+        else {
+          guess = guess / 2;
+        }
+      }
+    }
+    curDist = getDistance();
+  }
+  stopMoto(1);
+}
+


less blue

less blue

--- circadian_hallway_cycle_colors/circadian_hallway_cycle_colors.ino
+++ circadian_hallway_cycle_colors/circadian_hallway_cycle_colors.ino
@@ -39,30 +39,30 @@
 #define E_C5_G 10
 #define E_C5_B 0

-#define E_MAX_COLOR_DIFFERENCE 55
+#define E_MAX_COLOR_DIFFERENCE 105

 //Morning colors defined here
 #define M_C1_R 145
 #define M_C1_G 13
-#define M_C1_B 255
+#define M_C1_B 200

 #define M_C2_R 72
 #define M_C2_G 12
-#define M_C2_B 232
-
-#define M_C3_R 0
-#define M_C3_G 0
-#define M_C3_B 255
-
-#define M_C4_R 12
-#define M_C4_G 70
-#define M_C4_B 232
+#define M_C2_B 200
+
+#define M_C3_R 255
+#define M_C3_G 255
+#define M_C3_B 150
+
+#define M_C4_R 50
+#define M_C4_G 90
+#define M_C4_B 150

 #define M_C5_R 13
 #define M_C5_G 140
-#define M_C5_B 255
-
-#define M_MAX_COLOR_DIFFERENCE 145
+#define M_C5_B 200
+
+#define M_MAX_COLOR_DIFFERENCE 243

 void turn_on_morning_colors()
 {


Prise de mesure de tous les capteurs simultanément

--- sensorSlave/sensorSlave.ino
+++ sensorSlave/sensorSlave.ino
@@ -12,13 +12,13 @@

 const int sensorPins[][2] = {
   {
-    A0,4}
+    A0,4          }
   ,{
-    A1,3}
+    A1,3          }
   ,{
-    A2,2}
+    A2,2          }
   ,{
-    A3,1}
+    A3,1          }
 };

 const int sensor_SIZE = ARRAY_LENGTH(sensorPins);
@@ -32,9 +32,13 @@
   int i2cAddress = 0;
   for (int i=0;i<ARRAY_LENGTH(addressPins);i++){
     pinMode(addressPins[i], INPUT_PULLUP);
+
     if (digitalRead(addressPins[i]) == HIGH){
       i2cAddress += (1<<i);
     }
+
+    pinMode(addressPins[i], OUTPUT);
+    digitalWrite(addressPins[i], LOW);
   }

   Wire.begin(i2cAddress);
@@ -54,14 +58,36 @@
     pinMode(sensorPins[i][0], INPUT_PULLUP);
     pinMode(sensorPins[i][1], OUTPUT);
     digitalWrite(sensorPins[i][1], LOW);
-    delay(50);
+  }
+
+  unsigned long currentTime = millis();
+
+#ifdef LOG_SERIAL
+  Serial.println(millis());
+#endif
+
+  delay(100);
+
+  for (int i=0;i<sensor_SIZE;i++){

     A_Values[i] = 1023-analogRead(sensorPins[i][0]); //Attention à corriger ça
+  }
+
+  for (int i=0;i<sensor_SIZE;i++){

     pinMode(sensorPins[i][0], OUTPUT);
     digitalWrite(sensorPins[i][0], LOW);
     digitalWrite(sensorPins[i][1], HIGH);
-    delay(50);
+  }
+
+#ifdef LOG_SERIAL
+  Serial.println(millis());
+  Serial.println(millis() - currentTime);
+#endif
+
+  delay(millis() - currentTime);
+
+  for (int i=0;i<sensor_SIZE;i++){

     digitalWrite(sensorPins[i][1], LOW);
     digitalWrite(sensorPins[i][0], LOW);
@@ -75,7 +101,8 @@
   Serial.println();
 #endif

-  delay(600);
+  delay(900); // ici  ~ une seconde est passé + quelques microsecondes
+  delay(60*1000); // 1 min de pause
 }

 void requestEvent()
@@ -94,3 +121,8 @@
 void receiveEvent(int len){

 }
+
+
+
+
+


change pixel size to fit wheel's circumference for adults

--- arduino-neopixel.ino
+++ arduino-neopixel.ino
@@ -9,7 +9,7 @@
 //   NEO_GRB     Pixels are wired for GRB bitstream
 //   NEO_KHZ400  400 KHz bitstream (e.g. FLORA pixels)
 //   NEO_KHZ800  800 KHz bitstream (e.g. High Density LED strip)
-Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, 6, NEO_GRB + NEO_KHZ800);
+Adafruit_NeoPixel strip = Adafruit_NeoPixel(99, 6, NEO_GRB + NEO_KHZ800);

 char input[11];   // 文字列格納用
 String input_str;   // 文字列格納用


Update the servo point controller to move the servo to the last pos when turn on.

--- examples/servo_point_controler/servo_point_controler.ino
+++ examples/servo_point_controler/servo_point_controler.ino
@@ -42,8 +42,8 @@
 //#define PUSH_BUTTON1 28               //debug push button
 #define NODE_VARS 2                  //number o node variables.Servo speed, action to take on starting. see setupServos

-#define SERVO_SPEED_VAR        0
-#define SERVO_STARTACTION_VAR  1
+#define SERVO_SPEED_VAR        1
+#define SERVO_STARTACTION_VAR  2

 #define NODE_EVENTS 30              //max number of events
 #define EVENTS_VARS VAR_PER_SERVO   //number of variables per event
@@ -165,7 +165,7 @@
       if (isServoToTogle(servoidx)){
         //Serial.println("off-moving servo t");
         servos[servoidx].write(servo_end,SPEED);
-	lastPos = servo_end;
+	      lastPos = servo_end;
       }
       else {
         //Serial.println("off-moving servo");
@@ -174,13 +174,14 @@
       }
     }
    //write last pos to eprom
-   //variables start with number 1
+   //variables start with number 1
    cbus.setInternalNodeVariable(servoidx+1,lastPos);
 }

 //create the objects for each servo
-void setUpServos(){
+void setUpServos(){
   byte ac = cbus.getNodeVar(SERVO_STARTACTION_VAR);
+  Serial.println(ac);
   for (uint8_t i=0;i<NUM_SERVOS;i++){
     servos[i].attach(servopins[i]);

@@ -188,12 +189,12 @@
       case 0: //do nothing
       break;
       case 1://move to start position
-	servos[i].write(15,SPEED);
+	       servos[i].write(15,SPEED);
       break;
       case 2://mode to end position
       	servos[i].write(170,SPEED);
       break;
-      case 3://move to last position
+      case 3://move to last position
           moveServoToLastPosition(i);
       break;
     }
@@ -201,7 +202,7 @@
 }

 void moveServoToLastPosition(byte idx){
-    byte pos=cbus.getInternalNodeVar(idx+1);
+    byte pos=cbus.getInternalNodeVar(idx+1);
     if (pos < 175){
        servos[idx].write(pos,SPEED);
     }


Amend

Amend

--- Kleineswetter/Kleineswetter.ino
+++ Kleineswetter/Kleineswetter.ino
@@ -99,8 +99,7 @@
         systemState.roundsWithoutTransmission++;
         systemState.writeToRtc(0, sizeof(SystemState));

-        // TODO "8" here
-        sleepNowForServer(8, millis() - systemStart);
+        sleepNowForServer(-1, millis() - systemStart);
       } else {
         Serial.print("Connect because of change ");
         Serial.print(abs(systemState.lastTransmittedTemperatature - t));


Control Game Relay

Control Game Relay

--- PinballDriver/PinballDriver.ino
+++ PinballDriver/PinballDriver.ino
@@ -25,6 +25,42 @@
   20 Ground
 */

+/*
+  SF2 Solenoids
+  00  0 0  0  Pop Bumber
+  01  0 1  0  Left Kicking Rubber
+  02  0 2  0  Right Kicking Rubber
+  03  0 3  0  Bottom Left Kicker
+  04  0 4  0  Bottom Right Kicker
+  05  0 5  0  Left Plunger Gate
+  06  0 6  0  Right Plunger Gate
+  07  0 7  1  Left Stargate Ramp
+  08  1 0  1  Right Stargate Ramp
+  09  1 1  0  Left Hole
+  10  1 2  0  Right Hole
+  11  1 3  0  - Unused
+  12  1 4  0  - Unused
+  13  1 5  0  Car Reset
+  14  1 6  0  Lamp Left Tap
+  15  1 7  0  Lamp Lightstrip
+  16  2 0  0  Lamp Left Bottom
+  17  2 1  0  Lamp Ramp
+  18  2 2  0  Lamp Left Flipper
+  19  2 3  0  Lamp Right Bottom
+  20  2 4  0  Lamp Right Center
+  21  2 5  0  Lamp Right Top
+  22  2 6  0  Lamp Right Flipper
+  23  2 7  1  Low Playfield Flipper Relay
+  24  3 0  1  Motor Relay
+  25  3 1  1  Lightbox Relay
+  26  3 2  0  Coin Meter
+  27  3 3  0  Ball Release
+  28  3 4  0  Outhole
+  29  3 5  0  Knocker
+  30  3 6  1  Tilt Relay
+  31  3 7  1  Game Over Relay
+*/
+
 // 0, 1, 2, 3, 5, 6, 7, 8, 9

 // 0 Master Reset
@@ -41,15 +77,23 @@

-byte solenoidData[4]; // 32 solenoid values
+byte solenoidData[4] = {
+  0x00, 0x00, 0x00, 0x00
+}; // 32 solenoid values
+
+// after each run the solenoidData & solenoidReset
+// this will ensure that solenoids are not triggered for a long time
+byte solenoidHold[4] = {
+  0x80, 0x01, 0x80, 0xC3
+};

 const int masterResetPin = 0;

 const int solenoidStrobePins[4] = {
-  6,
   -1,
   -1,
   -1,
+  6,
 };

 const int solenoidDataPins[8] = {
@@ -82,27 +126,11 @@

   digitalWrite(masterResetPin, HIGH);
   delay(2000);
+
+  solenoidData[3] = 0x80;
 }

-long oldMillis = 0;
-
-bool on = false;
-long onDelay = 4000;
-
 void loop() {
-  long delta = millis() - oldMillis;
-  oldMillis = millis();
-
-  onDelay -= delta;
-  if(onDelay < 0) {
-    onDelay += 4000;
-
-    on = !on;
-
-    solenoidData[0] = on ? (1 << 7) : (0 << 7);
-  }
-
-
   for(int solenoidStrobeIndex = 0; solenoidStrobeIndex < 4; ++solenoidStrobeIndex) {
     const byte solenoidByte = solenoidData[solenoidStrobeIndex];

@@ -138,5 +166,8 @@
 //    delay(3000);
   }

+  for(int solenoidIndex = 0; solenoidIndex < 4; ++solenoidIndex) {
+    solenoidData[solenoidIndex] = solenoidData[solenoidIndex] & solenoidHold[solenoidIndex];
+  }
 }


Update abs.ino

Update abs.ino

--- src/Arduino/abs/abs.ino
+++ src/Arduino/abs/abs.ino
@@ -4,7 +4,9 @@
 #include <SoftwareSerial.h>
 #include <SD.h>
 #include <SPI.h>
-#include <Servo.h>
+#include <Servo.h>
+#include <comms.h>
+#include <hdlc.h>
 #include "abs.h"

 Servo myServo[MAX_SERVO];


Corrections

Corrections

--- script/core/arduino/robot/robot.ino
+++ script/core/arduino/robot/robot.ino
@@ -1,18 +1,22 @@
-int mAvant = 3;
-int mArrier = 4;
-int angle = 5;
+int mAvant = 5;
+int mArrier = 6;
+int angle = 9;
 int data = 0;

 void setup(){
   Serial.begin(9600);
-  analogWrite(angle, 90);
+  pinMode(angle, OUTPUT);
+  analogWrite(angle, 0);
+  pinMode(mAvant, OUTPUT);
+  pinMode(mArrier, OUTPUT);
   digitalWrite(mAvant, LOW);
   digitalWrite(mArrier, LOW);
 }

 void loop(){
-  if (Serial.available() > 0) {
-    data = Serial.read();
+  if (Serial.available()) {
+    data = Serial.read()-'0';
+    Serial.println(data);
     switch(data){
       case 0:
         digitalWrite(mAvant, LOW);
@@ -29,11 +33,11 @@
       case 3:
         while(Serial.available() <= 0)
           delay(1);
-        data = Serial.read();
+        data = Serial.read() - '0';
         analogWrite(angle, data);
         break;
       default:break;
     }
-    analogWrite(angle);
+    delay(1);
   }
 }


Added carriage returns to rf_serial_gateway in order that each message appears on a new line

--- rf_serial_gateway_v0_1/rf_serial_gateway_v0_1.ino
+++ rf_serial_gateway_v0_1/rf_serial_gateway_v0_1.ino
@@ -34,7 +34,7 @@
     #if DEBUG
         Serial.print("[rfSerialGateway - ");
         Serial.print(VERSION);
-        Serial.print("]");
+        Serial.println("]");
     #endif
     rf12_initialize(NODEID, FREQUENCY, NETWORKID);
 }
@@ -73,6 +73,7 @@
         encoder.push(inData.data[i]);
     }
     encoder.endList();
+    Serial.println();
 }

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


Fixed increment of maximum timeout allowed if transition not detected soon enough. Also added a counter to monitor the number of hits for each delay setting.

--- Debug_Auto.ino
+++ Debug_Auto.ino
@@ -8,7 +8,7 @@

  Please leave comment or suggestions in the "Issues" feature on the GIT-Hub site

- Remember to check both Polarity settings for sensible data.
+ Remember to check both nos of Bytes and header hits settings for sensible data.

  DebugVersion_09, 28tyh July 2014


short test by breaking one example

short test by breaking one example

--- examples/ChangeSensorI2CAddress/ChangeSensorI2CAddress.ino
+++ examples/ChangeSensorI2CAddress/ChangeSensorI2CAddress.ino
@@ -4,9 +4,9 @@
 I2CSoilMoistureSensor sensor(0x20);

 void setup() {
-  Wire.begin();
+  Wire.begins();
   Serial.begin(9600);
-
+
   sensor.begin(); // reset sensor
   delay(1000); // give some time to boot up
   Serial.print("I2C Soil Moisture Sensor Address: ");
@@ -18,12 +18,12 @@
   Serial.print("Change address to 0x21 ...");
   if (sensor.setAddress(0x21,true)) // set Sensor Address to 0x21 and reset
     Serial.println("... DONE");
-  else
+  else
     Serial.println("... ERROR");
   Serial.println();
 }

-/*loop scans I2C bus and displays foud addresses*/
+/*loop scans I2C bus and displays foud addresses*/
 void loop() {
   byte error, address;
   int nDevices;
@@ -52,7 +52,7 @@
       if (address<16)
         Serial.print("0");
       Serial.println(address,HEX);
-    }
+    }
   }
   if (nDevices == 0)
     Serial.println("No I2C devices found\n");


Update OnDemandConfigPortal.ino

Update OnDemandConfigPortal.ino

--- examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino
+++ examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino
@@ -169,7 +169,7 @@
   std::vector<const char *> menu = {"wifi","wifinoscan","info","param","close","sep","erase","restart","exit"};
   // wm.setMenu(menu); // custom menu, pass vector

-  wm.setParamsPage(true); // move params to seperate page, not wifi, do not combine with setmenu!
+  // wm.setParamsPage(true); // move params to seperate page, not wifi, do not combine with setmenu!

   // set static sta ip
   // wm.setSTAStaticIPConfig(IPAddress(10,0,1,99), IPAddress(10,0,1,1), IPAddress(255,255,255,0));
@@ -203,7 +203,7 @@

   // wm.setCleanConnect(true); // disconenct before connect, clean connect

-  // wm.setBreakAfterConfig(true);
+  wm.setBreakAfterConfig(true);

   //fetches ssid and pass and tries to connect
   //if it does not connect it starts an access point with the specified name
@@ -211,7 +211,7 @@
   //and goes into a blocking loop awaiting configuration
   wifiInfo();
   print_oled(F("Connecting..."),2);
-  if(!wm.autoConnect("WM_AutoConnectAP")) {
+  if(!wm.autoConnect("WM_AutoConnectAP","12345678")) {
     Serial.println("failed to connect and hit timeout");
     print_oled("Not Connected",2);
   }


1.0 RC2

1.0 RC2

Adding RGB Luxeon style device support

--- Lightsaber.ino
+++ Lightsaber.ino
@@ -20,17 +20,69 @@
 #include <Wire.h>
 #endif

+/*
+ * DO NOT MODIFY
+ */
 #define CONFIG_VERSION "LS01"
-#define VOL	13
-#define SOUNDFONT 2
-#define	SWING 750
-#define	CLASH_ACCEL 9000
-#define	CLASH_BRAKE 4000
-#define SWING_SUPPRESS 110
-#define CLASH_SUPPRESS 60
-#define MEMORYBASE 32
-#define SOUNDFONT_FOLDERS 3
-#define CLASH_PASSES 10
+
+//#define LEDSTRINGS
+#ifndef LEDSTRINGS
+#define LUXEON
+#endif
+
+/*
+ * DEFINE PINS
+ * Modify to match your project setup
+ * DO NOT USE PINS:
+ * A4 Reserved to MPU6050 SDA
+ * A5 Reserved to MPU6050 SCL
+ * D2 Reserved to MPU6050 interrupts
+ *
+ * Spare :
+ * A2,13,D11
+ */
+#ifdef LEDSTRINGS
+#define LEDSTRING1 			3
+#define LEDSTRING2 			4
+#define LEDSTRING3 			5
+#define LEDSTRING4 			6
+#define LEDSTRING5 			7
+#define LEDSTRING6 			8
+#endif
+#ifdef LUXEON
+#define COLORS		 		54   // Number of RGB (not RGBW) colors in our array. Do we need that much ?
+#define LED_RED 			3
+#define LED_GREEN 			4
+#define LED_BLUE 			5
+//#define LED_WHITE 			6   //Not used right now
+#endif
+
+#define DFPLAYER_RX			12
+#define DFPLAYER_TX			13
+#define SPK1				A0
+#define SPK2				A1
+#define MAIN_BUTTON			9
+#define LOCKUP_BUTTON		10
+
+/*
+ * DEFAULT CONFIG PARAMETERS
+ * Will be overriden by EEPROM settings once the first
+ * save will be done
+ */
+#define VOL					13
+#define SOUNDFONT 			2
+#define	SWING 				750
+#define	CLASH_ACCEL 		9000
+#define	CLASH_BRAKE 		4000
+
+/*
+ * OTHER PARAMETERS
+ */
+#define SWING_SUPPRESS 		110
+#define CLASH_SUPPRESS 		60
+#define MEMORYBASE 			32
+#define CLASH_PASSES 		10
+#define MAX_BRIGHTNESS		255

 /* For daily use I recommend you comment LS_INFO
  * When you plug your device to USB uncomment LS_INFO !
@@ -71,7 +123,19 @@
 /*
  * LED String variables
  */
-int ledPins[] = { 3, 4, 5, 6, 7, 8 };
+#ifdef LEDSTRINGS
+int ledPins[] = { LEDSTRING1, LEDSTRING2, LEDSTRING3, LEDSTRING4, LEDSTRING5,
+LEDSTRING6 };
+#endif
+#ifdef LUXEON
+int ledPins[] = {LED_RED, LED_GREEN,LED_BLUE /*,LED_WHITE*/};
+
+// byte color => {R,G,B,ColorNumber}
+byte mainColor[4] = {0,100,0,8}; //Green
+byte clashColor[4] = {100,0,0,0};	//Red
+byte currentColor[3];
+const int rgbFactor=100;
+#endif
 int brightness = 0;    // how bright the LED is

 /*
@@ -81,8 +145,6 @@
 bool configMode = false; // Play with your saber
 bool ignition = false;
 bool browsing = false;
-const int mainButtonPin = 9;
-const int clashButtonPin = 10;

 int mainButtonState = HIGH;        // the current readingMain from the input pin
 int lastMainButtonState = HIGH;   // the previous readingMain from the input pin
@@ -98,15 +160,13 @@
 bool mainPressed = false;
 unsigned long startLockupPressing;

-unsigned long debounceDelay = 5; // the debounce time; increase if the output flickers
+unsigned long debounceDelay = 5; // the debounce time; increase if the output lightFlickers

 /*
  * DFPLAYER variables
  */
 DFPlayer mp3;
 SoundFont soundFont;
-int SPK1 = A0;
-int SPK2 = A1;
 int lastPlayed = 0;
 int lastPlayed2 = 0;
 bool repeat = false;
@@ -125,19 +185,35 @@
 bool ok = true;
 int configAdress = 0;
 long lastValue = 0;
+#ifdef LEDSTRINGS
 struct StoreStruct {
+	// This is for mere detection if they are our settings
+	char version[5];
 	// The settings
 	int volume;						// 0 to 30
 	int soundFont; 		// as many as Sound font you have defined in Soundfont.h
 	long swingTreshold;				// treshold acceleration for Swing
 	long clashAccelTreshold;		// treshold acceleration for Swing
 	long clashBrakeTreshold;		// treshold acceleration for Swing
+} storage;
+#endif
+#ifdef LUXEON
+struct StoreStruct {
 	// This is for mere detection if they are our settings
 	char version[5];
-} storage = { VOL, SOUNDFONT, SWING, CLASH_ACCEL, CLASH_BRAKE, CONFIG_VERSION };
-
+	// The settings
+	int volume;// 0 to 30
+	int soundFont;// as many as Sound font you have defined in Soundfont.h
+	long swingTreshold;// treshold acceleration for Swing
+	long clashAccelTreshold;// treshold acceleration for Swing
+	long clashBrakeTreshold;// treshold acceleration for Swing
+	byte mainColor[4];
+	byte clashColor[4];
+	byte soundFontColorPreset[SOUNDFONT_QUANTITY][2];
+}storage;
+#endif
 void setup() {
-	turnOff(ledPins);
+	lightOff(ledPins);

 	// join I2C bus (I2Cdev library doesn't do this automatically)
 #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
@@ -158,13 +234,27 @@
 	configAdress = EEPROM.getAddress(sizeof(StoreStruct)); // Size of config object

 	if (!loadConfig()) {
+		for (int i = 0; i <= 5; i++)
+			storage.version[i] = CONFIG_VERSION[i];
 		storage.soundFont = SOUNDFONT;
 		storage.volume = VOL;
 		storage.swingTreshold = SWING;
 		storage.clashAccelTreshold = CLASH_ACCEL;
 		storage.clashBrakeTreshold = CLASH_BRAKE;
-		for (int i = 0; i <= 5; i++)
-			storage.version[i] = CONFIG_VERSION[i];
+#ifdef LUXEON
+		storage.mainColor[0] = 0;
+		storage.mainColor[1] = 100;
+		storage.mainColor[2] = 0;
+		storage.mainColor[3] = 8;
+		storage.clashColor[0] = 100;
+		storage.clashColor[1] = 0;
+		storage.clashColor[2] = 0;
+		storage.clashColor[3] = 0;
+		storage.soundFontColorPreset[0][0] = 8;
+		storage.soundFontColorPreset[0][1] = 0;
+		storage.soundFontColorPreset[1][0] = 0;
+		storage.soundFontColorPreset[0][1] = 16;
+#endif
 #ifdef LS_INFO
 		Serial.println(F("Config reverted to default value"));
 #endif
@@ -172,6 +262,13 @@
 #ifdef LS_INFO
 	else {
 		Serial.println(F("Config Loaded"));
+	}
+#endif
+
+#ifdef LUXEON
+	//initialise start color
+	for (int i = 2; i >= 0; i--) {
+		currentColor[i] = mainColor[i];
 	}
 #endif

@@ -259,7 +356,7 @@
 	/***** LED SEGMENT INITIALISATION  *****/

 	/***** DF PLAYER INITIALISATION  *****/
-	mp3.setSerial(12, 13);
+	mp3.setSerial(DFPLAYER_TX, DFPLAYER_RX);
 	mp3.setVolume(storage.volume);
 	pinMode(SPK1, INPUT);
 	pinMode(SPK2, INPUT);
@@ -287,8 +384,8 @@
 	}

 // read the state of the pushbuttons value:
-	readingMain = digitalRead(mainButtonPin);
-	readingLockup = digitalRead(clashButtonPin);
+	readingMain = digitalRead(MAIN_BUTTON);
+	readingLockup = digitalRead(LOCKUP_BUTTON);

 	MainButton();
 	LockupButton();
@@ -322,7 +419,7 @@
 					soundFont.getFolder());

 			// Light up the ledstrings
-			turnOn(ledPins);
+			lightOn(ledPins);

 			// Get the initial position of the motion detector
 			motionEngine();
@@ -340,8 +437,9 @@
 			changePlayMode = false;
 		}

-		//brightness = random(128, 190);
-		brightness = 200 - (abs(analogRead(SPK1) - analogRead(SPK2)));
+		// Amount of brightness to fade
+		brightness = MAX_BRIGHTNESS
+				- (abs(analogRead(SPK1) - analogRead(SPK2)));
 #ifdef LS_HEAVY_DEBUG
 		Serial.print(F("Brightness: "));
 		Serial.print(brightness);
@@ -350,7 +448,7 @@
 		Serial.print(F("   SPK2: "));
 		Serial.println(analogRead(SPK2));
 #endif
-		flicker(ledPins, brightness);
+		lightFlicker(ledPins, brightness);

 		// ************************* blade movement detection ************************************
 		motionEngine();
@@ -429,7 +527,7 @@
 			printAcceleration(aaWorld);
 #endif
 #ifdef LS_CLASH_DEBUG
-				Serial.println(F("");
+			Serial.println(F("");
 #endif
 		} else {
 			/*
@@ -476,13 +574,6 @@
 			} else if (clashSuppress == CLASH_SUPPRESS) {
 				clashSuppress = 0;
 			}
-			/*
-			 if (swingSuppress > 0 and swingSuppress < SWING_SUPPRESS) {
-			 swingSuppress++;
-			 } else if (swingSuppress == SWING_SUPPRESS) {
-			 swingSuppress = 0;
-			 }
-			 */
 #ifdef LS_SWING_DEBUG
 			if (swingSuppress) {
 				Serial.print(F("swingSuppress= "));
@@ -575,6 +666,48 @@
 	 */
 	else if (configMode) {
 		long value = 0;
+#ifdef LUXEON
+		byte rgbArray[COLORS][3] =
+		{
+			// RGB Array 3 wide 54 tall, stores RGB values
+			// (There's gotta be a prettier way to do this!)
+			{	100,0,0}, /*Red*/
+			{	100,15,0},
+			{	100,40,0},
+			{	100,60,0},
+			{	100,100,0},
+			{	60,100,0},
+			{	40,100,0},
+			{	15,100,0},
+			{	0,100,0} /*Green*/,
+			{	0,100,15},
+			{	0,100,40},
+			{	0,100,60},
+			{	0,100,100},
+			{	0,60,100},
+			{	0,40,100},
+			{	0,15,100},
+			{	0,0,100}, /*Blue*/
+			{	15,0,100},
+			{	40,0,100},
+			{	60,0,100},
+			{	100,0,100},
+			{	100,0,60},
+			{	100,0,40},
+			{	100,0,15},
+			//Hue one, a lighter starts at Array pointer 40100
+			{	100,15,15}, {100,40,15}, {100,60,15}, {100,100,15},
+			{	60,100,15}, {40,100,15}, {15,100,15}, {15,100,40},
+			{	15,100,60}, {15,100,100}, {15,60,100}, {15,40,100},
+			{	15,15,100}, {40,15,100}, {60,15,100}, {100,15,100},
+			{	100,15,60}, {100,15,40},
+			//Hue two, Lightest starts at Array pointer 10040
+			{	100,40,40}, {100,60,40}, {100,100,40}, {60,100,40},
+			{	40,100,40}, {40,100,60}, {40,100,100}, {40,60,100},
+			{	40,40,100}, {60,40,100}, {100,40,100}, {100,40,60},
+		};
+#endif
+
 		if (!browsing) {
 			//mp3.playTrackFromDir(1, 3,false);
 #ifdef LS_INFO
@@ -601,8 +734,10 @@
 		case 0:
 			if (enterMenu) {
 				mp3.playTrackFromDir(4, 1, false);
-				turnOff(ledPins);
+#ifdef LEDSTRINGS
+				lightOff(ledPins);
 				analogWrite(ledPins[0], 160);
+#endif
 #ifdef LS_INFO
 				Serial.print(F("-------VOLUME-------\nCurrent Volume :"));
 				Serial.println(storage.volume);
@@ -628,8 +763,10 @@
 		case 1:
 			if (enterMenu) {
 				mp3.playTrackFromDir(5, 1, false);
-				turnOff(ledPins);
+#ifdef LEDSTRINGS
+				lightOff(ledPins);
 				analogWrite(ledPins[1], 160);
+#endif
 #ifdef LS_INFO
 				Serial.println(F("-----SOUNDFONT------\nCurrent value :"));
 				Serial.println(soundFont.getFolder());
@@ -647,14 +784,123 @@
 			if (value != lastValue) {
 				storage.soundFont = value;
 				soundFont.setFolder(value);
+#ifdef LUXEON
+				mainColor[3]=storage.soundFontColorPreset[value][0];
+				mainColor[0]=rgbArray[mainColor[3]][0];
+				mainColor[1]=rgbArray[mainColor[3]][1];
+				mainColor[2]=rgbArray[mainColor[3]][2];
+
+				clashColor[3]=storage.soundFontColorPreset[value][1];
+				clashColor[0]=rgbArray[clashColor[3]][0];
+				clashColor[1]=rgbArray[clashColor[3]][1];
+				clashColor[2]=rgbArray[clashColor[3]][2];
+#endif
+#ifdef LS_INFO
 				Serial.println(soundFont.getFolder());
+#endif
 			}
 			break;
+#ifdef LEDSTRINGS
 		case 2:
+			menu++;
+		case 3:
+			menu++;
+		case 4:
+			menu++;
+#endif
+#ifdef LUXEON
+			case 2:
+			if (enterMenu) {
+				//mp3.playTrackFromDir(8, 1, false);
+				ledOff(ledPins);
+				lightChangeColor(mainColor);
+#ifdef LS_INFO
+				Serial.print(
+						F("--MAIN COLOR--\nCurrent value :"));
+#endif
+				enterMenu = false;
+			}
+			lastValue = storage.mainColor[3];
+			value = storage.mainColor[3] + lockupLastPlayed;
+			lockupLastPlayed = 0;
+			if (value < 0) {
+				value = COLORS;
+			} else if (value > COLORS) {
+				value = 0;
+			}
+			if (value != lastValue) {
+				storage.mainColor[0]= rgbArray[value][0];
+				storage.mainColor[1]= rgbArray[value][0];
+				storage.mainColor[2]= rgbArray[value][0];
+				storage.mainColor[3] = value;
+				lightChangeColor(mainColor);
+#ifdef LS_INFO
+				Serial.println(storage.clashBrakeTreshold);
+#endif
+			}
+			break;
+			case 3:
+			if (enterMenu) {
+				//mp3.playTrackFromDir(8, 1, false);
+				ledOff(ledPins);
+				lightChangeColor(mainColor);
+#ifdef LS_INFO
+				Serial.print(
+						F("--CLASH  COLOR--\nCurrent value :"));
+#endif
+				enterMenu = false;
+			}
+			lastValue = storage.clashColor[3];
+			value = storage.clashColor[3] + lockupLastPlayed;
+			lockupLastPlayed = 0;
+			if (value < 0) {
+				value = COLORS;
+			} else if (value > COLORS) {
+				value = 0;
+			}
+			if (value != lastValue) {
+				storage.clashColor[0]= rgbArray[value][0];
+				storage.clashColor[1]= rgbArray[value][0];
+				storage.clashColor[2]= rgbArray[value][0];
+				storage.clashColor[3] = value;
+				lightChangeColor(mainColor);
+#ifdef LS_INFO
+				Serial.println(storage.clashBrakeTreshold);
+#endif
+			}
+			break;
+			case 4:
+			if (enterMenu) {
+				//mp3.playTrackFromDir(8, 1, false);
+			ledOff(ledPins);
+#ifdef LS_INFO
+				Serial.print(
+						F("--DO YOU WANT TO ASSIGN THOSE COLOR TO CURRENT SOUNDFONT ? --\nMain :Yes / Lockup: No"));
+#endif
+				enterMenu = false;
+			}
+			if (lockupLastPlayed >0) {
+				//Yes
+				//We save color values to this Soundfount
+				storage.soundFontColorPreset[storage.soundFont][0]=mainColor[3];
+				storage.soundFontColorPreset[storage.soundFont][0]=clashColor[3];
+				menu++;
+			}
+			else if (lockupLastPlayed <0) {
+				//No
+				// we do nothing and leave this menu
+				menu++;
+			}
+			lockupLastPlayed =0;
+			break;
+#endif
+		case 5:
 			if (enterMenu) {
 				mp3.playTrackFromDir(6, 1, false);
-				turnOff(ledPins);
+#ifdef LEDSTRINGS
+				lightOff(ledPins);
 				analogWrite(ledPins[2], 160);
+#endif
 #ifdef LS_INFO
 				Serial.print(F("--SWING SENSITIVITY--\nCurrent value :"));
 				Serial.print(storage.swingTreshold);
@@ -679,11 +925,13 @@
 #endif
 			}
 			break;
-		case 3:
+		case 6:
 			if (enterMenu) {
 				mp3.playTrackFromDir(7, 1, false);
-				turnOff(ledPins);
+#ifdef LEDSTRINGS
+				lightOff(ledPins);
 				analogWrite(ledPins[3], 160);
+#endif
 #ifdef LS_INFO
 				Serial.print(
 						F(
@@ -710,11 +958,13 @@
 #endif
 			}
 			break;
-		case 4:
+		case 7:
 			if (enterMenu) {
 				mp3.playTrackFromDir(8, 1, false);
-				turnOff(ledPins);
+#ifdef LEDSTRINGS
+				lightOff(ledPins);
 				analogWrite(ledPins[4], 160);
+#endif
 #ifdef LS_INFO
 				Serial.print(
 						F("--CLASH  BRAKE SENSITIVITY--\nCurrent value :"));
@@ -764,7 +1014,7 @@
 			changeMenu = false;
 			isBigAcceleration = false;

-			turnOff(ledPins);
+			lightOff(ledPins);
 			mp3.setSingleLoop(repeat);
 			ignition = false;
 			lastPlayed = 0;
@@ -775,19 +1025,19 @@
 			saveConfig();

 			//RESET CONFIG
-			/*
+/*
 			 for (int i = 0; i < EEPROMSizeATmega328; i++) {
 			 //			 if (EEPROM.read(i) != 0) {
 			 EEPROM.update(i, 0);
 			 //			 }
 			 }
-			 */
+*/
 			mp3.playTrackFromDir(3, 1);
 			browsing = false;
 			enterMenu = false;
 			lastPlayed = 0;
 			lockupLastPlayed = 0;
-			turnOff(ledPins);
+			lightOff(ledPins);
 			menu = 0;
 			configMode = false;
 			repeat = false;
@@ -985,7 +1235,7 @@
 				}
 			}
 		}
-	} else if (diff > debounceDelay + 300) {
+	} else if (diff > debounceDelay + 200) {
 		if (readingLockup == lockupButtonState) {
 			if (actionMode) {
 				//Triggers Lockup
@@ -1022,6 +1272,9 @@

 	if (actionMode) {
 		if (toPlay == 4) {
+#ifdef LUXEON
+			lightChangeColor(mainColor);
+#endif
 			lastPlayed = mp3.playTrackFromDir(4, soundFont.getFolder());
 			repeat = true;
 			changePlayMode = true;
@@ -1030,18 +1283,31 @@
 			swingSuppress = 0;

 		} else if (toPlay == 5) {
-			if (soundFont.getLockup()) {
+			//Lockup
+#ifdef LUXEON
+			lightChangeColor(clashColor);
+#endif
+	//		Serial.println(soundFont.getLockup());
+	//		if (soundFont.getLockup()) {
 				lastPlayed = mp3.playTrackFromDir(soundFont.getLockup(),
 						soundFont.getFolder());
-			}
+	//		}
 			lockupLastPlayed = lastPlayed;
 			repeat = true;
 			changePlayMode = true;
 		} else if (toPlay == 1) {
-			if (soundFont.getBlaster()) {
+			// Blaster
+#ifdef LEDSTRINGS
+			analogWrite(random(0, 5), 0); //momentary shut off one led segment
+#endif
+#ifdef LUXEON
+			lightChangeColor(clashColor);
+#endif
+		//	Serial.println(soundFont.getBlaster());
+		//	if (soundFont.getBlaster()) {
 				lastPlayed = mp3.playTrackFromDir(soundFont.getBlaster(),
 						soundFont.getFolder());
-			}
+		//	}
 			lockupLastPlayed = 0;
 			repeat = false;
 			changePlayMode = true;
@@ -1049,35 +1315,86 @@
 	}
 }

-void turnOn(int ledPins[]) {
+#ifdef LEDSTRINGS
+void lightOn(int ledPins[]) {
+
 // Light up the ledstrings
-	int i;
-	for (i = 0; i < 6; i++) {
+	for (int i = 0; i <= 5; i++) {
 		digitalWrite(ledPins[i], HIGH);
 		if (i < 5) {
 			delay(83);
 		}
 	}
-}				//turnOn
-
-void turnOff(int ledPins[]) {
-// Light up the ledstrings
-	int i;
-	for (i = 5; i >= 0; i--) {
+
+}				//lightOn
+
+void lightOff(int ledPins[]) {
+// Light off the ledstrings
+	for (int i = 5; i >= 0; i--) {
 		digitalWrite(ledPins[i], LOW);
 		if (i > 0) {
 			delay(83);
 		}
 	}
-}				//turnOff
-
-void flicker(int ledPins[], int value) {
-// Flicker the ledstrings
-	int i;
-	for (i = 5; i >= 0; i--) {
+}				//lightOff
+
+void lightFlicker(int ledPins[], int value) {
+// lightFlicker the ledstrings
+	for (int i = 5; i >= 0; i--) {
 		analogWrite(ledPins[i], value);
 	}
-} //flicker
+} //lightFlicker
+#endif
+
+#ifdef LUXEON
+void ledOff(int ledPins[]) {
+// Light off the leds
+	for (int i = 0; i <= 2; i++) {
+		digitalWrite(ledPins[i], LOW);
+	}
+} //ledOff
+
+void lightOn(int ledPins[]) {
+
+// Light up the leds
+	for (int fadeIn=6;fadeIn>0;fadeIn--) {
+		for (int i = 0; i <= 2; i++) {
+			analogWrite(ledPins[i], (MAX_BRIGHTNESS/fadeIn)*currentColor[i]/100);
+		}
+		delay(85);
+	}
+} //lightOn
+
+void lightOff(int ledPins[]) {
+// Light off the leds
+	// Fade out
+	for (int fadeOut=6;fadeOut>=1;fadeOut--) {
+		for (int i = 2; i >= 0; i--) {
+			analogWrite(ledPins[i], (MAX_BRIGHTNESS/fadeOut)*currentColor[i]/100);
+		}
+		delay(85);
+	}
+	// shut Off
+	for (int i = 0; i <= 2; i++) {
+		digitalWrite(ledPins[i], LOW);
+	}
+} //lightOff
+
+void lightFlicker(int ledPins[], int value) {
+// lightFlicker the leds
+	for (int i = 0; i <2; i++) {
+		analogWrite(ledPins[i], value*currentColor[i]/rgbFactor);
+	}
+} //lightFlicker
+
+void lightChangeColor(byte color[]) {
+// lightFlicker the leds
+	for (int i = 0; i < 2; i++) {
+		currentColor[i] = color[i];
+		analogWrite(ledPins[i], MAX_BRIGHTNESS*currentColor[i]/100);
+	}
+} //lightFlicker
+#endif

 #ifdef LS_MOTION_DEBUG
 void printQuaternion(Quaternion quaternion, long multiplier = 100000) {


Add GPRS_SMSread.ino example

Add GPRS_SMSread.ino example

Add GPRS_SMSread.ino example

--- examples/GPRS_SMSread/GPRS_SMSread.ino
+++ examples/GPRS_SMSread/GPRS_SMSread.ino
@@ -53,7 +53,7 @@
       Serial.println(phone);
       Serial.print("Datetime: ");
       Serial.println(datetime);
-      Serial.print("Recv Message: ");
+      Serial.print("Recieved Message: ");
       Serial.println(message);
    }
 }


Update send_Blink.ino

Update send_Blink.ino

Corrected some comments while reading through this

--- examples/send_Blink/send_Blink.ino
+++ examples/send_Blink/send_Blink.ino
@@ -27,9 +27,9 @@

 void loop()
 {   Serial.println("In loop");
-    // send data:  id = 0x00, standrad frame, data len = 8, stmp: data buf
+    // send data:  id = 0x00, standard frame, data len = 8, stmp: data buf
     CAN.sendMsgBuf(0x70,0, 8, stmp);
-    delay(1000);                       // send data per 100ms
+    delay(1000);                       // send data once per second
 }

 /*********************************************************************************************************


-Make wifi delay a taskdelay.

-Make wifi delay a taskdelay.

--- wifi.ino
+++ wifi.ino
@@ -26,7 +26,7 @@
     tft.invertDisplay( true );
     while ( !WiFi.smartConfigDone() )
     {
-      delay(500);
+      vTaskDelay( 500 / portTICK_PERIOD_MS );
       Serial.print(".");
     }
     Serial.println("");
@@ -50,7 +50,7 @@
   {
     Serial.print( "." );
     tft.print( "." );
-    delay( 500 );
+    vTaskDelay( 500 / portTICK_PERIOD_MS );
   }
   tft.println();
   Serial.println();
@@ -69,7 +69,7 @@
     Serial.println( WiFi.status() );
     tft.println( WiFi.status() );
     // restart the AP to try again
-    delay(5000);
+    vTaskDelay( 500 / portTICK_PERIOD_MS );
     ESP.restart();
   }
 }


Bugfix

Bugfix

Conflict met PORD.
=>opgelost

--- src/Arduino/voorbeeld_registers/voorbeeld_registers.ino
+++ src/Arduino/voorbeeld_registers/voorbeeld_registers.ino
@@ -9,7 +9,7 @@
 #define USEDPINS_PORTF 0xFF //b1111 1111
 #define USEDPINS_PORTL 0xC7 //b1100 0111
 #define USEDPINS_PORTG 0x03 //b0000 0011
-#define USEDPINS_PORTD 0x80 //b1000 0000
+#define USEDPINS_PORTD_ 0x80 //b1000 0000

 # define aantalSamples 6

@@ -187,7 +187,7 @@
   DDRF = ~USEDPINS_PORTF;
   DDRL = ~USEDPINS_PORTL;
   DDRG = ~USEDPINS_PORTG;
-  DDRD = ~USEDPINS_PORTD; // Deze moet eigenlijk niet omdat DDRD bij de uitgangen al werd juist gezet.
+  DDRD = ~USEDPINS_PORTD_; // Deze moet eigenlijk niet omdat DDRD bij de uitgangen al werd juist gezet.

 }

@@ -220,7 +220,6 @@
 //Deze functie gaat de poorten (registers) lezen en serieel terugsturen.
 //Nu in binair maar kan ook in HEX.
 void readStatusOutputPorts() {
-
   unsigned int partB = (PORTB & USEDPINS_PORTB) << 8;
   unsigned int partD = (PORTD & USEDPINS_PORTD) >> 2;
   unsigned int partE1 = (PORTE & 0x08) << 5;
@@ -245,12 +244,6 @@

 }

-void readStatusInputPorts() {
-
-  byte temp_PINF = ((PINF & 0x01) << 7) | ((PINF & 0x02) << 5) | ((PINF & 0x04) << 3) | ((PINF & 0x08) << 1) | ((PINF & 0x10) >> 1) | ((PINF & 0x20) >> 3) | ((PINF & 0x40) >> 5) | ((PINF & 0x80) >> 7);
-
-}
-
 void leesStatusIngangen() {
   float temp1 = micros();
   temp_INPUT_STATUS = 0x0000;


Revert "Update BucketWheelActuationDriver.ino"

This reverts commit 6c2a4322442f9c04e21fb090b9aece0a4601ba52.

--- BucketWheelActuationDriver/BucketWheelActuationDriver.ino
+++ BucketWheelActuationDriver/BucketWheelActuationDriver.ino
@@ -82,7 +82,6 @@
 //        128
 //        130
 //        131
-        //driveClockwise(int motorID, int speed, unsigned char command)
         driveClockwise(128, readValue, 1);
         driveClockwise(130, readValue, 1);
         driveClockwise(131, readValue, 1);
@@ -129,7 +128,6 @@

     //update and print position as we move
     currentSteps += dir;
-    //every 50,000 ms print new position
     if (i%500 == 0) printPosition();

     //wait for 100 ms
@@ -146,7 +144,6 @@
   if (Serial.available()) {
     char command = Serial.read();
     switch (command) {
-      //emergency stom if command == 's' or 'S'
       case 's':
         e_stop = true;
         break;


Demonstration for IoTaaP Cloud service

Demonstration for IoTaaP Cloud service


Unauthorized messages are now ignored

Unauthorized messages are now ignored

--- src/CAN/CAN_receive_v2/CAN_receive_v2.ino
+++ src/CAN/CAN_receive_v2/CAN_receive_v2.ino
@@ -79,13 +79,12 @@

         // Authenticate the message
         if (Authenticate())
+        {
           Serial.println("\tAuth Good");
+          TakeAction();     // only respond to authorized messages
+        }
         else
           Serial.println("\tFAILED AUTH");
-
-        // Once Authentication is finished, this will be moved
-        // inside the IF above. Acts based off the data sent
-        TakeAction();
     }
 }


revert afer commiting a non-working test

--- DelayAndSerial/DelayAndSerial.ino
+++ DelayAndSerial/DelayAndSerial.ino
@@ -38,7 +38,6 @@
   }
   Serial.println("Starting up!");

-  Serial.println(TEMPERATURES[2]);

 }


extend send

extend send

--- testing/arduino/servo-radar3-ros-v2.ino
+++ testing/arduino/servo-radar3-ros-v2.ino
@@ -17,9 +17,10 @@

 sensor_msgs::JointState jointMessage;
-ros::Publisher sinbot_odometry("sinbot_odometry", &jointMessage);
+ros::Publisher odometryPublisher("/odometry", &jointMessage);

 char jointFrameid[] = "/ultrasound/joint";
+char *jointNames[] = {"FRONT", "BACK"};

 // Ultrasonic Sensor
@@ -56,12 +57,21 @@
 {
     nh.initNode();
     nh.advertise(rangePublisher);
+    nh.advertise(odometryPublisher);

     rangeMessage.radiation_type = sensor_msgs::Range::ULTRASOUND;
     rangeMessage.field_of_view = 0.1;
     rangeMessage.min_range = 0.0;
     rangeMessage.max_range = maxDistance/100; // cm to meter

+
+    jointMessage.header.frame_id = jointFrameid;
+    jointMessage.name_length = 2;
+    //jointMessage.velocity_length = 2;
+    jointMessage.position_length = 2;
+    //jointMessage.effort_length = 2;
+
+    jointMessage.name = jointNames;

     // attach servo pin and set to initial direction
@@ -72,7 +82,7 @@

 long GetRange(int id)
 {
-    long range = 0
+    long range = 0;
     if(id == 1)
     {
         range = sonar1.ping_cm();
@@ -142,12 +152,18 @@
     if(servoPos == actualServoPos)
     {
         ServoMotor.write(GetNextServoAngle());
-        delay(5);
+        //delay(5);
     }

     SendDistanceToROS(1, rangeFront);
     SendDistanceToROS(2, rangeBack);

+    // TODO - extra function to send
+    float pos[2] = {servoPos, (servoPos+180%360)};
+    jointMessage.position = pos;
+    jointMessage.header.stamp = nh.now();
+    odometryPublisher.publish(&jointMessage);
+
     nh.spinOnce();
 }


Fix datalogging to log all data as of 10/19

--- boards/Datalogging/log_CAN/log_CAN.ino
+++ boards/Datalogging/log_CAN/log_CAN.ino
@@ -82,7 +82,7 @@

         /*  CAN Address to be displayed in the serial monitor*/
-        if (canId != 16) goto START_LOOP;
+//        if (canId != 16/) goto START_LOOP;

         for(int i = 0; i<len; i++)    // print the data
         {