Hello all, may be I did not get the point of this thread, but a very similar code to measure the AVR CPU voltage is already part of the MySensors library: MyHwAVR.cpp#L289
I use it in some of my PIR sensors and it works fine. Simply call hwCPUVoltage() to get it.
This is from my code:
void sendBatteryLevel()
{
// This calls the internal voltage measurement
uint16_t voltage = hwCPUVoltage();
// Li AAA Cell Voltage range: discharged - full 2.6V - 3.0V
uint16_t batteryPcnt = map(voltage, 2600, 3000, 0, 100);
batteryPcnt = constrain(batteryPcnt, 0, 100);
// This MySensors function sends the "internal battery info" to the gateway
sendBatteryLevel(batteryPcnt);
}
BR Immo