nRF5 action!
-
@Terrence said in nRF5 Bluetooth action!:
VS Code with the Arduino Extension is your friend.
I'll try that. Maybe it will be a little less of a learning curve than Visual Micro yet still do what I need.
-
I just now did a brute force hack of the MySensors BatteryPoweredSensor sketch, where I copied and renamed the hwCPUVoltage function from the library and then called it from within a tight loop so that I never lose the locus of control. It worked!
/** * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each * repeater and gateway builds a routing tables in EEPROM which keeps track of the * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad <henrik.ekblad@mysensors.org> * Copyright (C) 2013-2015 Sensnology AB * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * version 2 as published by the Free Software Foundation. * ******************************* * * DESCRIPTION * * This is an example that demonstrates how to report the battery level for a sensor * Instructions for measuring battery capacity on A0 are available here: * http://www.mysensors.org/build/battery * */ // Enable debug prints to serial monitor //#define MY_DEBUG // Enable and select radio type attached //#define MY_RADIO_NRF24 //#define MY_RADIO_RFM69 #define MY_RADIO_NRF5_ESB //#include <MySensors.h> int BATTERY_SENSE_PIN = A0; // select the input pin for the battery sense point //unsigned long SLEEP_TIME = 900000; // sleep time between reads (seconds * 1000 milliseconds) unsigned long SLEEP_TIME = 1000; // sleep time between reads (seconds * 1000 milliseconds) int oldBatteryPcnt = 0; uint16_t counter=0; uint16_t volts=0; uint16_t theHwCPUVoltage() { // VDD is prescaled 1/3 and compared with the internal 1.2V reference Serial.println("Inside hwCPUVoltage function."); #if defined(NRF_ADC) Serial.println("This is an NRF_ADC."); // NRF51: // Sampling is done with lowest resolution to minimize the time // 20uS@260uA // Concurrent ressource: disable uint32_t lpcomp_enabled = NRF_LPCOMP->ENABLE; NRF_LPCOMP->ENABLE = 0; // Enable and configure ADC NRF_ADC->ENABLE = 1; NRF_ADC->CONFIG = (ADC_CONFIG_EXTREFSEL_None << ADC_CONFIG_EXTREFSEL_Pos) | (ADC_CONFIG_PSEL_Disabled << ADC_CONFIG_PSEL_Pos) | (ADC_CONFIG_REFSEL_VBG << ADC_CONFIG_REFSEL_Pos) | (ADC_CONFIG_INPSEL_SupplyOneThirdPrescaling << ADC_CONFIG_INPSEL_Pos) | (ADC_CONFIG_RES_8bit << ADC_CONFIG_RES_Pos); NRF_ADC->EVENTS_END = 0; NRF_ADC->TASKS_START = 1; while(!NRF_ADC->EVENTS_END); NRF_ADC->EVENTS_END = 0; int32_t sample = (int32_t)NRF_ADC->RESULT; NRF_ADC->TASKS_STOP = 1; NRF_ADC->ENABLE = 0; // Restore LPCOMP state NRF_LPCOMP->ENABLE = lpcomp_enabled; return (sample*3600)/255; #elif defined(NRF_SAADC) // NRF52: // Sampling time 3uS@700uA Serial.println("This is an NRF_SAADC."); int32_t sample; NRF_SAADC->ENABLE = SAADC_ENABLE_ENABLE_Enabled << SAADC_ENABLE_ENABLE_Pos; NRF_SAADC->RESOLUTION = SAADC_RESOLUTION_VAL_8bit << SAADC_RESOLUTION_VAL_Pos; NRF_SAADC->CH[0].PSELP = SAADC_CH_PSELP_PSELP_VDD << SAADC_CH_PSELP_PSELP_Pos; NRF_SAADC->CH[0].CONFIG = (SAADC_CH_CONFIG_BURST_Disabled << SAADC_CH_CONFIG_BURST_Pos) | (SAADC_CH_CONFIG_MODE_SE << SAADC_CH_CONFIG_MODE_Pos) | (SAADC_CH_CONFIG_TACQ_3us << SAADC_CH_CONFIG_TACQ_Pos) | (SAADC_CH_CONFIG_REFSEL_Internal << SAADC_CH_CONFIG_REFSEL_Pos) | (SAADC_CH_CONFIG_GAIN_Gain1_6 << SAADC_CH_CONFIG_GAIN_Pos) | (SAADC_CH_CONFIG_RESN_Bypass << SAADC_CH_CONFIG_RESN_Pos) | (SAADC_CH_CONFIG_RESP_Bypass << SAADC_CH_CONFIG_RESP_Pos); NRF_SAADC->OVERSAMPLE = SAADC_OVERSAMPLE_OVERSAMPLE_Bypass << SAADC_OVERSAMPLE_OVERSAMPLE_Pos; NRF_SAADC->SAMPLERATE = SAADC_SAMPLERATE_MODE_Task << SAADC_SAMPLERATE_MODE_Pos; NRF_SAADC->RESULT.MAXCNT = 1; NRF_SAADC->RESULT.PTR = (uint32_t)&sample; NRF_SAADC->EVENTS_STARTED = 0; NRF_SAADC->TASKS_START = 1; while (!NRF_SAADC->EVENTS_STARTED); NRF_SAADC->EVENTS_STARTED = 0; NRF_SAADC->EVENTS_END = 0; NRF_SAADC->TASKS_SAMPLE = 1; while (!NRF_SAADC->EVENTS_END); NRF_SAADC->EVENTS_END = 0; NRF_SAADC->EVENTS_STOPPED = 0; NRF_SAADC->TASKS_STOP = 1; while (!NRF_SAADC->EVENTS_STOPPED); NRF_SAADC->EVENTS_STOPPED = 1; NRF_SAADC->ENABLE = (SAADC_ENABLE_ENABLE_Disabled << SAADC_ENABLE_ENABLE_Pos); return (sample*3600)/255; #else Serial.println("Unknown MCU!!"); // unknown MCU return 0; #endif } void setup() { Serial.begin(115200); Serial.println("Setup procedure beginning."); while (true) { volts=theHwCPUVoltage(); Serial.print("counter="); Serial.print(counter++); Serial.print(", hwCPUVoltage="); Serial.println(volts); } // use the 1.1 V internal reference //#if defined(__AVR_ATmega2560__) // analogReference(INTERNAL1V1); //#else // analogReference(INTERNAL); //#endif }Here is a sample of the output:
Inside hwCPUVoltage function. This is an NRF_SAADC. counter=5013, hwCPUVoltage=3303 Inside hwCPUVoltage function. This is an NRF_SAADC. counter=5014, hwCPUVoltage=3303 Inside hwCPUVoltage function. This is an NRF_SAADC. counter=5015, hwCPUVoltage=3303 Inside hwCPUVoltage function. This is an NRF_SAADC. counter=5016, hwCPUVoltage=3303 Inside hwCPUVoltage function. This is an NRF_SAADC. counter=5017, hwCPUVoltage=3303 Inside hwCPUVoltage function. This is an NRF_SAADC. counter=5018, hwCPUVoltage=3303 Inside hwCPUVoltage function. This is an NRF_SAADC. counter=5019, hwCPUVoltage=3303 Inside hwCPUVoltage function. This is an NRF_SAADC. counter=5020, hwCPUVoltage=3303 Inside hwCPUVoltage function. This is an NRF_SAADC. counter=5021, hwCPUVoltage=3303 Inside hwCPUVoltage function. This is an NRF_SAADC. counter=5022, hwCPUVoltage=3303 Inside hwCPUVoltage function. This is an NRF_SAADC. counter=5023, hwCPUVoltage=3303 Inside hwCPUVoltage function. This is an NRF_SAADC. counter=5024, hwCPUVoltage=3303 Inside hwCPUVoltage function. This is an NRF_SAADC. counter=5025, hwCPUVoltage=3303 Inside hwCPUVoltage function. This is an NRF_SAADC. counter=5026, hwCPUVoltage=3303 Inside hwCPUVoltage function. This is an NRF_SAADC. counter=5027, hwCPUVoltage=3303 Inside hwCPUVoltage function. This is an NRF_SAADC. counter=5028, hwCPUVoltage=3303 Inside hwCPUVoltage function. This is an NRF_SAADC. counter=5029, hwCPUVoltage=3303 Inside hwCPUVoltage function. This is an NRF_SAADC. counter=5030, hwCPUVoltage=3289 Inside hwCPUVoltage function. This is an NRF_SAADC. counter=5031, hwCPUVoltage=3303 Inside hwCPUVoltage function. This is an NRF_SAADC. counter=5032, hwCPUVoltage=3303 Inside hwCPUVoltage function. This is an NRF_SAADC. counter=5033, hwCPUVoltage=3303 Inside hwCPUVoltage function. This is an NRF_SAADC. counter=5034, hwCPUVoltage=3303 Inside hwCPUVoltage function. This is an NRF_SAADC. counter=5035, hwCPUVoltage=3303 Inside hwCPUVoltage function. This is an NRF_SAADC. counter=5036, hwCPUVoltage=3303 Inside hwCPUVoltage function. This is an NRF_SAADC. counter=5037, hwCPUVoltage=3303 Inside hwCPUVoltage function. This is an NRF_SAADC. counter=5038, hwCPUVoltage=3289 Inside hwCPUVoltage function. This is an NRF_SAADC. counter=5039, hwCPUVoltage=3303 Inside hwCPUVoltage function. This is an NRF_SAADC. counter=5040, hwCPUVoltage=3303 Inside hwCPUVoltage function. This is an NRF_SAADC. counter=5041, hwCPUVoltage=3303 Inside hwCPUVoltage function. This is an NRF_SAADC. counter=5042, hwCPUVoltage=3303 Inside hwCPUVoltage function. This is an NRF_SAADC. counter=5043, hwCPUVoltage=3303 Inside hwCPUVoltage function. This is an NRF_SAADC. counter=5044, hwCPUVoltage=3303 Inside hwCPUVoltage function. This is an NRF_SAADC. counter=5045, hwCPUVoltage=3303 Inside hwCPUVoltage function. This is an NRF_SAADC. counter=5046, hwCPUVoltage=3303 Inside hwCPUVoltage function. This is an NRF_SAADC. counter=5047, hwCPUVoltage=3303 Inside hwCPUVoltage function. This is an NRF_SAADC. counter=5048, hwCPUVoltage=3303 Inside hwCPUVoltage function. This is an NRF_SAADC. counter=5049, hwCPUVoltage=3303 Inside hwCPUVoltage function. This is an NRF_SAADC. counter=5050, hwCPUVoltage=3303 Inside hwCPUVoltage function. This is an NRF_SAADC. counter=5051, hwCPUVoltage=3303 Inside hwCPUVoltage function. This is an NRF_SAADC. counter=5052, hwCPUVoltage=3303 Inside hwCPUVoltage function. This is an NRF_SAADC. counter=5053, hwCPUVoltage=3303 Inside hwCPUVoltage function. This is an NRF_SAADC. counter=5054, hwCPUVoltage=3303 Inside hwCPUVoltage function. This is an NRF_SAADC. counter=5055, hwCPUVoltage=3303 Inside hwCPUVoltage function. This is an NRF_SAADC. counter=5056, hwCPUVoltage=3303 Inside hwCPUVoltage function. This is an NRF_SAADC. counter=5057, hwCPUVoltage=3303 -
Besides that it can now do println()'s, the other good news is that it looks like I won't need to change the pin assignment.
Too bad the demo sketch only transmits one byte of voltage information, rather than two bytes.
-
@d00616 said in nRF5 Bluetooth action!:
For this, you can use the implemented hwCPUVoltage() function.
I tried this function call on an nRF52 DK, and it seems to work. I then tried it on an Ebyte module, treated as an nRF52 DK "board", and it reported zero voltage. So, probably I just need to do a pin mapping so that it reads the voltage on the proper pin. But which pin/mapping would it be? I thought that Vcc wouldn't really be mappable to anything but Vcc. I guess whichever analog pin (if that's what it is?) is connected to Vcc on the nRF52 DK is the pin I need to find and re-map to its equivalent pin on the Ebyte module. Hmmm.... I'll have to look into which one that would be.
@NeverDie said in nRF5 Bluetooth action!:
I tried this function call on an nRF52 DK, and it seems to work. I then tried it on an Ebyte module, treated as an nRF52 DK "board", and it reported zero voltage.
I have tried the hwCPUVoltage() function with an Ebyte and an RedBear module. Both modules are reporting the voltage.
-
Received a new module. Here's a size comparison with the Ebyte Module:


