Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Troubleshooting
  3. fail converting 1.5 sketch to 2.0

fail converting 1.5 sketch to 2.0

Scheduled Pinned Locked Moved Troubleshooting
2 Posts 2 Posters 1.2k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • carlekiC Offline
    carlekiC Offline
    carleki
    wrote on last edited by
    #1

    Hi guys !

    I'm trying to convert a temperature sketch with CR2032 battery monitoring, and the OneWire without resistor lib (to avoid the 4.7k resistor attached to the Dallas)

    But, it seems I have not well followed the instructions to convert a sketch from 1.5.4 to 2.0, because it won't compile !

    Here is the original sketch (1.5) :

    // avec mesure de la batterie avec Vcc.h
    // ok avec pile CR2032 et docATmega328 8Mhz MYSBootloader et efuse 0x07
    // pour DS18B20 SANS resistance
    // nécessite la lib OneWire : OneWireNoResistor-master.zip
    //
    // boards.txt :
    //proMYSBL.name=docATmega328 8Mhz MYSBootloader
    
    //proMYSBL.upload.tool=avrdude
    //proMYSBL.upload.protocol=arduino
    //proMYSBL.upload.maximum_size=30720
    //proMYSBL.upload.maximum_data_size=2048
    //proMYSBL.upload.speed=115200
    
    //proMYSBL.bootloader.tool=avrdude
    //proMYSBL.bootloader.low_fuses=0xE2
    //proMYSBL.bootloader.high_fuses=0xDA
    //proMYSBL.bootloader.extended_fuses=0x07
    //proMYSBL.bootloader.unlock_bits=0x3F
    //proMYSBL.bootloader.lock_bits=0x0F
    //proMYSBL.bootloader.file=MySBootloader/MYSBootloader.hex
    
    //proMYSBL.build.mcu=atmega328p
    //proMYSBL.build.f_cpu=8000000L
    //proMYSBL.build.board=AVR_UNO
    //proMYSBL.build.core=arduino:arduino
    //proMYSBL.build.variant=arduino:standard
    #include <MySensor.h>
    #include <SPI.h>
    #include <DallasTemperature.h>
    #include <OneWire.h>
    #include <Vcc.h>
    
    #define ONE_WIRE_BUS 4 // Pin where dallase sensor is connected
    #define ONE_WIRE_GND 5
    #define ONE_WIRE_VCC 3
    #define ID_BatPcnt 1
    #define ID_Bat 2
    
    #define MAX_ATTACHED_DS18B20 16
    
    // 60000 = 1 minute
    // 12000 = 2 minutes
    // 300000 = 5 minutes
    // 600000 = 10 minutes
    #define SLEEP_TIME 300000  // Sleep time between reads (in milliseconds)
    
    
    
    
    const float VccMin   = 2.3;             // Vcc mini attendu, en Volts.
    const float VccMax   = 3;           // Vcc Maximum attendu, en Volts (2 piles AA neuves)
    const float VccCorrection = 2.52/2.6; // calibration : Vcc mesuré au multimètre / Vcc mesuré par l'Arduino par vcc.Read_Volts() dans sketch 1/2
    Vcc vcc(VccCorrection);
    
    OneWire oneWire(ONE_WIRE_BUS);
    DallasTemperature sensors(&oneWire);
    MySensor gw;
    MyMessage msgBAT_PCNT(ID_BatPcnt,V_VAR1); // on utilise le type V_VAR1 pour le % de charge des piles
    MyMessage msgBAT(ID_Bat,V_VAR2);          // on utilise le type V_VAR2 pour la tension des piles
    float lastTemperature[MAX_ATTACHED_DS18B20];
    uint8_t numSensors = 0;
    boolean receivedConfig = false;
    boolean metric = true;
    // Initialize temperature message
    MyMessage msg(0, V_TEMP);
    int oldvalue = 0;
    int node_id = 30; // on donne un ID au node
    
    void setup()
    {
      // Startup OneWire
    #ifdef ONE_WIRE_VCC
      pinMode(ONE_WIRE_VCC, OUTPUT);
      digitalWrite(ONE_WIRE_VCC, HIGH);
    #endif
    #ifdef ONE_WIRE_GND
      pinMode(ONE_WIRE_GND, OUTPUT);
      digitalWrite(ONE_WIRE_GND, LOW);
    #endif
    
      analogReference(INTERNAL);
      pinMode(BATT_IN_PIN, INPUT);
      pinMode(BATT_VCC_PIN, OUTPUT);
      digitalWrite(BATT_VCC_PIN, LOW);
    
      sensors.begin();
    
      // Startup and initialize MySensors library. Set callback for incoming messages.
     // gw.begin();
      gw.begin(NULL, node_id, true);
      // Send the sketch version information to the gateway and Controller
      gw.sendSketchInfo("Temperature Sensor", "1.0");
    
      // Fetch the number of attached temperature sensors
      numSensors = sensors.getDeviceCount();
    
      sensors.setWaitForConversion(false);//saves a few mAs per read :-) to debug
    
      // Present all sensors to controller
      gw.present(ID_BatPcnt, S_CUSTOM);  // type S_CUSTOM pour le capteur "% de charge"
      gw.present(ID_Bat, S_CUSTOM);      // type S_CUSTOM pour le capteur "tension"
      for (int i = 0; i < numSensors && i < MAX_ATTACHED_DS18B20; i++) {
        gw.present(i, S_TEMP);  
      }
    }
    
    
    void loop()
    {
      // Process incoming messages (like config from server)
      //gw.process();
    // mesure de Vcc
          float v = vcc.Read_Volts();
          // calcul du % de charge batterie
          float p = 100 * ((v - VccMin) / (VccMax - VccMin));
          // On envoie les données des capteurs et de l'état de la batterie au Gateway
          //gw.sendBatteryLevel(p);  // Inutile...
          gw.send(msgBAT_PCNT.set(p, 1)); // 1 décimale
          gw.send(msgBAT.set(v, 3));      // 2 décimales
      // Fetch temperatures from Dallas sensors
      // Fetch temperatures from Dallas sensors
      sensors.requestTemperatures();
    
      gw.sleep(750);//wait for conversion in sleep mode
    
      // 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>((gw.getConfig().isMetric ? sensors.getTempCByIndex(i) : sensors.getTempFByIndex(i)) * 10.)) / 10.;
    
        // Only send data if temperature has changed and no error
        gw.send(msg.setSensor(i).set(temperature, 1));
          lastTemperature[i] = temperature;
        //if (lastTemperature[i] != temperature && temperature != -127.00) {
    
          // Send in the new temperature
          
        //}
      }
     
      gw.sleep(SLEEP_TIME);//wake on interrupt or after sleep-time
    }
    

    Here is my "converted" sketch :

    // avec mesure de la batterie avec Vcc.h
    // ok avec pile CR2032 et docATmega328 8Mhz MYSBootloader et efuse 0x07
    // pour DS18B20 SANS resistance
    // nécessite la lib OneWire : OneWireNoResistor-master.zip
    //
    // boards.txt :
    //proMYSBL.name=docATmega328 8Mhz MYSBootloader
    
    //proMYSBL.upload.tool=avrdude
    //proMYSBL.upload.protocol=arduino
    //proMYSBL.upload.maximum_size=30720
    //proMYSBL.upload.maximum_data_size=2048
    //proMYSBL.upload.speed=115200
    
    //proMYSBL.bootloader.tool=avrdude
    //proMYSBL.bootloader.low_fuses=0xE2
    //proMYSBL.bootloader.high_fuses=0xDA
    //proMYSBL.bootloader.extended_fuses=0x07
    //proMYSBL.bootloader.unlock_bits=0x3F
    //proMYSBL.bootloader.lock_bits=0x0F
    //proMYSBL.bootloader.file=MySBootloader/MYSBootloader.hex
    
    //proMYSBL.build.mcu=atmega328p
    //proMYSBL.build.f_cpu=8000000L
    //proMYSBL.build.board=AVR_UNO
    //proMYSBL.build.core=arduino:arduino
    //proMYSBL.build.variant=arduino:standard
    #include <MySensors.h>
    #include <SPI.h>
    #include <DallasTemperature.h>
    #include <OneWire.h>
    #include <Vcc.h>
    
    #define ONE_WIRE_BUS 4 // Pin where dallase sensor is connected
    #define ONE_WIRE_GND 5
    #define ONE_WIRE_VCC 3
    
    
    #define ID_BatPcnt 1
    #define ID_Bat 2
    
    #define MAX_ATTACHED_DS18B20 16
    #define MY_NODE_ID 123
    #define MY_RADIO_NRF24
    
    // 60000 = 1 minute
    // 12000 = 2 minutes
    // 300000 = 5 minutes
    // 600000 = 10 minutes
    #define SLEEP_TIME 300000  // Sleep time between reads (in milliseconds)
    
    
    const float VccMin   = 2.3;             // Vcc mini attendu, en Volts.
    const float VccMax   = 3;           // Vcc Maximum attendu, en Volts (2 piles AA neuves)
    const float VccCorrection = 2.52/2.6; // calibration : Vcc mesuré au multimètre / Vcc mesuré par l'Arduino par vcc.Read_Volts() dans sketch 1/2
    Vcc vcc(VccCorrection);
    
    OneWire oneWire(ONE_WIRE_BUS);
    DallasTemperature sensors(&oneWire);
    //MySensor gw;
    MyMessage msgBAT_PCNT(ID_BatPcnt,V_VAR1); // on utilise le type V_VAR1 pour le % de charge des piles
    MyMessage msgBAT(ID_Bat,V_VAR2);          // on utilise le type V_VAR2 pour la tension des piles
    float lastTemperature[MAX_ATTACHED_DS18B20];
    uint8_t numSensors = 0;
    boolean receivedConfig = false;
    boolean metric = true;
    // Initialize temperature message
    MyMessage msg(0, V_TEMP);
    int oldvalue = 0;
    
    void before()
    {
      // Startup up the OneWire library
      sensors.begin();
    }
    
    void setup()
    {
      // Startup OneWire
    #ifdef ONE_WIRE_VCC
      pinMode(ONE_WIRE_VCC, OUTPUT);
      digitalWrite(ONE_WIRE_VCC, HIGH);
    #endif
    #ifdef ONE_WIRE_GND
      pinMode(ONE_WIRE_GND, OUTPUT);
      digitalWrite(ONE_WIRE_GND, LOW);
    #endif
    
      analogReference(INTERNAL);
      pinMode(BATT_IN_PIN, INPUT);
      pinMode(BATT_VCC_PIN, OUTPUT);
      digitalWrite(BATT_VCC_PIN, LOW);
    
        
    }
    
    void presentation()
    {
      // Startup and initialize MySensors library. Set callback for incoming messages.
     // gw.begin();
      //gw.begin(NULL, node_id, true);
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo("TS sR batt", "2.0");
    
      // Fetch the number of attached temperature sensors
      numSensors = sensors.getDeviceCount();
    
      sensors.setWaitForConversion(false);//saves a few mAs per read :-) to debug
    
      // Present all sensors to controller
      present(ID_BatPcnt, S_CUSTOM);  // type S_CUSTOM pour le capteur "% de charge"
      present(ID_Bat, S_CUSTOM);      // type S_CUSTOM pour le capteur "tension"
      for (int i = 0; i < numSensors && i < MAX_ATTACHED_DS18B20; i++) {
        present(i, S_TEMP);  
      }
    }
    
    void loop()
    {
      // Process incoming messages (like config from server)
      //gw.process();
    // mesure de Vcc
          float v = vcc.Read_Volts();
          // calcul du % de charge batterie
          float p = 100 * ((v - VccMin) / (VccMax - VccMin));
          // On envoie les données des capteurs et de l'état de la batterie au Gateway
          //gw.sendBatteryLevel(p);  // Inutile...
          send(msgBAT_PCNT.set(p, 1)); // 1 décimale
          send(msgBAT.set(v, 3));      // 2 décimales
      // Fetch temperatures from Dallas sensors
      // Fetch temperatures from Dallas sensors
      sensors.requestTemperatures();
    
      sleep(750);//wait for conversion in sleep mode
    
      // 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>((gw.getConfig().isMetric ? sensors.getTempCByIndex(i) : sensors.getTempFByIndex(i)) * 10.)) / 10.;
    
        // Only send data if temperature has changed and no error
        send(msg.setSensor(i).set(temperature, 1));
          lastTemperature[i] = temperature;
        //if (lastTemperature[i] != temperature && temperature != -127.00) {
    
          // Send in the new temperature
          
        //}
      }
     
      sleep(SLEEP_TIME);//wake on interrupt or after sleep-time
    }
    

    And the error given by the Arduino IDE :

    In file included from /home/carmelo/Arduino/tmp/tmp_tempbattv2/tmp_tempbattv2.ino:28:0:
    /home/carmelo/Arduino/libraries/MySensors/MySensors.h:332:2: error: #error No forward link or gateway feature activated. This means nowhere to send messages! Pretty pointless.
     #error No forward link or gateway feature activated. This means nowhere to send messages! Pretty pointless.
      ^
    exit status 1
    Erreur de compilation pour la carte Arduino Pro or Pro Mini
    
    1 Reply Last reply
    0
    • DIYProjectsD Offline
      DIYProjectsD Offline
      DIYProjects
      wrote on last edited by DIYProjects
      #2

      Hi Carmelo42. Here your sketch modified. You need to define all MySensors parameters before to include the library. I add 2 variables (BATT_IN_PIN, BATT_VCC_PIN). You need to set Pins. I think, it'll run now. I don't check if the measure of the temperature is correct.

      // avec mesure de la batterie avec Vcc.h
      // ok avec pile CR2032 et docATmega328 8Mhz MYSBootloader et efuse 0x07
      // pour DS18B20 SANS resistance
      // nécessite la lib OneWire : OneWireNoResistor-master.zip
      //
      // boards.txt :
      //proMYSBL.name=docATmega328 8Mhz MYSBootloader
      
      //proMYSBL.upload.tool=avrdude
      //proMYSBL.upload.protocol=arduino
      //proMYSBL.upload.maximum_size=30720
      //proMYSBL.upload.maximum_data_size=2048
      //proMYSBL.upload.speed=115200
      
      //proMYSBL.bootloader.tool=avrdude
      //proMYSBL.bootloader.low_fuses=0xE2
      //proMYSBL.bootloader.high_fuses=0xDA
      //proMYSBL.bootloader.extended_fuses=0x07
      //proMYSBL.bootloader.unlock_bits=0x3F
      //proMYSBL.bootloader.lock_bits=0x0F
      //proMYSBL.bootloader.file=MySBootloader/MYSBootloader.hex
      
      //proMYSBL.build.mcu=atmega328p
      //proMYSBL.build.f_cpu=8000000L
      //proMYSBL.build.board=AVR_UNO
      //proMYSBL.build.core=arduino:arduino
      //proMYSBL.build.variant=arduino:standard
      #define MY_NODE_ID 123
      #define MY_RADIO_NRF24
      
      #include <SPI.h>
      #include <MySensors.h>
      
      #include <DallasTemperature.h>
      #include <OneWire.h>
      #include <Vcc.h>
      
      #define ONE_WIRE_BUS 4 // Pin where dallase sensor is connected
      #define ONE_WIRE_GND 5
      #define ONE_WIRE_VCC 3
      
      
      #define ID_BatPcnt 1
      #define ID_Bat 2
      #define BATT_IN_PIN 1
      #define BATT_VCC_PIN 2
      
      #define MAX_ATTACHED_DS18B20 16
      
      
      // 60000 = 1 minute
      // 12000 = 2 minutes
      // 300000 = 5 minutes
      // 600000 = 10 minutes
      #define SLEEP_TIME 300000  // Sleep time between reads (in milliseconds)
      
      
      const float VccMin   = 2.3;             // Vcc mini attendu, en Volts.
      const float VccMax   = 3;           // Vcc Maximum attendu, en Volts (2 piles AA neuves)
      const float VccCorrection = 2.52/2.6; // calibration : Vcc mesuré au multimètre / Vcc mesuré par l'Arduino par vcc.Read_Volts() dans sketch 1/2
      Vcc vcc(VccCorrection);
      
      OneWire oneWire(ONE_WIRE_BUS);
      DallasTemperature sensors(&oneWire);
      //MySensor gw;
      MyMessage msgBAT_PCNT(ID_BatPcnt,V_VAR1); // on utilise le type V_VAR1 pour le % de charge des piles
      MyMessage msgBAT(ID_Bat,V_VAR2);          // on utilise le type V_VAR2 pour la tension des piles
      float lastTemperature[MAX_ATTACHED_DS18B20];
      uint8_t numSensors = 0;
      boolean receivedConfig = false;
      boolean metric = true;
      // Initialize temperature message
      MyMessage msg(0, V_TEMP);
      int oldvalue = 0;
      
      void before()
      {
        // Startup up the OneWire library
        sensors.begin();
      }
      
      void setup()
      {
        // Startup OneWire
      #ifdef ONE_WIRE_VCC
        pinMode(ONE_WIRE_VCC, OUTPUT);
        digitalWrite(ONE_WIRE_VCC, HIGH);
      #endif
      #ifdef ONE_WIRE_GND
        pinMode(ONE_WIRE_GND, OUTPUT);
        digitalWrite(ONE_WIRE_GND, LOW);
      #endif
        analogReference(INTERNAL);
        pinMode(BATT_IN_PIN, INPUT);
        pinMode(BATT_VCC_PIN, OUTPUT);
        digitalWrite(BATT_VCC_PIN, LOW);
      
          
      }
      
      void presentation()
      {
        // Startup and initialize MySensors library. Set callback for incoming messages.
       // gw.begin();
        //gw.begin(NULL, node_id, true);
        // Send the sketch version information to the gateway and Controller
        sendSketchInfo("TS sR batt", "2.0");
      
        // Fetch the number of attached temperature sensors
        numSensors = sensors.getDeviceCount();
      
        sensors.setWaitForConversion(false);//saves a few mAs per read :-) to debug
      
        // Present all sensors to controller
        present(ID_BatPcnt, S_CUSTOM);  // type S_CUSTOM pour le capteur "% de charge"
        present(ID_Bat, S_CUSTOM);      // type S_CUSTOM pour le capteur "tension"
        for (int i = 0; i < numSensors && i < MAX_ATTACHED_DS18B20; i++) {
          present(i, S_TEMP);  
        }
      }
      
      void loop()
      {
        // Process incoming messages (like config from server)
        //gw.process();
      // mesure de Vcc
            float v = vcc.Read_Volts();
            // calcul du % de charge batterie
            float p = 100 * ((v - VccMin) / (VccMax - VccMin));
            // On envoie les données des capteurs et de l'état de la batterie au Gateway
            //gw.sendBatteryLevel(p);  // Inutile...
            send(msgBAT_PCNT.set(p, 1)); // 1 décimale
            send(msgBAT.set(v, 3));      // 2 décimales
        // Fetch temperatures from Dallas sensors
        // Fetch temperatures from Dallas sensors
        sensors.requestTemperatures();
      
        sleep(750);//wait for conversion in sleep mode
      
        // 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>((getConfig().isMetric ? sensors.getTempCByIndex(i) : sensors.getTempFByIndex(i)) * 10.)) / 10.;
      
          // Only send data if temperature has changed and no error
          send(msg.setSensor(i).set(temperature, 1));
            lastTemperature[i] = temperature;
          //if (lastTemperature[i] != temperature && temperature != -127.00) {
      
            // Send in the new temperature
            
          //}
        }
       
        sleep(SLEEP_TIME);//wake on interrupt or after sleep-time
      }
      

      If you need more info : http://www.diyprojects.io/mysensors-v2-discover-news-migrate-old-sketchs/ (or http://www.projetsdiy.fr/mysensors-version2-decouverte-nouveautes-convertir-sketch/ in french)

      1 Reply Last reply
      2
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      9

      Online

      11.7k

      Users

      11.2k

      Topics

      113.1k

      Posts


      Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • MySensors
      • OpenHardware.io
      • Categories
      • Recent
      • Tags
      • Popular