Significant update of Arduino code:

Significant update of Arduino code:

- Added calibration code to calibrate the thresholds for the detectors by powering the lasers on and off and monitoring the photoresistors.
- Change the protocol to single byte for each change: "A"  - 'H" for laser interrupted, "a"-"h" for laser back on.

--- Arduino/LaserHarpMultiplex/LaserHarpMultiplex.ino
+++ Arduino/LaserHarpMultiplex/LaserHarpMultiplex.ino
@@ -1,5 +1,19 @@
 /*
-  Analog input, serial output
+  Laser Harp monitoring via Arduino.
+
+  Monitors the inputs of 8 photoresistors that detect lasers, multiplexed via
+  a 74HC5067 IC and read by the Arduino analog input.
+
+  Sends output via serial with the following format:
+    57600 baud, 8 data bits, 1 stop.
+
+    Sends "~" to start, indicating that data follows.
+    While monitoring, sends "~" character every second as a heartbeat.
+    Sends character "A" - "H" when laser beam is interrupted.
+    Sends character "a" - "h" when laser beam is restored.
+
+    Sends character "@" to indicate that debugging information is being output. After
+    "@" is received, all input should be ignored until a "~" is received.
  */

 // These constants won't change.  They're used to give names
@@ -11,10 +25,20 @@
 const int multiplexBit2Pin = 4;  // Pin that controls bit 0 of the multiplexer
 const int multiplexBit3Pin = 5;  // Pin that controls bit 0 of the multiplexer

-const int inputCount = 8;  // Number of inputs we are reading
+// Pin for status LED.
+const int ledPin = 9;
+
+// Pin for turning lasers on/off
+const int laserPin = 8;
+
+const int inputCount = 8;  // Number of inputs we are reading. Can be up to 16.

 // Thresholds for input on each pin. >= this value is ON, < this value is OFF.
-int thresholds[inputCount] = { 400, 400, 400, 400, 400, 400, 400, 400 };
+// These are set in the power-on calibration routine.
+int thresholds[inputCount];
+
+// Values during calibration.
+int calibrateMin[inputCount], calibrateMax[inputCount];

 // Current values for each pin (on or off).
 byte current[inputCount];
@@ -30,9 +54,6 @@
     delayMicroseconds(10);  // delay 10 microseconds to allow multiplexer to stabilize.
     return analogRead(analogInPin);
 }
-
-// Pin for status LED.
-const int ledPin = 9;

 // Type of LED modes.
 const byte LED_ON = 0; // on solid
@@ -101,6 +122,110 @@
   }
 }

+void setLasers(boolean on)
+{
+    digitalWrite(laserPin, on ? HIGH : LOW);
+}
+
+void gatherCalibrationData()
+{
+  long start = millis();
+
+  for (int i = 0; i < inputCount; ++i) {
+    calibrateMin[i] = 1023;
+    calibrateMax[i] = 0;
+  }
+
+  while (millis() - start < 1500) {
+    for (int i = 0; i < inputCount; ++i) {
+      int value = multiplexedAnalogRead(i);
+      if (value < calibrateMin[i])
+        calibrateMin[i] = value;
+      if (value > calibrateMax[i])
+        calibrateMax[i] = value;
+
+      delay(1);
+    }
+
+    updateLed();
+  }
+}
+
+// Display the range of calibration data that was read.
+void displayCalibrationData()
+{
+  for (int i = 0; i < inputCount; ++i) {
+    Serial.print(i);
+    Serial.print(": ");
+    Serial.print(calibrateMin[i]);
+    Serial.print(" to ");
+    Serial.print(calibrateMax[i]);
+    Serial.println();
+  }
+}
+
+// If the gap in reading between on and off is less than this gap, signal an error.
+const int minCalibrationGap = 60;
+
+// Calibrate the photoresistor thresholds. Turn the lasers ON, and read
+// the photoresistors, keeping the lowest values detected.
+// Turn the lasers OFF, read the photoresistors, keeping the highest values detected.
+// Put the threshold halfway between those values. If the gap between on and off is
+// less than "minCalibrationGap", indicate an error by blinking the status LED the
+// number of the laser that is in error.
+void calibrate()
+{
+  int minLasersOn[inputCount], maxLasersOff[inputCount];
+
+  // Blink LED slowly to indicate calibration going on.
+  setLedMode(LED_SLOW, 0);
+
+  Serial.println("@"); // Indicate that debugging output follows; do not interpret as data.
+  Serial.println("Calibrating light sensors...");
+
+  setLasers(true);
+  delay(400);  // let lasers get fully powered on.
+  gatherCalibrationData();
+  Serial.println("Lasers on:");
+  displayCalibrationData();
+  for (int i = 0; i < inputCount; ++i)
+    minLasersOn[i] = calibrateMin[i];
+
+  setLasers(false);
+  delay(400);  // let lasers get fully powered off.
+  gatherCalibrationData();
+  Serial.println("Lasers off:");
+  displayCalibrationData();
+  for (int i = 0; i < inputCount; ++i)
+    maxLasersOff[i] = calibrateMax[i];
+
+  setLasers(true);
+
+  Serial.println("Calibration complete; thresholds are:");
+  int error = -1; // Set to first laser we can't calibrate.
+  for (int i = 0; i < inputCount; ++i) {
+    thresholds[i] = (minLasersOn[i] + maxLasersOff[i]) / 2;
+    Serial.print(i);
+    Serial.print(": ");
+    Serial.print(thresholds[i]);
+
+    if (minLasersOn[i] - maxLasersOff[i] < minCalibrationGap) {
+      Serial.print("  CALIBRATION FAILED!");
+      if (error == -1)
+        error = i;
+    }
+    Serial.println();
+  }
+
+  // If we had a calibration error, blink the status LED to show laser with problem.
+  if (error >= 0)
+    setLedMode(LED_NUMBER, error + 1);
+  else
+    setLedMode(LED_ON, 0);
+
+  Serial.println("~");  // Transition back to output data.
+}
+
 void setup() {
   // initialize serial communications at 57600 bps:
   Serial.begin(57600);
@@ -111,12 +236,24 @@
   pinMode(multiplexBit2Pin, OUTPUT);
   pinMode(multiplexBit3Pin, OUTPUT);
   pinMode(ledPin, OUTPUT);
+  pinMode(laserPin, OUTPUT);

   setLedMode(LED_ON, 0);
-}
-
+  calibrate();
+  setLasers(true);
+}
+
+const long heartbeat = 1000;  // milliseconds between heartbeats.
 void loop() {
+    long lastTimeHeartbeat, currentTime;
+
     updateLed();
+
+    currentTime = millis();
+    if (currentTime - lastTimeHeartbeat > heartbeat) {
+      lastTimeHeartbeat = currentTime;
+      Serial.println('~');
+    }

     for (int i = 0; i < inputCount; ++i) {

@@ -128,16 +265,14 @@

         // If different than last value, send notification.
         if (newInput != current[i]) {
-            //Serial.print(i);
-            //Serial.print(newInput ? '+' : '-');
-            //Serial.println();
-            if (newInput){
-              Serial.print(i);
-            }
-        }
+            if (newInput)
+              Serial.print('a' + i); // HIGH means laser detected -> interruption OFF
+            else
+              Serial.print('A' + i); // LOW means laser not detected -> interruption ON
+         }
         current[i] = newInput;
     }

-    // wait 2 milliseconds before the next loop
-    delay(2);
-}
+    // wait 1 milliseconds before the next loop
+    delay(1);
+}


Add automatic range selection

Add automatic range selection

--- Arduino/MPU9150_MS5611_IMU/MPU9150_MS5611_IMU.ino
+++ Arduino/MPU9150_MS5611_IMU/MPU9150_MS5611_IMU.ino
@@ -106,7 +106,14 @@
 #define GYRO_X_OFFSET 0.0f
 #define GYRO_Y_OFFSET 0.0f
 #define GYRO_Z_OFFSET 0.0f
-
+#define GYRO_RANGE_DEGPS 250.0f
+#define ACCEL_RANGE_G 2.0f
+#define MAG_RANGE_mG 12290.0f// milliGauss (1229 microTesla per 2^12 bits, 10 mG per microTesla)
+/*
+#define MAG_X_OFFSET 123.0f
+#define MAG_Y_OFFSET -47.0f
+#define MAG_Z_OFFSET 119.0f
+*/
 // Declare device MPU6050 class
 MPU6050 mpu(0x69);

@@ -152,6 +159,11 @@

 const float sea_press = 1013.25;
 float press, temperature, altitude;
