Posts made by zen85
-
RE: mysbootloader with MY_SIGINING_SIMPLE_PASSWD
@anticimex
i thought so since using #define MY_ENCRYPTION_SIMPLE_PASSWD does not do any of the signing stuff but still works fine. it seems way simpler. i just hoped that would solve my issue... i tried messing with the bootloader but i did not get anywhere so far. -
RE: mysbootloader with MY_SIGINING_SIMPLE_PASSWD
can someone tell me if
#define MY_ENCRYPTION_SIMPLE_PASSWD "mypassword" would work with mysbootloader? -
RE: irq pin for nrf24l01
so if i use an esp8266 as gateway AND i want to use the bufferfeature - to which pin do i have to actually connect the irq on the esp8266? The documentation is not helping me here.
-
RE: mysbootloader with MY_SIGINING_SIMPLE_PASSWD
@mfalkvidd said in mysbootloader with MY_SIGINING_SIMPLE_PASSWD:
@zen85 MySensors is open source. Anything is possible, if someone builds it
i am thinking about digging into this since this is the only thing missing i would love seeing. i really want the network secured with a password to be safe. i guess the main limitation is the size of the bootloader and therefor it has to be extremly clever... am i right?
or are there other options i am not thinking about to make my network a bit secure?
-
RE: mysbootloader with MY_SIGINING_SIMPLE_PASSWD
@tekka
thanks for the answer... is the term 'currently' an indicator that this might change anytime? i would love to be able to do fota and have at least basic security.... -
RE: RF Nano = Nano + NRF24, for just $3,50 on Aliexpress
@torfinn
i had to set
#define MY_RF24_CE_PIN 10
#define MY_RF24_CS_PIN 9
on mine (definetly not + btw) a while back.... -
mysbootloader with MY_SIGINING_SIMPLE_PASSWD
i do not find any information on where and how to set the MY_SIGINING_SIMPLE_PASSWD in the bootloader so i can compile one that works with this feature. the docs just say it is able to do signing since 1.3 - but i guess setting a password would now work for firmware updates for example?
-
RE: mysbootloader not working with nano? [solved]
@tekka
EDITED ANSWER*: it worked!- it did not work because of a typo... sorry for that....
-
RE: mysbootloader not working with nano? [solved]
ok... some success but not really. The bootloader does not seem to work using my custom-boards where the ce and cs pin are switched? where does one have to put something like:
#define RF24_CE_PIN 10
#define RF24_CS_PIN 9
?should it be in the mysbootloader.c? because this did not work... or somewhere else?
the line "#define SPI_PINS_CE9_CSN10" in the mysbootloader.c also worries me? but just switching the numbers does not work either and throws an error...
-
RE: mysbootloader not working with nano? [solved]
ok... i once again report back to my own entry since i became a little smarter.
i found out 2 things:
- in the boards.txt i have to set the right fuse-settings. for the 16mhz nano i used:
MYSBL.menu.frequency.MYSBL16.bootloader.low_fuses=0xFF MYSBL.menu.frequency.MYSBL16.bootloader.high_fuses=0xDA MYSBL.menu.frequency.MYSBL16.bootloader.extended_fuses=0xFD
- i used a screw-terminal board where the ce and cs pins are switched. in the usual sketch i define
// Set custom pins for Nano-Radio-Board #define MY_RF24_CE_PIN 10 #define MY_RF24_CS_PIN 9
i am sure the mysbootloader needs to know that too... so am i right that i have to compile a new bootloader where i have to put:
#define RF24_CE_PIN 10
#define RF24_CS_PIN 9
?i am really having a hard time compiling one since i have zero experience with that and eclipse doesn't seem of much help here. so if anybody can confirm this before i go through this fruitless struggle again i would be very glad...
-
RE: [solved] I_REBOOT crashes arduino while I_PRESENT does work as expected?
as soon as i burned a new bootloader it worked. watchdog does not like old bootloader and since mysensors is using that for rebooting it fixed my issue.
-
mysbootloader not working with nano? [solved]
Hello,
did anybody successfully get mysbootloader for fota get to work on a nano? i burned the bootloader via an uno (arduino as isp)... everything seemed to work fine...
but nothing changes actually - the log on myscontroller says nothing about a new bootloader whenever i try to click the node > settings > Board with mysbootloader i see the functions. when i click anything like "reassign ID" it just reboots with the old ID - when i try to load a new sketch via "assign firmware" it is the same. it just reboots and nothing changed.
i tried different gateways (rpi and nodemcu), i tried different mysbootloaders with different channels from the github repository, ... it seems to be the same everytime...
did anybody run into the same issues or has a hint - i tried now for 2 days without progress...
-
RE: [solved] I_REBOOT crashes arduino while I_PRESENT does work as expected?
I just found out that using watchdog do reboot also does the same to the arduino (it is a nano and more people seem to have the problem specifically on nanos) ... so i guess mysensors has nothing to do with my problem. i probably need a new bootloader...
-
[solved] I_REBOOT crashes arduino while I_PRESENT does work as expected?
In MYScontroller i can send I_PRESENT and request a heartbeat to a node and i get the expected results... When i send I_REBOOT on the other hand the arduino starts blinking like crazy and the powersource needs to be removed before it works normally again. just pressing the reset button also does not work.
the last serial output before "dying" is:
20518 TSF:MSG:READ,0-0-188,s=0,c=3,t=16,pt=0,l=0,sg=1: 20533 TSF:MSG:SEND,188-188-0-0,s=255,c=3,t=17,pt=6,l=25,sg=1,ft=0,st=OK:<NONCE> 20674 TSF:MSG:READ,0-0-188,s=0,c=3,t=13,pt=0,l=1,sg=1:0
so i also have burned mysbootloader and the following things in the header:
#define MY_RF24_CHANNEL 100 // In EU the default channel 76 overlaps with wifi, so you could try using channel 100. You will have to select the same setting on every device in the network (including the gateway). #define MY_OTA_FIRMWARE_FEATURE // Mysensors: security #define MY_SECURITY_SIMPLE_PASSWD "******" // Be aware that longer passwords use slightly more memory. #define MY_SIGNING_SOFT_RANDOMSEED_PIN A7 // Setting a pin to pickup random electromagnetic noise helps make encryption more secure. #define MY_RF24_PA_LEVEL RF24_PA_MAX // Offers the most range, but high power can cause issues on cheap Chinese NRF24 radios
the node has no sleep, delay, wait command either...
does anybody have an idea what this could be?
-
RE: Trouble with nodes going offline after a while
hey. i was having the same problems from time to time - i found out that its mostly wiring - therefor i am a great fan of easypcb and other boards that let one mount the radio directly.
and also mounting a fan on my gateway (rpi3b) helped a lot with that. other than that repeaternodes...also install myscontroller - makes debugging way nicer and more efficient because you see in realtime whats going on... you might not have just one problem but more at the same time.
-
RE: Home Assistant MySensors Notify problem
@ddevilliers said in Home Assistant MySensors Notify problem:
Note Home Assistant do receive values from the sensors. I just cant get HA to send a text value to the sensors as per the HA example.
Thank you.did you ever find out? i am having the same issue here.
-
RE: (homeassistant) mysensors.notify does nothing, (alternatives?)
sorry for spamming my own thread... i just want to keep updates coming in while debugging... i got it to the point where the homeassistant log tells me: "Unable to find service notify/mysensors".
but apparently there is no known solution to do this. i even unplugged and restarted everything. i am hitting a dead end here...
-
RE: (homeassistant) mysensors.notify does nothing, (alternatives?)
let me ask differently again:
did anybody get this:
https://www.home-assistant.io/components/notify.mysensors/to work? i find no useful example and have the suspicion that it just doesnt work anymore since all the forumentries seem old and outdated?
-
RE: (homeassistant) mysensors.notify does nothing, (alternatives?)
or does anybody have an alternative?
i just want to send a V_TEXT to a node via the dashboard.
-
(homeassistant) mysensors.notify does nothing, (alternatives?)
I cant get mysensors.notify to work...
in my configuration.yaml i put this:
input_boolean: baum_fx_twinkle: name: Twinkle initial: off
and in my automations.yaml i have this.
- alias: 'send scene to map' trigger: platform: state entity_id: input_boolean.baum_fx_twinkle to: 'on' action: service: notify.mysensors data: message: twinkle target: 'lalelu 111 2'
it works when i use MYSController with type c_set, subtype V_TEXT settings. but whenever i try to press the switch it does nothing... also there is nothing logged in MYSController.
Same when i try to use the call-service-page in my homeassistant backend... just nothing - not even an error...does anyone have an idea? I checked for correct IDs and everything and in MYSController it definetly works... but homeassistant is very reluctant to do anything...
-
RE: NUM_LEDS value in LED-Strip Sketch can not be more than "201"?
@mfalkvidd
i will definetly do that within the next days. -
RE: NUM_LEDS value in LED-Strip Sketch can not be more than "201"?
its exactly as you guys say. taking a mega solves my issue and thats fine. i work with arduinos for many years now but its the first time i ran out of storage so i did not have this on the radar. i also learned much about arduinos with that issue. i guess thats a huge thanks for steering me into the right direction.
-
RE: NUM_LEDS value in LED-Strip Sketch can not be more than "201"?
oke.... apparently the storage for variables was too low on the nano.
i replaced it with a mega and now it works.
-
RE: NUM_LEDS value in LED-Strip Sketch can not be more than "201"?
@zen85 said in NUM_LEDS value in LED-Strip Sketch can not be more than "201"?:
@electrik
its indeed strange.
i am using 2.3.1 - so this should be ok.... i replaced delay(wait) with wait(wait) which throws:
"'wait' cannot be used as a function"my nano uses the "atmega328p (Old Bootloader)" as processor... could that be an issue but i dont see how...?
ok... i see why wait(wait) was a problem... i displaced the variable "wait" with another one and then it compiles... but it has no impact on the issue.
i also checked out the limit again... it actually works up to 207 leds... more than that and it breaks...
-
RE: NUM_LEDS value in LED-Strip Sketch can not be more than "201"?
@electrik
its indeed strange.
i am using 2.3.1 - so this should be ok.... i replaced delay(wait) with wait(wait) which throws:
"'wait' cannot be used as a function"my nano uses the "atmega328p (Old Bootloader)" as processor... could that be an issue but i dont see how...?
-
RE: NUM_LEDS value in LED-Strip Sketch can not be more than "201"?
i also tried to change it into long but there is no change in behaviour...
-
RE: NUM_LEDS value in LED-Strip Sketch can not be more than "201"?
actually i am using a nano.
it tells me:
Sketch uses 18372 bytes (59%) of program storage space. Maximum is 30720 bytes. Global variables use 1070 bytes (52%) of dynamic memory, leaving 978 bytes for local variables. Maximum is 2048 bytes.
but there is no warning...
using wait(...) instead of delay(...) just gives me "wait can not be used as a function arduino" and nothing compiles... did you mean millis(...)?
-
RE: NUM_LEDS value in LED-Strip Sketch can not be more than "201"?
first i had the same thought. so i tried adding the flames to another really simple mysensors-relaysketch which have nothing to do with each other and the same thing happens... values over 201 brake the flames entirely as long as there is a mysensors-radio running. i tried with that code:
#include <Adafruit_NeoPixel.h> #define PIN 2 #define NUM_LEDS 350 // Parameter 1 = number of pixels in strip // Parameter 2 = pin number (most are valid) // Parameter 3 = pixel type flags, add together as needed: // NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) // NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) // NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) // NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRBW + NEO_KHZ800); /** * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each * repeater and gateway builds a routing tables in EEPROM which keeps track of the * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad <henrik.ekblad@mysensors.org> * Copyright (C) 2013-2015 Sensnology AB * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * version 2 as published by the Free Software Foundation. * ******************************* * * REVISION HISTORY * Version 1.0 - Henrik Ekblad * * DESCRIPTION * Example sketch showing how to control physical relays. * This example will remember relay state after power failure. * http://www.mysensors.org/build/relay * * * * Only sends a quick pulse via a reed relay. Useful to hack other devices with push * buttons. In my case, a cheap IKEA dishwasher that didn't have a timer. */ // security //#define MY_SIGNING_SIMPLE_PASSWD "changeme" //#define MY_ENCRYPTION_SIMPLE_PASSWD "changeme" //#define MY_RF24_DATARATE RF24_250KBPS // Slower datarate offers more range. Only the + version of the radio supports 250kbps //#define MY_RF24_DATARATE RF24_1MBPS //#define MY_RF24_DATARATE RF24_2MBPS #define MY_RF24_CE_PIN 10 #define MY_RF24_CS_PIN 9 // Enable debug prints to serial monitor #define MY_DEBUG #define MY_NODE_ID 76 // Enable and select radio type attached #define MY_RADIO_RF24 //#define MY_RADIO_RFM69 //#define MY_RS485 //#define MY_RF24_CE_PIN 49 //#define MY_RF24_CS_PIN 53 //#define MY_RF24_PA_LEVEL RF24_PA_MIN #define MY_RF24_PA_LEVEL RF24_PA_LOW // Enable repeater functionality for this node //#define MY_REPEATER_FEATURE #include <MySensors.h> // MySensors children #define DEVICE_STATUS_ID 0 // The first 'child' of this device is a text field that contains status updates. #define RELAY_1_CHILD_ID 1 // MySensors child ID #define DONE_CHILD_ID 2 // MySensors child ID #define RELAY_1_PIN 4 // Arduino Digital I/O pin number for first relay (second on pin+1 etc) #define NUMBER_OF_RELAYS 1 // Total number of attached relays #define RELAY_ON 1 // GPIO value to write to turn on attached relay #define RELAY_OFF 0 // GPIO value to write to turn off attached relay #define PULSELENGTH 500 // How long the pulse should last (how long the button should be pressed). #define LOOPDURATION 600000 #define ON_TOO_LONG 9 // If it's been on for X * 10 minutes, then it should send a message. #define RADIO_DELAY 150 // Keeps the bad Chinese radio happy / supplied with stable power. byte loopCounter = 0; boolean state = 0; byte retryCounter = 3; MyMessage charmsg(DEVICE_STATUS_ID, V_TEXT); // Sets up the message format that we'll be sending to the MySensors gateway later. The first part is the ID of the specific sensor module on this node. The second part tells the gateway what kind of data to expect. MyMessage relaymsg(RELAY_1_CHILD_ID, V_STATUS); MyMessage donemsg(DONE_CHILD_ID, V_TRIPPED); void before() { //for (int pin=0; pin < NUMBER_OF_RELAYS; pin++) { // Then set relay pins in output mode // pinMode(pin + RELAY_1_PIN, OUTPUT); // Set relay to last known state (using eeprom storage) // digitalWrite(pin, LOW); //} pinMode(RELAY_1_PIN, OUTPUT); // Set relay to last known state (using eeprom storage) digitalWrite(RELAY_1_PIN, LOW); } void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo(F("stepperzeug"), F("1.1")); wait(RADIO_DELAY); present(DEVICE_STATUS_ID, S_INFO, F("Status")); wait(RADIO_DELAY); present(RELAY_1_CHILD_ID, S_BINARY, F("Start")); wait(RADIO_DELAY); present(DONE_CHILD_ID, S_MOTION, F("Done?")); wait(RADIO_DELAY); //send(relaymsg.setSensor(RELAY_1_CHILD_ID).set( RELAY_OFF )); wait(200); //for (int i=0; i<NUMBER_OF_RELAYS; i++) { // Register all sensors to gw (they will be created as child devices) //present(sensor, S_BINARY, F("Start")); wait(100); //send(relaymsg.setSensor(RELAY_1).set( RELAY_OFF )); wait(100); //} } void setup() { wait(1000); Serial.begin(115200); Serial.println(F("Hello world, I am a dish washer.")); strip.begin(); strip.show(); // Initialize all pixels to 'off' if(isTransportReady()){ Serial.println(F("Connected to gateway")); send(charmsg.setSensor(DEVICE_STATUS_ID).set( F("Dishwasher turned on"))); wait(RADIO_DELAY); send(relaymsg.set(state?false:true), true); wait(RADIO_DELAY); // Send new state and request ack back send(donemsg.setSensor(DONE_CHILD_ID).set(0)); wait(RADIO_DELAY); }else{ Serial.println(F("Not connected to gateway")); } } void loop() { Fire(-500,15,0); } /* void messageRepeat(MyMessage &message, bool ack = true) { int repeat = 1; int repeats = 10; int repeatdelay = 0; boolean sendOK = false; Serial.print("Sending message of child "); Serial.println(message.sensor); while ((sendOK == false) and (repeat < repeats)) { if (send(message, ack)) { sendOK = true; Serial.print("Send OK"); } else { sendOK = false; Serial.print("Send ERROR "); Serial.print(repeat); repeatdelay += RADIO_DELAY; } if (ack == true) { Serial.println(" With ack "); } else { Serial.println(" Without ack "); } repeat++; wait(repeatdelay); } } */ void receive(const MyMessage &message) { // We only expect one type of message from controller. But we better check anyway. Serial.print("Incoming message for child: "); Serial.println(message.sensor); if (message.isAck() && message.sensor == RELAY_1_CHILD_ID) { // We got the ACK! Serial.println("- Received ACK for relay"); retryCounter = 0; } else{ // Change relay state Serial.println("-Gateway wants to change relay position"); if (message.type==V_STATUS) { Serial.print ("-Received V_status:"); Serial.println(message.getBool()); if( message.sensor == RELAY_1_CHILD_ID ){ boolean desiredState = message.getBool()?RELAY_ON:RELAY_OFF; if(desiredState == RELAY_ON){ //digitalWrite(message.sensor-1+RELAY_1_PIN, RELAY_ON); //wait(PULSELENGTH); //digitalWrite(message.sensor-1+RELAY_1_PIN, RELAY_OFF); Serial.print ("-Switching relay on..."); digitalWrite(RELAY_1_PIN, RELAY_ON); //wait(PULSELENGTH); //Serial.println ("Switching relay off."); //digitalWrite(RELAY_1_PIN, RELAY_OFF); send(relaymsg.set(RELAY_ON), true); wait(RADIO_DELAY); //retryCounter = 3; } if(desiredState == RELAY_OFF){ //digitalWrite(message.sensor-1+RELAY_1_PIN, RELAY_ON); //wait(PULSELENGTH); //digitalWrite(message.sensor-1+RELAY_1_PIN, RELAY_OFF); //Serial.print ("-Switching relay on..."); //digitalWrite(RELAY_1_PIN, RELAY_ON); //wait(PULSELENGTH); Serial.println ("Switching relay off."); digitalWrite(RELAY_1_PIN, RELAY_OFF); send(relaymsg.set(RELAY_OFF), true); wait(RADIO_DELAY); //retryCounter = 3; } } //digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF); // Store state in eeprom saveState(message.sensor, message.getBool()); // Write some debug info } } } void Fire(int Cooling, int Sparking, int SpeedDelay) { static byte heat[NUM_LEDS]; int cooldown; // Step 1. Cool down every cell a little for( int i = 0; i < NUM_LEDS; i++) { cooldown = random(0, ((Cooling * 10) / NUM_LEDS) + 2); if(cooldown>heat[i]) { heat[i]=0; } else { heat[i]=heat[i]-cooldown; } } // Step 2. Heat from each cell drifts 'up' and diffuses a little for( int k= NUM_LEDS - 1; k >= 2; k--) { heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2]) / 3; } // Step 3. Randomly ignite new 'sparks' near the bottom if( random(255) < Sparking ) { int y = random(7); heat[y] = heat[y] + random(160,255); //heat[y] = random(160,255); } // Step 4. Convert heat to LED colors for( int j = 0; j < NUM_LEDS; j++) { setPixelHeatColor(j, heat[j] ); } showStrip(); delay(SpeedDelay); } void setPixelHeatColor (int Pixel, byte temperature) { // Scale 'heat' down from 0-255 to 0-191 byte t192 = round((temperature/255.0)*150); // calculate ramp up from byte heatramp = t192 & 0x3F; // 0..63 heatramp <<= 0; // scale up to 0..252 // figure out which third of the spectrum we're in: if( t192 > 0x80) { // hottest setPixel(Pixel, 255, 255, heatramp); } else if( t192 > 0x40 ) { // middle setPixel(Pixel, 255, heatramp, 0); } else { // coolest setPixel(Pixel, heatramp, 0, 0); } } // *** REPLACE TO HERE *** void showStrip() { #ifdef ADAFRUIT_NEOPIXEL_H // NeoPixel strip.show(); #endif #ifndef ADAFRUIT_NEOPIXEL_H // FastLED FastLED.show(); #endif } void setPixel(int Pixel, byte red, byte green, byte blue) { #ifdef ADAFRUIT_NEOPIXEL_H // NeoPixel strip.setPixelColor(Pixel, strip.Color(red, green, blue)); #endif #ifndef ADAFRUIT_NEOPIXEL_H // FastLED leds[Pixel].r = red; leds[Pixel].g = green; leds[Pixel].b = blue; #endif } void setAll(byte red, byte green, byte blue) { for(int i = 0; i < NUM_LEDS; i++ ) { setPixel(i, red, green, blue); } showStrip(); }
whereas:
#include <Adafruit_NeoPixel.h> #define PIN 2 #define NUM_LEDS 350 // Parameter 1 = number of pixels in strip // Parameter 2 = pin number (most are valid) // Parameter 3 = pixel type flags, add together as needed: // NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) // NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) // NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) // NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRBW + NEO_KHZ800); void setup() { strip.begin(); strip.show(); // Initialize all pixels to 'off' } // *** REPLACE FROM HERE *** void loop() { Fire(-500,15,0); } void Fire(int Cooling, int Sparking, int SpeedDelay) { static byte heat[NUM_LEDS]; int cooldown; // Step 1. Cool down every cell a little for( int i = 0; i < NUM_LEDS; i++) { cooldown = random(0, ((Cooling * 10) / NUM_LEDS) + 2); if(cooldown>heat[i]) { heat[i]=0; } else { heat[i]=heat[i]-cooldown; } } // Step 2. Heat from each cell drifts 'up' and diffuses a little for( int k= NUM_LEDS - 1; k >= 2; k--) { heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2]) / 3; } // Step 3. Randomly ignite new 'sparks' near the bottom if( random(255) < Sparking ) { int y = random(7); heat[y] = heat[y] + random(160,255); //heat[y] = random(160,255); } // Step 4. Convert heat to LED colors for( int j = 0; j < NUM_LEDS; j++) { setPixelHeatColor(j, heat[j] ); } showStrip(); delay(SpeedDelay); } void setPixelHeatColor (int Pixel, byte temperature) { // Scale 'heat' down from 0-255 to 0-191 byte t192 = round((temperature/255.0)*150); // calculate ramp up from byte heatramp = t192 & 0x3F; // 0..63 heatramp <<= 0; // scale up to 0..252 // figure out which third of the spectrum we're in: if( t192 > 0x80) { // hottest setPixel(Pixel, 255, 255, heatramp); } else if( t192 > 0x40 ) { // middle setPixel(Pixel, 255, heatramp, 0); } else { // coolest setPixel(Pixel, heatramp, 0, 0); } } // *** REPLACE TO HERE *** void showStrip() { #ifdef ADAFRUIT_NEOPIXEL_H // NeoPixel strip.show(); #endif #ifndef ADAFRUIT_NEOPIXEL_H // FastLED FastLED.show(); #endif } void setPixel(int Pixel, byte red, byte green, byte blue) { #ifdef ADAFRUIT_NEOPIXEL_H // NeoPixel strip.setPixelColor(Pixel, strip.Color(red, green, blue)); #endif #ifndef ADAFRUIT_NEOPIXEL_H // FastLED leds[Pixel].r = red; leds[Pixel].g = green; leds[Pixel].b = blue; #endif } void setAll(byte red, byte green, byte blue) { for(int i = 0; i < NUM_LEDS; i++ ) { setPixel(i, red, green, blue); } showStrip(); }
works perfectly fine....
its really strange.
-
NUM_LEDS value in LED-Strip Sketch can not be more than "201"?
Hello,
I am having a strange phenomenon here... I made a sketch for mysensors which works perfectly fine. Its a Flameeffekt where you can set the flameheight and intensity with the dimmer (lower value = more and highter flames). Its quite cool and works fine...
/* * Example Dimmable Light * Code adapted from http://github.com/mysensors/MySensors/tree/master/examples/DimmableLight * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org * */ // Enable debug prints #define MY_DEBUG // Enable and select radio type attached #define MY_NODE_ID 129 #define MY_RADIO_RF24 //#define MY_RADIO_RFM69 #define MY_RF24_CE_PIN 10 #define MY_RF24_CS_PIN 9 #include <MySensors.h> #define CHILD_ID 2 #define LIGHT_OFF 0 #define LIGHT_ON 1 #define SN "Baum" #define SV "1.0" /* int16_t last_state = LIGHT_ON; int16_t last_dim = 100; MyMessage light_msg( CHILD_ID_LIGHT, V_STATUS ); MyMessage dimmer_msg( CHILD_ID_LIGHT, V_PERCENTAGE ); */ int16_t last_state = LIGHT_OFF; int16_t last_dim = 100; char rgb[7] = "00ff00"; // RGB value. int currentLevel = 0; // Current dimmer level. int red = 100; int green = 100; int blue = 100; MyMessage dimmerMsg(CHILD_ID, V_PERCENTAGE); MyMessage lightMsg(CHILD_ID, V_STATUS); MyMessage rgbMsg(CHILD_ID, V_RGB); #include <Adafruit_NeoPixel.h> #ifdef __AVR__ #include <avr/power.h> #endif #define NUM_LEDS 200 #define PIN 2 Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRBW + NEO_KHZ800); int yada = 255; uint32_t magenta_ada = strip.Color(200, 0, 200); uint32_t red_ada = strip.Color(200, 0, 0); uint32_t black_ada = strip.Color(0, 0, 0); void setup() { //update_light(); Serial.println( "Blutmond - Digitalled Node ready to receive messages..." ); strip.begin(); strip.Color(55, 0, 33); strip.setBrightness(100); //strip.fill(black_ada); //strip.show(); // Initialize all pixels to 'off' } void loop() { //In MySensors2.x, first message must come from within loop() static bool first_message_sent = false; if ( first_message_sent == false ) { Serial.println( "Sending initial state..." ); send_dimmer_message(); send_status_message(); send_rgb_message(); first_message_sent = true; } int yadacooling = 255/100 * last_dim; int yadasparkling = 255/100 * (100 - last_dim); int yadaspeed = 120/100 * last_dim; Fire(yadacooling,yadasparkling,yadaspeed); } void presentation() { // Send the sketch version information to the gateway sendSketchInfo( SN, SV ); present( CHILD_ID, S_RGB_LIGHT ); } void receive(const MyMessage &message) { if (message.type == V_RGB) { // Retrieve the RGB value from the incoming message. // RGB LED not implemented, just a dummy print. String hexstring = message.getString(); hexstring.toCharArray(rgb, sizeof(rgb)); Serial.print("Changing color to "); Serial.println(rgb); //getRGB(rgb); String rgb2 = rgb; Serial.println(rgb2); rgb2.toUpperCase(); char c[7]; rgb2.toCharArray(c, 8); red = hexcolorToInt(c[0], c[1]); green = hexcolorToInt(c[2], c[3]); blue = hexcolorToInt(c[4], c[5]); Serial.print("REED: "); Serial.println(red); Serial.print("green: "); Serial.println(green); Serial.print("blue: "); Serial.println(blue); update_light(); send_rgb_message(); } //When receiving a V_STATUS command, switch the light between OFF //and the last received dimmer value if ( message.type == V_STATUS ) { Serial.println( "V_STATUS command received..." ); int lstate = message.getInt(); if (( lstate < 0 ) || ( lstate > 1 )) { Serial.println( "V_STATUS data invalid (should be 0/1)" ); return; } last_state = lstate; //If last dimmer state is zero, set dimmer to 100 if (( last_state == LIGHT_ON ) && ( last_dim == 0 )) { last_dim=100; } //Update constroller status send_status_message(); } else if ( message.type == V_PERCENTAGE ) { Serial.println( "V_PERCENTAGE command received..." ); int dim_value = constrain( message.getInt(), 0, 100 ); if ( dim_value == 0 ) { last_state = LIGHT_OFF; //Update constroller with dimmer value & status send_dimmer_message(); send_status_message(); } else { last_state = LIGHT_ON; last_dim = dim_value; Serial.println(red); Serial.println(last_dim); int dimmerval = last_dim; //red = red /100 * dimmerval; //green = green /100 * dimmerval; //blue = blue /100 * dimmerval; Serial.println(red); Serial.println(dimmerval); //Driver.begin(); // begin //Driver.SetColor(red, green, blue); //Red. first node data //Driver.SetColor(red, green, blue); //Blue. second node data //Driver.end(); //Update constroller with dimmer value send_dimmer_message(); } } else { Serial.println( "Invalid command received..." ); return; } //Here you set the actual light state/level update_light(); } void update_light() { //For this example, just print the light status to console. if ( last_state == LIGHT_OFF ) { Serial.println( "Light state: OFF" ); // colorWipe(strip.Color(0, 0, 0), 0); // Red //Driver.begin(); // begin //Driver.SetColor(0, 0, 0); //Red. first node data //Driver.SetColor(0, 0, 0); //Blue. second node data //Driver.end(); } else { Serial.print( "Light state: ON, Level: " ); Serial.println( last_dim ); int reddim = red /100 * last_dim; int greendim = green /100 * last_dim; int bluedim = blue /100 * last_dim; //colorWipe(strip.Color(red, green, blue), 2); // Red int yada = NUM_LEDS * last_dim / 100; ; Serial.print("yadavalue: " ); Serial.println (yada); int pixelfiller = NUM_LEDS - yada ; Serial.print("pixelfiller: "); Serial.println (pixelfiller); //strip.fill(red_ada, 0, yada); //strip.fill(black_ada, yada, pixelfiller); //strip.show(); //Driver.begin(); // begin //Driver.SetColor(reddim, greendim, bluedim); //Red. first node data //Driver.SetColor(reddim, greendim, bluedim); //Red. first node data //Driver.end(); } } void send_rgb_message() { send( rgbMsg.set(rgb)); } void send_dimmer_message() { send( dimmerMsg.set( last_dim ) ); } void send_status_message() { if ( last_state == LIGHT_OFF ) { send( lightMsg.set( (int16_t)0) ); } else { send( lightMsg.set( (int16_t)1) ); } } void getRGB(String hexvalue) { hexvalue.toUpperCase(); char c[7]; hexvalue.toCharArray(c, 8); int red = hexcolorToInt(c[1], c[2]); int green = hexcolorToInt(c[3], c[4]); int blue = hexcolorToInt(c[5], c[6]); Serial.print("REED: "); Serial.println(red); Serial.print("green: "); Serial.println(green); Serial.print("blue: "); Serial.println(blue); return red + green + blue; } int hexcolorToInt(char upper, char lower) { int uVal = (int)upper; int lVal = (int)lower; uVal = uVal > 64 ? uVal - 55 : uVal - 48; uVal = uVal << 4; lVal = lVal > 64 ? lVal - 55 : lVal - 48; // Serial.println(uVal+lVal); return uVal + lVal; } // Fill the dots one after the other with a color void colorWipe(uint32_t c, uint8_t wait) { for(uint16_t i=0; i<strip.numPixels(); i++) { strip.setPixelColor(i, c); strip.show(); delay(wait); } } void Fire(int Cooling, int Sparking, int SpeedDelay) { static byte heat[NUM_LEDS]; int cooldown; // Step 1. Cool down every cell a little for( int i = 0; i < NUM_LEDS; i++) { cooldown = random(0, ((Cooling * 10) / NUM_LEDS) + 2); if(cooldown>heat[i]) { heat[i]=0; } else { heat[i]=heat[i]-cooldown; } } // Step 2. Heat from each cell drifts 'up' and diffuses a little for( int k= NUM_LEDS - 1; k >= 2; k--) { heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2]) / 3; } // Step 3. Randomly ignite new 'sparks' near the bottom if( random(255) < Sparking ) { int y = random(7); heat[y] = heat[y] + random(160,255); //heat[y] = random(160,255); } // Step 4. Convert heat to LED colors for( int j = 0; j < NUM_LEDS; j++) { setPixelHeatColor(j, heat[j] ); } showStrip(); delay(SpeedDelay); } void setPixelHeatColor (int Pixel, byte temperature) { // Scale 'heat' down from 0-255 to 0-191 byte t192 = round((temperature/255.0)*191); // calculate ramp up from byte heatramp = t192 & 0x3F; // 0..63 heatramp <<= 2; // scale up to 0..252 // figure out which third of the spectrum we're in: if( t192 > 0x80) { // hottest setPixel(Pixel, 255, 255, heatramp); } else if( t192 > 0x40 ) { // middle setPixel(Pixel, 255, heatramp, 0); } else { // coolest setPixel(Pixel, heatramp, 0, 0); } } /* void Fire(int Cooling, int Sparking, int SpeedDelay) { static byte heat[NUM_LEDS]; int cooldown; // Step 1. Cool down every cell a little for( int i = 0; i < NUM_LEDS; i++) { cooldown = random(0, ((Cooling * 10) / NUM_LEDS) + 2); if(cooldown>heat[i]) { heat[i]=0; } else { heat[i]=heat[i]-cooldown; } } // Step 2. Heat from each cell drifts 'up' and diffuses a little for( int k= NUM_LEDS - 1; k >= 2; k--) { heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2]) / 3; } // Step 3. Randomly ignite new 'sparks' near the bottom if( random(255) < Sparking ) { int y = random(7); heat[y] = heat[y] + random(160,255); //heat[y] = random(160,255); } // Step 4. Convert heat to LED colors for( int j = 0; j < NUM_LEDS; j++) { setPixelHeatColor(j, heat[j] ); } showStrip(); delay(SpeedDelay); } void setPixelHeatColor (int Pixel, byte temperature) { // Scale 'heat' down from 0-255 to 0-191 byte t192 = round((temperature/255.0)*191); // calculate ramp up from byte heatramp = t192 & 0x3F; // 0..63 heatramp <<= 2; // scale up to 0..252 // figure out which third of the spectrum we're in: if( t192 > 0x80) { // hottest setPixel(Pixel, 255, 255, heatramp); } else if( t192 > 0x40 ) { // middle setPixel(Pixel, 255, heatramp, 0); } else { // coolest setPixel(Pixel, heatramp, 0, 0); } } */ void showStrip() { #ifdef ADAFRUIT_NEOPIXEL_H // NeoPixel strip.show(); #endif #ifndef ADAFRUIT_NEOPIXEL_H // FastLED FastLED.show(); #endif } void setPixel(int Pixel, byte red, byte green, byte blue) { #ifdef ADAFRUIT_NEOPIXEL_H // NeoPixel strip.setPixelColor(Pixel, strip.Color(red, green, blue)); #endif #ifndef ADAFRUIT_NEOPIXEL_H // FastLED leds[Pixel].r = red; leds[Pixel].g = green; leds[Pixel].b = blue; #endif } void setAll(byte red, byte green, byte blue) { for(int i = 0; i < NUM_LEDS; i++ ) { setPixel(i, red, green, blue); } showStrip(); }
what is weird is that if i set the value of the NUM_LEDS to more than 201 it stops working. the flames just dont work anymore eventhough mysensors works fine. If it just take the part of the LEDs and exclude mysensors it works perfectly fine again with higher values like 350...
#include <Adafruit_NeoPixel.h> #define PIN 2 #define NUM_LEDS 350 // Parameter 1 = number of pixels in strip // Parameter 2 = pin number (most are valid) // Parameter 3 = pixel type flags, add together as needed: // NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) // NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) // NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) // NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRBW + NEO_KHZ800); /** * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each * repeater and gateway builds a routing tables in EEPROM which keeps track of the * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad <henrik.ekblad@mysensors.org> * Copyright (C) 2013-2015 Sensnology AB * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * version 2 as published by the Free Software Foundation. * ******************************* * * REVISION HISTORY * Version 1.0 - Henrik Ekblad * * DESCRIPTION * Example sketch showing how to control physical relays. * This example will remember relay state after power failure. * http://www.mysensors.org/build/relay * * * * Only sends a quick pulse via a reed relay. Useful to hack other devices with push * buttons. In my case, a cheap IKEA dishwasher that didn't have a timer. */ // security //#define MY_SIGNING_SIMPLE_PASSWD "changeme" //#define MY_ENCRYPTION_SIMPLE_PASSWD "changeme" //#define MY_RF24_DATARATE RF24_250KBPS // Slower datarate offers more range. Only the + version of the radio supports 250kbps //#define MY_RF24_DATARATE RF24_1MBPS //#define MY_RF24_DATARATE RF24_2MBPS #define MY_RF24_CE_PIN 10 #define MY_RF24_CS_PIN 9 // Enable debug prints to serial monitor #define MY_DEBUG #define MY_NODE_ID 76 // Enable and select radio type attached #define MY_RADIO_RF24 //#define MY_RADIO_RFM69 //#define MY_RS485 //#define MY_RF24_CE_PIN 49 //#define MY_RF24_CS_PIN 53 //#define MY_RF24_PA_LEVEL RF24_PA_MIN #define MY_RF24_PA_LEVEL RF24_PA_LOW // Enable repeater functionality for this node //#define MY_REPEATER_FEATURE #include <MySensors.h> // MySensors children #define DEVICE_STATUS_ID 0 // The first 'child' of this device is a text field that contains status updates. #define RELAY_1_CHILD_ID 1 // MySensors child ID #define DONE_CHILD_ID 2 // MySensors child ID #define RELAY_1_PIN 4 // Arduino Digital I/O pin number for first relay (second on pin+1 etc) #define NUMBER_OF_RELAYS 1 // Total number of attached relays #define RELAY_ON 1 // GPIO value to write to turn on attached relay #define RELAY_OFF 0 // GPIO value to write to turn off attached relay #define PULSELENGTH 500 // How long the pulse should last (how long the button should be pressed). #define LOOPDURATION 600000 #define ON_TOO_LONG 9 // If it's been on for X * 10 minutes, then it should send a message. #define RADIO_DELAY 150 // Keeps the bad Chinese radio happy / supplied with stable power. byte loopCounter = 0; boolean state = 0; byte retryCounter = 3; MyMessage charmsg(DEVICE_STATUS_ID, V_TEXT); // Sets up the message format that we'll be sending to the MySensors gateway later. The first part is the ID of the specific sensor module on this node. The second part tells the gateway what kind of data to expect. MyMessage relaymsg(RELAY_1_CHILD_ID, V_STATUS); MyMessage donemsg(DONE_CHILD_ID, V_TRIPPED); void before() { //for (int pin=0; pin < NUMBER_OF_RELAYS; pin++) { // Then set relay pins in output mode // pinMode(pin + RELAY_1_PIN, OUTPUT); // Set relay to last known state (using eeprom storage) // digitalWrite(pin, LOW); //} pinMode(RELAY_1_PIN, OUTPUT); // Set relay to last known state (using eeprom storage) digitalWrite(RELAY_1_PIN, LOW); } void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo(F("stepperzeug"), F("1.1")); wait(RADIO_DELAY); present(DEVICE_STATUS_ID, S_INFO, F("Status")); wait(RADIO_DELAY); present(RELAY_1_CHILD_ID, S_BINARY, F("Start")); wait(RADIO_DELAY); present(DONE_CHILD_ID, S_MOTION, F("Done?")); wait(RADIO_DELAY); //send(relaymsg.setSensor(RELAY_1_CHILD_ID).set( RELAY_OFF )); wait(200); //for (int i=0; i<NUMBER_OF_RELAYS; i++) { // Register all sensors to gw (they will be created as child devices) //present(sensor, S_BINARY, F("Start")); wait(100); //send(relaymsg.setSensor(RELAY_1).set( RELAY_OFF )); wait(100); //} } void setup() { wait(1000); Serial.begin(115200); Serial.println(F("Hello world, I am a dish washer.")); strip.begin(); strip.show(); // Initialize all pixels to 'off' if(isTransportReady()){ Serial.println(F("Connected to gateway")); send(charmsg.setSensor(DEVICE_STATUS_ID).set( F("Dishwasher turned on"))); wait(RADIO_DELAY); send(relaymsg.set(state?false:true), true); wait(RADIO_DELAY); // Send new state and request ack back send(donemsg.setSensor(DONE_CHILD_ID).set(0)); wait(RADIO_DELAY); }else{ Serial.println(F("Not connected to gateway")); } } void loop() { Fire(-500,15,0); } /* void messageRepeat(MyMessage &message, bool ack = true) { int repeat = 1; int repeats = 10; int repeatdelay = 0; boolean sendOK = false; Serial.print("Sending message of child "); Serial.println(message.sensor); while ((sendOK == false) and (repeat < repeats)) { if (send(message, ack)) { sendOK = true; Serial.print("Send OK"); } else { sendOK = false; Serial.print("Send ERROR "); Serial.print(repeat); repeatdelay += RADIO_DELAY; } if (ack == true) { Serial.println(" With ack "); } else { Serial.println(" Without ack "); } repeat++; wait(repeatdelay); } } */ void receive(const MyMessage &message) { // We only expect one type of message from controller. But we better check anyway. Serial.print("Incoming message for child: "); Serial.println(message.sensor); if (message.isAck() && message.sensor == RELAY_1_CHILD_ID) { // We got the ACK! Serial.println("- Received ACK for relay"); retryCounter = 0; } else{ // Change relay state Serial.println("-Gateway wants to change relay position"); if (message.type==V_STATUS) { Serial.print ("-Received V_status:"); Serial.println(message.getBool()); if( message.sensor == RELAY_1_CHILD_ID ){ boolean desiredState = message.getBool()?RELAY_ON:RELAY_OFF; if(desiredState == RELAY_ON){ //digitalWrite(message.sensor-1+RELAY_1_PIN, RELAY_ON); //wait(PULSELENGTH); //digitalWrite(message.sensor-1+RELAY_1_PIN, RELAY_OFF); Serial.print ("-Switching relay on..."); digitalWrite(RELAY_1_PIN, RELAY_ON); //wait(PULSELENGTH); //Serial.println ("Switching relay off."); //digitalWrite(RELAY_1_PIN, RELAY_OFF); send(relaymsg.set(RELAY_ON), true); wait(RADIO_DELAY); //retryCounter = 3; } if(desiredState == RELAY_OFF){ //digitalWrite(message.sensor-1+RELAY_1_PIN, RELAY_ON); //wait(PULSELENGTH); //digitalWrite(message.sensor-1+RELAY_1_PIN, RELAY_OFF); //Serial.print ("-Switching relay on..."); //digitalWrite(RELAY_1_PIN, RELAY_ON); //wait(PULSELENGTH); Serial.println ("Switching relay off."); digitalWrite(RELAY_1_PIN, RELAY_OFF); send(relaymsg.set(RELAY_OFF), true); wait(RADIO_DELAY); //retryCounter = 3; } } //digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF); // Store state in eeprom saveState(message.sensor, message.getBool()); // Write some debug info } } } void Fire(int Cooling, int Sparking, int SpeedDelay) { static byte heat[NUM_LEDS]; int cooldown; // Step 1. Cool down every cell a little for( int i = 0; i < NUM_LEDS; i++) { cooldown = random(0, ((Cooling * 10) / NUM_LEDS) + 2); if(cooldown>heat[i]) { heat[i]=0; } else { heat[i]=heat[i]-cooldown; } } // Step 2. Heat from each cell drifts 'up' and diffuses a little for( int k= NUM_LEDS - 1; k >= 2; k--) { heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2]) / 3; } // Step 3. Randomly ignite new 'sparks' near the bottom if( random(255) < Sparking ) { int y = random(7); heat[y] = heat[y] + random(160,255); //heat[y] = random(160,255); } // Step 4. Convert heat to LED colors for( int j = 0; j < NUM_LEDS; j++) { setPixelHeatColor(j, heat[j] ); } showStrip(); delay(SpeedDelay); } void setPixelHeatColor (int Pixel, byte temperature) { // Scale 'heat' down from 0-255 to 0-191 byte t192 = round((temperature/255.0)*150); // calculate ramp up from byte heatramp = t192 & 0x3F; // 0..63 heatramp <<= 0; // scale up to 0..252 // figure out which third of the spectrum we're in: if( t192 > 0x80) { // hottest setPixel(Pixel, 255, 255, heatramp); } else if( t192 > 0x40 ) { // middle setPixel(Pixel, 255, heatramp, 0); } else { // coolest setPixel(Pixel, heatramp, 0, 0); } } // *** REPLACE TO HERE *** void showStrip() { #ifdef ADAFRUIT_NEOPIXEL_H // NeoPixel strip.show(); #endif #ifndef ADAFRUIT_NEOPIXEL_H // FastLED FastLED.show(); #endif } void setPixel(int Pixel, byte red, byte green, byte blue) { #ifdef ADAFRUIT_NEOPIXEL_H // NeoPixel strip.setPixelColor(Pixel, strip.Color(red, green, blue)); #endif #ifndef ADAFRUIT_NEOPIXEL_H // FastLED leds[Pixel].r = red; leds[Pixel].g = green; leds[Pixel].b = blue; #endif } void setAll(byte red, byte green, byte blue) { for(int i = 0; i < NUM_LEDS; i++ ) { setPixel(i, red, green, blue); } showStrip(); }
just adding mysensors makes it weird. I tried everything but nothing works so far. does anybody have an idea?
-
RE: Mysensorized Roomba
// 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 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 <MySensors.h> #include <SoftwareSerial.h> //#define RELAY_1 5 // Arduino Digital I/O pin number for first relay (second on pin+1 etc) //#define NUMBER_OF_RELAYS 2 // Total number of attached relays //#define RELAY_ON 1 // GPIO value to write to turn on attached relay //#define RELAY_OFF 0 // GPIO value to write to turn off attached relay #define NUMBER_OF_FUNCTION 7 #define NUMBER_OF_SENSORS 6 #define ROOMBA_READ_TIMEOUT 300 #define ROOMBA_WAKE_COUNT 10 int ddPin = 6; int rxPin = 3; int txPin = 4; int ledPin = 13; 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" }; 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 = 300000; // 300000 = 5 min - 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 }; #define bumpright (sensorbytes[0] & 0x01) #define bumpleft (sensorbytes[0] & 0x02) 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-1+RELAY_1); if (mySensor == 0) { if (myComand == 1) { Serial.println("Clean"); //clean(); rcommand(135); } else { Serial.println("Stopp1"); //halt(); rstop(); } } if (mySensor == 1) { if (myComand == 1) { Serial.println("dock"); //dock(); rcommand(143); } else { Serial.println("Stopp2"); //halt(); rstop(); } } if (mySensor == 2) { if (myComand == 1) { Serial.println("song"); //dock(); rcommand(141); rsong(0); } else { Serial.println("Stopp2"); //halt(); rstop(); } } } } void halt() { ; roomba.write(131); // SAFE byte j = 0x00; roomba.write(137); roomba.write(j); roomba.write(j); roomba.write(j); roomba.write(j); } void dock() { delay(1000); roomba.write(143); } void clean() { delay(1000); roomba.write(135); } 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("wakeup: "); 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; }
i love this project. i am the owner of a roomba 620 and hooked it up to a arduino-mega. putting "clean()" in the code does what it should and the radiomodules are working fine. but it seems that i dont get values from the sensors and so nothing is showing up in homeassistant...
i checked the wiring about 5 times already and since starting for example "clean()" works i think it is a different issue...
did anyone else try this and ran into the same problem?