Question about RS485 and MY_DEBUG



  • Hey guys,

    I gues i have an simple question ,
    Is it normal that RS485 on Hardware Serial only works with MY_DEBUG enabled?

    If i exclude the MY_DEBUG, communication stops to the gateway

    Here an example sketch:

    #define MY_DEBUG
    #define MY_RS485
    #define MY_RS485_DE_PIN 2
    #define MY_RS485_BAUD_RATE 19200
    #define MY_RS485_HWSERIAL Serial
    #define MY_NODE_ID 5
    
    
    #include <MySensors.h>  
    #include <DallasTemperature.h>
    #include <OneWire.h>
    
    #define COMPARE_TEMP 0 // Send temperature only if changed? 1 = Yes 0 = No
    
    #define ONE_WIRE_BUS A1 // Pin where dallase sensor is connected 
    #define MAX_ATTACHED_DS18B20 2
    unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
    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[MAX_ATTACHED_DS18B20];
    int numSensors=0;
    bool receivedConfig = false;
    bool metric = true;
    // Initialize temperature message
    MyMessage msga(0,V_TEMP);
    
    
    
    
    
    #define CHILD_ID_LIGHT 25
    #define LIGHT_SENSOR_ANALOG_PIN 0
    
    
    MyMessage msg(CHILD_ID_LIGHT, V_TEXT);
    int lastLightLevel;
    
    
    void before()
    {
      // Startup up the OneWire library
      sensors.begin();
    }
    
    
    void setup()  
    { 
      // requestTemperatures() will not block current thread
      sensors.setWaitForConversion(false);
    }
    
    
    
    void presentation()
    {
        // Send the sketch version information to the gateway and Controller
        sendSketchInfo("Node 5", "1.0");
    
        // Register all sensors to gateway (they will be created as child devices)
        present(CHILD_ID_LIGHT, S_BINARY);
    
    
      numSensors = sensors.getDeviceCount();
    
      // Present all sensors to controller
      for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {   
         present(i, S_TEMP);
      }
    
        
    }
    
    void loop()
    {
    
      sensors.requestTemperatures();
    
      // query conversion time and sleep until conversion completed
      int16_t conversionTime = sensors.millisToWaitForConversion(sensors.getResolution());
      // sleep() call can be replaced by wait() call if node need to process incoming messages (or if node is repeater)
      wait(conversionTime);
    
      // Read temperatures and send them to controller 
      for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {
    
        // Fetch and round temperature to one decimal
        float temperature = static_cast<float>(static_cast<int>((getControllerConfig().isMetric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i)) * 10.)) / 10.;
    
        // Only send data if temperature has changed and no error
        #if COMPARE_TEMP == 1
        if (lastTemperature[i] != temperature && temperature != -127.00 && temperature != 85.00) {
        #else
        if (temperature != -127.00 && temperature != 85.00) {
        #endif
    
    
        int16_t lightLevel = (1023-analogRead(LIGHT_SENSOR_ANALOG_PIN))/10.23;
            send(msg.set(lightLevel));
            
          // Send in the new temperature
          send(msga.setSensor(i).set(temperature,1));
          // Save new temperatures for next compare
          lastTemperature[i]=temperature;
        }
      }
      wait(SLEEP_TIME);
    }
    
    

Log in to reply
 

Suggested Topics

46
Online

11.4k
Users

11.1k
Topics

112.6k
Posts