+
+short n_gyro_range = 0;
+short n_gyro_range_old = 0;
+short n_accel_range = 0;
+short n_accel_range_old = 0;

 void setup()
 {
@@ -234,6 +246,8 @@
     pushAvg(press);
     press = getAvg(movavg_buff, MOVAVG_SIZE);
     altitude = getAltitude(press, temperature);
+    automaticGyroRangeSelection();
+    automaticAccelRangeSelection();
     if(mpu.getIntDataReadyStatus() == 1) { // wait for data ready status register to update all data registers
             mcount++;
            // read the raw sensor data
@@ -242,9 +256,9 @@
             a1 = a1 + ACC_X_OFFSET;
             a2 = a2 + ACC_Y_OFFSET;
             a3 = a3 + ACC_Z_OFFSET;
-            ax_g = a1*2.0f/32768.0f; // 2 g full range for accelerometer
-            ay_g = a2*2.0f/32768.0f;
-            az_g = a3*2.0f/32768.0f;
+            ax_g = a1*ACCEL_RANGE_G*pow(2, n_accel_range)/pow(2, 15);
+            ay_g = a2*ACCEL_RANGE_G*pow(2, n_accel_range)/pow(2, 15);
+            az_g = a3*ACCEL_RANGE_G*pow(2, n_accel_range)/pow(2, 15);

             mpu.getRotation  ( &g1, &g2, &g3  );
             g1 = -g1;
@@ -252,9 +266,9 @@
             g1 = g1 + GYRO_X_OFFSET;
             g2 = g2 + GYRO_Y_OFFSET;
             g3 = g3 + GYRO_Z_OFFSET;
-            gx_degps = g1*250.0f/32768.0f; // 250 deg/s full range for gyroscope
-            gy_degps = g2*250.0f/32768.0f;
-            gz_degps = g3*250.0f/32768.0f;
+            gx_degps = g1*GYRO_RANGE_DEGPS*pow(2, n_gyro_range)/pow(2, 15);
+            gy_degps = g2*GYRO_RANGE_DEGPS*pow(2, n_gyro_range)/pow(2, 15);
+            gz_degps = g3*GYRO_RANGE_DEGPS*pow(2, n_gyro_range)/pow(2, 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.
@@ -270,9 +284,9 @@
             m1 = m1 + MAG_X_OFFSET;
             m2 = m2 + MAG_Y_OFFSET;
             m3 = m3 + MAG_Z_OFFSET;
-            mx = m1*10.0f*1229.0f/4096.0f; // milliGauss (1229 microTesla per 2^12 bits, 10 mG per microTesla)
-            my = m2*10.0f*1229.0f/4096.0f;
-            mz = m3*10.0f*1229.0f/4096.0f;
+            mx = m1*MAG_RANGE_mG/pow(2, 12);
+            my = m2*MAG_RANGE_mG/pow(2, 12);
+            mz = m3*MAG_RANGE_mG/pow(2, 12);
             mcount = 0;
             }
          }
@@ -323,13 +337,13 @@
       len = mavlink_msg_to_send_buffer(buf, &msg);
       Serial.write(buf, len);

-
+      /*
       //static inline uint16_t mavlink_msg_highres_imu_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg,
       //						       uint64_t time_usec, float xacc, float yacc, float zacc, float xgyro, float ygyro, float zgyro, float xmag, float ymag, float zmag, float abs_pressure, float diff_pressure, float pressure_alt, float temperature, uint16_t fields_updated)
       mavlink_msg_highres_imu_pack(system_id, component_id, &msg, (uint64_t)time_boot_us, ax_g*9.81, ay_g*9.81, az_g*9.81, gx_degps*PI/180.0f, gy_degps*PI/180.0f, gz_degps*PI/180.0f, my, mx, mz, press, press, altitude, temperature, a1);
       len = mavlink_msg_to_send_buffer(buf, &msg);
       Serial.write(buf, len);
-      /*
+
       //mavlink_msg_scaled_imu_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg,
       // uint32_t time_boot_ms, int16_t xacc, int16_t yacc, int16_t zacc, int16_t xgyro, int16_t ygyro, int16_t zgyro, int16_t xmag, int16_t ymag, int16_t zmag)
       mavlink_msg_raw_imu_pack(system_id, component_id, &msg, time_boot_ms, a1, a2, a3, g1, g2, g3, m1, m2, m3);
@@ -390,6 +404,62 @@
       count = millis();
     }
 }
+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;
+  }
+  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
+    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;
+  }
+
+  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);
+    n_accel_range_old = n_accel_range;
+  }
+}
+

 float getAltitude(float press, float temp) {
   //return (1.0f - pow(press/101325.0f, 0.190295f)) * 4433000.0f;


fix anto.pub

fix anto.pub

--- examples/Quick_start_anto_dht11/Quick_start_anto_dht11.ino
+++ examples/Quick_start_anto_dht11/Quick_start_anto_dht11.ino
@@ -69,15 +69,11 @@

    if(temp >= 0){
-      Antosend = String(temp);                     //แปลง temp เป็น string
-      Antosend.toCharArray(buf,Antosend.length()); //string ยัดใส่ buf
-      anto.pub("Temp",(const char*)buf);           //ใช้ buf ส่งค่าขึ้นไป
+      anto.pub("Temp",temp);           //ใช้ buf ส่งค่าขึ้นไป
    }

    if(humid >= 0){
-      Antosend = String(humid);
-      Antosend.toCharArray(buf,Antosend.length());
-      anto.pub("Humid",(const char*)buf);
+      anto.pub("Humid",humid);
    }

   delay(1000);


anavi-thermometer-thingspeak.ino: Add BH1750

Read data from I2C light sensor BH1750 and send it to
thingspeak.com. Improvements of the source code to make
it fail safe.

Signed-off-by: Leon Anavi <be92910ae7bb6f58bb9b7c6f845bc30640119592@anavi.org>

--- anavi-thermometer/anavi-thermometer-thingspeak/anavi-thermometer-thingspeak.ino
+++ anavi-thermometer/anavi-thermometer-thingspeak/anavi-thermometer-thingspeak.ino
@@ -40,10 +40,6 @@
 #define ONE_WIRE_BUS 12
 OneWire oneWire(ONE_WIRE_BUS);
 DallasTemperature sensors(&oneWire);
-
-// Configure pins
-const int pinAlarm = 16;
-const int pinButton = 0;

 // Configure the interval in milliseconds to read data
 // from the sensors and to publish it to thingspeak.com
@@ -60,31 +56,35 @@
 // specfic DHT22 unit on your board
 const float temperatureCoef = 1;

-float dhtTemperature = 0;
-float dhtHumidity = 0;
-float dsTemperature = 0;
+//Configure I2C sensor for light
+const int sensorBH1750 = 0x23;

 // For random generation of MQTT client ID
 static const char alphanum[] ="0123456789"
                               "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                               "abcdefghijklmnopqrstuvwxyz";

+String txtTemperature = "";
+String txtHumidity = "";
+String txtWater="";
+String txtLight = "";
+
 void drawDisplay(const char *line1, const char *line2 = "", const char *line3 = "")
 {
-    // Write on OLED display
-    // Clear the internal memory
-    u8g2.clearBuffer();
-    // Set appropriate font
-    u8g2.setFont(u8g2_font_ncenR14_tr);
-    u8g2.drawStr(0,14, line1);
-    u8g2.drawStr(0,39, line2);
-    u8g2.drawStr(0,64, line3);
-    // Transfer internal memory to the display
-    u8g2.sendBuffer();
-}
-
-void connectWiFi() {
-
+  // Write on OLED display
+  // Clear the internal memory
+  u8g2.clearBuffer();
+  // Set appropriate font
+  u8g2.setFont(u8g2_font_ncenR14_tr);
+  u8g2.drawStr(0,14, line1);
+  u8g2.drawStr(0,39, line2);
+  u8g2.drawStr(0,64, line3);
+  // Transfer internal memory to the display
+  u8g2.sendBuffer();
+}
+
+void connectWiFi()
+{
   delay(10);
   // We start by connecting to a WiFi network
   Serial.println();
@@ -137,31 +137,45 @@
   }
 }

-void setup()
-{
-    // put your setup code here, to run once:
-    Serial.begin(115200);
-    Serial.println();
-    u8g2.begin();
-    dht.begin();
-    sensors.begin();
-
-    delay(10);
-
-    //LED
-    pinMode(pinAlarm, OUTPUT);
-    //Button
-    pinMode(pinButton, INPUT);
-
-    drawDisplay("ANAVI Thermometer");
-
-    connectWiFi();
-    mqttClient.setServer(mqtt_server, 1883);
-}
-
-void mqttpublish(String temperature, String humidity, String water) {
+bool isSensorAvailable(int sensorAddress)
+{
+  // Check if I2C sensor is present
+  Wire.beginTransmission(sensorAddress);
+  return 0 == Wire.endTransmission();
+}
+
+void sensorWriteData(int i2cAddress, uint8_t data)
+{
+  Wire.beginTransmission(i2cAddress);
+  Wire.write(data);
+  Wire.endTransmission();
+}
+
+String readLight()
+{
+  // Power on sensor
+  sensorWriteData(sensorBH1750, 0x01);
+  // Set mode continuously high resolution mode
+  sensorWriteData(sensorBH1750, 0x10);
+
+  uint16_t tempAmbientLight;
+
+  Wire.requestFrom(sensorBH1750, 2);
+  tempAmbientLight = Wire.read();
+  tempAmbientLight <<= 8;
+  tempAmbientLight |= Wire.read();
+  // s. page 7 of datasheet for calculation
+  tempAmbientLight = tempAmbientLight/1.2;
+
+  char convert[80];
+  sprintf(convert, "%u", tempAmbientLight);
+  return String(convert);
+}
+
+void mqttpublish(String temperature, String humidity, String water, String light)
+{
   // Create data string to send to ThingSpeak
-  String data = String("field1=" + temperature + "&field2=" + humidity+ "&field3=" + water);
+  String data = String("field1=" + temperature + "&field2=" + humidity + "&field3=" + water + "&field4=" + light);
   int length = data.length();
   char msgBuffer[length];
   data.toCharArray(msgBuffer,length+1);
@@ -176,55 +190,81 @@
   mqttClient.publish(topicBuffer, msgBuffer);
 }

+void setup()
+{
+  // put your setup code here, to run once:
+  Serial.begin(115200);
+  Serial.println();
+  u8g2.begin();
+  dht.begin();
+  sensors.begin();
+
+  delay(10);
+
+  drawDisplay("ANAVI Thermometer");
+
+  connectWiFi();
+  mqttClient.setServer(mqtt_server, 1883);
+}
+
 void loop()
 {
-    // Reconnect if MQTT client is not connected.
-    if (!mqttClient.connected())
-    {
-      reconnect();
-    }
-
-    float humidity = dht.readHumidity();
-    float temp = dht.readTemperature();
-    if (isnan(humidity) || isnan(temp))
-    {
-      delay(sensorInterval);
-      return;
-    }
-
+  // Reconnect if MQTT client is not connected.
+  if (!mqttClient.connected())
+  {
+    reconnect();
+  }
+
+  float humidity = dht.readHumidity();
+  float temp = dht.readTemperature();
+  if (!isnan(humidity) && !isnan(temp))
+  {
     // Adjust temperature depending on the calibration coefficient
     temp = temp*temperatureCoef;
-    dhtTemperature = temp;
-    dhtHumidity = humidity;

-    String txtTemperature = String(dhtTemperature, 1);
-    String air="Air "+txtTemperature+"C ";
+    txtTemperature = String(temp, 1);
+    txtHumidity = String(humidity, 0);
+  }
+
+  String air = "";
+  if (0 < txtTemperature.length())
+  {
+    air="Air "+txtTemperature+"C ";
     Serial.println(air);
-    String txtHumidity = String(dhtHumidity, 0);
-    String hum="Humidity "+txtHumidity+"%";
+  }
+
+  String hum = "";
+  if (0 < txtHumidity.length())
+  {
+    hum="Humidity "+txtHumidity+"%";
     Serial.println(hum);
-
-    String txtWater="";
-    String water="";
-    if (0 < sensors.getDeviceCount())
+  }
+
+  String water="";
+  if (0 < sensors.getDeviceCount())
+  {
+    sensors.requestTemperatures();
+    txtWater = String(sensors.getTempCByIndex(0),1);
+    water="Water "+txtWater+"C";
+    Serial.println(water);
+  }
+  drawDisplay(air.c_str(), hum.c_str(), water.c_str());
+
+  // Publish data to thingspeak.com over MQTT
+  const unsigned long currentMillis = millis();
+  if (publishInterval <= (currentMillis - sensorPreviousMillis))
+  {
+    // Read light only if sensor is attached
+    if (isSensorAvailable(sensorBH1750))
     {
-        sensors.requestTemperatures();
-        float wtemp = sensors.getTempCByIndex(0);
-        dsTemperature = wtemp;
-        txtWater = String(dsTemperature,1);
-        water="Water "+String(dsTemperature,1)+"C";
-        Serial.println(water);
+        txtLight = readLight();
+        Serial.println("Light "+txtLight+" Lux");
     }
-    drawDisplay(air.c_str(), hum.c_str(), water.c_str());
-
-    // Publish data to thingspeak.com over MQTT
-    const unsigned long currentMillis = millis();
-    if (publishInterval <= (currentMillis - sensorPreviousMillis))
-    {
-        sensorPreviousMillis = currentMillis;
-        mqttpublish(txtTemperature, txtHumidity, txtWater);
-    }
-
-    // Read data from the sensor every 3 seconds
-    delay(sensorInterval);
-}
+
+    sensorPreviousMillis = currentMillis;
+    mqttpublish(txtTemperature, txtHumidity, txtWater, txtLight);
+  }
+
+  // Read data from the sensor every 3 seconds
+  delay(sensorInterval);
+}


Add SENSOR_TYPE. Also keep track of totalReadings so we know where the gaps are.

--- Arduino/libraries/UA_Sensors/examples/BridgeSensorGSM/BridgeSensorGSM.ino
+++ Arduino/libraries/UA_Sensors/examples/BridgeSensorGSM/BridgeSensorGSM.ino
@@ -3,13 +3,8 @@

   Sketch used by UA Sensors platform.

-  Notes:
-  - Sketch handles specific case with current test sensor
-    where SD Card does not write
-  - Need to test if this version works on test sensor
-
   Created 14 6 2014
-  Modified 1 7 2014
+  Modified 2 7 2014
 */

 #include <LowPower.h>
@@ -45,6 +40,7 @@

 // Settings
 // -------------------------------
+#define SENSOR_TYPE                "d"
 #define SEND_DATA_AFTER_X_READINGS 4
 #define SLEEP_CYCLES               4
 #define NUM_THERM_READINGS         5
@@ -70,6 +66,7 @@

 // Global Variables
 int numCachedReadings = 0;
+int totalReadings = 0;
 SensorReading sensorReadings[SEND_DATA_AFTER_X_READINGS];
 UASensors_Sim900 sim900;
 UASensors_RTC rtc(RTC_CS_PIN);
@@ -190,7 +187,11 @@

   // 13. Combine time, distance, and temperature into a single string.
   // -----------------------------------------------------------------
-  String dataString = String(unixTime) + " " + String(roundedDistance) + " " + String(roundedTemperature);
+  totalReadings += 1;
+  String dataString = String(totalReadings) + " " +
+    String(unixTime) + " " +
+    String(roundedDistance) + " " +
+    String(roundedTemperature);

   // Cache distance and time in global array variable
   sensorReadings[numCachedReadings].distance = roundedDistance;
@@ -217,7 +218,11 @@

     // 18. Prepare text message
     // ---------------------
-    String textMessage = String(sensorReadings[0].timestamp) + " " + String(sensorReadings[0].distance) + " " + String(sensorReadings[0].temperature);
+    String textMessage = String(SENSOR_TYPE) + " " +
+      String(sensorReadings[0].timestamp) + " " +
+      String(sensorReadings[0].distance) + " " +
+      String(sensorReadings[0].temperature);
+
     time_t startTime = sensorReadings[0].timestamp;
     int minutesElapsed = 0;

@@ -259,7 +264,6 @@
     // 20. Turn off GSM.
     // -----------------

-    // Turn off GSM power pin.
     if (sim900.ensureOffline() == false)
     {
       // TODO(richard-to): What would be best way to handle this issue?
@@ -270,5 +274,5 @@

   // Turn off GSM MOSFET.
   digitalWrite(MOSFET_GSM_PIN, LOW);
-  delay(1000);
+  delay(2000);
 }


fixing typo on baud rate

fixing typo on baud rate

--- chp08/uart/uartEchoC/BBBSerialEcho.ino
+++ chp08/uart/uartEchoC/BBBSerialEcho.ino
@@ -2,9 +2,9 @@

 // This function is called once when the program starts.
 void setup() {
-   // Choose a baud rate and configuration. 9600
+   // Choose a baud rate and configuration. 115200
    // Default is 8-bit with No parity and 1 stop bit
-   Serial.begin(9600, SERIAL_8N1);
+   Serial.begin(115200, SERIAL_8N1);
 }

 // This function will loop as quickly as possible, forever.


Experiment: smaller min/max

Experiment: smaller min/max

--- current-test-program/servo_via_timer.ino
+++ current-test-program/servo_via_timer.ino
@@ -3,7 +3,7 @@
 Servo servo1;

 int SERVO1_MIN = 1250;
-int SERVO1_MAX = 2000;
+int SERVO1_MAX = 1750;
 unsigned long SERVO1_DURATION_MS = 1200;
 unsigned long servo1_timestep_micros;
 unsigned long servo1_next_time_micros;


Fixed Servo Issue

Fixed Servo Issue

I first replace the malfunctioning servo but I also change some code in
the Arduino so that the servo would go to the desired height.

--- Testing_Arduino101_2/Testing_Arduino101_2.ino
+++ Testing_Arduino101_2/Testing_Arduino101_2.ino
@@ -108,7 +108,7 @@

 //------------------VARIABLESs----------------
 char input, trash_input;
-int servoH_top = 100, servoH_bottom = 85;
+int servoH_top = 170, servoH_bottom = 0;
 long last_time = 0;
 int control = 0;
 int stop_button = 10;
@@ -316,13 +316,6 @@
   Serial.print(ultrasonic2);
   Serial.print("&");
 }
