-
Notifications
You must be signed in to change notification settings - Fork 180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Example to send requestTemperature() and requestBatteryLevel() every x seconds from nRF5x #215
Comments
Maybe @d00616 could help, given your apparent knowledge about sleep modes on the nRF5x? |
Also relevant: #203. Unfortunately this was closed because it would need "changes to library". So this ticket is here to request those changes if needed. |
i found this sketch linked somewhere in the issues here He also has a description of the voltage measurement at the comments on top |
Thanks @mristau for linking the example sketch of @kriswiner. He writes
Probably one needs different values for a coin cell. Since I assume this is of interest to many users, I'd suggest to include a stripped-down version of his sketch (only the battery part) as one of the official examples. |
So what I am essentially looking for is an Arduino version of
|
I also see the functions arduino-BLEPeripheral/src/BLEDevice.h Lines 92 to 93 in f591da1
We should make an example sketch using them for nRF5. |
This is what I have at the moment - questions inline:
|
I didn't work with that temperature sensor, we have one embedded into our accelerometer. There has to be some connection from battery to a nRF pin, at our board it's to A2, then analogRead(PIN) will get a value between 0 and 1023, or 4095 if using 12bit The voltage divider should be chosen by the Voltage of the battery, at LiPo 3.7-4.2V are max values. Those should be reduced to below 3.3V |
While this thread is very useful (thanks @mristau) I still would like to see an example sketch to be added so that one can get this kind of thing right from the examples rather than having to search for it on GitHub. Hence I would appreciate if you could give it consideration @sandeepmistry. I think making low power devices that can also send their own battery level and temperature is one of the killer applications for this project. |
How to add BLE batteryService to Beacon code #include <BLEPeripheral.h> BLEPeripheral blePeripheral ; char* Data = "a196c876-de8c-4c47-1234-d7afd5ae7127"; BLEService batteryService = BLEService("180F"); if (blePeripheral.setTxPower(4)) } void loop() { delay(1000); |
Any idea about how to send string data from app(nrfToolBox) to ble module(nrf51822) and vice-versa? |
can i get the code for nrf52832 Development kit |
Code for reading cr2032 battery level (via VDD pin): // https://github.com/andenore/NordicSnippets/blob/master/examples/saadc/main.c
float getBatteryVoltage()
{
volatile uint16_t result = 9999;
volatile float voltage = 0;
NRF_SAADC->RESOLUTION = SAADC_RESOLUTION_VAL_14bit << SAADC_RESOLUTION_VAL_Pos;
for (int i = 0; i < 8; i++) {
NRF_SAADC->CH[i].PSELN = SAADC_CH_PSELP_PSELP_NC;
NRF_SAADC->CH[i].PSELP = SAADC_CH_PSELP_PSELP_NC;
}
// Configure SAADC singled-ended channel, Internal reference (0.6V) and 1/6 gain.
NRF_SAADC->CH[0].CONFIG = (SAADC_CH_CONFIG_GAIN_Gain1_6 << SAADC_CH_CONFIG_GAIN_Pos) |
(SAADC_CH_CONFIG_MODE_SE << SAADC_CH_CONFIG_MODE_Pos) |
(SAADC_CH_CONFIG_REFSEL_Internal << SAADC_CH_CONFIG_REFSEL_Pos) |
(SAADC_CH_CONFIG_RESN_Bypass << SAADC_CH_CONFIG_RESN_Pos) |
(SAADC_CH_CONFIG_RESP_Bypass << SAADC_CH_CONFIG_RESP_Pos) |
(SAADC_CH_CONFIG_TACQ_3us << SAADC_CH_CONFIG_TACQ_Pos);
NRF_SAADC->CH[0].PSELP = SAADC_CH_PSELP_PSELP_VDD;
NRF_SAADC->CH[0].PSELN = SAADC_CH_PSELP_PSELP_NC;
NRF_SAADC->RESULT.PTR = (uint32_t)&result;
NRF_SAADC->RESULT.MAXCNT = 1; // One sample
// No automatic sampling, will trigger with TASKS_SAMPLE.
NRF_SAADC->SAMPLERATE = SAADC_SAMPLERATE_MODE_Task << SAADC_SAMPLERATE_MODE_Pos;
// Enable SAADC (would capture analog pins if they were used in CH[0].PSELP)
NRF_SAADC->ENABLE = SAADC_ENABLE_ENABLE_Enabled << SAADC_ENABLE_ENABLE_Pos;
// Calibrate the SAADC (only needs to be done once in a while)
NRF_SAADC->TASKS_CALIBRATEOFFSET = 1;
while (NRF_SAADC->EVENTS_CALIBRATEDONE == 0);
NRF_SAADC->EVENTS_CALIBRATEDONE = 0;
while (NRF_SAADC->STATUS == (SAADC_STATUS_STATUS_Busy <<SAADC_STATUS_STATUS_Pos));
NRF_SAADC->TASKS_START = 1;
while (!NRF_SAADC->EVENTS_STARTED);
NRF_SAADC->EVENTS_STARTED = 0;
NRF_SAADC->TASKS_SAMPLE = 1;
while (!NRF_SAADC->EVENTS_END);
NRF_SAADC->EVENTS_END = 0;
// Stop the SAADC, since it's not used anymore.
NRF_SAADC->TASKS_STOP = 1;
while (NRF_SAADC->EVENTS_STOPPED == 0);
NRF_SAADC->EVENTS_STOPPED = 0;
NRF_SAADC->ENABLE = (SAADC_ENABLE_ENABLE_Disabled << SAADC_ENABLE_ENABLE_Pos);
// Convert the result to voltage
// Result = [V(p) - V(n)] * GAIN/REFERENCE * 2^(RESOLUTION)
// Result = (VDD - 0) * ((1/6) / 0.6) * 2^14
// VDD = Result / 4551.1
voltage = (float)result / 4551.1f;
return voltage;
} You can use it like this for your battery characteristic: float battVoltage = getBatteryVoltage();
uint8_t battLevel = map(battVoltage, 0, 3.0, 0, 100); // map battery level from 0-3V to 0-100%
battlevelCharacteristic.setValue(battLevel); // set the battery level characteristic value |
Please add an example sketch to send battery voltage every x seconds with nRF5x.
Possibly a circuit like shown here is needed, although I am not sure since #203 talks about an "inbuilt function to measure the battery voltage using the VDD given to the chip".
The sketch should be optimized for low power consumption to run off a coin cell for a long time.
I think this kind of example will be very useful for anyone who wants to make a sensor that sends data in intervals from battery-operated sensor devices.
The text was updated successfully, but these errors were encountered: