[Minor] Updated code

[Minor] Updated code

--- arduino/ble_ph_sensor.ino
+++ arduino/ble_ph_sensor.ino
@@ -1,4 +1,5 @@
 #include "string.h"
+#include "LowPower.h"

 #define TRUE  1
 #define FALSE 0
@@ -9,6 +10,7 @@

 #define DEF_NOTIF_INTERVAL    20000
 #define MAX_NOTIF_ACTIVE_TIME 360000
+#define CATCH_QUERY_DURATION  2000

 #define MATCHED 0

@@ -22,8 +24,12 @@
 char  _aRecvBuf[20] = {};
 int   _iRecvIdx = 0;
 int   _bLiveNotif = FALSE;
+int   _bFirstActivate = TRUE;
 long  _lLastNotif = 0;
 long  _lNotifStartTime = 0;
+
+
+long  _lStartTime = 0;
 eState_t _eState = UNKNOWN;

 int utl_match(const char* s1, const char* s2, int iLen);
@@ -43,14 +49,28 @@
   Serial.begin(115200);

   pinMode(DEPLOY_STATUS_PIN, OUTPUT);
-  digitalWrite(DEPLOY_STATUS_PIN, HIGH);
-
+  digitalWrite(DEPLOY_STATUS_PIN, LOW);
+
+  pinMode(13, OUTPUT);
+
+  _lStartTime = millis();
   sys_setState(INACTIVE);
   //sys_setState(IDLE);
   return;
 }

 void loop() {
+  if (_bFirstActivate) {
+    digitalWrite(DEPLOY_STATUS_PIN, HIGH);
+    delay(50);
+    digitalWrite(DEPLOY_STATUS_PIN, LOW);
+    delay(50);
+    digitalWrite(DEPLOY_STATUS_PIN, HIGH);
+    delay(50);
+    digitalWrite(DEPLOY_STATUS_PIN, LOW);
+    _bFirstActivate = FALSE;
+  }
+
   _iRecvIdx = 0;
   memset(_aRecvBuf, 0, sizeof(_aRecvBuf));

@@ -75,11 +95,20 @@
   }

   delay(90);