-void silence_servo(){
-  servo_top();
-  delay(500);
-  servo_bottom();
-  delay(2000);
-  myservo.write(87);
-}

 void servo_info(){
   Serial.print(myservo.read());
@@ -364,7 +357,7 @@
         Serial.begin(9600);     // opens serial port, sets data rate to 9600 bps
         //Serial.println("Welcome to the Arduino Command HQ");
         myservo.attach(5);
-        myservo.write(87);
+        myservo.write(servoH_top);

         enableInterrupt(stop_button, stop_motor_ALL , CHANGE);

@@ -483,10 +476,6 @@
                 servo_change();
                 //Serial.print("Hello9");
               }
-            case 'e':
-              if(command_status == 1){
-                silence_servo();
-              }
             case 'R':
               command_status = 1;
               //Serial.print("Hello10");


Update RTC memory example

Update RTC memory example

--- libraries/esp8266/examples/RTCUserMemory/RTCUserMemory.ino
+++ libraries/esp8266/examples/RTCUserMemory/RTCUserMemory.ino
@@ -1,52 +1,106 @@
-// Example: Storing struct data in RTC user memory
+// Example: Storing struct data in RTC user rtcDataory
 //
-// Struct data with the maximum size of 512 bytes can be stored in the RTC user memory using the ESP-specifc APIs.
-// The stored data can be retained between deep sleep cycles. However, the data might be lost after power cycling the ESP8266.
+// Struct data with the maximum size of 512 bytes can be stored
+// in the RTC user rtcDataory using the ESP-specifc APIs.
+// The stored data can be retained between deep sleep cycles.
+// However, the data might be lost after power cycling the ESP8266.
+//
+// This example uses deep sleep mode, so connect GPIO16 and RST
+// pins before running it.
 //
 // Created Mar 30, 2016 by Macro Yau.
 //
 // This example code is in the public domain.

-typedef struct {
-  byte data[512];
-} rtcUserMemory;
+// CRC function used to ensure data validity
+uint32_t calculateCRC32(const uint8_t *data, size_t length);

-rtcUserMemory mem;
+// helper function to dump memory contents as hex
+void printMemory();