-
Breakout board for the Ebyte nRF52832 module is now completed:
https://www.openhardware.io/view/436/nRF52832-Breakout-Board#tabs-comments -
Breakout board for the Ebyte nRF52832 module is now completed:
https://www.openhardware.io/view/436/nRF52832-Breakout-Board#tabs-comments -
@NeverDie Dam you why would you make it so wide? can it fit on a single bread board?
Also how did you get those so fast?
@Mike_Lemo said in nRF5 Bluetooth action!:
Dam you why would you make it so wide?
In 20/20 hindsight, you're right. At the time I designed it I had huge concerns that the range on the nRF52832 might be awful, because the Adafruit nRF52832 feather that I tested had poor range. So, I gave it a very large ground plane to see if maybe that cured the problem. Only later did I receive the Ebyte module, which turned out to have good range even by itself.
can it fit on a single bread board?
Sorry, you'll need two.
Also how did you get those so fast?
OSH PARK averages around two weeks for me. That's the main reason why I buy from them.
-
@mtiutiu said in nRF5 Bluetooth action!:
@NeverDie
Where did you get that small nrf52832 module? -
@mtiutiu said in nRF5 Bluetooth action!:
@NeverDie
Where did you get that small nrf52832 module? -
@NeverDie I guess you don't need to make a breakout board for those, your spare NModules will do if you use the "PA/LNA" radio footprint ;)
-
Just realized it has 2 extra I/O on the side, and the SWD are only pads on top, which makes 8 I/O available, it's much more interesting than the NRF51822 version.
-
Just realized it has 2 extra I/O on the side, and the SWD are only pads on top, which makes 8 I/O available, it's much more interesting than the NRF51822 version.
-
@Nca78
Is there even a way to program the nRF51822 version? I'd have to check, but I don't recall the two SWD pins being on its pinout.@NeverDie said in nRF5 Bluetooth action!:
@Nca78
Is there even a way to program the nRF51822 version? I'd have to check, but I don't recall the two SWD pins being on its pinout.They are on the pinout, so you only have 4 I/Os available.
-
@NeverDie said in nRF5 Bluetooth action!:
I tried this function call on an nRF52 DK, and it seems to work. I then tried it on an Ebyte module, treated as an nRF52 DK "board", and it reported zero voltage.
I have tried the hwCPUVoltage() function with an Ebyte and an RedBear module. Both modules are reporting the voltage.
@d00616 said in nRF5 Bluetooth action!:
I have tried the hwCPUVoltage() function with an Ebyte and an RedBear module. Both modules are reporting the voltage.
That's good news. There must be something wrong with how I'm doing it. Which board type are you using for the Ebyte module?
-
From what I understand the NRF52832 has some kind of enforcer that allows different serial hardwares to be assigned to different pins
Now using the arduino IDE I want to use the I2C pins that are assigned hardwarely to different pins here is the situation
I have one PCB that has SCL connected to pin 20 and SDA to 21
and another PCB that has SCL connected to pin 11 and SDA to pin 12
I want to define the enforcer for the pins within their dedicated sketches without running around to the internal arduino files and change the pin assignment for each upload to each board.
How'd I do that? I assume you'd have to do some thing like that in the upper side of the personal code.
#define SDL...(Something else I don't know ) 11
#define SDA...(Something else I don't know ) 12 -
I think I have a better hypothesis as to what's going on in my situation: the ebyte module is getting hung-up trying to establish communication with the serial gateway. Looking at the output of the serial gateway, it looks as though it is receiving packets from the Ebyte module. However, looking at the Ebyte output, it thinks it is failing. So, the Ebyte never quite gets out of the "establish communication link" mode.
This doesn't occur, though, if I use an nRF52 DK, instead of an Ebyte module.
So, what might explain this is maybe the MISO pin on the Ebyte module isn't mapped right.
@d00616 Would you please share the pin mappings and board type that you are using for your ebyte module? Since you are having success, I think that will fix the problem.