Navigation

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

    Topics created by karl261

    • karl261

      Node / sketch with Dallas and Relay starts behaving weird after one day
      Troubleshooting • • karl261  

      5
      0
      Votes
      5
      Posts
      1045
      Views

      karl261

      How would you do this?Like this? I tried to move it to the setup function. This is also a version I found using non blocking (millis()) code. // if you uncomment this, you can get test and debug updates about everything the sensor is doing by using the serial monitor tool. //#define MY_DEBUG // Enable and select radio type attached #define MY_RADIO_NRF24 // A 2.4Ghz transmitter and receiver, often used with MySensors. // #define MY_RF24_PA_LEVEL RF24_PA_MIN // This sets a low-power mode for the radio. Useful if you use the verison with the bigger antenna, but don't want to power that from a separate power source. It can also fix problems with fake Chinese versions of the radio. // #define MY_RADIO_RFM69 // 433Mhz transmitter and reveiver. // Choose if you want this sensor to also be a repeater. // #define MY_REPEATER_FEATURE // Just remove the two slashes at the beginning of this line to also enable this sensor to act as a repeater for other sensors. If this node is on battery power, you probably shouldn't enable this. // Are you using this sensor on battery power? // #define BATTERY_POWERED // Just remove the two slashes at the beginning of this line if your node is battery powered. It will then go into deep sleep as much as possible. While it's sleeping it can't work as a repeater! //#define MY_RF24_PA_LEVEL RF24_PA_LOW #define MY_PARENT_NODE_ID 99 #define MY_PARENT_NODE_IS_STATIC #define MY_NODE_ID 8 #define MY_BAUD_RATE 9600 // LIBRARIES (in the Arduino IDE go to Sketch -> Include Library -> Manage Libraries to add these if you don't have them installed yet.) #include <SPI.h> #include <MySensors.h> #include <DallasTemperature.h> #include <OneWire.h> #define RELAY_1 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 //Added this nteger to avoid stupid collect2.exe: error: ld returned 5 exit status. //It seems adding one or removing one (or plenty) solves the error. //int stupidinteger=0; //int stupidintegertwo=0; //int stupidintegerthree=0; // VARIABLES YOU CAN CHANGE #define COMPARE_TEMP 1 // Send temperature only if changed? 1 = Yes 0 = No. Can save battery. #define ONE_WIRE_BUS 7 // Digital pin where Dallas sensor(s) is/are connected. #define maxAttachedDS18B20 16 // Maximum amount of teperature sensors you can connect to this arduino (16). const long measurementInterval = 10000; // Time to wait between reads (in milliseconds). float tempThreshold = 0.1; // How big a temperature difference has to be before an update is sent. Makes the sensor less precise, but also less jittery, and can save battery. //VARIABLES YOU PROBABLY SHOULDN'T CHANGE #define TEMP_CHILD_ID 0 // for MySensors. Within this node each sensortype should have its own ID number. OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs) DallasTemperature sensors(&oneWire); // Pass the oneWire reference to Dallas Temperature. float lastTemperature[maxAttachedDS18B20]; // creates an array to hold the previous temperature measurements for each possible sensor. int numSensors = 0; // variable to contain the number of found attached sensors. unsigned long measurementSleepTime = 0; // variable to store the calculated Sleep time if the node is battery powered. bool metric = true; // Variable that stores if the sensor will output the temperature in Fahrenheit of Celsius. The gateway sends this preference to the node. bool receivedConfig = false; // This is not used in the code, but perhaps MySensors requires this? // Mysensors settings MyMessage msg(TEMP_CHILD_ID,V_TEMP); // Sets up the message format that we'l 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. void before() { sensors.begin(); // Startup up the OneWire library. It allows multiple sensors to talk over one wire (one pin). for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS; sensor++, pin++) { // Then set relay pins in output mode pinMode(pin, OUTPUT); // Set relay to last known state (using eeprom storage) digitalWrite(pin, loadState(sensor)?RELAY_ON:RELAY_OFF); } } void setup() { metric = getControllerConfig().isMetric; for(int i=0; i<maxAttachedDS18B20; i++) { lastTemperature[i] = 0; //Pre-filling array with 0's. } sensors.setWaitForConversion(false); // requestTemperatures() will not block current thread #ifdef BATTERY_POWERED // If the node is batter ypowered, we'll let Sleep take over the scheduling. measurementSleepTime = measurementInterval; measurementInterval = 0; // When the Arduino is asleep, millis doesn't increment anymore (time stops as it were). To fix this, we'll set the measurement interval time to 1, so that when the arduino wakes up it will immediately try to measure again. #endif //Serial.begin(115200); // for serial debugging. //Serial.println("Hello world, I am a sensor node."); } void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo("Maischen relay and Dallas non blocking", "1.0"); for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS; sensor++, pin++) { // Register all sensors to gw (they will be created as child devices) present(sensor, S_BINARY); } numSensors = sensors.getDeviceCount(); // Fetch the number of attached temperature sensors for (int i=0; i<numSensors && i<maxAttachedDS18B20; i++) { present(i, S_TEMP); } } void loop() { // You should not change these variables: static boolean dallasIsMeasuring = true; // Used to indicate when the time is right for a new measurement to be made. static boolean dallasIsCalculating = false; // Used to bridge the time that is needed to calculate the temperature values by the Dallas library. unsigned long currentMillis = 0; // The millisecond clock in the main loop. static unsigned long previousMeasurementMillis = 0; // Used to remember the time of the last temperature measurement. static int16_t conversionTime = 0; // Used to store the time needed to calculate the temperature from measurements. currentMillis = millis(); // The time since the sensor started, counted in milliseconds. This script tries to avoid using the Sleep function, so that it could at the same time be a MySensors repeater. // Let's measure the temperature if(dallasIsMeasuring == true && currentMillis - previousMeasurementMillis >= measurementInterval) { // If we're not calculating, and enough time has passed, we'll start again. dallasIsMeasuring = false; // We're measuring, so let's take it off our to-do list. //Serial.println("Starting new measurement(s)"); previousMeasurementMillis = currentMillis; // Mark the time of the initialiation of this measurement. // Fetch temperatures from Dallas sensors sensors.requestTemperatures(); // query conversion time. Apparently it takes a while to calculate. //conversionTime = sensors.millisToWaitForConversion(sensors.getResolution()); conversionTime = millisToWaitForConversion(sensors.getResolution()); // This is a modified version of the line above, to deal with the problem in the current Dallas library. dallasIsCalculating = true; //Next step is to re-calculate the temperature again. } // Next, let's calculate and send the temperature if(dallasIsCalculating == true && currentMillis - conversionTime > previousMeasurementMillis) { dallasIsCalculating = false; // We're doing this now, so check calculating off the to-do list too. for (int i=0; i<numSensors && i<maxAttachedDS18B20; i++){ // Loop through all the attached temperature sensors. //float temperature = getControllerConfig().isMetric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i); // Fetch the temperature form the current sensor float temperature = static_cast<float>(static_cast<int>((metric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i)) * 10.)) / 10.; //Serial.print("Sensor #"); //Serial.print(i); //Serial.print(" says it is "); //Serial.print(temperature); //Serial.println(" degrees"); if(temperature != -127.00 && temperature != 85.00) { // Avoids working with measurement errors. if (COMPARE_TEMP == 1 && abs(temperature - lastTemperature[i]) < tempThreshold) { // is the temperature difference bigger than the threshold? //Serial.print(temperature - lastTemperature[i]); //Serial.print("- difference too small, so not sending the new measurement to the gateway.\n"); } else { //Serial.print(temperature - lastTemperature[i]); //Serial.print("Sending the new temperature to the gateway.\n"); send(msg.setSensor(i).set(temperature,1)); lastTemperature[i] = temperature; // Save new temperatures to be able to compare in the next round. } } } // Both tasks are done. Time to wait until we should measure again. //Serial.print("zzzzZZZZzzzzZZZZzzzz\n"); #ifdef BATTERY_POWERED unsigned long quicktimecheck = millis(); // check how much time has passed during the measurement (can be up to 750 milliseconds), and then calculate from that how long to sleep until the next intended measuring time. unsigned long sleeptime = measurementSleepTime - (quicktimecheck - previousMeasurementMillis); //How much time has passed already during the calculating? Subtract that from the intended interval time. sleep (sleeptime); #endif dallasIsMeasuring = true; } } // This function helps to avoid a problem with the latest Dallas temperature library. int16_t millisToWaitForConversion(uint8_t bitResolution) { switch (bitResolution) { case 9: return 94; case 10: return 188; case 11: return 375; default: return 750; } } void receive(const MyMessage &message) { // We only expect one type of message from controller. But we better check anyway. if (message.type==V_STATUS) { // Change relay state 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 //Serial.print("Incoming change for sensor:"); //Serial.print(message.sensor); //Serial.print(", New status: "); //Serial.println(message.getBool()); } }
    • karl261

      Raspberry uninteruptable power suppy
      Hardware • • karl261  

      17
      0
      Votes
      17
      Posts
      4365
      Views

      karl261

      My UPS is working fine now for the past several months. My current setup is like this: AC -- Power suppply power bank -- power bank -- supercaps -- voltage regulator 5V -- raspi. The supercaps are needd because when the powerbank switches there is a short power interruption. The supercaps are buffering this. The 5V voltage regulator is needed, because when the power bank is charging and discharging at the same time its output voltage drops to 4.6 V or so. The voltage regulator keeps this at 5 V at all times.
    • karl261

      BME280 How to use it outdoors
      Hardware • • karl261  

      36
      0
      Votes
      36
      Posts
      29552
      Views

      Nca78

      @parachutesj thank you for the link I never noticed those before.
    • karl261

      Battery sensor and re-connecting to gateway
      Troubleshooting • • karl261  

      24
      0
      Votes
      24
      Posts
      6289
      Views

      tekka

      @Mark-Swift Almost #define MY_TRANSPORT_WAIT_READY_MS 60000 applies only when the node starts, i.e. before entering loop(). Once you are in loop() and you put the node to sleep #define MY_SLEEP_TRANSPORT_RECONNECT_TIMEOUT_MS 10000 defines how long the node will try to establish a connection before going to sleep, default is 10s. Please have a look here for additional information.
    • karl261

      Node is not using repeater to talk to gateway
      Troubleshooting • • karl261  

      42
      0
      Votes
      42
      Posts
      7866
      Views

      karl261

      @karl261 said: @tekka But now I found something: the repeater sketch does not work, if MY_DEBUG is commented out. I tried several times forth and back. On the gw I get the output below. I checked and re-programmed the repeater. It seems that it has gone away. I can use my repeater without MY_DEBUG. I don't know what caused this, but the repeater is working now.
    • karl261

      How to properly debug Serial Gateway nRF24L01+ ?
      Troubleshooting • • karl261  

      4
      0
      Votes
      4
      Posts
      4285
      Views

      karl261

      @hek Thanks a lot! That really helped. Finally had time to look into it. So for other people I will try to write down what I did. I tested this for one of my sensors. I am using Mysensors 1.5 master branch. MyTransportNRF24: I commented out the "private:" to make the rf24 function public. RF24_config.h: I commented out the "#define MINIMAL" to make some more functions available in RF24.cpp. then I added to my sketch: "#include <printf.h>" in the beginning, I found the file somewhere on the net. in the void setup() function I added "printf_begin();" I do not fully understand this, but it seems to define stdio. Because I read in RF24.h printf.h /** * Print a giant block of debugging information to stdout * * @warning Does nothing if stdout is not defined. See fdevopen in stdio.h */ void printDetails(void); in the void loop(); I added "radio.rf24.printDetails();" ... and after several months of research it is finally printing some debug output. For example: PA Power = PA_HIGH I wonder why this is so difficult to use and there is so little info about debugging. Hope it helps someone!
    • karl261

      How to read a seven segment display?
      Development • • karl261  

      6
      0
      Votes
      6
      Posts
      2135
      Views

      karl261

      I think it does not look too complicated. Finally got around to open the thing. I am surprised by its simplicity, at least it looks like. Plenty of space. But I am scared that the display is just pressed into the board. I hope I won't kill it. So know I have to find out how it works... It should be also super easy to control the four buttons (only two are actually needed) with optocouplers... I wonder if it is possible to hack the radio transmission... Comments?