+  if((_lStartTime + CATCH_QUERY_DURATION) < millis()){
+    digitalWrite(DEPLOY_STATUS_PIN, HIGH);
+    delay(500);
+    digitalWrite(DEPLOY_STATUS_PIN, LOW);
+    _bFirstActivate = TRUE;
+    LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
+    _lStartTime = millis();
+  }
   return;
 }

 int com_recv(char* aBuf) {
   if (Serial.available() > 0) {
+    _lStartTime = millis();
     char c = 1;
     while (c >= 0) {
       c = Serial.read();
@@ -96,31 +125,34 @@
   return STATUS_OK;
 }

+int dat_respSensor() {
+    char aBaseStr[32];
+    char aValStr[10];
+
+    memset(aBaseStr, 0, sizeof(aBaseStr));
+    memset(aValStr, 0, sizeof(aValStr));
+
+//    float dVal = 14.0 * (random(20, 80) / 100.0);
+
+    int iAdcVal = analogRead(PH_SENSOR_PIN);
+    float dVoltage = (iAdcVal * 5.0) / 1024;
+    float dVal = dVoltage;
+    //float dVal = dVoltage * 2.2570 + 2.6675;
+
+    dtostrf(dVal, 5, 2, aValStr);
+
+    strcpy(aBaseStr, " RDATA:pH=");
+    strcat(aBaseStr, aValStr);
+    strcat(aBaseStr, ";");
+
+    Serial.println(aBaseStr);
+}
+
 int dat_liveNotif() {
   /* If the current time since our last notif is greater than
     DEF_NOTIF_INTERVAL, then send out a reading */
   if ( (_lLastNotif + DEF_NOTIF_INTERVAL) < millis() ) {
-    char aBaseStr[32];
-    char aValStr[10];
-
-    memset(aBaseStr, 0, sizeof(aBaseStr));
-    memset(aValStr, 0, sizeof(aValStr));
-
-//    float dVal = 14.0 * (random(20, 80) / 100.0);
-
-    int iAdcVal = analogRead(PH_SENSOR_PIN);
-    float dVoltage = (iAdcVal * 5.0) / 1024;
-    float dVal = dVoltage;
-    //float dVal = dVoltage * 2.2570 + 2.6675;
-
-    dtostrf(dVal, 5, 2, aValStr);
-
-    strcpy(aBaseStr, " RDATA:pH=");
-    strcat(aBaseStr, aValStr);
-    strcat(aBaseStr, ";");
-
-    Serial.println(aBaseStr);
-
+    dat_respSensor();
     _lLastNotif = millis();
   }

@@ -175,9 +207,11 @@
 int req_read(char* pMsg, int iLen) {
   dat_resetLiveNotif();
   sys_setState(BUSY);
-  Serial.println(" RREAD:OK;");
-  delay(250);
-  Serial.println(" RDSTA:OK;");
+  //Serial.println(" RREAD:OK;");
+  delay(100);
+  dat_respSensor();
+  //Serial.println(" RDSTA:OK;");
+  sys_setState(IDLE);

   return STATUS_OK;
 }
@@ -199,7 +233,7 @@

 int req_deploy(char* pMsg, int iLen) {
   if (sys_getState() == INACTIVE) {
-    digitalWrite(DEPLOY_STATUS_PIN, LOW);
+//    digitalWrite(DEPLOY_STATUS_PIN, LOW);
     sys_setState(IDLE);
     Serial.println(" RDEPL:OK;");
   } else {
@@ -216,7 +250,7 @@
       /* Stop any ongoing read sessions when we undeploy */
       req_stop(pMsg, iLen);

-      digitalWrite(DEPLOY_STATUS_PIN, HIGH);
+//      digitalWrite(DEPLOY_STATUS_PIN, HIGH);
       sys_setState(INACTIVE);
       Serial.println(" RUNDP:OK;");
     } else {


Dropping the accelerometer values

Dropping the accelerometer values

--- arduino/brobot/brobot.ino
+++ arduino/brobot/brobot.ino
@@ -47,9 +47,9 @@
     currentTick = millis();
     minValue = analogRead(accel);

-    // If the minValue is > 400 (512 is roughly 0 g),
+    // If the minValue is > 350 (512 is roughly 0 g),
     // return immediately as nothing interesting is happening
-    if (minValue > 400)
+    if (minValue > 350)
     {
         return 0;
     }
@@ -62,23 +62,23 @@
     minValue = sampleAccel(minValue, endTick);

     // Now map minValue to a strength value between 1 and 5 and return that
-    if (minValue <= 100)
+    if (minValue <= 0)
     {
         return 5;
     }
-    else if (minValue <= 150)
+    else if (minValue <= 50)
     {
         return 4;
     }
-    else if (minValue <= 250)
+    else if (minValue <= 150)
     {
         return 3;
     }
-    else if (minValue <= 350)
+    else if (minValue <= 250)
     {
         return 2;
     }
-    else //if (minValue <= 400)
+    else //if (minValue <= 350)
     {
         return 1;
     }


Change some formatting

Change some formatting

--- mouse_rat.ino
+++ mouse_rat.ino
@@ -25,6 +25,8 @@
       outMin   =  200,
       outMax   = -200;

+int calibrationCounter = 0;
+
 float xRange[] = {0,0};
 float yRange[] = {0,0};

@@ -38,20 +40,20 @@

 // Configures the gain and integration time for the TSL2561
 void configureSensor(void) {
-  // 1.) Set the accelerometer range
+  // Set the accelerometer range
   //lsm.setupAccel(lsm.LSM9DS0_ACCELRANGE_2G);
   lsm.setupAccel(lsm.LSM9DS0_ACCELRANGE_4G);
   //lsm.setupAccel(lsm.LSM9DS0_ACCELRANGE_6G);
   //lsm.setupAccel(lsm.LSM9DS0_ACCELRANGE_8G);
   //lsm.setupAccel(lsm.LSM9DS0_ACCELRANGE_16G);

-  // 2.) Set the magnetometer sensitivity
+  // Set the magnetometer sensitivity
   lsm.setupMag(lsm.LSM9DS0_MAGGAIN_2GAUSS);
   //lsm.setupMag(lsm.LSM9DS0_MAGGAIN_4GAUSS);
   //lsm.setupMag(lsm.LSM9DS0_MAGGAIN_8GAUSS);
   //lsm.setupMag(lsm.LSM9DS0_MAGGAIN_12GAUSS);

-  // 3.) Setup the gyroscope
+  // Setup the gyroscope
   lsm.setupGyro(lsm.LSM9DS0_GYROSCALE_245DPS);
   //lsm.setupGyro(lsm.LSM9DS0_GYROSCALE_500DPS);
   //lsm.setupGyro(lsm.LSM9DS0_GYROSCALE_2000DPS);
@@ -75,17 +77,12 @@
 void mpr_setup() {
   // needed to keep leonardo/micro from starting too fast!
   while (!Serial);
-
-  Serial.begin(9600);
-  Serial.println("Adafruit MPR121 Capacitive Touch sensor test");
+  Serial.begin(9600);    Serial.println("Adafruit MPR121 Capacitive Touch sensor test");

   // Default address is 0x5A, if tied to 3.3V its 0x5B
   // If tied to SDA its 0x5C and if SCL then 0x5D
-  if (!cap.begin(0x5A)) {
-    Serial.println("MPR121 not found, check wiring?");
-    while (1);
-  }
-  Serial.println("MPR121 found!");
+  if (!cap.begin(0x5A))  Serial.println("MPR121 not found");
+  else                   Serial.println("MPR121 found!");
 }

@@ -111,17 +108,22 @@
   float accelX = clamp(accel.acceleration.x, accelMin, accelMax);
   float accelY = clamp(accel.acceleration.y, accelMin, accelMax);

-  if (accel.acceleration.x > xRange[1] || accel.acceleration.x < xRange[0]) {
-    my = map(accelX, accelMin, accelMax, outMax, outMin);
-    mx = map(accelY, accelMin, accelMax, outMax, outMin);
+  if (calibrationCounter > 5) {
+
+    if (accel.acceleration.x < xRange[0] || accel.acceleration.x > xRange[1]) {
+      mx = map(accelY - yNormal, accelMin, accelMax, outMax, outMin);
+    }
+
+    if (accel.acceleration.y < yRange[0] || accel.acceleration.y > yRange[1]) {
+      my = map(accelX - xNormal, accelMin, accelMax, outMax, outMin);
+    }
+
+    Mouse.move(mx, my, 0);
+  else {
+    calibrationCounter++;
+    calibrate(accelX, accelY);
   }
-  else if (accel.acceleration.y > yRange[1] || accel.acceleration.y < yRange[0]) {
-    my = map(accelX, accelMin, accelMax, outMax, outMin);
-    mx = map(accelY, accelMin, accelMax, outMax, outMin);
-  }
-
-  Mouse.move(mx, my, 0);
-  delay(5);
+  delay(7);
 }

@@ -145,6 +147,21 @@
 }

+void calibrate(float x, float y) {
+  xRange[0] = min(xRange[0], x);
+  xRange[1] = max(xRange[1], x);
+
+  yRange[0] = min(yRange[0], y);
+  yRange[1] = max(yRange[1], y);
+
+  xNormal = (xRange[0] + xRange[1])/2;
+  yNormal = (yRange[0] + yRange[1])/2;
+
+  Serial.print(xRange[0]); Serial.print(", "); Serial.println(xRange[1]);
+  Serial.print(yRange[0]); Serial.print(", "); Serial.println(yRange[1]);
+}
+
+
 void touchHandler(int id) {
   Serial.print(id); Serial.println(" touched");

@@ -179,21 +196,6 @@
 }

-void calibrate(float x, float y) {
-   xRange[0] = min(xRange[0], x);
-   xRange[1] = max(xRange[1], x);
-
-   yRange[0] = min(yRange[0], y);
-   yRange[1] = max(yRange[1], y);
-
-   xNormal = (xRange[0] + xRange[1])/2;
-   yNormal = (yRange[0] + yRange[1])/2;
-
-   Serial.print(xRange[0]); Serial.print(", "); Serial.println(xRange[1]);
-   Serial.print(yRange[0]); Serial.print(", "); Serial.println(yRange[1]);
-}
-
-
 float clamp(float value, float min_, float max_) {
   return (value < min_) ? min_ : (value > max_) ? max_ : value;
 }
@@ -201,7 +203,6 @@

 void displaySensorDetails(void) {
   sensor_t accel, mag, gyro, temp;
-
   lsm.getSensor(&accel, &mag, &gyro, &temp);

   Serial.println(F("------------------------------------"));
@@ -214,35 +215,5 @@
   Serial.println(F("------------------------------------"));
   Serial.println(F(""));

-  Serial.println(F("------------------------------------"));
-  Serial.print  (F("Sensor:       ")); Serial.println(mag.name);
-  Serial.print  (F("Driver Ver:   ")); Serial.println(mag.version);
-  Serial.print  (F("Unique ID:    ")); Serial.println(mag.sensor_id);
-  Serial.print  (F("Max Value:    ")); Serial.print(mag.max_value); Serial.println(F(" uT"));
-  Serial.print  (F("Min Value:    ")); Serial.print(mag.min_value); Serial.println(F(" uT"));
-  Serial.print  (F("Resolution:   ")); Serial.print(mag.resolution); Serial.println(F(" uT"));
-  Serial.println(F("------------------------------------"));
-  Serial.println(F(""));
-
-  Serial.println(F("------------------------------------"));
-  Serial.print  (F("Sensor:       ")); Serial.println(gyro.name);
-  Serial.print  (F("Driver Ver:   ")); Serial.println(gyro.version);
-  Serial.print  (F("Unique ID:    ")); Serial.println(gyro.sensor_id);
-  Serial.print  (F("Max Value:    ")); Serial.print(gyro.max_value); Serial.println(F(" rad/s"));
-  Serial.print  (F("Min Value:    ")); Serial.print(gyro.min_value); Serial.println(F(" rad/s"));
-  Serial.print  (F("Resolution:   ")); Serial.print(gyro.resolution); Serial.println(F(" rad/s"));
-  Serial.println(F("------------------------------------"));
-  Serial.println(F(""));
-
-  Serial.println(F("------------------------------------"));
-  Serial.print  (F("Sensor:       ")); Serial.println(temp.name);
-  Serial.print  (F("Driver Ver:   ")); Serial.println(temp.version);
-  Serial.print  (F("Unique ID:    ")); Serial.println(temp.sensor_id);
-  Serial.print  (F("Max Value:    ")); Serial.print(temp.max_value); Serial.println(F(" C"));
-  Serial.print  (F("Min Value:    ")); Serial.print(temp.min_value); Serial.println(F(" C"));
-  Serial.print  (F("Resolution:   ")); Serial.print(temp.resolution); Serial.println(F(" C"));
-  Serial.println(F("------------------------------------"));
-  Serial.println(F(""));
-
   delay(500);
 }


Re-added pinMode()

Re-added pinMode()

--- src/du.ino
+++ src/du.ino
@@ -88,7 +88,7 @@
   if (debug) Serial.println("dw");
   int p = getPin(pin);
   if(p == -1) { if(debug) Serial.println("badpin"); return; }
-  //pinMode(p, OUTPUT);
+  pinMode(p, OUTPUT);
   if (atoi(val) == 0) {
     digitalWrite(p, LOW);
   } else {
@@ -103,7 +103,7 @@
   if (debug) Serial.println("dr");
   int p = getPin(pin);
   if(p == -1) { if(debug) Serial.println("badpin"); return; }
-  //pinMode(p, INPUT);
+  pinMode(p, INPUT);
   int oraw = digitalRead(p);
   char m[7];
   sprintf(m, "%02d::%02d", p,oraw);
@@ -117,7 +117,7 @@
   if(debug) Serial.println("ar");
   int p = getPin(pin);
   if(p == -1) { if(debug) Serial.println("badpin"); return; }
-  //pinMode(p, INPUT); // don't want to sw
+  pinMode(p, INPUT); // don't want to sw
   int rval = analogRead(p);
   char m[8];
   sprintf(m, "%s::%03d", pin, rval);
@@ -127,6 +127,7 @@
 void aw(char *pin, char *val) {
   if(debug) Serial.println("aw");
   int p = getPin(pin);
+  pinMode(p, OUTPUT);
   if(p == -1) { if(debug) Serial.println("badpin"); return; }
   analogWrite(p,atoi(val));
 }


avoid map() call

avoid map() call


trying to start the arduino test-example

--- rs232testduino/rs232testduino.ino
+++ rs232testduino/rs232testduino.ino
@@ -4,12 +4,22 @@
   Serial.begin(baudr);

   // Testing kfx::RS232::WriteByte
+  byte a = Serial.ReadByte();
+
+  // Testing kfx::RS232::ReadBuf
+  Serial.print("Caracte recibido: ");

   // Testing kfx::RS232::ReadByte
+  Serial.print(a);
+

   // Testing kfx::RS232::WriteBuf
+  char A[80];
+  A = Serial.readBytes();
+  Serial.print("");

-  // Testing kfx::RS232::ReadBuf
+
+
 }

 void loop() { }


Working flasher, thread always running

Working flasher, thread always running

--- bolt-arduino.ino
+++ bolt-arduino.ino
@@ -1,3 +1,6 @@
+#include <Thread.h>
+#include <ThreadController.h>
+
 //CONSTANTS
 const uint8_t P_LED_VCC = 5;
 const uint8_t P_LED_DATA = 8;
@@ -10,6 +13,7 @@
 //0 is always default value
 const uint8_t LED_STATE_OFF = 0;
 const uint8_t LED_STATE_ON = 1;
+const uint8_t LED_STATE_FLASHING = 2;

 const uint8_t NUMBER_OF_BITS = 16;

@@ -17,6 +21,10 @@

 //Array keeping track of states
 uint8_t states[NUMBER_OF_BITS];
+
+Thread flasherThread;
+
+bool currentlyFlashing = true;

 void setup() {
   Serial.begin(115200);
@@ -27,15 +35,24 @@
   pinMode(P_LED_CLOCK, OUTPUT);
   pinMode(P_LED_LATCH, OUTPUT);

-  states[1] = LED_STATE_ON;
+  states[1] = LED_STATE_FLASHING;
   states[4] = LED_STATE_ON;
   states[5] = LED_STATE_ON;
   states[8] = LED_STATE_ON;
   states[10] = LED_STATE_ON;
   shiftOut();
+
+  //Thread setup
+  flasherThread = Thread();
+  flasherThread.setInterval(1000);
+  flasherThread.onRun(threadCallback);
 }

-void loop() {}
+void loop() {
+  if (flasherThread.shouldRun()) {
+    flasherThread.run();
+  }
+}

 void shiftOut() {
   //Latch Low. VCC high
@@ -52,6 +69,14 @@
       case LED_STATE_ON:
         digitalWrite(P_LED_DATA, HIGH);
         break;
+      case LED_STATE_FLASHING:
+        if (currentlyFlashing) {
+          digitalWrite(P_LED_DATA, HIGH);
+        } else {
+          digitalWrite(P_LED_DATA, LOW);
+        }
+        currentlyFlashing = !currentlyFlashing;
+        break;
     }

@@ -67,3 +92,8 @@
   analogWrite(P_LED_VCC, LED_VCC_PWM);
 }

+void threadCallback() {
+
+  shiftOut();
+}
+


Make the drift adjustment faster.  Increase the tape threshold again.

--- linefollow/linefollow.ino
+++ linefollow/linefollow.ino
@@ -14,7 +14,7 @@
 #define SPEED_ADJUSTMENT 20

 // These thresholds are manually configured.
-#define TAPE_THRESHOLD  175 // below this value, we are looking at the tape
+#define TAPE_THRESHOLD  200 // below this value, we are looking at the tape

 RedBotMotors motors;
 int leftSpeed;   // variable used to store the leftMotor speed
@@ -72,11 +72,11 @@
   {
     inRecovery = true;
     if(driftingLeft) {
-      leftSpeed = SPEED;
+      leftSpeed = SPEED + 20;
       rightSpeed = MIN_SPEED;
     }
     else if(driftingRight) {
-      rightSpeed = SPEED;
+      rightSpeed = SPEED + 20;
       leftSpeed = MIN_SPEED;
     }
     else {


I2C works actually

I2C works actually


percentage shift varies

percentage shift varies

--- vibrate_alarm_clock.ino
+++ vibrate_alarm_clock.ino
@@ -125,8 +125,12 @@
   int batteryRange = MAX_BATTERY_MILLIVOLT - MIN_BATTERY_MILLIVOLT;

   int batteryPercent = 100 * (((float)(batteryMilliVolt - MIN_BATTERY_MILLIVOLT)) / batteryRange);
-
-  display.setCursor(104,40);
+
+  if(batteryPercent < 100){
+     display.setCursor(110,40);
+  } else {
+     display.setCursor(104,40);
+  }
   display.print(batteryPercent);
   display.print("%");


transmit channel and callsign in manual mode and on a channel with a low signal

--- src/rx5808-pro-diversity/rx5808-pro-diversity.ino
+++ src/rx5808-pro-diversity/rx5808-pro-diversity.ino
@@ -240,6 +240,10 @@
     // rodate the display output 180 degrees.
     // drawScreen.flip(); // OLED only!

+#ifdef USE_IR_EMITTER
+    // Used to Transmit IR Payloads
+    Serial.begin(9600);
+#endif
 }

 // LOOP ----------------------------------------------------------------------------
@@ -566,9 +570,19 @@
     /*****************************************/
     if(state == STATE_MANUAL || state == STATE_SEEK)
     {
+        // read rssi
+        wait_rssi_ready();
+        rssi = readRSSI();
+        rssi_best = (rssi > rssi_best) ? rssi : rssi_best;
+
         channel=channel_from_index(channelIndex); // get 0...40 index depending of current channel
         if(state == STATE_MANUAL) // MANUAL MODE
         {
+#ifdef USE_IR_EMITTER
+            if(millis() % 1000 == 0 && rssi < 20) { // send channel info every second until rssi is locked.
+                sendIRPayload();
+            }
+#endif
             // handling of keys
             if( digitalRead(buttonUp) == LOW)        // channel UP
             {
@@ -602,11 +616,6 @@
             }

         }
-        // show signal strength
-        wait_rssi_ready();
-        rssi = readRSSI();
-        rssi_best = (rssi > rssi_best) ? rssi : rssi_best;
-

         // handling for seek mode after screen and RSSI has been fully processed
         if(state == STATE_SEEK) //


a hacky way of achieving this

a hacky way of achieving this

--- client/client.ino
+++ client/client.ino
@@ -2,7 +2,7 @@
 #include <IRremote.h>
 #include <string.h>

-// #define DEBUG
+#define DEBUG
 #include "utils.h"

 // Trying to elucidate the way communication works first
@@ -239,8 +239,11 @@

       if (atoi(p.id) == atoi(deviceId) && p.type[0] == 'i') {
         // all sorts of instructions
+        char cmd[4+1];
+        string_copy(cmd, p.data, 0, 3);
+        cmd[4] = '\0';
         DEBUG_PRINTLN("[CONNECTED] command issued");
-        if (strcmp(p.data, "0001") == 0) {
+        if (strcmp(cmd, "0001") == 0) {
           digitalToggle(controlledPin);
           Serial.print("p");
         }
@@ -248,11 +251,11 @@
           digitalWrite(controlledPin, LOW);
           Serial.print("p");
         }
-        else if (strcmp(p.data, "v_up") == 0) {
+        else if (strcmp(cmd, "v_up") == 0) {
           // digitalWrite(controlledPin, LOW);
           Serial.print("u");
         }
-        else if (strcmp(p.data, "v_dn") == 0) {
+        else if (strcmp(cmd, "v_dn") == 0) {
           // digitalWrite(controlledPin, LOW);
           Serial.print("d");
         }


update smart home device ID

update smart home device ID

--- client/client.ino
+++ client/client.ino
@@ -57,9 +57,9 @@
 #define statusPending 1
 #define statusOn 2

-const char deviceTV[3] = "11";
-const char deviceMusic[3] = "12";
-const char deviceLamp[3] = "13";
+const char deviceTV[3] = "12";
+const char deviceMusic[3] = "13";
+const char deviceLamp[3] = "11";
 const char deviceFan[3] = "14";

 boolean statePending = false;


Update thread name

Update thread name

--- src/drivefw/drivefw.ino
+++ src/drivefw/drivefw.ino
@@ -14,7 +14,7 @@
 const char* COMMAND_NAMES[] = {"IDLE","FORWARD","REVERSE","INVALID","LEFT","INVALID","INVALID","INVALID","RIGHT"};
 const char* CONTENT_TYPES[] = {"PLATFORM"};

-void* send(void* params);
+void* post(void* params);

 int gMagnitude = 0;
 bool gLights = false;
@@ -36,11 +36,11 @@
     gKeepGoing = true;
     char* delimiter = strchr(platform_name, ':');
     printf("%s Wifi RC Interface\n", delimiter+1);
-    pthread_create(&gSendThread, NULL, send, platform_name);
+    pthread_create(&gSendThread, NULL, post, platform_name);

 }

-void* send(void* params)
+void* post(void* params)
 {
     while(gKeepGoing)
     {


Add a counter for the fun...

Add a counter for the fun...

--- Industruino-stomp/Industruino-stomp.ino
+++ Industruino-stomp/Industruino-stomp.ino
@@ -29,6 +29,7 @@
 // Global
 int       counter;
 int       state;
+int       loopcount = 0;
 String    session;
 EthernetClient client; //Ethernet client mode
 byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
@@ -81,7 +82,9 @@
   String body;
   String frame;
   String response;
-
+
+  loopcount++;
+  lcd.setCursor(0, 4); lcd.print(loopcount);
   // If disconnected
   if( state == DISCONNECTED )
   {


Status led added

Status led added

--- arduino/arduino.ino
+++ arduino/arduino.ino
@@ -15,6 +15,8 @@
 int currentMotor1Pin2 = 0; // pin 7 on L293D
 int currentMotor2Pin1 = 0;
 int currentMotor2Pin2 = 0;
+
+int led_status = 0;

 // the setup routine runs once when you press reset:
@@ -140,6 +142,14 @@
   while(true) {
     int incomingByte = Serial.read();
     if(incomingByte != -1) {
+      if (led_status == 0) {
+        digitalWrite(LED_BUILTIN, 1);
+        led_status = 1;
+      } else {
+        digitalWrite(LED_BUILTIN, 0);
+        led_status = 0;
+      }
+
       return incomingByte;
     }
   }


added zero reset

added zero reset

--- longboard-ctl.ino
+++ longboard-ctl.ino
@@ -38,7 +38,7 @@

 #if AccelerometerSoftLPFilter
 #include <FilterOnePole.h>
-#define LowpassFreq 0.04
+#define LowpassFreq 0.005
 auto lpFilter = FilterOnePole( LOWPASS, LowpassFreq );
 #endif

@@ -46,9 +46,19 @@

 // Accelerometer
 auto mma = MMA8452();
+
+// Zero velocity handling
 float zeroOffset = 0;
 unsigned int zeroResetCounter = 0;
-const unsigned calibrationSamples = 256;
+#define ZeroResetCounterEps 0.001
+const float ZeroResetDamping = 0.01;
+const unsigned int MaxZeroCounter = 1.0 / ZeroResetDamping;
+
+// Zero offset handling
+const unsigned int CalibrationSamples = 100;
+
+unsigned long newAccTime;
+unsigned int dt;

 #if AccelerometerNewDataInterrupt
 // tells that accelerometer data is ready (with interrupt)
@@ -63,6 +73,8 @@
 // declarations
 void setupBluetooth();
 bool setupAccelerometer();
+inline float getUnfilteredXAcc();
+inline float getXAccSample();
 void calibrateZeroVel();
 float trapezoidalRule(float fa, float fb, int dt);

@@ -96,8 +108,21 @@

 // MAINLOOP
 void loop() {
+    float x = getXAccSample();
+
+    xVelocity += trapezoidalRule(lastAccValue, x, dt);
+    // damping factor
+    xVelocity += -xVelocity * zeroResetCounter * ZeroResetDamping;
+
+    // Update globals
+    lastAccTime = newAccTime;
+    lastAccValue = x;
+
+    Bluetooth.println(xVelocity*1000);
+
+}
+inline float getUnfilteredXAcc() {
     float x, y, z;
-    unsigned long newAccTime;

 #if AccelerometerNewDataInterrupt
     if (accDataReady) Bluetooth.println("DToo fast accelerometer");
@@ -107,12 +132,22 @@
     newAccTime = micros();

     // micros overflow or not
-    unsigned int dt = (newAccTime < lastAccTime) ?
+    dt = (newAccTime < lastAccTime) ?
         (newAccTime + 0x7FFFFFFFL) - (lastAccTime & 0x7FFFFFFFL):
         newAccTime - lastAccTime;

     mma.getAcceleration(&x, &y, &z);
     x += zeroOffset;
+    return x;
+}
+
+inline float getXAccSample() {
+    float x = getUnfilteredXAcc();
+
+    if (abs(x) < ZeroResetCounterEps)
+        zeroResetCounter < MaxZeroCounter ? ++zeroResetCounter : 0 ;
+    else
+        zeroResetCounter = (float) zeroResetCounter * 0.4;

     Bluetooth.print('E');
     Bluetooth.print(x*1000);
@@ -123,26 +158,8 @@
 #endif
     Bluetooth.print(x*1000);
     Bluetooth.print(',');
-
-    xVelocity += trapezoidalRule(lastAccValue, x, dt);
-
-    // Update globals
-    lastAccTime = newAccTime;
-    lastAccValue = x;
-
-    Bluetooth.println(xVelocity*1000);
-
-    //if (abs(x) > 0.05) {
-    //    Serial.println(x);
-        //Serial.print(",");
-        //Serial.print(y);
-        //Serial.print(",");
-        //Serial.println(z);
-    //}
-    //Serial.print("A");
-    //Serial.println((short)(x * 1000));
-}
-
+    return x;
+}

 // Stop and blink when error occurs
@@ -172,7 +189,7 @@
     mma.setLowNoiseMode(true);
     mma.setPowerMode(MMA_HIGH_RESOLUTION);

-    mma.setHighPassFilter(true, MMA_HP4); // Defaults (?) to highest cutoff: 16Hz
+    mma.setHighPassFilter(true, MMA_HP3); // Defaults (?) to highest cutoff: 16Hz

 #if AccelerometerNewDataInterrupt
     // data ready interrupt
@@ -195,12 +212,11 @@
     Bluetooth.println("DCalibrating zero-speed");

     // avarage
-    float x, y, z, sum = 0;
-    for (unsigned i = 0; i < calibrationSamples; ++i) {
-        mma.getAcceleration(&x, &y, &z);
-        sum += x;
+    float sum = 0;
+    for (unsigned i = 0; i < CalibrationSamples; ++i) {
+        sum += getUnfilteredXAcc();
     }
-    zeroOffset = sum / -calibrationSamples;
+    zeroOffset = -sum / (float) CalibrationSamples;
     Bluetooth.print("DCalibrated: ");
     Bluetooth.println(zeroOffset*1000);
 }


no message

no message

--- Led_fixture_sec.ino
+++ Led_fixture_sec.ino
@@ -4,7 +4,6 @@
 // 2014.06.20 v. 1.2 - partaisiju DIMMeasanu uz 1 sekundes intervalu
 // 2014.07.19 v. 2.0 - izlaboju lielu kludu DIMMesanas algoritma, pieliku DIMM rezima indikaciju
 // 2014.07.21 v. 2.1 - koda optimizacija, iznemtas liekas strukturas un mainigie
-

 // ~/Documents/Arduino/350W LED Fixture LDD/led_fixture


its 5am

its 5am

--- Servos/servo_controller/servo_controller.ino
+++ Servos/servo_controller/servo_controller.ino
@@ -5,7 +5,7 @@

 /* for each servo (corresponding to the index), the arduino pin
  * at which it's attached */
-int pins[] = {0};
+int pins[] = {2,3,4,5,6,7,8,9,10};

 /* high and low values platform corresponding to each servo */
 int servo_low[] = {130, 140, 150, 4, 60, 143, 8, 154, 150};
@@ -13,8 +13,8 @@
 int servo_pos[9];
 int servo_vel[] = {5,1,2,6,3,7,2,3,4};

-void sweep_all();
-void sweep_servo(int servo_num);
+//void sweep_all();
+//void sweep_servo(int servo_num);

 void setup()
@@ -23,14 +23,22 @@
   Serial.begin(9600);
   for(int i = 0; i < 9; i++) {
     servos[i].attach(pins[i]);
-    servo_pos[9] = (int)random(0,360);
+    servos[i].write(servo_high[i]);
+  // servo_pos[9] = (int)random(0,360);
   }
+
+  //s0.attach(pins[0]);
+
+
+
 }

 void loop()
 {
-  for(int i = 0; i < 9; i++) {
-    float servo_pos_rads = servo_pos[9]/180*3.1415926535
+  sweep_servo(random(8));
+  delay(500);
+  /*for(int i = 0; i < 9; i++) {
+    float servo_pos_rads = servo_pos[9]/180*3.1415926535;

     double nextpos = (sin(servo_pos_rads) + 1)/2;
     int lo = servo_low[i];
@@ -40,7 +48,7 @@
     servos[i].write(actualpos);

     servo_pos[i] = (servo_pos[i] + servo_vel[i]) % 360;
-  }
+  }*/
 }

 /* sweep_all - moves all servos up down to their low height
@@ -50,7 +58,6 @@
  * Works simultaneously - all servos will move one together,
  * one degree at a time
  */
-/*
 void sweep_all()
 {
   int heights[9];
@@ -79,7 +86,11 @@
     for(int j = 0; j < 9; j++)
     {
       if(heights[j] != servo_low[j])
+      {
         heights[j]--;
+        servos[j].write(heights[j]);
+        delay(100);
+      }
     }
   }

@@ -103,13 +114,18 @@
     for(int j = 0; j < 9; j++)
     {
       if(heights[j] != servo_high[j])
+      {
         heights[j]++;
+        servos[j].write(heights[j]);
+        delay(100);
+      }
+
     }
   }

   Serial.println("sweep of all servos complete");
 }
-*/
+
 /* sweep_servo - moves single servo down to lowest height
  * and back up to max height. works regardless of starting
  * position of the servo


Added one more valid pair for drivers

Added one more valid pair for drivers

--- module/module.ino
+++ module/module.ino
@@ -272,6 +272,10 @@
 	else if ( sum == maximumValue ) {
 		return true;
 	}
+ // both are 12
+  else if ( sum == maximumValue + 1 ) {
+    return true;
+  }
 	// all other values are invalid
 	else {
 		return false;


Fixing bug related to RFID not initializing if on Uno WiFi

--- module/module.ino
+++ module/module.ino
@@ -4,11 +4,11 @@
 // For Arduino with integrated WiFi
 #ifdef UnoWiFi
 	#include <Ciao.h>
+	SoftwareSerial RFID(WIFI_RX, WIFI_TX);
 #else
 	SoftwareSerial WIFI(WIFI_RX, WIFI_TX);
+	SoftwareSerial RFID(RFID_RX, RFID_TX);
 #endif
-
-SoftwareSerial RFID(RFID_RX, RFID_TX);

 void setup() {
 	// Set up pins


fimware: improve servo reliability

fimware: improve servo reliability

--- firmware/firmware.ino
+++ firmware/firmware.ino
@@ -40,6 +40,7 @@
 int xlimit_pin2 = A3;
 int servopin = A1;
 Servo servoPen;
+int servo_position = 90;

 float curX, curY, curZ;
 float tarX, tarY, tarZ; // target xyz position
@@ -133,6 +134,18 @@
 void initPosition() { curX = 0; curY = 0; posA = 0; posB = 0; }

+// ----------------------------------------
+// SERVO
+
+void servoMove(int tpos) {
+  int d = tpos - servo_position;
+
+  for (int i = 0; servo_position != tpos; i++) {
+    servo_position += (d > 0) ? 1 : -1;
+    servoPen.write(servo_position);
+    delay(15);
+  }
+}

 // ----------------------------------------
 // PARSING
@@ -177,8 +190,9 @@
 void parsePen(char * cmd) {
   char * tmp;
   strtok_r(cmd, " ", &tmp);
-  int pos = atoi(tmp);
-  servoPen.write(pos);
+  int tpos = atoi(tmp);
+
+  servoMove(tpos);
 }

 void parsePenPosSetup(char * cmd) {
@@ -314,7 +328,7 @@
   initRobotSetup();
   initPosition();

-  servoPen.write(roboSetup.data.penUpPos);
+  servoMove(roboSetup.data.penUpPos);
   delay(100);
   servoPen.attach(servopin);


Added n64 prefix verify routine, needs testing

--- firmware/firmware.ino
+++ firmware/firmware.ino
@@ -41,6 +41,8 @@
 #define ZERO  '\0'  // Use a byte value of 0x00 to represent a bit with value 0.
 #define ONE    '1'  // Use an ASCII one to represent a bit with value 1.  This makes Arduino debugging easier.
 #define SPLIT '\n'  // Use a new-line character to split up the controller state packets.
+
+

 // Declare some space to store the bits we read from a controller.
@@ -141,6 +143,20 @@
 }

+
+inline bool checkPrefixN64 ()
+{
+    if( rawData[0] != 0 ) return false; // 0
+    if( rawData[1] != 0 ) return false; // 0
+    if( rawData[2] != 0 ) return false; // 0
+    if( rawData[3] != 0 ) return false; // 0
+    if( rawData[4] != 0 ) return false; // 0
+    if( rawData[5] != 0 ) return false; // 0
+    if( rawData[6] != 0 ) return false; // 0
+    if( rawData[7] == 0 ) return false; // 1
+    if( rawData[8] == 0 ) return false; // 1
+    return true;
+}

 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 // Sends a packet of controller data over the Arduino serial interface.


Clean up.

Clean up.

--- examples/Tools/CosaAutoCalibration/CosaAutoCalibration.ino
+++ examples/Tools/CosaAutoCalibration/CosaAutoCalibration.ino
@@ -39,34 +39,30 @@
   // Start the watchdog and internal real-time clock
   Watchdog::begin();
   RTC::begin();
-
-  // Synchronized clocks
-  uint32_t now = clock.await();
-  delay(500);
-  bark.time(now + 1);
 }

 void loop()
 {
-  static int32_t cycle = 1;
-
-  // Wait for clock update
-  uint32_t now = clock.await();
-
-  // Calculate error and possible adjustment
-  int32_t diff = bark.time() - now;
-  int32_t err = (1000 * diff) / cycle;
-  if (err != 0) {
-    bark.adjust(err / 2);
-    trace << endl << PSTR("calibration=") << bark.calibration() << endl;
-    cycle = 1;
-    clock.time(0);
-    now = clock.await();
-    delay(500);
-    bark.time(now + 1);
+  // Measure the watchdog clock. Wait for stable measurement
+  uint32_t us = 10000L;
+  for (int j = 0; j < 10;) {
+    uint32_t t = us;
+    uint32_t w = bark.time();
+    while (w == bark.time()) yield();
+    uint32_t start = RTC::micros();
+    w = bark.time();
+    while (w == bark.time()) yield();
+    uint32_t stop = RTC::micros();
+    us = stop - start;
+    int32_t diff = t - us;
+    if (diff < 0) diff = -diff;
+    if (diff > 50) j = 0; else j += 1;
+    trace << j << '.';
   }
-  else {
-    trace << '.';
-    cycle += 1;
-  }
+  trace << endl;
+  int32_t diff = (1000000UL - us);
+  int16_t ms = (diff + 500L) / 1000;
+  bark.adjust(ms);
+  trace << PSTR("calibration=") << bark.calibration() << endl;
+  sleep(5);
 }


safety

safety

--- coni/arduino/main/master/master_old.ino
+++ coni/arduino/main/master/master_old.ino
@@ -0,0 +1,218 @@
+void setup() {
+  // put your setup code here, to run once:
+  pinMode(53, OUTPUT);
+  pinMode(52, OUTPUT);
+  pinMode(51, OUTPUT);
+  pinMode(50, OUTPUT);
+
+  Serial.begin(9600);
+  Serial2.begin(4800);
+
+  pinMode(12, INPUT_PULLUP);
+
+  pinMode(6, OUTPUT);
+  pinMode(7, OUTPUT);
+  digitalWrite(6, HIGH);
+  digitalWrite(7, HIGH);
+
+}
+
+bool oki = false;
+uint32_t dataOut = 0;
+long dataIn = 0;
+char tag;
+bool inv = false;
+
+String inString = "";
+
+void loop() {
+  /*// put your main code here, to run repeatedly:
+    if (digitalRead(12)) {
+    digitalWrite(52,HIGH);
+    if (oki) {
+      Serial2.println("ciao");
+      oki = false;
+    }
+    }
+    else {
+    digitalWrite(52,LOW);
+    oki = true;
+    }*/
+  if (Serial.available() > 0) {
+    int inChar = Serial.read();
+    if (isDigit(inChar)) {
+      inString += (char)inChar;
+    }
+    else {
+      if ((inChar != '\n') && (inChar != '-')) {
+        tag = ((char)inChar);
+      }
+      else if (inChar == '-') {
+        inv = true;
+      }
+    }
+
+    if (inChar == '\n') {
+
+      dataIn = inString.toInt();
+      if (inv) {
+        dataIn *= -1;
+        inv = false;
+      }
+
+      switch (tag) {
+        case 'a':   //pos A
+          dataOut = dataIn * (100800 / 360) + 500000;
+          Serial.print(tag);
+          Serial.print(dataIn);
+          Serial.print(" // ");
+          Serial.println(dataOut);
+          Serial2.print(dataOut);
+          break;
+        case 'A':
+          if (dataIn > 360) { //vel A
+            dataOut = dataIn + 1500000;
+          }
+          else { //abs A
+            dataOut = dataIn * (100800 / 360) + 16500000;
+          }
+          Serial.print(tag);
+          Serial.print(dataIn);
+          Serial.print(" // ");
+          Serial.println(dataOut);
+          Serial2.print(dataOut);
+          break;
+        case 'b':   //pos B
+          dataOut = dataIn * (100800 / 360) + 2500000;
+          Serial.print(tag);
+          Serial.print(dataIn);
+          Serial.print(" // ");
+          Serial.println(dataOut);
+          Serial2.print(dataOut);
+          break;
+        case 'B':   //vel B
+          if (dataIn > 360) { //vel B
+            dataOut = dataIn + 3500000;
+          }
+          else { //abs B
+            dataOut = dataIn * (100800 / 360) + 17500000;
+          }
+          Serial.print(tag);
+          Serial.print(dataIn);
+          Serial.print(" // ");
+          Serial.println(dataOut);
+          Serial2.print(dataOut);
+          break;
+        case 'c':   //pos C
+          dataOut = dataIn * (100800 / 360) + 6500000;
+          Serial.print(tag);
+          Serial.print(dataIn);
+          Serial.print(" // ");
+          Serial.println(dataOut);
+          Serial2.print(dataOut);
+          break;
+        case 'C':
+          if (dataIn > 360) { //vel C
+            dataOut = dataIn + 7500000;
+          }
+          else { //abs C
+            dataOut = dataIn * (100800 / 360) + 18500000;
+          }
+          Serial.print(tag);
+          Serial.print(dataIn);
+          Serial.print(" // ");
+          Serial.println(dataOut);
+          Serial2.print(dataOut);
+          break;
+        case 'd':   //pos D
+          dataOut = dataIn * (100800 / 360) + 8500000;
+          Serial.print(tag);
+          Serial.print(dataIn);
+          Serial.print(" // ");
+          Serial.println(dataOut);
+          Serial2.print(dataOut);
+          break;
+        case 'D':
+          if (dataIn > 360) { //vel D
+            dataOut = dataIn + 9500000;
+          }
+          else { //abs D
+            dataOut = dataIn * (100800 / 360) + 19500000;
+          }
+          Serial.print(tag);
+          Serial.print(dataIn);
+          Serial.print(" // ");
+          Serial.println(dataOut);
+          Serial2.print(dataOut);
+          break;
+        case 'e':   //pos E
+          dataOut = dataIn * (100800 / 360) + 10500000;
+          Serial.print(tag);
+          Serial.print(dataIn);
+          Serial.print(" // ");
+          Serial.println(dataOut);
+          Serial2.print(dataOut);
+          break;
+        case 'E':
+          if (dataIn > 360) { //vel E
+            dataOut = dataIn + 11500000;
+          }
+          else { //abs E
+            dataOut = dataIn * (100800 / 360) + 20500000;
+          }
+          Serial.print(tag);
+          Serial.print(dataIn);
+          Serial.print(" // ");
+          Serial.println(dataOut);
+          Serial2.print(dataOut);
+          break;
+        case 's':
+          dataOut = 15500000;
+          Serial.print("Stop // ");
+          Serial.println(dataOut);
+          Serial2.print(dataOut);
+          break;
+        case 'z':
+          Serial.println("z");
+          Serial.println(dataOut);
+          switch (dataIn) {
+            case 1:
+              Serial.print("zerosA // ");
+              Serial.println(4500000);
+              Serial2.print(4500000);
+              break;
+            case 2:
+              Serial.print("zerosB // ");
+              Serial.println(5500000);
+              Serial2.print(5500000);
+              break;
+            case 3:
+              Serial.print("zerosC // ");
+              Serial.println(12500000);
+              Serial2.print(12500000);
+              break;
+            case 4:
+              Serial.print("zerosD // ");
+              Serial.println(13500000);
+              Serial2.print(13500000);
+              break;
+            case 5:
+              Serial.print("zerosE // ");
+              Serial.println(14500000);
+              Serial2.print(14500000);
+              break;
+            default:
+              Serial.println("motore non esistente");
+              break;
+          }
+          break;
+        default:
+          Serial.println("comando inesistente");
+          break;
+      }
+
+      inString = "";
+
+    }
+  }
+}


implement test mode

implement test mode

--- ksp-gegi-mini/ksp-gegi-mini.ino
+++ ksp-gegi-mini/ksp-gegi-mini.ino
@@ -27,6 +27,8 @@
 const uint8_t dataPin  = A2;  // SERIN (3)
 const uint8_t latchPin = A3;  // RCK (12)

+bool testMode = true;	// in test mode we can blink lights without Python!
+
 class digitalPin {
   public: // pinOn/Off - 0-127=hw pin, 128+[0..7]=serial pin
     digitalPin(const uint8_t id, const uint8_t pinSwitch, const uint8_t pinOn, const uint8_t pinOff);
@@ -35,6 +37,7 @@
     void updateLed(const bool blink) ;
     uint8_t getId() const { return(m_id); }
     uint8_t getOnOffBits() const; // return object where serial bits are on/off according to state m_OnLed+m_Offled
+    uint8_t getSwitchState() const { return(m_lastPinState); }
   private:
     const uint8_t m_id, m_pinSwitch, m_pinOn, m_pinOff;
     uint8_t m_OnLed { LOW };
@@ -198,6 +201,8 @@
 }

 void handleStatusReset() {
+  // disable test mode
+  testMode = false;
   // pass own status
   updatePins(true);
   // request status update
@@ -216,8 +221,24 @@
   }
 }

+void handleTestMode() {
+	for (auto &p : digiPins) {
+		if (p.getSwitchState()) {
+			p.updateLedState('G',1);
+			p.updateLedState('R',0);
+		} else {
+			p.updateLedState('G',0);
+			p.updateLedState('R',1);
+		}
+	}
+}
+
 void loop() {
+  if (testMode) {
+	  handleTestMode();
+  }
   checkSerialInput();
   updatePins(false);
   delay(100);
 }
+


use built-in serial console code

use built-in serial console code

--- examples/RF12/RF12tune3/RF12tune3.ino
+++ examples/RF12/RF12tune3/RF12tune3.ino
@@ -1,4 +1,4 @@
-/// @dir RF12tune2
+/// @dir RF12tune3
 /// This sketch loads a configuration into eeprom compatible with rf12_config.
 /// It then enters a frequency scanning mode to find the
 /// centre of frequency offset from its partner ack'ing Jeenode.
@@ -18,7 +18,6 @@
 #include <JeeLib.h>
 #include <util/crc16.h>
 #include <avr/eeprom.h>
-#include <SoftwareSerial.h>
 #define ACK_TIME   20  // number of milliseconds to wait for an ack
 #define RETRY_LIMIT 9  // maximum number of times to retry
 #define RADIO_SYNC_MODE 2
@@ -65,12 +64,8 @@
 static RF12Config config;
 unsigned int frequency_offset;

-
 #if defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny44__)
-#define SERIAL_BAUD 19200
-#define txPin 9  //PA1         AIO1 - > Connect to RX on USB BUB
-#define rxPin 10 //PA0         DIO1 - > Connect to TX on USB BUB
-SoftwareSerial mySerial =  SoftwareSerial(rxPin, txPin);
+#define SERIAL_BAUD 9600
 #else
 #define SERIAL_BAUD 57600
 #endif
@@ -80,15 +75,7 @@
 byte parameters = 0;

 void setup() {
-#if defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny44__)
-  pinMode(rxPin, INPUT);
-  pinMode(txPin, OUTPUT);
-  mySerial.begin(SERIAL_BAUD);
-//  bitSet(DDRB, 0);    // Power up
-//  bitClear(PORTB, 0); // RFM12B
-#else
   Serial.begin(SERIAL_BAUD);
-#endif
   showString(PSTR("\n[RF12tune3.0]\n"));
   delay(5000);  // Startup delay to debounce disconnection
   while (!enough) {
@@ -135,21 +122,12 @@
     showString(PSTR("Insufficient parameters 0x"));
     showNibble(0x1F - parameters >> 4);
     showNibble(0x1F - parameters);
-#if defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny44__)
-    mySerial.println();
-    mySerial.println(config.group);
-    mySerial.println(config.nodeId);
-    mySerial.println(frequency_offset);
-#else
     Serial.println();
     Serial.println(config.group);
     Serial.println(config.nodeId);
     Serial.println(frequency_offset);
-#endif
     while(1) // Nothing more
-    {
       delay(32767);
-    }
   }

   setEEProm();
@@ -178,15 +156,9 @@
 void loop() {
   unsigned int scan, upLow, upHigh, downLow, downHigh;
   showString(PSTR("Scanning started "));
-#if defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny44__)
-  mySerial.print(frequency_offset);
-  showString(PSTR(" +/- "));
-  mySerial.println(SCAN_WIDTH);
-#else
   Serial.print(frequency_offset);
   showString(PSTR(" +/- "));
   Serial.println(SCAN_WIDTH);
-#endif
   delay(50);

     upLow = 0xFFFF;
@@ -202,26 +174,16 @@
    }
       else {
         showString(PSTR("No Ack "));
-#if defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny44__)
-        mySerial.print(scan);
-#else
         Serial.print(scan);
-#endif
         showString(PSTR("\r"));
         delay(50);
       }
   }
   if ((upHigh == 0) || (upLow == 0xFFFF)) return;  // If nobody answers then restart loop
     showString(PSTR("Scan up complete "));
-#if defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny44__)
-    mySerial.print(upLow);
-    showString(PSTR("-"));
-    mySerial.println(upHigh);
-#else
     Serial.print(upLow);
     showString(PSTR("-"));
     Serial.println(upHigh);
-#endif
     delay(50);
     downLow = 0xFFFF;
     downHigh = 0;
@@ -235,35 +197,21 @@
      delay(50);
    }
       else {
-#if defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny44__)
-       showString(PSTR("No Ack "));
-        mySerial.print(scan);
- #else
+        showString(PSTR("No Ack "));
         Serial.print(scan);
- #endif
         showString(PSTR("\r"));
         delay(50);
       }
   }
   if ((downHigh == 0) || (downLow == 0xFFFF)) return;  // If nobody answers then restart loop
   showString(PSTR("Scan down complete "));
-#if defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny44__)
-  mySerial.print(downLow);
-  showString(PSTR("-"));
-  mySerial.println(downHigh);
-#else
   Serial.print(downLow);
   showString(PSTR("-"));
   Serial.println(downHigh);
-#endif

  frequency_offset = ( ((upLow + downLow) / 2) + ((((upHigh + downHigh) / 2) - ((upLow + downLow)/ 2)) / 2)   );
   showString(PSTR("Centre frequency offset is "));
-#if defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny44__)
-  mySerial.println(frequency_offset);
-#else
   Serial.println(frequency_offset);
-#endif
   delay(50);
   setEEProm();
   while(1) // Nothing more
@@ -281,13 +229,8 @@
     if (c == 0)
       break;
     if (c == '\n')
-#if defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny44__)
-      mySerial.print('\r');
-    mySerial.print(c);
-#else
       Serial.print('\r');
     Serial.print(c);
-#endif
   }
 }
 static void setEEProm()
@@ -347,10 +290,6 @@
   char c = '0' + (nibble & 0x0F);
   if (c > '9')
     c += 7;
-#if defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny44__)
-  mySerial.print(c);
-#else
   Serial.print(c);
-#endif
-}
-
+}
+


Cleanup formatting.

Cleanup formatting.

--- examples/Tools/CosaRF24scanner/CosaRF24scanner.ino
+++ examples/Tools/CosaRF24scanner/CosaRF24scanner.ino
@@ -87,7 +87,7 @@
       DELAY(WAIT_TIME);
       m_channel[i] += (read(RPD) != 0);
       m_ce.clear();
-      }
+    }
   } while (--samples);
 }


