Add function to measure Vbat with some simple filter (mean of n samples, 10 by default)
This commit is contained in:
parent
37e77ebef6
commit
5665ccff52
@ -68,15 +68,10 @@ class Data:
|
|||||||
#Data from Feather board
|
#Data from Feather board
|
||||||
self.data['SYS'] = {'time': {'val': datetime_format.format(*clock.datetime[0:6]),
|
self.data['SYS'] = {'time': {'val': datetime_format.format(*clock.datetime[0:6]),
|
||||||
'unit': '' },
|
'unit': '' },
|
||||||
'v_bat': {'val': vbat.value*0.000100708,
|
'v_bat': {'val': measure_vbat(),
|
||||||
'unit': 'V' },
|
'unit': 'V' },
|
||||||
'CPU_temp': {'val': microcontroller.cpu.temperature,
|
'CPU_temp': {'val': microcontroller.cpu.temperature,
|
||||||
'unit': '°C' }}
|
'unit': '°C' }}
|
||||||
# Note about v_bat calculation :
|
|
||||||
# 0.000100708 = 2*3.3/65536 with
|
|
||||||
# 2 : voltage is divided by 2
|
|
||||||
# 3.3 : Vref = 3.3V
|
|
||||||
# 65536 : 16bit ADC
|
|
||||||
|
|
||||||
#Data from BME280
|
#Data from BME280
|
||||||
self.data['BME280'] = {'temp': { 'val': round(bme280.temperature, 1), 'unit': '°C' },
|
self.data['BME280'] = {'temp': { 'val': round(bme280.temperature, 1), 'unit': '°C' },
|
||||||
@ -197,6 +192,20 @@ def set_clock_from_GPS():
|
|||||||
clock.datetime = gps_datetime #Trust GPS if there is a bias
|
clock.datetime = gps_datetime #Trust GPS if there is a bias
|
||||||
print("New date/time : " + datetime_format.format(*clock.datetime[0:6]))
|
print("New date/time : " + datetime_format.format(*clock.datetime[0:6]))
|
||||||
|
|
||||||
|
def measure_vbat(samples=10, timestep=0.01):
|
||||||
|
"""Measure Vbattery as the mean of n samples with timestep second between
|
||||||
|
each measurement"""
|
||||||
|
# Note about v_bat calculation :
|
||||||
|
# 0.000100708 = 2*3.3/65536 with
|
||||||
|
# 2 : voltage is divided by 2
|
||||||
|
# 3.3 : Vref = 3.3V
|
||||||
|
# 65536 : 16bit ADC
|
||||||
|
v = 0
|
||||||
|
for i in range(samples):
|
||||||
|
v = v + vbat.value
|
||||||
|
time.sleep(timestep)
|
||||||
|
return v/samples*0.000100708
|
||||||
|
|
||||||
#########
|
#########
|
||||||
# Setup #
|
# Setup #
|
||||||
#########
|
#########
|
||||||
|
Loading…
Reference in New Issue
Block a user