setting and blinking

setting and blinking

--- moros/moros.ino
+++ moros/moros.ino
@@ -311,7 +311,6 @@
       serprintf("Done setting clocks, resetting\r\n");
       reset();
     }
-    // XXX blink the clocks correctly
   }

   void reset() {
@@ -339,7 +338,7 @@
     unsigned long press_duration_ms = state->press_duration_ms;
     bool button_pressed = state->pressed;
     bool just_released = state->just_released;
-
+//    serprintf("bp: %d jr: %d dms: %lu gs: %d\r\n", button_press, just_released, press_duration_ms, game_state);

     switch (game_state) {
       case PRE_GAME:
@@ -351,11 +350,14 @@
         break;
       case IN_PROGRESS:
         if (button_pressed) {
-          if (press_duration_ms > mode_button_reset_ms) {
-            reset();
-          } else if (press_duration_ms > 0) {
+          if (press_duration_ms > 0) {
             pause();
           }
+        }
+        break;
+      case PAUSED:
+        if (press_duration_ms > mode_button_reset_ms) {
+          reset();
         }
         break;
       case SET_TIME:
@@ -365,53 +367,11 @@
         break;
       case SET_TIME_CLOCK_1:
       case SET_TIME_CLOCK_2:
-        if (press_duration_ms > 0) {
+        if (just_released) {
           set_time_next_step();
         }
         break;
     }
-/*
-    //unsigned long mode_button_held = mode_button->poll();
-    unsigned long mode_button_held = state->press_duration_ms;
-    bool button_pressed = state->pressed;
-
-    if (game_state != SET_TIME && button_pressed) {
-      if (mode_button_held > 0) {
-        pause();
-      }
-      if (mode_button_held > mode_button_poweroff_ms) {
-        power_off();
-      } else if (mode_button_held > mode_button_settime_ms) {
-        set_time();
-      } else if (mode_button_held > mode_button_reset_ms) {
-        reset();
-      }
-    } else if (game_state == SET_TIME) {
-//      serprintf("mode button, _in_ SET_TIME, button_pressed is %d held for %lu and previous %lu\r\n", button_pressed, mode_button_held, mode_button_previous_hold_time_ms);
-      // we don't want to be in here because we changed state but the button is still pressed
-
-      if ((mode_button_held < mode_button_previous_hold_time_ms) && !button_pressed) {
-        serprintf("reset button was held for %lu and is pressed: %d\r\n", state->press_duration_ms, state->pressed);
-        // move to the next clock to set or exit
-        serprintf("in handle_mode_button, calling set_time_next_step\r\n");
-        set_time_next_step();
-      }
-    } else {
-      if (mode_button_held > 0 && button_pressed) {
-        serprintf("Mode button held for %lu an is pressed=%d with game state:%d\r\n", mode_button_held, button_pressed, game_state);
-      }
-    }
-    mode_button_last_pressed_state = state->pressed;
-
-    if (mode_button_last_pressed_at_ms != state->pressed_at) {
-        mode_button_last_pressed_at_ms = state->pressed_at;
-    }
-
-    if (!button_pressed && (mode_button_held < mode_button_previous_hold_time_ms || mode_button_previous_hold_time_ms == 0)) {
-//      serprintf("mode_button_held %lu mode_button_previous_hold_time_ms %lu\r\n", mode_button_held, mode_button_previous_hold_time_ms);
-      mode_button_previous_hold_time_ms = mode_button_held;
-    }
-    */
   }

@@ -502,7 +462,6 @@

   void tick() {
     unsigned long tick_ms = millis(); // the start of this tick
-
     switch (game_state) {
       case INIT:
         return;
@@ -519,9 +478,16 @@
         players[active_player]->tick();
         break;
       case SET_TIME:
+        break;
       case SET_TIME_CLOCK_1:
       case SET_TIME_CLOCK_2:
         handle_set_time_player_buttons();
+        if (tick_ms > blink_start_ms + 1500) {
+           blink_start_ms = tick_ms;
+           players[clock_being_set]->blank_text();
+        } else if (tick_ms > blink_start_ms + 500) {
+           players[clock_being_set]->update_display();
+        }
         break;
       case PAUSED:
         handle_paused_player_buttons();
@@ -531,69 +497,6 @@
         break;
     }
     handle_mode_button();
-/*
-    if (interrupt_fired != NONE) {
-      // Someone pressed a button since the last time we checked.
-      int player_who_pressed = interrupt_to_player(interrupt_fired);
-
-      if (player_who_pressed == NONE) {
-        // Unrecognized button interrupt
-        serprintf("received interrupt %d, but no player has a button on that interrupt!\r\n", interrupt_fired);
-
-      } else if (game_state != SET_TIME && (active_player == NONE || player_who_pressed == active_player)) {
-        // either it was nobody's turn, or the active player pressed their button
-        serprintf("Got a player button press from button %d\r\n", player_who_pressed);
-
-        if (players[player_who_pressed]->out_of_time()) {
-          // the other player is already out of time, so ignore
-          active_player = NONE;
-        } else {
-          serprintf("Player %d ended turn by button press.\r\n", player_who_pressed);
-          // switch to the opposite player from the one whose button was pressed
-          active_player = (player_who_pressed+1) % 2;
-          game_state = IN_PROGRESS;
-          players[active_player]->clock->start();
-        }
-      } else if (game_state == SET_TIME) {
-        serprintf("Setting the time, got player button %d clock being set:%d\r\n", player_who_pressed, clock_being_set);
-        if (player_who_pressed == 0) {
-          players[clock_being_set]->clock->add_minute();
-        } else if (player_who_pressed == 1) {
-          players[clock_being_set]->clock->subtract_minute();
-        }
-      } else {
-        serprintf("Ignoring button press for inactive player %d\r\n", player_who_pressed);
-      }
-
-      interrupt_fired = NONE;
-    }
-
-    handle_mode_button();
-
-    if (active_player != NONE) {
-      // It's someone's turn:
-
-      // Check for flag
-      if (players[active_player]->out_of_time()) {
-        serprintf("Flag fell for player %d\r\n", active_player);
-        players[active_player]->flag();
-        active_player = NONE;
-        return;
-      }
-      if (game_state == IN_PROGRESS) {
-        players[active_player]->tick();
-      }
-    }
-
-    if (game_state == SET_TIME) {
-      if (tick_ms > blink_start_ms + 1500) {
-         blink_start_ms = tick_ms;
-         players[clock_being_set]->blank_text();
-      } else if (tick_ms > blink_start_ms + 500) {
-         players[clock_being_set]->update_display();
-      }
-    }
-    */
   }
 };
 int Controller::active_player = NONE;


- add command "s"(sound) which triggered when sound start - brightness

--- arduino-neopixel.ino
+++ arduino-neopixel.ino
@@ -21,8 +21,15 @@
 String input_str;   // 文字列格納用
 int i = 0;  // 文字数のカウンタ

-uint32_t instrument_color = 0;
-uint32_t effect_color = 0;
+int i_color_r = 0;
+int i_color_g = 0;
+int i_color_b = 0;
+int e_color_r = 0;
+int e_color_g = 0;
+int e_color_b = 0;
+
+#define BRIGHTNESS_MIN 0.5 // 平常時のBrightness
+float brightness = 1;

 void setup() {
   strip.begin();
@@ -34,38 +41,17 @@
   colorWipe(0, DELAY_TIME);
 }

-//void loop() {
-//    if (0<Serial.available()) {
-//      // 255,255,255 255,255,255
-//      String str = Serial.readStringUntil('\n');
-//      int inst_r = str.substring(0,3).toInt();
-//      int inst_g = str.substring(4,7).toInt();
-//      int inst_b = str.substring(8,11).toInt();
-//
-//      // あまり強く光らせると色が安定しないのでリミットを設ける
-//      int _inst_r = constrainValue(inst_r);
-//      int _inst_g = constrainValue(inst_g);
-//      int _inst_b = constrainValue(inst_b);
-//      Serial.println("::: setColor :::");
-//      Serial.println("instrument:["+String(inst_r)+","+String(inst_g)+","+String(inst_b)+"] constrains to ["+String(_inst_r)+","+String(_inst_g)+","+String(_inst_b)+"]");
-//
-//      instrument_color = strip.Color(_inst_r, _inst_g, _inst_b);
-//      updateLED();
-//    }
-//}
-
 void loop() {
   if (0<Serial.available()) {
     String command = Serial.readStringUntil(':');
     String argument = Serial.readStringUntil(';');
-    if(command=="i") {
+    if(command=="i") { // set instrument color
       Serial.println(command);
       if(argument.length()==11) {
         // argument likes "255.255.255"
-        int r = constrainValue(argument.substring(0,3).toInt());
-        int g = constrainValue(argument.substring(4,7).toInt());
-        int b = constrainValue(argument.substring(8,11).toInt());
-        instrument_color = strip.Color(r, g, b);
+        i_color_r = constrainValue(argument.substring(0,3).toInt());
+        i_color_g = constrainValue(argument.substring(4,7).toInt());
+        i_color_b = constrainValue(argument.substring(8,11).toInt());
         updateLED();
       }
       else {
@@ -73,13 +59,12 @@
         Serial.println(argument);
       }
     }
-    else if(command=="e") {
+    else if(command=="e") { // set effect color
       if(argument.length()==11) {
         // argument likes "255.255.255"
-        int r = constrainValue(argument.substring(0,3).toInt());
-        int g = constrainValue(argument.substring(4,7).toInt());
-        int b = constrainValue(argument.substring(8,11).toInt());
-        effect_color = strip.Color(r, g, b);
+        e_color_r = constrainValue(argument.substring(0,3).toInt());
+        e_color_g = constrainValue(argument.substring(4,7).toInt());
+        e_color_b = constrainValue(argument.substring(8,11).toInt());
         updateLED();
       }
       else {
@@ -87,9 +72,18 @@
         Serial.println(argument);
       }
     }
+    else if(command=="s") { // sound trigger
+      brightness = 1.0;
+    }
     else {
       Serial.print("Command not found:");
       Serial.println(command);
+    }
+  }
+  else {
+    if(BRIGHTNESS_MIN < brightness) {
+      brightness -= 0.01;
+      updateLED();
     }
   }
 }
@@ -115,6 +109,8 @@
 }

 void updateLED() {
+  uint32_t instrument_color = multiplicateBrightness(i_color_r, i_color_g, i_color_b);
+  uint32_t effect_color = multiplicateBrightness(e_color_r, e_color_g, e_color_b);
   for(uint16_t i=0; i<strip.numPixels(); i++) {
     if(i<TOTAL_PIXELS/4){
       strip.setPixelColor(i, instrument_color);
@@ -130,6 +126,12 @@
     }
   }
   strip.show();
+}
+uint32_t multiplicateBrightness(int _r, int _g, int _b) {
+  int r = (int) _r*brightness;
+  int g = (int) _g*brightness;
+  int b = (int) _b*brightness;
+  return strip.Color(r, g, b);
 }

 // Fill the dots one after the other with a color


init var

init var

--- monitor_client/monitor_client.ino
+++ monitor_client/monitor_client.ino
@@ -6,6 +6,7 @@
 #define DHT11PIN 2
 dht11 DHT11;
 GPRS gprs(PIN_TX, PIN_RX, BAUDRATE,"cmnet");
+char target_url[61];
 char buffer[128];

 void setup(){


Revert "Remove uneeded header"

Revert "Remove uneeded header"

This reverts commit c142750b4d31de0385e2e2ec10bf201b7e17daa0.

--- iDONT.ino
+++ iDONT.ino
@@ -4,6 +4,8 @@
 #include <DNSServer.h>            //Local DNS Server used for redirecting all requests to the configuration portal
 #include <ESP8266WebServer.h>     //Local WebServer used to serve the configuration portal
 #include <WiFiManager.h>          //https://github.com/kentaylor/WiFiManager WiFi
+#include <ESP8266WebServer.h>
+

 WiFiServer* pWifiServer;
 unsigned char btnState;


Add support for reading sensors.

Add support for reading sensors.

Additionally a persistent_queue is now used to store pending messages.

--- wifi-feather/wifi-feather.ino
+++ wifi-feather/wifi-feather.ino
@@ -4,11 +4,12 @@
 #include <TimeLib.h>
 #include <WiFiUdp.h>

-#include "persistent_vector.h"
+#include "persistent_queue.h"
 #include "ssid-info.h"
 #include "util.h"

-PrintEx serial = Serial;
+static constexpr char const* SENSOR_ID = "bostonfern1";
+static constexpr unsigned ENABLE_SENSOR_PIN = 14;

 static constexpr unsigned CONNECTION_TIMEOUT = 5000;
 static constexpr char const* HOST = "192.168.1.2";
@@ -17,21 +18,28 @@
 static constexpr size_t MAX_PENDING_MESSAGES = 4;
 static constexpr size_t SAMPLES_PER_MESSAGE = 8;

+static constexpr unsigned SENSOR_WARMUP_DELAY = 1000;
+static constexpr unsigned DELAY_BETWEEN_SAMPLES = 500;
+
 // Sleep time: 30s (measured in us)
 static constexpr unsigned SLEEP_TIME = 30 * 1000 * 1000;
+
+static constexpr unsigned short local_port = 8888;

 struct message {
   time_t time;
   unsigned short samples[SAMPLES_PER_MESSAGE];
 };

-typedef persistent_vector<message> pending_messages_queue;
+typedef persistent_queue<message> pending_messages_queue;
+
 static pending_messages_queue* pending_messages;

 static WiFiUDP Udp;
-static constexpr unsigned short local_port = 8888;
+// TODO make ntp_client a template capable of handling both WiFiUDP and EthernetUDP
+static ntp_client ntp(Udp);

-static ntp_client ntp(Udp);
+static PrintEx serial = Serial;

 void setup() {
   Serial.begin(115200);
@@ -56,20 +64,31 @@
 }

 void loop() {
-  message msg;
-  msg.time = now();
-  for (unsigned short i = 0; i < SAMPLES_PER_MESSAGE; i++)
-    msg.samples[i] = i;
-
-  pending_messages->push_back(msg);
-
+  read_sensor();
   send_messages();

   Serial.println("Storing data to EEPROM");
   EEPROM.commit();

+  Serial.println("Going to sleep");
   ESP.deepSleep(SLEEP_TIME);
   Serial.println(">>> This should not print");
+}
+
+void read_sensor() {
+  digitalWrite(ENABLE_SENSOR_PIN, HIGH);
+  delay(SENSOR_WARMUP_DELAY);
+
+  message msg;
+  msg.time = now();
+  for (unsigned short i = 0; i < SAMPLES_PER_MESSAGE; i++) {
+    delay(DELAY_BETWEEN_SAMPLES);
+    msg.samples[i] = analogRead(A0);
+  }
+
+  digitalWrite(ENABLE_SENSOR_PIN, LOW);
+
+  pending_messages->push(msg);
 }

 static void connect_wifi() {
@@ -86,13 +105,6 @@
   serial.printf("Address: %s\n", WiFi.localIP().toString().c_str());
 }

-static WiFiClient connect_client() {
-  WiFiClient client;
-  if (!client.connect(HOST, PORT))
-    fatal_error("Connection to host failed");
-  return client;
-}
-
 static void delete_messages() {
   auto size = pending_messages_queue::storage_size(MAX_PENDING_MESSAGES);
   for (size_t i = 0; i < size; i++)
@@ -107,28 +119,31 @@
   serial.printf("Attempting to send %d messages\n",
       pending_messages->size());

-  // XXX Add pop_front() ???
-  // XXX Implement a circular queue ???
   while (!pending_messages->empty()) {
-    auto last_idx = pending_messages->size() - 1;
-    auto& msg = (*pending_messages)[last_idx];
-    serial.printf("About to send msg %d (idx: %d)\n", msg.time, last_idx);
-    // TODO use error code
-    send_message(msg);
-    pending_messages->pop_back();
-  }
+    auto& msg = pending_messages->front();
+    if (!send_message(msg))
+      break;
+    pending_messages->pop();
+  }
 }

-static void send_message(const message& msg) {
-  // TODO use the same connection for all messages
-  auto client = connect_client();
+static bool send_message(const message& msg) {
+  // XXX use the same connection for all messages ???
+  WiFiClient client;
+  if (!client.connect(HOST, PORT))
+    return false;
+
+  // TODO check result of prints
   client.print("sensor-id: ");
-  serial.printf("msg.time=%d\n", msg.time);
+  client.println(SENSOR_ID);
+  client.print("time: ");
   client.println(msg.time);

 //      serial.printf("time: %d\n", msg.time);
 //    for (size_t s = 0; s < SAMPLES_PER_MESSAGE; s++)
 //      serial.printf("sample%d: %d\n", s, msg.samples[s]);
+
+  return true;
 }

 static void print_date() {


Fix to compile for ESP8266

Fix to compile for ESP8266

The example now compiles, although the SDA/SCL pin numbers may need
adjusting according to device and usage.

--- examples/SoftWire_MLX90614/SoftWire_MLX90614.ino
+++ examples/SoftWire_MLX90614/SoftWire_MLX90614.ino
@@ -23,9 +23,13 @@
 uint8_t sdaPin = 16; // JTAG TDI
 uint8_t sclPin = 19; // JTAG TCK
 uint8_t powerPin = 18;
-#else
+#elif defined(ARDUINO_ARCH_AVR)
 uint8_t sdaPin = A4;
 uint8_t sclPin = A5;
+#else
+// Adjust to suit your non-AVR architecture
+uint8_t sdaPin = 0;
+uint8_t sclPin = 1;
 #endif

 const uint8_t cmdAmbient = 6;


update 20150216.13:51

update 20150216.13:51

--- sensTMP36/src/sketch.ino
+++ sensTMP36/src/sketch.ino
@@ -10,7 +10,7 @@
 #define activityLED 3

 // *** declare constants
-const float ref5V = 5.14;   // reference: 5.0V on measurePin == 1023.0
+const float ref5V = 5.06;   // reference: 5.0V on measurePin == 1023.0

 // (numSamples ^ 0.5) is the S/N ratio that can be achieved.


tried to get around pointer issue, to no avail

--- src/ESP8266_RelayServer/ESP8266_RelayServer.ino
+++ src/ESP8266_RelayServer/ESP8266_RelayServer.ino
@@ -9,11 +9,11 @@
 ESP8266WebServer server(80);

 int myPins[] = {0,2,4,5,12,13,14,15,16};
-int myPin;
+const char* pathOn[] = {"/r0on", "/r1on", "/r2on", "/r3on", "/r4on", "/r5on", "/r6on", "/r7on", "/r8on" };
+const char* pathOff[] = {"/r0off", "/r1off", "/r2off", "/r3off", "/r4off", "/r5off", "/r6off", "/r7off", "/r8off" };
+
 int i;
 String sPin;
-String sUrl;
-const char cUrl;

 void handleRoot() {
   server.send(200, "text/plain", "hello from esp8266!");
@@ -66,23 +66,21 @@
   server.on("/", handleRoot);

   for (i = 0; i < 9; i = i + 1) {
-    myPin = myPins[i];
     sPin = String(i);
+    Serial.println(sPin);
+    Serial.println(myPins[i]);
+    Serial.println(pathOn[i]);
+    Serial.println(pathOff[i]);
+    Serial.println("\n");

-    sUrl = "/relay" + sPin + "On";
-    cUrl = sUrl.c_str();
-
-    server.on(&cUrl, [](){
+    server.on(pathOn[i], [](){
       server.send(200, "text/plain", "Relay " + sPin + " is on");
-      digitalWrite(myPin, 0);
+      digitalWrite(myPins[i], 0);
     });

-    sUrl = "/relay" + sPin + "Off";
-    cUrl = sUrl.c_str();
-
-    server.on(&cUrl, [](){
+    server.on(pathOff[i], [](){
       server.send(200, "text/plain", "Relay " + sPin + " is off");
-      digitalWrite(myPin, 1);
+      digitalWrite(myPins[i], 1);
     });
   }


SLEEP_P削除

--- 2_example/example17_ir_rc/example17_ir_rc.ino
+++ 2_example/example17_ir_rc/example17_ir_rc.ino
@@ -16,7 +16,6 @@
 #define PASS "password"                     // パスワード
 #define SENDTO "192.168.0.255"              // 送信先のIPアドレス
 #define PORT 1024                           // 送信のポート番号
-#define SLEEP_P 29*60*1000000               // スリープ時間 29分(uint32_t)
 #define DEVICE "ir_rc_1,"                   // デバイス名(5文字+"_"+番号+",")
 #define AEHA        0                       // 赤外線送信方式(Panasonic、Sharp)
 #define NEC         1                       // 赤外線送信方式 NEC方式


stubbed 12V relay remote to Tower.ino

stubbed 12V relay remote to Tower.ino

Still need to actually write code.

--- src/Tower/Tower.ino
+++ src/Tower/Tower.ino
@@ -2,6 +2,7 @@

 // The IDE requires all libraries to be #include’d in the main (.ino) file.  Clutter.
 #include <Streaming.h> // <<-style printing
+#include <Bounce.h> // buttons
 #include <Metro.h> // timers
 #include <Simon_Indexes.h> // sizes, indexing and comms common to Towers and Console
 #include <EEPROM.h> // saving and loading radio settings
@@ -57,6 +58,13 @@
 #define RED_MAX 255
 #define GRN_MAX 220
 #define BLU_MAX 210
+
+// remote control
+#define SYSTEM_ENABLE_PIN A0
+#define FIRE_ENABLE_PIN A1
+Bounce systemEnable = Bounce(SYSTEM_ENABLE_PIN, BUTTON_DEBOUNCE_TIME);
+Bounce fireEnable = Bounce(FIRE_ENABLE_PIN, BUTTON_DEBOUNCE_TIME);
+

 void setup() {
   // put your setup code here, to run once:


Test version with extensible framework.

Test version with extensible framework.


Added all sensors to setup function

Added all sensors to setup function

--- robot.ino
+++ robot.ino
@@ -10,6 +10,8 @@

 void Robot::setUp() {
   sensorForward.setUp();
+  sensorRight.setUp();
+  sensorLeft.setUp();
   motorLeft.setUp();
   motorRight.setUp();
 }


Improve the percussion envelope, but turn it off by default

--- roto2.ino
+++ roto2.ino
@@ -60,12 +60,9 @@
     mixer1.gain(2, 0.25);
     mixer1.gain(3, 0.25);

-    perc.frequency(440.0);
-    perc.amplitude(1.0);
-    percEnvelope.attack(5.0);
+    percEnvelope.attack(10.0);
     percEnvelope.sustain(0.0);
-    percEnvelope.decay(40.0);
-    percEnvelope.release(5.0);
+    percEnvelope.decay(80.0);

     mixer2.gain(0, 0.5);
     mixer2.gain(1, 0.0625);
@@ -121,12 +118,10 @@

     float fund = note2freq(note);

-    Serial.print(voices.Available(), DEC);
     if (voices.Available() == kNumVoices) {
         perc.frequency(2*fund);
         // Compensate for frequency response: normalize to highest MIDI freq.
         perc.amplitude(log2(4186.0)/log2(fund));
-        percEnvelope.noteOn();
     }

     voice_t voice = voices.NoteOn(note);


Update main.ino

Update main.ino

--- main/main.ino
+++ main/main.ino
@@ -175,7 +175,7 @@
   int timeout = 0;
   char message_ok = 0;
   // Prepair message
-  message.id = 5E8;
+  message.id = 0x7D0; //id of 2000, lower priority than other node
   message.header.rtr = 0;
   message.header.length = 8;
   message.data[0] = 0x02;


No sort median filter; brake test expanded.

--- Elcano_C2_In_Out/Elcano_C2_In_Out.ino
+++ Elcano_C2_In_Out/Elcano_C2_In_Out.ino
@@ -184,7 +184,7 @@

         initialize();

-        CalibrateBrakes();
+        CalibrateBrakes(95,900);

        CalibrateSteering(HardRight,3);
        CalibrateSteering(HardLeft,3);
@@ -197,7 +197,7 @@
 }

 /*---------------------------------------------------------------------------------------*/
-void CalibrateBrakes()
+void CalibrateBrakes(int delayBig, int delaySmall)
 {
   // This routine establishes the correct values for MinimumBrake and FullBrake.
   // Verify that the value for FullBrake stops the vehicle.
@@ -222,7 +222,7 @@
      {
        analogWrite(DiskBrake, i);
 //       int current =  analogRead(CurrentBrake);
-       delay(95);  // allow tiime for brake to respond
+       delay(delaySmall);  // allow tiime for brake to respond
        feedbacks[0] = analogRead(BrakeFB);
        delay(1);
        feedbacks[1] = analogRead(BrakeFB);
@@ -237,7 +237,7 @@
        Serial.print(i); Serial.print(", ");
 //       Serial.print(current); Serial.print(", ");
        Serial.println(feedback);
-       delay(900);   // hold each brake position 1 second.
+       delay(delaySmall);   // hold each brake position 1 second.
      }
 }
 void moveSteer(int i)
@@ -429,6 +429,10 @@
   static unsigned long OutsideTime;
   int center;

+  for (int i = 900; i> 0; i-=10)
+          CalibrateBrakes(i/10, i);
+
+
   return;

   OutsideTime = EndTime - TimeNow;


Version 2.9c - 2nd October 2019

Version 2.9c - 2nd October 2019

Support Curiosity Nano

--- ulisp.ino
+++ ulisp.ino
@@ -151,10 +151,6 @@

 #elif defined(ARDUINO_AVR_ATmega4809)   /* Curiosity Nano using MegaCoreX */
 #define Serial Serial3
-#define WORKSPACESIZE 1068-SDSIZE       /* Objects (4*bytes) */
-#define EEPROMSIZE 256                  /* Bytes */
-#define SYMBOLTABLESIZE BUFFERSIZE      /* Bytes - no long symbols */
-
 #define WORKSPACESIZE 1068-SDSIZE       /* Objects (4*bytes) */
 #define EEPROMSIZE 256                  /* Bytes */
 #define SYMBOLTABLESIZE BUFFERSIZE      /* Bytes - no long symbols */


improved main script to use the built-in-led library

--- src/main.ino
+++ src/main.ino
@@ -1,6 +1,8 @@
+#include "built-in-led.h"
+#include <Arduino.h>
 #include <EEPROM.h>
+#include <MFRC522.h>
 #include <SPI.h>
-#include <MFRC522.h>

 constexpr uint8_t relay = 12;

@@ -19,31 +21,38 @@

 MFRC522 mfrc522(SS_PIN, RST_PIN);

+boolean checkTwo(byte a[], byte b[]);
+boolean findID(byte find[]);
+boolean isMaster(byte test[]);
+uint8_t findIDSLOT(byte find[]);
+uint8_t getID();
+void deleteID(byte a[]);
+void loop();
+void readID(uint8_t number);
+void setup();
+void writeID(byte a[]);
+
 void setup() {
+  digitalWrite(relay, LOW);
   pinMode(relay, OUTPUT);
-  digitalWrite(relay, LOW);
-
-  Serial.begin(9600);
+  builtInLed::setup();
+
   SPI.begin();

   mfrc522.PCD_Init();
   mfrc522.PCD_SetAntennaGain(mfrc522.RxGain_max);

-  Serial.println(F("SESAME"));
-  Serial.println("");
-
   byte v = mfrc522.PCD_ReadRegister(mfrc522.VersionReg);

   if ((v == 0x00) || (v == 0xFF)) {
-    Serial.println(F("Communication with MFRC522 has failed."));
-
-    while(true);
+    while (true) {
+      builtInLed::sos();
+    }
   }

   if (EEPROM.read(1) != 143) {
-    Serial.println(F("Define a master card by scanning one now."));
-
     do {
+      builtInLed::mc();
       successRead = getID();
     } while (!successRead);

@@ -52,17 +61,13 @@
     }

     EEPROM.write(1, 143);
-
-    Serial.println(F("Succesfully defined the master card."));
-    Serial.println("");
   }

   for (uint8_t i = 0; i < 4; i++) {
     masterCard[i] = EEPROM.read(2 + i);
   }

-  Serial.println(F("Ready to bounce!"));
-  Serial.println("");
+  builtInLed::ok();
 }

 void loop() {
@@ -73,58 +78,41 @@
   if (programMode) {
     if (isMaster(readCard)) {
       programMode = false;
-
-      Serial.println(F("Master card scanned."));
-      Serial.println(F("Exiting program mode."));
-      Serial.println("");
-    } else {
-      if (findID(readCard)) {
-        Serial.println(F("I know this PICC, removing..."));
-        deleteID(readCard);
-        Serial.println(F("Scan a PICC to ADD or REMOVE to EEPROM"));
-
-        return;
-      }
-
-      Serial.println(F("I do not know this PICC, adding..."));
-      writeID(readCard);
-      Serial.println(F("Scan a PICC to ADD or REMOVE to EEPROM"));
-    }
-  } else {
-    if (isMaster(readCard)) {
-      programMode = true;
-      Serial.println(F("Hello Master - Entered Program Mode"));
-      uint8_t count = EEPROM.read(0);
-      Serial.print(F("I have "));
-      Serial.print(count);
-      Serial.print(F(" record(s) on EEPROM"));
-      Serial.println("");
-      Serial.println(F("Scan a PICC to ADD or REMOVE to EEPROM"));
-      Serial.println(F("Scan Master Card again to Exit Program Mode"));
+      builtInLed::ok();

       return;
     }

     if (findID(readCard)) {
-      Serial.println(F("Welcome! Open sesame!"));
-      granted();
+      deleteID(readCard);
+      builtInLed::ok();
+
       return;
     }

-    Serial.println(F("You shall not pass"));
-    denied();
-  }
-}
-
-void granted() {
-  digitalWrite(relay, HIGH);
-  delay(500);
-  digitalWrite(relay, LOW);
-  delay(1000);
-}
-
-void denied() {
-  delay(1000);
+    writeID(readCard);
+    builtInLed::ok();
+
+    return;
+  }
+
+  if (isMaster(readCard)) {
+    programMode = true;
+    builtInLed::mc();
+
+    return;
+  }
+
+  if (findID(readCard)) {
+    digitalWrite(relay, HIGH);
+    delay(500);
+    digitalWrite(relay, LOW);
+    builtInLed::ok();
+
+    return;
+  }
+
+  builtInLed::sos();
 }

 uint8_t getID() {
@@ -136,14 +124,10 @@
     return 0;
   }

-  Serial.println(F("Scanned PICC's UID:"));
-
   for (uint8_t i = 0; i < 4; i++) {
     readCard[i] = mfrc522.uid.uidByte[i];
-    Serial.print(readCard[i], HEX);
-  }
-
-  Serial.println("");
+  }
+
   mfrc522.PICC_HaltA();

   return 1;
@@ -158,12 +142,6 @@
 }

 void writeID(byte a[]) {
-  if (findID(a)) {
-    Serial.println(F("Failed! There is something wrong with ID or bad EEPROM"));
-
-    return;
-  }
-
   uint8_t num = EEPROM.read(0);
   uint8_t start = (num * 4) + 6;
   num++;
@@ -172,14 +150,10 @@
   for (uint8_t j = 0; j < 4; j++) {
     EEPROM.write(start + j, a[j]);
   }
-
-  Serial.println(F("Succesfully added ID record to EEPROM"));
 }

 void deleteID(byte a[]) {
   if (!findID(a)) {
-    Serial.println(F("Failed! There is something wrong with ID or bad EEPROM"));
-
     return;
   }

@@ -202,8 +176,6 @@
   for (uint8_t k = 0; k < 4; k++) {
     EEPROM.write(start + j + k, 0);
   }
-
-  Serial.println(F("Succesfully removed ID record from EEPROM"));
 }

 boolean checkTwo(byte a[], byte b[]) {


restore previously lost low-power code

restore previously lost low-power code

--- examples/RF12/radioBlip/radioBlip.ino
+++ examples/RF12/radioBlip/radioBlip.ino
@@ -1,32 +1,35 @@
 // Send out a radio packet every minute, consuming as little power as possible
 // 2010-08-29 <jc@wippler.nl> http://opensource.org/licenses/mit-license.php

-// all the low-power functions have been moved into the Ports library
-
 #include <JeeLib.h>

-static word payload;
+static long payload;
+
+// this must be added since we're using the watchdog for low-power waiting
+ISR(WDT_vect) { Sleepy::watchdogEvent(); }

 void setup() {
-#ifndef SDCR
-    DDRB |= bit(0);
-    for (byte i = 0; i < 6; ++i) {
-        PINB = bit(0);
-        delay(128);
-    }
-#endif
     rf12_initialize(4, RF12_868MHZ, 5);
+    rf12_sleep(RF12_SLEEP);
+
+    // stay off  3 minutes after reset, to make sure that power is stable
+    for (byte i = 0; i < 3; ++i)
+        Sleepy::loseSomeTime(60000);
 }

 void loop() {
     ++payload;

+    rf12_sleep(RF12_WAKEUP);
+
     while (!rf12_canSend())
         rf12_recvDone();

     rf12_sendStart(0, &payload, sizeof payload);
+    // set the sync mode to 2 if the fuses are still the Arduino default
+    // mode 3 (full powerdown) can only be used with 258 CK startup fuses
+    rf12_sendWait(2);

-    MilliTimer t;
-    while (!t.poll(1000))
-        rf12_recvDone();
+    rf12_sleep(RF12_SLEEP);
+    Sleepy::loseSomeTime(60000);
 }


Vibe changes

Vibe changes


Update McLighting.ino

Update McLighting.ino

USE_WS2812FX_UART are pointers!

--- Arduino/McLighting/McLighting.ino
+++ Arduino/McLighting/McLighting.ino
@@ -94,10 +94,10 @@
   NeoEsp8266Dma800KbpsMethod* dma;
 #endif
 #ifdef USE_WS2812FX_UART1 // Uses UART1: GPIO1/TXD0/TX, more info: https://github.com/Makuna/NeoPixelBus/wiki/ESP8266-NeoMethods
-  NeoEsp8266Uart0800KbpsMethod dma;
+  NeoEsp8266Uart0800KbpsMethod* dma;
 #endif
 #ifdef USE_WS2812FX_UART2 // Uses UART2: GPIO2/TXD1/D4, more info: https://github.com/Makuna/NeoPixelBus/wiki/ESP8266-NeoMethods
-  NeoEsp8266Uart1800KbpsMethod dma;
+  NeoEsp8266Uart1800KbpsMethod* dma;
 #endif

 void initDMA(uint16_t stripSize = NUMLEDS){


modify header include adding path to libraries

--- firmware/examples/readTag/readtag.ino
+++ firmware/examples/readTag/readtag.ino
@@ -1,6 +1,6 @@
-#include "pn532_i2c\pn532_i2c.h"
-#include "pn532_i2c\PN532\PN532.h"
-#include "pn532_i2c\NDEF\NfcAdapter.h"
+#include "pn532_i2c/pn532_i2c.h"
+#include "pn532_i2c/PN532/PN532.h"
+#include "pn532_i2cNDEF/NfcAdapter.h"

 PN532_I2C pn532_i2c(Wire);
 NfcAdapter nfc = NfcAdapter(pn532_i2c);


Fixing up the M2 firmware. Removing some dead code and debugging statements

--- sketches/M2_CAN_haz_bus/M2_CAN_haz_bus.ino
+++ sketches/M2_CAN_haz_bus/M2_CAN_haz_bus.ino
@@ -110,7 +110,7 @@
         CAN_FRAME tx_frame;
         tx_frame.data.byte[0] = 0x30;

-        //TODO: Support for configurable padding
+        //TODO: Support for configurable padding and delay
         CreateCanFrame(isotp_tx_arbid, isotp_tx_extended, 1, tx_frame.data.byte, true, 0x00, &tx_frame);

         if(mode == CMD_CAN_MODE_SNIFF_CAN0 && !can_tx_frames0.enqueue(&tx_frame))
@@ -354,18 +354,6 @@
                 isotp_tx_PCIIndex = 1;
                 isotp_tx_index = 0;
                 isotp_tx_length = 0;
-                if (mode != CMD_CAN_MODE_CITM)
-                {
-                    device->setRXFilter(0, 0, 0x7FF, false);
-                    device->detachCANInterrupt(0);
-                }
-                else
-                {
-                    Can0.setRXFilter(0, 0, 0x7FF, false);
-                    Can0.detachCANInterrupt(0);
-                    Can1.setRXFilter(0, 0, 0x7FF, false);
-                    Can1.detachCANInterrupt(0);
-                }
             }
         }
     }


Experimental changes for first complete Typeatron prototype

--- typeatron/mark1/arduino/typeatron/typeatron.ino
+++ typeatron/mark1/arduino/typeatron/typeatron.ino
@@ -126,41 +126,69 @@
   analogWrite(bluePin, 255 - (unsigned int) blue);
 }

+int colorToggle = 0;
+
+void colorDebug() {
+    if (colorToggle) {
+        writeRGBColor(RED);
+    } else {
+        writeRGBColor(BLUE);
+    }
+    colorToggle = !colorToggle;
+}
+

 ////////////////////////////////////////////////////////////////////////////////

 // these are global so that we can read from setup() as well as loop()
 unsigned int input[5];
-unsigned inputState = 0;
+unsigned inputState;

 unsigned int lastInputState = 0;

 void readInput() {
-    input[0] = digitalRead(keyPin1);
-    input[1] = digitalRead(keyPin2);
-    input[2] = digitalRead(keyPin3);
-    input[3] = digitalRead(keyPin4);
-    input[4] = digitalRead(keyPin5);
+    input[0] = !digitalRead(keyPin1);
+    input[1] = !digitalRead(keyPin2);
+    input[2] = !digitalRead(keyPin3);
+    input[3] = !digitalRead(keyPin4);
+    input[4] = !digitalRead(keyPin5);
+
+    inputState = 0;

     for (int i = 0; i < 5; i++) {
       inputState |= input[i] << i;
     }
 }

+// note: tones may not be played (via the Typeatron's transducer) in parallel with the reading of button input,
+// as the vibration causes the push button switches to oscillate when depressed
 void startupSequence() {
+    tone(transducerPin, 220);
     writeRGBColor(RED);
     digitalWrite(vibrationMotorPin, HIGH);
-    delay(300);
+    delay(200);
+    tone(transducerPin, 440);
+    writeRGBColor(GREEN);
+    delay(200);
+    tone(transducerPin, 880);
     writeRGBColor(BLUE);
     digitalWrite(vibrationMotorPin, LOW);
+    delay(200);
+    noTone(transducerPin);
 }

 void setup() {
-    pinMode(keyPin1, INPUT);
+    pinMode(keyPin1, INPUT);
     pinMode(keyPin2, INPUT);
     pinMode(keyPin3, INPUT);
     pinMode(keyPin4, INPUT);
     pinMode(keyPin5, INPUT);
+    // take advantage of the Arduino's internal pullup resistors
+    digitalWrite(keyPin1, HIGH);
+    digitalWrite(keyPin2, HIGH);
+    digitalWrite(keyPin3, HIGH);
+    digitalWrite(keyPin4, HIGH);
+    digitalWrite(keyPin5, HIGH);

     pinMode(vibrationMotorPin, OUTPUT);
     pinMode(transducerPin, OUTPUT);
@@ -429,21 +457,18 @@

     readInput();

-    // bells and whistles
-    if (input[0] == HIGH) {
-        //digitalWrite(ledPin, HIGH);
-        tone(transducerPin, 440);
-    } else {
-        //digitalWrite(ledPin, LOW);
-        noTone(transducerPin);
-    }
-    if (input[4] == HIGH) {
-        digitalWrite(laserPin, HIGH);
-    } else {
-        digitalWrite(laserPin, LOW);
-    }
-
     if (inputState != lastInputState) {
+        colorDebug();
+sprintf(errstr, "input changed from %d to %d\n", lastInputState, inputState);
+error(errstr);
+
+        // bells and whistles
+        if (input[4] == LOW) {
+            digitalWrite(laserPin, HIGH);
+        } else {
+            digitalWrite(laserPin, LOW);
+        }
+
         unsigned int before = micros();

         char keys[6];


How to teach young people to program? How I pretend to program? # kidsSerie-06

How to teach young people to program? How I pretend to program? # kidsSerie-06

--- _06_kidSerie_sketch_unique_Adafruit_IO_FakeToReal_Feeds.ino
+++ _06_kidSerie_sketch_unique_Adafruit_IO_FakeToReal_Feeds.ino
@@ -47,8 +47,8 @@

 /************************* WiFi Access Point *********************************/

-const char* WLAN_SSID     = "YourRouterSSID";
-const char* WLAN_PASS     = "YourRouterPassword";
+#define WLAN_SSID     = "YourRouterSSID";
+#define WLAN_PASS     = "YourRouterPassword";

 //ESP8266WebServer server(80);

@@ -100,10 +100,12 @@
 // Notice MQTT paths for AIO follow the form: <username>/feeds/<feedname>
 //Adafruit_MQTT_Publish test_topic = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/test");
 Adafruit_MQTT_Publish temp_topic = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/temp");
+Adafruit_MQTT_Publish humid_topic = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/humid");
 /****************************** Subscriptions*********************************/
 // Setup a feed called 'test' for subscribing to changes.
 //Adafruit_MQTT_Subscribe test_subscription = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME "/feeds/test");
 Adafruit_MQTT_Subscribe temp_subscription = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME "/feeds/temp");
+Adafruit_MQTT_Subscribe humid_subscription = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME "/feeds/humid");

 /***************************  MQTT Conn   ************************************/

@@ -173,6 +175,7 @@
   // Setup MQTT subscription for onoff feed.
   //mqtt.subscribe(&test_subscription);
   mqtt.subscribe(&temp_subscription);
+  mqtt.subscribe(&humid_subscription);
 }

 //uint32_t x=0;    // Mock data
@@ -192,7 +195,7 @@

  /****************************** Subscript  ***********************************/
  Adafruit_MQTT_Subscribe *subscription;
-  while ((subscription = mqtt.readSubscription(5000))) {
+  /*while ((subscription = mqtt.readSubscription(5000))) {
     //if (subscription == &test_subscription) {
     if (subscription == &temp_subscription) {
       //Serial.print(F("Got: "));
@@ -201,7 +204,18 @@
       Serial.println((char *)temp_subscription.lastread);

     }
-  }
+  }*/
+  while ((subscription = mqtt.readSubscription(10000))) {
+    if (subscription == &humid_subscription) {
+      Serial.print(F("Got humid: "));
+      Serial.println((char *)humid_subscription.lastread);
+    }
+    else {
+      Serial.print(F("Got temp: "));
+      Serial.println((char *)temp_subscription.lastread);
+    }
+  }
+
  /****************************** Publish  **********************************/
    // Now we can publish stuff!
   //Serial.print(F("\nSending test val "));
@@ -215,7 +229,16 @@
   } else {
     Serial.println(F("OK!"));
  }
-}
+
+  Serial.print(F("\nSending humid val "));
+  Serial.print(humidity);
+  Serial.print("...");
+  if (! humid_topic.publish(humidity)) {
+    Serial.println(F("Failed"));
+  } else {
+    Serial.println(F("OK!"));
+  }
+
 /****************************** Ping  ***************************************/

   // ping the server to keep the mqtt connection alive
@@ -225,6 +248,7 @@
     mqtt.disconnect();
   }
 */
