hwCPUVoltage() on AVR screws up analogRead() readings



  • Can I use hwCPUVoltage() function to read cpu power supply voltage in my sketch? As far as I understand this function is not documented.

    I'm asking because this function affects analogReference(INTERNAL) with further analogRead(pin) call. According to source code it seems for me that hwCPUVoltage() isn't restoring ADC settings before return.

    Simple code to test is looking something like this:

    void setup()
    {
        analogReference(INTERNAL);
    }
    
    void loop()
    {
        analogRead(pin_number); // good value
        hwCPUVoltage();
        analogRead(pin_number); // bad value
    }
    

  • Mod

    There is a vcc voltage library if you want to read voltage supplied but I heard it isn't very accurate


Log in to reply
 

Looks like your connection to MySensors Forum was lost, please wait while we try to reconnect.