-void printMemory(bool readFromRtc) {
-  char buf[3];
-  Serial.print(readFromRtc ? "Read:  " : "Write: ");
-  for (int i = 0; i < sizeof(mem); i++) {
-    sprintf(buf, "%02X", mem.data[i]);
-    Serial.print(buf);
-    Serial.print(" ");
-  }
-  Serial.println();
-}
+// Structure which will be stored in RTC memory.
+// First field is CRC32, which is calculated based on the
+// rest of structure contents.
+// Any fields can go after CRC32.
+// We use byte array as an example.
+struct {
+  uint32_t crc32;
+  byte data[508];
+} rtcData;

 void setup() {
   Serial.begin(115200);
   Serial.println();
+  delay(1000);

-  // Read struct from RTC user memory
-  if (ESP.rtcUserMemoryRead((uint32_t*) &mem, sizeof(mem))) {
-    printMemory(true);
+  // Read struct from RTC memory
+  if (ESP.rtcUserMemoryRead(0, (uint32_t*) &rtcData, sizeof(rtcData))) {
+    Serial.println("Read: ");
+    printMemory();
+    Serial.println();
+    uint32_t crcOfData = calculateCRC32(((uint8_t*) &rtcData) + 4, sizeof(rtcData) - 4);
+    Serial.print("CRC32 of data: ");
+    Serial.println(crcOfData, HEX);
+    Serial.print("CRC32 read from RTC: ");
+    Serial.println(rtcData.crc32, HEX);
+    if (crcOfData != rtcData.crc32) {
+      Serial.println("CRC32 in RTC memory doesn't match CRC32 of data. Data is probably invalid!");
+    }
+    else {
+      Serial.println("CRC32 check ok, data is probably valid.");
+    }
   }

   // Generate new data set for the struct
-  for (int i = 0; i < sizeof(mem); i++) {
-    mem.data[i] = random(0, 128);
+  for (int i = 0; i < sizeof(rtcData); i++) {
+    rtcData.data[i] = random(0, 128);
+  }
+  // Update CRC32 of data
+  rtcData.crc32 = calculateCRC32(((uint8_t*) &rtcData) + 4, sizeof(rtcData) - 4);
+  // Write struct to RTC memory
+  if (ESP.rtcUserMemoryWrite(0, (uint32_t*) &rtcData, sizeof(rtcData))) {
+    Serial.println("Write: ");
+    printMemory();
+    Serial.println();
   }

-  // Write struct to RTC user memory
-  if (ESP.rtcUserMemoryWrite((uint32_t*) &mem, sizeof(mem))) {
-    printMemory(false);
-  }
-
-  // Enter deep sleep mode for 10 seconds
-  ESP.deepSleep(10e6);
+  Serial.println("Going into deep sleep for 5 seconds");
+  ESP.deepSleep(5e6);
 }

 void loop() {
-
 }
+
+uint32_t calculateCRC32(const uint8_t *data, size_t length)
+{
+  uint32_t crc = 0xffffffff;
+  while (length--) {
+    uint8_t c = *data++;
+    for (uint32_t i = 0x80; i > 0; i >>= 1) {
+      bool bit = crc & 0x80000000;
+      if (c & i) {
+        bit = !bit;
+      }
+      crc <<= 1;
+      if (bit) {
+        crc ^= 0x04c11db7;
+      }
+    }
+  }
+  return crc;
+}
+
+void printMemory() {
+  char buf[3];
+  for (int i = 0; i < sizeof(rtcData); i++) {
+    sprintf(buf, "%02X", rtcData.data[i]);
+    Serial.print(buf);
+    if ((i + 1) % 32 == 0) {
+      Serial.println();
+    }
+    else {
+      Serial.print(" ");
+    }
+  }
+  Serial.println();
+}


Move MIDI keys over to a global MIDI state

--- roto.ino
+++ roto.ino
@@ -82,6 +82,9 @@
 // initialization.
 uint8_t midiKeys[127] = {0};
 uint8_t midiControl[127] = {0};
+
+#define MANUAL_KEY_0 (35)
+#define MANUAL_KEY_61 (MANUAL_KEY_0 + 61)

 #define CC_DRAWBAR_1 (70)
 #define CC_DRAWBAR_2 (71)
@@ -97,7 +100,6 @@
 #define CC_PERCUSSION_SOFT (89)
 #define CC_PERCUSSION_THIRD (95) // is this correct?

-uint8_t keys[62] = {0};
 uint16_t volumes[92] = {0};
 uint16_t percVolumes[92] = {0};

@@ -233,15 +235,14 @@

     // MIDI notes always have the high bit unset, but just in case.
     if (note & 0x80) {
-        midiKeys[note & 0x7f] = vel;
-    }
-
-    int key = note2key(note);
-    if (key < 1 || key > 61) {
         return;
     }

-    keys[key] = 1;
+    midiKeys[note & 0x7f] = vel;
+    if (note <= MANUAL_KEY_0 || note > MANUAL_KEY_61) {
+        return;
+    }
+
     updateTonewheels();

     if (++numKeysDown == 1 && midiControl[CC_PERCUSSION]) {
@@ -256,8 +257,8 @@
     Serial.print(note);
     Serial.print("\n");

-    int key = note2key(note);
-    if (key < 1 || key > 61) {
+    midiKeys[note & 0x7f] = vel;
+    if (note <= MANUAL_KEY_0 || note > MANUAL_KEY_61) {
         return;
     }

@@ -265,7 +266,6 @@
         percussionEnv.noteOff();
     }

-    keys[key] = 0;
     updateTonewheels();
 }

@@ -336,10 +336,10 @@
         }
     }

-    manual_fill_volumes(keys, percBars, percVolumes);
+    manual_fill_volumes(&midiKeys[MANUAL_KEY_0], percBars, percVolumes);
     percussion.setVolumes(percVolumes);

-    manual_fill_volumes(keys, bars, volumes);
+    manual_fill_volumes(&midiKeys[MANUAL_KEY_0], bars, volumes);
     tonewheels.setVolumes(volumes);
 }

@@ -391,7 +391,7 @@
         Serial.print("keys[");
         Serial.print(i);
         Serial.print("] = ");
-        Serial.print(keys[i]);
+        Serial.print(midiKeys[MANUAL_KEY_0 + i]);
         Serial.print("\n");
     }
 }


Make init match standard init for example

--- examples/FirebaseTranscriber_ESP8266/FirebaseTranscriber_ESP8266.ino
+++ examples/FirebaseTranscriber_ESP8266/FirebaseTranscriber_ESP8266.ino
@@ -22,11 +22,11 @@

 // Set these to run example.
 #define FIREBASE_HOST ""
-#define FIREBASE_PATH "/fthing"
 #define FIREBASE_AUTH ""
 #define WIFI_SSID ""
 #define WIFI_PASSWORD ""

+#define FIREBASE_PATH "/fthing"
 #define DIGITAL_IN D1
 #define DIGITAL_OUT BUILTIN_LED
 #define ANALOG_IN A0


Change comments to english.

Change comments to english.

--- examples/ReadNUID/ReadNUID.ino
+++ examples/ReadNUID/ReadNUID.ino
@@ -1,102 +1,113 @@
 /*
-Kiara Navarro
-sophiekovalevsky arroba fedoraproject.org
-www.panamahitek.com
-*/
+ * --------------------------------------------------------------------------------------------------------------------
+ * Example sketch/program showing how to read new NUID from a PICC to serial.
+ * --------------------------------------------------------------------------------------------------------------------
+ * This is a MFRC522 library example; for further details and other examples see: https://github.com/miguelbalboa/rfid
+ *
+ * Example sketch/program showing how to the read data from a PICC (that is: a RFID Tag or Card) using a MFRC522 based RFID
+ * Reader on the Arduino SPI interface.
+ *
+ * When the Arduino and the MFRC522 module are connected (see the pin layout below), load this sketch into Arduino IDE
+ * then verify/compile and upload it. To see the output: use Tools, Serial Monitor of the IDE (hit Ctrl+Shft+M). When
+ * you present a PICC (that is: a RFID Tag or Card) at reading distance of the MFRC522 Reader/PCD, the serial output
+ * will show the type, and the NUID if a new card has been detected. Note: you may see "Timeout in communication" messages
+ * when removing the PICC from reading distance too early.
+ *
+ * @license Released into the public domain.
+ *
+ * Typical pin layout used:
+ * -----------------------------------------------------------------------------------------
+ *             MFRC522      Arduino       Arduino   Arduino    Arduino          Arduino
+ *             Reader/PCD   Uno           Mega      Nano v3    Leonardo/Micro   Pro Micro
+ * Signal      Pin          Pin           Pin       Pin        Pin              Pin
+ * -----------------------------------------------------------------------------------------
+ * RST/Reset   RST          9             5         D9         RESET/ICSP-5     RST
+ * SPI SS      SDA(SS)      10            53        D10        10               10
+ * SPI MOSI    MOSI         11 / ICSP-4   51        D11        ICSP-4           16
+ * SPI MISO    MISO         12 / ICSP-1   50        D12        ICSP-1           14
+ * SPI SCK     SCK          13 / ICSP-3   52        D13        ICSP-3           15
+ */

-/*
- Pinaje (MFRC522 hacia Arduino)
- MFRC522 pin SDA hacia el pin 10
- MFRC522 pin SCK hacia el pin 13
- MFRC522 pin MOSI hacia el pin 11
- MFRC522 pin MISO hacia el pin 12
- MFRC522 pin GND a tierra
- MFRC522 pin RST hacia el pin 9
- MFRC522 pin 3.3V A 3.3. V
-*/
-
-// Librerías necesarias
 #include <SPI.h>
 #include <MFRC522.h>

-#define SS_PIN 10 // pin SDA hacia el pin 10
-#define RST_PIN 9 // pin RST hacia el pin 9
+#define SS_PIN 10
+#define RST_PIN 9

-MFRC522 rfid(SS_PIN, RST_PIN); // Creo la instancia de la clase MFRC522
+MFRC522 rfid(SS_PIN, RST_PIN); // Instance of the class

-MFRC522::MIFARE_Key key; // Crea una estructura de tipo llave
+MFRC522::MIFARE_Key key;

