Day one changes

Day one changes

--- code/arduino/_1rev/_1rev.ino
+++ code/arduino/_1rev/_1rev.ino
@@ -1,4 +1,7 @@
 #include <AccelStepper.h>
+
+// Steppers 1, 2 and 4 on big easy driver, stepper 3 on easydriver
+

 AccelStepper stepper1(1,12,13);
 AccelStepper stepper2(1,10,11);
@@ -6,8 +9,15 @@
 AccelStepper stepper4(1,8,9);
 void setup()
 {
+   Serial.begin(9600);
+   Keyboard.begin();
+   while (!Serial) {
+    ; // wait for serial port to connect. Needed for Leonardo only
+  }
+
+  Serial.write("Flip-Flap Ready!");
    stepper1.setMaxSpeed(12000);
-   stepper1.setAcceleration(12000.0);
+   stepper1.setAcceleration(24000.0);

    stepper2.setMaxSpeed(12000);
    stepper2.setAcceleration(12000.0);
@@ -20,14 +30,39 @@
 }
 void loop()
 {
-   stepper1.runToNewPosition(19200);
-   stepper2.runToNewPosition(19200);
-   stepper3.runToNewPosition(-9600);
-   stepper4.runToNewPosition(19200);
-   stepper1.setCurrentPosition(0);
-   stepper2.setCurrentPosition(0);
-   stepper3.setCurrentPosition(0);
-   stepper4.setCurrentPosition(0);
-   delay(2000);
+   if (Serial.available() > 0) {
+    // read incoming serial data:
+    char inChar = Serial.read();
+    // Type the next ASCII value from what you received:
+     switch (inChar){
+     case 'a':
+     stepper1.runToNewPosition(480);
+     stepper1.setCurrentPosition(0);
+     break;
+     case 'b':
+     stepper2.runToNewPosition(480);
+     stepper2.setCurrentPosition(0);
+     break;
+     case 'c':
+     stepper3.runToNewPosition(240);
+     stepper3.setCurrentPosition(0);
+     break;
+     case 'd':
+     stepper4.runToNewPosition(480);
+     stepper4.setCurrentPosition(0);
+     break;
+     }
+  }
+
+
+ //  stepper1.runToNewPosition(9600); //240 steps per letter
+ //  stepper2.runToNewPosition(9600);
+ //  stepper3.runToNewPosition(-4800); //120 steps per letter
+ //  stepper4.runToNewPosition(9600);
+ //  stepper1.setCurrentPosition(0);
+ //  stepper2.setCurrentPosition(0);
+ //  stepper3.setCurrentPosition(0);
+ //  stepper4.setCurrentPosition(0);
+ //  delay(2000);

 }


Added unit test for charlieplexed LEDs

Added unit test for charlieplexed LEDs

The 2x2 LEDs are charlieplexed meaning that
they are easily addressed one by one but
cannot be turned on together
In order to turn them on together, they
need to be flickered. Meaning they have
to be turned off and on quickly to make
it look like they are being turned on
simultaneously.
The results are quite good for 4 LEDs

Signed-off-by: nisha <ba6353e519422079c5746796dcd035c620a84798@gmail.com>

--- sketch_unittest/sketch_unittest.ino
+++ sketch_unittest/sketch_unittest.ino
@@ -56,9 +56,11 @@
   // 11 as an input for high impedence state
   pinMode(9, OUTPUT);
   pinMode(11, INPUT);
+  // Turn 1 on
   digitalWrite(10, LOW);
   digitalWrite(9, HIGH);
   delay(1000);
+  // Turn 2 on
   digitalWrite(9, LOW);
   digitalWrite(10, HIGH);
   delay(1000);
@@ -66,12 +68,84 @@
   // and set pin 11 as an output
   pinMode(11, OUTPUT);
   pinMode(9, INPUT);
+  // Turn 3 on
   digitalWrite(11, LOW);
   digitalWrite(10, HIGH);
   delay(1000);
+  // Turn 4 on
   digitalWrite(10, LOW);
   digitalWrite(11, HIGH);
   delay(1000);
+}
+
+/*
+ * Turn on 2x2 LED Matrix in this order:
+ * 1 2
+ * 3 4
+ * 1&2 and 3&4 are tied together so
+ * this will have to be flickered
+ * In addition, because modes are being changed
+ * for each LED selection, the loop timings are adjusted
+ */
+void turnOn2x2(){
+  // set 9 and 10 as outputs and 11 as
+  // as input for high impedence state
+  for (int i=1; i<=900; i++){
+    pinMode(9, OUTPUT);
+    pinMode(11, INPUT);
+    // turn 10 low and flicker 9 on and off
+    digitalWrite(10, LOW);
+    digitalWrite(9, HIGH);
+    delay(1);
+    digitalWrite(9, LOW);
+    delay(1);
+  }
+  // turn 1 and 2 on
+  for (int i=1; i<=900; i++){
+    pinMode(9, OUTPUT);
+    pinMode(11, INPUT);
+    digitalWrite(9, HIGH);
+    digitalWrite(10, LOW);
+    delay(1);
+    digitalWrite(9, LOW);
+    digitalWrite(10, HIGH);
+    delay(1);
+  }
+  // turn 1, 2 and 3 on
+  for (int i=1; i<=600; i++){
+    pinMode(9, OUTPUT);
+    pinMode(11, INPUT);
+    digitalWrite(9, HIGH);
+    digitalWrite(10, LOW);
+    delay(1);
+    digitalWrite(9, LOW);
+    digitalWrite(10, HIGH);
+    delay(1);
+    pinMode(9, INPUT);
+    pinMode(11, OUTPUT);
+    digitalWrite(11, LOW);
+    digitalWrite(10, HIGH);
+    delay(1);
+  }
+  // turn 1, 2, 3 and 4 on
+    for (int i=1; i<=500; i++){
+    pinMode(9, OUTPUT);
+    pinMode(11, INPUT);
+    digitalWrite(9, HIGH);
+    digitalWrite(10, LOW);
+    delay(1);
+    digitalWrite(9, LOW);
+    digitalWrite(10, HIGH);
+    delay(1);
+    pinMode(9, INPUT);
+    pinMode(11, OUTPUT);
+    digitalWrite(11, LOW);
+    digitalWrite(10, HIGH);
+    delay(1);
+    digitalWrite(10, LOW);
+    digitalWrite(11, HIGH);
+    delay(1);
+  }
 }

 void setup() {
@@ -82,5 +156,5 @@
 }

 void loop() {
-  blink2x2();
+  turnOn2x2();
 }


changed PID controller values for smoother driving

--- scr_arduino/scr_arduino.ino
+++ scr_arduino/scr_arduino.ino
@@ -46,9 +46,9 @@
 scr_proto::SpeedCommand motor_msg;

 // Initialize Publishers
-ros::Publisher left_encoder_pub("left_encoder", &l_enc_msg);
+//ros::Publisher left_encoder_pub("left_encoder", &l_enc_msg);
 ros::Publisher left_wheel_pub("lw_speed", &l_wheel_msg);
-ros::Publisher right_encoder_pub("right_encoder", &l_enc_msg);
+//ros::Publisher right_encoder_pub("right_encoder", &l_enc_msg);
 ros::Publisher right_wheel_pub("rw_speed", &r_wheel_msg);

 // Placeholders for wheel speeds in rad/s
@@ -70,13 +70,15 @@
 Timer g_TimerEncoder;
 float L_EncoderVelocity = 0; // Radians per second
 long L_LastEncoderValue = 0;
-double L_EncoderAngle = 0; // In revolutions (360.0 degrees = 1.0)
+double L_EncoderDelta = 0;
+double L_LastEncoderDelta = 0;
 float R_EncoderVelocity = 0; // Radians per second
 long R_LastEncoderValue = 0;
-double R_EncoderAngle = 0; // In revolutions (360.0 degrees = 1.0)
+double R_EncoderDelta = 0;
+double R_LastEncoderDelta = 0;
+double beta = .95;  // Low Pass Parameter for encoder velocity

 // Speed Controller Initialization
-
 double L_PIDout = 0;
 double R_PIDout = 0;

@@ -84,17 +86,17 @@
 PID L_DCMotorPID(&L_WheelVelocity,
                  &L_PIDout,
                  &lw_cmd_spd,
-                 1.5,
+                 0.75,
                  0.0,
-                 0.1,
+                 0.15,
                  REVERSE);

 PID R_DCMotorPID(&R_WheelVelocity,
                  &R_PIDout,
                  &rw_cmd_spd,
-                 1.5,
+                 0.75,
                  0.0,
-                 0.1,
+                 0.15,
                  REVERSE);

 // Motor Callbacks
@@ -110,13 +112,13 @@

   // Get position in revolutions (includes multiple revolutions)
 // Serial.println(encoderValue);
-  L_EncoderAngle = (double)L_encoderValue / (double)TICKS_PER_REVOLUTION;
-  R_EncoderAngle = (double)R_encoderValue / (double)TICKS_PER_REVOLUTION;
+  L_EncoderDelta = (double)(L_encoderValue - L_LastEncoderValue) * (1-beta) + L_LastEncoderDelta * beta;
+  R_EncoderDelta = (double)(R_encoderValue - R_LastEncoderValue) * (1-beta) + R_LastEncoderDelta * beta;
 // Serial.println(g_EncoderAngle);

   // Get velocity in ticks/sec
-  L_EncoderVelocity = 1000.0*(float)(L_encoderValue-L_LastEncoderValue)/(float)ENCODER_TIME_DELAY_MS;
-  R_EncoderVelocity = 1000.0*(float)(R_encoderValue-R_LastEncoderValue)/(float)ENCODER_TIME_DELAY_MS;
+  L_EncoderVelocity = 1000.0*(double)(L_EncoderDelta)/(double)ENCODER_TIME_DELAY_MS;
+  R_EncoderVelocity = 1000.0*(double)(R_EncoderDelta)/(double)ENCODER_TIME_DELAY_MS;

   // Convert to revolutions/sec
   L_EncoderVelocity /= (double)TICKS_PER_REVOLUTION;
@@ -129,6 +131,9 @@
   // Set last known encoder ticks
   L_LastEncoderValue = L_encoderValue;
   R_LastEncoderValue = R_encoderValue;
+
+  L_LastEncoderDelta = L_EncoderDelta;
+  R_LastEncoderDelta = R_EncoderDelta;
 }

 ros::Subscriber<scr_proto::SpeedCommand> motor_sub("speed_command", MotorCallback);
@@ -150,8 +155,8 @@
   nh.subscribe(motor_sub);

   // Encoder Pubs
-  nh.advertise(left_encoder_pub);
-  nh.advertise(right_encoder_pub);
+  //nh.advertise(left_encoder_pub);
+  //nh.advertise(right_encoder_pub);

   // Wheel Speeds in rad/s
   nh.advertise(right_wheel_pub);
@@ -183,14 +188,14 @@
   rm_cmd += R_PIDout;

   // Populate messages
-  l_enc_msg.data = lm_cmd;
-  r_enc_msg.data = rm_cmd;
+  //l_enc_msg.data = lm_cmd;
+  //r_enc_msg.data = rm_cmd;
   l_wheel_msg.data = L_WheelVelocity;
   r_wheel_msg.data = R_WheelVelocity;

   // Publish Data
-  left_encoder_pub.publish( &l_enc_msg );
-  right_encoder_pub.publish( &r_enc_msg );
+  //left_encoder_pub.publish( &l_enc_msg );
+  //right_encoder_pub.publish( &r_enc_msg );
   left_wheel_pub.publish( &l_wheel_msg );
   right_wheel_pub.publish( &r_wheel_msg );

@@ -200,6 +205,6 @@
   // Write Speeds to motor driver
   pmd.setSpeeds(lm_cmd, rm_cmd);

-  delay(25);
-}
-
+  delay(30);
+}
+


added '#include <SPI.h>' to .ino example because older versions of Arduino will complain if this header is not included

--- example/AnalogVoltageTester/AnalogVoltageTester.ino
+++ example/AnalogVoltageTester/AnalogVoltageTester.ino
@@ -1,3 +1,4 @@
+#include <SPI.h>
 #include <DACx311.h>
 #define PIN_CS 10


correction attente firmware

correction attente firmware

--- sensorSlave/sensorSlave.ino
+++ sensorSlave/sensorSlave.ino
@@ -6,7 +6,9 @@

 //TODO
 //
-// make adress configurable with digital pins
+// make adress configurable with digital pins or via I2C ?
+
+// store read frequency in EEPROM
 // write read frequency via I2C
 // read frequency via I2C

@@ -34,7 +36,6 @@
 #endif
 }

-
 void loop()
 {
   for (int i=0;i<sensor_SIZE;i++){
@@ -53,7 +54,6 @@

     digitalWrite(sensorPins[i][1], LOW);
     digitalWrite(sensorPins[i][0], LOW);
-    delay(100);
   }

 #ifdef LOG_SERIAL
@@ -64,8 +64,7 @@
   Serial.println();
 #endif

-  delay(800);
-
+  delay(600);
 }

 void requestEvent()


Bug fixes on Setup

Bug fixes on Setup

--- ps2_controller/ps2_controller.ino
+++ ps2_controller/ps2_controller.ino
@@ -9,9 +9,6 @@
   http://store.curiousinventor.com/guides/PS2/
   http://www.lynxmotion.com/images/files/ps2cmd01.txt
 */
