nighttime icons

nighttime icons

--- WifiWeatherGuy.ino
+++ WifiWeatherGuy.ino
@@ -1,3 +1,4 @@
+#include <time.h>
 #include <ArduinoJson.h>
 #include <SPI.h>
 #include <FS.h>
@@ -174,7 +175,7 @@
 }

 struct Conditions {
-	char icon[16];
+	char icon[20];
 	char weather[32];
 	int temp, feelslike;
 	int humidity;
@@ -182,9 +183,9 @@
 	int atmos_pressure;
 	int pressure_trend;
 	char wind_dir[10];
-	char sunrise_hour[3];
+	int sunrise_hour;
 	char sunrise_minute[3];
-	char sunset_hour[3];
+	int sunset_hour;
 	char sunset_minute[3];
 	char moonrise_hour[3];
 	char moonrise_minute[3];
@@ -206,7 +207,6 @@
 		return false;

 	c.epoch = epoch;
-	strlcpy(c.icon, current_observation[F("icon")] | "", sizeof(c.icon));
 	strlcpy(c.weather, current_observation[F("weather")] | "", sizeof(c.weather));
 	if (cfg.metric) {
 		c.temp = current_observation[F("temp_c")];
@@ -221,14 +221,16 @@
 	}
 	c.humidity = atoi(current_observation[F("relative_humidity")] | "0");
 	c.pressure_trend = atoi(current_observation[F("pressure_trend")] | "0");
-	strlcpy(c.wind_dir, current_observation[F("wind_dir")] | "", sizeof(c.wind_dir));;
+	strlcpy(c.wind_dir, current_observation[F("wind_dir")] | "", sizeof(c.wind_dir));
 	c.wind_degrees = current_observation[F("wind_degrees")];
 	strlcpy(c.city, current_observation[F("observation_location")][F("city")] | "", sizeof(c.city));
+
 	JsonObject &sun = root[F("sun_phase")];
-	strlcpy(c.sunrise_hour, sun[F("sunrise")][F("hour")] | "", sizeof(c.sunrise_hour));
+	c.sunrise_hour = atoi(sun[F("sunrise")][F("hour")] | "0");
 	strlcpy(c.sunrise_minute, sun[F("sunrise")][F("minute")] | "", sizeof(c.sunrise_minute));
-	strlcpy(c.sunset_hour, sun[F("sunset")][F("hour")] | "", sizeof(c.sunset_hour));
+	c.sunset_hour = atoi(sun[F("sunset")][F("hour")] | "0");
 	strlcpy(c.sunset_minute, sun[F("sunset")][F("minute")] | "", sizeof(c.sunset_minute));
+
 	JsonObject &moon = root[F("moon_phase")];
 	strlcpy(c.age_of_moon, moon[F("ageOfMoon")] | "", sizeof(c.age_of_moon));
 	strlcpy(c.moon_phase, moon[F("phaseofMoon")] | "", sizeof(c.moon_phase));
@@ -236,6 +238,15 @@
 	strlcpy(c.moonrise_minute, moon[F("moonrise")][F("minute")] | "", sizeof(c.moonrise_minute));
 	strlcpy(c.moonset_hour, moon[F("moonset")][F("hour")] | "", sizeof(c.moonset_hour));
 	strlcpy(c.moonset_minute, moon[F("moonset")][F("minute")] | "", sizeof(c.moonset_minute));
+
+	struct tm *tm = localtime(&epoch);
+	const char *icon = current_observation[F("icon")] | "";
+	if (!tm || (tm->tm_hour >= c.sunrise_hour && tm->tm_hour <= c.sunset_hour))
+		strlcpy(c.icon, icon, sizeof(c.icon));
+	else {
+		strcpy_P(c.icon, PSTR("nt_"));
+		strlcat(c.icon, icon, sizeof(c.icon)-3);
+	}
 	return true;
 }

@@ -250,7 +261,7 @@
 	int wind_degrees;
 	int ave_humidity;
 	char conditions[32];
-	char icon[16];
+	char icon[20];
 } forecasts[4];

 void update_forecasts(JsonObject &root) {
@@ -322,7 +333,7 @@
 	tft.setCursor(right(4, tft.width(), 2), 1);
 	tft.print(F("moon"));
 	tft.setTextSize(1);
-	tft.setCursor(strlen(c.sunrise_hour) == 1? 7: 1, 17);
+	tft.setCursor(c.sunrise_hour < 10? 7: 1, 17);
 	tft.print(c.sunrise_hour);
 	tft.print(':');
 	tft.print(c.sunrise_minute);


Change newly created files to use LF for end of line

--- src/Gortobot_v3c.ino
+++ src/Gortobot_v3c.ino
@@ -8,7 +8,6 @@
 // change isbd to use hardware serial
 // battery classes, abstract, fake
 // gps classes, abstract, fake
-// get rid of software serial

 // Program Modes (config)
 #include <configs/config.h>


Motor code for calinbration and softer start/stop

--- arduino_motor/arduino_motor.ino
+++ arduino_motor/arduino_motor.ino
@@ -2,10 +2,10 @@
 //#include "utility/Adafruit_MS_PWMServoDriver.h"

 Adafruit_MotorShield AFMS = Adafruit_MotorShield();
-Adafruit_DCMotor *M1 = AFMS.getMotor(1);
-Adafruit_DCMotor *M2 = AFMS.getMotor(2);
-Adafruit_DCMotor *M3 = AFMS.getMotor(3);
-Adafruit_DCMotor *M4 = AFMS.getMotor(4);
+Adafruit_DCMotor *Mrf = AFMS.getMotor(1);
+Adafruit_DCMotor *Mlf = AFMS.getMotor(4);
+Adafruit_DCMotor *Mrb = AFMS.getMotor(2);
+Adafruit_DCMotor *Mlb = AFMS.getMotor(3);

 void setup() {
   Serial.begin(9600);           // set up Serial library at 9600 bps
@@ -14,11 +14,39 @@
   AFMS.begin();  // create with the default frequency 1.6KHz
 }

+// ----- state ------
+int speed = 200;
+int suddenness = 100;
+int trim = 0;
+
+int Vrf = 0;
+int Vlf = 0;
+int Vrb = 0;
+int Vlb = 0;
+int speed_rf = 0;
+int speed_lf = 0;
+int speed_rb = 0;
+int speed_lb = 0;
+
+unsigned long current_time = 0;
+
 void loop() {
   int command;
   if (Serial.available()) {
      command = Serial.read();
      switch (command) {
+       case 'A':
+         Vlf = 10;
+         break;
+       case 'B':
+         Vrf = 10;
+         break;
+       case 'C':
+         Vlb = 10;
+         break;
+       case 'D':
+         Vrb = 10;
+         break;
        case 'f':
          do_forward();
          break;
@@ -39,72 +67,84 @@
          break;
      }
   }
+
+  if (millis() - current_time > suddenness) {
+     current_time = millis();
+
+     adjust_speed ("rf", Mrf, speed, Vrf, &speed_rf);
+     adjust_speed ("lf", Mlf, speed, Vlf, &speed_lf);
+     adjust_speed ("rb", Mrb, speed, Vrb, &speed_rb);
+     adjust_speed ("lb", Mlb, speed, Vlb, &speed_lb);
+  }
+}
+
+void adjust_speed (char * m, Adafruit_DCMotor *M, int speed, int V, int *speed_m) {
+  int delta = speed * V - *speed_m * 10;
+
+  if (!delta) {
+    return;
+  }
+  delta = delta / 40 + 1;
+  *speed_m = *speed_m + delta;
+  if (*speed_m < 10 && -*speed_m < 10) {
+     *speed_m = 0;
+  }
+  if (!strcmp (m, "lf")) {
+     Serial.print(m);
+     Serial.print(" ");
+     Serial.println(*speed_m);
+  }
+  if (*speed_m > 0) {
+     M->setSpeed(*speed_m);
+     M->run(FORWARD);
+  } else if (*speed_m < 0) {
+     M->setSpeed(-*speed_m);
+     M->run(BACKWARD);
+  } else {
+     M->run(RELEASE);
+  }
 }

 void do_forward() {
-  M1->setSpeed(200);
-  M2->setSpeed(200);
-  M3->setSpeed(200);
-  M4->setSpeed(200);
-  M1->run(FORWARD);
-  M2->run(FORWARD);
-  M3->run(FORWARD);
-  M4->run(FORWARD);
+  Vlf = 10;
+  Vrf = 10;
+  Vlb = 10;
+  Vrb = 10;
 }

 void do_reverse() {
-  M1->setSpeed(200);
-  M2->setSpeed(200);
-  M3->setSpeed(200);
-  M4->setSpeed(200);
-  M1->run(BACKWARD);
-  M2->run(BACKWARD);
-  M3->run(BACKWARD);
-  M4->run(BACKWARD);
+  Vlf = -10;
+  Vrf = -10;
+  Vlb = -10;
+  Vrb = -10;
 }

 void do_right_turn() {
-  M1->setSpeed(200);
-  M2->setSpeed(0);
-  M3->setSpeed(200);
-  M4->setSpeed(0);
-  M1->run(FORWARD);
-  M2->run(FORWARD);
-  M3->run(FORWARD);
-  M4->run(FORWARD);
+  Vlf = 0;
+  Vrf = 10;
+  Vlb = 0;
+  Vrb = 10;
 }

 void do_left_turn() {
-  M1->setSpeed(0);
-  M2->setSpeed(200);
-  M3->setSpeed(0);
-  M4->setSpeed(200);
-  M1->run(FORWARD);
-  M2->run(FORWARD);
-  M3->run(FORWARD);
-  M4->run(FORWARD);
+  Vlf = 10;
+  Vrf = 0;
+  Vlb = 10;
+  Vrb = 0;
 }

 void do_pivot_left() {
-  M1->setSpeed(100);
-  M2->setSpeed(100);
-  M3->setSpeed(100);
-  M4->setSpeed(100);
-  M1->run(BACKWARD);
-  M2->run(FORWARD);
-  M3->run(BACKWARD);
-  M4->run(FORWARD);
+  Vlf = -10;
+  Vrf = 10;
+  Vlb = -10;
+  Vrb = 10;
 }

 void do_stop() {
-  M1->setSpeed(0);
-  M2->setSpeed(0);
-  M3->setSpeed(0);
-  M4->setSpeed(0);
-  M1->run(FORWARD);
-  M2->run(FORWARD);
-  M3->run(FORWARD);
-  M4->run(FORWARD);
+  Vlf = 0;
+  Vrf = 0;
+  Vlb = 0;
+  Vrb = 0;
 }


Made the vars printout use "buffer" and made it smaller

--- Arduino/BLuB/BLuB.ino
+++ Arduino/BLuB/BLuB.ino
@@ -500,15 +500,14 @@

 void cmd_vars( void )
 {
-	char buf[20];
 	Serialprintln( "Vars:" );
 	for( int i=0 ; i<(kNVariables/2) ; i++ )
 	{
-		snprintf( buf, 20, "  %c: %-9d", i+'a', variables[i] );
-		Serial.print( buf );
-
-		snprintf( buf, 20, "    %c: %-9d", i+13+'a', variables[i+13] );
-		Serial.println( buf );
+		snprintf( buffer, kBufLen, "  %c: %-5d", i+'a', variables[i] );
+		Serial.print( buffer );
+
+		snprintf( buffer, kBufLen, " %c: %-5d", i+13+'a', variables[i+13] );
+		Serial.println( buffer );
 	}
 }


Checked arduino1.ino

Checked arduino1.ino

--- working_directory/arduino_codes/arduino1/arduino1.ino
+++ working_directory/arduino_codes/arduino1/arduino1.ino
@@ -3,7 +3,7 @@
 //FLAGS -- Mainloop
 int flag_check_ldr =  0;
 int flag_check_5v_brownout = 1;
-int flag_check_12v_brownout = 0;
+int flag_check_12v_brownout = 1;

 // FLAGS -- Status
 int flag_5v_brownout_detected = 0;
@@ -13,14 +13,14 @@

 //THRESHOLDS
 int threshold_12v = 700; //#CHANGE
-int threshold_5v = 700; //#CHANGE
+int threshold_5v = 512; //#CHANGE
 int threshold_ldr = 512;

 //Pin Definitions
-char pin_5v_brownout = A3;
-char pin_12v_brownout = A4;
-char pin_ldr_1 = A1;
-char pin_ldr_2 = A2;
+char pin_5v_brownout = A2;
+char pin_12v_brownout = A3;
+char pin_ldr_1 = A5;
+char pin_ldr_2 = A4;
 int pin_relay_5v = 6;
 int pin_relay_12v = 7;

@@ -42,6 +42,8 @@
 	pinMode(pin_ldr_1,INPUT);
 	pinMode(pin_ldr_2,INPUT);
     pinMode(debug_pin,OUTPUT);
+    pinMode(pin_relay_5v,OUTPUT);
+    pinMode(pin_relay_12v,OUTPUT);

 	// Safety Initializations
 	turn_off_dynamixel();
@@ -65,7 +67,7 @@

 	// checks for 5 Volt brown out
 	if(flag_check_5v_brownout == 1){
-		check_for_12v_brownout();
+		check_for_5v_brownout();
 	}

 	// checks for LDR status
@@ -103,19 +105,33 @@
 void check_for_5v_brownout(){
 	// This function is used to check for stable 5 Volts
 	input_5v = analogRead(pin_5v_brownout);
-	if(flag_5v_brownout_detected == 1){
-		// CHANGE LATER (to ensure actual brownout and not a minor fluctuation)
-		if(input_5v<threshold_5v){
-			turn_on_backup_battery();
-			flag_5v_brownout_detected = 1;
-		}
-	}
-	else{
-		if(input_5v>threshold_5v){
-			turn_off_backup_battery();
-			flag_5v_brownout_detected = 0;
-		}
-	}
+	// if(flag_5v_brownout_detected == 0){
+	// 	// CHANGE LATER (to ensure actual brownout and not a minor fluctuation)
+
+	Serial.println(input_5v);
+	delay(500);
+
+	// if(input_5v<threshold_5v){
+	// 	turn_on_backup_battery();
+	// 	flag_5v_brownout_detected = 1;
+	// }
+	// else{
+	// 	// turn_off_backup_battery();
+	// 	flag_5v_brownout_detected = 0;
+	// }
+
+
+	// 	if(input_5v<threshold_5v){
+	// 		turn_on_backup_battery();
+	// 		flag_5v_brownout_detected = 1;
+	// 	}
+	// }
+	// else{
+	// 	if(input_5v>threshold_5v){
+	// 		turn_off_backup_battery();
+	// 		flag_5v_brownout_detected = 0;
+	// 	}
+	// }
 }

 void check_both_ldr(){


[CapacitanceTester] switch to microsecond timing

--- Electronics101/CapacitanceTester/CapacitanceTester.ino
+++ Electronics101/CapacitanceTester/CapacitanceTester.ino
@@ -47,22 +47,22 @@
   char capStr[10];

   digitalWrite(charge_pin, HIGH);
-  startTime = millis();
+  startTime = micros();
   while(analogRead(read_charge_pin) < vtrigger_level) {}
-  elapsedTime = millis() - startTime;
+  elapsedTime = micros() - startTime;
   digitalWrite(charge_pin, LOW);

   lcd.clear();
   lcd.print("test complete:");
   lcd.setCursor(0, 1);

-  capacitance = ((float)elapsedTime / r1) * 1000.0; //mF
-  if(capacitance>1) { //mF
+  capacitance = ((float)elapsedTime / r1); // uF
+  if(capacitance>1) { //uF
     dtostrf(capacitance, 4, 3, capStr);
     lcd.print(capStr);
     lcd.print("uF");
   } else {
-    dtostrf(capacitance * 1000, 4, 3, capStr);
+    dtostrf(capacitance * 1000.0, 4, 3, capStr);
     lcd.print(capStr);
     lcd.print("nF");
   }


set correct number of LEDs

set correct number of LEDs

--- tree/tree.ino
+++ tree/tree.ino
@@ -2,7 +2,7 @@

 #define PIXEL_PIN   13    // Digital IO pin connected to the NeoPixels.

-#define PIXEL_COUNT 10//22
+#define PIXEL_COUNT 22

 #define BUTTON_PIN  3


test_ok2

--- module0/module0.ino
+++ module0/module0.ino
@@ -23,18 +23,50 @@
 }

 void turn_left(){
+  bool done = false;
   while(numberof_active_sensors() != 0){
     motor->go(80, 80, FORWARD);
+    done = true;
   }
-  while(true) stop();
+
+  if (done){
+    do{
+      motor->go(80, 80, ANTICLOCKWISE);
+      delayMicroseconds(1);
+    } while (numberof_active_sensors() < 1);
+  }
+
+  stop();
+  delay(1000);
 }

+
 void turn_right(){
+  bool done = false;
   while(numberof_active_sensors() != 0){
     motor->go(80, 80, FORWARD);
+    done = true;
   }
-  while(true)  stop();
+
+  if (done){
+    do{
+      motor->go(80, 80, CLOCKWISE);
+      delayMicroseconds(1);
+    } while (numberof_active_sensors() < 1);
+  }
+
+  stop();
+  delay(1000);
 }
+
+
+
+//void turn_right(){
+//  while(numberof_active_sensors() != 0){
+//    motor->go(80, 80, FORWARD);
+//  }
+//  while(true)  stop();
+//}

 void loop()
 {


Rename to use with IDE

Rename to use with IDE


Update comment about board. [ci skip]

Update comment about board.
[ci skip]

--- examples/Boards_WiFi/TinyDuino_WiFi/TinyDuino_WiFi.ino
+++ examples/Boards_WiFi/TinyDuino_WiFi/TinyDuino_WiFi.ino
@@ -18,6 +18,8 @@
  * Feel free to apply it to any other example. It's simple!
  *
  * Note: Firmware version 1.14 or later is preferred.
+ *       Tools->Board     should be "Arduino Pro or Pro Mini"
+ *       Tools->Processor should be "ATmega 328 (3.3V, 8MHz)"
  *
  * Change WiFi ssid, pass, and Blynk auth token to run :)
  *


Kan half rechtsdraaien. RF werkt niet.

Kan half rechtsdraaien. RF werkt niet.

--- eerste/eerste.ino
+++ eerste/eerste.ino
@@ -4,6 +4,7 @@
                 // twelve servo objects can be created on most boards

 int pos = 90;    // variable to store the servo position
+int count = 0;

 //pinkers
 int Lpinker = 4; // Linker pinker
@@ -34,8 +35,9 @@
 bool achteruitRijden= LOW;
 bool linksRijden = LOW;
 bool rechtsRijden = LOW;
-bool rondKijken = LOW;
+bool rechtsKijken = LOW;
 bool vooruitKijken = HIGH;
+bool rechtsDraaien = LOW;

 int LmotorA= 5;  // Left  motor H bridge, input A
 int LmotorB = 6;  // Left  motor H bridge, input B
@@ -142,31 +144,34 @@
        previousMillisServo = currentMillisServo;
        myservo.write(pos);

-       if(vooruitKijken){
-       pos += hoekServo;
-       if(pos >= 125 || pos<= 55)hoekServo = hoekServo*-1;
-       }
-
-       }
+       if(vooruitKijken)
+       {
+         pos += hoekServo;
+         if(pos >= 125 || pos <= 55) hoekServo = hoekServo*-1;
+       }
      }