Fix ABS parsing

Fix ABS parsing

--- Event_Printer/Event_Printer.ino
+++ Event_Printer/Event_Printer.ino
@@ -130,7 +130,7 @@
     Serial.println("");

     // ABS Status
-    unsigned char lnibble2 = LO_NIBBLE(data[1]);
+    unsigned char lnibble2 = HI_NIBBLE(data[1]);
     Serial.print("ABS: ");
     if( lnibble2 == 0x05 ) Serial.print("ON");
     else if( lnibble2 == 0x0B ) Serial.print("OFF");


Fix speed issues with runSteppersToPos()

--- OpenStage/openStage_moveToTarget.ino
+++ OpenStage/openStage_moveToTarget.ino
@@ -113,33 +113,35 @@

 void runSteppersToPos(){
-  bool verbose=1;
-  if (verbose){
-     Serial.println("Entering runSteppersToPos");
-  }
-

-  int n=0; //counter to monitor if the controller is locked in this loop
-  long keepMoving=1;
-  while (keepMoving>0){
+  //int n=0; //counter to monitor if the controller is locked in this loop
+  bool keepMoving=1;
+
+  while (keepMoving){

     keepMoving=0;
     for (int ii=0; ii<numAxes; ii++){
       if (!axisPresent[ii]){
         continue;
       }
-      if ((*mySteppers[ii]).distanceToGo()>0){
-          keepMoving++;
-          (*mySteppers[ii]).run();
-      }
+      if ((*mySteppers[ii]).distanceToGo() != 0){
+         keepMoving=1;
+      }
     }
-
+
+    //Motion is a touch faster if we place run code here
+    for (int ii=1; ii<numAxes; ii++){
+       (*mySteppers[ii]).run();
+    }
+
+
+      //I haven't seen lock-ups in ages, so we comment out this code.
       //Sometimes the controller locks up following analog stick motions
       //This is due to it getting stuck in this loop with the motors at zero
       //speed. Not yet clear why this happens, but in the mean time we can catch
       //it with the following code and deliver an audible indication that something
       //is wrong. This enables us to keep going and not lock up.
-      long currentTotalSpeed=0;
+       /*  long currentTotalSpeed=0;
       for (int ii=0; ii<numAxes; ii++){
         if (!axisPresent[ii]){
            continue;
@@ -158,6 +160,7 @@
           }
         break;
       }
+      */
    } //close while loop

 } //End runSteppersToPos


Addition of Websocket server and splitting of execution loop.

Minor changes needed to ensure compatability before testing.

--- FH_Tbot.ino
+++ FH_Tbot.ino
@@ -1,5 +1,5 @@
 /*
-Copyright 2016, Tilden Groves.
+Copyright 2017, Tilden Groves, Alexander Battarbee.

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
@@ -16,6 +16,9 @@

 #pragma GCC optimize ("-O2")           // O0 none, O1 Moderate optimization, 02, Full optimization, O3, as O2 plus attempts to vectorize loops, Os Optimize space
 #include <ESP8266WiFi.h>
+#include <WebSockets.h>
+#include <WebSocketsServer.h>
+#include <WebSocketsClient.h>
 #include <FS.h>
 #include <DNSServer.h>
 #include <Ticker.h>
@@ -39,10 +42,8 @@
 bool enableCompatibilityMode = false;   // turn on compatibility mode for older devices, spacifically sets no encryption and 11B wifi standard

-
-
-
 void setupWiFi(void);
+void setupWebsocket(void);
 void initHardware(void);
 void sendFile(File);
 String getContentType(String);
@@ -79,6 +80,7 @@
 Ticker rBH;                            // right bumper hit reverse timer
 WiFiServer server(80);
 WiFiClient client;
+WebSocketsServer webSocket = WebSocketsServer(81);
 DNSServer dnsServer;
 Ticker HeartBeatTicker;
 int distance = 500;
@@ -174,7 +176,13 @@
     }
     currentClient = 0;
   }
-
+  executeRequest(req);
+  //Loop WebSocket Server
+  webSocket.loop();
+
+}
+void executeRequest(String req){
+
   if (!req.length()){// empty request
       return;
       }
@@ -278,6 +286,30 @@
           sendFile(fileString);
         }
 }
+/**
+ * Handles Websocket reception, deciding what needs to be done vs the type of message.
+ */
+void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t payLength){
+  switch(type){
+    case WStype_DISCONNECTED:
+      //perform disconnection events (i.e. send bot to idle.)
+      Serial.println(num + " Disconnected!\n");
+      break;
+    case WStype_CONNECTED:{
+      //HANDLE NEW CLIENT CONNECTION
+      //IPAddress ip = webSocket.remoteIP(num);
+      //Serial.println(num + " Connected from "+ ip[0] + "."+ip[1]+"."+ip[2]+"."+ip[3]+" url: "+payload+"\n");
+      //ACK connection to client
+      webSocket.sendTXT(num, "Connected");
+      break;
+    case WStype_TEXT:
+      //Perform actions based on a good payload.
+      //Serial.println(num + "get Text: "+ payload +"\n");
+      //executeRequest(payload);
+      break;
+    }
+  }
+}

 void setupWiFi()
 {
@@ -308,6 +340,12 @@
   dnsServer.start(DNS_PORT, "*", apIP);// default FHTbot.com  //must use '.com, .org etc..' and cant use '@ or _ etc...' ! . Use "*" to divert all **VALID** names
   server.begin();
   server.setNoDelay(true);
+}
+
+void setupWebsocket(){
+  //start websocket
+  webSocket.begin();
+  webSocket.onEvent(webSocketEvent);
 }

 void initHardware()