-// Inicializo vector que almacenará el NUID del PICC
+// Init array that will store new NUID
 byte nuidPICC[3];

 void setup() {
-	Serial.begin(9600);
-	SPI.begin(); // Inicia el bus de SPI
-	rfid.PCD_Init(); // Inicia el lector
+    Serial.begin(9600);
+    SPI.begin(); // Init SPI bus
+    rfid.PCD_Init(); // Init MFRC522

-	// Carga los valores que vienen por defecto para las llaves A y B
-	for (byte i = 0; i < 6; i++) {
-	    key.keyByte[i] = 0xFF;
-	}
+    for (byte i = 0; i < 6; i++) {
+        key.keyByte[i] = 0xFF;
+    }

-	Serial.println(F("Este código escanea el número de identificación de una tarjeta MIFARE Classic."));
-	Serial.print(F("Utilizando la siguiente llave:"));
-	printHex(key.keyByte, MFRC522::MF_KEY_SIZE);
+    Serial.println(F("This code scan the MIFARE Classsic NUID."));
+    Serial.print(F("Using the following key:"));
+    printHex(key.keyByte, MFRC522::MF_KEY_SIZE);
 }

 void loop() {

-    // Buscando nuevas tarjetas
+    // Look for new cards
     if ( ! rfid.PICC_IsNewCardPresent())
         return;

-    // Verifica si el NUID ha sido leído
+    // Verify if the NUID has been readed
     if ( ! rfid.PICC_ReadCardSerial())
         return;

-    Serial.print(F("Tipo de PICC: "));
+    Serial.print(F("PICC type: "));
     byte piccType = rfid.PICC_GetType(rfid.uid.sak);
     Serial.println(rfid.PICC_GetTypeName(piccType));

-    // Verifica si la tarjeta es de tipo MIFARE Classic
+    // Check is the PICC of Classic MIFARE type
     if (piccType != MFRC522::PICC_TYPE_MIFARE_MINI &&
-    	piccType != MFRC522::PICC_TYPE_MIFARE_1K &&
-    	piccType != MFRC522::PICC_TYPE_MIFARE_4K) {
-        Serial.println(F("Tu tarjeta no es del tipo MIFARE Classic"));
+        piccType != MFRC522::PICC_TYPE_MIFARE_1K &&
+        piccType != MFRC522::PICC_TYPE_MIFARE_4K) {
+        Serial.println(F("Your tag is not of type MIFARE Classic."));
         return;
     }

     if (rfid.uid.uidByte[0] != nuidPICC[0] ||
-	    rfid.uid.uidByte[1] != nuidPICC[1] ||
-	    rfid.uid.uidByte[2] != nuidPICC[2] ||
-	    rfid.uid.uidByte[3] != nuidPICC[3] ) {
-		Serial.println(F("Se ha detectado nueva tarjeta"));
+        rfid.uid.uidByte[1] != nuidPICC[1] ||
+        rfid.uid.uidByte[2] != nuidPICC[2] ||
+        rfid.uid.uidByte[3] != nuidPICC[3] ) {
+        Serial.println(F("A new card has been detected."));

-		// Almacena el NUID en el arreglo nuidPICC
-		for (byte i = 0; i < 4; i++) {
-			nuidPICC[i] = rfid.uid.uidByte[i];
-		}
-
-	    Serial.println(F("Su número no único de identificación es:"));
-	    Serial.print(F("En hexadecimal: "));
-	    printHex(rfid.uid.uidByte, rfid.uid.size);
-	    Serial.println();
-	    Serial.print(F("En decimal: "));
-	    printDec(rfid.uid.uidByte, rfid.uid.size);
-	    Serial.println();
+        // Store NUID into nuidPICC array
+        for (byte i = 0; i < 4; i++) {
+            nuidPICC[i] = rfid.uid.uidByte[i];
+        }
+
+        Serial.println(F("The NUID tag is:"));
+        Serial.print(F("In hex: "));
+        printHex(rfid.uid.uidByte, rfid.uid.size);
+        Serial.println();
+        Serial.print(F("In dec: "));
+        printDec(rfid.uid.uidByte, rfid.uid.size);
+        Serial.println();
     }
-    else Serial.println("Tarjeta leída anteriormente, ingrese otra.");
+    else Serial.println("Card read previously.");

     // Halt PICC
     rfid.PICC_HaltA();

-    // Detiene el cifrado en el PCD
+    // Stop encryption on PCD
     rfid.PCD_StopCrypto1();
 }

 /**
- * Función que ayuda a representar valores hex en el monitor serial
+ * Helper routine to dump a byte array as hex values to Serial.
  */
 void printHex(byte *buffer, byte bufferSize) {
     for (byte i = 0; i < bufferSize; i++) {
@@ -106,7 +117,7 @@
 }

 /**
- * Función que ayuda a representar valores en dec en el monitor serial
+ * Helper routine to dump a byte array as dec values to Serial.
  */
 void printDec(byte *buffer, byte bufferSize) {
     for (byte i = 0; i < bufferSize; i++) {


Update arduino_md03_v_5_0.ino

Update arduino_md03_v_5_0.ino

Added a debug option to remove the LCD updates and speed up the main loop

--- arduino/arduino_md03_v_5_0/arduino_md03_v_5_0.ino
+++ arduino/arduino_md03_v_5_0/arduino_md03_v_5_0.ino
@@ -20,6 +20,7 @@
  LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
 */

+const int debug = 0;
 const int potPin1 = A0;
 const int potPin2 = A1;
 const int potPin3 = A2;
@@ -81,30 +82,27 @@
 String statusString = "";        // a string to hold the output

 void setup(){
-  /*
-  Wire.begin(); //start I2C bus
-  delay(100); //wait for bus to stabalise
-  */
+  if (debug == 1){
+     Wire.begin(); //start I2C bus
+     delay(100); //wait for bus to stabalise
+     lcd.begin (16,2); // 2 rows x 16 char
+     // Switch on the backlight
+     lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
+     lcd.setBacklight(HIGH);
+     lcd.clear();
+     lcd.setCursor(0,0);
+     lcd.print("ArcEyes MD03 I2C");
+     lcd.setCursor(0,1);
+     lcd.print("SandBox");
+     delay(30);
+     //lcd.clear();
+  }
   pinMode(rlyPin1,OUTPUT); // Setup pins
   pinMode(rlyPin2,OUTPUT); // Setup pins
   pinMode(rlyPin3,OUTPUT); // Setup pins
   pinMode(motorPinDir1,OUTPUT); // Setup pins
   pinMode(motorPinDir2,OUTPUT); // Setup pins
   pinMode(motorPinDir3,OUTPUT); // Setup pins
-
-  /*
-  lcd.begin (16,2); // 2 rows x 16 char
-  // Switch on the backlight
-  lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
-  lcd.setBacklight(HIGH);
-  lcd.clear();
-  lcd.setCursor(0,0);
-  lcd.print("ArcEyes MD03 I2C");
-  lcd.setCursor(0,1);
-  lcd.print("SandBox");
-  delay(30);
-  //lcd.clear();
-  */

   //serial
   Serial.begin(115200);
@@ -197,16 +195,17 @@
 }

 // Debug: Show current commands on lcd
-*/
 void lcd_command() {
-  lcd.clear();
-  lcd.setCursor(0,0);
-  lcd.print(
-          "Y"+String(cmd.yaw_pwm)+" "+String(cmd.yaw_direction)
-          +" L"+String(cmd.lid_pwm)+" "+String(cmd.lid_direction)
-          );
-}
-*/
+  if (debug == 1){
+     lcd.clear();
+     lcd.setCursor(0,0);
+     lcd.print(
+             "Y"+String(cmd.yaw_pwm)+" "+String(cmd.yaw_direction)
+             +" L"+String(cmd.lid_pwm)+" "+String(cmd.lid_direction)
+             );
+        }
+}
+

 // Send command to the motors
 void do_command() {
@@ -231,56 +230,13 @@
   Serial.println(statusString);
 }

-byte manualSpeedControl(int speedPin, byte potPin, int rlyPin, int dirPin, byte direct, int speedControl){
-    int potVal = analogRead(potPin);
-    if(potVal < 450){               //Sets reverse speed from Pot1
-      digitalWrite(rlyPin, LOW);
-      speedControl = map(potVal, 450, 0, 0, 250);
-      direct = LOW;
-    }
-    else if(potVal < 573){          // sets zero speed from Pot1
-      digitalWrite(rlyPin, HIGH);
-      speedControl = 0;
-    }
-    else if (potVal >= 574){        // sets forward speed from Pot1
-      digitalWrite(rlyPin, LOW);
-      speedControl = map(potVal, 574, 1023, 0, 250);
-      direct = HIGH;
-    }
-    analogWrite(speedPin, speedControl);
-    digitalWrite(dirPin, direct);
-
-    return direct;
-}
-/*
-byte getData(int address, byte reg){                   // function for getting data from MD03
-  Wire.beginTransmission(address);
-  Wire.write(reg);
-  Wire.endTransmission();
-
-  byte data = 0;
-  //for (int i; i<100; i++){
-    Wire.requestFrom(address, 1);         // Requests byte from MD03
-    while(Wire.available() < 1);          // Waits for byte to become availble
-    data = Wire.read();
-    //}
-
-  return(data);
-}
-
-void sendData(int address, byte reg, byte val){         // Function for sending data to MD03
-  Wire.beginTransmission(address);         // Send data to MD03
-    Wire.write(reg);
-    Wire.write(val);
-  Wire.endTransmission();
-}
-*/
 /*
   SerialEvent occurs whenever a new data comes in the
  hardware serial RX.  This routine is run between each
  time loop() runs, so using delay inside loop can delay
  response.  Multiple bytes of data may be available.
  */
+
 void serialEvent() {
   while (Serial.available()) {
     // get the new byte:
@@ -296,8 +252,9 @@
       stringComplete = true;
     }
   }
-  lcd.clear();
-  lcd.setCursor(0,0);
-  lcd.print(inputString);
-
-}
+  if (debug == 1){
+     lcd.clear();
+     lcd.setCursor(0,0);
+     lcd.print(inputString);
+  }
+}


