Navigation

    • Register
    • Login
    • OpenHardware.io
    • Categories
    • Recent
    • Tags
    • Popular
    1. Home
    2. Eoreh
    • Profile
    • Following
    • Followers
    • Topics
    • Posts
    • Best
    • Groups

    Eoreh

    @Eoreh

    1
    Reputation
    7
    Posts
    391
    Profile views
    0
    Followers
    0
    Following
    Joined Last Online

    Eoreh Follow

    Best posts made by Eoreh

    • RE: Mysensorized Roomba

      Thanks for sharing this. You inspire me and i also made a similar solution during this weekend.😃

      0_1480952640095_upload-333fe90d-3b5d-4329-9c6d-12edbdcaa6f0

      roomba620_mod

      But I have a problem. Maybe you could answer or someone from the forum.
      I can not wake up my vacuum (roomba 620) from the state of "suspension" to whose passes automatically after 5 minutes. (all diodes off). Complete code is on end of post.

      0_1480953181292_upload-2cb7e05b-938a-4d19-b41e-fcb7f25e6327

      From old documentation "Roomba_SCI_Spec_Manual.pdf" wake up should looks like this

      ser.setRTS (0)
      time.sleep (0.1)
      ser.setRTS (1)
      time.sleep (2)
      

      I can do it "hardware". It means when my yellow cabel from "DD" during insertion into arduino pinMode(D3, OUTPUT) ... roomba weak up all times.

      But when cable is connect to D3 permanently and try send few times signals like this.

      	digitalWrite(D3, LOW); delay(10); 
      	digitalWrite(D3, HIGHT); delay(2);
      

      It didnt work.

      Of course it wake up when i push button "clean" by finger. Did you have similar problem ❓
      My full code is little more complicate and right now looks like this:

      
      #define MY_BAUD_RATE 115200
      
      // Enable debug prints to serial monitor
      #define MY_DEBUG
      
      // Enable and select radio type attached
      #define MY_RADIO_NRF24
      //#define MY_RADIO_RFM69
      
      // Enable repeater functionality for this node
      //#define MY_REPEATER_FEATURE
      
      
      #define MY_RF24_CHANNEL	76   // brama - kuchnia 
      
      #define CHILD_ID_BATT_TEMP			100	 // Id of the 2nd msg1_3
      #define CHILD_ID_BATT_PROC			101   // Id of the 2nd msg1_4
      #define CHILD_ID_BATT_VOLT			102   // Id of the 2nd msg1_2
      #define CHILD_ID_BATT_AH			103   // Id of the 2nd msg2_5
      #define CHILD_ID_BATT_CHARGE_TYPE	104   // Id of the 2nd msg1_1
      #define CHILD_ID_BATT_CHARGE_SOURCE 105   // Id of the 2nd msg2_2
      
      
      #include <SoftwareSerial.h>
      #include <MySensors.h>
      
      
      #define NUMBER_OF_FUNCTION 7 
      #define NUMBER_OF_SENSORS 6 
      
      int ddPin = 3;
      int rxPin = 6;
      int txPin = 7;
      
      
      SoftwareSerial roomba(rxPin, txPin);
      
      const char SWITCH_NAMES[NUMBER_OF_FUNCTION][14] = { "Roomba-Stop","Roomba-Dock","Roomba-Clean","Roomba-Spot","Roomba-Max","Roomba-Power","Roomba-Play" };
      const char SENSORS_NAMES[NUMBER_OF_SENSORS][24] = { "Roomba-Batt-Temp","Roomba-Batt-Proc","Roomba-Batt-Volt", "Roomba-Batt-mAH" , "Roomba-Batt-CHt" , "Roomba-Batt-CHs" };
      
      
      
      //for sensorgetting
      
      #define ROOMBA_READ_TIMEOUT 300
      #define ROOMBA_WAKE_COUNT 10
      
      uint8_t buf[52];
      boolean lowBattery = true; // Acts as a debounce
      long battery_Current_mAh = 0;
      long battery_Total_mAh = 0;
      long battery_percent = 0;
      boolean DeadBattery = false;
      boolean FullBattery = true;
      unsigned long chargingState = 0;
      long voltage = 0;
      long temp = 0;
      long OiMode = 0;
      long ChargeSource = 0;
      
      long sensorfrequency = 60000; // frequency the sensors are read
      long lastsensorread = 0; // when were the sensors read the last time
      unsigned long lastsensorssend = 0;
      
      const char ChargeTypes[6][34] = { "Not charging","Reconditioning Charging","Full Charging","Trickle Charging","Waiting","Charging Fault Condition" };
      const char OiTypes[4][14] = { "Off","Passive","Safe","Full" };
      
      int packetSizes[58] = {
      	0,0,0,0,0,0, //1-6
      	1,1,1,1,1,1,1,1,1,1,1,1, //7-18
      	2,2, //19-20
      	1, //21
      	2,2, //22-23
      	1, //24
      	2,2,2,2,2,2,2, //25-31
      	1, //32
      	2, //33
      	1,1,1,1,1, //34-38
      	2,2,2,2,2,2, //39-44
      	1, //45
      	2,2,2,2,2,2, //46-51
      	1,1, //52-53
      	2,2,2,2, //54-57
      	1 //58
      };
      
      // Initialize messages
      
      MyMessage msg1_3(CHILD_ID_BATT_TEMP, V_TEMP); //status of Temperature
      MyMessage msg1_4(CHILD_ID_BATT_PROC, V_PH); //status of Charge [%]
      MyMessage msg1_2(CHILD_ID_BATT_VOLT, V_VOLTAGE); //status of Voltage
      MyMessage msg2_5(CHILD_ID_BATT_AH, V_CURRENT); //status of mAH
      MyMessage msg1_1(CHILD_ID_BATT_CHARGE_TYPE, V_TEXT); //status of charget type
      MyMessage msg2_2(CHILD_ID_BATT_CHARGE_SOURCE, V_TEXT); //status of charger source
      
      void setup() {
      	pinMode(ddPin, OUTPUT);
      	digitalWrite(ddPin, LOW);
      	Serial.begin(115200);
      	while (!Serial) {
      		; // wait for serial port to connect. Needed for native USB port only
      	}
      	roomba.begin(115200);
      	//Serial.println("Sending start command...");
      	//delay(1000);
      	//// set up ROI to receive commands
      	defsongs();
      	delay(500);
      	rstop();
      	Serial.println("Ready to go!");
      }
      
      void presentation()
      {
      	// Send the sketch version information to the gateway and Controller
      	sendSketchInfo("Roomba", "1.2");
      
      	for (int sensor = 0; sensor < NUMBER_OF_FUNCTION; sensor++) {
      		// Register all sensors to gw (they will be created as child devices)
      		present(sensor, S_BINARY, SWITCH_NAMES[sensor]);
      		delay(100);
      	}
      	present(CHILD_ID_BATT_TEMP, S_TEMP, SENSORS_NAMES[0]); delay(100);
      	present(CHILD_ID_BATT_PROC, S_WATER_QUALITY, SENSORS_NAMES[1]); delay(100);
      	present(CHILD_ID_BATT_VOLT, S_MULTIMETER, SENSORS_NAMES[2]);	delay(100);
      	present(CHILD_ID_BATT_AH, S_MULTIMETER, SENSORS_NAMES[3]);	delay(100);
      	present(CHILD_ID_BATT_CHARGE_TYPE, S_INFO, SENSORS_NAMES[4]); delay(100);
      	present(CHILD_ID_BATT_CHARGE_SOURCE, S_INFO, SENSORS_NAMES[5]);	delay(100);
      }
      
      void loop() {
      	unsigned long now = millis();
      	if (now > lastsensorssend + sensorfrequency)
      	{
      		readsensors();
      		lastsensorssend = now;
      	}
      }
      
      void receive(const MyMessage &message) {
      	// We only expect one type of message from controller. But we better check anyway.
      	if (message.type == V_LIGHT) {
      		int mySensor = message.sensor;
      		int myComand = message.getBool();
      
      		//Serial.print(message.sensor);
      
      		if (myComand == 1) {
      			switch (mySensor) {
      			case 0:
      				Serial.println("Stop");
      				rstop();
      				break;
      			case 1:
      				Serial.println("Dock");
      				rcommand(143);
      				break;
      			case 2:
      				Serial.println("Clean");
      				rcommand(135);
      				break;
      			case 3:
      				Serial.println("Spot");
      				rcommand(134);
      				break;
      			case 4:
      				Serial.println("Max");
      				rcommand(136);
      				break;
      			case 5:
      				Serial.println("Power-Off");
      				rcommand(133);
      				break;
      			case 6:
      				Serial.println("Song");
      				rcommand(141);
      				rsong(0);
      				break;
      			}
      		}
      	}
      }
      
      void rstop() {
      	if (rwakeup()) {
      		roomba.write(128);  delay(100);
      		roomba.write(131);	delay(100);
      		roomba.write(137);	delay(100);
      		byte j = 0x00;
      		roomba.write(j); delay(100);
      		roomba.write(j); delay(100);
      		roomba.write(j); delay(100);
      		roomba.write(j); delay(100);
      		roomba.write(128);
      	}
      
      }
      
      void rsong(int b) {
      	roomba.write(b); delay(100);
      }
      
      
      
      void rcommand(int command) {
      	if (rwakeup()) {
      		roomba.write(128);	delay(100);
      		roomba.write(131);	delay(100);
      		roomba.write(command);
      	}
      }
      
      void play(char note, int rlong) {
      	roomba.write(rnote(note));	delay(10);	roomba.write(64 / rlong);	delay(10);
      }
      
      bool rwakeup() {
      	bool ret = getSensors(6, buf, 52);
      	Serial.print("wekup: ");
      	Serial.print(ret);
      	if (!ret) {
      		for (int ii = 1; ii < ROOMBA_WAKE_COUNT; ii++)
      		{
      			for (int jj = 0; jj < 3; jj++) {
      				digitalWrite(ddPin, HIGH); delay(10); 
      				digitalWrite(ddPin, LOW); delay(2);
      			}
      			delay(100);
      			roomba.write(128);
      			if (getSensors(6, buf, 52)) {
      				ret = true;
      				break;
      			}
      			Serial.print("-");
      		}
      	}
      	Serial.println(ret);
      	return ret;
      }
      
      bool getSensors(uint8_t packetID, uint8_t* dest, uint8_t len) {
      	roomba.write(142);
      	delay(100);
      	roomba.write(packetID);
      	delay(100);
      	return getData(dest, len);
      }
      
      
      bool getData(uint8_t* dest, uint8_t len)
      {
      	while (len-- > 0)
      	{
      		unsigned long startTime = millis();
      		while (!roomba.available())
      		{
      			// Look for a timeout
      			if (millis() > startTime + ROOMBA_READ_TIMEOUT)
      				return false; // Timed out
      		}
      		*dest++ = roomba.read();
      	}
      	return true;
      }
      
      //for sensorgetting
      int getPacketSize(int p) {
      	return packetSizes[p - 1];
      }
      int getPacketOffset(int p) {
      	int i = 0;
      	for (int s = 1; s < p; s++) {
      		i += getPacketSize(s);
      	}
      	return i;
      }
      
      //read sensors
      void readsensors()
      {
      
      	if (getSensors(6, buf, 52)) {
      
      		int off = 0;
      
      		// Battery Checks
      		off = getPacketOffset(21);
      		chargingState = buf[off + 0];
      		voltage = buf[off + 2] + 256 * buf[off + 1];
      		temp = buf[off + 5];
      		battery_Current_mAh = buf[off + 7] + 256 * buf[off + 6];
      		battery_Total_mAh = buf[off + 9] + 256 * buf[off + 8];
      
      		if (battery_Total_mAh == 0) battery_Total_mAh = 1;
      		int nBatPcent = battery_Current_mAh * 100 / battery_Total_mAh;
      		battery_percent = nBatPcent;
      
      		//Oi Mode
      		off = getPacketOffset(35);
      		OiMode = buf[off + 0];
      
      		//ChargeSource
      		off = getPacketOffset(34);
      		ChargeSource = buf[off + 0];
      
      
      		send(msg1_3.set(temp));  delay(100);
      		send(msg1_4.set(battery_percent));  delay(100);
      		send(msg1_2.set(round(voltage / 10), 1));  delay(100);
      		send(msg2_5.set(battery_Current_mAh));  delay(100);
      		send(msg1_1.set(ChargeTypes[chargingState]));  delay(100);
      		send(msg2_2.set(ChargeSource));  delay(100);
      
      		//send(msg2_5.set(chargingState));  // Send info value to gw
      		//send(msg2_5.set("charging state"));  // Send info value to gw
      		//send(msg2_5.set(battery_Total_mAh));  // Send info value to gw
      		//send(msg2_1.set(OiTypes[OiMode]));  // Send info value to gw
      		lastsensorread = millis();
      
      	}
      	else { send(msg1_1.set("roomba is off")); }  // Send info value to gw
      }
      
      void defsongs() {
      	uint8_t zero = 0;
      	roomba.write(128);	delay(100);	roomba.write(131);	delay(100);	//[128 131](Start the command stream and change roomba mode to "Safe" mode)
      	roomba.write(140);	delay(100);	roomba.write(zero);	delay(100);	//[140 0](Start song definition and define the first song, song number 0)
      	roomba.write(25);	//[16](16 notes will be sent for song number 0)
      	play('E', 4);		//[76 16](play Mi sound for 1 / 4 seconds) // E
      	play('E', 4);
      	play('E', 2);
      	play('E', 4);
      	play('E', 4);
      	play('E', 2);		//[76 32](play Mi sound for 1 / 2 seconds)
      	play('E', 4);
      	play('G', 4);
      	play('C', 4);
      	play('D', 4);
      	play('E', 1);
      
      	play('F', 4);
      	play('F', 4);
      	play('F', 2);
      
      	play('F', 4);
      	play('E', 4);
      	play('E', 2);
      
      	play('E', 4);
      	play('D', 4);
      	play('D', 4);
      	play('E', 4);
      	play('D', 1);
      	delay(100);
      	roomba.write(128);
      }
      
      int rnote(char note) {
      	int command = 31;
      	switch (note) {
      	case 'C': command = 72; break;
      	case 'D': command = 74; break;
      	case 'E': command = 76; break;
      	case 'F': command = 77; break;
      	case 'G': command = 79; break;
      	}
      	return command;
      }
      
      posted in My Project
      Eoreh
      Eoreh

    Latest posts made by Eoreh

    • RE: Mysensorized Roomba

      HI !.
      @EmielA said:

      With this approach you don't need to put anything on top of the Roomba which wil get broken off (is my experience) when its e.g. working under the bench.

      I have only 1 dock station and many rooms :). My roomba dont going "under the bench" so i dont have experience like yours with sensor on top.

      But will be interested looks for code in your approach so please show it.

      Thank You.

      posted in My Project
      Eoreh
      Eoreh
    • RE: Mysensorized Roomba

      Hi !
      My bad. I type mistake in post on forum. In code is good version. Of course You have right should be "HIGH"

      But You give me some idea on "problem in line D3" . I plugin my logic analizer (Saleae) and bingo!. In my egz. arduino this port was "broken" and dont give any change signal. I plugin into D5 and all works. 😍

      I have one small issue / feature. After play song -> (in my code upper this song is Jingle bell for Chrismas) - roomba dont react on buttons. I think i will change this. Also statistic is very bad write. It's also for rewrite.

      Now i have to do more test, and next make looking good case for "node" on roomba. (cos mother-in-law - kill me 🙂 ). But right now im very happy.

      Thank you @emka for your replay.

      posted in My Project
      Eoreh
      Eoreh
    • RE: Mysensorized Roomba

      Thanks for sharing this. You inspire me and i also made a similar solution during this weekend.😃

      0_1480952640095_upload-333fe90d-3b5d-4329-9c6d-12edbdcaa6f0

      roomba620_mod

      But I have a problem. Maybe you could answer or someone from the forum.
      I can not wake up my vacuum (roomba 620) from the state of "suspension" to whose passes automatically after 5 minutes. (all diodes off). Complete code is on end of post.

      0_1480953181292_upload-2cb7e05b-938a-4d19-b41e-fcb7f25e6327

      From old documentation "Roomba_SCI_Spec_Manual.pdf" wake up should looks like this

      ser.setRTS (0)
      time.sleep (0.1)
      ser.setRTS (1)
      time.sleep (2)
      

      I can do it "hardware". It means when my yellow cabel from "DD" during insertion into arduino pinMode(D3, OUTPUT) ... roomba weak up all times.

      But when cable is connect to D3 permanently and try send few times signals like this.

      	digitalWrite(D3, LOW); delay(10); 
      	digitalWrite(D3, HIGHT); delay(2);
      

      It didnt work.

      Of course it wake up when i push button "clean" by finger. Did you have similar problem ❓
      My full code is little more complicate and right now looks like this:

      
      #define MY_BAUD_RATE 115200
      
      // Enable debug prints to serial monitor
      #define MY_DEBUG
      
      // Enable and select radio type attached
      #define MY_RADIO_NRF24
      //#define MY_RADIO_RFM69
      
      // Enable repeater functionality for this node
      //#define MY_REPEATER_FEATURE
      
      
      #define MY_RF24_CHANNEL	76   // brama - kuchnia 
      
      #define CHILD_ID_BATT_TEMP			100	 // Id of the 2nd msg1_3
      #define CHILD_ID_BATT_PROC			101   // Id of the 2nd msg1_4
      #define CHILD_ID_BATT_VOLT			102   // Id of the 2nd msg1_2
      #define CHILD_ID_BATT_AH			103   // Id of the 2nd msg2_5
      #define CHILD_ID_BATT_CHARGE_TYPE	104   // Id of the 2nd msg1_1
      #define CHILD_ID_BATT_CHARGE_SOURCE 105   // Id of the 2nd msg2_2
      
      
      #include <SoftwareSerial.h>
      #include <MySensors.h>
      
      
      #define NUMBER_OF_FUNCTION 7 
      #define NUMBER_OF_SENSORS 6 
      
      int ddPin = 3;
      int rxPin = 6;
      int txPin = 7;
      
      
      SoftwareSerial roomba(rxPin, txPin);
      
      const char SWITCH_NAMES[NUMBER_OF_FUNCTION][14] = { "Roomba-Stop","Roomba-Dock","Roomba-Clean","Roomba-Spot","Roomba-Max","Roomba-Power","Roomba-Play" };
      const char SENSORS_NAMES[NUMBER_OF_SENSORS][24] = { "Roomba-Batt-Temp","Roomba-Batt-Proc","Roomba-Batt-Volt", "Roomba-Batt-mAH" , "Roomba-Batt-CHt" , "Roomba-Batt-CHs" };
      
      
      
      //for sensorgetting
      
      #define ROOMBA_READ_TIMEOUT 300
      #define ROOMBA_WAKE_COUNT 10
      
      uint8_t buf[52];
      boolean lowBattery = true; // Acts as a debounce
      long battery_Current_mAh = 0;
      long battery_Total_mAh = 0;
      long battery_percent = 0;
      boolean DeadBattery = false;
      boolean FullBattery = true;
      unsigned long chargingState = 0;
      long voltage = 0;
      long temp = 0;
      long OiMode = 0;
      long ChargeSource = 0;
      
      long sensorfrequency = 60000; // frequency the sensors are read
      long lastsensorread = 0; // when were the sensors read the last time
      unsigned long lastsensorssend = 0;
      
      const char ChargeTypes[6][34] = { "Not charging","Reconditioning Charging","Full Charging","Trickle Charging","Waiting","Charging Fault Condition" };
      const char OiTypes[4][14] = { "Off","Passive","Safe","Full" };
      
      int packetSizes[58] = {
      	0,0,0,0,0,0, //1-6
      	1,1,1,1,1,1,1,1,1,1,1,1, //7-18
      	2,2, //19-20
      	1, //21
      	2,2, //22-23
      	1, //24
      	2,2,2,2,2,2,2, //25-31
      	1, //32
      	2, //33
      	1,1,1,1,1, //34-38
      	2,2,2,2,2,2, //39-44
      	1, //45
      	2,2,2,2,2,2, //46-51
      	1,1, //52-53
      	2,2,2,2, //54-57
      	1 //58
      };
      
      // Initialize messages
      
      MyMessage msg1_3(CHILD_ID_BATT_TEMP, V_TEMP); //status of Temperature
      MyMessage msg1_4(CHILD_ID_BATT_PROC, V_PH); //status of Charge [%]
      MyMessage msg1_2(CHILD_ID_BATT_VOLT, V_VOLTAGE); //status of Voltage
      MyMessage msg2_5(CHILD_ID_BATT_AH, V_CURRENT); //status of mAH
      MyMessage msg1_1(CHILD_ID_BATT_CHARGE_TYPE, V_TEXT); //status of charget type
      MyMessage msg2_2(CHILD_ID_BATT_CHARGE_SOURCE, V_TEXT); //status of charger source
      
      void setup() {
      	pinMode(ddPin, OUTPUT);
      	digitalWrite(ddPin, LOW);
      	Serial.begin(115200);
      	while (!Serial) {
      		; // wait for serial port to connect. Needed for native USB port only
      	}
      	roomba.begin(115200);
      	//Serial.println("Sending start command...");
      	//delay(1000);
      	//// set up ROI to receive commands
      	defsongs();
      	delay(500);
      	rstop();
      	Serial.println("Ready to go!");
      }
      
      void presentation()
      {
      	// Send the sketch version information to the gateway and Controller
      	sendSketchInfo("Roomba", "1.2");
      
      	for (int sensor = 0; sensor < NUMBER_OF_FUNCTION; sensor++) {
      		// Register all sensors to gw (they will be created as child devices)
      		present(sensor, S_BINARY, SWITCH_NAMES[sensor]);
      		delay(100);
      	}
      	present(CHILD_ID_BATT_TEMP, S_TEMP, SENSORS_NAMES[0]); delay(100);
      	present(CHILD_ID_BATT_PROC, S_WATER_QUALITY, SENSORS_NAMES[1]); delay(100);
      	present(CHILD_ID_BATT_VOLT, S_MULTIMETER, SENSORS_NAMES[2]);	delay(100);
      	present(CHILD_ID_BATT_AH, S_MULTIMETER, SENSORS_NAMES[3]);	delay(100);
      	present(CHILD_ID_BATT_CHARGE_TYPE, S_INFO, SENSORS_NAMES[4]); delay(100);
      	present(CHILD_ID_BATT_CHARGE_SOURCE, S_INFO, SENSORS_NAMES[5]);	delay(100);
      }
      
      void loop() {
      	unsigned long now = millis();
      	if (now > lastsensorssend + sensorfrequency)
      	{
      		readsensors();
      		lastsensorssend = now;
      	}
      }
      
      void receive(const MyMessage &message) {
      	// We only expect one type of message from controller. But we better check anyway.
      	if (message.type == V_LIGHT) {
      		int mySensor = message.sensor;
      		int myComand = message.getBool();
      
      		//Serial.print(message.sensor);
      
      		if (myComand == 1) {
      			switch (mySensor) {
      			case 0:
      				Serial.println("Stop");
      				rstop();
      				break;
      			case 1:
      				Serial.println("Dock");
      				rcommand(143);
      				break;
      			case 2:
      				Serial.println("Clean");
      				rcommand(135);
      				break;
      			case 3:
      				Serial.println("Spot");
      				rcommand(134);
      				break;
      			case 4:
      				Serial.println("Max");
      				rcommand(136);
      				break;
      			case 5:
      				Serial.println("Power-Off");
      				rcommand(133);
      				break;
      			case 6:
      				Serial.println("Song");
      				rcommand(141);
      				rsong(0);
      				break;
      			}
      		}
      	}
      }
      
      void rstop() {
      	if (rwakeup()) {
      		roomba.write(128);  delay(100);
      		roomba.write(131);	delay(100);
      		roomba.write(137);	delay(100);
      		byte j = 0x00;
      		roomba.write(j); delay(100);
      		roomba.write(j); delay(100);
      		roomba.write(j); delay(100);
      		roomba.write(j); delay(100);
      		roomba.write(128);
      	}
      
      }
      
      void rsong(int b) {
      	roomba.write(b); delay(100);
      }
      
      
      
      void rcommand(int command) {
      	if (rwakeup()) {
      		roomba.write(128);	delay(100);
      		roomba.write(131);	delay(100);
      		roomba.write(command);
      	}
      }
      
      void play(char note, int rlong) {
      	roomba.write(rnote(note));	delay(10);	roomba.write(64 / rlong);	delay(10);
      }
      
      bool rwakeup() {
      	bool ret = getSensors(6, buf, 52);
      	Serial.print("wekup: ");
      	Serial.print(ret);
      	if (!ret) {
      		for (int ii = 1; ii < ROOMBA_WAKE_COUNT; ii++)
      		{
      			for (int jj = 0; jj < 3; jj++) {
      				digitalWrite(ddPin, HIGH); delay(10); 
      				digitalWrite(ddPin, LOW); delay(2);
      			}
      			delay(100);
      			roomba.write(128);
      			if (getSensors(6, buf, 52)) {
      				ret = true;
      				break;
      			}
      			Serial.print("-");
      		}
      	}
      	Serial.println(ret);
      	return ret;
      }
      
      bool getSensors(uint8_t packetID, uint8_t* dest, uint8_t len) {
      	roomba.write(142);
      	delay(100);
      	roomba.write(packetID);
      	delay(100);
      	return getData(dest, len);
      }
      
      
      bool getData(uint8_t* dest, uint8_t len)
      {
      	while (len-- > 0)
      	{
      		unsigned long startTime = millis();
      		while (!roomba.available())
      		{
      			// Look for a timeout
      			if (millis() > startTime + ROOMBA_READ_TIMEOUT)
      				return false; // Timed out
      		}
      		*dest++ = roomba.read();
      	}
      	return true;
      }
      
      //for sensorgetting
      int getPacketSize(int p) {
      	return packetSizes[p - 1];
      }
      int getPacketOffset(int p) {
      	int i = 0;
      	for (int s = 1; s < p; s++) {
      		i += getPacketSize(s);
      	}
      	return i;
      }
      
      //read sensors
      void readsensors()
      {
      
      	if (getSensors(6, buf, 52)) {
      
      		int off = 0;
      
      		// Battery Checks
      		off = getPacketOffset(21);
      		chargingState = buf[off + 0];
      		voltage = buf[off + 2] + 256 * buf[off + 1];
      		temp = buf[off + 5];
      		battery_Current_mAh = buf[off + 7] + 256 * buf[off + 6];
      		battery_Total_mAh = buf[off + 9] + 256 * buf[off + 8];
      
      		if (battery_Total_mAh == 0) battery_Total_mAh = 1;
      		int nBatPcent = battery_Current_mAh * 100 / battery_Total_mAh;
      		battery_percent = nBatPcent;
      
      		//Oi Mode
      		off = getPacketOffset(35);
      		OiMode = buf[off + 0];
      
      		//ChargeSource
      		off = getPacketOffset(34);
      		ChargeSource = buf[off + 0];
      
      
      		send(msg1_3.set(temp));  delay(100);
      		send(msg1_4.set(battery_percent));  delay(100);
      		send(msg1_2.set(round(voltage / 10), 1));  delay(100);
      		send(msg2_5.set(battery_Current_mAh));  delay(100);
      		send(msg1_1.set(ChargeTypes[chargingState]));  delay(100);
      		send(msg2_2.set(ChargeSource));  delay(100);
      
      		//send(msg2_5.set(chargingState));  // Send info value to gw
      		//send(msg2_5.set("charging state"));  // Send info value to gw
      		//send(msg2_5.set(battery_Total_mAh));  // Send info value to gw
      		//send(msg2_1.set(OiTypes[OiMode]));  // Send info value to gw
      		lastsensorread = millis();
      
      	}
      	else { send(msg1_1.set("roomba is off")); }  // Send info value to gw
      }
      
      void defsongs() {
      	uint8_t zero = 0;
      	roomba.write(128);	delay(100);	roomba.write(131);	delay(100);	//[128 131](Start the command stream and change roomba mode to "Safe" mode)
      	roomba.write(140);	delay(100);	roomba.write(zero);	delay(100);	//[140 0](Start song definition and define the first song, song number 0)
      	roomba.write(25);	//[16](16 notes will be sent for song number 0)
      	play('E', 4);		//[76 16](play Mi sound for 1 / 4 seconds) // E
      	play('E', 4);
      	play('E', 2);
      	play('E', 4);
      	play('E', 4);
      	play('E', 2);		//[76 32](play Mi sound for 1 / 2 seconds)
      	play('E', 4);
      	play('G', 4);
      	play('C', 4);
      	play('D', 4);
      	play('E', 1);
      
      	play('F', 4);
      	play('F', 4);
      	play('F', 2);
      
      	play('F', 4);
      	play('E', 4);
      	play('E', 2);
      
      	play('E', 4);
      	play('D', 4);
      	play('D', 4);
      	play('E', 4);
      	play('D', 1);
      	delay(100);
      	roomba.write(128);
      }
      
      int rnote(char note) {
      	int command = 31;
      	switch (note) {
      	case 'C': command = 72; break;
      	case 'D': command = 74; break;
      	case 'E': command = 76; break;
      	case 'F': command = 77; break;
      	case 'G': command = 79; break;
      	}
      	return command;
      }
      
      posted in My Project
      Eoreh
      Eoreh
    • RE: gw.request() and domoticz - problem with get V_DISTANCE

      .. after some tests. If Im not wrong only few messages / variables - is support by gw.request() and domoticz.
      I used sketch belowe to tests, and i found only supports for:

      • S_LIGHT / V_LIGHT
      • S_DIMMER / V_DIMMER
      • S_BINARY / V_LIGHT
      • S_BINARY / V_STATUS

      My check list is in this sketch for tests in section comments

      #include <SPI.h>
      #include <MySensor.h>  
      #include <EEPROM.h>  
      
      /*  list of checked types /variables */
      
      /* supported by domoticz and gw.request -> type/variable:
      	S_LIGHT / V_LIGHT 
      	S_DIMMER / V_DIMMER 
      	S_BINARY / V_LIGHT
      	S_BINARY / V_STATUS
      */
      /* NOT supported by domoticz and gw.request -> type/variable:
      	S_DOOR / V_TRIPPED
      	S_MOTION / V_TRIPPED
      	S_DISTANCE / V_DISTANCE 
      	S_TEMP / V_TEMP 
      	S_BINARY / V_WATT
      	S_HUM / V_HUM
      	S_WIND / V_WIND
      	S_POWER / V_KWH
      */
      
      #define CHILD_ID 1                  // Id of the sensor child
      
      #define S_type   S_LIGHT      // here change type 
      #define V_type   V_LIGHT   		// here change variable 
      
      int clearEEPROM = 1;				// if required reset memory change for 1 
      
      MySensor gw;
      MyMessage msg(CHILD_ID, V_type);
      unsigned long SEND_FREQUENCY = 1000;  // 1 sec = 1000;
      
      void setup()
      {
      	if (clearEEPROM == 1) {
      		Serial.println("Reset EEPROM");
      		ClearEEPROM();
      		clearEEPROM = 0;
      	}
      
      	gw.begin(incomingMessage);
      	gw.sendSketchInfo("Test", "1.1");
      	gw.present(CHILD_ID, S_type);
      }
      
      void loop()
      {
      	gw.process();
      	gw.request(CHILD_ID, V_type, 0);
      	gw.wait(1000);
      	gw.send(msg.set(0));
      	gw.wait(1000);
      	gw.sleep(SEND_FREQUENCY);
      }
      
      void incomingMessage(const MyMessage &message) {
      	if (message.type == V_type) {
      		Serial.println("Received from gw ");
      	}
      	Serial.println("incomingMessage");
      }
      
      void ClearEEPROM()
      {
      	Serial.println("Clearing EEPROM");
      	for (int i = 0;i<512;i++) {
      		EEPROM.write(i, 0xff);
      	}
      	Serial.println("Cleared EEPROM");
      }
      
      
      posted in Troubleshooting
      Eoreh
      Eoreh
    • RE: gw.request() and domoticz - problem with get V_DISTANCE

      Hi !.
      Sure next sketch I will use. But the problem looks like it is elsewhere.
      I found that if i change in this sketch

      • S_DISTANCE -> S_LIGHT
      • V_DISTANCE -> V_LIGHT

      its works ! 😃 Maybe just this type (V_DISTANCE) is not supported in Domoticz and gw.request() (?)

      So now I will start a little more test. I'm going to check other types.

      posted in Troubleshooting
      Eoreh
      Eoreh
    • RE: gw.request() and domoticz - problem with get V_DISTANCE

      Thx for quick answer Hek !.
      I comment this line

      	//gw.sleep(SEND_FREQUENCY);
      

      upload sketch by still no have log from "V_DISTANCE". Any other idea ?

      posted in Troubleshooting
      Eoreh
      Eoreh
    • gw.request() and domoticz - problem with get V_DISTANCE

      Hey !
      I have a problem with receiving from the controller Domoticz (V2.3799) the V_DISTANCE by gw.request()
      MySensors is 1.5 - Latest Release.

      I wrote a short test program that shows a problem.

      #include <SPI.h>
      #include <MySensor.h>  
      
      #define CHILD_ID 1                              // Id of the sensor child
      MySensor gw;
      MyMessage msg(CHILD_ID, V_DISTANCE);
      MyMessage msg2(CHILD_ID, V_VAR1);
      unsigned long SEND_FREQUENCY = 3000;  // 1 sekunda = 1000;
      
      void setup()
      {
      	gw.begin(incomingMessage);
      	gw.sendSketchInfo("Test", "1.1");
      	gw.present(CHILD_ID, S_DISTANCE);
      }
      
      void loop()
      {
      	gw.process();
      	gw.request(CHILD_ID, V_DISTANCE, 0);
      	gw.request(CHILD_ID, V_VAR1, 0);
      		delay(2000);
      			gw.send(msg.set(0));
      		delay(2000);
      			gw.send(msg2.set(1));
      		delay(2000);
      	gw.sleep(SEND_FREQUENCY);
      }
      
      void incomingMessage(const MyMessage &message) {
      	if (message.type == V_VAR1) {
      		Serial.println("Received V_VAR1 from gw ");
      	}
      	if (message.type == V_DISTANCE) {
      	Serial.println("Received V_DISTANCE from gw ");
      	}
      	Serial.println("incomingMessage");
      }
      

      I do not know why I get message for V_VAR1 and didnt get for V_DISTANCE. ?
      And short LOG from my node here:

      Opening port
      Port open
      find parent
      send: 255-255-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,st=bc:
      read: 0-0-255 s=255,c=3,t=8,pt=1,l=1,sg=0:0
      parent=0, d=1
      req id
      send: 255-255-0-0 s=255,c=3,t=3,pt=0,l=0,sg=0,st=ok:
      read: 0-0-255 s=255,c=3,t=4,pt=0,l=2,sg=0:20
      send: 20-20-0-0 s=255,c=0,t=17,pt=0,l=3,sg=0,st=fail:1.5
      send: 20-20-0-0 s=255,c=3,t=6,pt=1,l=1,sg=0,st=ok:0
      read: 0-0-20 s=255,c=3,t=6,pt=0,l=1,sg=0:M
      id=20
      send: 20-20-0-0 s=255,c=0,t=17,pt=0,l=3,sg=0,st=ok:1.5
      send: 20-20-0-0 s=255,c=3,t=6,pt=1,l=1,sg=0,st=ok:0
      read: 0-0-20 s=255,c=3,t=6,pt=0,l=1,sg=0:M
      sensor started, id=20, parent=0, distance=1
      send: 20-20-0-0 s=255,c=3,t=11,pt=0,l=4,sg=0,st=ok:Test
      send: 20-20-0-0 s=255,c=3,t=12,pt=0,l=3,sg=0,st=ok:1.1
      send: 20-20-0-0 s=1,c=0,t=15,pt=0,l=0,sg=0,st=ok:
      send: 20-20-0-0 s=1,c=2,t=13,pt=0,l=0,sg=0,st=ok:
      send: 20-20-0-0 s=1,c=2,t=24,pt=0,l=0,sg=0,st=ok:
      send: 20-20-0-0 s=1,c=1,t=13,pt=2,l=2,sg=0,st=ok:0
      send: 20-20-0-0 s=1,c=1,t=24,pt=2,l=2,sg=0,st=ok:1
      read: 0-0-20 s=1,c=2,t=24,pt=0,l=0,sg=0:
      Received V_VAR1 from gw
      incomingMessage
      send: 20-20-0-0 s=1,c=2,t=13,pt=0,l=0,sg=0,st=ok:
      send: 20-20-0-0 s=1,c=2,t=24,pt=0,l=0,sg=0,st=ok:
      send: 20-20-0-0 s=1,c=1,t=13,pt=2,l=2,sg=0,st=ok:0
      send: 20-20-0-0 s=1,c=1,t=24,pt=2,l=2,sg=0,st=ok:1
      read: 0-0-20 s=1,c=2,t=24,pt=0,l=1,sg=0:1
      Received V_VAR1 from gw 
      incomingMessage
      send: 20-20-0-0 s=1,c=2,t=13,pt=0,l=0,sg=0,st=ok:
      send: 20-20-0-0 s=1,c=2,t=24,pt=0,l=0,sg=0,st=ok:
      send: 20-20-0-0 s=1,c=1,t=13,pt=2,l=2,sg=0,st=ok:0
      send: 20-20-0-0 s=1,c=1,t=24,pt=2,l=2,sg=0,st=ok:1
      
      Port closed
      

      I dont know why i get only message for V_VAR1 and I didnt get for V_DISTANCE. ?

      posted in Troubleshooting
      Eoreh
      Eoreh