@@ -506,4 +544,4 @@
     }
      #endif
 }
-
+


First fully-working project

First fully-working project

At this time, I connected all the pins I needed to this project, created the software and this was it. The fully-functional project on its feet, sending data on the SQL database from tm-edu.ro.
- 10th of February 2017

--- temp/temp.ino
+++ temp/temp.ino
@@ -1,75 +1,432 @@
-#include <Adafruit_Sensor.h>
-#include <DHT.h>
-#include <DHT_U.h>
-
-#define DHTPIN            2         // Pin which is connected to the DHT sensor.
-
-// Uncomment the type of sensor in use:
-//#define DHTTYPE           DHT11     // DHT 11
-#define DHTTYPE           DHT22     // DHT 22 (AM2302)
-//#define DHTTYPE           DHT21     // DHT 21 (AM2301)
-
-// See guide for details on sensor wiring and usage:
-//   https://learn.adafruit.com/dht/overview
-
-DHT_Unified dht(DHTPIN, DHTTYPE);
-
-uint32_t delayMS;
-
-void setup() {
+#include <Arduino.h>
+#include <SoftwareSerial.h>
+#include <ESP8266_Simple.h>
+#include <LiquidCrystal.h>
+#include <DHT.h>
+
+#define DEBUG 1
+
+#define PHOTOpin A0    // analog photoresistor
+#define GASpin A7      // analog gas
+#define PIRsensorPin 24// digital PIR
+#define pBlu 3         // digital blue LED
+#define pGrn 4         // digital green LED
+#define pRed 5         // digital red LED
+#define ESP8266_SSID  "H218N"
+#define ESP8266_PASS  "certificat"
+#define RXpinSEND 12   // ESP-01 wifiSEND module TX
+#define TXpinSEND 13   // ESP-01 wifiSEND module RX
+#define RELAYbutton 14 // digital switch 1
+#define ALARMbutton 15 // digital switch 2
+#define RELAYpin 16    // digital relay
+#define DHTpin 21      // digital temp sensor
+#define BUZZpin 22     // digital buzzer
+
+#define REFRESHupload 30 //15*60 second to upload data to server / to be changed to 15 min
+
+LiquidCrystal lcd(51, 50, 6, 7, 8, 9);
+ESP8266_Simple wifiSEND( RXpinSEND, TXpinSEND);
+DHT dht( DHTpin, DHT11);
+
+byte smiley[8] = {
+  B00000,
+  B11011,
+  B00000,
+  B00000,
+  B10001,
+  B01110,
+  B00000,
+};
+byte doo[8] = {
+  B10000,
+  B10000,
+  B10000,
+  B10000,
+  B10000,
+  B10000,
+  B10000,
+};
+byte re[8] = {
+  B11000,
+  B11000,
+  B11000,
+  B11000,
+  B11000,
+  B11000,
+  B11000,
+};
+byte mi[8] = {
+  B11100,
+  B11100,
+  B11100,
+  B11100,
+  B11100,
+  B11100,
+  B11100,
+};
+byte fa[8] = {
+  B11110,
+  B11110,
+  B11110,
+  B11110,
+  B11110,
+  B11110,
+  B11110,
+};
+byte sol[8] = {
+  B11111,
+  B11111,
+  B11111,
+  B11111,
+  B11111,
+  B11111,
+  B11111,
+};
+
+void setup(){
+  lcd.createChar(0,smiley);
+  lcd.createChar(1,doo);
+  lcd.createChar(2,re);
+  lcd.createChar(3,mi);
+  lcd.createChar(4,fa);
+  lcd.createChar(5,sol);
+  lcd.begin(16, 2);
+  lcd.setCursor(0,0);
+  lcd.print("Loading...             ");
+  int loadTime = 0;
+  loadScreen(loadTime); loadTime++;
+  pinMode(pRed, OUTPUT);
+  pinMode(pGrn, OUTPUT);
+  pinMode(pBlu, OUTPUT);
+  pinMode(PIRsensorPin,INPUT);
+  pinMode(ALARMbutton,INPUT);
+  pinMode(RELAYbutton,INPUT);
+  pinMode(RELAYpin, OUTPUT);
+  pinMode(BUZZpin, OUTPUT);
   Serial.begin(9600);
-  // Initialize device.
-  dht.begin();
-  Serial.println("DHTxx Unified Sensor Example");
-  // Print temperature sensor details.
-  sensor_t sensor;
-  dht.temperature().getSensor(&sensor);
-  Serial.println("------------------------------------");
-  Serial.println("Temperature");
-  Serial.print  ("Sensor:       "); Serial.println(sensor.name);
-  Serial.print  ("Driver Ver:   "); Serial.println(sensor.version);
-  Serial.print  ("Unique ID:    "); Serial.println(sensor.sensor_id);
-  Serial.print  ("Max Value:    "); Serial.print(sensor.max_value); Serial.println(" *C");
-  Serial.print  ("Min Value:    "); Serial.print(sensor.min_value); Serial.println(" *C");
-  Serial.print  ("Resolution:   "); Serial.print(sensor.resolution); Serial.println(" *C");
-  Serial.println("------------------------------------");
-  // Print humidity sensor details.
-  dht.humidity().getSensor(&sensor);
-  Serial.println("------------------------------------");
-  Serial.println("Humidity");
-  Serial.print  ("Sensor:       "); Serial.println(sensor.name);
-  Serial.print  ("Driver Ver:   "); Serial.println(sensor.version);
-  Serial.print  ("Unique ID:    "); Serial.println(sensor.sensor_id);
-  Serial.print  ("Max Value:    "); Serial.print(sensor.max_value); Serial.println("%");
-  Serial.print  ("Min Value:    "); Serial.print(sensor.min_value); Serial.println("%");
-  Serial.print  ("Resolution:   "); Serial.print(sensor.resolution); Serial.println("%");
-  Serial.println("------------------------------------");
-  // Set delay between sensor readings based on sensor details.
-  delayMS = sensor.min_delay / 1000;
+  wifiSEND.begin(9600); loadScreen(loadTime); loadTime++;
+
+
+  lcd.setCursor(0,0); lcd.print("Resetting...             ");
+  for( loadTime = 2 ; loadTime < 10; ++loadTime)
+    loadScreen(loadTime);
+
+  char bufferr[300];
+  wifiSEND.sendCommand(F("AT+CWJAP?"), bufferr, sizeof(bufferr));
+  delay(5000);
+  if(DEBUG){
+    Serial.println(bufferr);
+    Serial.println(ESP8266_SSID);
+  }
+
+  if(bufferr!=ESP8266_SSID){
+  char buffer11[300];
+  wifiSEND.sendCommand(F("AT+RST"), buffer11, sizeof(buffer11));
+  delay(5000);
+  wifiSEND.setupAsWifiStation(ESP8266_SSID, ESP8266_PASS, &Serial);
+  delay(5000);
+  }
+
+  lcd.setCursor(0,0); lcd.print("Connecting...             ");
+  for( loadTime = 10 ; loadTime < 16; ++loadTime)
+    loadScreen(loadTime);
+  lcd.setCursor(0,1);
+  lcd.print(" Ready!            ");
+  delay(800);
 }

-void loop() {
-  // Delay between measurements.
-  delay(delayMS);
-  // Get temperature event and print its value.
-  sensors_event_t event;
-  dht.temperature().getEvent(&event);
-  if (isnan(event.temperature)) {
-    Serial.println("Error reading temperature!");
-  }
-  else {
-    Serial.print("Temperature: ");
-    Serial.print(event.temperature);
-    Serial.println(" *C");
-  }
-  // Get humidity event and print its value.
-  dht.humidity().getEvent(&event);
-  if (isnan(event.relative_humidity)) {
-    Serial.println("Error reading humidity!");
-  }
-  else {
-    Serial.print("Humidity: ");
-    Serial.print(event.relative_humidity);
-    Serial.println("%");
-  }
+int alarm=0,lightBulb=0;
+int lastON=0,r=0;
+unsigned long WIFIupload = -REFRESHupload ,LASTmotion = 0;
+
+void loop()
+{
+
+  if(DEBUG) Serial.print("Gas value is ");
+  if(DEBUG) Serial.println(analogRead(GASpin));
+  if(analogRead(GASpin)>500){
+      lcd.setCursor(0,0);
+      lcd.print(" WARNING! Gas");
+      lcd.setCursor(0,1);
+      lcd.print("  limit exceeded!");
+      tone(BUZZpin, 2000, 500);
+
+      char buffer[250];
+
+      memcpy(buffer, 0, sizeof(buffer));
+      strncpy_P(buffer, PSTR("/getgas.php?p=abc"), sizeof(buffer)-1);
+
+      strncpy_P(buffer+strlen(buffer), PSTR("&lastg="), sizeof(buffer)-strlen(buffer)-1);
+      ltoa(analogRead(GASpin), buffer+strlen(buffer), 10);
+
+      Serial.print("Requesting GAS");
+      Serial.print(buffer);
+      Serial.print(": ");
+
+      unsigned int httpResponseCode =
+        wifiSEND.GET
+        (
+          F("86.123.250.85"),
+          80,
+          buffer,
+          sizeof(buffer),
+          F("seba.tm-edu.ro"),
+          2
+
+
+        );
+
+    if(httpResponseCode == 200 || httpResponseCode == ESP8266_OK){
+      Serial.println("OK");
+      Serial.println(buffer);
+    }
+    else
+      if(httpResponseCode < 100)
+        wifiSEND.debugPrintError((byte)httpResponseCode, &Serial);
+      else{
+        Serial.print("HTTP Status ");
+        Serial.println(httpResponseCode);
+      }
+
+     delay(1000);
+  }
+  else
+    noTone(BUZZpin);
+
+
+  if(digitalRead(ALARMbutton)){
+    alarm++; alarm=alarm%2;
+    Serial.print("Alarm is "); Serial.println(alarm);
+    if(alarm){
+
+      lcd.setCursor(0,0); lcd.print("House will be         ");
+      lcd.setCursor(0,1); lcd.print(" armed in         ");
+      delay(1000);
+
+      for( int i = 59 ; i>=0 ; --i ){
+        lcd.setCursor(12,1);
+        if(i<10) lcd.setCursor(11,1);
+        lcd.print(i); lcd.print("         ");
+
+        setColor(40,0,0);
+        delay(100);
+        setColor(0,0,0);
+        delay(900);
+
+        if(digitalRead(ALARMbutton)){
+          alarm++; alarm=alarm%2;
+          Serial.print("Alarm is "); Serial.println(alarm);
+          break;
+        }
+      }
+      if(alarm){
+        lcd.setCursor(0,0);
+        lcd.print("House is now");
+        lcd.setCursor(0,1);
+        lcd.print("      ARMED!          ");
+        setColor(255,0,0);
+        }
+      else{
+        lcd.setCursor(0,0);
+        lcd.print("House is now");
+        lcd.setCursor(0,1);
+        lcd.print("    UNARMED!           ");
+        setColor(0,0,255);
+      }
+    }
+    else{
+      lcd.setCursor(0,0);
+      lcd.print("House is now");
+      lcd.setCursor(0,1);
+      lcd.print("    UNARMED!          ");
+      setColor(0,0,255);
+    }
+    delay(2000);
+    setColor(0,0,0);
+  }
+
+
+  if(digitalRead(RELAYbutton)){
+    lightBulb++; lightBulb=lightBulb%2;
+    Serial.print("The light bulb is "); Serial.println(lightBulb);
+    if(lightBulb){
+      lcd.setCursor(0,0);
+      lcd.print("Light bulb                ");
+      lcd.setCursor(0,1);
+      lcd.print("         ON!          ");
+      setColor(255,255,255);
+      digitalWrite(RELAYpin,HIGH);
+    }
+    else{
+      lcd.setCursor(0,0);
+      lcd.print("Light bulb          ");
+      lcd.setCursor(0,1);
+      lcd.print("         OFF!     ");
+      setColor(0,0,0);
+      digitalWrite(RELAYpin,LOW);
+    }
+    delay(900);
+    if(lastON){
+      r++; r%=2;
+    }
+  }
+  lastON=digitalRead(RELAYbutton);
+
+
+  if(digitalRead(PIRsensorPin)){ // motion sense
+    if(DEBUG) Serial.println("Somebody is in this area!");
+    LASTmotion=millis()/1000;
+
+    if(alarm==1){
+      char buffer[250];
+
+      memcpy(buffer, 0, sizeof(buffer));
+      strncpy_P(buffer, PSTR("/getmotion.php?p=abc"), sizeof(buffer)-1);
+
+      strncpy_P(buffer+strlen(buffer), PSTR("&lastm="), sizeof(buffer)-strlen(buffer)-1);
+      ltoa(millis()/1000, buffer+strlen(buffer), 10);
+
+      Serial.print("Requesting MOTION");
+      Serial.print(buffer);
+      Serial.print(": ");
+
+      unsigned int httpResponseCode =
+        wifiSEND.GET
+        (
+          F("86.123.250.85"),
+          80,
+          buffer,
+          sizeof(buffer),
+          F("seba.tm-edu.ro"),
+          2
+
+
+        );
+
+      if(httpResponseCode == 200 || httpResponseCode == ESP8266_OK){
+        Serial.println("OK");
+        Serial.println(buffer);
+      }
+      else
+        if(httpResponseCode < 100)
+          wifiSEND.debugPrintError((byte)httpResponseCode, &Serial);
+        else{
+          Serial.print("HTTP Status ");
+          Serial.println(httpResponseCode);
+        }
+    }
+  }
+
+
+  if(DEBUG){
+    Serial.println("Brightness: "); // brightness
+    Serial.println(analogRead(PHOTOpin));
+    Serial.println();
+    Serial.print("Temperature = "); // DHT
+    Serial.println(dht.readTemperature());
+    Serial.print("Humidity = ");
+    Serial.println(dht.readHumidity());
+    Serial.println();
+  }
+
+  if(r==0){
+    lcd.setCursor(0,0);
+    lcd.print("  Humid="); lcd.print((int)dht.readHumidity()); lcd.print("%            ");
+    lcd.setCursor(0,1);
+    lcd.print(" Warmth="); lcd.print((int)dht.readTemperature()); lcd.println("'C            ");
+  }
+  else{
+    lcd.setCursor(0,0);
+    lcd.print("Brightness: ");
+    lcd.print(analogRead(PHOTOpin));
+    lcd.print("               ");
+    lcd.setCursor(0,1);
+    lcd.print("Gas: ");
+    lcd.print(analogRead(GASpin)); lcd.print("  ");
+    lcd.write(byte(0)); lcd.print("               ");
+  }
+
+
+  if(WIFIupload+REFRESHupload<millis()/1000){
+
+    char buffer[250];
+
+      memcpy(buffer, 0, sizeof(buffer));
+      strncpy_P(buffer, PSTR("/get.php?p=abc"), sizeof(buffer)-1);
+
+      strncpy_P(buffer+strlen(buffer), PSTR("&temp="), sizeof(buffer)-strlen(buffer)-1);
+      ltoa((int)dht.readTemperature(), buffer+strlen(buffer), 10);
+
+      strncpy_P(buffer+strlen(buffer), PSTR("&hum="), sizeof(buffer)-strlen(buffer)-1);
+      ltoa((int)dht.readHumidity(), buffer+strlen(buffer), 10);
+
+      strncpy_P(buffer+strlen(buffer), PSTR("&gas="), sizeof(buffer)-strlen(buffer)-1);
+      ltoa(analogRead(GASpin), buffer+strlen(buffer), 10);
+
+      strncpy_P(buffer+strlen(buffer), PSTR("&light="), sizeof(buffer)-strlen(buffer)-1);
+      ltoa(analogRead(PHOTOpin), buffer+strlen(buffer), 10);
+
+      strncpy_P(buffer+strlen(buffer), PSTR("&relay="), sizeof(buffer)-strlen(buffer)-1);
+      ltoa(lightBulb, buffer+strlen(buffer), 10);
+
+      strncpy_P(buffer+strlen(buffer), PSTR("&ms="), sizeof(buffer)-strlen(buffer)-1);
+      ltoa(millis()/1000, buffer+strlen(buffer), 10);
+
+      strncpy_P(buffer+strlen(buffer), PSTR("&lmdbu="), sizeof(buffer)-strlen(buffer)-1);
+      ltoa(LASTmotion, buffer+strlen(buffer), 10);
+
+      strncpy_P(buffer+strlen(buffer), PSTR("&alarm="), sizeof(buffer)-strlen(buffer)-1);
+      ltoa(alarm, buffer+strlen(buffer), 10);
+
+      Serial.print("Requesting UPLOAD");
+      Serial.print(buffer);
+      Serial.print(": ");
+
+      unsigned int httpResponseCode =
+        wifiSEND.GET
+        (
+          F("86.123.250.85"),
+          80,
+          buffer,
+          sizeof(buffer),
+          F("seba.tm-edu.ro"),
+          2
+
+
+        );
+
+      if(httpResponseCode == 200 || httpResponseCode == ESP8266_OK){
+        Serial.println("OK");
+        Serial.println(buffer);
+      }
+      else
+        if(httpResponseCode < 100)
+          wifiSEND.debugPrintError((byte)httpResponseCode, &Serial);
+        else{
+          Serial.print("HTTP Status ");
+          Serial.println(httpResponseCode);
+        }
+    WIFIupload=millis()/1000;
+  }
+
+
+  if(DEBUG)
+    for(int i=0;i<30;i++) Serial.println();
+  delay(2000);
 }
+
+void setColor(int red, int green, int blue)
+{
+  digitalWrite(pRed, red);
+  digitalWrite(pGrn, green);
+  digitalWrite(pBlu, blue);
+}
+
+void loadScreen(int j){
+  for(int i=1;i<=5;i++){
+    lcd.setCursor(j,1);
+    lcd.write(byte(i));
+    delay(140-j*5);
+  }
+}
+


moved serialEvent() into the main loop()

--- ArduinoMiniCloudMonitor/ArduinoMiniCloudMonitor.ino
+++ ArduinoMiniCloudMonitor/ArduinoMiniCloudMonitor.ino
@@ -1,8 +1,7 @@
 /*
  * MiniCloudMonitor
  *
- * A NodeJS application that opens a USB serial connection to a RGB LED light,
- * displaying AWS CloudWatch events triggered by AWS IoT MQTT events.
+ * Opens a serial connection to receive colour values to be displayed by the BlinkM RGB LED.
  * Based on BlinkM examples.
  *
  * BlinkM connections to Arduino
@@ -18,9 +17,8 @@
 #include "Wire.h"
 #include "BlinkM_funcs.h"

-const byte blinkm_addr = 0x09;   // i2c address of your BlinkM
+const byte blinkm_addr = 0x09;   // BlinkM i2c address
 String inputString = "";         // a string to hold incoming data
-boolean stringComplete = false;  // whether the string is complete

 void setup() {
@@ -45,36 +43,24 @@
 }

-void serialEventRun(void) {
-  if (Serial.available()) serialEvent();
-}
-
-
-void serialEvent() {
+void loop() {
   while (Serial.available()) {
     char inChar = (char)Serial.read();
-    inputString += inChar;
+
     if (inChar == '\n') {
-      stringComplete = true;
+      long number = strtol(inputString.c_str(), NULL, 16);
+
+      byte r = number >> 16;
+      byte g = number >> 8 & 0xFF;
+      byte b = number & 0xFF;
+
+      BlinkM_fadeToRGB(blinkm_addr, r, g, b);
+      inputString = "";
+
+    } else {
+      inputString += inChar;
     }
   }
 }

-void loop() {
-  if (stringComplete) {
-    long number = strtol(inputString.c_str(), NULL, 16);
-
-    byte r = number >> 16;
-    byte g = number >> 8 & 0xFF;
-    byte b = number & 0xFF;
-
-    BlinkM_stopScript(blinkm_addr);
-    BlinkM_fadeToRGB(blinkm_addr, r, g, b);
-
-    inputString = "";
-    stringComplete = false;
-  }
-}
-
-


We are not sending data to the client. We have problems with the websocketlib functions.

--- ServerSketch/ServerSketch.ino
+++ ServerSketch/ServerSketch.ino
@@ -102,7 +102,13 @@
     "/static/css/app.css", "text/css"                                           }
   ,
   {
+    "/static/css/jquery.mobile-1.4.1.css", "text/css"                                           }
+  ,
+  {
     "/static/css/jquery.mobile-1.4.1.min.css", "text/css"                                           }
+  ,
+  {
+    "/static/img/loading.gif", "image/gif"                                           }
   ,
   {
     "/static/js/app.js", "application/javascript"                                           }
@@ -211,6 +217,13 @@
     // Send Galileo's HW state to ALL clients
     // This function is continuesly called
     // **********************************
+    iNumBytes = sendStatusToWebsiteNew(wsi);
+    if (iNumBytes < 0)
+    {
+      lwsl_err("ERROR %d writing to socket\n", iNumBytes);
+      return 1;
+    }
+    /*
     getSerialCommand();
     if( !g_iNewCode )
     {
@@ -230,7 +243,7 @@
         return 1;
       }
     }
-
+*/
     break;

   case LWS_CALLBACK_RECEIVE:
@@ -413,19 +426,72 @@

   if( g_luiCounter%100 == 0)
   {
-    Serial.println("NEW CODE");
-
+    Serial.println("NEW CODE - WTF");
+/*
     unsigned char buf[LWS_SEND_BUFFER_PRE_PADDING + 512 + LWS_SEND_BUFFER_POST_PADDING];
     unsigned char *p = &buf[LWS_SEND_BUFFER_PRE_PADDING];

     updateBoardState();
     aJsonObject *msg = getJsonBoardState();
     char * pTempPointer = aJson.print(msg);
+//    String sTempString = aJson.print(msg);
+   // snprintf(buf,sizeof(buf),"%s",aJson.print(msg));
+
     p = (unsigned char *)pTempPointer;
     aJson.print(msg, &serial_stream);
+//    aJson.deleteItem(msg);
+
+    //n = sizeof(pTempPointer);
+//    n = sprintf(bufTwo,"%s",pTempPointer);
+    Serial.println("");
+    Serial.print("n: ");
+    Serial.println(n);
+ //   Serial.print("len: ");
+  //  Serial.println(    sTempString.length() );
+//    n = libwebsocket_write(wsi, p, n, LWS_WRITE_TEXT);
+    n = libwebsocket_write(wsi, p, 2000, LWS_WRITE_TEXT);
+    */
+
+    /*
+    unsigned char buf[LWS_SEND_BUFFER_PRE_PADDING + 2000 + LWS_SEND_BUFFER_POST_PADDING];
+    unsigned char *p = &buf[LWS_SEND_BUFFER_PRE_PADDING];
+
+    updateBoardState();
+    aJsonObject *msg = getJsonBoardState();
+    char * pTempPointer = "{\"status\":\"OK\",\"pins\":{ \"13\":{\"label\":\"Pin 13\",\"is_analog\":\"false\",\"is_input\":\"false\",\"value\":\"1\"}  }}"; //aJson.print(msg);
+//    String sTempString = aJson.print(msg);
+   // snprintf(buf,sizeof(buf),"%s",aJson.print(msg));
+
+    p = (unsigned char *)pTempPointer;
+    aJson.print(msg, &serial_stream);
+//    aJson.deleteItem(msg);
+
+    //n = sizeof(pTempPointer);
+//    n = sprintf(bufTwo,"%s",pTempPointer);
+    Serial.println("");
+    Serial.print("n: ");
+    Serial.println(n);
+ //   Serial.print("len: ");
+  //  Serial.println(    sTempString.length() );
+//    n = libwebsocket_write(wsi, p, n, LWS_WRITE_TEXT);
+    n = libwebsocket_write(wsi, p, 2000, LWS_WRITE_TEXT);
+
+
     aJson.deleteItem(msg);
-
+    */
+    unsigned char buf[LWS_SEND_BUFFER_PRE_PADDING + 512 + LWS_SEND_BUFFER_POST_PADDING];
+    unsigned char *p = &buf[LWS_SEND_BUFFER_PRE_PADDING];
+
+    //n = sprintf((char *)p, "%s","{\"status\":\"OK\",\"pins\":{ \"13\":{\"label\":\"Pin 13\",\"is_analog\":\"false\",\"is_input\":\"false\",\"sensitivity\":\"0.5\",\"is_inverted\":\"false\",\"is_visible\":\"true\",\"value\":\"1\"}  }}");
+//    n = sprintf((char *)p, "%s","{\"status\":\"OK\",\"pins\":{ \"13\":{\"label\":\"Pin 13\",\"is_analog\":false,\"is_input\":false,\"sensitivity\":0.5,\"is_inverted\":false,\"is_visible\":true,\"value\":1}  }}");
+//    n = sprintf((char *)p, "%s","{\"status\":\"OK\",\"pins\":{ \"14\":{\"label\":\"A0\",\"is_analog\":true,\"is_input\":true,\"sensitivity\":0.5,\"is_inverted\":false,\"is_visible\":true,\"value\":0.5}, \"3\":{\"label\":\"~3\",\"is_analog\":true,\"is_input\":false,\"sensitivity\":0.5,\"is_inverted\":false,\"is_visible\":true,\"value\":0.6}  }}");
+      n = sprintf((char *)p, "%s","{\"status\":\"OK\",\"pins\":{ \"14\":{\"label\":\"A0\",\"is_analog\":true,\"is_input\":true,\"sensitivity\":0.5,\"is_inverted\":false,\"is_visible\":true,\"value\":0.5}, \"3\":{\"label\":\"~3\",\"is_analog\":true,\"is_input\":false,\"sensitivity\":0.5,\"is_inverted\":false,\"is_visible\":true,\"value\":0.6}  },\"connections\":[{\"source\":\"14\",\"target\":\"3\"}] }");
+
+
     n = libwebsocket_write(wsi, p, n, LWS_WRITE_TEXT);
+
+
+
   }

   g_luiCounter++;


Code formatting clean up

Code formatting clean up

--- projects/arduino/led_matrix_256/led_matrix_256.ino
+++ projects/arduino/led_matrix_256/led_matrix_256.ino
@@ -1,7 +1,7 @@
 #include <Adafruit_NeoPixel.h>
 #ifdef __AVR__
-  #include <avr/power.h>
-  #include "IRremote.h"  //Remote control library
+#include <avr/power.h>
+#include "IRremote.h"  //Remote control library
 #endif

 #define PIN 4
@@ -16,183 +16,186 @@
 //int sensorPin = A5;    // select the input pin for the potentiometer
 //int sensorValue = 0;  // variable to store the value coming from the sensor

-  int frame;
-  int j;
-  uint32_t i;
-  uint32_t d=0;
-  uint32_t b=pow(2,7);
-  uint32_t g=pow(2,15);
-  uint32_t r=pow(2,23);
-  uint32_t p=b+r;
-  uint32_t y=g+r;
-  uint32_t a=b+g;
-  uint32_t w=b+g+r;
+int frame;
+int j;
+uint32_t i;
+uint32_t d=0;
+uint32_t b=pow(2,7);
+uint32_t g=pow(2,15);
+uint32_t r=pow(2,23);
+uint32_t p=b+r;
+uint32_t y=g+r;
+uint32_t a=b+g;
+uint32_t w=b+g+r;

 void setup() {
-  // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
-  #if defined (__AVR_ATtiny85__)
+    // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
+#if defined (__AVR_ATtiny85__)
     if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
-  #endif
-  // End of trinket special code
-
+#endif
+    // End of trinket special code
+
     irrecv.enableIRIn(); // Start the remote control receiver

-  Serial.begin(9600); // setup serial printing so you can troubleshoot
-  //Serial.print("i=");  //Print something to serial terminal for viewing
-  //Serial.print(i);
- strip.begin();
- strip.show(); // Initialize all pixels to 'off'
+    Serial.begin(9600); // setup serial printing so you can troubleshoot
+    //Serial.print("i=");  //Print something to serial terminal for viewing
+    //Serial.print(i);
+    strip.begin();
+    strip.show(); // Initialize all pixels to 'off'

 }

 void loop() {

-  //colorWipe(strip.Color(255, 0, 0), 10); // Red and time (not to exceed 255 since uint8_t is used below) to next LED
-  //rainbow(1);
-
-
-Serial.print("Frame in loop=");
-Serial.print(frame);
-Serial.println();
-delay(200);
-  //sensorValue = analogRead(sensorPin);  //read the analog input value and print it
-  //int frame = sensorValue/250;
-
-rainbowCycle(128);
-  //colorWipe1(strip.Color(0, 0, 255), 10); // Red and time to next LED
-    }
-
+    //colorWipe(strip.Color(255, 0, 0), 10); // Red and time (not to exceed 255 since uint8_t is used below) to next LED
+    //rainbow(1);
+
+
+    Serial.print("Frame in loop=");
+    Serial.print(frame);
+    Serial.println();
+    delay(200);
+    //sensorValue = analogRead(sensorPin);  //read the analog input value and print it
+    //int frame = sensorValue/250;
+
+    rainbowCycle(128);
+    //colorWipe1(strip.Color(0, 0, 255), 10); // Red and time to next LED
+}
+

 // Slightly different, this makes the rainbow equally distributed throughout
 void rainbowCycle(uint8_t wait) {
-frame=myRemoteRead();
-Serial.print("Frame in Show Routine=");
-Serial.print(frame);
-Serial.println();
+    frame=myRemoteRead();
+    Serial.print("Frame in Show Routine=");
+    Serial.print(frame);
+    Serial.println();
 //Frame 1
-if (frame==1) {
-
-uint32_t myMatrixRow1[256] = {d,d,w,w,d,d,d,d,d,d,d,d,d,d,d,d,
-                              d,d,d,d,d,d,d,d,d,d,d,w,d,w,d,d,
-                              d,d,d,w,d,w,d,d,d,d,d,d,d,d,d,d,
-                              d,d,d,d,d,d,d,d,d,w,d,d,d,d,d,d,
-                              d,d,d,d,d,d,w,w,w,w,w,d,d,d,d,d,
-                              d,d,d,d,d,w,w,w,w,w,d,d,d,d,d,d,
-                              d,d,d,d,d,r,r,r,g,r,r,r,d,d,d,d,
-                              d,d,d,r,r,r,r,g,r,r,r,r,d,d,d,d,
-                              d,d,d,r,r,r,r,g,g,g,r,r,r,r,d,d,
-                              d,d,r,r,r,r,g,g,g,r,r,r,r,d,d,d,
-                              d,d,d,r,r,r,g,g,g,g,g,r,r,r,d,d,
-                              d,d,r,r,g,g,g,g,g,g,g,r,r,d,d,d,
-                              d,d,d,r,g,g,g,g,g,g,g,g,g,r,d,d,
-                              d,d,d,r,r,r,r,y,r,r,r,r,d,d,d,d,
-                              d,d,d,d,d,r,r,r,y,r,r,r,d,d,d,d,
-                              d,d,d,d,d,r,r,y,r,r,d,d,d,d,d,d};
-
-for(i=0; i< strip.numPixels(); i++) {
-      strip.setPixelColor(i, myMatrixRow1[i]);
-      strip.setBrightness(1);
+    if (frame==1) {
+
+        uint32_t myMatrixRow1[256] = {d,d,w,w,d,d,d,d,d,d,d,d,d,d,d,d,
+                                      d,d,d,d,d,d,d,d,d,d,d,w,d,w,d,d,
+                                      d,d,d,w,d,w,d,d,d,d,d,d,d,d,d,d,
+                                      d,d,d,d,d,d,d,d,d,w,d,d,d,d,d,d,
+                                      d,d,d,d,d,d,w,w,w,w,w,d,d,d,d,d,
+                                      d,d,d,d,d,w,w,w,w,w,d,d,d,d,d,d,
+                                      d,d,d,d,d,r,r,r,g,r,r,r,d,d,d,d,
+                                      d,d,d,r,r,r,r,g,r,r,r,r,d,d,d,d,
+                                      d,d,d,r,r,r,r,g,g,g,r,r,r,r,d,d,
+                                      d,d,r,r,r,r,g,g,g,r,r,r,r,d,d,d,
+                                      d,d,d,r,r,r,g,g,g,g,g,r,r,r,d,d,
+                                      d,d,r,r,g,g,g,g,g,g,g,r,r,d,d,d,
+                                      d,d,d,r,g,g,g,g,g,g,g,g,g,r,d,d,
+                                      d,d,d,r,r,r,r,y,r,r,r,r,d,d,d,d,
+                                      d,d,d,d,d,r,r,r,y,r,r,r,d,d,d,d,
+                                      d,d,d,d,d,r,r,y,r,r,d,d,d,d,d,d
+                                     };
+
+        for(i=0; i< strip.numPixels(); i++) {
+            strip.setPixelColor(i, myMatrixRow1[i]);
+            strip.setBrightness(1);
             //delay(50);
-            }
-
-
-      //delay(4000);
-}
+        }
+
+
+        //delay(4000);
+    }

 //Frame 2
-else if (frame==2) {
-
-uint32_t myMatrixRow2[256] = {d,d,d,d,d,d,d,d,r,d,d,d,d,d,d,d,
-                              d,d,d,d,d,d,d,r,d,d,d,d,d,d,d,d,
-                              d,d,d,d,d,d,d,r,w,r,d,d,d,d,d,d,
-                              d,d,d,d,d,r,r,w,r,r,d,d,d,d,d,d,
-                              d,d,d,d,d,d,d,r,r,r,d,d,d,d,d,d,
-                              d,d,d,d,d,d,d,y,d,d,d,d,d,d,d,d,
-                              d,d,d,d,d,d,d,d,y,d,d,d,d,d,d,d,
-                              d,d,d,d,w,w,w,w,w,w,w,d,d,d,d,d,
-                              d,d,d,d,d,w,w,w,w,w,w,w,d,d,d,d,
-                              d,d,d,d,w,w,w,w,w,w,w,d,d,d,d,d,
-                              d,d,d,d,d,w,w,w,w,w,w,w,d,d,y,d,
-                              y,d,y,d,w,w,w,w,w,w,w,d,d,d,d,d,
-                              y,y,y,d,d,w,w,w,w,w,w,w,d,d,y,d,
-                              d,y,y,y,w,w,w,w,w,w,w,y,y,y,y,d,
-                              d,d,d,y,y,y,y,y,y,y,y,y,y,y,d,d,
-                              d,d,d,y,y,y,y,y,y,y,y,y,d,d,d,d};
-
-for(i=0; i< strip.numPixels(); i++) {
-      strip.setPixelColor(i, myMatrixRow2[i]);
-      strip.setBrightness(1);
+    else if (frame==2) {
+
+        uint32_t myMatrixRow2[256] = {d,d,d,d,d,d,d,d,r,d,d,d,d,d,d,d,
+                                      d,d,d,d,d,d,d,r,d,d,d,d,d,d,d,d,
+                                      d,d,d,d,d,d,d,r,w,r,d,d,d,d,d,d,
+                                      d,d,d,d,d,r,r,w,r,r,d,d,d,d,d,d,
+                                      d,d,d,d,d,d,d,r,r,r,d,d,d,d,d,d,
+                                      d,d,d,d,d,d,d,y,d,d,d,d,d,d,d,d,
+                                      d,d,d,d,d,d,d,d,y,d,d,d,d,d,d,d,
+                                      d,d,d,d,w,w,w,w,w,w,w,d,d,d,d,d,
+                                      d,d,d,d,d,w,w,w,w,w,w,w,d,d,d,d,
+                                      d,d,d,d,w,w,w,w,w,w,w,d,d,d,d,d,
+                                      d,d,d,d,d,w,w,w,w,w,w,w,d,d,y,d,
+                                      y,d,y,d,w,w,w,w,w,w,w,d,d,d,d,d,
+                                      y,y,y,d,d,w,w,w,w,w,w,w,d,d,y,d,
+                                      d,y,y,y,w,w,w,w,w,w,w,y,y,y,y,d,
+                                      d,d,d,y,y,y,y,y,y,y,y,y,y,y,d,d,
+                                      d,d,d,y,y,y,y,y,y,y,y,y,d,d,d,d
+                                     };
+
+        for(i=0; i< strip.numPixels(); i++) {
+            strip.setPixelColor(i, myMatrixRow2[i]);
+            strip.setBrightness(1);
             //delay(50);
-            }
-
-
-      //delay(1000);
-}
+        }
+
+
+        //delay(1000);
+    }

 //Frame 3
-else if (frame==3) {
-
-uint32_t myMatrixRow3[256] = {d,d,d,d,d,d,d,g,g,d,d,d,d,d,d,d,
-                              d,d,d,d,d,d,d,g,g,d,d,d,d,d,d,d,
-                              d,d,d,d,d,d,b,g,g,g,d,d,d,d,d,d,
-                              d,d,d,d,d,d,g,g,b,r,d,d,d,d,d,d,
-                              d,d,d,d,d,g,g,g,b,g,b,d,d,d,d,d,
-                              d,d,d,d,d,g,b,g,g,g,b,d,d,d,d,d,
-                              d,d,d,d,g,g,b,g,g,g,b,b,d,d,d,d,
-                              d,d,d,d,g,r,g,b,b,g,g,g,d,d,d,d,
-                              d,d,d,g,b,g,g,g,g,b,b,g,g,d,d,d,
-                              d,d,d,g,b,p,g,g,g,b,b,g,g,d,d,d,
-                              d,d,b,g,p,g,g,b,g,g,g,g,b,b,d,d,
-                              d,d,g,g,y,g,b,b,g,r,g,b,b,g,d,d,
-                              d,g,g,g,g,b,b,g,g,g,b,b,g,g,g,d,
-                              d,d,d,d,d,d,y,y,y,y,d,d,d,d,d,d,
-                              d,d,d,d,d,d,y,y,y,y,d,d,d,d,d,d,
-                              d,d,d,d,d,d,y,y,y,y,d,d,d,d,d,d};
-
-for(i=0; i< strip.numPixels(); i++) {
-      strip.setPixelColor(i, myMatrixRow3[i]);
-      strip.setBrightness(1);
+    else if (frame==3) {
+
+        uint32_t myMatrixRow3[256] = {d,d,d,d,d,d,d,g,g,d,d,d,d,d,d,d,
+                                      d,d,d,d,d,d,d,g,g,d,d,d,d,d,d,d,
+                                      d,d,d,d,d,d,b,g,g,g,d,d,d,d,d,d,
+                                      d,d,d,d,d,d,g,g,b,r,d,d,d,d,d,d,
+                                      d,d,d,d,d,g,g,g,b,g,b,d,d,d,d,d,
+                                      d,d,d,d,d,g,b,g,g,g,b,d,d,d,d,d,
+                                      d,d,d,d,g,g,b,g,g,g,b,b,d,d,d,d,
+                                      d,d,d,d,g,r,g,b,b,g,g,g,d,d,d,d,
+                                      d,d,d,g,b,g,g,g,g,b,b,g,g,d,d,d,
+                                      d,d,d,g,b,p,g,g,g,b,b,g,g,d,d,d,
+                                      d,d,b,g,p,g,g,b,g,g,g,g,b,b,d,d,
+                                      d,d,g,g,y,g,b,b,g,r,g,b,b,g,d,d,
+                                      d,g,g,g,g,b,b,g,g,g,b,b,g,g,g,d,
+                                      d,d,d,d,d,d,y,y,y,y,d,d,d,d,d,d,
+                                      d,d,d,d,d,d,y,y,y,y,d,d,d,d,d,d,
+                                      d,d,d,d,d,d,y,y,y,y,d,d,d,d,d,d
+                                     };
+
+        for(i=0; i< strip.numPixels(); i++) {
+            strip.setPixelColor(i, myMatrixRow3[i]);
+            strip.setBrightness(1);
             //delay(50);
-            }
-
-
-      //delay(1000);
-}
-if (frame<=3){
+        }
+
+
+        //delay(1000);
+    }
+    if (frame<=3) {
         if(frame>=0) {
-        strip.show();
-      }
-      }
+            strip.show();
+        }
+    }
 //delay(5000);
 }