+}
  /********************************* MQTT Conn  ********************************/
 // Function to connect and reconnect as necessary to the MQTT server.
 // Should be called in the loop function and it will take care if connecting.
@@ -273,7 +297,7 @@
     temp_c = dht.readTemperature();    // Read temperature as Celsius
     // Check if any reads failed and exit early (to try again).
     //if (isnan(humidity) || isnan(temp_f)) {
-    if (isnan(humidity) || isnan(temp_c)) {
+    if (isnan(temp_c) || isnan(humidity) || temp_c != 0 || humidity != 0) {
       Serial.println("Failed to read from DHT sensor!");
       return;
     }


firmware: fix servo initial pos

firmware: fix servo initial pos

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

 float curX, curY, curZ;
 float tarX, tarY, tarZ; // target xyz position
@@ -328,9 +328,10 @@
   initRobotSetup();
   initPosition();

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

   goHome();
   requestNextCommand();


Minor mods

Minor mods


Added Arduino code for the BLE master

Added Arduino code for the BLE master

--- arduino/rfglow_ble/rfglow_ble.ino
+++ arduino/rfglow_ble/rfglow_ble.ino
@@ -112,7 +112,7 @@
   Serial.print(len);

   Serial.print(F(" bytes: "));
-  /*
+
   for(int i=0; i<len; i++)
    Serial.print((char)buffer[i]);

@@ -122,7 +122,7 @@
     Serial.print(" 0x"); Serial.print((char)buffer[i], HEX);
   }
   Serial.print(F(" ]"));
-  */
+
   Serial.println();

   if (len == 4) {
@@ -152,6 +152,7 @@
       c_hue = hue;
       c_saturation = saturation;
       c_brightness = brightness;
+      sends = 0;
       Serial.print("Parsed values: ");
       Serial.print(c_hue);
       Serial.print(", ");


add 0 to PWM output

add 0 to PWM output

--- arduino/vaz2103mon/vaz2103mon.ino
+++ arduino/vaz2103mon/vaz2103mon.ino
@@ -32,17 +32,17 @@
     int net = Serial.parseInt();
     if (Serial.read() == '\n') {

-      if (cpu > 0) {
+      if (cpu >= 0) {
         if (cpu < 256) {
           analogWrite(11, cpu);
         }
       }
-      if (ram > 0) {
+      if (ram >= 0) {
         if (ram < 256) {
           analogWrite(10, ram);
         }
       }
-      if (net > 0) {
+      if (net >= 0) {
         if (net < 256) {
           analogWrite(9, net);
         }


2 new program functions display deg and integrate

--- Arduino/sketches/Sensor_Module/RawSensorData.ino
+++ Arduino/sketches/Sensor_Module/RawSensorData.ino
@@ -1,7 +1,9 @@
-// UNCOMMENT ONE OF THE TWO OPTIONS BELOW
+// UNCOMMENT ONE OF THE FOUR OPTIONS BELOW

 //#define PRINTDATA // uncomment to display raw data over serial port in format [gX     gY     gZ      aX      aY      aZ]
-#define SAMPLERATE // uncomment to display sampling rate over serial port updates every 2 seconds with sampleing rate in Hz
+//#define PRINTANGLE // identical to PRINTDATA but gyro data is in delta degrees [gX     gY     gZ      aX      aY      aZ]
+//#define PRINTANGLESUM // uncomment to display simple intigration of gyro over X axis in degrees
+//#define SAMPLERATE // uncomment to display max sampling rate over serial port updates every 2 seconds with sampleing rate in Hz

 #include <avr/eeprom.h>

@@ -12,6 +14,10 @@
 static uint16_t calibratingA = 0;  // the calibration is done in the main loop. Calibrating decreases at each cycle down to 0, then we enter in a normal mode.
 static int16_t  acc_25deg;

+#if defined(PRINTANGLE) || defined(PRINTANGLESUM)
+	#define GYRO_SCALE ((2380 * PI)/((32767.0f / 4.0f ) * 180.0f * 1000000.0f))
+	#define RADTODEG  57.2957795;
+#endif

 // ************************************************************************************************************
 // Main Program
@@ -23,9 +29,40 @@
 }

 void loop()
-{
+{
 	ACC_getADC();
 	Gyro_getADC();
+	#if (defined(PRINTANGLE) || defined(PRINTANGLESUM))
+		static uint16_t previousT;
+ 		uint16_t currentT = micros();
+ 		float scale, deltaGyroAngle[3];
+ 		float static angleSum[3];
+ 		byte axis = 0;
+
+ 		scale = (currentT - previousT) * GYRO_SCALE;
+ 		previousT = currentT;
+
+ 		for (axis = 0; axis < 3; axis++){
+    		deltaGyroAngle[axis] = gyroADC[axis]  * scale * RADTODEG;
+    	}
+
+    #if defined(PRINTANGLESUM)
+    	angleSum[0] += deltaGyroAngle[0];
+    	if(Serial.available() > 0)
+    	{
+    		angleSum[0] = 0;
+    		Serial.read();
+    	}
+    	Serial.println(angleSum[0]);
+   	#endif
+
+   	#if defined(PRINTANGLE)
+    	printAngleData(deltaGyroAngle);
+    #endif
+
+    	delayMicroseconds(650); // emperical delay between readings
+
+	#endif
 	#if defined(PRINTDATA)
 		printRawData();
 	#elif defined(SAMPLERATE)
@@ -36,22 +73,42 @@
 // ************************************************************************************************************
 // Helper Functions
 // ************************************************************************************************************
-void printRawData() //prints raw data over serial port in format "[gX     gY     gZ      aX      aY      aZ]\n"
-{
-	Serial.print("[");
-	Serial.print(gyroADC[0]);
-	Serial.print("\t\t");
-	Serial.print(gyroADC[1]);
-	Serial.print("\t\t");
-	Serial.print(gyroADC[2]);
-	Serial.print("\t\t");
-	Serial.print(accADC[1]);
-	Serial.print("\t\t");
-	Serial.print(accADC[2]);
-	Serial.print("\t\t");
-	Serial.print(accADC[3]);
-	Serial.println("]");
-}
+#if defined(PRINTDATA)
+	void printRawData() //prints raw data over serial port in format "[gX     gY     gZ      aX      aY      aZ]\n"
+	{
+		Serial.print("[");
+		Serial.print(gyroADC[0]);
+		Serial.print("\t\t");
+		Serial.print(gyroADC[1]);
+		Serial.print("\t\t");
+		Serial.print(gyroADC[2]);
+		Serial.print("\t\t");
+		Serial.print(accADC[1]);
+		Serial.print("\t\t");
+		Serial.print(accADC[2]);
+		Serial.print("\t\t");
+		Serial.print(accADC[3]);
+		Serial.println("]");
+	}
+#endif
+
+#if defined(PRINTANGLE)
+	void printAngleData(float *deltaGyroAngle){
+		Serial.print("[");
+		Serial.print(deltaGyroAngle[0]);
+		Serial.print("\t\t");
+		Serial.print(deltaGyroAngle[1]);
+		Serial.print("\t\t");
+		Serial.print(deltaGyroAngle[2]);
+		Serial.print("\t\t");
+		Serial.print(accADC[1]);
+		Serial.print("\t\t");
+		Serial.print(accADC[2]);
+		Serial.print("\t\t");
+		Serial.print(accADC[3]);
+		Serial.println("]");
+	}
+#endif

 #if defined(SAMPLERATE)
 		long ptime = 0;


Security problems jeje

Security problems jeje

--- sketchs/NodeSketch/NodeSketch.ino
+++ sketchs/NodeSketch/NodeSketch.ino
@@ -18,49 +18,49 @@

 void setup() {
   Serial.begin(115200);
-
-  mb.config("Onix", "180196260499");
+
+  mb.config("SSID", "PASSWORD");
   while (WiFi.status() != WL_CONNECTED) { delay(250); }
   Serial.println(WiFi.localIP());
-
+
   for (int i = 0, j = 0; i < cin_count, j < cout_count; i++, j++) {
     mb.addCoil(in_coils[i]);
     mb.addCoil(out_coils[j]);
   }
-
+
   for (int i = 0; i < hin_count; i++) {
     mb.addHreg(in_hreg[i]);
   }
-
+
   ts = millis();
 }

 void loop() {
-
+
    mb.task();
    int data = 0;
-
+
    if (Serial.available()) {
-
+
      for (int i = 0; i < cin_count; i++) {
        data = Serial.parseInt();
        mb.Coil(in_coils[i], data);

        Serial.println(data);
-     }
-
+     }
+
      for (int i = 0; i < hin_count; i++) {
        data = Serial.parseInt();
        mb.Hreg(in_hreg[i], data);
-
+
        Serial.println(data);
-     }
-
-     for (int i = 0; i < cout_count; i++) {
+     }
+
+     for (int i = 0; i < cout_count; i++) {
        int data = mb.Coil(out_coils[i]);
-       Serial.println(data);
-
+       Serial.println(data);
+
        while(Serial.parseInt() != data){}
-     }
+     }
    }
 }


v.1.5 Sensor-update

v.1.5 Sensor-update

Sensor functions updated to v.1.5

--- Arduino/BatteryRFID/BatteryRFID.ino
+++ Arduino/BatteryRFID/BatteryRFID.ino
@@ -1,22 +1,23 @@
 /*
    --------------------------------------------------------
-          Jeti RFID-Battery version 1.4
+          Jeti RFID-Battery version 1.5
    --------------------------------------------------------

     Tero Salminen RC-Thoughts.com 2016 www.rc-thoughts.com
-
-	Anti-metal Mifare 1k tag used - Blocks 4 & 5
+
+    Anti-metal Mifare 1k tag used - Blocks 4 & 5

     - Improved performance from previous solutions
     - Compatibility with Jeti R- and REX-receivers improved
     - RFID-tag Writing via Jetibox from transmitter added
+    - Accepts change of RFID-tag without power-cycle
     - Compatible with DC/DS-14/16/24
     - Compatible with Revo Bump and Robbe BID systems
     - Code housekeeping (Poorly...)

     Big thanks to RC-Groups forum-members who lent not only
-	Revo Bump tags but also an Revo Bump controller!
-	Michael and Warren, thank you!
+    Revo Bump tags but also an Revo Bump controller!
+    Michael and Warren, thank you!
    --------------------------------------------------------
      ALWAYS test functions thoroughly before use!
    --------------------------------------------------------
@@ -48,7 +49,7 @@
 MFRC522::MIFARE_Key key;

 #define prog_char char PROGMEM
-#define GETCHAR_TIMEOUT_ms 30 //was 20
+#define GETCHAR_TIMEOUT_ms 30

 #ifndef JETI_RX
 #define JETI_RX 3
@@ -64,12 +65,13 @@
 unsigned int uCells;
 unsigned int uCcount;
 unsigned int uPack;
-String uName = "N/A";
 unsigned int wBatteryID;
 unsigned int wCapacity;
 unsigned int wCycles;
 unsigned int wCells;
 unsigned int wCcount;
+String uName = "N/A";
+int uLoopCount = 0;

 #define ITEMNAME_1 F("ID")
 #define ITEMTYPE_1 F("")
@@ -214,7 +216,6 @@

 uint8_t frame[10];
 short value = 27;
-int uLoopCount = 0;
 #define MAX_SCREEN 9     //Jetibox screens
 #define MAX_CONFIG 1     //Jetibox configurations
 #define COND_LES_EQUAL 1
@@ -292,22 +293,22 @@
       }
     case 1 : {
         msg_line1[0] = 0; msg_line2[0] = 0;
-
+
         strcat_P((char*)&msg_line1, (prog_char*)F("#:"));
         temp[0] = 0;
         floatToString((char*)&temp, wBatteryID, 0);
         strcat((char*)&msg_line1, (char*)&temp);
-
+
         strcat_P((char*)&msg_line2, (prog_char*)F("Cap:"));
         temp[0] = 0;
         floatToString((char*)&temp, wCapacity, 0);
         strcat((char*)&msg_line2, (char*)&temp);
-
+
         strcat_P((char*)&msg_line1, (prog_char*)F(" Cy:"));
         temp[0] = 0;
         floatToString((char*)&temp, wCycles, 0);
         strcat((char*)&msg_line1, (char*)&temp);
-
+
         strcat_P((char*)&msg_line2, (prog_char*)F(" Cel:"));
         temp[0] = 0;
         floatToString((char*)&temp, wCells, 0);
@@ -317,7 +318,7 @@
         temp[0] = 0;
         floatToString((char*)&temp, wCcount, 0);
         strcat((char*)&msg_line1, (char*)&temp);
-
+
         JB.JetiBox((char*)&msg_line1, (char*)&msg_line2);
         break;
       }
@@ -401,6 +402,25 @@

 void loop()
 {
+  if ( bReadCard && revo ) {
+    mfrc522.PICC_IsNewCardPresent();
+    if (! mfrc522.PICC_IsNewCardPresent()) {
+      revo = false;
+      bReadCard = false;
+    }
+  }
+
+  if ( bReadCard && rct ) {
+    mfrc522.PCD_StopCrypto1();
+    mfrc522.PICC_IsNewCardPresent();
+    if (! mfrc522.PICC_IsNewCardPresent()) {
+      rct = false;
+      bReadCard = false;
+      uLoopCount = 0;
+    }
+  }
+
+  //
   if (! bReadCard) {
     if ( ! mfrc522.PICC_IsNewCardPresent()) {
       return;
@@ -410,43 +430,24 @@
       return;
     }

-    // If we are using RC-Thoughts tag
+    // Determine tag used
+    // Check if we are using RC-Thoughts tag
     MFRC522::PICC_Type piccType = mfrc522.PICC_GetType(mfrc522.uid.sak);
     if (piccType == MFRC522::PICC_TYPE_MIFARE_1K) {
       rct = true;
       revo = false;
-      readBlock(block, readbackblock);
-      uBatteryID = ((readbackblock[0] & 0xff) << 8) | readbackblock[1];
-      uCapacity = ((readbackblock[2] & 0xff) << 8) | readbackblock[3];
-      uCycles = ((readbackblock[4] & 0xff) << 8) | readbackblock[5];
-      uCells = ((readbackblock[6] & 0xff) << 8) | readbackblock[7];
-      readBlock(block2, readbackblock);
-      uCcount = ((readbackblock[0] & 0xff) << 8) | readbackblock[1];
-      Serial.println("Battery name: N/A");
-      Serial.print("ID: "); Serial.println(uBatteryID);
-      Serial.print("Capacity: "); Serial.println(uCapacity);
-      Serial.print("Cycles: "); Serial.println(uCycles);
-      Serial.print("Cells: "); Serial.println(uCells);
-      Serial.print("C-Value: "); Serial.println(uCcount);
-      bReadCard = true;
-
-      if (! tagValues)
-      {
-        wBatteryID = uBatteryID;
-        wCapacity = uCapacity;
-        wCycles = uCycles;
-        wCells = uCells;
-        wCcount = uCcount;
-      }
-      tagValues = true;
-    }
-    // If we are using Revo Bump-tag
+      uLoopCount = 0;
+    }
+    // Check if we are using Revo Bump-tag
     if (piccType == MFRC522::PICC_TYPE_MIFARE_UL) {
       rct = false;
       revo = true;
     }
   }
+
+  // If we are on RC-Thoughts Tag increase cycle-count after some time
   if ((uLoopCount == 240) && bReadCard && rct) {
+    mfrc522.PICC_ReadCardSerial();
     Serial.println("Writing out new cycle count");
     uCycles = uCycles + 1;
     unsigned char high = (byte)(uBatteryID >> 8);
@@ -466,12 +467,49 @@
     low  = (byte)uCcount;
     blockcontent[0] = high; blockcontent[1] = low;
     writeBlock(block2, blockcontent);
+    Serial.println("Battery name: N/A");
+    Serial.print("ID: "); Serial.println(uBatteryID);
+    Serial.print("Capacity: "); Serial.println(uCapacity);
+    Serial.print("Cycles: "); Serial.println(uCycles);
+    Serial.print("Cells: "); Serial.println(uCells);
+    Serial.print("C-Value: "); Serial.println(uCcount);
   }

   if ((uLoopCount < 241) && bReadCard && rct) {
     uLoopCount++;
   }

+  // RC-Thoughts Tag Process START
+  if (! bReadCard && rct) {
+    readBlock(block, readbackblock);
+    uBatteryID = ((readbackblock[0] & 0xff) << 8) | readbackblock[1];
+    uCapacity = ((readbackblock[2] & 0xff) << 8) | readbackblock[3];
+    uCycles = ((readbackblock[4] & 0xff) << 8) | readbackblock[5];
+    uCells = ((readbackblock[6] & 0xff) << 8) | readbackblock[7];
+    readBlock(block2, readbackblock);
+    uCcount = ((readbackblock[0] & 0xff) << 8) | readbackblock[1];
+    Serial.println("RC-Thoughts Info");
+    Serial.println("Battery name: N/A");
+    Serial.print("ID: "); Serial.println(uBatteryID);
+    Serial.print("Capacity: "); Serial.println(uCapacity);
+    Serial.print("Cycles: "); Serial.println(uCycles);
+    Serial.print("Cells: "); Serial.println(uCells);
+    Serial.print("C-Value: "); Serial.println(uCcount);
+    bReadCard = true;
+
+    if (! tagValues)
+    {
+      wBatteryID = uBatteryID;
+      wCapacity = uCapacity;
+      wCycles = uCycles;
+      wCells = uCells;
+      wCcount = uCcount;
+    }
+    tagValues = true;
+  }
+  // RC-Thoughts Tag Process END
+
+  // Revo Process START
   if (! bReadCard && revo) {
     // RFID-buffer definition
     byte buffer[18];
@@ -520,16 +558,26 @@
     // Process Revo pack-count for correct cell-count - Not used
     mfrc522.MIFARE_Read(27, buffer, &size);
     uPack = buffer[2];
-    if (uPack == 1){uCells = uCells*2;}
-    if (uPack == 2){uCells = uCells*3;}
-    if (uPack == 3){uCells = uCells*4;}
-    if (uPack == 4){uCells = uCells*5;}
-    if (uPack == 5){uCells = uCells*6;}
+    if (uPack == 1) {
+      uCells = uCells * 2;
+    }
+    if (uPack == 2) {
+      uCells = uCells * 3;
+    }
+    if (uPack == 3) {
+      uCells = uCells * 4;
+    }
+    if (uPack == 4) {
+      uCells = uCells * 5;
+    }
+    if (uPack == 5) {
+      uCells = uCells * 6;
+    }

     // Process Revo - Cycles
     mfrc522.MIFARE_Read(16, buffer, &size);
     uCycles = ((buffer[2] & 0xff) << 8) | buffer[1];
-
+    Serial.println("Revo-Info");;
     Serial.print("Battery name: "); Serial.println(uName);
     Serial.print("ID: "); Serial.println(uBatteryID);
     Serial.print("Capacity: "); Serial.println(uCapacity);
@@ -538,6 +586,7 @@
     Serial.print("C-Value: "); Serial.println(uCcount);
     bReadCard = true;
   }
+  // Revo Process END

   unsigned long time = millis();
   SendFrame();
@@ -580,12 +629,12 @@
         case 112 : // LEFT
           if (current_screen  != MAX_SCREEN)
             if (current_screen == 99) current_screen = 1;
-            if (current_screen == 98) current_screen = 1;
-            else
-            {
-              current_screen--;
-              if (current_screen > MAX_SCREEN) current_screen = 0;
-            }
+          if (current_screen == 98) current_screen = 1;
+          else
+          {
+            current_screen--;
+            if (current_screen > MAX_SCREEN) current_screen = 0;
+          }
           break;
         case 208 : // UP
           if (current_screen == 2) {
@@ -676,7 +725,7 @@
                 }
                 tagValues = true;
               }
-			  // Do not allow writing if Revo Bump is used, show a reason
+              // Do not allow writing if Revo Bump is used, show a reason
               if (bReadCard && revo) {
                 current_screen = 98;
               }
@@ -728,4 +777,4 @@
   else
     wait = wait - milli;
   pinMode(JETI_TX, OUTPUT);
-}+}


Updates watch.ino to use new SSD1306 API

--- watch.ino
+++ watch.ino
@@ -74,45 +74,29 @@
   if (changes == 0) return;

 #define W     Watch
-  uint8_t xpos = 0, ypos = 0;
-
-  uint8_t toclear;

   W.needs_redraw |= changes & REDRAW_FLAG;
   changes &= ~REDRAW_FLAG;

-  switch(changes) {
-     case 1:
-       toclear = 2;
-       break;
-     case 2:
-       toclear = 5;
-       break;
-     case 0xFF:
-     case 3:
-     default:
-       toclear = 8;
-       break;
-  }
-
-  if (W.needs_redraw) toclear = 8;
-
-  uint8_t clearwidth = SCREEN_WIDTH*toclear/8;
-  xpos = SCREEN_WIDTH - clearwidth;
-  oled.clearWindow(xpos, ypos, xpos+clearwidth, ypos + FONT_Y*2);
+  // not using FONT_Y and FONT_SIZE etc b/c I have to make sure h is a
+  // multiple of 8!
+  uint8_t h = 16;
+  uint8_t ypos = 16;
+  uint8_t xpos = (SCREEN_WIDTH - FONT_SPACE*8*2)/2;
+
+  oled.setBufferRegion(0, ypos, SCREEN_WIDTH, h);

   sprintf(_sbuf, "%02d:%02d:%02d", W.hours, W.minutes, W.seconds);
-  oled.drawString(_sbuf, 0, ypos, FONT_SIZE*2, W.color);
+
+  oled.drawString(_sbuf, xpos, 0, FONT_SIZE*2, W.color);

   if (changes > 3 || W.needs_redraw) {
-    ypos += LINE_HEIGHT*2;
-
-    oled.clearWindow(0, ypos, SCREEN_WIDTH, ypos+FONT_Y);
-
-    sprintf(_sbuf, "%04d/%02d/%02d", W.year, W.month, W.day);
-    xpos = SCREEN_WIDTH - (8*FONT_X);
+    oled.setBufferRegion(0, ypos+h+8, SCREEN_WIDTH, FONT_Y*2);
+
+    sprintf(_sbuf, "%02d/%02d", W.day, W.month);
+    xpos = SCREEN_WIDTH - (5*FONT_SPACE*2);
     xpos /= 2;
-    oled.drawString(_sbuf, xpos, ypos, FONT_SIZE, W.color);
+    oled.drawString(_sbuf, xpos, ypos, FONT_SIZE*2, W.color);
   }

   W.needs_redraw = 0;


More kludges to improve usability until speed is better

--- esp8266-arm-swd.ino
+++ esp8266-arm-swd.ino
@@ -139,22 +139,26 @@

     uint32_t addr = intArg("addr");
     uint32_t count = intArg("count");
-    if (count == 0) count = 64 * 1024 / 4;
+    if (count == 0) count = 4 * 1024 / 4;

     // Navigation links at the top and bottom
     for (int nav = 0;; nav++) {

-        appendMemLink(output, addr - count/4, count, "<<page");
+        appendMemLink(output, addr - count/4, count, "<--");
         output += " ";
         appendMemLink(output, addr - 64*1024/4, count, "<<64k");
         output += " ";
         appendMemLink(output, addr - 8*1024/4, count, "<<8k");
-        output += " - ";
+        output += " ";
+        appendMemLink(output, addr - 1*1024/4, count, "<<1k");
+        output += " --- ";
+        appendMemLink(output, addr + 1*1024/4, count, "1k>>");
+        output += " ";
         appendMemLink(output, addr + 8*1024/4, count, "8k>>");
         output += " ";
         appendMemLink(output, addr + 64*1024/4, count, "64k>>");
         output += " ";
-        appendMemLink(output, addr + count/4, count, "page>>");
+        appendMemLink(output, addr + count/4, count, "-->");
         output += "\n\n";

         if (nav > 0) {


2 obvious fuckups, untested - still a shitty late night hack

--- arduino_esp8266/omega_fallblatt_raw/omega_fallblatt_raw.ino
+++ arduino_esp8266/omega_fallblatt_raw/omega_fallblatt_raw.ino
@@ -44,8 +44,10 @@

   pinMode(PIN_STROBE, INPUT);

-  if(encoder_val == 63 || encoder_val != prev_val + 1)
+  if(encoder_val == 63 || encoder_val != prev_val + 1){
     timerReadEncoder.once_ms(1, readEncoder);
+    return;
+  }

   if(encoder_val == encoder_desired_val){
     digitalWrite(PIN_TRIAC_N, 1);
@@ -85,7 +87,7 @@
       encoder_desired_val++;
     if(ch == 's')
       encoder_desired_val--;
-    if(encoder_desired_val < 1)encoder_desired_val=63;
+    if(encoder_desired_val < 1)encoder_desired_val=62;
     if(encoder_desired_val > 62)encoder_desired_val=1;
     if(ch == 'x')
       digitalWrite(PIN_TRIAC_N, 1);


wip, not working yet

wip, not working yet

--- spBox.ino
+++ spBox.ino
@@ -36,7 +36,7 @@
 #define DELAY_MS_10HZ	100		// milliseconds delay -> 10 Hz

 // update_temperature_pressure_step
-#define SENSOR_TEMP_PAUSED				0
+#define SENSOR_PAUSED				0
 #define SENSOR_REQ_TEMP					1
 #define SENSOR_READ_TEMP_REQ_PRESSURE	2
 #define SENSOR_READ_PRESSURE			3
@@ -319,13 +319,13 @@
 	mag.getHeading(&sensors.mx, &sensors.my, &sensors.mz);
 }

-void get_temperature_pressure(int8_t step)
-{
-	switch (step){
+void get_temperature_pressure()
+{
+	switch (sensors.update_temperature_pressure_step){
 		case SENSOR_REQ_TEMP:
 			barometer.setControl(BMP085_MODE_TEMPERATURE);
 			os_timer_disarm(&timer_update_temperature_pressure_steps);
-			os_timer_setfn(&timer_update_temperature_pressure_steps, (os_timer_func_t *)update_temperature_pressure_cb, (void *)0);
+			os_timer_setfn(&timer_update_temperature_pressure_steps, (os_timer_func_t *)update_temperature_pressure_step_cb, (void *)0);
 			os_timer_arm(&timer_update_temperature_pressure_steps, barometer.getMeasureDelayMilliseconds(), false);
 			break;

@@ -380,17 +380,18 @@
 		get_mag();
 		sensors.changed_accel_gyro_mag = true;
 	}
+
 	if (sensors.do_update_temperature_pressure) {
 		sensors.do_update_temperature_pressure = false;
-		sensors.update_temperature_pressure_step = 1;
-		get_temperature_pressure(sensors.update_temperature_pressure_step);
+		sensors.update_temperature_pressure_step = SENSOR_REQ_TEMP;	// first step
+		get_temperature_pressure();
 	} else if (sensors.do_update_temperature_pressure_step) {
 		sensors.do_update_temperature_pressure_step = false;
 		sensors.update_temperature_pressure_step++;
-		get_temperature_pressure(sensors.update_temperature_pressure_step);
+		get_temperature_pressure();
 	}
 	if (sensors.update_temperature_pressure_step == SENSOR_DONE){
-		sensors.update_temperature_pressure_step = SENSOR_TEMP_PAUSED;
+		sensors.update_temperature_pressure_step = SENSOR_PAUSED;
 		sensors.changed_temperatur_pressure = true;
 	}
 }
@@ -450,11 +451,11 @@
 	initialize_barometer();
 	initialize_rotary_encoder();

-	//sensors.update_temperature_pressure_step = SENSOR_TEMP_PAUSED;
-	//setup_update_temperature_pressure_timer();
-
+	sensors.update_temperature_pressure_step = SENSOR_PAUSED;
+	sensors.do_update_temperature_pressure_step = false;
+	setup_update_temperature_pressure_timer();
 	setup_update_accel_gyro_mag_timer();
-	//setup_update_display_timer();
+	setup_update_display_timer();
 }

 void loop() {