-
-//  Todo: Add command to send Neutral controller data and reset controller inputs
-//  Send Neutral Controller data periodically (500ms, maybe?) when there's no input running

 #define axisLx 2
 #define axisLy 3
@@ -313,7 +310,7 @@
   calculatePong();
   getAttention();
   readMotors();
-  changeReadMotorsStatus();
+  //changeReadMotorsStatus();
   //Serial.println("END OF SETUP");
   //  And we are ready to go
 }


TG-13 #ready-for-test - print future state out of serial port

--- AlarmClock.ino
+++ AlarmClock.ino
@@ -19,6 +19,7 @@
 // INPUT OUTPUT VARIABLES
 int buttonValues[NUMBER_OF_BUTTONS];
 int oldButtonValues[NUMBER_OF_BUTTONS];
+
 // HARDWARE
 SoftwareSerial softwareSerial0(0, 1);


Change order of task initiation

Change order of task initiation

Control the initiation of the MAXM1 task from the OPER_TASK. The MAXM1
task already controls the initiation of the MAXM2 task.

Convert various magic values to constants and document.

--- sketches/control/single_bench/single_bench.ino
+++ sketches/control/single_bench/single_bench.ino
@@ -29,13 +29,29 @@
 const byte maxm2Dev = 13;

 // Start and end hours of operation
-const unsigned char start_hh = 9;
-const unsigned char start_mm = 0;
-const unsigned char stop_hh = 17;
-const unsigned char stop_mm = 0;
+const unsigned char start_hh = 18;
+const unsigned char start_mm = 39;
+const unsigned char stop_hh = 18;
+const unsigned char stop_mm = 40;
+
+// Length of first MaxM light cycle in seconds
+// The light scripts on the MaxMs MUST be
+// shorter than this value.
+// const byte maxm1_cycle = 90;
+const byte maxm1_cycle = 30;

 // Seconds after starting first MaxM to start second
-const byte maxm2_offset = 30;
+// const byte maxm2_offset = 30;
+const byte maxm2_offset = 15;
+
+// Length of time check cycle in seconds
+// const byte check_cycle = 60;
+const byte check_cycle = 15;
+
+// Somewhere I got the idea there was a pause needed
+// at the end of the setup() function. Set it to
+// 2 seconds.
+const byte startup_pause = 20;

 // LEDs
 const byte led1 = 1;
@@ -130,7 +146,11 @@
 // LEDs are on port 4
 Port ledPort (4);

-int is_operational = 0;
+// 1 = lights working, 0 = lights not
+byte is_operational = 0;
+
+// Set to 1 when MaxM 1 is active
+byte maxm1_active = 0;

 long start_min = 0;
 long stop_min = 0;
@@ -148,6 +168,10 @@
     Serial.flush();
 #endif

+    // Start the clock
+    // Not sure this is needed since it is a null function
+    RTC.begin();
+
     // Turn the radio off completely
     rf12_initialize(17, RF12_868MHZ);
     rf12_sleep(RF12_SLEEP);
@@ -159,7 +183,7 @@
     ledPort.mode(OUTPUT);
     ledPort.mode2(OUTPUT);

-    // The MaxMs are supposed to be programmed to not start on poweron
+    // The MaxMs are supposed to be programmed to not start on power-on
     // but turn thenm off just to be sure
     //TODO check for errors; and then do what?
     maxm1.send();
@@ -181,21 +205,20 @@
     maxm2.write(0);
     maxm2.stop();

+    //TODO check the RTC is working correctly
+
     // Start tasks after a pause for the power supply to settle
-    scheduler.timer(OPER_TIME, 15);
-    scheduler.timer(MAXM1, 20);
+    // Not sure where the "pause" came from!
+    scheduler.timer(OPER_TIME, startup_pause);
 }

 void loop () {
     switch (scheduler.pollWaiting()) {
         // Control first MaxM
         case MAXM1:
-#ifdef DEBUG_TRACE
-            Serial.print("MAXM1 operational: ");
-            Serial.println(is_operational);
-            Serial.flush();
-#endif
             if (is_operational == 1) {
+                scheduler.timer(MAXM1, maxm1_cycle * 10);
+                scheduler.timer(MAXM2, maxm2_offset * 10);
                 doFlash(ledPort, led1, 1);
 #ifdef DEBUG_TRACE
                 Serial.println("MAXM1");
@@ -207,14 +230,11 @@
                 maxm1.write(1);
                 maxm1.write(0);
                 maxm1.stop();
-            }
-            scheduler.timer(MAXM2, maxm2_offset * 10);
-            scheduler.timer(MAXM1, 900);
+            }
             break;

         // Control second MaxM
         case MAXM2:
-            if  (is_operational != 1) break;
             maxm2.send();
             maxm2.write('p');
             maxm2.write(0);
@@ -223,6 +243,10 @@
             maxm2.stop();

             doFlash(ledPort, led1, 2);
+#ifdef DEBUG_TRACE
+            Serial.println("MAXM2");
+            Serial.flush();
+#endif
             break;

         // Check if within operational time
@@ -230,38 +254,52 @@
             // Get time
             DateTime now = RTC.now();

-            // Loop every 60 seconds
-            const int loop_interval = 60;
-            int sec_til_loop = loop_interval - (now.get() % loop_interval);
-
-            // Check if should be operational and set flag
+            // Check every check_cycle seconds
+            int sec_til_check = check_cycle - (now.get() % check_cycle);
+            scheduler.timer(OPER_TIME, sec_til_check * 10);
+
+#ifdef DEBUG_TRACE
+            Serial.print("RTC time: ");
+            Serial.print(now.year());
+            Serial.print('-');
+            Serial.print(now.month());
+            Serial.print('-');
+            Serial.print(now.day());
+            Serial.print(' ');
+            Serial.print(now.hour());
+            Serial.print(':');
+            Serial.print(now.minute());
+            Serial.print(':');
+            Serial.print(now.second());
+            Serial.print(" dow: ");
+            Serial.println(now.dayOfWeek());
+            Serial.flush();
+#endif
+            // Check if should be operational and set flag
             long cur_min = toMin(now.hour(), now.minute());
             if ((cur_min >= start_min) && (cur_min < stop_min))  {
                 is_operational = 1;
+                // Start the MAXM1 task if not already active
+                if (maxm1_active == 0) {
+                  scheduler.timer(MAXM1, 0);
+                  maxm1_active = 1;
+                }
 #ifdef DEBUG_TRACE
                 Serial.println("Lights are operational");
                 Serial.flush();
 #endif
             } else {
                 is_operational = 0;
+                maxm1_active = 0;
+                //TODO consider turning off MaxMs like in setup()
 #ifdef DEBUG_TRACE
                 Serial.println("Lights are sleeping");
                 Serial.flush();
 #endif
             }

-            // Flash LED2 one for every minute in ten if "operational"
-            // otherwise only 1 flash
-            int num_flash = 1;
-            // Actually just flash one every minute
-            // if (is_operational == 1) {
-                // num_flash = (now.get() % 600);
-                // num_flash = num_flash / 60;
-            // }
-            doFlash(ledPort, led2, num_flash);
-
-            // Check reschedule amount aganst RTC
-            scheduler.timer(OPER_TIME, sec_til_loop * 10);
+            // Flash LED2 one for every minute
+            doFlash(ledPort, led2, 1);
             break;
     }
 }


Turn on asynchronously + add more button codes

--- volvo_hid.ino
+++ volvo_hid.ino
@@ -5,6 +5,8 @@
 // MCP2004 LIN bus frame:
 // ZERO_BYTE SYN_BYTE ID_BYTE DATA_BYTES.. CHECKSUM_BYTE

+#define DEBUG false
+
 #include "Mouse.h"
 #include "Keyboard.h"
 #include "SoftwareSerial.h"
@@ -15,11 +17,12 @@
 #define CS_PIN 15
 #define RX_LED 17
 #define MOBILE_CHARGER_PIN A3
-#define RTI_RX_PIN 8
-#define RTI_TX_PIN 9
+#define RTI_RX_PIN 16
+#define RTI_TX_PIN 10

 #define HEARTBEAT_TIMEOUT 2000
 #define CLICK_TIMEOUT 100
+#define OFF_CLICK_TIMEOUT 3000 // how long to hold "back" button to turn off

 #define RTI_INTERVAL 100
 #define MOBILE_CHARGER_TRIGGER_TIME 2500
@@ -47,12 +50,35 @@
 // BTN_RIGHT      20 8 0 0 0 F7
 // IGN_KEY_ON     50 E 0 F1

-#define JOYSTICK_UP 1
-#define JOYSTICK_DOWN 2
-#define JOYSTICK_LEFT 4
-#define JOYSTICK_RIGHT 8
-#define BUTTON_BACK 1
-#define BUTTON_ENTER 8
+#define KEY_MEDIA_PLAYPAUSE 0xe8
+#define KEY_MEDIA_STOPCD 0xe9
+#define KEY_MEDIA_PREVIOUSSONG 0xea
+#define KEY_MEDIA_NEXTSONG 0xeb
+#define KEY_MEDIA_EJECTCD 0xec
+#define KEY_MEDIA_VOLUMEUP 0xed
+#define KEY_MEDIA_VOLUMEDOWN 0xee
+#define KEY_MEDIA_MUTE 0xef
+#define KEY_MEDIA_WWW 0xf0
+#define KEY_MEDIA_BACK 0xf1
+#define KEY_MEDIA_FORWARD 0xf2
+#define KEY_MEDIA_STOP 0xf3
+#define KEY_MEDIA_FIND 0xf4
+#define KEY_MEDIA_SCROLLUP 0xf5
+#define KEY_MEDIA_SCROLLDOWN 0xf6
+#define KEY_MEDIA_EDIT 0xf7
+#define KEY_MEDIA_SLEEP 0xf8
+#define KEY_MEDIA_COFFEE 0xf9
+#define KEY_MEDIA_REFRESH 0xfa
+#define KEY_MEDIA_CALC 0xfb
+
+#define JOYSTICK_UP 0x1
+#define JOYSTICK_DOWN 0x2
+#define JOYSTICK_LEFT 0x4
+#define JOYSTICK_RIGHT 0x8
+#define BUTTON_BACK 0x1
+#define BUTTON_ENTER 0x8
+#define BUTTON_NEXT 0x10
+#define BUTTON_PREV 0x2

 short rtiStep;

@@ -60,7 +86,7 @@

 LinFrame frame = LinFrame();

-unsigned long currentMillis, lastHeartbeat, lastBackDown, lastEnterDown, lastMouseDown, lastRtiWrite;
+unsigned long currentMillis, lastHeartbeat, lastBackDown, lastEnterDown, lastMouseDown, lastOffDown, lastRtiWrite, lastPrevDown, lastNextDown, lastOnTrigger;
 int mouseSpeed = MOUSE_BASE_SPEED;
 short state = STATE_OFF;

@@ -70,7 +96,9 @@
   pinMode(CS_PIN, OUTPUT);
   digitalWrite(CS_PIN, HIGH);

-//  Serial.begin(9600);
+  if (DEBUG)
+    Serial.begin(9600);
+
   Serial1.begin(9600);
   rtiSerial.begin(2400);

@@ -79,6 +107,8 @@

   pinMode(MOBILE_CHARGER_PIN, OUTPUT);
   analogWrite(MOBILE_CHARGER_PIN, 0);
+
+  //turn_on();
 }

 void loop() {
@@ -87,7 +117,11 @@
   if (Serial1.available())
     read_lin_bus();

+  // debug
+  //test_mouse_move();
+
   release_keys();
+  release_on();
   check_ignition_key();
   rti();
 }
@@ -153,6 +187,9 @@
         Keyboard.press(KEY_ESC);

       lastBackDown = currentMillis;
+
+      if (!lastOffDown)
+        lastOffDown = currentMillis;
       break;

     case BUTTON_ENTER:
@@ -161,6 +198,29 @@

       lastEnterDown = currentMillis;
       break;
+
+    case BUTTON_PREV:
+      if (!lastPrevDown) {
+        Keyboard.press(KEY_MEDIA_PREVIOUSSONG);
+        debug("PREV");
+      }
+
+      lastPrevDown = currentMillis;
+      break;
+
+    case BUTTON_NEXT:
+      if (!lastNextDown) {
+        Keyboard.press(KEY_MEDIA_NEXTSONG);
+        debug("NEXT");
+      }
+
+      lastNextDown = currentMillis;
+      break;
+
+    default:
+      Serial.write(frame.get_byte(2));
+      debug("");
+      lastOffDown = 0;
   }
 }

@@ -189,27 +249,52 @@
     lastMouseDown = 0;
     mouseSpeed = MOUSE_BASE_SPEED;
   }
