Any nordic developer ?
I am trying the following code on nrf52 module:
MicroPython v1.9.4-378-gab81578-dirty on 2018-08-17; PCA10040 with NRF52832
Type "help()" for more information.
>> import machine
>>> machine.ADC.battery_level()
100
>>>
Then I installed the code below.
I can connect to nrf52 module using Nordic nRF Connect but I am reading battery level value 28%.
Any tips ?
from ubluepy import Service, Characteristic, UUID, Peripheral, constants
from machine import ADC
def event_handler(id, handle, data):
global periph
global serv_batt
if id == constants.EVT_GAP_CONNECTED:
LED(1).on()
elif id == constants.EVT_GAP_DISCONNECTED:
LED(1).off()
periph.advertise(device_name="micr_batt", services=[serv_batt])
elif id == constants.EVT_GATTS_READ:
data[0]= ADC.battery_level()
return
def start():
global periph
global serv_batt
LED(1).off()
uuid_batt_service = UUID("0x180F")
uuid_batt_chr = UUID("0x2A19")
serv_batt = Service(uuid_batt_service)
bat_props = Characteristic.PROP_NOTIFY | Characteristic.PROP_READ
bat_attrs = Characteristic.ATTR_CCCD
bat_chr = Characteristic(uuid_batt_chr, props = bat_props, attrs = bat_attrs)
serv_batt.addCharacteristic(bat_chr)
periph = Peripheral()
periph.addService(serv_batt)
periph.setConnectionHandler(event_handler)
periph.advertise(device_name="micr_batt", services=[serv_batt])