+
    if (currentMillisSensor - previousMillisSensor >= intervalSensor) {
      previousMillisSensor = currentMillisSensor;
      Distance();

-     if (pos >= 55 && pos <= 125 && distance <= 10 && distance > 0) {
-       vooruitRijden = LOW;
-       //rondKijken = HIGH;
-       //vooruitKijken = LOW;
+     if (pos >= 55 && pos <= 125 && distance <= 10 && distance > 0) {
+       count += 1;
+       vooruitRijden = LOW;
+       if (count >= 5) rechtsKijken = HIGH;
+
        Serial.println("STOP");
+
       }

      else if (pos >= 55 && pos <= 125 && distance > 10 || distance == -1) {
-
+        count = 0;
        vooruitRijden = HIGH;
        //rondKijken = LOW;
        Serial.println("DRIVE");
      }
      }
+     }

   if(vooruitRijden){
@@ -174,12 +179,47 @@
          Stuur = 1500;
   }

-  if(rondKijken) {
-    pos += hoekServoRondkijken;
-       if(pos >= 180 || pos<= 0)hoekServoRondkijken = hoekServoRondkijken*-1;
-       //if (pos == 90 && distance > 10 || distance == -1) vooruitKijken = HIGH;
-       //if (pos == 0 && distance > 10 || distance == -1) { Stuur = 2000; Snelheid = 1500;}
+  if(rechtsKijken) {
+    vooruitKijken = LOW;
+    Serial.println("rechtskijken");
+    Serial.println(distance);
+    Serial.println(pos);
+    pos = 0;
+     if ( pos == 0 && distance >= 10 || distance == -1)
+     {
+       Snelheid = 1500;
+       Stuur = 2000;
+       rechtsDraaien = HIGH;
+
+       Serial.println("rechtsdraaien");
+      //  vooruitKijken = HIGH;
+     }
+    /* else
+     {
+       pos = 180;
+       Serial.println("Linkskijken");
+
+       if (pos == 180 && distance >= 20 ||distance == -1)
+       {
+         Snelheid = 1500;
+         Stuur = 1000;
+         Serial.println("Linksdraaien");
+         vooruitKijken = HIGH;
+       }
+       else vooruitKijken = HIGH;
+     }*/
+  }
+
+  if (rechtsDraaien)
+  {
+    pos = 90;
+    Serial.println("Rechtsdraaien");
+    if (pos == 90 && distance >= 30 || distance == -1)
+    {
+      rechtsKijken = LOW;
+      vooruitKijken = HIGH;
     }
+  }

     Pinkers(Stuur, currentMillis);


Fixed Bugs

Fixed Bugs

All messages were reading errors, added “feeling” message

--- Code/CodeVersion_1_27_2015/CodeVersion_1_27_2015.ino
+++ Code/CodeVersion_1_27_2015/CodeVersion_1_27_2015.ino
@@ -70,16 +70,14 @@
   char c;
   String inputcommand="";
   // Check for available SMS
-  delay(1000);
-  if (sms.available())
-  {
-
+  //delay(1000);
+  if (sms.available()){
     // Get remote number
     sms.remoteNumber(senderNumber, 20);
-
     // Read message bytes and print them
     while(c=sms.read())
       inputcommand+=c;
+
     sms.beginSMS(senderNumber);

     if(findWord("water",inputcommand)){
@@ -88,6 +86,23 @@
       sms.print("Thanks for the drink!");
       sms.endSMS();
     }
+
+    else if(findWord("feeling",inputcommand)){
+      // Question: "How are you feeling?" "Feeling good?"
+      colorWipe(strip.Color(0, 0, 0), 50);
+      uint16_t x = tsl.getLuminosity(TSL2561_VISIBLE);
+      float f = dht.readTemperature(true);
+      if(x>=1500 && f>=70.0){
+        sms.print("I'm feeling great! Getting enough light and the temperature feels good.");
+        delay(1000);
+        sms.endSMS();
+      } else if(x<=1500 && f>=70.0){
+        sms.print("I'm O.K.! It's a little dark in here but the temperature feels good.");
+        delay(1000);
+        sms.endSMS();
+      }
+    }
+
     else if(findWord("light",inputcommand)){
       colorWipe(strip.Color(0, 0, 0), 50);    // Black/off
       uint16_t x = tsl.getLuminosity(TSL2561_VISIBLE);
@@ -95,8 +110,7 @@
       String stringThree = stringOne + x;
       sms.print(stringThree);
       delay(1000);
-      sms.endSMS();
-      //delay(400);
+      sms.endSMS();
     }
     else if(findWord("temp",inputcommand)){
       colorWipe(strip.Color(0, 0, 0), 50);
@@ -113,7 +127,7 @@
     else if(findWord("hello",inputcommand)){
       colorWipe(strip.Color(255, 128, 255), 50);
       sms.print("Hello my name is Erb, lets grow some plants!");
-      //delay(1000);
+      delay(1000);
       sms.endSMS();

     }
@@ -129,13 +143,10 @@
       sms.print("I dont know what that means :( ");
       delay(1000);
       sms.endSMS();
-
-    }
-
+    }
     sms.flush();
-
-  }
-  }
+    }
+   }

  int findWord(String searchWord, String sentence) {
@@ -153,7 +164,7 @@
  int activateWatering(int motor_pin,int delaySeconds){
    digitalWrite(motor_pin,HIGH);
    play_melody();
-   delay(delaySeconds*1000);
+   //delay(delaySeconds*1000);
    digitalWrite(motor_pin,LOW);
  }


Update SEN0093_no_pin_state_change.ino.ino

--- Sensor_Tests/Individual_Sensor_Sketches/Thermometers/SEN0093_infrared/SEN0093_no_pin_state_change.ino/SEN0093_no_pin_state_change.ino.ino
+++ Sensor_Tests/Individual_Sensor_Sketches/Thermometers/SEN0093_infrared/SEN0093_no_pin_state_change.ino/SEN0093_no_pin_state_change.ino.ino
@@ -1,11 +1,4 @@
-/*
-
-www.DFRobot.com
-
-Author: Lauren
-Version:0.1
-
-*/
+

 ////////////////Arduino例子程序///////////////////////////////////////


Fixed issues in arduino temperature sensor

--- features/iot-plugins-feature/arduino-plugin-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/agent/PollServer.ino
+++ features/iot-plugins-feature/arduino-plugin-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/agent/PollServer.ino
@@ -26,22 +26,33 @@
     client.fastrprint(IOT_SERVICE_EPOINT);
     client.fastrprint(F(" HTTP/1.1"));
     client.fastrprint(F("\n"));
-    client.fastrprint(host.c_str());
+    client.fastrprint(host.c_str());client.fastrprint(F("\n"));
     client.fastrprint(F("Authorization: Bearer ")); client.fastrprint(F(DEVICE_TOKEN)); client.fastrprint(F("\n"));
     client.fastrprint(F("Content-Type: application/json")); client.fastrprint(F("\n"));
     client.fastrprint(F("Accept: application/json")); client.fastrprint(F("\n"));
     client.fastrprint(F("\n"));
+    client.fastrprint(F("protocol: HTTP\n"));

     client.println();

+    if(DEBUG) {
+        Serial.print("GET ");
+        Serial.print(IOT_SERVICE_EPOINT);
+        Serial.print(" HTTP/1.1"); Serial.println();
+        Serial.print(host); Serial.println();
+        Serial.print("Content-Type: application/json"); Serial.println();
+        Serial.println();
+    }

     delay(1000);

     while (client.available()) {
         char response = client.read();
+        if(DEBUG) Serial.print(response);
         responseMsg += response;

     }
+    Serial.println();
     Serial.println("Ended..");
     int index = responseMsg.lastIndexOf(":");
     int newLine = responseMsg.lastIndexOf("\n");


Fix time handling when reporting intervals are shorter than a few minutes; improve debug/test output a bit.

--- test/PoE-test/tussendeur-asis-2017/tussendeur-asis-2017.ino
+++ test/PoE-test/tussendeur-asis-2017/tussendeur-asis-2017.ino
@@ -37,11 +37,13 @@
 #else
 #define REPORTING_PERIOD        (10*1000)   //  10 seconds -- -- how often to report our states; in milli seconds.
 #define PREFIX "test"
+#define MQTT_KEEPALIVE          (10)        // seconds -- keep alive check; default is 2 minutes - but it is
+// easier to keep this short during debugging - i.e. when testing breaking connections. Note that this may not
+// work if the Arduino CPP gets the order wrong.
 #endif

-
 typedef enum doorstates { CLOSED, CHECKINGCARD, OPEN } doorstate_t;
-const char doorstates_names[OPEN+1][15] = { "closed", "checking-card", "open" };
+const char doorstates_names[OPEN + 1][15] = { "closed", "checking-card", "open" };

 doorstate_t doorstate;
 unsigned long long last_doorstatechange = 0;
@@ -56,8 +58,10 @@
 #include <ArduinoOTA.h>
 #include <ESP32Ticker.h>
 #include <PubSubClient.h>
-#include <MFRC522.h>    // Requires modifed MFRC522 (see pull rq) or the -master branch as of late DEC 2017.
+
+// Requires modifed MFRC522 (see pull rq) or the -master branch as of late DEC 2017.
 // https://github.com/miguelbalboa/rfid.git
+#include <MFRC522.h>

@@ -551,12 +555,16 @@
 void reportStats() {
   char buff[255];
   snprintf(buff, sizeof(buff),
-           "[%s] alive-uptime %02ld:%02ld :"
-           "swipes %ld, opens %ld, closes %ld, fails %ld, mis-swipes %ld, mqtt reconnects %ld, mqtt fails %ld, door %s",
+           "[%s] alive-uptime %02ld:%02ld "
+           "mqtt: %s (state %d) "
+           "swipes %ld, opens %ld, closes %ld, fails %ld, mis-swipes %ld, mqtt reconnects %ld, mqtt fails %ld, "
+           "door %s, state %s(%d)",
            pname, cnt_minutes / 60, (cnt_minutes % 60),
+           client.connected() ? "connected" : "not-connected", client.state(),
            cnt_cards,
            cnt_opens, cnt_closes, cnt_fails, cnt_misreads, cnt_reconnects, cnt_mqttfails,
-           isOpen() ? "open" : "closed"
+           isOpen() ? "open" : "closed",
+           doorstates_names[doorstate], doorstate
           );
   client.publish(log_topic, buff);
   Serial.println(buff);
@@ -603,7 +611,7 @@

   if (lastdoorstate != doorstate) {
     char msg[255];
-    snprintf(msg, sizeof(msg), "Change from state %s(%d) to (%s)%d\n",
+    snprintf(msg, sizeof(msg), "Change from state %s(%d) to %s(%d)",
              doorstates_names[lastdoorstate], lastdoorstate, doorstates_names[doorstate], doorstate);
     Serial.println(msg);
 #ifndef LOCALMQTT
@@ -632,7 +640,13 @@
   {
     static unsigned long tock = 0;
     if (millis() - tock > REPORTING_PERIOD) {
-      cnt_minutes += ((millis() - tock) + 500) / 1000 / 60;
+      static unsigned long last_min = 0;
+      unsigned long delta = millis() - last_min;
+      unsigned int mins = delta / 60 / 1000;
+      if (mins > 0) {
+        cnt_minutes += mins;
+        last_min += mins * 60 * 1000;
+      }
       reportStats();
       tock = millis();
     }


Make pin assignment for ethernet explicit; in order to no longer rely on linking/include order (and thus work with gcc/studio-io), update for Feb 2018 ArduinoIDE and github libs of that date from Espressif, extra debug info on state changes, move some magic values to #defined constants, make test/debug version a bit more agressive on reporting.

--- test/PoE-test/tussendeur-asis-2017/tussendeur-asis-2017.ino
+++ test/PoE-test/tussendeur-asis-2017/tussendeur-asis-2017.ino
@@ -2,7 +2,7 @@
     to the existing setup late 2017.

 */
-#include "/Users/dirkx/.passwd.h"
+// #include "/Users/dirkx/.passwd.h"

 // Wired ethernet.
 //
@@ -25,10 +25,24 @@

 #define SOLENOID_GPIO     (14)

-#define DOOR_OPEN_DELAY   (10*1000)
-#define REPORTING_PERIOD  (300*1000)
+#define DOOR_OPEN_DELAY         (10*1000)   //  10 seconds -- how long to hold the relay engaged; in milli seconds.
+#define CACHE_FALLBACK_TIMEOUT  (500)       // 0.5 second  -- how long to wait for a reply before checking the cache.
+
+// Report regulary - but swithc to a higher frequency if we are in test mode. Also prefix our MQTT topic with 'test'
+// to avoid confusing production.
+//
+#ifdef LOCALMQTT
+#define REPORTING_PERIOD        (300*1000)  //   5 minutes -- how often to report our states; in milli seconds.
+#define PREFIX ""
+#else
+#define REPORTING_PERIOD        (10*1000)   //  10 seconds -- -- how often to report our states; in milli seconds.
+#define PREFIX "test"
+#endif
+

 typedef enum doorstates { CLOSED, CHECKINGCARD, OPEN } doorstate_t;
+const char doorstates_names[OPEN+1][15] = { "closed", "checking-card", "open" };
+
 doorstate_t doorstate;
 unsigned long long last_doorstatechange = 0;

@@ -64,12 +78,6 @@
 extern void callback(char* topic, byte * payload, unsigned int length);

 bool caching = false;
-
-#ifdef LOCALMQTT
-#define PREFIX ""
-#else
-#define PREFIX "test"
-#endif

 const char rfid_topic[] = PREFIX "deur/tussendeur/rfid";
 const char door_topic[] = PREFIX "deur/tussendeur/open";
@@ -154,7 +162,8 @@
   // force it to ETH -- requires pull RQ https://github.com/espressif/arduino-esp32/issues/944
   // and https://github.com/espressif/esp-idf/issues/1431.
   //
-  ArduinoOTA.begin(TCPIP_ADAPTER_IF_ETH);
+  // ArduinoOTA.begin(TCPIP_ADAPTER_IF_ETH);
+  ArduinoOTA.begin();

   Serial.println("OTA enabled.");
   ota = true;
@@ -180,11 +189,11 @@
 {
   switch (event) {
     case SYSTEM_EVENT_ETH_START:
-      Serial.println("ETH Started");
+      Serial.println("ETH Started" + ETH.macAddress());
       ETH.setHostname(pname);
       break;
     case SYSTEM_EVENT_ETH_CONNECTED:
-      Serial.println("ETH Connected");
+      Serial.println("ETH Connected " + ETH.macAddress());
       break;
     case SYSTEM_EVENT_ETH_GOT_IP:
     case SYSTEM_EVENT_STA_GOT_IP:
@@ -256,9 +265,8 @@
   if (p)
     strncpy(pname, p + 1, sizeof(pname));

-  p = index(pname, '.');
-  if (p)
-    *p = 0;
+  if ((p = index(pname, '.')))
+    * p = '\0';

 #ifndef LOCALMQTT
   // Alert us to safe, non production versions.
@@ -275,7 +283,9 @@

   WiFi.onEvent(WiFiEvent);

-  ETH.begin();
+  if (!(ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER, ETH_PHY_MDC, ETH_PHY_MDIO, ETH_PHY_TYPE, ETH_CLK_MODE))) {
+    Serial.println("Ethernet failed to begin() up\n");
+  }

   Serial.println("SPI init");
   spirfid.begin(MFRC522_SCK, MFRC522_MISO, MFRC522_MOSI, MFRC522_SDA);
@@ -290,7 +300,7 @@
   byte regVal = 0xA0; //rx irq
   mfrc522.PCD_WriteRegister(mfrc522.ComIEnReg, regVal);

-  Serial.println("Setting up MQTT");
+  Serial.println("Setting up MQTT to " + String(mqtt_host)  + ":" + String(mqtt_port, DEC));
   client.setServer(mqtt_host, mqtt_port);
   client.setCallback(callback);

@@ -303,39 +313,44 @@
     wipeCache();
   } else {
     caching = true;
-    listDir(SPIFFS, " / ", "");
+    unsigned long count = listDir(SPIFFS, "/", "");
+    Serial.println("Total of " + String(count, DEC) + " files.");
   };

   Serial.println("setup() done.\n\n");
 }

 // This function is taken from the SPIFFS_Test example. Under the expressif ESP32 license.
+// It returns the number of entries found (files only).
 //
-void listDir(fs::FS &fs, const char * dirname, String prefix) {
+unsigned long listDir(fs::FS &fs, const char * dirname, String prefix) {
   Serial.print(prefix);
   Serial.println(dirname);
+  unsigned long count = 0;

   File root = fs.open(dirname);
   if (!root) {
     Serial.println("Failed to open directory");
-    return;
+    return 0;
   }
   if (!root.isDirectory()) {
     Serial.println("Not a directory");
-    return;
+    return 0;
   }

   File file = root.openNextFile();
   while (file) {
     if (file.isDirectory()) {
-      listDir(fs, file.name(), prefix + " ");
+      count += listDir(fs, file.name(), prefix + " ");
     } else {
       Serial.print(prefix + " ");
       Serial.println(file.name());
+      count ++;
     }
     file = root.openNextFile();
   }
   root.close();
+  return count;
 }

 void wipeCache() {
@@ -356,7 +371,7 @@
     SPIFFS.mkdir(String(i));

   Serial.println("Directory structure created.");
-  listDir(SPIFFS, " / ", "");
+  listDir(SPIFFS, "/", "");
   caching = true;
 };

@@ -365,7 +380,7 @@
   for (int i = 0; i < uid.size; i++) {
     path += String(uid.uidByte[i], DEC);
     if (i == 0)
-      path += " / ";
+      path += "/";
     else
       path += ".";
   };
@@ -395,6 +410,7 @@

 void openDoor() {
   doorstate = OPEN;
+  client.publish(log_topic, "Engaging solenoid");

   // Engage solenoid.
   digitalWrite(SOLENOID_GPIO, LOW);
@@ -443,8 +459,9 @@
     if (c >= 32 && c < 128)
       buff[l++] = c;
   };
+
   buff[l] = 0;
-  Serial.println(buff);
+  Serial.println("Handling command: <" + String(buff) + ">");

   if (!strcmp(buff, "reboot")) {
     ESP.restart();
@@ -453,6 +470,16 @@

   if (!strcmp(buff, "report")) {
     reportStats();
+    return;
+  }
+
+  if (!strcmp(buff, "cache")) {
+    char msg[255];
+    unsigned long count = listDir(SPIFFS, "/", "");
+
+    snprintf(msg, sizeof(msg), "[%s] Number of files in the cache: %lu", pname, count);
+    client.publish(log_topic, msg);
+    Serial.println(msg);
     return;
   }

@@ -547,7 +574,7 @@
     client.loop();
     if (!client.connected()) {
       long now = millis();
-      if (now - lastReconnectAttempt > 10*1000) {
+      if (now - lastReconnectAttempt > 10 * 1000) {
         lastReconnectAttempt = now;
         reconnect();
       }
@@ -557,38 +584,48 @@
       client.disconnect();
   }

-  {
-    static doorstate_t lastdoorstate = CLOSED;
-    switch (doorstate) {
-      case CHECKINGCARD:
-        if (millis() - last_doorstatechange > 1500 && caching && checkCache(uid)) {
-          char msg[255];
-          snprintf(msg, sizeof(msg), "[%s] Allowing door to open based on cached information.", pname);
-          Serial.println(msg);
-          client.publish(log_topic, msg);
-          openDoor();
-        }
-        break;
-      case OPEN:
-      case CLOSED:
-      default:
-        break;
-    };
-
-    if (lastdoorstate != doorstate) {
-      lastdoorstate = doorstate;
-      last_doorstatechange = millis();
-    }
-  }
+  static doorstate_t lastdoorstate = CLOSED;
+  switch (doorstate) {
+    case CHECKINGCARD:
+      if (millis() - last_doorstatechange > CACHE_FALLBACK_TIMEOUT && caching && checkCache(uid)) {
+        char msg[255];
+        snprintf(msg, sizeof(msg), "[%s] Allowing door to open based on cached information.", pname);
+        Serial.println(msg);
+        client.publish(log_topic, msg);
+        openDoor();
+      }
+      break;
+    case OPEN:
+    case CLOSED:
+    default:
+      break;
+  };
+
+  if (lastdoorstate != doorstate) {
+    char msg[255];
+    snprintf(msg, sizeof(msg), "Change from state %s(%d) to (%s)%d\n",
+             doorstates_names[lastdoorstate], lastdoorstate, doorstates_names[doorstate], doorstate);
+    Serial.println(msg);
+#ifndef LOCALMQTT
+    client.publish(log_topic, msg);
+#endif
+    lastdoorstate = doorstate;
+    last_doorstatechange = millis();
+  }
+
   // catch any logic errors or strange cases where the door is open while we think
   // we are not doing anything.
   //
   if ((millis() - last_doorstatechange > 10 * DOOR_OPEN_DELAY) && ((doorstate != CLOSED) || (!isClosed()))) {
     closeDoor();
-    char msg[256];
-    snprintf(msg, sizeof(msg), "[%s] Door in an odd state-forcing close.", pname);
-    Serial.println(msg);
-    client.publish(log_topic, msg);
+    static unsigned long lastReport = 0;
+    if (millis() - lastReport > 3000 || doorstate != lastdoorstate) {
+      lastReport = millis();
+      char msg[256];
+      snprintf(msg, sizeof(msg), "[%s] Door %sin an odd state-forcing close.", doorstate == lastdoorstate ? "still " : "",  pname);
+      Serial.println(msg);
+      client.publish(log_topic, msg);
+    };
     cnt_fails ++;
   }


Data rate and payload format updated.

Data rate and payload format updated.

--- embedded/embedded.ino
+++ embedded/embedded.ino
@@ -113,12 +113,19 @@
     char longitude[50];
     float_to_string(coord.lng, longitude, 8);

-    // Mounting JSON
-    String mydataStr = "{\"lat\":\""+String(latitude)+"\",\"lng\":\""+String(longitude)+"\"}";
-
-    // Converting String into uint8_t array
-    uint8_t mydata[mydataStr.length()+1];
-    mydataStr.getBytes(mydata,mydataStr.length()+1);
+    uint8_t mydata[11];
+
+    for (uint8_t loop=4; loop<9; loop++)
+    {
+      mydata[loop-4] = latitude[loop];
+    }
+
+    for (uint8_t loop=4; loop<9; loop++)
+    {
+      mydata[loop+1] = longitude[loop];
+    }
+
+    mydata[10] = 0;

     // Check if there is not a current TX/RX job running
@@ -202,7 +209,7 @@
     DR_SF8C : DR6
     */
     // Set data rate and transmit power for uplink (note: txpow seems to be ignored by the library)
-    LMIC_setDrTxpow(DR_SF12,14);
+    LMIC_setDrTxpow(DR_SF10,14);

     // Init coord
     gps_get_coordinates_ublox(&coord);
@@ -216,4 +223,4 @@
       flag_sent = 0;
     }
     os_runloop_once();
-}
+}


Make size make smaller by defining the new (from 11% to 2%).

--- brotherKH930_arduino.ino
+++ brotherKH930_arduino.ino
@@ -1,4 +1,9 @@
 #include "brotherKH930.h"
+
+void * operator new(size_t size);
+void * operator new(size_t size) {
+   return malloc(size);
+}

 PinSetup pins = kniticV2Pins();
 BrotherKH930 brother(pins, onChange, 0);


updated LCD display

updated LCD display

--- mwsLCD/mwsLCD.ino
+++ mwsLCD/mwsLCD.ino
@@ -28,60 +28,13 @@
 //This is for the 16x2 LCD
 LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

-//this is for RTC
-int clockAddress = 0x68;  // This is the I2C address
-int command = 0;  // This is the command char, in ascii form, sent from the serial port
-long previousMillis = 0;  // will store last time Temp was updated
-byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
-
-byte decToBcd(byte val)
-{
-  return ( (val/10*16) + (val%10) );
-}
-
-// Convert binary coded decimal to normal decimal numbers
-byte bcdToDec(byte val)
-{
-  return ( (val/16*10) + (val%16) );
-}
-
-// Gets the date and time from the ds1307 and prints result
-char* getDateDs1307(int flag) {
-  //if flag == 0 : date output
-  //if flag == 1 : time output
-  // Reset the register pointer
-  Wire.beginTransmission(clockAddress);
-  Wire.write(byte(0x00));
-  Wire.endTransmission();
-
-  Wire.requestFrom(clockAddress, 7);
-
-  // A few of these need masks because certain bits are control bits
-  second     = bcdToDec(Wire.read() & 0x7f);
-  minute     = bcdToDec(Wire.read());
-
-  // Need to change this if 12 hour am/pm
-  hour       = bcdToDec(Wire.read() & 0x3f);
-  dayOfWeek  = bcdToDec(Wire.read());
-  dayOfMonth = bcdToDec(Wire.read());
-  month      = bcdToDec(Wire.read());
-  year       = bcdToDec(Wire.read());
-
-  char sza[32];
-  if (flag==0)
-    sprintf(sza, "%02d-%02d-%02d",year,month,dayOfMonth);
-  if (flag==1)
-    sprintf(sza, "%02d:%02d:%02d",hour,minute,second);
-  return(sza);
-}
-//end of RTC
-
-
+//GPS
 TinyGPSPlus gps;

 static const int RXPin = 5, TXPin = 4; //GPS is attached to pin 4(TX from GPS) and pin 5(RX into GPS)
 SoftwareSerial ss(RXPin, TXPin);

+//Pressure & Humidity sensors on the weather shield
 MPL3115A2 myPressure; //Create an instance of the pressure sensor
 HTU21D myHumidity; //Create an instance of the humidity sensor

@@ -146,9 +99,9 @@
 //float pressure;
 //float dewptf; // [dewpoint F] - It's hard to calculate dewpoint locally, do this in the agent

-float batt_lvl = 11.8; //[analog value from 0 to 1023]
-float light_lvl = 455; //[analog value from 0 to 1023]
-//Rain time stamp Niroshan
+//float batt_lvl = 11.8; //[analog value from 0 to 1023]
+//float light_lvl = 455; //[analog value from 0 to 1023]
+//Rain time stamp Niroshan // Has to be global variable !
 int Rainindi=0;
 //Variables used for GPS
 //float flat, flon; // 39.015024 -102.283608686
@@ -494,10 +447,10 @@
   //Calc dewptf

   //Calc light level
-  light_lvl = get_light_level();
+  float light_lvl = get_light_level();

   //Calc battery level
-  batt_lvl = get_battery_level();
+  float batt_lvl = get_battery_level();

 //} //END OF GO CALC WEATHER FUNCTION


updated LCD display

updated LCD display

--- mwsLCD/mwsLCD.ino
+++ mwsLCD/mwsLCD.ino
@@ -101,7 +101,7 @@
 //float batt_lvl = 11.8; //[analog value from 0 to 1023]
 //float light_lvl = 455; //[analog value from 0 to 1023]
 //Rain time stamp Niroshan // Has to be global variable !
-int Rainindi=0;
+//int Rainindi=0;
 //Variables used for GPS
 //float flat, flon; // 39.015024 -102.283608686
 //unsigned long age;
@@ -129,12 +129,13 @@
     rain5m[minutes_5m] +=0.011*25.4; // increase this 5 mnts amout of rain
     rainlast = raintime; // set up for next event
   }
+  //Removed for dynamic memory reduction
   //Nirosha
   //Rain flag (1)
-  if(rain5m[minutes_5m] > 0)
-  {
-    Rainindi=1;
-  }
+  //if(rain5m[minutes_5m] > 0)
+  //{
+  //  Rainindi=1;
+  //}
   //Niroshan
 }

@@ -252,7 +253,7 @@
       seconds = 0;

       if(++minutes % 60 == 0) minutes = 0;
-      if(++minutes_5m % 5 == 0) Rainindi = 0;
+      //if(++minutes_5m % 5 == 0) Rainindi = 0;
       if(minutes_5m % 5 == 0) minutes_5m = 0;
       if(++minutes_10m % 10 == 0) minutes_10m = 0;

@@ -304,15 +305,10 @@
 float get_battery_level()
 {
   float operatingVoltage = analogRead(REFERENCE_3V3);
-
   float rawVoltage = analogRead(BATT);
-
   operatingVoltage = 3.30 / operatingVoltage; //The reference voltage is 3.3V
-
   rawVoltage = operatingVoltage * rawVoltage; //Convert the 0 to 1023 int to actual voltage on BATT pin
-
   rawVoltage *= 4.90; //(3.9k+1k)/1k - multiple BATT voltage by the voltage divider to get actual system voltage
-
   return(rawVoltage);
 }

@@ -320,16 +316,11 @@
 float get_wind_speed()
 {
   float deltaTime = millis() - lastWindCheck; //750ms
-
   deltaTime /= 1000.0; //Convert to seconds
-
   float windSpeed = (float)windClicks / deltaTime; //3 / 0.750s = 4
-
   windClicks = 0; //Reset and start watching for new wind
   lastWindCheck = millis();
-
   //windSpeed *= 1.492; //4 * 1.492 = 5.968MPH
-
   return(windSpeed);
 }

@@ -366,6 +357,8 @@
 //I don't like the way this function is written but Arduino doesn't support floats under sprintf
 void printWeather()
 {
+      digitalWrite(STAT2, HIGH); //Turn off stat LED
+
   //calcWeather(); //Go calc all the various sensors
 //Calculates each of the variables that wunderground is expecting
 //void calcWeather()
@@ -448,7 +441,6 @@
 //} //END OF GO CALC WEATHER FUNCTION

-
   Serial.println();
   Serial.print(gps.location.lng(), 6);
   Serial.print(",");
@@ -492,6 +484,7 @@
   lcd.setCursor(0, 2);
   lcd.print(sz);
   delay(2000);
+  digitalWrite(STAT2, LOW); //Turn off stat LED

   //Serial.print(",winddir=");
   Serial.print(",");
@@ -574,7 +567,7 @@
   Serial.print(rainin_5m, 2);
   //Serial.print(",rainindicate=");
   Serial.print(",");
-  Serial.print(Rainindi, 1);
+  //Serial.print(Rainindi, 1);

   //Not enough dynamic memory in UNO
   //lcd.clear();


Version 2. Polling and Write functions enabled

--- module/module.ino
+++ module/module.ino
@@ -91,9 +91,9 @@
 		delay(200);
 		responseFlag = getResponse(readData);
 		if(responseFlag == false) Serial.println("Unexpected result");
-	}
-	delay(5000);
-
+		Serial.println("You may now remove your card");
+	}
+	delay(3000);
 }

 void soundFeedback(bool reject) {
@@ -251,18 +251,17 @@
 	unsigned long pollCounter = 0;
 	int signalState;
 	int previousState;
+	bool cardPresent;
 	unsigned char A[bufferSize];

 	while(1) {
 		// poll for card
 		MF_SNR();
+		cardPresent = getResponse(A);
+		delay(cardTimeout);
 		if(!getResponse(A)) {
-			delay(cardTimeout);
-			if(!getResponse(A)) {
-				Serial.println("Card not detected.");
-				soundFeedback(reject);
-				return 0;
-			}
+			Serial.println("Card not detected.");
+			return 0;
 		}

 		// read signal state


Arbotix Software

Arbotix Software

--- sketch_jan30a/sketch_jan30a.ino
+++ sketch_jan30a/sketch_jan30a.ino
@@ -1,5 +1,7 @@
+
    #include <ax12.h>
    #include <Servo.h>
+
    Servo thrustOne;
    Servo thrustTwo;
    Servo thrustThree;
@@ -17,15 +19,16 @@
     int input[7];
     int temp;
     delay(500);
-    int characters[15];
+    int characters[20];
     Serial.print(Serial.available()+" ");
     if(Serial.peek()==45){
       Serial.read();
       while(1){
-        if(Serial.available()==20){//will change to accomadate \n
+        if(Serial.available()==20){
            Serial.print("In the if");
-           for (int i=0;i<15;i++){
-             int temp=(int)Serial.read();
+           for (int i=0;i<20;i++){
+             char temp2=(int)Serial.read();
+             int temp=(int)temp2;
              if(temp!=42 && temp!=38){
                characters[i]=temp;
              }


Removed thermometer support because it works unreliably.

--- firmware/firmware.ino
+++ firmware/firmware.ino
@@ -1,6 +1,3 @@
-#include <OneWire.h>
-#include <DallasTemperature.h>
-
 #include <ESP8266WiFi.h>
 #include "Adafruit_MQTT.h"
 #include "Adafruit_MQTT_Client.h"
@@ -15,13 +12,6 @@
 #define DS18B20     5   // Pin of Dallas DS18B20 digital thermometer

 #define TMP_INTER   5  // Update interval of temperature given in minutes
-
-// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
-OneWire oneWire(DS18B20);
-// Pass our oneWire reference to Dallas Temperature.
-DallasTemperature temp_sensor(&oneWire);
-float temperature;
-unsigned long last_temp_millis = 0;

 unsigned int i = 0;
@@ -38,11 +28,8 @@
 // for some reason (only affects ESP8266, likely an arduino-builder bug).
 void MQTT_connect();

-
-
 void setup() {
   // Initialization
-  temp_sensor.begin();
   pinMode(LED, OUTPUT);

   Serial.begin(74880);
@@ -64,9 +51,7 @@

   // Setup MQTT subscription for onoff feed.
   mqtt.subscribe(&onoffsw);
-
-  // Initial temperature reading
-  updateTemperature();
+
 }

@@ -78,6 +63,7 @@

   while (mqtt.readSubscription(10000)) {

+    // Turn the strip on
     if (strcmp((char *)onoffsw.lastread, "{\"On\":1}") == 0 && !led_on) {

       led_on = true;
@@ -90,6 +76,7 @@
       }

     }
+    // Turn the strip off
     else if (strcmp((char *)onoffsw.lastread, "{\"On\":0}") == 0 && led_on) {

       led_on = false;
@@ -103,7 +90,7 @@
       i = 0;

     }
-    // Check if the brightness setting has been updated
+    // Update the brightness value
     else if (strncmp((char *)onoffsw.lastread, "{\"Brightness\":", 14) == 0 ) {

       Serial.print(F("Brightness: "));
@@ -135,32 +122,8 @@
       }

       brightness = new_brightness;
-
     }
   }
-
-  // Update temperature every TMP_INTER minutes
-  if (millis() - last_temp_millis > TMP_INTER*60000) {
-    updateTemperature();
-  }
-}
-
-
-void updateTemperature() {
-  Serial.print("Requesting temperature...");
-
-  temp_sensor.requestTemperatures(); // Send the command to get temperatures
-  Serial.println("DONE");
-  // After we got the temperatures, we can print them here.
-  // We use the function ByIndex, and as an example get the temperature from the first sensor only.
-  Serial.print("Temperature is: ");
-  Serial.println(temp_sensor.getTempCByIndex(0));
-
-  temperature = temp_sensor.getTempCByIndex(0);
-
-  temp_mqtt.publish(temperature);
-
-  last_temp_millis = millis();
 }


Some comments added to main data sending loop

--- firmware/firmware.ino
+++ firmware/firmware.ino
@@ -38,7 +38,10 @@

 	// And do our loop for sending and recieving data.
 	while(true){
+		// Read our sensors.
 		Sensor_data sensor_data = sensors.read_sensors();
+
+		// Dump the info to our screen.
 		Serial.print(F("Sensor humidity: "));
 		Serial.println(sensor_data.humidity);
 		Serial.print(F("Sensor temperature: "));


Fixes types for channel and pipe.

Fixes types for channel and pipe.

--- sensor/sensor.ino
+++ sensor/sensor.ino
@@ -11,8 +11,8 @@

 RF24* radio;
 int TOILET = 0; // Make this unique for each sensor
-int CHANNEL = 0x60;
-int PIPE = 0x7272727069;
+uint8_t CHANNEL = 0x60;
+uint64_t PIPE = 0x7272727069;

 void setup() {
   Serial.begin(9600);


signed ints

signed ints

--- sensor/sensor.ino
+++ sensor/sensor.ino
@@ -65,8 +65,8 @@
 {
     watchdog_setup();

-    Serial.begin(9600);
-    pinMode(LED_DEBUG, OUTPUT);
+    //Serial.begin(9600);
+    //pinMode(LED_DEBUG, OUTPUT);

     pinMode(PIN_TX, OUTPUT);
     pinMode(PIN_TX_POWER, OUTPUT);
@@ -91,16 +91,16 @@
         tx_last = now;

         digitalWrite(PIN_SENSOR_POWER, HIGH);
+        long vcc = readVcc();
         int solar_read = analogRead(PIN_SOLAR);
-        //int thermistor_read = analogRead(PIN_SENSOR_THERMISTOR);
-        int temperature_external = Thermistor(analogRead(PIN_SENSOR_THERMISTOR));
+        int thermistor_read = analogRead(PIN_SENSOR_THERMISTOR);
         int soil_read = analogRead(PIN_SENSOR_SOIL);
         int lm35_read = analogRead(PIN_SENSOR_LM35);
-        int temperature_internal = (5 * lm35_read * 100)/1024;
         digitalWrite(PIN_SENSOR_POWER, LOW);
-
-
-
+
+        int temperature_external = Thermistor(thermistor_read);
+        int temperature_internal = (5.0 * lm35_read * 100.0)/1024.0;
+        int solr_mv = vcc / 1024.0 * solar_read * 2;

         // Send a transmission
         digitalWrite(PIN_TX_POWER, HIGH);
@@ -108,8 +108,8 @@
         // long int = 10 bytes in transmision string
         // byte = 3 bytes in transmision string
         char msg[35]; // string to send
-        sprintf(msg, "S,%d,%u,%u,%u,%u,%lu", msgId, solar_read, temperature_internal, temperature_external, soil_read, readVcc());
-        Serial.println(msg);
+        sprintf(msg, "S,%d,%i,%i,%i,%i,%lu", msgId, solr_mv, temperature_internal, temperature_external, soil_read, vcc);
+        //Serial.println(msg);
         vw_send((uint8_t *)msg, strlen(msg));
         vw_wait_tx(); // Wait until the whole message is gone
         digitalWrite(PIN_TX_POWER, LOW);
@@ -128,14 +128,16 @@
 /**
  * @see http://playground.arduino.cc/ComponentLib/Thermistor2
  */
-double Thermistor(int RawADC) {
+int Thermistor(int RawADC) {
  double Temp;
  Temp = log(10000.0*((1024.0/RawADC-1)));
   //         =log(10000.0/(1024.0/RawADC-1)) // for pull-up configuration
  Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
- Temp = Temp - 273.15;            // Convert Kelvin to Celcius
+ //Temp = Temp - 273.15;            // Convert Kelvin to Celcius
  //Temp = (Temp * 9.0)/ 5.0 + 32.0; // Convert Celcius to Fahrenheit
- return Temp;
+
+ int celcius = Temp - 273;
+ return celcius;
 }

 /**
@@ -168,7 +170,7 @@
 {
   sleep_flag = flag;

-  digitalWrite(LED_DEBUG, LOW);
+  //digitalWrite(LED_DEBUG, LOW);

   cli();
@@ -209,7 +211,7 @@
   // put ADC back
   ADCSRA = old_ADCSRA;

-  digitalWrite(LED_DEBUG, HIGH);
+  //digitalWrite(LED_DEBUG, HIGH);

 }


Ping now recognises Sharky with 3 sensors

--- embedded/arduino/sharky_measurement.ino
+++ embedded/arduino/sharky_measurement.ino
@@ -19,6 +19,8 @@

 void loop()
 {
+  delayMicroseconds(50);
+
   // check for measurement request on UART
   if (Serial.available() > 0) {
     // read the incoming byte:
@@ -80,7 +82,8 @@
   pinMode(pingPin3, INPUT);
   duration = pulseIn(pingPin3, HIGH);
   cm3 = microsecondsToCentimeters(duration);
-
+
+ /*
   // probe sensor 4
   pinMode(pingPin4, OUTPUT);
   digitalWrite(pingPin4, LOW);
@@ -93,6 +96,7 @@
   pinMode(pingPin4, INPUT);
   duration = pulseIn(pingPin4, HIGH);
   cm4 = microsecondsToCentimeters(duration);
+ */

   // output result on serial
   Serial.print(cm1);
@@ -100,8 +104,8 @@
   Serial.print(cm2);
   Serial.print(":");
   Serial.print(cm3);
-  Serial.print(":");
-  Serial.print(cm4);
+  //Serial.print(":");
+  //Serial.print(cm4);
   Serial.println();
 }


Added DEBUG for Serial printing.

Added DEBUG for Serial printing.

--- frankenbear.ino
+++ frankenbear.ino
@@ -1,6 +1,8 @@
 #include <Adafruit_PWMServoDriver.h>
 #include <Wire.h>
 #include "pitches.h"
+
+#define DEBUG 0

 // **************************
 // **** PROXIMITY SENSOR ****
@@ -91,7 +93,6 @@
   // Initialize serial port at 9600 baud.
   Serial.begin(9600);

-  Serial.println("VCNL");
   Wire.begin();
   pwm.begin();
   pwm.setPWMFreq(60);  // Analog servos run at ~60 Hz.
@@ -104,20 +105,26 @@
   }

   write8(VCNL4000_IRLED, 20);        // set to 20 * 10mA = 200mA
+#if DEBUG
+  Serial.println("VCNL");
   Serial.print("IR LED current = ");
   Serial.print(read8(VCNL4000_IRLED) * 10, DEC);
   Serial.println(" mA");
-
   Serial.print("Proximity measurement frequency = ");
+#endif
   uint8_t freq = read8(VCNL4000_SIGNALFREQ);
+#if DEBUG
   if (freq == VCNL4000_3M125) Serial.println("3.125 MHz");
   if (freq == VCNL4000_1M5625) Serial.println("1.5625 MHz");
   if (freq == VCNL4000_781K25) Serial.println("781.25 KHz");
   if (freq == VCNL4000_390K625) Serial.println("390.625 KHz");
+#endif

   write8(VCNL4000_PROXIMITYADJUST, 0x81);
+#if DEBUG
   Serial.print("Proximity adjustment register = ");
   Serial.println(read8(VCNL4000_PROXIMITYADJUST), HEX);
+#endif

   // Initialize the pushbutton pin as an input.
   pinMode(button_pin, INPUT);
@@ -131,9 +138,6 @@
 void loop()
 {
   photocell_reading = analogRead(photocell_pin);
-  Serial.print("Analog reading = ");
-  Serial.print(photocell_reading);
-  Serial.print("\t");

   // When it gets bright or dark, make a sound.
   // Don't play the sound again until it's normal lighting out.
@@ -169,10 +173,14 @@
       ambient_reading = read16(VCNL4000_AMBIENTDATA);
       proximity_reading = read16(VCNL4000_PROXIMITYDATA);

-      Serial.print("Ambient = ");
+#if DEBUG == 1
+      Serial.print("Analog reading = ");
+      Serial.print(photocell_reading);
+      Serial.print("\tAmbient = ");
       Serial.print(ambient_reading);
       Serial.print("\tProximity = ");
       Serial.println(proximity_reading);
+#endif
       break;
     }

@@ -180,12 +188,12 @@
   }

   // Don't wiggle again until it's normal proximity again.
-  if ( ambient_reading > 75 )
+  if ( ambient_reading > 45 )
   {
     normal_proximity_flag = 1;
   }

-  if ( ambient_reading < 30 && normal_proximity_flag ) // proximity_reading doesn't work well through fabric.
+  if ( ambient_reading < 30 && normal_proximity_flag ) // proximity_reading doesn't work well throu gh fabric.
   {
     for ( int i = 0; i < 4; i++ )
     {


Read Serial input and pass it into command handler

--- mutually-assured-destruction.ino
+++ mutually-assured-destruction.ino
@@ -56,30 +56,24 @@
 	Serial.begin(9600);     // Begin serial
   relay_setup();          // call before delay because relays are active low so we want to set to be HIGH as soon as possible

-#if MAD_LOGGING
-  Serial.println(F("It's a MAD World!"));
-#endif
+  LOGN(F("It's a MAD World!"));

   blinkLEDOnBootup();     // Blink the LED to give some time to reset Teensy if needed

   loadConfig(); // load important values about angles and other app settings that need to persist

-#if MAD_LOGGING
-  Serial.println(F("Begin Accelerometer Setup"));
+  LOGN(F("Begin Accelerometer Setup"));
   delay(100);
-#endif

   // Initalize the Accelerometer module
   accelerometer = new Accelerometer();
   accelerometer->setup();

-#if MAD_LOGGING
   if ( accelerometer->working ) {
-    Serial.println(F("Accelerometer setup complete"));
+    LOGN(F("Accelerometer setup complete"));
   } else {
-    Serial.println(F("Accelerometer setup failed."));
-  }
-#endif
+    LOGN(F("Accelerometer setup failed."));
+  }
 }

 void loop() {
@@ -94,14 +88,28 @@
        accelerometer->last_position == AccelerometerPositionNone) {

     if ( accelerometer->position == AccelerometerPositionSide0Top ) {   // RED
-      Serial.println("Pattern 1 On!");
-      r0->setOnWithPattern(SHAVE_LEFT);
+      cmd_poof(0x01);

     } else if ( accelerometer->position == AccelerometerPositionSide1Top ) {  // BLUE
-      Serial.println("Pattern 2 On!");
-      r1->setOnWithPattern(SINGLE_BUTTON_PRESS);
-
+      cmd_poof(0x02);
     }
+  }
+
+
+  // Check for Serial input commands
+  // TODO: specify Serial
+
+  byte incomingByte;
+  bool hadData = false;
+  while (Serial.available() > 0) {    // read the entire serial, and only process the last command
+    incomingByte = Serial.read();
+#if MAD_MAIN_LOGGING
+    Serial.print("Read a byte: "); Serial.println(incomingByte, HEX);
+#endif
+    hadData = true;
+  }
+  if ( hadData ) {
+    cmd_handle_from_serial(incomingByte);
   }

   // Relays call loop() on each main loop so they can update their internal state.
@@ -113,17 +121,37 @@
   delay(10);
 }

+
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////

 /**
  * Command handlers for commands  that can be sent to this board via Serial, RF, or some other comm channel
  */

+
+/*
+ * Passes a byte from Serial "API" into the command handlers
+ */
+void cmd_handle_from_serial(byte commandByte ) {
+  switch(commandByte) {
+    case 'L': cmd_poof(0x01); break;
+    case 'R': cmd_poof(0x02); break;
+    case 'B': cmd_poof(0x03); break;
+    case 'A': cmd_save_current_seesaw_angle(); break;
+    default:
+      LOGN("Unsupported command from serial.");
+      break;
+  }
+}
+
 /*
  * Calibrates the trigger angles of the seesaw.
  */
+
 void cmd_save_current_seesaw_angle() {
   // NOTE: could call loop() here to update angle, but assuming its been updated recently as it is always called inside loop()
+  LOGN(F("Handling Command: Save SeeSaw Angle"));
   accelerometer->storeCurrentAngleForSide();
 }

@@ -135,12 +163,26 @@
  * 0x03 : Both Relays
  */
 void cmd_poof(byte which) {
+
+  // Just logging
+  LOG(F("Handling Command: Poof "));
+  if (( which & 0x01) && (which & 0x02)) {
+    LOGN(F("Both"));
+  } else if ( which & 0x01 ) {
+    LOGN(F("LEFT 0x01"));
+  } else if ( which & 0x02 ) {
+    LOGN(F("RIGHT 0x02"));
+  }
+
+  // Handle the command
   if ( which & 0x01 ) {
     r0->setOnWithPattern(SINGLE_BUTTON_PRESS);
   }
   if ( which & 0x02 ) {
     r1->setOnWithPattern(SINGLE_BUTTON_PRESS);
   }
+
+  // Call loop so the relays update internally
   r0->loop();
   r1->loop();
 }
@@ -187,7 +229,7 @@
  */
 void blinkLEDOnBootup() {
   pinMode(LED, OUTPUT);
-  for ( int i = 0; i < 3; i++ ) {
+  for ( int i = 0; i < 4; i++ ) {
     digitalWrite(LED, HIGH);
     delay(500);
     digitalWrite(LED, LOW);


save ram store strings in flash

save ram store strings in flash

--- Arduino/Base/Base.ino
+++ Arduino/Base/Base.ino
@@ -49,10 +49,11 @@
     DEBUG_PRINTLN(F("Network Connection Failed."));
   }

+  DEBUG_PRINTLN("ok..");
 }

 void loop(){
-  DEBUG_PRINTLN("====================Beginning of Void Loop====================");
+  DEBUG_PRINTLN(F("====================Beginning of Void Loop===================="));

   /*
   This limits the sending of updates to the server by sending a maximum of 10 once every minute
@@ -60,7 +61,7 @@
   */
   if(timeout_timedout() || qCount == QMAX){
     if(qCount > 0){//will only send if q isn't empty
-      DEBUG_PRINT("Made it to server update. Number of messages: ");
+      DEBUG_PRINT(F("Made it to server update. Number of messages: "));
       DEBUG_PRINTLN(qCount);
       delay(1000);
       for(int i = 0; i < qCount; i++){
@@ -81,7 +82,7 @@
   }

   messageFromNode = xcomm.getMessage();
-  DEBUG_PRINTLN("Message From Node: "+ messageFromNode);
+  DEBUG_PRINT(F("Message From Node: "));DEBUG_PRINTLN(messageFromNode);

   if (messageFromNode != NULL) {
         uint8_t start = 0;
@@ -95,7 +96,7 @@
 		//DEBUG_PRINTLN(identifier.length());
 		identifier.trim();
 		if(identifier=="N"){
-			DEBUG_PRINTLN("Number of sensors request from " + nodeId);
+			DEBUG_PRINT(F("Number of sensors request from "));DEBUG_PRINTLN(nodeId);
 			DEBUG_PRINTLN(F("Making HTTP GET Request"));
 			response = simcomm.HTTPRequest(0, "http://sachleen.com/sachleen/parking/API/nodes/" + nodeId, "");
 			DEBUG_PRINTLN(response);
@@ -144,11 +145,11 @@
 			spacesAvail[qCount] = available;
 			qCount++;

-			DEBUG_PRINTLN("Storing in queue...");
+			DEBUG_PRINTLN(F("Storing in queue..."));
 		}
         delay(2000);
     }
-    DEBUG_PRINTLN("====================End of Void Loop====================");
+    DEBUG_PRINTLN(F("====================End of Void Loop===================="));
 }

 /*


fixed POST url

fixed POST url

--- Arduino/Base/Base.ino
+++ Arduino/Base/Base.ino
@@ -65,7 +65,7 @@
       delay(1000);
       for(int i = 0; i < qCount; i++){
 		DEBUG_PRINTLN(F("Making HTTP POST Request"));
-		simcomm.HTTPRequest(1, "http://sachleen.com/sachleen/parking/API/nodes/save", "id=" + nodeIds[i] + "&" + "available=" + spacesAvail[i] + "&" + apiKey);
+		simcomm.HTTPRequest(1, "http://sachleen.com/sachleen/parking/API/nodes/save", "id=" + nodeIds[i] + "&" + "available=" + spacesAvail[i] + "&api_key=" + apiKey);
         //sendResponse = sendRequestServer(nodeIds[i], 'U', spacesAvail[i], totalSpaces[i]);//Sends a message to the server to update the status of the node
 		DEBUG_PRINTLN(response);//Idk what the response is supposed to be yet...
 		/*
@@ -154,157 +154,6 @@
     DEBUG_PRINT("Free Ram after loop: ");DEBUG_PRINTLN(freeRam());
 }

-// int sendRequestServer(String nodeId, char identifierC, int amount, int total){
-		// int nodeNumber = -1;
-
-                // uint8_t responseStart;
-                // uint8_t responseEnd;
-                // uint8_t quoteStart;
-                // uint8_t quoteEnd;
-
-                // String responseTotal;
-                // String quoteCheck;
-
-		// switch(identifierC){
-			// case 'N':
-                                // /*
-				// DEBUG_PRINT("Sending Number of Sensors Request from : ");
-				// DEBUG_PRINTLN(nodeId);
-				// nodeNumber = 3;//Will be replaced with response from server
-				// break;
-                                // */
-
-				// DEBUG_PRINT("Sending Number of Sensors Request from : ");
-				// DEBUG_PRINTLN(nodeId);
-				// //Sending update to server
-				// SIM900.listen();
-				// // Set the bearer profile identifier to 1 (see bearer initialization in connectToNetwork() phase 4)
-				// SIM900.println(F("AT+HTTPPARA=\"CID\",\"1\""));
-				// response = sim900Response();
-				// if (response.indexOf("OK") < 0) {
-					// DEBUG_PRINTLN(F("Error setting CID"));
-					// DEBUG_PRINTLN(response);
-				// }
-
-				// // Set the URL
-				// DEBUG_PRINTLN(F("Setting URL"));
-
-				// SIM900.println("AT+HTTPPARA=\"URL\",\"http://sachleen.com/sachleen/parking/API/nodes/" + String(nodeId) + "\"");
-				// response = sim900Response();
-				// DEBUG_PRINTLN("HTTP RESPONSE IS: " + response);
-
-
-				// if (response.indexOf("OK") >= 0) {
-					// DEBUG_PRINTLN(F("Set URL"));
-					// pass = true;
-				// }
-
-				// if (pass) {
-					// pass = false;
-
-					// // Set the action to GET
-					// DEBUG_PRINTLN(F("Making HTTP Request"));
-
-					// SIM900.println(F("AT+HTTPACTION=0"));
-					// response = sim900Response();
-
-					// // Check for not only an OK but also a 200 status code.
-					// if (response.indexOf("OK") >= 0) {
-						// DEBUG_PRINTLN(F("Made request!"));
-						// pass = true;
-					// } else {
-						// response = sim900Response();
-						// DEBUG_PRINTLN(response);
-					// }
-				// }
-
-				// if (pass) {
-					// // Read response from server. By not providing any parameters, it reads all data.
-					// DEBUG_PRINTLN(F("Reading HTTP response data"));
-
-					// SIM900.println(F("AT+HTTPREAD"));
-
-					// response = sim900Response();
-					// DEBUG_PRINTLN(response);
-					// //response = "Success";
-					// if (response.indexOf("Success") >= 0) {
-						// DEBUG_PRINTLN(F("Request complete!"));
-					// } else {
-						// DEBUG_PRINTLN("Request did NOT return Success");
-						// DEBUG_PRINTLN(response);
-					// }
-					// responseStart = response.indexOf("total\":\"") + 8;
-					// responseEnd = responseStart + 1;
-
-					// quoteStart = responseEnd;
-					// quoteEnd = responseStart + 2;
-					// quoteCheck = response.substring(quoteStart, quoteEnd);
-
-
-					// if(quoteCheck.equals("\"")){
-						// responseTotal = response.substring(responseStart, responseEnd);
-					// }
-					// else{
-						// responseTotal = response.substring(responseStart, responseEnd + 1);
-					// }
-					// nodeNumber = responseTotal.toInt();
-				// }
-				// //response = responseFromServer;
-				// //This case (of char 'N') should return the number of sensors at the node
-				// //Needs parsing of string
-				// //nodeNumber = responseFromServer;
-				// break;
-
-			// case 'U':
-				// DEBUG_PRINT("Sending Update Message to Server: ");
-				// DEBUG_PRINTLN(nodeId + ',' + amount + ',' + total);
-				// nodeNumber = 1;
-				// break;
-			// default:
-				// DEBUG_PRINTLN("ERROR: Unrecognized Request");
-		// }
-		// //waits for a request form the server
-		// return nodeNumber;
-// }
-
-// void sendMessageNode(String targetId,int sensorCount){
-
-	// /*
-	// DEBUG_PRINT(F("Sending message to node:"));
-	// DEBUG_PRINTLN(targetId + ',' + sensorCount);
-	// */
-
-	// String messageToNode = targetId + "," + (String)sensorCount;
-	// xbee.listen();
-	// xbee.println(messageToNode);
-
-// }
-
-
-// String getNodeMessage() {
-
-	// //This will get any message being sent from a node
-	// xbee.listen();
-	// String incomingNodeMessage = xbeeResponse();
-	// DEBUG_PRINTLN(F("Message From Node"));
-	// DEBUG_PRINTLN(incomingNodeMessage);
-
-	// uint8_t start = 0;
-	// uint8_t end = incomingNodeMessage.indexOf(',');
-	// String targetNode = incomingNodeMessage.substring(start, end);
-
-	// sendMessageNode(targetNode, 0);//number sent is arbitrary. Lets the node know it received the message
-
-	// return incomingNodeMessage;
-// }
-
-int freeRam ()
-{
-  extern int __heap_start, *__brkval;
-  int v;
-  return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
-}
-
 /*
     Software Reset Functions
 */


Add files via upload

Add files via upload

fixed a few bugs:
forgot to multiply voltage by scaling factor of 11
forgot to close datafile after printing uuid
...
...
tired
...
...

--- arduino/tempLogger/tempLogger.ino
+++ arduino/tempLogger/tempLogger.ino
@@ -40,8 +40,8 @@
 #include "TrueRandom.h" //https://github.com/sirleech/TrueRandom

 //debug settings
-#define DEBUG 0 //turn off when unnecessary to preserve power
-#define DEBUG_TO_SD 0
+#define DEBUG 0 //0 debug off, 1 debug on. turn off when unnecessary to preserve power
+#define DEBUG_TO_SD 0 //0 debug off, 1 debug on

 //sd card variables
 #define POWA 4    // pin 4 supplies power to microSD card breakout and temp sensor
@@ -349,10 +349,19 @@
       int topDigit = uuidNumber[i] >> 4;
       int bottomDigit = uuidNumber[i] & 0x0f;
       // Print high hex digit
+#if DEBUG
+      Serial.print( "0123456789ABCDEF"[topDigit]);
+      Serial.print("0123456789ABCDEF"[bottomDigit]);
+#endif
       dataFile.print( "0123456789ABCDEF"[topDigit] );
       // Low hex digit
       dataFile.print( "0123456789ABCDEF"[bottomDigit] );
     }
+#if DEBUG
+    Serial.println();
+#endif
+
+    dataFile.close();
   }
 }

@@ -395,14 +404,6 @@
   Serial.begin(9600);
 #endif

-/*REMOVE
-  // set pin 4 (POWA) to output so that we can control the
-  //power of the sd reader and the temp sensor
-  pinMode(POWA, OUTPUT);
-  // turn on SD card and temp sensor
-  digitalWrite(POWA, HIGH);
-*/
-
   //set up sd card
   sd_setup();

@@ -480,21 +481,28 @@
     // take a number of analog samples and add them up
     while (sample_count < NUM_VOLTAGE_SAMPLES) {
         sum += analogRead(A3);
+        /*REMOVE*/
+#if DEBUG_TO_SD
+        write_Text_To_Disk("sum = "+String(sum)+"\n");
+#endif
+#if DEBUG
+        Serial.println("sum = "+String(sum)+"\n");
+#endif
         sample_count++;
         delay(10);
     }
     // use 5.0 for a 5.0V ADC reference voltage
     // 5.015V is the calibrated reference voltage
-    voltage = ((float)sum / (float)NUM_VOLTAGE_SAMPLES * 5.05) / 1024.0;
+    voltage = ((float)sum / (float)NUM_VOLTAGE_SAMPLES * 5) / 1024.0;
     sample_count = 0;
     sum = 0;
-
+    voltage *= 11;
     // send voltage for display on Serial Monitor
     // voltage multiplied by 11 when using voltage divider that
     // divides by 11. 11.132 is the calibrated voltage divide
     // value
 #if DEBUG
-    Serial.print(voltage * 11.133);
+    Serial.print(voltage);
     Serial.println (" V");
 #endif


Changed the values for serial port

Changed the values for serial port

--- arduino_signal/arduino_signal.ino
+++ arduino_signal/arduino_signal.ino
@@ -6,7 +6,7 @@
 void setup()   {
   // initialize the IR digital pin as an output:
   pinMode(IRledPin, OUTPUT);
-
+
   Serial.begin(9600);
 }

@@ -19,32 +19,36 @@
     inputCommand = Serial.read();
     Serial.println(inputCommand);
     switch (inputCommand) {
-      case 48:
+      case 117:
       Serial.write('0');
       SendOnCode();
       break;
-      case 49:
+      case 118:
+      Serial.write('0');
+      SendOnCode();
+      break;
+      case 119:
       Serial.write('1');
       SendChannelUpCode();
       break;
-      case 50:
+      case 120:
       Serial.write('2');
       SendChannelDownCode();
       break;
-      case 51:
+      case 121:
       Serial.write('3');
       SendVolUpCode();
       break;
-      case 52:
+      case 122:
       Serial.write('4');
       SendVolDownCode();
       break;
-      case 53:
+      case 123:
       Serial.write('5');
       SendChannel59Code();
       break;
     }
-
+
  // delay(5000);  // wait twenty seconds (10 seconds * 1000 milliseconds)
 }
 }
@@ -53,16 +57,16 @@
 // for a certain # of microseconds. We'll use this whenever we need to send codes
 void pulseIR(long microsecs) {
   // we'll count down from the number of microseconds we are told to wait
-
+
   cli();  // this turns off any background interrupts
-
+
   while (microsecs > 0) {
     // 38 kHz is about 13 microseconds high and 13 microseconds low
    digitalWrite(IRledPin, HIGH);  // this takes about 3 microseconds to happen
    delayMicroseconds(10);         // hang out for 10 microseconds
    digitalWrite(IRledPin, LOW);   // this also takes about 3 microseconds
    delayMicroseconds(10);         // hang out for 10 microseconds
-
+
    // so 26 microseconds altogether
    microsecs -= 26;
  }
@@ -156,532 +160,551 @@
 }
 void SendChannelUpCode() {
 //Change Channel Up
-delayMicroseconds(38792);
+delayMicroseconds(34632);
 pulseIR(8840);
 delayMicroseconds(4340);
-pulseIR(600);
-delayMicroseconds(480);
-pulseIR(600);
-delayMicroseconds(500);
-pulseIR(600);
-delayMicroseconds(1580);
-pulseIR(620);
-delayMicroseconds(480);
-pulseIR(600);
-delayMicroseconds(500);
-pulseIR(600);
-delayMicroseconds(480);
-pulseIR(620);
-delayMicroseconds(480);
-pulseIR(620);
-delayMicroseconds(480);
-pulseIR(600);
-delayMicroseconds(1580);
-pulseIR(600);
-delayMicroseconds(1580);
-pulseIR(620);
-delayMicroseconds(480);
-pulseIR(620);
-delayMicroseconds(1580);
-pulseIR(600);
-delayMicroseconds(1600);
-pulseIR(580);
-delayMicroseconds(1600);
-pulseIR(620);
-delayMicroseconds(1560);
-pulseIR(620);
-delayMicroseconds(1580);
-pulseIR(600);
-delayMicroseconds(1600);
-pulseIR(600);
-delayMicroseconds(500);
-pulseIR(580);
-delayMicroseconds(500);
-pulseIR(600);
-delayMicroseconds(500);
-pulseIR(600);
-delayMicroseconds(500);
-pulseIR(580);
-delayMicroseconds(500);
-pulseIR(600);
-delayMicroseconds(480);
-pulseIR(620);
-delayMicroseconds(480);
-pulseIR(600);
-delayMicroseconds(480);
-pulseIR(620);
-delayMicroseconds(1600);
-pulseIR(580);
-delayMicroseconds(1600);
-pulseIR(580);
-delayMicroseconds(1600);
-pulseIR(620);
-delayMicroseconds(1580);
-pulseIR(600);
-delayMicroseconds(1580);
-pulseIR(600);
-delayMicroseconds(1600);
-pulseIR(600);
-delayMicroseconds(1600);
+pulseIR(640);
+delayMicroseconds(460);
+pulseIR(600);
+delayMicroseconds(500);
+pulseIR(620);
+delayMicroseconds(1560);
+pulseIR(600);
+delayMicroseconds(500);
+pulseIR(620);
+delayMicroseconds(460);
+pulseIR(640);
+delayMicroseconds(460);
+pulseIR(640);
+delayMicroseconds(460);
+pulseIR(620);
+delayMicroseconds(460);
+pulseIR(640);
+delayMicroseconds(1560);
+pulseIR(620);
+delayMicroseconds(1580);
+pulseIR(600);
+delayMicroseconds(480);
+pulseIR(620);
+delayMicroseconds(1580);
+pulseIR(620);
+delayMicroseconds(1560);
+pulseIR(640);
+delayMicroseconds(1560);
+pulseIR(620);
+delayMicroseconds(1560);
+pulseIR(620);
+delayMicroseconds(1580);
+pulseIR(620);
+delayMicroseconds(1580);
+pulseIR(620);
+delayMicroseconds(460);
+pulseIR(640);
+delayMicroseconds(440);
+pulseIR(620);
+delayMicroseconds(500);
+pulseIR(620);
+delayMicroseconds(460);
+pulseIR(640);
+delayMicroseconds(460);
+pulseIR(600);
+delayMicroseconds(500);
+pulseIR(600);
+delayMicroseconds(480);
+pulseIR(620);
+delayMicroseconds(480);
+pulseIR(600);
+delayMicroseconds(1580);
+pulseIR(640);
+delayMicroseconds(1560);
+pulseIR(620);
+delayMicroseconds(1560);
+pulseIR(600);
+delayMicroseconds(1580);
+pulseIR(660);
+delayMicroseconds(1560);
+pulseIR(600);
+delayMicroseconds(1580);
+pulseIR(640);
+delayMicroseconds(1540);
+pulseIR(640);
+delayMicroseconds(38900);
+pulseIR(8840);
+delayMicroseconds(2140);
+pulseIR(620);
+delayMicroseconds(28284);
+pulseIR(8840);
+delayMicroseconds(2160);
+pulseIR(600);
+
+}
+void SendChannelDownCode() {
+
+//Change Channel Down
+delayMicroseconds(47428);
+pulseIR(8840);
+delayMicroseconds(4340);
+pulseIR(620);
+delayMicroseconds(460);
+pulseIR(640);
+delayMicroseconds(460);
+pulseIR(620);
+delayMicroseconds(1580);
+pulseIR(640);
+delayMicroseconds(460);
+pulseIR(620);
+delayMicroseconds(460);
+pulseIR(620);
+delayMicroseconds(480);
+pulseIR(600);
+delayMicroseconds(500);
+pulseIR(600);
+delayMicroseconds(480);
+pulseIR(620);
+delayMicroseconds(1580);
+pulseIR(620);
+delayMicroseconds(1560);
+pulseIR(600);
+delayMicroseconds(500);
+pulseIR(620);
+delayMicroseconds(1560);
+pulseIR(620);
+delayMicroseconds(1560);
+pulseIR(640);
+delayMicroseconds(1580);
+pulseIR(600);
+delayMicroseconds(1580);
+pulseIR(640);
+delayMicroseconds(1540);
+pulseIR(640);
+delayMicroseconds(1560);
+pulseIR(660);
+delayMicroseconds(420);
+pulseIR(640);
+delayMicroseconds(460);
+pulseIR(640);
+delayMicroseconds(1540);
+pulseIR(640);
+delayMicroseconds(460);
+pulseIR(640);
+delayMicroseconds(460);
+pulseIR(660);
+delayMicroseconds(420);
+pulseIR(640);
+delayMicroseconds(460);
+pulseIR(620);
+delayMicroseconds(480);
+pulseIR(620);
+delayMicroseconds(1560);
+pulseIR(640);
+delayMicroseconds(1560);
+pulseIR(640);
+delayMicroseconds(460);
+pulseIR(620);
+delayMicroseconds(1560);
+pulseIR(640);
+delayMicroseconds(1560);
+pulseIR(620);
+delayMicroseconds(1560);
+pulseIR(620);
+delayMicroseconds(1560);
+pulseIR(660);
+delayMicroseconds(38880);
+pulseIR(8820);
+delayMicroseconds(2180);
+pulseIR(600);
+
+}
+
+void SendVolUpCode() {
+
+//Vol Up
+delayMicroseconds(41216);
+pulseIR(8840);
+delayMicroseconds(4340);
+pulseIR(620);
+delayMicroseconds(460);
+pulseIR(640);
+delayMicroseconds(460);
+pulseIR(600);
+delayMicroseconds(1580);
+pulseIR(640);
+delayMicroseconds(460);
+pulseIR(600);
+delayMicroseconds(500);
+pulseIR(640);
+delayMicroseconds(440);
+pulseIR(640);
+delayMicroseconds(460);
+pulseIR(600);
+delayMicroseconds(500);
+pulseIR(620);
+delayMicroseconds(1560);
+pulseIR(640);
+delayMicroseconds(1540);
+pulseIR(640);
+delayMicroseconds(460);
+pulseIR(620);
+delayMicroseconds(1580);
+pulseIR(640);
+delayMicroseconds(1560);
+pulseIR(620);
+delayMicroseconds(1560);
+pulseIR(600);
+delayMicroseconds(1580);
+pulseIR(640);
+delayMicroseconds(1580);
+pulseIR(600);
+delayMicroseconds(480);
+pulseIR(620);
+delayMicroseconds(460);
+pulseIR(620);
+delayMicroseconds(500);
+pulseIR(640);
+delayMicroseconds(1540);
+pulseIR(600);
+delayMicroseconds(480);
+pulseIR(620);
+delayMicroseconds(480);
+pulseIR(640);
+delayMicroseconds(440);
+pulseIR(620);
+delayMicroseconds(480);
+pulseIR(640);
+delayMicroseconds(1560);
+pulseIR(600);
+delayMicroseconds(1580);
+pulseIR(640);
+delayMicroseconds(1560);
+pulseIR(640);
+delayMicroseconds(440);
+pulseIR(640);
+delayMicroseconds(1560);
+pulseIR(620);
+delayMicroseconds(1560);
+pulseIR(640);
+delayMicroseconds(1560);
+pulseIR(640);
+delayMicroseconds(1560);
+pulseIR(620);
+delayMicroseconds(38920);
+pulseIR(8800);
+delayMicroseconds(2160);
+pulseIR(640);
+
+}
+void SendVolDownCode() {
+
+//Vol Down
+delayMicroseconds(62900);
+pulseIR(8820);
+delayMicroseconds(4360);
+pulseIR(620);
+delayMicroseconds(460);
+pulseIR(640);
+delayMicroseconds(460);
+pulseIR(600);
+delayMicroseconds(1580);
+pulseIR(620);
+delayMicroseconds(480);
+pulseIR(640);
+delayMicroseconds(460);
+pulseIR(620);
+delayMicroseconds(460);
+pulseIR(640);
+delayMicroseconds(460);
+pulseIR(640);
+delayMicroseconds(460);
+pulseIR(620);
+delayMicroseconds(1560);
+pulseIR(640);
+delayMicroseconds(1560);
+pulseIR(620);
+delayMicroseconds(480);
+pulseIR(600);
+delayMicroseconds(1580);
+pulseIR(640);
+delayMicroseconds(1560);
+pulseIR(620);
+delayMicroseconds(1560);
+pulseIR(640);
+delayMicroseconds(1540);
+pulseIR(640);
+delayMicroseconds(1580);
+pulseIR(600);
+delayMicroseconds(480);
+pulseIR(620);
+delayMicroseconds(1580);
+pulseIR(620);
+delayMicroseconds(460);
+pulseIR(640);
+delayMicroseconds(1560);
+pulseIR(620);
+delayMicroseconds(460);
+pulseIR(660);
+delayMicroseconds(440);
+pulseIR(600);
+delayMicroseconds(500);
+pulseIR(620);
+delayMicroseconds(460);
+pulseIR(640);
+delayMicroseconds(1560);
+pulseIR(620);
+delayMicroseconds(460);
+pulseIR(640);
+delayMicroseconds(1560);
+pulseIR(620);
+delayMicroseconds(460);
+pulseIR(640);
+delayMicroseconds(1560);
+pulseIR(620);
+delayMicroseconds(1580);
+pulseIR(600);
+delayMicroseconds(1580);
+pulseIR(640);
+delayMicroseconds(1560);
+pulseIR(620);
+delayMicroseconds(38920);
+pulseIR(8800);
+delayMicroseconds(2160);
+pulseIR(640);
+delayMicroseconds(28284);
+pulseIR(8840);
+delayMicroseconds(2140);
+pulseIR(640);
+
+}
+void SendChannel59Code() {
+
+//Channel 59
+delayMicroseconds(28436);
+pulseIR(8780);
+delayMicroseconds(4380);
+pulseIR(620);
+delayMicroseconds(480);
+pulseIR(620);
+delayMicroseconds(460);
+pulseIR(640);
+delayMicroseconds(1580);
+pulseIR(600);
+delayMicroseconds(480);
+pulseIR(620);
+delayMicroseconds(460);
+pulseIR(640);
+delayMicroseconds(480);
+pulseIR(600);
+delayMicroseconds(480);
+pulseIR(640);
+delayMicroseconds(460);
+pulseIR(620);
+delayMicroseconds(1560);
+pulseIR(640);
+delayMicroseconds(1560);
+pulseIR(620);
+delayMicroseconds(460);
+pulseIR(640);
+delayMicroseconds(1560);
+pulseIR(620);
+delayMicroseconds(1560);
+pulseIR(640);
+delayMicroseconds(1560);
+pulseIR(640);
+delayMicroseconds(1560);
+pulseIR(620);
+delayMicroseconds(1560);
+pulseIR(620);
+delayMicroseconds(480);
+pulseIR(620);
+delayMicroseconds(1560);
+pulseIR(600);
+delayMicroseconds(500);
+pulseIR(640);
+delayMicroseconds(440);
+pulseIR(640);
+delayMicroseconds(1580);
+pulseIR(600);
+delayMicroseconds(480);
+pulseIR(620);
+delayMicroseconds(460);
+pulseIR(620);
+delayMicroseconds(480);
+pulseIR(620);
+delayMicroseconds(1560);
+pulseIR(620);
+delayMicroseconds(480);
+pulseIR(620);
+delayMicroseconds(1580);
+pulseIR(600);
+delayMicroseconds(1580);
+pulseIR(640);
+delayMicroseconds(460);
+pulseIR(640);
+delayMicroseconds(1540);
+pulseIR(680);
+delayMicroseconds(1520);
+pulseIR(620);
+delayMicroseconds(1580);
+pulseIR(600);
+delayMicroseconds(38920);
+pulseIR(8800);
+delayMicroseconds(2200);
+pulseIR(600);
+delayMicroseconds(28304);
+pulseIR(8780);
+delayMicroseconds(2200);
+pulseIR(620);
+
+pause(2);
+delayMicroseconds(18604);
+pulseIR(8780);
+delayMicroseconds(4400);
+pulseIR(620);
+delayMicroseconds(480);
+pulseIR(620);
+delayMicroseconds(460);
+pulseIR(640);
+delayMicroseconds(1560);
+pulseIR(620);
+delayMicroseconds(460);
+pulseIR(640);
+delayMicroseconds(460);
+pulseIR(620);
+delayMicroseconds(480);
+pulseIR(620);
+delayMicroseconds(460);
+pulseIR(680);
+delayMicroseconds(420);
+pulseIR(620);
+delayMicroseconds(1560);
+pulseIR(640);
+delayMicroseconds(1560);
+pulseIR(640);
+delayMicroseconds(460);
+pulseIR(640);
+delayMicroseconds(1560);
+pulseIR(620);
+delayMicroseconds(1560);
+pulseIR(640);
+delayMicroseconds(1540);
+pulseIR(680);
+delayMicroseconds(1520);
+pulseIR(640);
+delayMicroseconds(1560);
+pulseIR(600);
+delayMicroseconds(1580);
+pulseIR(640);
+delayMicroseconds(1560);
+pulseIR(640);
+delayMicroseconds(1540);
+pulseIR(620);
+delayMicroseconds(480);
+pulseIR(620);
+delayMicroseconds(1560);
+pulseIR(620);
+delayMicroseconds(480);
+pulseIR(640);
+delayMicroseconds(440);
+pulseIR(640);
+delayMicroseconds(460);
+pulseIR(620);
+delayMicroseconds(480);
+pulseIR(620);
+delayMicroseconds(480);
+pulseIR(620);
+delayMicroseconds(460);
+pulseIR(620);
+delayMicroseconds(1580);
+pulseIR(640);
+delayMicroseconds(460);
+pulseIR(620);
+delayMicroseconds(1560);
+pulseIR(640);
+delayMicroseconds(1560);
+pulseIR(620);
+delayMicroseconds(1560);
+pulseIR(540);
+delayMicroseconds(39000);
+pulseIR(8760);
+delayMicroseconds(2220);
+pulseIR(620);
+
+pause(2);
+delayMicroseconds(3500);
+pulseIR(8840);
+delayMicroseconds(4340);
+pulseIR(640);
+delayMicroseconds(460);
+pulseIR(600);
+delayMicroseconds(500);
+pulseIR(620);
+delayMicroseconds(1560);
+pulseIR(640);
+delayMicroseconds(460);
+pulseIR(620);
+delayMicroseconds(460);
+pulseIR(640);
+delayMicroseconds(460);
+pulseIR(640);
+delayMicroseconds(460);
+pulseIR(620);
+delayMicroseconds(460);
+pulseIR(640);
+delayMicroseconds(1560);
+pulseIR(620);
+delayMicroseconds(1560);
+pulseIR(640);
+delayMicroseconds(460);
+pulseIR(620);
+delayMicroseconds(1560);
+pulseIR(620);
+delayMicroseconds(1580);
+pulseIR(600);
+delayMicroseconds(1600);
+pulseIR(580);
+delayMicroseconds(1600);
+pulseIR(540);
+delayMicroseconds(1640);
+pulseIR(620);
+delayMicroseconds(1580);
+pulseIR(600);
+delayMicroseconds(500);
+pulseIR(600);
+delayMicroseconds(1600);
+pulseIR(580);
+delayMicroseconds(1600);
+pulseIR(520);
+delayMicroseconds(1660);
+pulseIR(580);
+delayMicroseconds(520);
+pulseIR(540);
+delayMicroseconds(560);
+pulseIR(560);
+delayMicroseconds(520);
+pulseIR(620);
+delayMicroseconds(480);
+pulseIR(540);
+delayMicroseconds(1640);
+pulseIR(620);
+delayMicroseconds(480);
+pulseIR(540);
+delayMicroseconds(560);
+pulseIR(600);
+delayMicroseconds(480);
+pulseIR(620);
+delayMicroseconds(1600);
+pulseIR(580);
+delayMicroseconds(1600);
+pulseIR(520);
+delayMicroseconds(1660);
 pulseIR(600);
 delayMicroseconds(38940);
 pulseIR(8820);
-delayMicroseconds(2140);
-pulseIR(620);
-}
-void SendChannelDownCode() {
-
-//Change Channel Down
-delayMicroseconds(14964);
-pulseIR(8820);
-delayMicroseconds(4340);
-pulseIR(600);
-delayMicroseconds(480);
-pulseIR(620);
-delayMicroseconds(480);
-pulseIR(620);
-delayMicroseconds(1560);
-pulseIR(620);
-delayMicroseconds(480);
-pulseIR(620);
-delayMicroseconds(500);
-pulseIR(580);
-delayMicroseconds(480);
-pulseIR(620);
-delayMicroseconds(480);
-pulseIR(620);
-delayMicroseconds(480);
-pulseIR(600);
-delayMicroseconds(1580);
-pulseIR(620);
-delayMicroseconds(1580);
-pulseIR(620);
-delayMicroseconds(480);
-pulseIR(600);
-delayMicroseconds(1580);
-pulseIR(600);
-delayMicroseconds(1600);
-pulseIR(600);
-delayMicroseconds(1580);
-pulseIR(620);
-delayMicroseconds(1560);
-pulseIR(620);
-delayMicroseconds(1600);
-pulseIR(600);
-delayMicroseconds(1580);
-pulseIR(600);
-delayMicroseconds(500);
-pulseIR(580);
-delayMicroseconds(500);
-pulseIR(600);
-delayMicroseconds(1600);
-pulseIR(600);
-delayMicroseconds(480);
-pulseIR(620);
-delayMicroseconds(480);
-pulseIR(600);
-delayMicroseconds(500);
-pulseIR(600);
-delayMicroseconds(480);
-pulseIR(620);
-delayMicroseconds(480);
-pulseIR(620);
-delayMicroseconds(1560);
-pulseIR(620);
-delayMicroseconds(1580);
-pulseIR(600);
-delayMicroseconds(500);
-pulseIR(600);
-delayMicroseconds(1600);
-pulseIR(580);
-delayMicroseconds(1600);
-pulseIR(580);
-delayMicroseconds(1600);
-pulseIR(620);
-delayMicroseconds(1580);
-pulseIR(600);
-delayMicroseconds(38940);
-pulseIR(8840);
-delayMicroseconds(2120);
-pulseIR(620);
-
-}
-
-void SendVolUpCode() {
-
-//Vol Up
-delayMicroseconds(44280);
-pulseIR(8860);
-delayMicroseconds(4320);
-pulseIR(620);
-delayMicroseconds(480);
-pulseIR(600);
-delayMicroseconds(480);
-pulseIR(620);
-delayMicroseconds(1580);
-pulseIR(600);
-delayMicroseconds(500);
-pulseIR(600);
-delayMicroseconds(480);
-pulseIR(620);
-delayMicroseconds(480);
-pulseIR(600);
-delayMicroseconds(480);
-pulseIR(620);
-delayMicroseconds(480);
-pulseIR(620);
-delayMicroseconds(1580);
-pulseIR(600);
-delayMicroseconds(1600);
-pulseIR(580);
-delayMicroseconds(500);
-pulseIR(620);
-delayMicroseconds(1580);
-pulseIR(600);
-delayMicroseconds(1580);
-pulseIR(580);
-delayMicroseconds(1600);
-pulseIR(620);
-delayMicroseconds(1600);
-pulseIR(580);
-delayMicroseconds(1600);
-pulseIR(600);
-delayMicroseconds(500);
-pulseIR(600);
-delayMicroseconds(480);
-pulseIR(600);
-delayMicroseconds(500);
-pulseIR(600);
-delayMicroseconds(1580);
-pulseIR(620);
-delayMicroseconds(480);
-pulseIR(600);
-delayMicroseconds(500);
-pulseIR(580);
-delayMicroseconds(500);
-pulseIR(600);
-delayMicroseconds(500);
-pulseIR(600);
-delayMicroseconds(1580);
-pulseIR(620);
-delayMicroseconds(1580);
-pulseIR(600);
-delayMicroseconds(1580);
-pulseIR(600);
-delayMicroseconds(500);
-pulseIR(600);
-delayMicroseconds(1600);
-pulseIR(600);
-delayMicroseconds(1580);
-pulseIR(620);
-delayMicroseconds(1580);
-pulseIR(600);
-delayMicroseconds(1580);
-pulseIR(620);
-delayMicroseconds(38920);
+delayMicroseconds(2160);
+pulseIR(600);
+delayMicroseconds(28304);
 pulseIR(8840);
 delayMicroseconds(2140);
-pulseIR(600);
-}
-void SendVolDownCode() {
-
-//Vol Down
-delayMicroseconds(272);
-pulseIR(8820);
-delayMicroseconds(4360);
-pulseIR(580);
-delayMicroseconds(520);
-pulseIR(580);
-delayMicroseconds(500);
-pulseIR(600);
-delayMicroseconds(1600);
-pulseIR(580);
-delayMicroseconds(500);
-pulseIR(600);
-delayMicroseconds(500);
-pulseIR(580);
-delayMicroseconds(520);
-pulseIR(580);
-delayMicroseconds(500);
-pulseIR(600);
-delayMicroseconds(500);
-pulseIR(560);
-delayMicroseconds(1620);
-pulseIR(600);
-delayMicroseconds(1600);
-pulseIR(580);
-delayMicroseconds(500);
-pulseIR(620);
-delayMicroseconds(1580);
-pulseIR(600);
-delayMicroseconds(1600);
-pulseIR(560);
-delayMicroseconds(1620);
-pulseIR(600);
-delayMicroseconds(1600);
-pulseIR(580);
-delayMicroseconds(1600);
-pulseIR(580);
-delayMicroseconds(520);
-pulseIR(600);
-delayMicroseconds(1580);
-pulseIR(580);
-delayMicroseconds(520);
-pulseIR(600);
-delayMicroseconds(1580);
-pulseIR(580);
-delayMicroseconds(540);
-pulseIR(580);
-delayMicroseconds(480);
-pulseIR(620);
-delayMicroseconds(500);
-pulseIR(560);
-delayMicroseconds(520);
-pulseIR(600);
-delayMicroseconds(1580);
-pulseIR(600);
-delayMicroseconds(520);
-pulseIR(580);
-delayMicroseconds(1600);
-pulseIR(560);
-delayMicroseconds(540);
-pulseIR(580);
-delayMicroseconds(1600);
-pulseIR(580);
-delayMicroseconds(1600);
-pulseIR(620);
-delayMicroseconds(1580);
-pulseIR(600);
-delayMicroseconds(1580);
-pulseIR(600);
-delayMicroseconds(38940);
-pulseIR(8820);
-delayMicroseconds(2180);
-pulseIR(580);
-}
-void SendChannel59Code() {
-
-//Channel 59
-delayMicroseconds(5128);
-pulseIR(8760);
-delayMicroseconds(4420);
-pulseIR(560);
-delayMicroseconds(540);
-pulseIR(580);
-delayMicroseconds(500);
-pulseIR(600);
-delayMicroseconds(1600);
-pulseIR(580);
-delayMicroseconds(500);
-pulseIR(600);
-delayMicroseconds(500);
-pulseIR(580);
-delayMicroseconds(520);
-pulseIR(580);
-delayMicroseconds(500);
-pulseIR(600);
-delayMicroseconds(480);
-pulseIR(540);
-delayMicroseconds(1660);
-pulseIR(600);
-delayMicroseconds(1600);
-pulseIR(580);
-delayMicroseconds(500);
-pulseIR(600);
-delayMicroseconds(1600);
-pulseIR(560);
-delayMicroseconds(1620);
-pulseIR(580);
-delayMicroseconds(1620);
-pulseIR(600);
-delayMicroseconds(1600);
-pulseIR(580);
-delayMicroseconds(1600);
-pulseIR(520);
-delayMicroseconds(580);
-pulseIR(580);
-delayMicroseconds(1600);
-pulseIR(580);
-delayMicroseconds(520);
-pulseIR(600);
-delayMicroseconds(480);
-pulseIR(600);
-delayMicroseconds(1600);
-pulseIR(600);
-delayMicroseconds(500);
-pulseIR(600);
-delayMicroseconds(480);
-pulseIR(540);
-delayMicroseconds(560);
-pulseIR(600);
-delayMicroseconds(1580);
-pulseIR(540);
-delayMicroseconds(560);
-pulseIR(600);
-delayMicroseconds(1600);
-pulseIR(520);
-delayMicroseconds(1660);
-pulseIR(600);
-delayMicroseconds(500);
-pulseIR(520);
-delayMicroseconds(1660);
-pulseIR(620);
-delayMicroseconds(1580);
-pulseIR(600);
-delayMicroseconds(1580);
-pulseIR(580);
-delayMicroseconds(38960);
-pulseIR(8760);
-delayMicroseconds(2240);
-pulseIR(580);
-delayMicroseconds(28744);
-pulseIR(8840);
-delayMicroseconds(4340);
-pulseIR(580);
-delayMicroseconds(500);
-pulseIR(620);
-delayMicroseconds(480);
-pulseIR(600);
-delayMicroseconds(1580);
-pulseIR(620);
-delayMicroseconds(480);
-pulseIR(580);
-delayMicroseconds(520);
-pulseIR(600);
-delayMicroseconds(480);
-pulseIR(620);
-delayMicroseconds(480);
-pulseIR(600);
-delayMicroseconds(500);
-pulseIR(580);
-delayMicroseconds(1600);
-pulseIR(620);
-delayMicroseconds(1580);
-pulseIR(600);
-delayMicroseconds(480);
-pulseIR(620);
-delayMicroseconds(1560);
-pulseIR(620);
-delayMicroseconds(1600);
-pulseIR(600);
-delayMicroseconds(1580);
-pulseIR(600);
-delayMicroseconds(1580);
-pulseIR(620);
-delayMicroseconds(1600);
-pulseIR(580);
-delayMicroseconds(1600);
-pulseIR(600);
-delayMicroseconds(1580);
-pulseIR(620);
-delayMicroseconds(1580);
-pulseIR(580);
-delayMicroseconds(500);
-pulseIR(620);
-delayMicroseconds(1580);
-pulseIR(600);
-delayMicroseconds(480);
-pulseIR(620);
-delayMicroseconds(480);
-pulseIR(620);
-delayMicroseconds(480);
-pulseIR(600);
-delayMicroseconds(480);
-pulseIR(620);
-delayMicroseconds(480);
-pulseIR(620);
-delayMicroseconds(480);
-pulseIR(600);
-delayMicroseconds(1580);
-pulseIR(620);
-delayMicroseconds(480);
-pulseIR(600);
-delayMicroseconds(1580);
-pulseIR(620);
-delayMicroseconds(1580);
-pulseIR(600);
-delayMicroseconds(1600);
-pulseIR(600);
-delayMicroseconds(38940);
-pulseIR(8820);
-delayMicroseconds(2140);
-pulseIR(600);
-delayMicroseconds(44636);
-pulseIR(8820);
-delayMicroseconds(4360);
-pulseIR(580);
-delayMicroseconds(520);
-pulseIR(580);
-delayMicroseconds(500);
-pulseIR(600);
-delayMicroseconds(1600);
-pulseIR(600);
-delayMicroseconds(480);
-pulseIR(620);
-delayMicroseconds(480);
-pulseIR(580);
-delayMicroseconds(520);
-pulseIR(580);
-delayMicroseconds(500);
-pulseIR(580);
-delayMicroseconds(520);
-pulseIR(580);
-delayMicroseconds(1600);
-pulseIR(620);
-delayMicroseconds(1580);
-pulseIR(600);
-delayMicroseconds(480);
-pulseIR(620);
-delayMicroseconds(1580);
-pulseIR(600);
-delayMicroseconds(1600);
-pulseIR(560);
-delayMicroseconds(1620);
-pulseIR(600);
-delayMicroseconds(1600);
-pulseIR(600);
-delayMicroseconds(1600);
-pulseIR(560);
-delayMicroseconds(1620);
-pulseIR(600);
-delayMicroseconds(480);
-pulseIR(580);
-delayMicroseconds(1620);
-pulseIR(600);
-delayMicroseconds(1600);
-pulseIR(580);
-delayMicroseconds(1600);
-pulseIR(580);
-delayMicroseconds(520);
-pulseIR(600);
-delayMicroseconds(480);
-pulseIR(620);
-delayMicroseconds(480);
-pulseIR(580);
-delayMicroseconds(520);
-pulseIR(600);
-delayMicroseconds(1580);
-pulseIR(580);
-delayMicroseconds(520);
-pulseIR(600);
-delayMicroseconds(480);
-pulseIR(620);
-delayMicroseconds(480);
-pulseIR(580);
-delayMicroseconds(1600);
-pulseIR(620);
-delayMicroseconds(1600);
-pulseIR(580);
-delayMicroseconds(1600);
-pulseIR(580);
-delayMicroseconds(38940);
-pulseIR(8820);
-delayMicroseconds(2180);
-pulseIR(580);
-delayMicroseconds(28324);
-pulseIR(8820);
-delayMicroseconds(2160);
-pulseIR(600);
+pulseIR(640);


reversed direction sense so + is away from limit switch; added crude hard and soft limit checks

--- arduino/motor_driver/motor_driver.ino
+++ arduino/motor_driver/motor_driver.ino
@@ -33,7 +33,7 @@

 // physical:
 const float WHEEL_RADIUS = (2.0 + 0.125) * 2.54; // 2 inch wheel + 1/8" grommet, in cm
-
+const float MAX_POSITION = 51.0; // in cm

@@ -119,6 +119,8 @@
   Timer1.start();

   Timer1.attachInterrupt(countSteps);
+
+  //Serial.begin(9600);
 }

 void loop() {
@@ -144,12 +146,11 @@
     // reset the timer
     updateTime = now;

-    // local debug -- you can get rid of this
-    //Serial.println("send one");
   } // end if

   updateSpeed(elapsed);
   checkLimitSwitch();
+  checkPositionLimits();

   // check for incoming messages
   etherOSC.listen();
@@ -190,8 +191,20 @@
 void checkLimitSwitch() {
   int hardLimit = digitalRead(HARDLIMITPIN);
   if (hardLimit==1) {
-    go(0);
-    goalSpeed = 0;
+    if (currentSpeed > 0) {
+      go(0);
+      goalSpeed = 0;
+    }
+    stepperpos = 0;
+  }
+}
+
+void checkPositionLimits() {
+  if (stepperpos >= MAX_POSITION * STEPS_PER_CM) {
+    if (currentSpeed < 0) {
+      go(0);
+      goalSpeed = 0;
+    }
   }
 }

@@ -207,12 +220,13 @@
   }
   if (cps < 0) {
     cps = -cps;
-    digitalWrite(DIRPIN, 1);
+    dir = 0;
+  } else {
     dir = 1;
-  } else {
-    digitalWrite(DIRPIN, 0);
-    dir = 0;
   }
+
+  digitalWrite(DIRPIN, dir);
+
   period = 1000000.0 / cps / STEPS_PER_CM;
   // try to get duty period to be about 50 us
   unsigned long duty = (1024.0 * 50.0) / period;


Change the threshold in hopes that the bot can stop before hitting the wall.

--- arduino/sonar_driver/sonar_driver.ino
+++ arduino/sonar_driver/sonar_driver.ino
@@ -1,13 +1,13 @@
 #include <Wire.h>
 #include <NewPing.h>

-#define MAX_DISTANCE 500
+#define MAX_DISTANCE 250
 #define INVALID_DATA -1
-#define RANGE_HIGH 50
-#define RANGE_LOW 5
+#define RANGE_THRESHOLD 10
+#define LED13 13

 #define SONAR_NUM 4
-#define MEDIAN 8
+#define MEDIAN 7

 #define ADDR_SELECT 4
 #define ENABLE 2
@@ -51,23 +51,22 @@
   Wire.onRequest(requestEvent);
 }

+int loopCount = 0;
+
 void loop() {
+  digitalWrite(LED13, loopCount % 2);
   for (int i = 0; i < SONAR_NUM; i++) {
-    digitalWrite(IRQ[i], LOW);
     if (isEnabled()) {
       ranges[i] = ping(i);
-      if (i % 2) {
-        if (ranges[i] < RANGE_LOW) {
-          digitalWrite(IRQ[i], HIGH);
-        }
+      if (INVALID_DATA < ranges[i] <= RANGE_THRESHOLD) {
+        digitalWrite(IRQ[i], HIGH);
       } else {
-        if (ranges[i] > RANGE_HIGH) {
-          digitalWrite(IRQ[i], HIGH);
-        }
+        digitalWrite(IRQ[i], LOW);
       }
       report();
     }
   }
+  loopCount++;
 }

 void report() {
@@ -93,7 +92,7 @@
   return digitalRead(ENABLE);
 }

-void requestEvent(){
+void requestEvent() {
   byte buffer[SONAR_NUM * 2];
   memcpy(ranges, buffer, sizeof(buffer));
   Wire.write(buffer, sizeof(buffer));


implemented white out (violence) mode using button 3

--- super_freq/super_freq.ino
+++ super_freq/super_freq.ino
@@ -238,9 +238,9 @@
     pinMode(button3Pin, INPUT);

     // check for button press to enter LED count set mode
-    button2State = digitalRead(button2Pin);
-
-    if (button2State == HIGH) {
+    button3State = digitalRead(button3Pin);
+
+    if (button3State == HIGH) {
         set_LED_count_mode = true;
     }

@@ -343,26 +343,26 @@
     }
     strip.show();

-    // button 1 may still be pressed since the code gets here very fast
+    // button 3 may still be pressed since the code gets here very fast
     // if button 1 is pressed, wait will the user releases it
-    while (button2State == HIGH) {
+    while (button3State == HIGH) {
         // do nothing, we need to wait until user releases the button
-        button2State = digitalRead(button2Pin);
+        button3State = digitalRead(button3Pin);
     }

     // button 2 is used to exit the LED count set mode
-    while (button3State == LOW) {
+    while (button2State == LOW) {
         button2State = digitalRead(button2Pin);
         button3State = digitalRead(button3Pin);
         increment_LED_count = false;

-        if (button2State == HIGH) {
+        if (button3State == HIGH) {
             increment_LED_count = true;
         }

-        while (button2State == HIGH) {
+        while (button3State == HIGH) {
             // do nothing, we need to wait until user releases the button
-            button2State = digitalRead(button2Pin);
+            button3State = digitalRead(button3Pin);
         }

         if (increment_LED_count) {
@@ -381,6 +381,26 @@
     set_LED_count_mode = false;
 }

+void engageViolence() {
+    if (DEBUG) {
+        Serial.println("Violence mode engaged!");
+    }
+
+    // first ramp up the brightness
+    for (int i=0; i < 128; i++) {
+        strip_color = strip.Color(i, i, i);
+        for (int i=0; i < strip.numPixels(); i++) {
+            strip.setPixelColor(i, strip_color);
+        }
+        strip.show();
+    }
+
+    while (button3State == HIGH) {
+        // do nothing, we hold the violence!
+        button3State = digitalRead(button3Pin);
+    }
+}
+
 void loop() {
     // check for LED count mode
     if (set_LED_count_mode == true) {
@@ -391,13 +411,21 @@
         return;
     }

-    // read color palette input pin here
-    // this line reserved for color palette pin
+    // read pattern engage input pin here
     button2State = digitalRead(button2Pin);

     if (button2State == HIGH) {
-        // pauses the colors
+        // pauses the colors now, but will initialize pattern mode
+        // need to grab the current color
         return;
+    }
+
+    // read white out input pin here
+    button3State = digitalRead(button3Pin);
+
+    if (button3State == HIGH) {
+        // engage violence mode!
+        engageViolence();
     }

     // check if palette changed