-int myRemoteRead(){
-int remoteframe=3;
-Serial.print("remoteframe=");
-Serial.print(remoteframe);
-Serial.println();
-if (irrecv.decode(&results)) // have we received an IR signal?
+int myRemoteRead() {
+    int remoteframe=3;
+    Serial.print("remoteframe=");
+    Serial.print(remoteframe);
+    Serial.println();
+    if (irrecv.decode(&results)) // have we received an IR signal?
     {
 //switch(results.value){
-if(results.value==0xA3C8EDDB){
+        if(results.value==0xA3C8EDDB) {

 //case 0xA3C8EDDB: // + button pressed
-remoteframe=1;  //set frame to 1 if remote control + button is pressed
-return remoteframe;
+            remoteframe=1;  //set frame to 1 if remote control + button is pressed
+            return remoteframe;
 //break;
-}
-
-else if (results.value==0xE5CFBD7F){
+        }
+
+        else if (results.value==0xE5CFBD7F) {
 //case 0xE5CFBD7F: // - button pressed
-remoteframe=2;  //set frame to 1 if remote control + button is pressed
-return remoteframe;
+            remoteframe=2;  //set frame to 1 if remote control + button is pressed
+            return remoteframe;
 //break;
-  }
+        }

 //frame=3; //set frame to default 3

-}
+    }
 //irrecv.resume(); // receive the next value
-return remoteframe;
-}
+    return remoteframe;
+}