+
+  if (lastOffDown && currentMillis - lastOffDown > OFF_CLICK_TIMEOUT) {
+    turn_off();
+    lastOffDown = 0;
+  }
+
+  if (lastPrevDown && currentMillis - lastPrevDown > CLICK_TIMEOUT) {
+    Keyboard.release(KEY_MEDIA_PREVIOUSSONG);
+    lastPrevDown = 0;
+  }
+
+  if (lastNextDown && currentMillis - lastNextDown > CLICK_TIMEOUT) {
+    Keyboard.release(KEY_MEDIA_NEXTSONG);
+    lastNextDown = 0;
+  }
 }

 void check_ignition_key() {
   if (lastHeartbeat && currentMillis - lastHeartbeat > HEARTBEAT_TIMEOUT) {
+    debug("Ignition off");
     lastHeartbeat = 0;
     turn_off();
   }
 }

 void turn_on() {
+  debug("Turn on");
   state = STATE_ON;
   turn_on_phone();
 }

 void turn_on_phone() {
   analogWrite(MOBILE_CHARGER_PIN, 255);
-  delay(MOBILE_CHARGER_TRIGGER_TIME);
-  analogWrite(MOBILE_CHARGER_PIN, 0);
+  lastOnTrigger = currentMillis;
+}
+
+void release_on() {
+  if (lastOnTrigger && currentMillis - lastOnTrigger > MOBILE_CHARGER_TRIGGER_TIME) {
+    analogWrite(MOBILE_CHARGER_PIN, 0);
+    lastOnTrigger = 0;
+    debug("Release on");
+  }
 }

 void turn_off() {
+  debug("Turn off");
   state = STATE_OFF;
 }

@@ -223,6 +308,11 @@
         rti_print(0x46);
       else
         rti_print(0x40);
+
+      if (state == STATE_OFF)
+        debug("RTI OFF");
+      else
+        debug("RTI ON");

       rtiStep++;
       break;
@@ -247,6 +337,13 @@

 // -- debugging

+void test_mouse_move() {
+  delay(1000);
+  Mouse.move(10, 10, 0);
+  delay(1000);
+  Mouse.move(-10, -10, 0);
+}
+
 void dump_frame() {
   for (int i = 0; i < frame.num_bytes(); i++) {
     Serial.print(frame.get_byte(i), HEX);
@@ -255,3 +352,8 @@
   Serial.println();
 }

+void debug(char* message) {
+  if (DEBUG)
+    Serial.println(message);
+}
+


add remote function

add remote function

--- arduino/opencr_arduino/opencr/libraries/OpenManipulator/example/Arduino/Chain/d_open_manipulator_chain/d_open_manipulator_chain.ino
+++ arduino/opencr_arduino/opencr/libraries/OpenManipulator/example/Arduino/Chain/d_open_manipulator_chain/d_open_manipulator_chain.ino
@@ -34,14 +34,15 @@
   initManipulator();

   connectProcessing();
-
-  goal_position.push_back(0.0);
-  goal_position.push_back(0.0);
-  goal_position.push_back(0.0);
-  goal_position.push_back(0.0);
-
-  goal_pose.position = OM_MATH::makeVector3(-0.050, 0.0, 0.203);
-  goal_pose.orientation = Eigen::Matrix3f::Identity();
+  connectRC100();
+
+  // goal_position.push_back(0.0);
+  // goal_position.push_back(0.0);
+  // goal_position.push_back(0.0);
+  // goal_position.push_back(0.0);
+
+  // goal_pose.position = OM_MATH::makeVector3(-0.050, 0.0, 0.203);
+  // goal_pose.orientation = Eigen::Matrix3f::Identity();

   initThread();
   startThread();
@@ -49,14 +50,15 @@

 void loop()
 {
-  // fromRC100();
-
-  if (Serial.available())
-  {
-    MUTEX::wait();
-    fromProcessing(Serial.readStringUntil('\n'));
-    MUTEX::release();
-  }
+  getData(0.100f);
+
+
+  // if (Serial.available())
+  // {
+  //   MUTEX::wait();
+  //   fromProcessing(Serial.readStringUntil('\n'));
+  //   MUTEX::release();
+  // }

   // switch(seq)
   // {
@@ -139,4 +141,63 @@
     loop();
     showLedStatus();
   }
+}
+
+void getData(uint32_t wait_time)
+{
+  static uint8_t state = 0;
+  static uint32_t tick = 0;
+
+  bool rc100_flag      = false;
+  bool processing_flag = false;
+
+  uint16_t get_rc100_data     = 0;
+  String get_processing_data = "";
+
+  if (availableRC100())
+  {
+    get_rc100_data = rc100.readData();
+    rc100_flag = true;
+  }
+
+  if (availableProcessing())
+  {
+    get_processing_data = Serial.readStringUntil('\n');
+    processing_flag = true;
+  }
+
+  switch (state)
+  {
+    case 0:
+      if (rc100_flag)
+      {
+        MUTEX::wait();
+        fromRC100(get_rc100_data);
+        MUTEX::release();
+
+        tick = millis();
+        state  = 1;
+      }
+      else if (processing_flag)
+      {
+        MUTEX::wait();
+        fromProcessing(get_processing_data);
+        MUTEX::release();
+
+        tick = millis();
+        state  = 1;
+      }
+     break;
+
+    case 1:
+      if ((millis() - tick) >= wait_time)
+      {
+        state = 0;
+      }
+     break;
+
+    default :
+     state = 0;
+     break;
+  }
 }


Fixed issue #14

Fixed issue #14

--- DigitalVFO.ino
+++ DigitalVFO.ino
@@ -853,8 +853,8 @@
   attachInterrupt(digitalPinToInterrupt(re_pinB), pinB_isr, RISING);
   attachInterrupt(digitalPinToInterrupt(re_pinPush), pinPush_isr, CHANGE);

-  // look at RE button, if DOWN this function returns 'true'
-  return (PIND & 0x10);
+  // look at RE push button, if DOWN this function returns 'true'
+  return PIND & 0x10;
 }

 //----------------------------------------
@@ -1308,6 +1308,12 @@
     lcd.print("DigitalVFO reset");
     lcd.setCursor(0, 1);
     lcd.print(" nothing saved");
+
+    // wait until button NOT down
+    while (PIND & 0x10)
+      ;
+
+    // after a small delay, continue
     delay(2000);
     lcd.clear();
     delay(1000);
@@ -1321,6 +1327,9 @@

   // show the main screen and continue in loop()
   show_main_screen();
+
+  // eat any events that may have been generated
+  event_flush();
 }

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


Added latest sensor code from Lucas.

Added latest sensor code from Lucas.

--- src/MonsterSketch/MonsterSketch.ino
+++ src/MonsterSketch/MonsterSketch.ino
@@ -91,12 +91,14 @@

   g_poMySensorModule->getLocation(g_fX,g_fY,g_fZ);
   g_poDataMonster->setPosture(g_fX,  g_fY,  g_fZ);
-  Serial.print("X: ");
-  Serial.print(g_fX);
-  Serial.print(" Y: ");
-  Serial.print(g_fY);
-  Serial.print(" Z: ");
-  Serial.println(g_fZ);
+ Serial.print(g_fX, DEC);
+  Serial.print(",");
+  delay(1);
+  Serial.print(g_fY, DEC);
+  Serial.print(",");
+  delay(1);
+  Serial.print(g_fZ, DEC);
+  Serial.println();

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


inhibit automatic close on restart

inhibit automatic close on restart

--- GeheimTuer.ino
+++ GeheimTuer.ino
@@ -297,10 +297,12 @@
     doorState = doorClosed;
     setLeds1(green, ledFade);
     Serial.print(F("closed\r\n"));
