Voltage Readings from attiny
Another cool feature besides the temperature reading is the fact that you can read the supply voltage (Vcc) from the attiny's ADC. This is another use for our sample function:
uint16_t sample(uint8_t admux){
uint16_t res;
ADMUX = admux;
set_sleep_mode(SLEEP_MODE_ADC);
ADCSRA |= _BV(ADEN) | _BV(ADSC);
while(ADCSRA & _BV(ADSC))
sleep_mode();
res = ADC;
ADCSRA &= ~(_BV(ADEN));
return res;
}
Now you need to set the ADMUX
register to 0x0C
like data.voltage = sample(0x0C);
Host Side Conversion
On host side, you need to do some conversion:
(1.1*1023)/Value = Voltage
This is really usefull to control the battery voltage. We had powered RFM12 and attiny45 with just 1.9V and we could send! So a good value for a alert would be like 2.0V