Add DHT Sensor

Add DHT Sensor

--- ArduinoSensorBoard/ArduinoSensorBoard.ino
+++ ArduinoSensorBoard/ArduinoSensorBoard.ino
@@ -1,9 +1,14 @@
 #include <SPI.h>
 #include "nRF24L01.h"
 #include "RF24.h"
+#include "DHT.h"
 //#include "printf.h"

+#define DHTPIN 2
+#define DHTTYPE DHT11
+
 RF24 radio(9,10);
+DHT dht(DHTPIN, DHTTYPE);

 const uint64_t pipes[2] = { 0xF0F0F0F001LL, 0xF0F0F0F002LL };
 const byte shortAddr = 0x02;
@@ -14,8 +19,10 @@
 void setup(void)
 {
   Serial.begin(57600);
-
+
+  dht.begin();
   radio.begin();
+
   radio.setAutoAck(false);
   radio.setRetries(15,15);
   radio.setPALevel(RF24_PA_MAX);
@@ -48,7 +55,7 @@
       if (pipenum==1){
           runCommand(ptr);
       }
-      Serial.println(ptr[12]);
+      Serial.println(ptr[13]);

       radio.stopListening();
       radio.write(ptr, sizeof(byte[32]));
@@ -94,12 +101,24 @@

 }
 void readTemp(byte* ptr){
-  ptr[12] = 255;
-  ptr[13] = 2;
+  float t = dht.readTemperature();
+  if (!isnan(t)){
+    ptr[13] = (byte)t;
+    ptr[12] = 255;
+  }else{
+    ptr[12] = 13;
+  }
+
+
 }
 void readHum(byte* ptr){
-  ptr[12] = 255;
-  ptr[14] = 23;
+  float h = dht.readHumidity();
+  if (!isnan(h)){
+    ptr[14] = (byte)h;
+    ptr[12] = 255;
+  }else{
+    ptr[12] = 14;
+  }
 }
 void readLum(byte* ptr){
   ptr[12] = 255;


Cleaning up Interactive Drawing

Cleaning up Interactive Drawing

Removing un-used functions and irrelevant comments. Adding licensing.

--- sketches/InteractiveDrawing/InteractiveDrawing.ino
+++ sketches/InteractiveDrawing/InteractiveDrawing.ino
@@ -1,3 +1,12 @@
+/*
+
+Copyright (c) 2013 - Philippe Laulheret, Second Story [http://www.secondstory.com]
+
+This code is protected under MIT license.
+For more information visit  : https://github.com/secondstory/LYT
+
+*/
+
 #include <Dhcp.h>
 #include <Dns.h>
 #include <WiFi.h>
@@ -99,47 +108,6 @@
 }