+/*
   } else if (swBack == LOW) {
     doorState = doorOpen;
     setLeds1(green, ledBlink);
     Serial.print(F("open\r\n"));
+*/
   } else {
     doorState = doorBlocked;
     setLeds1(red, ledSolid);


readability changes

readability changes

--- GeheimTuer.ino
+++ GeheimTuer.ino
@@ -28,7 +28,7 @@
 const int switchTrigger = 2;
 const int switchTriggerIRQ = 0;

-// PIR sensor
+// PIR sensor, active-high
 const int pirPin = 12;

 // on-board status LED
@@ -36,6 +36,7 @@

 // ad-hoc acceleration profile
 // TODO: self-calibration by means of driveTotalMillis
+// TODO: sense & limit motor current
 struct accelProfile {
   unsigned long maxMillis; // time until next step, 0 == end of profile
   unsigned long stepMillis; // modify PWM value every stepMillis ms
@@ -57,7 +58,7 @@
     add: 4,
     minPWM: 0,
     maxPWM: 64,
-    startPWM: 0,
+    startPWM: 1,
     useStartPWM: true,
     brake: false
   },
@@ -68,6 +69,7 @@

 // normal operation
 // try accelerating as fast as possible without skipping belt teeth
+// belt tension limits torque. important safety feature
 // TODO: install less stiff spring between belt and door to dampen the initial pull
 const struct accelProfile accelProfileHigh[] = {
   { // slow start
@@ -77,7 +79,7 @@
     add: 1,
     minPWM: 0,
     maxPWM: 255,
-    startPWM: 0,
+    startPWM: 1,
     useStartPWM: true, // first element always sets initial PWM value
     brake: false
   },
@@ -208,16 +210,16 @@
 // buttons & switches do different things in different states
 enum doorStates { doorClosed, doorOpening, doorOpen, doorClosing, doorBlocked, doorBlockedPir, doorError } doorState;

-double drivePWM = 0;
+double drivePWM;
 const double drivePWMscale = 1; // fiddling aid, constant factor applied to calculated PWM value. TODO: update profile & remove

 // TODO: the timing system has some quirks. think again or document

 unsigned long lastMillis = 0; // last loop's millis() result

-unsigned long driveMillis = 0;
-unsigned long driveStepMillis = 0;
-unsigned long driveTotalMillis = 0;
+unsigned long driveMillis;
+unsigned long driveProfileMillis;
+unsigned long driveTotalMillis;

 const unsigned long openInterval = 3000; // ms before the door closes again, unless blocked by button
 unsigned long openMillis = 0;
@@ -232,6 +234,8 @@
 //const unsigned long ledMoveInterval = 250; // shift LED window every X ms
 unsigned long ledMoveInterval; // shift LED window every X ms - varied by drivePWM
 unsigned long ledMillis = 0;
+const unsigned int ledMoveMin = 50; // minimum move interval if drivePWM == 255
+const unsigned int ledMoveMax = 305; // maximum move interval if drivePWM == 0

 bool swFront, swBack, swTrigger, motorDiagA, motorDiagB, pirTrigger; // debounced inputs
 bool swFrontDeglitch, swBackDeglitch, swTriggerDeglitch, motorDiagADeglitch, motorDiagBDeglitch, pirDeglitch; // TODO: quick hack. document
@@ -404,16 +408,16 @@
   switch(doorState) {
     case doorClosed:
       // wait until a button is pressed or the front switch opens
-      if (swFront == HIGH || swTrigger == LOW) {
-        if (swFront == HIGH) {
+      if (swTrigger == LOW || swFront == HIGH) {
+        if (swTrigger == LOW) {
+          debug(currentMillis, F("Button switch triggered - opening door\r\n"));
+          initDrive(backward, accelProfileHigh);
+          swTrigger = HIGH; // re-arm swTrigger
+        } else {
           // maybe someone tried to pull the door open
           // TODO: or the door slams too fast into the end-stop and rebounds. align profile & inertial reality
           debug(currentMillis, F("Front switch triggered - opening door\r\n"));
           initDrive(backward, accelProfileLow);
-        } else {
-          debug(currentMillis, F("Button switch triggered - opening door\r\n"));
-          initDrive(backward, accelProfileHigh);
-          swTrigger = HIGH; // re-arm swTrigger
         }
         setLeds2(white, black, EXTRAPIX, ledBackward);
         doorState = doorOpening;
@@ -431,12 +435,13 @@
         break;
       }

-if (pirTrigger == HIGH) {
-  debug(currentMillis, F("Motion sensor triggered - door blocked by PIR\r\n"));
-  setLeds1(yellow, ledBlink);
-  doorState = doorBlockedPir;
-  break;
-}
+      // reset timeout while sensor input is HIGH
+      if (pirTrigger == HIGH) {
+        debug(currentMillis, F("Motion sensor triggered - door blocked by PIR\r\n"));
+        setLeds1(yellow, ledBlink);
+        doorState = doorBlockedPir;
+        break;
+      }

       openMillis += elapsedMillis;
       if (openMillis >= openInterval || swBack == HIGH) {
@@ -490,14 +495,14 @@
       }

       driveTotalMillis += elapsedMillis;
-      driveStepMillis += elapsedMillis;
-      if (driveStepMillis >= accelProfile[accelProfileIdx].stepMillis) {
-        driveMillis += driveStepMillis;
-        driveStepMillis = 0;
+      driveMillis += elapsedMillis;
+      if (driveMillis >= accelProfile[accelProfileIdx].stepMillis) {
+        driveProfileMillis += driveMillis;
+        driveMillis = 0;

         // switch to next profile step
-        if (driveMillis >= accelProfile[accelProfileIdx].maxMillis) {
-          driveMillis = 0;
+        if (driveProfileMillis >= accelProfile[accelProfileIdx].maxMillis) {
+          driveProfileMillis = 0;
           accelProfileIdx++;

           // end-stop not reached at end of profile, someone might be in the way
@@ -541,7 +546,7 @@

         analogWrite(motorPWMPin, round(drivePWM*drivePWMscale));

-ledMoveInterval = 50 + ((1-(drivePWM/255))*200);
+ledMoveInterval = ledMoveMin + ((255-drivePWM)*((double)(ledMoveMax-ledMoveMin)/255));
 Serial.print(F(", ledMoveInterval: "));
 Serial.println(ledMoveInterval);

@@ -549,20 +554,8 @@
       break;

     case doorBlockedPir:
+      // motion stopped, return to work
       if (pirTrigger == LOW) {
-
-// hold the door open if button pressed
-// TODO: another possibility would be to fall-through to doorBlocked
-// and close the door instead. which way is better?
-if (swTrigger == LOW) {
-  motorFree();
-  debug(currentMillis, F("Button switch triggered - door blocked\r\n"));
-  setLeds1(red, ledSolid);
-  doorState = doorBlocked;
-  swTrigger = HIGH;
-  break;
-}
-
         if (swBack == LOW) {
           debug(currentMillis, F("IR sensor LOW - door open\r\n"));
           openMillis = 0;
@@ -573,6 +566,16 @@
           setLeds1(red, ledSolid);
           doorState = doorBlocked;
         }
+      }
+      // hold the door open if button pressed
+      // TODO: another possibility would be to fall-through to doorBlocked
+      // and close the door instead. which way is better?
+      if (swTrigger == LOW) {
+        motorFree();
+        debug(currentMillis, F("Button switch triggered - door blocked\r\n"));
+        setLeds1(red, ledSolid);
+        doorState = doorBlocked;
+        swTrigger = HIGH;
       }
       break;

@@ -728,7 +731,7 @@
   accelProfile = profile;
   accelProfileIdx = 0;
   drivePWM = accelProfile[0].startPWM;
-  driveMillis = driveStepMillis = driveTotalMillis = 0;
+  driveMillis = driveProfileMillis = driveTotalMillis = 0;

   switch(motorDir) {
     case forward:


Update BB-UNIT.ino

Update BB-UNIT.ino

--- Firmware/BB-UNIT/BB-UNIT.ino
+++ Firmware/BB-UNIT/BB-UNIT.ino
@@ -70,6 +70,11 @@

   < ENABLE >
   'ENABLE a1 x1 z1 \n'    // ENABLE MOTOR AB, XY and Z (a = AB, x=XY, z = Z | 0 = desabled | 1 = enabled )
+
+
+
+  FOR AFTER
+  http://tutorial.cytron.com.my/2014/05/15/wireless-uart-with-arduino-and-433mhz-or-434mhz-module/

 */


Actuator with IR Sensor working.

Actuator with IR Sensor working.

--- hardware/actuators/actuator/actuator.ino
+++ hardware/actuators/actuator/actuator.ino
@@ -4,23 +4,58 @@
 AF_DCMotor motor2(2, MOTOR12_64KHZ); // create motor #2, 64KHz pwm
 String inputString = "";         // a string to hold incoming data
 boolean stringComplete = false;  // whether the string is complete
-
+int toggleCountdown = 0;
+int sensorPin = A0;    // select the input pin for the potentiometer
+int sensorValue = 0;  // variable to store the value coming from the sensor
+int offCount = 0;
+
+
 void setup() {
-  Serial.begin(250000);           // set up Serial library at 9600 bps
-  Serial.println("Motor test!");
+  Serial.begin(250000);
   motor1.setSpeed(255);     // set the speed to 200/255
   motor2.setSpeed(255);     // set the speed to 200/255
   inputString.reserve(10);
 }

 void loop() {
-  serialEvent();
+   readIRSensor();
+   serialEvent();
  if (stringComplete) {
-    toggle();
+    toggle(true);
+    toggleCountdown = 2000;
     inputString = "";
     stringComplete = false;
   }
+  if (toggleCountdown != 0) {
+    if (toggleCountdown == 1) {
+      toggleCountdown = 0;
+      toggle(false);
+    }
+  else {toggleCountdown--;}
+  }
 }
+
+void readIRSensor() {
+  //Serial.println(analogRead(sensorPin));
+
+  int irSensorVoltageCutoff = 900;
+  // the average power of the sensor through an ever more dirty belt.
+  // Heck this is the dirty belt sensor!
+  //irSensorVoltageCutoff needs to adjust, maybe it should be set on the PC side?
+  if (analogRead(sensorPin) > irSensorVoltageCutoff)  {
+      offCount = offCount + 1;
+    }
+  else
+  {
+  if (offCount != 0) {
+      //if it's under 50 it's just a bounce.
+      if (offCount > 50) {
+        Serial.println(offCount );
+      }
+      offCount = 0;
+      }
+  }
+}

 void serialEvent() {
   while (Serial.available()) {
@@ -36,14 +71,18 @@
   }
 }

-void toggle() {
-  motor1.run(FORWARD);      // turn it on going forward
-  motor2.run(FORWARD);      // turn it on going forward
-  delay(50);
-  motor1.run(RELEASE);      // stopped
-  motor2.run(RELEASE);      // stopped
+void toggle(boolean on) {
+  if (on) {
+    motor1.run(FORWARD);      // turn it on going forward
+    motor2.run(FORWARD);      // turn it on going forward
+  }
+  else {
+    motor1.run(RELEASE);      // stopped
+    motor2.run(RELEASE);      // stopped
+   }
 }

+


What do you feed a invisible plant?

What do you feed a invisible plant?

--- Skittle_sorter/Skittle_sorter/Skittle_sorter.ino
+++ Skittle_sorter/Skittle_sorter/Skittle_sorter.ino
@@ -1,29 +1,132 @@
-/*Button
- * LED attached from pin 13 to ground
- * pushbutton attached to pin 2 from +5V
- * 10K resistor attached to pin 2 from ground
+/*     Arduino Project - Color Sorting Machine
+ *
+ *  by Dejan Nedelkovski, www.HowToMechatronics.com
+ *
  */
-
-const int buttonPin = 2;
-const int ledPin =  13;
-int buttonState = 0;         // variable for reading pushbutton status
-
+#include <Servo.h>
+#define S0 2
+#define S1 3
+#define S2 4
+#define S3 5
+#define sensorOut 6
+Servo topServo;
+Servo bottomServo;
+int frequency = 0;
+int color=0;
 void setup() {
-  pinMode(ledPin, OUTPUT);
-  pinMode(buttonPin, INPUT);
+  pinMode(S0, OUTPUT);
+  pinMode(S1, OUTPUT);
+  pinMode(S2, OUTPUT);
+  pinMode(S3, OUTPUT);
+  pinMode(sensorOut, INPUT);
+  // Setting frequency-scaling to 20%
+  digitalWrite(S0, HIGH);
+  digitalWrite(S1, LOW);
+  topServo.attach(7);
+  bottomServo.attach(8);
+  Serial.begin(9600);
 }
-
 void loop() {
-  // read the state of the pushbutton value:
-  buttonState = digitalRead(buttonPin);
-
-  // check if the pushbutton is pressed.
-  // if it is, the buttonState is HIGH:
-  if (buttonState == HIGH) {
-    // LED on:
-    digitalWrite(ledPin, HIGH);
-  } else {
-    // LED off:
-    digitalWrite(ledPin, LOW);
+  topServo.write(115);
+  delay(500);
+
+  for(int i = 115; i > 65; i--) {
+    topServo.write(i);
+    delay(2);
   }
+  delay(500);
+
+  color = readColor();
+  delay(10);
+  switch (color) {
+    case 1:
+    bottomServo.write(50);
+    break;
+    case 2:
+    bottomServo.write(75);
+    break;
+    case 3:
+    bottomServo.write(100);
+    break;
+    case 4:
+    bottomServo.write(125);
+    break;
+    case 5:
+    bottomServo.write(150);
+    break;
+    case 6:
+    bottomServo.write(175);
+    break;
+
+    case 0:
+    break;
+  }
+  delay(300);
+
+  for(int i = 65; i > 29; i--) {
+    topServo.write(i);
+    delay(2);
+  }
+  delay(200);
+
+  for(int i = 29; i < 115; i++) {
+    topServo.write(i);
+    delay(2);
+  }
+  color=0;
 }
+// Custom Function - readColor()
+int readColor() {
+  // Setting red filtered photodiodes to be read
+  digitalWrite(S2, LOW);
+  digitalWrite(S3, LOW);
+  // Reading the output frequency
+  frequency = pulseIn(sensorOut, LOW);
+  int R = frequency;
+  // Printing the value on the serial monitor
+  Serial.print("R= ");//printing name
+  Serial.print(frequency);//printing RED color frequency
+  Serial.print("  ");
+  delay(50);
+  // Setting Green filtered photodiodes to be read
+  digitalWrite(S2, HIGH);
+  digitalWrite(S3, HIGH);
+  // Reading the output frequency
+  frequency = pulseIn(sensorOut, LOW);
+  int G = frequency;
+  // Printing the value on the serial monitor
+  Serial.print("G= ");//printing name
+  Serial.print(frequency);//printing RED color frequency
+  Serial.print("  ");
+  delay(50);
+  // Setting Blue filtered photodiodes to be read
+  digitalWrite(S2, LOW);
+  digitalWrite(S3, HIGH);
+  // Reading the output frequency
+  frequency = pulseIn(sensorOut, LOW);
+  int B = frequency;
+  // Printing the value on the serial monitor
+  Serial.print("B= ");//printing name
+  Serial.print(frequency);//printing RED color frequency
+  Serial.println("  ");
+  delay(50);
+  if(R<45 & R>32 & G<65 & G>55){
+    color = 1; // Red
+  }
+  if(G<55 & G>43 & B<47 &B>35){
+    color = 2; // Orange
+  }
+  if(R<53 & R>40 & G<53 & G>40){
+    color = 3; // Green
+  }
+  if(R<38 & R>24 & G<44 & G>30){
+    color = 4; // Yellow
+  }
+  if(R<56 & R>46 & G<65 & G>55){
+    color = 5; // Brown
+  }
+  if (G<58 & G>45 & B<40 &B>26){
+    color = 6; // Blue
+  }
+  return color;
+}


Cleanup and better battery reporting

Cleanup and better battery reporting

--- DigitalVFO.ino
+++ DigitalVFO.ino
@@ -15,12 +15,6 @@
 #include <LiquidCrystal.h>
 #include <EEPROM.h>

-//-----
-// Conditional compile flags
-//-----
-
-#define INC_BATTERY   1
-
 // debug bit masks:
 #define DEBUG_DDS     (1 << 0)
 #define DEBUG_FREQ    (1 << 1)
@@ -30,9 +24,7 @@
 #define DEBUG_RE      (1 << 5)
 #define DEBUG_INT     (1 << 6)
 #define DEBUG_DISP    (1 << 7)
-#if INC_BATTERY
 #define DEBUG_BATT    (1 << 8)
-#endif

 #define DEBUG         (DEBUG_BATT)
 //#define DEBUG         0
@@ -198,8 +190,9 @@
 //-----

 // milliseconds delay between measuring battery voltage
-//const int VoltageDelay = 1000;
-const int VoltageDelay = 30000;
+const long MeasureVoltageDelay = 1000;
+// number of measure periods before report (if wanted in DEBUG)
+const long ReportVoltageDelay = 30;

 // stuff for the calibrate action
 const int MinClockOffset = -32000;
@@ -347,10 +340,8 @@
     Serial.println("    DEBUG_INT\tbit is set");
   if (debug & DEBUG_DISP)
     Serial.println("    DEBUG_DISP\tbit is set");
-#if INC_BATTERY
   if (debug & DEBUG_BATT)
     Serial.println("    DEBUG_BATT\tbit is set");
-#endif
 }

 //----------------------------------------
@@ -2197,7 +2188,7 @@
 {
   lcd.clear();
   lcd.setCursor(0, 0);
-  lcd.print("Vfo:");
+  lcd.print("Freq:");
   display_sel_value(VfoFrequency, VfoSelectDigit, NumFreqChars, NumCols - NumFreqChars - 2, 0);
   lcd.print("Hz");

@@ -2993,56 +2984,90 @@
 struct MenuItem *mia_main[] = {&mi_slots, &mi_settings, &mi_reset, &mi_credits};
 struct Menu menu_main = {"Menu", ALEN(mia_main), mia_main};

-
-//----------------------------------------
-// Standard Arduino loop() function.
-//----------------------------------------
-
-void loop(void)
-{
-#if INC_BATTERY
-  // measure voltage every whenever
-  // we will get a value of 1023 for 3.3 volts
-  static UINT last_volts_time = -VoltageDelay;    // millis() value last time we measured
-  ULONG now = millis();
-  if (now < last_volts_time)
-    last_volts_time = -VoltageDelay;    // handle wraparound of millis()
-  if (now > last_volts_time + VoltageDelay)
-  {
-    last_volts_time = now;
-    UINT measured = analogRead(mc_BattVolts);
-    MeasuredVoltage = ((3.3 * measured) / 1023) * (32.0/10.0);
+//----------------------------------------
+// Measure the battery voltage.
+// We measure every "MeasureVoltageDelay" milliseconds, update the battery symbol.
+// If DEBUG reporting is turned on, we report every "ReportVoltageDelay" measurements.
+//----------------------------------------
+
+void measure_battery(void)
+{
+  // get the time since the last measurement
+  static long last_volts_time = -MeasureVoltageDelay;    // millis() value last time we measured
+  long now_milli = millis();
+  if (now_milli < last_volts_time)
+    last_volts_time = -MeasureVoltageDelay;    // handle wraparound of millis()
+
+  // if not time yet, return
+  if (now_milli < last_volts_time + MeasureVoltageDelay)
+    return;
+
+  // measuring, set measurement time to "now"
+  last_volts_time = now_milli;
+
+  // measure voltage, we will get a value of 1023 for 3.3 volts
+  UINT measured = analogRead(mc_BattVolts);
+  MeasuredVoltage = ((3.3 * measured) / 1023) * (32.0/10.0);

 #if (DEBUG & DEBUG_BATT)
-      Serial.printf(F("raw volts=%d\n"), measured);
-#endif
-
-    // figure out which battery symbol to use
-    if (MeasuredVoltage < MinVoltage)
+  static int batt_report_count = 0;
+  if (++batt_report_count > 0)
+  {
+    Serial.printf(F("raw volts=%d, "), measured);
+  }
+#endif
+
+  // figure out which battery symbol to use
+  if (MeasuredVoltage < MinVoltage)
+  {
+    if (MeasuredVoltage < 1.0)
     {
-        BatterySymbol = battunder;
-        if (MeasuredVoltage < 1.0)
-        {
-          BatterySymbol = battnone;
-        }
+      BatterySymbol = battnone;
+#if (DEBUG & DEBUG_BATT)
+      if (batt_report_count > 0)
+        Serial.printf(F("no battery\n"));
+#endif
     }
-    else if (MeasuredVoltage > MaxVoltage)
-        BatterySymbol = battover;
     else
     {
-      int percent = (int) ((MeasuredVoltage - MinVoltage) / (MaxVoltage - MinVoltage) * 100.0);
-      int batt_bucket = (int) (percent/20);
-      BatterySymbol = batt_syms[batt_bucket + 2];
+      BatterySymbol = battunder;
 #if (DEBUG & DEBUG_BATT)
+      if (batt_report_count > 0)
+        Serial.printf(F("battery under voltage\n"));
+#endif
+    }
+  }
+  else if (MeasuredVoltage > MaxVoltage)
+  {
+    BatterySymbol = battover;
+#if (DEBUG & DEBUG_BATT)
+    if (batt_report_count > 0)
+      Serial.printf(F("battery over voltage\n"));
+#endif
+  }
+  else
+  {
+    int percent = (int) ((MeasuredVoltage - MinVoltage) / (MaxVoltage - MinVoltage) * 100.0);
+    int batt_bucket = (int) (percent/20);
+    BatterySymbol = batt_syms[batt_bucket + 2];
+#if (DEBUG & DEBUG_BATT)
+    if (batt_report_count > 0)
+    {
       Serial.printf(F("actual volts=%f, percent=%d, batt_bucket=%d\n"),
                       MeasuredVoltage, percent, batt_bucket);
-#endif
+      batt_report_count = -ReportVoltageDelay;
     }
-    display_battery();
-  }
-#endif
-
-  // gather any commands from controller
+#endif
+  }
+}
+
+//----------------------------------------
+// Do any commands from the external controller.
+//----------------------------------------
+
+void do_external_commands(void)
+{
+  // gather any commands from the external controller
   while (Serial.available())
   {
     char ch = Serial.read();
@@ -3057,21 +3082,28 @@
       char answer[2048];

       CommandBuffer[CommandIndex] = '\0';
-      Serial.printf(F(">>> %s\n"), do_external_cmd(answer, CommandBuffer, CommandIndex-1));
+      Serial.printf(F("%s >>> %s\n"),
+                    CommandBuffer, do_external_cmd(answer, CommandBuffer, CommandIndex-1));
       CommandIndex = 0;
     }
   }
-
-  // handle all events in the queue
+}
+
+//----------------------------------------
+// Handle events from the rotary encoder.
+//----------------------------------------
+
+void handle_RE_events()
+{
   while (event_pending() > 0)
   {
     // get next event and handle it
     VFOEvent event = event_pop();
-
-#if (DEBUG & DEBUG_EVENT)
-    Serial.printf(F("loop: event=%s\n"), event2display(event));
-#endif
-
+
+  #if (DEBUG & DEBUG_EVENT)
+    Serial.printf(F("handle_RE_events: event=%s\n"), event2display(event));
+  #endif
+
     switch (event)
     {
       case vfo_RLeft:
@@ -3112,22 +3144,36 @@
         // unrecognized event, ignore
         break;
     }
-
-    // update the display
-    display_sel_value(VfoFrequency, VfoSelectDigit, NumFreqChars, NumCols - NumFreqChars - 2, 0);
-#if INC_BATTERY
-    display_battery();
-#endif
-
-    // if online, update DDS-60 and write changes to EEPROM
-#if (DEBUG & DEBUG_FREQ)
+  }
+}
+
+//----------------------------------------
+// Standard Arduino loop() function.
+//----------------------------------------
+
+void loop(void)
+{
+  // do any external commands
+  do_external_commands();
+
+  // handle all events in the queue
+  handle_RE_events();
+
+  // check the battery
+  measure_battery();
+
+  // update the display
+  display_sel_value(VfoFrequency, VfoSelectDigit, NumFreqChars, NumCols - NumFreqChars - 2, 0);
+  display_battery();
+
+  #if (DEBUG & DEBUG_FREQ)
     Serial.printf(F("Main loop: VfoFrequency=%ld\n"), VfoFrequency);
-#endif
-
-    if (VfoMode == vfo_Online)
-    {
-      save_to_eeprom();
-      dds_update(VfoFrequency);
-    }
-  }
-}
+  #endif
+
+  // if online, update DDS-60 and write changes to EEPROM
+  if (VfoMode == vfo_Online)
+  {
+    save_to_eeprom();
+    dds_update(VfoFrequency);
+  }
+}


Feature: using single fastled,  added photosensor to detect dark rooms so the light will be dimme

--- moist-plants.ino
+++ moist-plants.ino
@@ -1,8 +1,16 @@
 // Arduino Hygrometer
-// version: 0.4
+// version: 1.0
 // Author: Mika Hassinen

-#define TIME_INTERVAL 60000	// 60 second interval
+#include <FastLED.h>
+
+// fastled defines
+#define NUM_LEDS 1
+#define DATA_PIN 0
+#define MAX_LED_VALUE 255
+
+// timer and sensor
+#define TIME_INTERVAL 1000	// 1 second interval
 #define FLASH_TIME_INTERVAL 400	// 400 ms flash interval
 #define SENSOR_PIN A1		// input pin for the sensor

@@ -12,15 +20,19 @@
 // 0% humidity (air):	575
 // 100% humidity (water): 285
 #define MIN_LEVEL 300	// 99% humidity
-#define MAX_LEVEL 550	// 1% humidity
+#define MAX_LEVEL 450	// 1% humidity
 #define LOW_LEVEL_THRESHOLD 1	// minimum threshold for the water level (=desert dry soil)

-int ledPins[] = {3, 4, 5, 6, 7, 8, 9, 10, 11};
-int ledArraySize = (sizeof(ledPins)/sizeof(int));
+#define BRIGHTNESS_OFF 0
+#define BRIGHTNESS_MIN 10
+#define BRIGHTNESS_MAX 150
+#define BRIGHTNESS_PIN A2
+#define BRIGHTNESS_THRESHOLD 70

 int sensorValue = 0;  // variable to store the value coming from the sensor

 int ledLevel = 0;
+CRGB smartLed[NUM_LEDS];

 bool blink = false;

@@ -28,28 +40,16 @@

 void setup() {

-	// setup serial for debugging
-	Serial.begin(115200);
-
 	// setup outputs
 	pinMode(SENSOR_PIN, INPUT);

-	// test leds
-	for (int pin = 0; pin < (sizeof(ledPins)/sizeof(int)); pin++ ) {
-		pinMode(ledPins[pin], OUTPUT);
-		delay(150);	// light up each LED in 0.15 second intervals
-		digitalWrite(ledPins[pin], HIGH);
-	}
-	delay(1000);	// show all LEDs on for a second
+	FastLED.addLeds<NEOPIXEL, DATA_PIN>(smartLed, NUM_LEDS);
 	setLedLevel(0);
 	delay(400);	// add a short delay so the transition to real led level is more subtle
-
-	// print led array size
-	Serial.print("[DEBUG]: led count: ");
-	Serial.println(ledArraySize);
-
-	// update LEDs now
-	doUpdate();
+	for (int i = 0; i < MAX_LED_VALUE; i++) {
+		setLedLevel(i);
+		delay(25);
+	}
 }

 void loop() {
@@ -65,11 +65,8 @@
 	if ((unsigned long)(currentTime - flashTimer) >= FLASH_TIME_INTERVAL) {

 		if (ledLevel <= LOW_LEVEL_THRESHOLD) {
-			if (blink)
-				setLedLevel(1);	// turn on first (red) LED
-			else
-				setLedLevel(0); // turn off all LEDs
-
+			if (blink) setLedLevel(0); // turn off all LEDs
+			else setLedLevel(ledLevel);
 			blink = !blink;
 		}

@@ -82,11 +79,10 @@
 void doUpdate() {
 	int newLedLevel;
 	// read the value from the sensor:
-	sensorValue = readSensor();
+	sensorValue = readSensor(SENSOR_PIN, MIN_LEVEL, MAX_LEVEL);

-	// since the sensor values are reversed (bigger value is dry and smaller value is moist)
-	// we should reverse the led values at this point
-	newLedLevel = map(sensorValue, MIN_LEVEL, MAX_LEVEL, ledArraySize, 1);
+	// sensor values are reversed (bigger value is dry and smaller value is moist)
+	newLedLevel = map(sensorValue, MIN_LEVEL, MAX_LEVEL, 255, 1);

 	// update if the value changes
 	if (ledLevel != newLedLevel) {
@@ -94,40 +90,49 @@
 		setLedLevel(ledLevel);
 	}

-	// debug data
-	Serial.print("[DEBUG]: current value, led level: ");
-	Serial.print(sensorValue);
-	Serial.print("\t");
-	Serial.println(ledLevel);
 }

 /**
- * Ligts LEDs according to given level where 0 is all LEDs are OFF and 5 is all LEDs are ON
+ * Ligt the LED according to given level where 0 is LED OFF and 255 green
  * @param Integer level number of leds to light up from 0 to 5
  */
 void setLedLevel(int level) {
-	if (level < 0) level = 0;
-	if (level > (ledArraySize) ) level = ledArraySize;
+	int ledR = 0,
+		ledG = 0,
+		ledB = 0;

-	for (int pin = 0; pin < ledArraySize; pin++ ) {
-		pinMode(ledPins[pin], OUTPUT);
-		if (level >= pin+1)
-			digitalWrite(ledPins[pin], HIGH);
-		else
-			digitalWrite(ledPins[pin], LOW);
+	int brightnessValue = readSensor(BRIGHTNESS_PIN, 0, 200);
+
+	// turn off LED if level is zero
+	if (level == 0) {
+		FastLED.setBrightness(BRIGHTNESS_OFF);
+	} else {
+		if (brightnessValue > BRIGHTNESS_THRESHOLD) FastLED.setBrightness(BRIGHTNESS_MAX);
+		else FastLED.setBrightness(BRIGHTNESS_MIN);
 	}
+
+	// reverse LED level so red is shown when the soil is dry and green when moist
+	level = map(constrain(level, 0, MAX_LED_VALUE), 0, 255, 255, 0);
+
+	// this changes the led color from red to yellow to green
+	ledR = constrain(2 * level, 0, 255);
+	ledG = constrain(2 * (255 - level), 0, 255);
+
+	// set led color and show it to the world
+	smartLed[0].setRGB(ledR, ledG, ledB);
+	FastLED.show();
 }

 /**
  * Read moisture sensor multiple times and return the average
  * @return Integer
  */
-int readSensor() {
+int readSensor(int sensorPin, int min, int max) {

 	int average;
 	float sensorValue, sum;
 	for (int i = 0; i < 50; i++) {
-		sensorValue = analogRead(SENSOR_PIN);
+		sensorValue = analogRead(sensorPin);
 		sum += sensorValue;
 		delay(1);
 	}
@@ -136,8 +141,8 @@
 	average = (int)(sum/50.0);

 	// limit sensor reading between min & max calibration values
-	average = min(average, MAX_LEVEL);	// min: the smaller of two numbers
-	average = max(average, MIN_LEVEL);	// max: the bigger of two numbers
+	average = min(average, max);	// min: the smaller of two numbers
+	average = max(average, min);	// max: the bigger of two numbers

-	return average;
+	return constrain(average, min, max);
 }


+added power_node_v1.1.ino (NOT USING THIS. FOR DOCU PURPOSES)

--- power_node_v1.1/power_node_v1.1/power_node_v1.1.ino
+++ power_node_v1.1/power_node_v1.1/power_node_v1.1.ino
@@ -77,8 +77,8 @@
 String sec;
 char *xbsend[2];
 char xsend[XBLEN];
-char id[16][3]={"A0","A1","A2","A3","A4","A5","A6","A7","A8","A9","AA","AB","AC","AD","AE","AF"};
-//char id[16][3]={"B0","B1","B2","B3","B4","B5","B6","B7","B8","B9","BA","BB","BC","BD","BE","BF"};
+//char id[16][3]={"A0","A1","A2","A3","A4","A5","A6","A7","A8","A9","AA","AB","AC","AD","AE","AF"};
+char id[16][3]={"B0","B1","B2","B3","B4","B5","B6","B7","B8","B9","BA","BB","BC","BD","BE","BF"};
 char end_id[]="^";
 char *dummy;

@@ -99,6 +99,8 @@

 int xbFlag=0;
 char dataXB[160];
+
+
 /*********************/

 // SH + SL Address of receiving XBee
@@ -376,6 +378,7 @@
     delay(500);

     //data="xbee-power module code";
+    strcat(dataXB,"^");
     data=(char *) malloc(160);
     sprintf(data,dataXB,sizeof(dataXB));
     //dataXB.toCharArray(data,sizeof(dataXB));
@@ -569,8 +572,7 @@
   timestamp= ReadTimeDate(&lastSec, &lastMin, &lastHr);
   customDue.write(command);
   customDue.write("/");
-  //customDue.println(timestamp);
-  customDue.println("2020-12-31 23:55:00");
+  customDue.println(timestamp);

   Serial.print(command);
   Serial.print(F("/"));
@@ -666,6 +668,13 @@

       else {
         Serial.println(F("done"));
+        //dataXB="";
+        for (unsigned char m=0;m<160;m++){
+          dataXB[m]=0;
+        }
+        //sprintf(dataXB,"",sizeof(""));
+        digitalWrite(trigForDue, LOW);
+        return;
       }
     }
   }
@@ -685,6 +694,8 @@
   t.stop(x);
   globalChecker = 1;
   breaker = 1;
-}
-
-
+
+  return;
+}
+
+


nothing important.

nothing important.

--- duinoCar/duinoCar.ino
+++ duinoCar/duinoCar.ino
@@ -2,6 +2,7 @@
 #include <SD.h>
 #include <TinyGPS.h>
 #include <TN901.h>
+#include <U8glib.h>
 #include "config.h"

@@ -9,13 +10,14 @@
   Serial.begin(9600);   // Debug port
   Serial2.begin(9600);  // APC 220 port
   Serial3.begin(4800);  // read GPS port
-
-  pinMode(led,OUTPUT);

   if(!SD.begin(sdCS)){
     Serial.println("Card failed, or not present");
+  }else{
+    Serial.println("Card initialized.");
   }
-  Serial.println("Card initialized.");
+
+  pinMode(led,OUTPUT);

   pinMode(throttle,OUTPUT);
   pinMode(switchPin,OUTPUT);
@@ -27,15 +29,13 @@
   pinMode(trigPin, OUTPUT);                           // Trigger pin set to output
   pinMode(echoPin, INPUT);                            // Echo pin set to input
   pinMode(onBoardLED, OUTPUT);                        // Onboard LED pin set to output
-  start();
+  start();                                            // Initialize the testPlatform

   Timer1.initialize(TIMER_US);                        // Initialise timer 1
   Timer1.attachInterrupt( timerIsr );                 // Attach interrupt to the timer service routine
   attachInterrupt(echo_int, echo_interrupt, CHANGE);  // Attach interrupt to the sensor echo input
   tn901Setup();
 }
-
-

 void loop(){


Fixed baud rate for Firmata!

Fixed baud rate for Firmata!

--- Sensorizer.ino
+++ Sensorizer.ino
@@ -178,8 +178,9 @@

   ble_setup();

-  // this is needed for debug printing on native USB port
-  SerialUSB.begin(57600);
+  // this is needed for debug printing on native USB port,
+  // as well as Firmata and MIDIRepeater
+  SerialUSB.begin(BAUD_RATE_USB);

   #if ENABLE_FIRMATA
   Firmata.setFirmwareVersion(0, 1);


DnsWebClient implemented  removed SPI  added dhcp ip address and url printouts

--- libraries/Ethernet/examples/DnsWebClient/DnsWebClient.ino
+++ libraries/Ethernet/examples/DnsWebClient/DnsWebClient.ino
@@ -1,25 +1,23 @@
 /*
   DNS and DHCP-based Web client

- This sketch connects to a website (http://www.google.com)
- using an Arduino Wiznet Ethernet shield.
-
- Circuit:
- * Ethernet shield attached to pins 10, 11, 12, 13
+ This sketch connects to www.google.com

  created 18 Dec 2009
  by David A. Mellis
  modified 12 April 2011
  by Tom Igoe, based on work by Adrian McEwen
+
+ modified 20 Feb 2014
+ by Craig Hollabaugh
+

- */
+*/

-#include <SPI.h>
 #include <Ethernet.h>

 // Enter a MAC address for your controller below.
-// Newer Ethernet shields have a MAC address printed on a sticker on the shield
-byte mac[] = {  0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
+byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
 char serverName[] = "www.google.com";

 // Initialize the Ethernet client library
@@ -30,15 +28,25 @@
 void setup() {
   // start the serial library:
   Serial.begin(9600);
+  Serial.println("\n\nDnsWebClient setup");
   // start the Ethernet connection:
   if (Ethernet.begin(mac) == 0) {
     Serial.println("Failed to configure Ethernet using DHCP");
     // no point in carrying on, so do nothing forevermore:
     while(true);
   }
-  // give the Ethernet shield a second to initialize:
-  delay(1000);
-  Serial.println("connecting...");
+  // print your local IP address:
+  Serial.print("My IP address: ");
+  for (byte thisByte = 0; thisByte < 4; thisByte++) {
+    // print the value of each byte of the IP address:
+    Serial.print(Ethernet.localIP()[thisByte], DEC);
+    Serial.print(".");
+  }
+  Serial.println();
+
+  Serial.print("connecting to http://");
+  Serial.println(serverName);
+

   // if you get a connection, report back via serial:


Hmmm, it seemed that arduino files don't get saved when compiled... Had to rewrite :)

--- WhaleMeter.ino
+++ WhaleMeter.ino
@@ -8,13 +8,12 @@

   This example code is in the public domain.
  */
-
-// Pin 3 has an green LED connected on the RGB LED shield
-// give it a name:
-int UV_EN = 3;
-int UV_VAL = 2;
-int L_SCL = 6;
-int L_SDA = 5;
+int LED = 1;
+int BATT = 6;
+int UV_EN = 5;
+int UV_VAL = 4;
+int L_SCL = 2;
+int L_SDA = 3;
 int TSL2561_ADDRESS = 0b0111001;
 int TSL2561_CMD = 0x80;
 int TSL_2561_BLOCK = 0x10;
@@ -31,19 +30,23 @@

 // the setup routine runs once when you press reset:
 void setup() {
-  Serial.begin(9600);
-  delay(1000);
   writeUv(0);
-  writeBatt(100);
+  writeBatt(0);
   writeIr(0);
   writeVis(0);
   advertisementData[9] = 0;

+  pinMode(UV_VAL, INPUT);
+  pinMode(BATT, INPUT);
+
+  pinMode(LED, OUTPUT);
+  digitalWrite(LED, LOW); // led off
   pinMode(UV_EN, OUTPUT);
   digitalWrite(UV_EN, HIGH); // enable the UV meter
   Serial.println("start");
   setup_TSL2561();
   Serial.println("setup done");
+  RFduinoBLE.advertisementInterval = 160;

   RFduinoBLE.deviceName="Whale";
 }
@@ -54,7 +57,7 @@
   Wire.beginOnPins(L_SCL, L_SDA);
   Wire.beginTransmission(TSL2561_ADDRESS);
   if (!(writeByte(TSL_REG_CONTROL, 0b11) && // powerup
-        writeByte(TSL_REG_TIMING, 0b10) && // 402ms integration time. no gain
+        writeByte(TSL_REG_TIMING, 0b10 /* 402ms interval */ | 0x10 /* 16x gain */) &&
         writeByte(TSL_REG_INTERRUPT, 0))) { // no interrupts
         Serial.println("error in setup");
         Serial.println(getError());
@@ -64,24 +67,22 @@
 // the loop routine runs over and over again forever:
 void loop() {
   word uv,vis, ir;
-  uv = analogRead(2);
+  uv = analogRead(UV_VAL);
+  batt = analogRead(BATT);
+  readData(vis, ir);
   writeUv(uv);
-  readData(vis, ir);
-  Serial.println(uv);
-  Serial.println(batt);
-  Serial.println(vis);
-  Serial.println(ir);
-
+  writeBatt(batt);
   writeVis(vis);
   writeIr(ir);
-  batt++;
-  writeBatt(batt);
+
   RFduinoBLE.advertisementData = advertisementData;
   RFduinoBLE.begin();
-  Serial.println("hi");
-
-  delay(1000);
+  RFduino_ULPDelay(990);
   RFduinoBLE.end();
+
+  digitalWrite(LED, HIGH);
+  RFduino_ULPDelay(10);
+  digitalWrite(LED, LOW);
 }

 void writeUv(word val) {


erase testing code

erase testing code

--- spi_flash.ino
+++ spi_flash.ino
@@ -3,7 +3,7 @@

 S25FL208K *spiFlash;

-uint32_t testAddr = 0x000008;
+uint32_t testAddr = 0x000000;

 void setup(){
   Serial.begin(115200);
@@ -12,14 +12,23 @@
   spiFlash = new S25FL208K(4);
   Serial.println("Setup complete.");

-  String test = "Hello world";
+  spiFlash->chipErase();
+
+  unsigned long timeWrite = millis();
+  while(spiFlash->getWIP()){
+
+  }
+  Serial.print("\nTime taken to erase:");
+  Serial.println(millis() - timeWrite);
+
+  String test = "1234";//"Hello world";

   uint8_t* dataToStore = new uint8_t[test.length()];
   for(int i = 0; i<test.length(); i++){
     dataToStore[i] = uint8_t(test[i]);
   }

-  unsigned long timeWrite = millis();
+  timeWrite = millis();
   spiFlash->storeData(testAddr, test.length(), dataToStore);

   while(spiFlash->getWIP()){
@@ -30,9 +39,12 @@
   Serial.println(millis() - timeWrite);

   uint8_t* dataToRead = new uint8_t[20];
-  spiFlash->readData(0, 20, dataToRead);
+  spiFlash->readData(testAddr, 20, dataToRead);
   for(int i = 0; i<20; i++){
-    Serial.print((char)dataToRead[i]);
+    Serial.println((char)dataToRead[i]);
+  }
+  for(int i = 0; i<20; i++){
+    Serial.println(dataToRead[i],BIN);//((char)dataToRead[i]);
   }
 }


arduino-apds-9960.ino: Error if there is no sensor

Show error message on the mini OLED I2C display if no APDS-9960
sensor modules has been detected.

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

--- sensors/APDS-9960/arduino-apds-9960/arduino-apds-9960.ino
+++ sensors/APDS-9960/arduino-apds-9960/arduino-apds-9960.ino
@@ -75,9 +75,11 @@
   if(!apds.begin())
   {
     Serial.println("ERROR: Failed to initialize gesture sensor! Please check your wiring.");
+    drawDisplay("APDS-9960", "ERROR", "NO SENSOR");
   }
   else {
     Serial.println("Gesture sensor initialized.");
+    drawDisplay("APDS-9960", "Initialized", "");
     gestureSensorDetected = true;
     //gesture mode will be entered once proximity mode senses something close
     apds.enableProximity(true);


Minor fix Change_Baud_Rate Example

Minor fix Change_Baud_Rate Example

- Less Decimal places

--- examples/Change_Baud_Rate/Change_Baud_Rate.ino
+++ examples/Change_Baud_Rate/Change_Baud_Rate.ino
@@ -33,7 +33,7 @@
   double bar = line.getTime();

   Serial.print("The Line to Sample Frequency Ratio is: ");
-  Serial.println( foo , 10 ); //10 is the number of decimal places
+  Serial.println( foo , 5 ); //5 is the number of decimal places

   Serial.print("The System Time is: ");
   Serial.println( bar );


Só um pouco a mais de  formalidade

Só um pouco a mais de  formalidade

Ter uma variável `esquema` não é uma boa ideia.

--- ATmega/ATmega.ino
+++ ATmega/ATmega.ino
@@ -1,5 +1,3 @@
-//NOTA: TROCAR O SERIAL CASO FOR TESTAR
-//substituir o "esquema"
 #include "EmonLib.h"
 #include <LiquidCrystal.h>
 #include <SoftwareSerial.h>
@@ -12,7 +10,7 @@
 unsigned long previousMillis  = 0;      // will store last time LED was updated
 unsigned long previousMillis1 = 0;
 const long    interval        = 200;    // interval at which to blink (milliseconds)
-String        esquema;
+String        stringSerial;
 boolean       ocupado         = true;

 const int     pino_sct        = 0;
@@ -59,7 +57,7 @@
   if (newData == true) {
     //esp8266.print("This just in ... ");
     //esp8266.println(receivedChars);
-    esquema = receivedChars;
+    stringSerial = receivedChars;
     newData = false;
   }
 }
@@ -95,20 +93,20 @@

   recvWithEndMarker();
   showNewData();
-  if (esquema.indexOf("T:") != -1) {
-    t = esquema.substring(esquema.indexOf("T:") + 2, esquema.indexOf('\r'));
+  if (stringSerial.indexOf("T:") != -1) {
+    t = stringSerial.substring(stringSerial.indexOf("T:") + 2, stringSerial.indexOf('\r'));
     esp8266.print("Tensão ajustada para ");
     esp8266.println(t);
     tensao = t.toInt();
   }
-  if (esquema.indexOf("CALIBRA:") != -1) {
-    cal = esquema.substring(esquema.indexOf("CALIBRA:") + 8, esquema.indexOf('\r'));
+  if (stringSerial.indexOf("CALIBRA:") != -1) {
+    cal = stringSerial.substring(stringSerial.indexOf("CALIBRA:") + 8, stringSerial.indexOf('\r'));
     esp8266.print("Nível de calibração ajustado para: ");
     esp8266.println(calibra);
     calibra = cal.toInt();
   }

-  if (esquema.indexOf("EASTEREGG") != -1) {
+  if (stringSerial.indexOf("EASTEREGG") != -1) {
     EASTEREGG();
   }

@@ -119,8 +117,8 @@
     delay(150);
     recvWithEndMarker();
     showNewData();
-    if (esquema.indexOf("IP:") != -1) {
-      ip = esquema.substring(esquema.indexOf("IP:") + 3, esquema.indexOf('\r'));
+    if (stringSerial.indexOf("IP:") != -1) {
+      ip = stringSerial.substring(stringSerial.indexOf("IP:") + 3, stringSerial.indexOf('\r'));
       ocupado = true;
       lcd.clear(); //Apaga a tela assim que achar o IP.
     }
@@ -147,7 +145,7 @@
   }
   //ip = "(desconectado)";
   ocupado = false;
-  esquema = "";
+  stringSerial = "";

   if (currentMillis - previousMillis >= interval) {
     // save the last time you blinked the LED


Minor formatting

Minor formatting

--- examples/pwm-teensy/pwm-teensy.ino
+++ examples/pwm-teensy/pwm-teensy.ino
@@ -4,11 +4,12 @@
 // FTM1 pins: 3, 4
 // FTM2 pins: 25, 32

-#define PWM_PIN 3
+#define PWM_PIN 10
+#define DIR_PIN 12

 int incomingByte = 0; // for incoming serial data

-unsigned int frequency = 488;
+unsigned int frequency = 488; // 488.28 Hz is the default PWM frequency
 unsigned int dutyCycle = 127;

 void setup()
@@ -26,7 +27,7 @@

     if (incomingByte == 104 || incomingByte == 108) // h or l: higher or lower frequency
     {
-      frequency = incomingByte == 104 ? frequency + 1 : frequency -1;
+      frequency = incomingByte == 104 ? frequency + 1 : frequency - 1;

       // Note: all other pins in the timer group are also changed!
       analogWriteFrequency(PWM_PIN, frequency);
@@ -35,7 +36,7 @@
     }
     if (incomingByte == 102 || incomingByte == 115) // f or s: faster or slower
     {
-      dutyCycle = incomingByte == 102 ? dutyCycle + 1 : dutyCycle -1;
+      dutyCycle = incomingByte == 102 ? dutyCycle + 1 : dutyCycle - 1;
       analogWrite(PWM_PIN, dutyCycle);
       Serial.print("dc: ");
       Serial.println(dutyCycle);


fixed merge conflicts

fixed merge conflicts

--- project.ino
+++ project.ino
@@ -21,8 +21,6 @@

 //Hardware constants
 #define PIN_STRIP 5
-//#define PIN_SENSOR 7
-//#define PIN_SERVO 8

 #define NUMBER_LEDS 48
 #define NUMBER_STRIPS 3
@@ -30,18 +28,9 @@
 #define PIN_SWITCH 2

 Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMBER_LEDS, PIN_STRIP, NEO_GRB + NEO_KHZ800);
-//Servo servo;
-
-//Servo variables
-//int servoPos = 0;
-//int servoSteps = 6;
-//int servoMinAngle = 0;
-//int servoMaxAngle = 90;
-//int servoStepAngle = (servoMaxAngle-servoMinAngle)/(servoSteps-1);
-//int servoMSPerDegree = 5;
+

 //Store of the measured distances of each servo step
-//int distanceValues[6];
   int distanceValues[3];
   int distanceValuesFade[3];

@@ -53,9 +42,8 @@
     distanceValuesFade[i] = maxDistance;
   }

-  pinMode(PIN_SWITCH, INPUT_PULLUP);           // set pin to input with internal pullup resistor
-
-  //
+  pinMode(PIN_SWITCH, INPUT_PULLUP); // set pin to input with internal pullup resistor
+
   pingTimer1 = millis() + pingSpeed; // Sensor 1 fires after 100ms (pingSpeed)
   pingTimer2 = pingTimer1 + (pingSpeed / 2); // Sensor 2 fires 50ms later
   pingTimer3 = pingTimer2 + (pingSpeed / 2); // Sensor 3 fires 50ms later
@@ -67,39 +55,20 @@
   strip.begin();
   strip.setBrightness(64);
   strip.show();
-
-  //Set servo to init position
-  //And wait for the servo reaching the position
-//  servo.attach(PIN_SERVO);
-//  servo.write(servoPos);
-//  delay(5*360);
 }
-
 /**
  *
  *  MAIN
  *  Move servo, read sensor and write leds
  *
  */
-void loop(){
-//  int i = 0;
-//  for(servoPos = servoMinAngle; servoPos < servoMaxAngle; servoPos += servoStepAngle){
-//    readSensorWriteLEDs(servoPos, i);
-//    i+=1;
-//  }
-//
-//  for(servoPos = servoMaxAngle; servoPos>servoMinAngle; servoPos-=servoStepAngle)
-//  {
-//    readSensorWriteLEDs(servoPos, i);
-//    i-=1;
-//  }
-   if (millis() >= pingTimer1) {
+void loop(){
+ if (millis() >= pingTimer1) {
    pingTimer1 += pingSpeed; // Make sensor 1 fire again 100ms later (pingSpeed)
    distanceValues[0] = sonar1.ping_cm();
    Serial.print("Ping 1: ");
    Serial.print(distanceValues[0]); // Convert ping time to distance and print result (0 = outside set distance range, no ping echo)
-   Serial.println("cm");
-
+   Serial.println("cm");
  }
  if (millis() >= pingTimer2) {
    pingTimer2 = pingTimer1 + (pingSpeed / 2); // Make sensor 2 fire again 50ms after sensor 1 fires
@@ -149,24 +118,6 @@
   }
 }

-//void readSensorWriteLEDs(int servoPosition, int i){
-//  servo.write(servoPosition);
-//  delay(servoMSPerDegree*servoStepAngle);
-//
-//  triggerSensor();
-//  int distance = readSensor();
-//  printDistance(distance);
-//
-//  distance = max(minDistance, distance);
-//  distance = min(maxDistance, distance);
-//  distanceValues[i] = distance;
-//
-//  visualizeWithDirection();
-//
-//  delay(35);
-//}
-
-
 /**
  * VISUALIZATION TYPE 2
  *
@@ -287,40 +238,7 @@
   strip.show();
 }

-/**
- *
- * DISTANCE SENSOR
- *
- **/
-
-//long readSensor(){
-//  // The same pin is used to read the signal from the PING))): a HIGH
-//  // pulse whose duration is the time (in microseconds) from the sending
-//  // of the ping to the reception of its echo off of an object.
-//  pinMode(PIN_SENSOR, INPUT);
-//  long duration = pulseIn(PIN_SENSOR, HIGH);
-//
-//  // convert the time into a distance
-//  return microsecondsToCentimeters(duration);
-//}
-
-//void triggerSensor(){
-//  // The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
-//  // Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
-//  pinMode(PIN_SENSOR, OUTPUT);
-//  digitalWrite(PIN_SENSOR, LOW);
-//  delayMicroseconds(2);
-//  digitalWrite(PIN_SENSOR, HIGH);
-//  delayMicroseconds(5);
-//  digitalWrite(PIN_SENSOR, LOW);
-//}
-
-/**
- *
- * HELPER FUNCTIONS
- *
- **/
-
+
 //void printDistance(int distance){
 //  Serial.print(distance);
 //  Serial.print(" cm");


Add debugging to high_temp/low_temp updating

I sense this still isn't working right, so I want to keep
an eye on it...

--- lcd_temperature_display.ino
+++ lcd_temperature_display.ino
@@ -243,12 +243,38 @@
     // Check for records
     if (current_temp > high_temp.temperature)
     {
+      #ifdef DEBUG
+        Serial.print("loop: updating high_temp.");
+        Serial.print(" high_temp.temperature=");
+        Serial.print(high_temp.temperature);
+        Serial.print(" high_temp.time=");
+        Serial.print(high_temp.time);
+        Serial.print(" current_temp=");
+        Serial.print(current_temp);
+        Serial.print(" millis=");
+        Serial.print(millis());
+        Serial.println("");
+      #endif
+
       high_temp.temperature = current_temp;
       high_temp.time = millis();
     }

     if (current_temp < low_temp.temperature)
     {
+      #ifdef DEBUG
+        Serial.print("loop: updating low_temp.");
+        Serial.print(" low_temp.temperature=");
+        Serial.print(low_temp.temperature);
+        Serial.print(" low_temp.time=");
+        Serial.print(low_temp.time);
+        Serial.print(" current_temp=");
+        Serial.print(current_temp);
+        Serial.print(" millis=");
+        Serial.print(millis());
+        Serial.println("");
+      #endif
+
       low_temp.temperature = current_temp;
       low_temp.time = millis();
     }


minor improvement to sef driving sketch

minor improvement to sef driving sketch

--- testing/arduino/self-driving-v8.ino
+++ testing/arduino/self-driving-v8.ino
@@ -4,7 +4,7 @@
 #include "NewPing.h"

 // Base Date
-const uint16_t initialDelay = 2500;
+const uint16_t initialDelay = 1500;

 // Ranges and Data
 const uint8_t rangeLimit_Warning1 = 70;
@@ -54,7 +54,7 @@
 const uint8_t servoLimitRight = 10;
 const uint8_t servoTiltRight = 50;
 const uint8_t servoCenter = 90;
-const uint8_t seroRotationDurationPerAngle = 2;
+const uint8_t seroRotationDurationPerAngle = 4;

 enum direction {
   LEFT,
@@ -63,16 +63,17 @@
 };
 direction servoRangeDirection = NONE;
 uint32_t servoLastScanTimestamp = 0;
+bool servoMoveCenterDenied = true;

 direction servoLastScan = NONE;

 // IR obstacle detection
 int obstaclePin = A7;
+int obstaclePin2 = A6;

 void setup()
 {
-    Serial.begin(115200);
     // Scanner
     pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
     pinMode(echoPin, INPUT); // Sets the echoPin as an Input
@@ -94,6 +95,7 @@

     // IR Detector
     pinMode(obstaclePin, INPUT);
+    pinMode(obstaclePin2, INPUT);

     LEDStrip.begin();
     LEDStrip.show(); // Initialize all pixels to 'off'
@@ -103,50 +105,39 @@
     ServoMotor.write(servoCenter);
 }

-void GetRange(int servoPos, bool rotating)
+void GetRange(int servoPos, bool rotateRobot)
 {
     long range = sonar.ping_cm();

     // fallback if return value is out of range
-    if(range == 0 && rotating) { range = maxDistance; }
+    if(range == 0 && rotateRobot) { range = maxDistance; }
     if(range > maxDistance) { range = maxDistance; }

-
-    //if(range == 0) { range = lastRange; }
-    //if(range > 0  && !rotating) { lastRange = range;}
-
     long avgRange;
-
-    if(servoPos == servoCenter)
+    if(servoPos == servoCenter)
     {
         if(range == 0) { range = lastRangeCenter; }
-        avgRange = (range + lastRangeCenter) / 2;
+        avgRange = (range * 2 + lastRangeCenter) / 3;
         lastRangeCenter = range;

-        rangeCenter = avgRange;
-    }
-    if(servoPos > servoCenter)
-    {
+        rangeCenter = avgRange;
+    }
+    if(servoPos > servoCenter)
+    {
         if(range == 0) { range = lastRangeLeft; }
-        avgRange = (range + lastRangeLeft) / 2;
+        avgRange = (range * 2 + lastRangeLeft) / 3;
         lastRangeLeft = range;

-        rangeLeft = avgRange;
-    }
-    if(servoPos < servoCenter)
-    {
+        rangeLeft = avgRange;
+    }
+    if(servoPos < servoCenter)
+    {
         if(range == 0) { range = lastRangeRight; }
-        avgRange = (range + lastRangeRight) / 2;
+        avgRange = (range * 2 + lastRangeRight) / 3;
         lastRangeRight = range;
-
-        rangeRight = avgRange;
-    }
-
-    Serial.print(range);
-    Serial.print(" - ");
-    Serial.print(avgRange);
-    Serial.print(" - ");
-    Serial.println(servoPos);
+
+        rangeRight = avgRange;
+    }
 }

 bool GetObstacle()
@@ -154,6 +145,11 @@
     if(analogRead(obstaclePin) < 500)
     {
         return true;
+    }
+    if(analogRead(obstaclePin2) < 500)
+    {
+        // TODO
+        // return true;
     }
     return false;
 }
@@ -237,20 +233,17 @@
     ColorSet(LEDStrip.Color(0, 0, 255));
 }

-
 void SetServo(uint32_t uptime, uint8_t servoPos)
 {
     uint32_t interval = 1000;
     uint32_t returnInterval = 300;
-
-    if(uptime < interval+1)
-    {
-        return;
-    }
-
-    if(servoLastScanTimestamp < uptime - interval)
+
+    if(uptime < returnInterval) { return; }
+
+    if(servoLastScanTimestamp + interval < uptime)
     {
         servoLastScanTimestamp = uptime;
+        servoMoveCenterDenied = false;

         if(servoLastScan == RIGHT)
         {
@@ -268,10 +261,12 @@
         return;
     }

-    if(servoLastScanTimestamp < uptime - returnInterval)
+    if(!servoMoveCenterDenied && servoLastScanTimestamp + returnInterval < uptime)
     {
         SetServoAngle(servoCenter);
         delay(seroRotationDurationPerAngle * (abs(servoCenter - servoPos)));
+        servoMoveCenterDenied = true;
+
     }
 }


Update mpxv6115v.ino

Update mpxv6115v.ino

--- example/mpxv6115v.ino
+++ example/mpxv6115v.ino
@@ -21,6 +21,7 @@
 int tolerance=25;
 float temp_voltage,degreeC,degreeF;				//Isı değişkenlerinin tanımlanması
 const unsigned long delaytime=250;
+int temp_temp;

@@ -34,8 +35,12 @@
 		  Serial.println("hazir");
 		  Serial.println("\n")			        //  attachInterrupt(digitalPinToInterrupt(up),upset,CHANGE)

+
+		 lc.shutdown(0,false);
+		 lc.setIntensity(0,8);
+      		 lc.clearDisplay(0);
 }
-
+//**************************************************MAIN LOOP****************************************************************
 void loop()
 {

@@ -43,19 +48,19 @@
 		test();
 		set();
 		monitor();
-		temp_measure();
+		//temp_measure();
 }

 void measure()
 {
-
+	temp_temp=temp_measure();

 }
 void test()
 {
-
+
 }

 void set()
@@ -65,14 +70,13 @@
 		driver.motorAForward();
 		vakum=analogRead(A0);
 	}
-
 }

 void monitor()
 {

 }
-unsigned int temp_measure()
+int temp_measure()
 {
 	temp_voltage = analogRead(temperatureAnalogInputPin) * 0.004882814;
 	degreesC = (voltage - 0.5) * 100.0;


Autoconnect to Bluetooth
Set IMU refresh rate to 10Hz

Signed-off-by: Cruz Monrreal II <663375bc5b4c6ed13a95cc63b2dd9f1e16363f4e@gmail.com>

--- examples/SpheroTankControl/SpheroTankControl.ino
+++ examples/SpheroTankControl/SpheroTankControl.ino
@@ -1,15 +1,17 @@
 /************************************************
  Written by Cruz Monrreal II
  Created on 08-19-2012
- Modified on 10-20-2012
+ Modified on 11-11-2012

  Updates can be found here:
   https://github.com/cmonr/Arduino-Sphero-Library
 ************************************************/

+#include <Bluetooth.h>
 #include <Sphero.h>
 #include <SabertoothSimplified.h>

+Bluetooth bluetooth;
 Sphero sphero;
 SabertoothSimplified ST;

@@ -17,6 +19,13 @@
   Serial.begin(9600);
   ST.drive(0);
   ST.turn(0);
+
+  delay(3000);
+
+  // Connect to Sphero
+  bluetooth.beginCMD();
+  bluetooth.connect();
+  bluetooth.endCMD();

   // Indicator LED
   sphero.setBackLED(0xFF);
@@ -27,7 +36,7 @@
   // Init Heading to 0
   sphero.setHeading(0x00);

-  // Get Pitch @ 5Hz
+  // Get Pitch @ 10Hz
   sphero.setStreamingData(10, 1, SPHERO_IMU_PITCH | SPHERO_IMU_YAW);
 }

@@ -51,4 +60,4 @@
     ST.drive(0);
     ST.turn(0);
   }
-}
+}


fix for ENABLE pin

fix for ENABLE pin

--- examples/TMC26XMotorTester/TMC26XMotorTester.ino
+++ examples/TMC26XMotorTester/TMC26XMotorTester.ino
@@ -26,10 +26,13 @@
 #include <TMC26XStepper.h>

 //you may adapt this to your shield or breakout board connection
-#define CS_PIN 2
-#define DIR_PIN 6
-#define STEP_PIN 7
-#define ENABLE_PIN 8 //if it is not connected it won't be a problem
+#define CS_PIN 10
+#define DIR_PIN 7
+#define STEP_PIN 4
+//if it is not connected it won't be a problem
+// Comment the line if you do not have an enable pin assigned, or the
+// enable pin collides with any of your boards CS pins
+#define ENABLE_PIN 8

 #define TIMER_CLOCK_FREQ 2000000.0 //2MHz for /8 prescale from 16MHz
@@ -43,9 +46,11 @@

 void setup() {
   //configure the enable pin
+  #ifdef ENABLE_PIN
   pinMode(ENABLE_PIN, OUTPUT);
   digitalWrite(ENABLE_PIN,HIGH);
-
+  #endif
+  // SPI.setClockDivider(SPI_CLOCK_DIV128);
   startSerial();
   startMotor();
   //set this according to you stepper


Update rfid_default_keys.ino (#268)

Update rfid_default_keys.ino (#268)

try to change the order of the known keys and meet the bug described at http://arduino.stackexchange.com/a/14316

--- examples/rfid_default_keys/rfid_default_keys.ino
+++ examples/rfid_default_keys/rfid_default_keys.ino
@@ -82,6 +82,11 @@
     byte block = 0;
     MFRC522::StatusCode status;

+    // http://arduino.stackexchange.com/a/14316
+    if ( ! mfrc522.PICC_IsNewCardPresent())
+        return false;
+    if ( ! mfrc522.PICC_ReadCardSerial())
+        return false;
     // Serial.println(F("Authenticating using key A..."));
     status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, block, key, &(mfrc522.uid));
     if (status != MFRC522::STATUS_OK) {


Battery indicator led

Battery indicator led

--- magbot_test/magbot_test.ino
+++ magbot_test/magbot_test.ino
@@ -2,6 +2,17 @@
  HC-SR04 Ultrasonic Range Finder.
  Two motors attached to the motor shield.
  speaker/piezo for sound
+
+ Arduino Uno has three timers; timer 0, timer 1, timer 2,
+ Timer 0 is used by the arduino for millis().
+ The motorsheild uses timer 2, for pwm on pins 3 & 11.
+ Since the standard arduino tone function uses timer 2 also,
+ we have to use a different library "NewTone" this uses timer 1 instead
+ which means no pwm on pins 10 & 9. it also means it is incompatable with the
+ standard servo library.
+ So we have pwm left on pins 5 & 6 to put some leds on.
+
+
  */

 #include <util/delay.h>
@@ -35,6 +46,9 @@
 int melody[] = { 262, 196, 196, 220, 196, 0, 247, 262 };
 int noteDurations[] = { 4, 8, 8, 4, 4, 4, 4, 4 };

+// Led configuration
+const byte led_battery = 5;
+
 unsigned long millis_now;

 void setup() {
@@ -54,6 +68,8 @@
   digitalWrite(motorB_brake, LOW);   // Disengage the Brake for Channel B

+  batteryLevel();
+
   // Turn in place constantly.
   digitalWrite(motorA_direction, HIGH); // Channel A forward
   digitalWrite(motorB_direction, LOW); // Channel B backward
@@ -72,9 +88,9 @@
     sonar_last = millis_now;

     unsigned int cm = sonar.ping_cm(); // Send a ping, get ping time in microseconds (uS).
-    Serial.print("Ping: ");
-    Serial.print(cm);
-    Serial.println("cm");
+    //Serial.print("Ping: ");
+    //Serial.print(cm);
+    //Serial.println("cm");
   }

   // Check to see if it's time for another melody.
@@ -83,15 +99,13 @@
     melody_last = millis_now;
     playMelody();

-    // Check battery level
-    long vcc = readVcc();
-    Serial.print("Battery: ");
-    Serial.println(vcc);
+    batteryLevel();
   }

 }

-void playMelody() {
+void playMelody()
+{
   // iterate over the notes of the melody:
   for (int thisNote = 0; thisNote < 8; thisNote++) {

@@ -108,6 +122,18 @@
     // stop the tone playing:
     noNewTone(tone_pin);
   }
+}
+
+void batteryLevel()
+{
+  // Check battery level
+  long vcc = readVcc();
+  byte batt = map(vcc, 2500, 5500, 0, 255);
+  analogWrite(led_battery, batt);
+  Serial.print("Battery: ");
+  Serial.print(vcc);
+  Serial.print(" : ");
+  Serial.println(batt);
 }

 /**


* setting can-filters (we do not receive can messages othewise) * adjusted can-frames to required values * removed memset for initialisation (causes unproper initialisation?)

--- uartpilot_proxy/uartpilot_proxy.ino
+++ uartpilot_proxy/uartpilot_proxy.ino
@@ -21,13 +21,12 @@
 inline void patchFrame(CAN_FRAME *frame) {
   switch (frame->id) {
     case 0x282:
-      frame->data.bytes[1] = p_cod->steerangle != 0 ? 0xC0 : 0;
+      if (p_cod->speed != 0 || p_cod->steerangle != 0) frame->data.bytes[1] = 0xC0;
+      else frame->data.bytes[1] = 0x00;
       break;
     case 0x382:
+      frame->data.bytes[0] = p_cod->speed;
       frame->data.bytes[3] = p_cod->steerangle;
-      break;
-    case 0x384:
-      frame->data.bytes[3] = p_cod->speed;
       break;
   }
 }
@@ -36,12 +35,21 @@
  * Standard arduino setup(), initialize things
  */
 void setup() {
+  Serial.begin(115200);
   Serial1.begin(115200);
   Can0.begin(CAN_BPS_250K);
   Can1.begin(CAN_BPS_250K);

+  for (int filter = 0; filter < 7; filter++) {
+    Can0.setRXFilter(filter, 0, 0, false);
+    Can1.setRXFilter(filter, 0, 0, false);
+  }
+
   p_cod = (UARTPilot::Msg_COD_t*) malloc(sizeof(p_cod));
-  memset(p_cod, 0, sizeof(p_cod));
+  p_cod->speed = 0;
+  p_cod->steerangle = 0;
+
+  Serial.print("uartpilot_proxy Initialized!");
 }

 /**


including pressure sensor

including pressure sensor

--- ctd/ctd.ino
+++ ctd/ctd.ino
@@ -1,5 +1,7 @@
 #include <SPI.h>
 #include <SD.h>
+#include <Wire.h>                  // BMP085
+#include <Adafruit_BMP085.h>       // BMP085
 // Base name must be six characters or less for short file names.
 #define FILE_BASE_NAME "Data"

@@ -8,10 +10,12 @@
 const int gLed =  11;      //
 const int rLed = 8;        //
 const int LM35 = A0;       // Temperature sensor
+Adafruit_BMP085 bmp;

 File dataFile;
 unsigned long int ttime;
 float temp;
+float time;

 const uint8_t BASE_NAME_SIZE = sizeof(FILE_BASE_NAME) - 1;
 char fileName[] = FILE_BASE_NAME "00.csv";
@@ -22,7 +26,7 @@
   pinMode(CS_PIN, OUTPUT);
   Serial.begin(9600);

-  if (!SD.begin(CS_PIN)) {
+  if (!SD.begin(CS_PIN) and !bmp.begin()) {
     Serial.println(F("begin failed"));
     digitalWrite(rLed, HIGH);
     delay(2000);
@@ -64,7 +68,7 @@
       return;
     }
   }
-  dataFfile = SD.open(fileName, FILE_WRITE);
+  dataFile = SD.open(fileName, FILE_WRITE);
   if (!dataFile) {
     // Blink 3 times faster
     Serial.println("open failed");


Working ping back and forth

Working ping back and forth

The pinging back and forth seems to work! Added some additional setup
lines from the previous commit.

--- feather_code_combined/feather_code_combined.ino
+++ feather_code_combined/feather_code_combined.ino
@@ -117,6 +117,21 @@
       while (! ble.isConnected()) {
         delay(500);
       }
+
+      // LED Activity command is only supported from 0.6.6
+      if ( ble.isVersionAtLeast(MINIMUM_FIRMWARE_VERSION) )
+      {
+        // Change Mode LED Activity
+        Serial.println(F("Change LED activity to " MODE_LED_BEHAVIOUR));
+        ble.sendCommandCheckOK("AT+HWModeLED=" MODE_LED_BEHAVIOUR);
+      }
+
+      // Set module to DATA mode
+      Serial.println( F("Switching to DATA mode!") );
+      ble.setMode(BLUEFRUIT_MODE_DATA);
+
+      ble.print("Bluetooth initialized");
+      Serial.println("Bluetooth initialized");
     }
     int16_t packetnum = 0;  // packet counter, we increment per xmission


Removed unused variable.

Removed unused variable.

--- examples/ServoDiscovery/ServoDiscovery.ino
+++ examples/ServoDiscovery/ServoDiscovery.ino
@@ -201,8 +201,6 @@
   while(Serial.read() != -1);
 }

-bool doAgain = true;
-
 void loop() {

   size_t servoCount = 0;


arduino side works too

arduino side works too

--- arduino/examples/i2c_driver_test/i2c_driver_test.ino
+++ arduino/examples/i2c_driver_test/i2c_driver_test.ino
@@ -48,6 +48,7 @@
   _reg_int.valuePointer = &int_reg_val;

   _reg_chrarry.dataType = DT_CHRARY;
+  Serial.println(_reg_chrarry.dataType,HEX);
   _reg_chrarry.valuePointer = chrarry_reg_val;

   _register[0] = _reg_int;