added more space feature and added no-space character

--- beanWheelwriterControl/beanWheelwriterControl.ino
+++ beanWheelwriterControl/beanWheelwriterControl.ino
@@ -98,7 +98,8 @@
       // button for testing
       byte digital1 = digitalRead(d1);
       if (digital1 == 0) {
-        forwardSpaces(5);
+        paper_vert(1,100);
+        //forwardSpaces(5);
         //fastText("this is really fast");
         //send_letter(0b000000001); // 'a'
         //send_letter(0b001011001); // 'b'
@@ -160,11 +161,14 @@
         send_return(charCount);
         charCount = 0;
     }
-    else if (charToPrint == 0 or charToPrint == 1 or
-             charToPrint == 4 or charToPrint == 21) {
-              // paper-up/down micro-down/micro-up
-              // ctrl-d is 4, ctrl-u is 21
-        paper_vert(charToPrint);
+    else if (charToPrint == 0 or charToPrint == 1) {
+        paper_vert(charToPrint,8); // full line up/down
+    }
+    else if (charToPrint == 4) { // micro-down, ctrl-d is 4
+        paper_vert(1,1);
+    }
+    else if (charToPrint == 21) { // micro-up, ctrl-u is 21
+        paper_vert(0,1);
     }
     else if (charToPrint == 2 or charToPrint == 0x7f) {
         // left arrow or delete
@@ -177,7 +181,7 @@
         // DOES NOT UPDATE CHARCOUNT!
         // THIS WILL CAUSE PROBLEMS WITH RETURN!
         // TODO: FIX THIS ISSUE
-        micro_backspace();
+        micro_backspace(1);
     }
     else {
         send_letter(asciiTrans[charToPrint]);
@@ -408,6 +412,16 @@
     delay(LETTER_DELAY); // before next character
 }

+void letterNoSpace(int letter) {
+    sendByte(0b100100001);
+    sendByte(0b000001011);
+    sendByte(0b100100001);
+    sendByte(0b000000011);
+    sendByte(letter);
+    sendByte(0); // don't send any spaces
+    delay(LETTER_DELAY); // before next character
+}
+
 void paper_vert(int direction) {
   // 0 == up
   // 1 == down
@@ -432,6 +446,20 @@
   delay(LETTER_DELAY * 2); // give it a bit more time
 }

+void paper_vert(int direction, int microspaces) {
+    // 0 == up
+    // 1 == down
+    sendByte(0b100100001);
+    sendByte(0b000001011);
+    sendByte(0b100100001);
+    sendByte(0b000000101);
+    sendByte((direction << 7) | (microspaces << 1));
+
+    sendByte(0b100100001);
+    sendByte(0b000001011);
+    delay(LETTER_DELAY * microspaces/5);
+}
+
 void backspace_no_correct() {
     sendByte(0b100100001);
     sendByte(0b000001011);
@@ -524,7 +552,8 @@
     sendByte(0b010010000);
 }

-void micro_backspace() {
+void micro_backspace(int microspaces) {
+    // 5 microspaces is one space
     sendByte(0b100100001);
     sendByte(0b000001110);
     sendByte(0b011010000);
@@ -536,7 +565,8 @@
     sendByte(0b100100001);
     sendByte(0b000000110);
     sendByte(0b000000000);
-    sendByte(0b000000010);
+    sendByte(microspaces << 1);
+    //sendByte(0b000000010);
     /*
     sendByte(0b100100001);

@@ -546,7 +576,8 @@
     sendByteOnPin(0b000001011);*/
 }

-void forwardSpaces(int num_spaces) {
+void forwardSpaces(int num_microspaces) {
+    // five microspaces is one real space
     sendByte(0b100100001);
     sendByte(0b000001110);
     sendByte(0b010010110);
@@ -560,7 +591,7 @@

     sendByte(0b010000000);
     //sendByte(0b001111100);
-    sendByte(0b000000010);
+    sendByte(num_microspaces << 1);
 }

 void spin() {


Small fix to Arkanoid for Attiny85

Small fix to Arkanoid for Attiny85

--- examples/arkanoid/arkanoid.ino
+++ examples/arkanoid/arkanoid.ino
@@ -262,11 +262,11 @@
 #ifdef ARKANOID_SSD1331
     ssd1331_96x64_spi_init(3,4,5);
 #elif defined(__AVR_ATtiny85__)
-    ssd1306_i2cInit_Embedded(0,0,0);
+    ssd1306_i2cInit_Embedded(-1,-1,0);
 #elif defined(SSD1306_WIRE_SUPPORTED)
     ssd1306_i2cInit_Wire(0);
 #elif defined(SSD1306_I2C_SW_SUPPORTED)
-    ssd1306_i2cInit_Embedded(0,0,0);
+    ssd1306_i2cInit_Embedded(-1,-1,0);
 #else
     #error "Not supported microcontroller or board"
 #endif
@@ -814,4 +814,4 @@
   sbi(ADCSRA,ADEN);                    // switch Analog to Digitalconverter ON
   ssd1306_displayOn();
 }
-#endif+#endif


Example: SerialControlleSDWriter: improve comments

--- examples/02-Utility/SerialControlledSDWriter/SerialControlledSDWriter.ino
+++ examples/02-Utility/SerialControlledSDWriter/SerialControlledSDWriter.ino
@@ -118,9 +118,9 @@
   setConfiguration(INPUT_MICJACK); //this will also unmute the system

   //prepare the SD writer for the format that we want and any error statements
-  audioSDWriter.setSerial(&myTympan);
-  audioSDWriter.setWriteDataType(AudioSDWriter::WriteDataType::INT16);  //this is the built-in the default, but here you could change it to FLOAT32
-  audioSDWriter.setNumWriteChannels(2);             //this is also the defaullt, but you could set it to 2
+  audioSDWriter.setSerial(&myTympan);         //the library will print any error info to this serial stream (note that myTympan is also a serial stream)
+  audioSDWriter.setWriteDataType(AudioSDWriter::WriteDataType::INT16);  //this is the built-in default, but here you could change it to FLOAT32
+  audioSDWriter.setNumWriteChannels(2);       //this is also the built-in defaullt, but you could change it to 4 (maybe?), if you wanted 4 channels.

   //End of setup
   BOTH_SERIAL.println("Setup: complete."); serialManager.printHelp();


cleanups

cleanups

--- src/pirNet.ino
+++ src/pirNet.ino
@@ -2,7 +2,7 @@

 #include <ArduinoOTA.h>
 #include <ESP8266WiFi.h>       // 1 Must come before ESP8266WebServer.h
-#include <ESP8266mDNS.h>
+// #include <ESP8266mDNS.h>
 #include "./buildVersion.h"
 #include "./configMgr.h"
 #include "./displayMgr.h"


Código de arduino

Código de arduino

--- arduino/Alarma.ino
+++ arduino/Alarma.ino
@@ -1,247 +0,0 @@
-/**
-   Aplicación para controlar una alarma hogareña controlada por puerto serie a través de una PC
-   UTN Facultad Regional Resistencia - 2015
-
-   @autor Motter Pemela
-   @autor Silva Beker Eliana
-   @autor Silva Omar
-   @autor Tato Rothamel Rodrigo
-*/
-//Estado de la alarma
-boolean alarmaOn = false;
-//Alarma disparada
-boolean alarmTriggered = false;
-
-//Sensores
-boolean bedroom3Window = false;
-boolean bedroom2Window = false;
-boolean hallWindow1 = false;
-boolean hallWindow2 = false;
-boolean frontDoor = false;
-boolean bedroom4Window = false;
-boolean hallMovement = false;
-
-
-const int BEDROOM_3_LIGHT = 2;
-const int BEDROOM_2_LIGHT = 3;
-const int BEDROOM_4_LIGHT = 6;
-const int HALL_LIGHT = 4;
-const int BATHROOM_3_LIGHT = 5;
-const int STAIRS_LIGHT = 7;
-
-const int BEDROOM_3_WINDOW_SENSOR = 8;
-const int BEDROOM_2_WINDOW_SENSOR = 9;
-const int HALL_WINDOW_1_SENSOR = 10;
-const int HALL_WINDOW_2_SENSOR = 11;
-const int BEDROOM_4_WINDOW_SENSOR = 12;
-const int MAIN_DOOR_SENSOR = A0;
-const int ALARM_LED = 13;
-const int HALL_MOVEMENT_SENSOR = A1;
-const int ALARM_TRIGGERED_CODE_EVENT = 22;//Código de disparo de alarma
-
-// the setup function runs once when you press reset or power the board
-
-void setup() {
-  // initialize digital pin 13 as an output.
-  pinMode(ALARM_LED, OUTPUT);
-  //Lights
-  pinMode(BEDROOM_3_LIGHT, OUTPUT);
-  pinMode(BEDROOM_2_LIGHT, OUTPUT);
-  pinMode(BEDROOM_4_LIGHT, OUTPUT);
-  pinMode(HALL_LIGHT, OUTPUT);
-  pinMode(BATHROOM_3_LIGHT, OUTPUT);
-  pinMode(STAIRS_LIGHT, OUTPUT);
-  //Sensors
-  pinMode(BEDROOM_3_WINDOW_SENSOR, INPUT);
-  pinMode(BEDROOM_2_WINDOW_SENSOR, INPUT);
-  pinMode(HALL_WINDOW_1_SENSOR, INPUT);
-  pinMode(HALL_WINDOW_2_SENSOR, INPUT);
-  pinMode(BEDROOM_4_WINDOW_SENSOR, INPUT);
-  pinMode(MAIN_DOOR_SENSOR, INPUT);
-  pinMode(HALL_MOVEMENT_SENSOR, INPUT);
-
-
-  digitalWrite(ALARM_LED, LOW);
-
-  Serial.begin(9600);
-}
-
-// the loop function runs over and over again forever
-void loop() {
-
-  int command = Serial.read();
-
-  if (command != -1) {
-    switchLights(command);
-    switchAlarm(command);
-  }
-  checkSensors();
-
-  delay(100);
-
-  // wait for a second
-}
-
-void switchLights(int light) {
-  if ((light >= 2 && light <= 7) || (light >= 248 && light <= 254)) {
-    //Serial.println(light);
-    if (light > 248) {
-      digitalWrite(abs(light - 256), LOW);
-    } else {
-      digitalWrite(abs(light), HIGH);
-    }
-  }
-}
-
-
-void switchAlarm(int light) {
-  //Verificar que ningun sensor este activado para poder activar alarma
-
-  if (light == 13 || light == 243) {
-    //Serial.println(light);
-    if (light == 243) {
-      digitalWrite(abs(light - 256), LOW);
-      alarmaOn = false;
-
-    } else {
-      if (!hallMovement && bedroom3Window && bedroom2Window && hallWindow1 && hallWindow2 && frontDoor
-          && bedroom4Window) {
-        digitalWrite(abs(light), HIGH);
-        alarmaOn = true;
-      }
-    }
-    alarmTriggered = false;//Vuelvo el estado de activación de alarma a su estado normal
-  }
-}
-
-void checkSensors() {
-
-
-  if (digitalRead(BEDROOM_3_WINDOW_SENSOR) == HIGH) {
-    if (bedroom3Window) {
-      bedroom3Window = false;
-      //Write event to console
-      Serial.println(-BEDROOM_3_WINDOW_SENSOR);
-      if (alarmaOn) {
-        alarmTriggered = true;
-      }
-    } else {
-      bedroom3Window = true;
-      Serial.println(BEDROOM_3_WINDOW_SENSOR);
-    }
-  }
-
-  if (digitalRead(BEDROOM_2_WINDOW_SENSOR) == HIGH) {
-    if (bedroom2Window) {
-      bedroom2Window = false;
-      //Write event to console
-      Serial.println(-BEDROOM_2_WINDOW_SENSOR);
-      if (alarmaOn) {
-        alarmTriggered = true;
-      }
-    } else {
-      bedroom2Window = true;
-      Serial.println(BEDROOM_2_WINDOW_SENSOR);
-    }
-  }
-
-  if (digitalRead(HALL_WINDOW_1_SENSOR) == HIGH) {
-    if (hallWindow1) {
-      hallWindow1 = false;
-      //Write event to console
-      Serial.println(-HALL_WINDOW_1_SENSOR);
-      if (alarmaOn) {
-        alarmTriggered = true;
-      }
-    } else {
-      hallWindow1 = true;
-      Serial.println(HALL_WINDOW_1_SENSOR);
-    }
-  }
-
-  if (digitalRead(HALL_WINDOW_2_SENSOR) == HIGH) {
-    if (hallWindow2) {
-      hallWindow2 = false;
-      //Write event to console
-      Serial.println(-HALL_WINDOW_2_SENSOR);
-      if (alarmaOn) {
-        alarmTriggered = true;
-      }
-    } else {
-      hallWindow2 = true;
-      Serial.println(HALL_WINDOW_2_SENSOR);
-    }
-  }
-
-  if (digitalRead(BEDROOM_4_WINDOW_SENSOR) == HIGH) {
-    if (bedroom4Window) {
-      bedroom4Window = false;
-      //Write event to console
-      Serial.println(-BEDROOM_4_WINDOW_SENSOR);
-      if (alarmaOn) {
-        alarmTriggered = true;
-      }
-    } else {
-      bedroom4Window = true;
-      Serial.println(BEDROOM_4_WINDOW_SENSOR);
-    }
-  }
-
-  if (digitalRead(MAIN_DOOR_SENSOR) == HIGH) {
-    if (frontDoor) {
-      frontDoor = false;
-      //Write event to console
-      Serial.println(-MAIN_DOOR_SENSOR);
-      if (alarmaOn) {
-        alarmTriggered = true;
-      }
-    } else {
-      frontDoor = true;
-      Serial.println(MAIN_DOOR_SENSOR);
-    }
-  }
-
-  //Valor menor al 10% del maximo de la entrada del potenciometro
-  //En este caso la lógica se invierte y se pasa como negativo para cuando
-  //no hay movimiento
-  if (analogRead(HALL_MOVEMENT_SENSOR) < 67) {
-    //Se detectan movimientos
-    if (!hallMovement) {
-      Serial.println(-HALL_MOVEMENT_SENSOR);
-      hallMovement = true;
-      if (alarmaOn) {
-        alarmTriggered = true;
-      }
-    }
-  } else {
-    //Ya no hay movimientos
-    if (hallMovement) {
-
-      Serial.println(HALL_MOVEMENT_SENSOR);
-      hallMovement = false;
-
-    }
-  }
-  if (alarmTriggered) {
-    Serial.println(ALARM_TRIGGERED_CODE_EVENT);
-    alarmTriggered = false;
-    alarm();
-  }
-}
-
-void alarm() {
-  long time = 0;
-  while (time < 120) {
-    for (int i = 2 ; i <= 7; i++) {
-      switchLights(i);
-    }
-    delay(250);
-    for (int j = 248 ; j <= 254; j++) {
-      switchLights(j);
-    }
-    delay(250);
-    time++;
-  }
-
-}
-


Color definition

Color definition

--- arduino/sketch.ino
+++ arduino/sketch.ino
@@ -10,6 +10,7 @@
 int counterColor[] = {20, 36, 214};
 int deadColor[] = {171, 3, 142};
 int bombColor[] = {20, 36, 214};
+int currentColor[] = {0, 0, 0};

 void setup() {
 	initSerial();
@@ -48,4 +49,9 @@
   analogWrite(REDPIN, color[0]);
   analogWrite(GREENPIN, color[1]);
   analogWrite(BLUEPIN, color[2]);
+  currentColor[] = {color[0], color[1], color[2]};
+}
+
+void fadeTo(int color[]) {
+
 }


update

update

--- src/Firmware.ino
+++ src/Firmware.ino
@@ -122,8 +122,8 @@
                 {
                     targetDuringTime = (long)(50000 / getCommand('f'));
                 }
-                double x = hasCommand('x') ? getCommand('x') : 0;
-                double y = hasCommand('y') ? getCommand('y') : 0;
+                double x = hasCommand('x') ? round(getCommand('x')*100.0)/100.0 : 0;
+                double y = hasCommand('y') ? round(getCommand('y')*100.0)/100.0 : 0;
                 if (isRelative)
                 {
                     move(x * pulsePerMM, y * pulsePerMM, cmd);


indoor bmp180 no longer reports as outdoor

--- arduino/Sketches/indoor_environment/indoor_environment.ino
+++ arduino/Sketches/indoor_environment/indoor_environment.ino
@@ -146,7 +146,8 @@
     dtostrf(altitudeInMeters, 1, 2, altitudeInMetersBuffer);

     sprintf(parameters,
-        "{\"sensorName\": \"outside-deck\", \"degreesCelcius\": %s, \"hectoPascals\": %s, \"altitudeInMeters\": %s}",
+        "{\"sensorName\": \"%s\", \"degreesCelcius\": %s, \"hectoPascals\": %s, \"altitudeInMeters\": %s}",
+        arduinoName,
         degreesCelciusBuffer,
         hectoPascalsBuffer,
         altitudeInMetersBuffer);


Removed unused libraries.

Removed unused libraries.

--- aquacontrol32.ino
+++ aquacontrol32.ino
@@ -10,8 +10,6 @@
 #include <AsyncTCP.h>              /* https://github.com/me-no-dev/ESPAsyncTCP */
 #include <ESPAsyncWebServer.h>     /* https://github.com/me-no-dev/ESPAsyncWebServer */
 #include <XPT2046_Touchscreen.h>   /* https://github.com/PaulStoffregen/XPT2046_Touchscreen */
-#include <HTTPClient.h>
-#include <ArduinoJson.h>

 #include "gitTagVersion.h"
 #include "deviceSetup.h"


update sample.

update sample.

--- firmware/examples/coaptest.ino
+++ firmware/examples/coaptest.ino
@@ -1,4 +1,4 @@
-#include "coap.h"
+#include "coap/coap.h"

 // CoAP server endpoint url callback
 void callback_light(CoapPacket &packet, IPAddress ip, int port);


feedback from H3+B support code

feedback from H3+B support code

--- f_ATmegaTimer.ino
+++ f_ATmegaTimer.ino
@@ -54,14 +54,15 @@
   noInterrupts();
   // Note: ATmega2560's fast PWM is buggy.
   //   1. fast PWM mode 15 doesn't work unless TOP < 256.
-  //   2. the first match is ignored under certain conditions (see *, **, and ***).
+  //   2. the first compare match interrupt call is bogus (see *).
+  //   3. the first match is ignored under certain conditions (see ** and ***).

   // Timer 5 (VSYNC)
   // COM5B[1:0] = 2 : clear OC5B on compare match, set OC5B at BOTTOM
   // COM5C[1:0] = 0 : OC5C pin disconnected
   // WGM5[3:0] = 14 : fast PWM mode 14
   TCCR5B = _BV(WGM53) | _BV(WGM52); // set no clock source
-  TCCR5A = _BV(COM5B1) | _BV(WGM51);
+  TCCR5A = _BV(WGM51); // disconnect OC5B pin (PORTL & _BV(4) is HIGH)
   // the following registers can be set properly only after WGMn is set
   OCR5B = vsync - 2; // MATCH
   OCR5C = vsync - 3; // ADVANCE MATCH
@@ -69,13 +70,14 @@
   ICR5 = vsync - 1; // TOP
   TCCR5B |= _BV(CS52) | _BV(CS51); // CS5[2:0] = 6 (external clock source on T5. clock on falling edge)

-  // * using an external clock source ATmega2560 has a bug that causes the first match ignored
+  // ** using an external clock source ATmega2560 has a bug that causes the first match ignored
   // WORKAROUND: toggle T5 to go beyond the first
   for (int i = 0; i < vsync; i++) {
     TCCR4C |= _BV(FOC4C); TCCR4C |= _BV(FOC4C);
   }
+  TCCR5A |= _BV(COM5B1); // connect OC5B pin (the internal OC5B register is HIGH)

-  // ** the first compare match interrupt call is bogus.
+  // * the first compare match interrupt call is bogus.
   firstcall = true;

   if (stretch != 0) {
@@ -112,7 +114,7 @@
   TIMSK5 = 0; // disable timer 5 interrupts
   TCCR5B = 0;
   TCCR5A = _BV(COM5B0); // toggle on compare match
-  DDRL |= _BV(4); // set OC5B to output
+  PORTL |= _BV(4); DDRL |= _BV(4); // set OC5B to output
   noInterrupts();
   if (!(PINL & _BV(4))) { // toggle if LOW
     TCCR5C |= _BV(FOC5B);


Fix ring example

Fix ring example

--- examples/Ring/Ring.ino
+++ examples/Ring/Ring.ino
@@ -16,13 +16,13 @@
 struct RingPixels : public VerticalStrand {
   RingPixels() : VerticalStrand(NUM_LEDS) {}

-  void doSetColor(int i, uint8_t red, uint8_t green, uint8_t blue, uint8_t /*alpha*/) final {
-    strip.setPixelColor(i, red, green, blue);
+  void doSetColor(int i, RgbaColor color) final {
+    strip.setPixelColor(i, color.red, color.green, color.blue);
   };
 } pixels;

 Esp8266Network network(ssid, pass);
-NetworkPlayer player(network);
+NetworkPlayer player(pixels, network);

 void setup()
 {
@@ -41,9 +41,6 @@
   pinMode(STATUS_PIN, OUTPUT);
   pinMode(RING_PIN, OUTPUT);
   pinMode(BUTTON_PIN, INPUT);
-
-  delay(2000);
-  player.begin(pixels);
 }

 void loop()


modified Advertising examples

modified Advertising examples

--- examples/Advertising/Advertising.ino
+++ examples/Advertising/Advertising.ino
@@ -24,20 +24,28 @@

   if(faboBLE.setAdvParameters()){
     Serial.println("Success:setAdvParams()");
-    if(faboBLE.setMode()){
-      Serial.println("Success:setMode()");
       byte uuid[16] = {0xcb,0x86,0xbc,0x31,0x05,0xbd,0x40,0xcc,0x90,0x3d,0x1c,0x9b,0xd1,0x3d,0x96,0x6b};
       byte major[2] = {0x00,0x71};
       byte minor[2] = {0x00,0x71};
       faboBLE.setBeaconUuid(uuid);
       faboBLE.setBeaconMajor(major);
       faboBLE.setBeaconMinor(minor);
-    } else {
-      Serial.println("Failed:setMode()");
+
+    if(faboBLE.sendBeacon()){
+      Serial.println("Success:sendBeacon()");
+    } else{
+      Serial.println("Failed:sendBeacon");
     }
   } else {
     Serial.println("Failed:setAdvParams()");
   }
+
+  if(faboBLE.setMode()){
+    Serial.println("Success:Start Beacon advertising");
+  } else {
+    Serial.println("Failed:Start Beacon advertising");
+  }
+
 }

 void loop()
@@ -48,8 +56,8 @@
   // ボタン押下判定
   if (buttonState == HIGH && isFirst == false) {
       isFirst == true;
-      if(!faboBLE.isAdvertising()){
-        if(faboBLE.sendBeacon()){
+      if(!faboBLE.isAdvertising()){
+        if(faboBLE.setMode()){
           Serial.println("Success:Start Beacon advertising");
         } else {
           Serial.println("Failed:Start Beacon advertising");


fix for ATtiny84

fix for ATtiny84

--- examples/Ports/tiny50hz/tiny50hz.ino
+++ examples/Ports/tiny50hz/tiny50hz.ino
@@ -35,6 +35,7 @@
 }

 static void setupAdc () {
+#if TEST_CODE
   // 1.1V int ref, C2/B4 + C3/B3 diff, 20x
   ADMUX = bit(REFS1) | bit(MUX2) | bit(MUX1) | bit(MUX0);
   // disable these pins for digital I/O
@@ -43,6 +44,16 @@
   ADCSRB = bit(BIN);
   // clock/8 i.e. 128 KHz
   ADCSRA = bit(ADEN) | bit(ADPS1) | bit(ADPS0);
+#else
+  // 1.1V int ref, PA1(+) and PA0(-) diff, 20x
+  ADMUX = bit(REFS1) | bit(MUX5) | bit(MUX3) | bit(MUX0);
+  // disable these pins for digital I/O
+  DIDR0 |= bit(ADC1D) | bit(ADC0D);
+  // bipolar
+  ADCSRB = bit(BIN);
+  // clock/8 i.e. 128 KHz
+  ADCSRA = bit(ADEN) | bit(ADPS1) | bit(ADPS0);
+#endif
 }

 static int readAdc () {


Update Voltmeter.ino

Update Voltmeter.ino

Added parantes, code not validated as it looks here yet.

--- laddstation/sub-module/Voltmeter.ino
+++ laddstation/sub-module/Voltmeter.ino
@@ -20,6 +20,7 @@

  // check to see what the value of the A0 input is and store it in the int(heltal) variable analogvalue
  // batteryVoltage är ett flyttal som visar decimaler. Formel : batteryVoltage = A0 * 2 / 112
+ {
     analogvalue = analogRead(A0);
     temp = analogvalue*2;
     batteryVoltage = temp/112;


Remove unused variable

Remove unused variable

--- src/Arduino/_23cm-trx/smeter.ino
+++ src/Arduino/_23cm-trx/smeter.ino
@@ -4,10 +4,6 @@
  */
 unsigned long nextMeterUpdate = 0;
 const unsigned long meterUpdateMillis = 50;
-
-// 10 characters plus a null character
-// so we can use it as a proper string.
-#define meterdisplaysize 10

 int currentMeter = 0;


rover: do not activate arm/tilt on boot

rover: do not activate arm/tilt on boot

This is not as convenient as I thought it will be,
and servos (unlike motors) behave well without attaching,
i.e. are released and not moving.

--- bb/bb.ino
+++ bb/bb.ino
@@ -101,12 +101,9 @@
   // not: READY(EnvironmentSensor);
   // (do not make it ready until the first measurement)

-  attachTilt(true);
-  attachArm(true);
-
   MODULE_READY(LightSensor);

-  //play(PinSpeaker, melody_HappyBirthday, sizeof(melody_HappyBirthday) >> 2);
+  play(PinSpeaker, melody_HappyBirthday, sizeof(melody_HappyBirthday) >> 2);
 }

 void loop() {


Added code to re-update LED strip after power is switched back on - strip loses its state when power is cut

--- ucontroller/ucontroller.ino
+++ ucontroller/ucontroller.ino
@@ -198,6 +198,10 @@
  */
  void updatePower() {
   digitalWrite(POWER_PIN, powerOn);
+  if(powerOn) {
+    delay(50);
+    updateLeds();
+  }
  }

 /**


extract pre-increment. same code, anyway

--- GeheimTuer.ino
+++ GeheimTuer.ino
@@ -1,9 +1,8 @@
 #include <WS2812.h>

-// LED stripe length
-#define MAXPIX 20
-// animation buffer, read window moves back and forth EXTRAPIX pixels
-#define EXTRAPIX 3
+// MAXPIX+EXTRAPIX must fit into uint8_t
+#define MAXPIX 20  // LED stripe length
+#define EXTRAPIX 3 // animation buffer, read window moves back and forth EXTRAPIX pixels

 // WS2812 output
 const int ledPin = 11;
@@ -465,9 +464,10 @@
         // switch to next profile step
         if (driveMillis >= accelProfile[accelProfileIdx].maxMillis) {
           driveMillis = 0;
+          accelProfileIdx++;

           // end-stop not reached at end of profile, someone might be in the way
-          if (accelProfile[++accelProfileIdx].maxMillis == 0) {
+          if (accelProfile[accelProfileIdx].maxMillis == 0) {
             motorFree();
             debug(currentMillis, F("End of profile - door blocked\r\n"));
             debug(currentMillis, F("Total ms: "));
@@ -639,9 +639,6 @@
   // similiar to what digitalRead() does, assumes that swPin has no timer output assigned
   // this still leads to several indirect lookups per sample. direct PINx access might be faster
   debounce(portInputRegister(digitalPinToPort(swPin)), digitalPinToBitMask(swPin), swVal, swDebounce);
-/*
-  *swDebounce = ((*swDebounce << 1) | digitalRead(swPin)) & 0x1FFF; // 13-bit debounce
-*/
 }

 //__attribute__((always_inline))


cosmetics: use debug(), free motor before Serial.print, typo

--- GeheimTuer.ino
+++ GeheimTuer.ino
@@ -360,7 +360,9 @@
     case 'F':
         swFront = HIGH; break;
     case 'm':
-        Serial.println(currentMillis); break;
+        debug(currentMillis, F("Door status: "));
+        Serial.println(doorState);
+        break;
     case 'h':
       motorDisable();
       doorState = doorError;
@@ -395,8 +397,8 @@
     case doorOpen:
       // hold the door open if button pressed during openInterval
       if (swTrigger == LOW) {
+        motorFree();
         debug(currentMillis, F("Button switch triggered - door blocked\r\n"));
-        motorFree();
         setLeds1(red, ledSolid);
         doorState = doorBlocked;
         swTrigger = HIGH;
@@ -691,7 +693,7 @@
 }

 void motorEnable() {
-  // return control to pull-ups on the driver2 board
+  // return control to pull-ups on the driver board
   pinMode(motorDiagAPin, INPUT);
   pinMode(motorDiagBPin, INPUT);
   Serial.print(F("Motor driver enabled\r\n"));