-void hsvtorgb(unsigned char *r, unsigned char *g, unsigned char *b, unsigned char h, unsigned char s, unsigned char v)
-{
-  //from http://web.mit.edu/storborg/Public/hsvtorgb.c
-    unsigned char region, fpart, p, q, t;
-
-    if(s == 0) {
-        /* color is grayscale */
-        *r = *g = *b = v;
-        return;
-    }
-
-    /* make hue 0-5 */
-    region = h / 43;
-    /* find remainder part, make it from 0-255 */
-    fpart = (h - (region * 43)) * 6;
-
-    /* calculate temp vars, doing integer multiplication */
-    p = (v * (255 - s)) >> 8;
-    q = (v * (255 - ((s * fpart) >> 8))) >> 8;
-    t = (v * (255 - ((s * (255 - fpart)) >> 8))) >> 8;
-
-    /* assign temp vars based on color cone region */
-    switch(region) {
-        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;
-        default:
-            *r = v; *g = p; *b = q; break;
-    }
-
-    return;
-}
-
-

@@ -171,7 +139,6 @@
     {

      decay_brightness(i);
-    //hsvtorgb(&r,&g,&b,(int) current_hue,default_sat, (int) bright[i]);
      getRGBFromHSB(r,g,b,current_hue,default_sat,  bright[i]);
     pixelBuffer[3*i] = r;
     pixelBuffer[3*i+1] = g;
@@ -188,7 +155,6 @@
 void updateStrip()
 {

-

   unsigned char* ptr = strip.pixels;
   unsigned char* pxBuf = pixelBuffer;
@@ -205,12 +171,7 @@
         if (even) ptr +=1;
       }
     }
