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)