-   // unsigned char r,g,b;
-    //if (bright[i] > default_brightness) bright[i] = std::max((float) bright[i] - decaySpeed*exp(,(float) default_brightness);
-    //decay_brightness(i);
-    //hsvtorgb(&r,&g,&b,(int) current_hue,default_sat, (int) bright[i]);
-    //setHsv(r,g,b,current_hue,default_sat,  bright[i]);
-    //strip.setPixelColor(i,r,g,b);
+
     if (even)
     {
       *ptr++ =*pxBuf++;


print out ID1, ID2, ID3 registers

print out ID1, ID2, ID3 registers

--- ili9488.ino
+++ ili9488.ino
@@ -7,6 +7,10 @@
 #define SCL 3   // clock, rising edge
 #define SDA 4   // data in to ILI9488
 #define SDO 5   // data out from ILI9488
+
+#define ILI9488_CMD_READ_ID1  0xDA
+#define ILI9488_CMD_READ_ID2  0xDB
+#define ILI9488_CMD_READ_ID3  0xDC

 void setup()
 {
@@ -43,20 +47,41 @@
   digitalWrite(CSX, HIGH);
 }

-void loop()
+uint8_t rdreg(uint8_t reg)
 {
+  uint8_t r;
+
   digitalWrite(DCX, LOW);
-  out_8(0xda);  // RDID1
+  out_8(reg);

-  Serial.println();
   digitalWrite(DCX, HIGH);
   digitalWrite(CSX, LOW);
   for (int i = 0; i < 8; i++) {
     digitalWrite(SCL, LOW);
     digitalWrite(SCL, HIGH);
-    Serial.println(digitalRead(SDO), DEC);
+    r = (r << 1) | digitalRead(SDO);
   }
   digitalWrite(CSX, HIGH);
+  return r;
+}
+
+uint8_t wrreg(uint8_t reg, uint8_t val)
+{
+  digitalWrite(DCX, LOW);
+  out_8(reg);
+  digitalWrite(DCX, HIGH);
+  out_8(val);
+}
+
+void loop()
+{
+  Serial.println();
+  Serial.print("ID1: ");
+  Serial.println(rdreg(ILI9488_CMD_READ_ID1), HEX);
+  Serial.print("ID2: ");
+  Serial.println(rdreg(ILI9488_CMD_READ_ID2), HEX);
+  Serial.print("ID3: ");
+  Serial.println(rdreg(ILI9488_CMD_READ_ID3), HEX);

   delay(3000);
 }


fixup baud on graph

fixup baud on graph

--- html/examples/04.Communication/Graph/Graph.ino
+++ html/examples/04.Communication/Graph/Graph.ino
@@ -28,7 +28,7 @@

 void setup() {
   // initialize the serial communication:
-  Serial.begin(9600);
+  Serial.begin(115200);
 }

 void loop() {


moving arduino and webinterface to on/off_ramp

--- arduino/arduino.ino
+++ arduino/arduino.ino
@@ -85,7 +85,6 @@
 // Global status variabels
 boolean fadeStepFlag = false;
 boolean publishSensorsFlag = false;
-boolean fadeStepToTargetColorFlag = false;

 int fadecounter = 0;
 int fadetToTargetCounter = 0;
@@ -143,14 +142,25 @@
 //
 //

-void setAmbilightValue(double value) {
-  ambilightValue = value;
+void setAmbilightValue(int value) {
+      Serial.println(value);
+
+//  Serial.print("new value is: ");
+ // Serial.println(value);
+  ambilightValue = round(1.0*value*(360.0/255));
+  Serial.print("new value is: ");
+  Serial.println(ambilightValue);
+
   setLedColorHSV(ambilightHue,1,ambilightValue); //Staturation constant at 1
 }

 void setAmbilightHue(int hue) {
-  ambilightHue = hue;
+
+    ambilightHue =hue;
+    Serial.print("new hue is: ");
+  Serial.println(ambilightHue);
+
   setLedColorHSV(ambilightHue,1,ambilightValue); //Staturation constant at 1
 }

@@ -162,24 +172,43 @@
   //Serial.print("Received MQTT message:");
   //Serial.println(payload);

-
+// TODO: PUBLISH VALUES TO OTHER SIDE OF RAMP
   if (strcmp(topic, DEVICE_1_ON_RAMP_VALUE) == 0) {
-    double value;
-    sscanf(payload, "%f", &value);
+    int value; // 0-255 => convert to float
+    Serial.println(payload);
+    sscanf(payload, "%d", &value);
     setAmbilightValue(value);
+
+    publishRetained(DEVICE_1_OFF_RAMP_VALUE,  payload);
+
+
   } else if (strcmp(topic, DEVICE_1_ON_RAMP_HUE) == 0) {
     int hue;
-    sscanf(payload, "%f", &hue);
-    setAmbilightHue(hue);
+    Serial.println("receive");
+    Serial.println(payload);
+
+    sscanf(payload, "%d", &hue);
+
+
+
+    setAmbilightHue(hue*(360/255));
+        //publishRetained(DEVICE_1_OFF_RAMP_HUE,  payload);
+
+
   } else if(strcmp(topic, DEVICE_1_ON_RAMP_POWER) == 0) {
     setWifi((char*)payload, wifiSwitchHomeGroup, 1);
+
+
+
   } else if(strcmp(topic, DEVICE_1_ON_RAMP_FADING)  == 0 ) {
     fadeStepFlag  = !(*payload == '0');
-    fadeStepToTargetColorFlag = false;
+
   } else if(strcmp(topic, DEVICE_2_ON_RAMP_POWER)  == 0) {
     setWifi((char*)payload, wifiSwitchHomeGroup, 2);
+
   }else if(strcmp(topic,DEVICE_3_ON_RAMP_POWER)  == 0) {
     setWifi((char*)payload, wifiSwitchHomeGroup, 3);
+
   } else if (strcmp(topic, "/devices/321995-ambilight/actions/wakeup") == 0) {
     Serial.println("wakeup");
   }
@@ -291,7 +320,7 @@

      char buffer[4];
      sprintf(buffer, "%s", ambilightValue);
-     publishRetained(DEVICE_1_OFF_RAMP_VALUE,  buffer);
+     publishRetained(DEVICE_1_ON_RAMP_VALUE,  buffer);
   }
 }

@@ -299,9 +328,10 @@
 void fadeLoop() {
   ambilightHue = ambilightHue < 360 ? ambilightHue+1 : 0;

-  char buffer[3];
-  sprintf(buffer, "%s", ambilightHue);
-  publishRetained(DEVICE_1_OFF_RAMP_HUE,  buffer);
+//   Serial.println(ambilightHue);
+  char buffer[6];
+  sprintf(buffer, "%f", 1.0*ambilightHue*(255.0/360));
+  //spublishRetained(DEVICE_1_ON_RAMP_HUE,  buffer);
 }

 void sensorLoop(){
@@ -316,7 +346,7 @@
   client.loop();

   if (sensorcounter % 65000 == 0) {
-    sensorLoop();
+  //  sensorLoop();
     sensorcounter= 0;
   }


Sped up turn timeout

Sped up turn timeout

For fast robots, the turn timeout was too long.  This makes it a bit
more reasonable.

--- examples/_2020Bot_Demo/_2020Bot_Demo.ino
+++ examples/_2020Bot_Demo/_2020Bot_Demo.ino
@@ -237,11 +237,11 @@
           break;
         case Left:
           motor.left(speed);
-          delayTimer = millis() + 250;
+          delayTimer = millis() + 100;
           break;
         case Right:
           motor.right(speed);
-          delayTimer = millis() + 250;
+          delayTimer = millis() + 100;
           break;
         case Stop:
           motor.stop();


fix:delete 192.168,0.28 from configTime arguments

--- examples/digital_clock/digital_clock.ino
+++ examples/digital_clock/digital_clock.ino
@@ -43,7 +43,7 @@
   Serial.print("IP address: ");
   Serial.println(WiFi.localIP());

-	configTime( JST, 0, "ntp.nict.jp", "ntp.jst.mfeed.ad.jp", "192.168.0.28");
+	configTime( JST, 0, "ntp.nict.jp", "ntp.jst.mfeed.ad.jp");
 }

 void loop(void){


Update motor_control.ino

Update motor_control.ino

--- Arduino/examples/motor_control.ino
+++ Arduino/examples/motor_control.ino
@@ -5,43 +5,10 @@

 scratch_n_sketch sns;
 /*
-void setup() {
-Serial.begin(115200);
-
-sns.begin(5);
-delay(1000);
-
-sns.fillScreen(15, 167, 255);
-sns.penColor(255, 255, 255);
-sns.fillRectangle(0, 0 , 239, 249);
-sns.textBackColor(15, 167, 255);
-sns.setFont();
-sns.drawText("Temperature", 50, 260);
-delay(10);
-}
-
-void loop() {
-
-sns.penColor(random(10, 255), random(10, 255), random(10, 255));
-
-sns.getSensorData();
-
-int tsx = map(sns.sensor.TouchX, 173, 904, 0, 239);
-int tsy = map(sns.sensor.TouchY, 53, 964, 0, 319);
-
-if(tsx > 0  && tsy > 0)
-sns.fillCircle(tsx, tsy, 2);
-
-delay(50);
-
-sns.penColor(255, 255, 0);
-float tp = sns.sensor.TempSensor;
-sprintf(ch, "%03d", (int)tp);
-sns.drawText(ch, 100, 290);
-delay(50);
-}
+* motor speed control demo
+* (c) 2015 warefab
+* autho : muchiri john
 */
-
 uint16_t xpos, ypos, count, pc;

 void setup(){
@@ -120,46 +87,3 @@
   }
   delay(50);
 }
-/*
-//draw graph : using A0 analog noise
-void setup()
-{
-sns.begin(5);
-delay(1000);
-Serial.begin(115200);
-// position of the line on screen
-xpos = 10;
-// clear the screen with a pretty color
-sns.fillScreen(0, 0, 0);
-sns.rotateDisplay(sns.rotate.rotate_90);
-sns.penColor(250, 180, 10);
-sns.setFont(sns.font.terminal);
-sns.drawText("LIGHT SENSOR", 90, 20);
-}
-int drawHeight;
-void loop()
-{
-// read the sensor and map it to the screen height
-sns.getSensorData();
-delay(10);
-drawHeight = (int)(map(sns.sensor.LightSensor, 0, 1023, 10, sns.height-60));
-// draw a line in a nice color
-sns.drawLine(xpos, sns.height - 10, xpos, sns.height - drawHeight);
-sprintf(ch, "%04d", sns.sensor.LightSensor);
-sns.penColor(10, 180, 250);
-sns.drawText(ch, 140, 40);
-sns.penColor(250, 180, 10);
-// if the graph has reached the screen edge
-// erase the screen and start again
-if (xpos >= sns.width) {
-xpos = 10;
-sns.fillScreen(0, 0, 0);
-sns.drawText("LIGHT SENSOR", 90, 20);
-}
-else {
-// increment the horizontal position:
-xpos++;
-}
-delay(100);
-}
-*/


started refectoring the meow sketch, no idea if it'll work because I'm on a plane right now

--- sketches/meowshoes.ino
+++ sketches/meowshoes.ino
@@ -4,41 +4,57 @@
   MEOW

  */
-
-bool leftStand = true;
-bool rightStand = true;

-int pendingTapLeft = -1;
-int pendingTapRight = -1;
-int tapTimeoutLeftToe = 0;
-int tapTimeoutRightToe = 0;
-int tapTimeoutLeftHeel = 0;
-int tapTimeoutRightHeel = 0;
-
-int leftToeVal = 0;
-int leftHeelVal = 0;
-int rightToeVal = 0;
-int rightHeelVal = 0;
-
-// These constants won't change.  They're used to give names
-// to the pins used:
-const int leftToePin = 0;
-const int leftHeelPin = 1;
-const int rightToePin = 2;
-const int rightHeelPin = 3;
-const int tapTimeoutThresh = 30;

 void setup() {
+
+  // flag for user standing
+  bool leftStand  = true;
+  bool rightStand = true;
+
+  // a foot tap is pending but not confirmed
+  int pendingTapLeft  = -1;
+  int pendingTapRight = -1;
+
+  // setting up whether a pending foot tap times out or not
+  int tapTimeoutLeftToe   = 0;
+  int tapTimeoutRightToe  = 0;
+  int tapTimeoutLeftHeel  = 0;
+  int tapTimeoutRightHeel = 0;
+
+  // these will store the analog values received from the pressure sensors
+  int leftToeVal   = 0;
+  int leftHeelVal  = 0;
+  int rightToeVal  = 0;
+  int rightHeelVal = 0;
+
+  // constants defining the ardiuno analog pins used
+  const int leftToePin   = 0;
+  const int leftHeelPin  = 1;
+  const int rightToePin  = 2;
+  const int rightHeelPin = 3;
+
+  // how long the threshold is for a tap to timeout and not be confirmed
+  // this number is the milliseconds divisible by 10 as we delay for 10ms between each read later
+  const int tapTimeoutThresh = 30;
+
   // initialize serial communications at 9600 bps:
   Serial.begin(9600);
 }

 void loop() {
-
+
+  monitorFeet();
+
+}
+
+// this is the guts of it, the filter of the analog data into actual foot taps to be sent over serial
+void monitorFeet() {
+
     // read *all* of the pins!
-    leftToeVal = analogRead(leftToePin);
-    leftHeelVal = analogRead(leftHeelPin);
-    rightToeVal = analogRead(rightToePin);
+    leftToeVal   = analogRead(leftToePin);
+    leftHeelVal  = analogRead(leftHeelPin);
+    rightToeVal  = analogRead(rightToePin);
     rightHeelVal = analogRead(rightHeelPin);

     // if tap is already pending, and the tap lasted for at least 300 milliseconds
@@ -75,25 +91,30 @@

     // if left toe is pressed, set pending tap and increment time tapped for
     // make sure to check that heel is not also down, otherwise the user is standing/pausing
-    if (isPressed(leftToeVal) == true && isPressed(leftHeelVal) == false) {
+    if (isPressed(leftToeVal) && !isPressed(leftHeelVal)) {
         pendingTapLeft = leftToePin;
         tapTimeoutLeftToe++;

-     } else if (isPressed(leftHeelVal) == true && isPressed(leftToeVal) == false) {
+    // if left heel is pressed, set pending tap and increment time tapped for
+    // make sure to check that toe is not also down, otherwise the user is standing/pausing
+     } else if (isPressed(leftHeelVal) && !isPressed(leftToeVal)) {
         pendingTapLeft = leftHeelPin;
         tapTimeoutLeftHeel++;

-     } else if (isPressed(rightHeelVal) == true && isPressed(rightToeVal) == false) {
+    // if right heel is pressed, set pending tap and increment time tapped for
+    // make sure to check that toe is not also down, otherwise the user is standing/pausing
+     } else if (isPressed(rightHeelVal) && !isPressed(rightToeVal)) {
         pendingTapRight = rightHeelPin;
         tapTimeoutRightHeel++;
-
-     } else if (isPressed(rightToeVal) == true && isPressed(rightHeelVal) == false) {
+
+    // if right toe is pressed, set pending tap and increment time tapped for
+    // make sure to check that heel is not also down, otherwise the user is standing/pausing
+     } else if (isPressed(rightToeVal) && !isPressed(rightHeelVal)) {
         pendingTapRight = rightToePin;
         tapTimeoutRightToe++;

-
      } else {
-      // their toe came back up
+      // their foot came back up
        pendingTapLeft = -1;
        tapTimeoutLeftToe = 0;
        delay(10);
@@ -102,20 +123,25 @@
   // wait 10 milliseconds before the next loop
   // for the analog-to-digital converter to settle
   // after the last reading:
-  delay(10);
+  delay(10);
 }

-// checks the sensor value
+// checks the sensor value to see if it's at a value suggesting pressure on it
 bool isPressed(int val) {
-      if (val < 30) {
-        return true;
-      } else {
-        return false;
-      }
+
+  // this 30 val below will need to change when you solder the pins properly :P
+  // it'll most likely be like 995 or something similar
+  // that number is calibrated to my weight, tap strength and particular sensors
+  if (val < 30)
+    return true else return false;
+
 }

 // prints the pin number to serial for javascript to pick up and use to play and sequence sounds
 void sendTap(int pinNo) {
+    // print the pin number to serial, node can recognise it and go from there
      Serial.println(pinNo);
+
+     // not sure why this delay is in here, I think it was a desparate hackathon move
      delay(10);
 }