nRF5 action!
-
@Nca78 said in nRF5 Bluetooth action!:
If supplied with less than 3.6V you can do it with ADC, 1.2V voltage reference and 1/3 prescaling.
But I've only looked at the theory yet.For this, you can use the implemented hwCPUVoltage() function. Reading the voltage costs nRF51: 260µA/20µs | nRF52: 700µA/3µs
-
@d00616 said in nRF5 Bluetooth action!:
hwCPUVoltage()
I'm finally installing Visual Micro, because I hope it will help me quickly find where all these functions are defined. With all these new layers, the Arduino IDE is just no longer cutting it.
-
LOL. Well, Visual Micro found it alright, but just in the wrong place. It found it in MyHwAVR.cpp
-
@NeverDie said in nRF5 Bluetooth action!:
@d00616 said in nRF5 Bluetooth action!:
hwCPUVoltage()
I'm finally installing Visual Micro, because I hope it will help me quickly find where all these functions are defined. With all these new layers, the Arduino IDE is just no longer cutting it.
good choice
for nrf5, the function is located in MyHwNRF5.cpp
-
@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.
-
Actually, something different may be going on. Here's the function definition:
uint16_t hwCPUVoltage() { // 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 }
One, perhaps likely, theory would be that it doesn't recognize the MCU, which would explain why it returns the value of zero. Well, to debug that, I added the Serial.println(...) statements into the library code (see above) in an attempt to see which of the if-else branches is being taken, but none of the Serial.println(...)'s were printed! Here's a sample of the output from the Ebyte Module:
332641 TSF:MSG:SEND,255-255-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK: 332968 TSF:MSG:READ,0-0-255,s=255,c=3,t=8,pt=1,l=1,sg=0:0 332973 TSF:MSG:FPAR OK,ID=0,D=1 334649 TSM:FPAR:OK 334650 TSM:ID 334651 TSM:ID:REQ 334654 TSF:MSG:SEND,255-255-0-0,s=59,c=3,t=3,pt=0,l=0,sg=0,ft=0,st=OK: 336662 TSM:ID 336663 TSM:ID:REQ 336665 TSF:MSG:SEND,255-255-0-0,s=23,c=3,t=3,pt=0,l=0,sg=0,ft=0,st=OK: 338673 TSM:ID 338674 TSM:ID:REQ 338676 TSF:MSG:SEND,255-255-0-0,s=242,c=3,t=3,pt=0,l=0,sg=0,ft=0,st=OK: 340684 TSM:ID 340685 TSM:ID:REQ 340687 TSF:MSG:SEND,255-255-0-0,s=205,c=3,t=3,pt=0,l=0,sg=0,ft=0,st=OK: 342695 !TSM:ID:FAIL 342696 TSM:FAIL:CNT=7 342698 TSM:FAIL:DIS 342700 TSF:TDI:TSL 402703 TSM:FAIL:RE-INIT 402705 TSM:INIT 402706 TSM:INIT:TSP OK 402708 TSM:FPAR 402711 TSF:MSG:SEND,255-255-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK: 403472 TSF:MSG:READ,0-0-255,s=255,c=3,t=8,pt=1,l=1,sg=0:0 403478 TSF:MSG:FPAR OK,ID=0,D=1 404719 TSM:FPAR:OK 404720 TSM:ID 404721 TSM:ID:REQ 404724 TSF:MSG:SEND,255-255-0-0,s=241,c=3,t=3,pt=0,l=0,sg=0,ft=0,st=OK: 406732 TSM:ID 406733 TSM:ID:REQ 406735 TSF:MSG:SEND,255-255-0-0,s=205,c=3,t=3,pt=0,l=0,sg=0,ft=0,st=OK: 408743 TSM:ID 408744 TSM:ID:REQ 408747 TSF:MSG:SEND,255-255-0-0,s=168,c=3,t=3,pt=0,l=0,sg=0,ft=0,st=OK: 410754 TSM:ID 410755 TSM:ID:REQ 410757 TSF:MSG:SEND,255-255-0-0,s=131,c=3,t=3,pt=0,l=0,sg=0,ft=0,st=OK: 412765 !TSM:ID:FAIL 412766 TSM:FAIL:CNT=7 412768 TSM:FAIL:DIS 412770 TSF:TDI:TSL 472773 TSM:FAIL:RE-INIT 472775 TSM:INIT 472776 TSM:INIT:TSP OK 472778 TSM:FPAR 472781 TSF:MSG:SEND,255-255-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK: 472955 TSF:MSG:READ,0-0-255,s=255,c=3,t=8,pt=1,l=1,sg=0:0 472960 TSF:MSG:FPAR OK,ID=0,D=1 474789 TSM:FPAR:OK 474790 TSM:ID 474791 TSM:ID:REQ 474794 TSF:MSG:SEND,255-255-0-0,s=167,c=3,t=3,pt=0,l=0,sg=0,ft=0,st=OK: 476802 TSM:ID 476803 TSM:ID:REQ 476805 TSF:MSG:SEND,255-255-0-0,s=131,c=3,t=3,pt=0,l=0,sg=0,ft=0,st=OK: 478813 TSM:ID 478814 TSM:ID:REQ 478816 TSF:MSG:SEND,255-255-0-0,s=94,c=3,t=3,pt=0,l=0,sg=0,ft=0,st=OK: 480824 TSM:ID 480825 TSM:ID:REQ 480827 TSF:MSG:SEND,255-255-0-0,s=57,c=3,t=3,pt=0,l=0,sg=0,ft=0,st=OK: 482835 !TSM:ID:FAIL 482836 TSM:FAIL:CNT=7 482838 TSM:FAIL:DIS 482840 TSF:TDI:TSL
I'm not quite sure how to interpret that, but pretty clearly it doesn't contain the println's that I was expecting.
Any theories as to what's going on?
-
Bracketing that and setting it aside, I do now notice this line in the BatteryPoweredSensor demo sketch:
int BATTERY_SENSE_PIN = A0; // select the input pin for the battery sense point
So, if I map that A0 in the sketch to the A0 of the Ebyte Module, then maybe (hopefully) the voltage measurement will work on the Ebyte Module. I'll give it a try.
-
Unfortunately, after I add:
#include <mySensors.h>
the locus of control goes somewhere else (I guess the gateway or something?). Anyhow, it makes this very hard to debug.
For instance, the pin of interest is PIN_AIN0. I can't find where it's defined, and I can't print out its value either, because of this locus of control issue.
Anyhow, I think I may wait for others to get up and running with their modules, and start facing the same issues. Maybe then we can help each other figure this stuff out.
-
@NeverDie I don't know why the println() doesn't work. There is an "DEBUG_OUTPUT(x, ##VA_ARGS)" macro, you can use when debug is enabled.
NRF_ADC is the nRF51 ADC and NRF_SAADC is the ADC of the nRF52. They are defined when "nrf.h" is included.
What board type have use used for your tests?
-
@d00616 said in nRF5 Bluetooth action!:
What board type have use used for your tests?
The nRF52832 Ebyte Module.
-
@NeverDie VS Code with the Arduino Extension is your friend.
-
@d00616 said in nRF5 Bluetooth action!:
What board type have use used for your tests?
I just re-read your question and realized you were asking something else than the question that I answered above.
Answer: nRF52 DK is the board type, because I wired directly to P0.06 as its Tx pin on the Ebyte nRF52832 Module.
-
@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.
-
@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
-
@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.
-
@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
-
@Nca78
Thanks! Good to know.
-
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.
-
@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.
-
Does anybody know why the function tone() doesn't work for the nrf52?
-
@Mike_Lemo could you be slightly more specific than "doesn't work"?
-
@mfalkvidd said in nRF5 Bluetooth action!:
@Mike_Lemo could you be slightly more specific than "doesn't work"?
apparently it doesn't recognize it says tone wasn't declared in this scope
That's how the line looks tone(BUZZER_PIN, BUZZER_TONE);
BUZZER_PIN = 26
BUZZER_TONE = 3000
-
@Mike_Lemo if you mean the stuff described at https://www.arduino.cc/en/Reference/Tone it's because it only supports the following mcus:
ATmega8
ATmega168/328
ATmega1280
-
@mfalkvidd said in nRF5 Bluetooth action!:
@Mike_Lemo if you mean the stuff described at https://www.arduino.cc/en/Reference/Tone it's because it only supports the following mcus:
ATmega8
ATmega168/328
ATmega1280How is it possible to make it copatible with the NRF52?
-
@Mike_Lemo it (the tone library) would need to be ported
-
@mfalkvidd said in nRF5 Bluetooth action!:
@Mike_Lemo it would need to be ported
No idea what you are talking about.
-
@Mike_Lemo look it up? https://en.wikipedia.org/wiki/Software_portability#Effort_to_port_source_code
-
@NeverDie said in nRF5 Bluetooth action!:
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.
Some further evidence in support of this hypothesis (from: https://github.com/mysensors/ArduinoHwNRF5
Most components, like UART, SPI, Wire Bus, of the nRF5 series chips don't have a fixed pin mapping.
-
@mfalkvidd said in nRF5 Bluetooth action!:
@Mike_Lemo look it up? https://en.wikipedia.org/wiki/Software_portability#Effort_to_port_source_code
Well apperantly this function uses a PWM pin at 50% duty but the frequency varies according to the functiong user parameter now I just know how to active a PWM pin at 50% duty but not how to acces the NRF52 registers to change the frequency of the PWM.
I don't realy know how to access the registers you see at the product's PDF and the other process.
-
Someone managed to get NFC to work with this IC on the arduino IDE?
-
Does the nRF52 mcu communicate with its radio using SPI, or some other bus? Or are all the radio registers simply memory mapped?
@NeverDie said in nRF5 Bluetooth action!:
Some further evidence in support of this hypothesis (from: https://github.com/mysensors/ArduinoHwNRF5
Most components, like UART, SPI, Wire Bus, of the nRF5 series chips don't have a fixed pin mapping.
Well, if the mcu uses SPI to communicate with the radio, then I simply need to define which SPI "pins" those are. Attached is the pin mapping file that I used to successfully map the pins for Rx and Tx.
0_1501606355303_MyNRF5Board.cpp
-
@NeverDie if I'm not wrong you managed to connect the Ebyte module to your MySensors network, no ?
I did it anyway and it received data.
Radio is internally connected inside the nrf52 chip so I don't see how a module could have a different mapping ?
-
@Nca78 said in nRF5 Bluetooth action!:
Radio is internally connected inside the nrf52 chip so I don't see how a module could have a different mapping ?
Yeah, that's what I thought originally, and it probably is true. I'm just grasping at straws to understand why the "board" type seems to be affecting the radio communications. I'm also completely new to the mysensors way of handling radio, so that's getting in my way. I'm might have to try something more barebones before I can make sense of this.
-
Some Nordic guidance might help.
Building Bluetooth-Connected IoT Wireless Sensor Prototypes with Minimal Effort
-
I've confirmed it now. Even if I comment out all apparent radio message sends, the mere act of including:
#include <MySensors.h>
results in a loss of control by the sketch itself to something within MySensors that wants to establish communication between the node and the gateway. Not even sure how that is happening. In any case, it is just overcomplicating the debugging, and I really don't want that right now because it is effectively hanging what I'm trying to do.
For now, all I want is a simple send packet--like either the mirf or the twh20 libraries have for the nRF24L01--with no complicating factors. Is that too much to ask? I can probably find that somewhere within the library, but how do I turn-off this loop that it's in where it's repetitively trying to establish the initial communication with the serial gateway?
-
@NeverDie said in nRF5 Bluetooth action!:
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?
I have the equal module like yours.
@NeverDie said in nRF5 Bluetooth action!:
@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.
The module is connected to SWDIO/CLK, VCC and the GND near the radio. I don't remember which pin I used for Serial TX.
@NeverDie said in nRF5 Bluetooth action!:
Does the nRF52 mcu communicate with its radio using SPI, or some other bus? Or are all the radio registers simply memory mapped?
The registers are memory mapped, the data transferred with "EasyDMA" into the memory.
@NeverDie said in nRF5 Bluetooth action!:
I've confirmed it now. Even if I comment out all apparent radio message sends, the mere act of including: '#include <MySensors.h>' results in a loss of control by the sketch itself to something within MySensors that wants to establish communication between the node and the gateway.
The SecurityPersonalizer defines '#define MY_CORE_ONLY' before including 'MySensors.h'. In theory, you can use the radio functions defined in 'hal/transport/MyTransportHAL.h' directly. I had no luck with this, but I haven't invested time to debug this.
-
@Mike_Lemo said in nRF5 Bluetooth action!:
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 ) 12You have to install the "MySensors nRF5 Boards" package. In the examples section for this package, you can find two files (MyNRF5Board.h + MyNRF5Board.cpp). Add these files to your sketch and compile it using "MyNRF5Board nRF52822" as you board.
@Mike_Lemo said in nRF5 Bluetooth action!:
Well apperantly this function uses a PWM pin at 50% duty but the frequency varies according to the functiong user parameter now I just know how to active a PWM pin at 50% duty but not how to acces the NRF52 registers to change the frequency of the PWM.
The registers are documented in the Infocenter and the bitfields.
I don't realy know how to access the registers you see at the product's PDF and the other process.
To access the registers, you have to add '#include <nrf.h>' to your code. Mostly the hardware is accesses by NRF_HWNAME->REGISTER
Doing PWM is a little bit complex. The code is different for nRF51 and nRF52. Look into wiring_analog_nRF51.c and (wiring_analog_nRF51.c)[https://github.com/sandeepmistry/arduino-nRF5/blob/c98a190eb34c0247eb8e0764a6367c7f9e51d2fc/cores/nRF5/wiring_analog_nRF52.c#L214]
If you clone this code, for nRF52 you have to use another timer, like TIMER2, because you can't define the interrupt routine twice.
-
So I'm trying to program the S4AT modules and I have the ugly message
** Programming Started ** auto erase enabled Info : nRF51822-QFAA(build code: H0) 256kB Flash Error: Cannot erase protected sector at 0x0 Error: failed erasing sectors 0 to 13 embedded:startup.tcl:454: Error: ** Programming Failed **
I tried to use JLink programs but it says it cannot connect to the module, so I cannot unlock (ends with timeout message) and I cannot erase (fails with -1 return value)...
Does that mean I have to go the long hard way with a bluepill as programmer and openocd ? Anyone has other ideas to unlock and erase the device ?
-
@Nca78 said in nRF5 Bluetooth action!:
Does that mean I have to go the long hard way with a bluepill as programmer and openocd ? Anyone has other ideas to unlock and erase the device ?
Select in to Tools menu "None" Softdevice and then "Burn Bootloader". This raises an error but the device is erased completely.
-
@d00616 said in nRF5 Bluetooth action!:
Select in to Tools menu "None" Softdevice and then "Burn Bootloader". This raises an error but the device is erased completely.
Thank you it works !
That's probably when trying to use this function that I managed to unlock&erase the EByte module "by mistake"The only problem now is the range seems to be very bad
Less than 10m with just a brick wall and it fails to completely send the presentation messages.
EBytes nrf52832 module works well in the same conditions, same for their nrf24 modules.[Edit] in fact not that bad, it works ok when changing the orientation of the module. Could be due to the funky wiring but my bet is it on the tiny antenna design. My gateway is an old through hole nrf24 clone so range should not be a problem in an appartment with a PA/LNA gateway.
-
@d00616 said in nRF5 Bluetooth action!:
The registers are memory mapped, the data transferred with "EasyDMA" into the memory.
In this case I'm going to try a different Ebyte module. Maybe the one I'm using is defective or somehow became damaged.
-
@d00616 said in nRF5 Bluetooth action!:
Select in to Tools menu "None" Softdevice and then "Burn Bootloader". This raises an error but the device is erased completely.
I'm happy to report this also worked when, just now, I programmed a new Ebyte module. Like d00616 said earlier, it's a much faster way to do a mass erase.
Unfortunately, and in contrast with the nRF52 DK, the new Ebyte module I just programmed is behaving the same as the Ebyte I've been experimenting with. No change.
-
I will test tomorrow with the Ebyte module I have soldered, and the reset pin too.
-
@d00616 said in nRF5 Bluetooth action!:
MySensors nRF5 Boards
Thanks for the caring replay.
I couldn't find that exact "MySensors nRF5 Boards" library you were talking about also what is the purpose of this library anyways?
Do you know where can the arduino library folder be found with all the arduino functions?
-
@Mike_Lemo it is here :
https://github.com/mysensors/ArduinoHwNRF5Scroll up in this thread for more details, or read the documentation there.
-
@Mike_Lemo said in nRF5 Bluetooth action!:
I couldn't find that exact "MySensors nRF5 Boards" library you were talking about also what is the purpose of this library anyways?
Follow the instructions for ArduinoBoards and ArduinoHwNRF5
Do you know where can the arduino library folder be found with all the arduino functions?
The arduino-nrf5 port only implements functionality documented in the official Arduino Reference but mostly not more functionality available for SAMD :-(. Additional functionality like BLE or using included hardware must come from external libraries like MySensors.
A good way to implement the tone commands is to fork the arduino-nRF5 repository at github. Change what you need and create an pull request with reference to the Arduino reference. If you inform me about your PR I comment it to increase the chance for acceptance otherwise it's time to maintain an separate fork of this repository.
-
@Nca78 said in nRF5 Bluetooth action!:
I will test tomorrow with the Ebyte module I have soldered, and the reset pin too.
That would be great! Please try the BatteryPoweredSensor sketch when you do. I'm very curious if you will have the same or different result as what I'm getting.
-
@d00616 said in nRF5 Bluetooth action!:
@Mike_Lemo said in nRF5 Bluetooth action!:
I couldn't find that exact "MySensors nRF5 Boards" library you were talking about also what is the purpose of this library anyways?
Follow the instructions for ArduinoBoards and ArduinoHwNRF5
Do you know where can the arduino library folder be found with all the arduino functions?
The arduino-nrf5 port only implements functionality documented in the official Arduino Reference but mostly not more functionality available for SAMD :-(. Additional functionality like BLE or using included hardware must come from external libraries like MySensors.
A good way to implement the tone commands is to fork the arduino-nRF5 repository at github. Change what you need and create an pull request with reference to the Arduino reference. If you inform me about your PR I comment it to increase the chance for acceptance otherwise it's time to maintain an separate fork of this repository.
that actually caused more trouble won't even let me compile the blank included example code.
-
@Mike_Lemo said in nRF5 Bluetooth action!:
that actually caused more trouble won't even let me compile the blank included example code.
Are you talking about the MyNRF5Board example? Arduino IDE compiles it for me without any complaints.
-
@NeverDie When choosing "MyNRF5Board nrf52832"?
-
-
At some point, I had to re-arrange the libraries though (don't remember which files or which ones) to get all this stuff working. Before that, it wasn't finding the files. Actually, I think this would be a good topic for discussion, to make sure we're all doing it the same way. If we're doing it differently, it might make cross-checking each others attempts more difficult. Also, maybe there's a better way than the brute-force way that I did it.
If anyone has interest, I can post how my libraries are currently structured. If nothing else, it would be a starting point for discussion on what to do (or not to do).
-
@NeverDie said in nRF5 Bluetooth action!:
At some point, I had to re-arrange the libraries though (don't remember which files or which ones) to get all this stuff working. Before that, it wasn't finding the files. Actually, I think this would be a good topic for discussion, to make sure we're all doing it the same way. If we're doing it differently, it might make cross-checking each others attempts more difficult. Also, maybe there's a better way than the brute-force way that I did it.
If anyone has interest, I can post how my libraries are currently structured. If nothing else, it would be a starting point for discussion on what to do (or not to do).
Dunno that whole arduino BRF52832 programming thing seems too complicated just started to learn how to use the nordic SDK with eclipse until a proper solution is found.
-
@Mike_Lemo said in nRF5 Bluetooth action!:
Dunno that whole arduino BRF52832 programming thing seems too complicated just started to learn how to use the nordic SDK with eclipse until a proper solution is found.
It hasn't been easy, I'll grant you that. I get the impression d00616 probably does most of his work in Linux, and so some of the disconnect with the Windows IDE probably stems from that. Once we get the basics ironed out, though, I expect things will go more smoothly. In fact, I think we're almost there. A lot of the work for sleeping, measuring source voltage, etc., has already been done, which is far better than starting from scratch. And there's even example code, which helps tremendously.
-
Good news! Interestingly enough, the MockMySensors sketch seems to work fine when I load it onto the Ebyte. What a relief! So, I may try hijacking that sketch to convey voltage measurements instead of the BatteryPoweredSensor sketch that mysteriously hasn't been working on my Ebyte modules.
-
@Mike_Lemo said in nRF5 Bluetooth action!:
Dunno that whole arduino BRF52832 programming thing seems too complicated just started to learn how to use the nordic SDK with eclipse until a proper solution is found.
The Nordic SDK is more complete than Arduino-nrf5 at the moment, but there is no compatibility with MySensors.
The good news, with SDK 13 the 'Nordic Semiconductor ASA' License was changed. The old ASA was the reason for me to rewrite the complete ESB protocol. Now the license is much less restrictive. I think now the way is open to integrate SDK code into arduino-nrf5 or provide SDK based arduino-libraries.
@NeverDie said in nRF5 Bluetooth action!:
It hasn't been easy, I'll grant you that. I get the impression d00616 probably does most of his work in Linux, and so some of the disconnect with the Windows IDE probably stems from that.
I can't change the way of Windows driver handling, but when there are Windows specific issues then they bust be fixed.
-
@d00616 said in nRF5 Bluetooth action!:
@Mike_Lemo said in nRF5 Bluetooth action!:
Dunno that whole arduino BRF52832 programming thing seems too complicated just started to learn how to use the nordic SDK with eclipse until a proper solution is found.
The Nordic SDK is more complete than Arduino-nrf5 at the moment, but there is no compatibility with MySensors.
The good news, with SDK 13 the 'Nordic Semiconductor ASA' License was changed. The old ASA was the reason for me to rewrite the complete ESB protocol. Now the license is much less restrictive. I think now the way is open to integrate SDK code into arduino-nrf5 or provide SDK based arduino-libraries.
.
You mean way more complete every thing is accesable there and there is an example for everything and I didn't use my sensors anyways
-
@Mike_Lemo said in nRF5 Bluetooth action!:
You mean way more complete every thing is accesable there and there is an example for everything and I didn't use my sensors anyways
No. I mean if you want to use the Nordic MCU with BLE and you want to access the whole hardware without developing drivers, then the Nordic SDK is an option. For special requirements like tone() you have to develop your own routine for Arduino or SDK.
If you want write code which is compatible with other Vendors or want use MySensors then the SDK isn't the best choice.
The arduino-nrf5 targets to provide the Arduino language. I think this is mostly complete. MySensors brings additional support for enhanced pin output modes and the random number generator (no SoftDevice support here).
Accessing the internal MCU hardware must be added via Arduino libraries. With the new SDK license I think it's possible to put parts of the SDK into libraries supporting Hardware which is not specified in the Arduino reference.
If you want to develop BLE applications with portable code, there are open source implementations like http://mynewt.apache.org/ which are designed to be portable.
-
Good news! The hwCPUVoltage() function measures the Vcc voltage on the Ebyte module in millivolts. I'm able to send that as a barometer reading using the mocksensors sketch, and it arrives all the way into Domoticz, where it is logged and graphed. So, obviously I need to streamline that a bit, but the proof of concept works.
-
Quantization error on the hwCpuVoltage() function appears to about 14 millivolts, which is a nice little improvement over the atmega328p. Measurement accuracy appears to be well within those bounds.
Next step is to measure voltage on an analog pin using an AnalogRead. Not sure if the reference voltage is Vcc (as it typically is with the atmega328p) or something else for those measurements.
-
Given new Arduino Primo contains a buzzer connected to nrf52, we might expect tone() function to be compatible with nrf52 very soon
https://www.arduino.cc/en/uploads/Main/ARDUINO_PRIMO-V022_SCH.pdf
-
@NeverDie said in nRF5 Bluetooth action!:
Quantization error on the hwCpuVoltage() function appears to about 14 millivolts, which is a nice little improvement over the atmega328p. Measurement accuracy appears to be well within those bounds.
Next step is to measure voltage on an analog pin using an AnalogRead. Not sure if the reference voltage is Vcc (as it typically is with the atmega328p) or something else for those measurements.
Strangely, if I do, say, analogRead(A4) on the nRF52832, all I get back is a 10-bit number, not a 12-bit number. i.e. the number never exceeds 1023. That can't be right. Should I be using a different function call to get the full 12 bits on the nRF52832?
-
@NeverDie looks like you need to call analogReadResolution first https://github.com/sandeepmistry/arduino-nRF5/blob/425e719af8d85b543def01e49a6ef4048525dc59/cores/nRF5/wiring_analog.h#L74
-
@mfalkvidd said in nRF5 Bluetooth action!:
@NeverDie looks like you need to call analogReadResolution first https://github.com/sandeepmistry/arduino-nRF5/blob/425e719af8d85b543def01e49a6ef4048525dc59/cores/nRF5/wiring_analog.h#L74
Thanks! That did the trick. Calling analogReadResolution(12) once in Setup() routine, I now get back a 12-bit number (i.e. up to 4095) thereafter when I do an analogRead(...).
-
So, just did the experiment, and here are the results. Supplying 3.3v to the Ebyte Module, a voltage of 3.0 volts on A4 yields an analogRead(A4) of 4095. Less voltage on A4 yields a lower number.
So, generalizing, I suspect that the reference voltage for analogRead() is Vcc-0.3.
So, you either know Vcc, because of a voltage regulator or something, or else you must call hwCpuVoltage() to get what it is. Then, subtract 0.3v from that, and that's the reference voltage which corresponds to an analogRead() return value of 4095.
-
I just did a quick and dirty measurement on the current consumption of the nRF52832 Ebyte module during sleep, and it measured 10 milliamps. I measured it using a uCurrent Gold. That's very high current for most battery powered applications. Can someone else here please measure it also and either confirm or refute?
I invoked sleep with this from the mocksensors sketch:
wait(SLEEP_TIME); //sleep a bit
Perhaps there's a way to invoke a deeper sleep than that where less current is drawn?
-
@NeverDie
Trysleep(60000); // Sleeps for a minute in deep sleep
-
@rmtucker said in nRF5 Bluetooth action!:
sleep(60000); // Sleeps for a minute in deep sleep
Thanks! That's a big improvement. I'm now reading 51uA. I did the measurements on the Ebyte nRF52832 module, powering it at 3.3v.
However, to be frank, that's still rather high compared to, say, an atmega328p with a RFM69 radio, which can have a combined sleep current of less than 1uA.
Is there anything more that can be done to lower the sleep current further?
-
Is that a bare board with nothing connected (Not even serial)?
-
@rmtucker said in nRF5 Bluetooth action!:
Is that a bare board with nothing connected (Not even serial)?
Yes. It's the bare Ebyte nRF52832 module. The only connections are Vcc and GND.
-
Theoretically it should be around 1.9uA
-
Interestingly, I just now tried the same measurement with one of these nRF52832 modules instead of the Ebyte module:
https://www.aliexpress.com/item/nRF52832-Bluetooth-4-1-BLE-Module-M4-Transparent-Transmission-SMA-512K-FLASH-64K-RAM-pass-through/32798522093.html?spm=a2g0s.9042311.0.0.KKA3PF
and during sleep it measured 6uA. Quite a bit lower!Anyone know of a module which tests even lower than that?
-
@NeverDie said in nRF5 Bluetooth action!:
Interestingly, I just now tried the same measurement with one of these nRF52832 modules instead of the Ebyte module:
https://www.aliexpress.com/item/nRF52832-Bluetooth-4-1-BLE-Module-M4-Transparent-Transmission-SMA-512K-FLASH-64K-RAM-pass-through/32798522093.html?spm=a2g0s.9042311.0.0.KKA3PF
and during sleep it measured 6uA. Quite a bit lower!Anyone know of a module which tests even lower than that?
Did you use the same board definition in the IDE and the same script ?
-
@Nca78 said in nRF5 Bluetooth action!:
Did you use the same board definition in the IDE and the same script ?
Yes.
-
@NeverDie
Have you tried sleep and wait for an external interrupt instead of sleep and wake on timer?
Just in case it is the lfxtl that is causing the problem.
-
@rmtucker said in nRF5 Bluetooth action!:
@NeverDie
Have you tried sleep and wait for an external interrupt instead of sleep and wake on timer?
Just in case it is the lfxtl that is causing the problem.Haven't tried that yet. Is there a library functional call for that, or do I need to start addressing the registers directly? With this new mpu, I feel like I'm learning to walk all over again.
-
-
@rmtucker said in nRF5 Bluetooth action!:
Try
sleep(digitalPinToInterrupt(10), FALLING,0);
Unexpected result: using that as the sleep invocation, the infor-link module measures at 14ua while sleeping. i.e. worse, not better, compared to the 6ua measured earlier.
-
Looks as though the infor-link is using an A620N crystal:
I tried to see if I could find a datasheet for it, in the hope of learning what its current consumption is (or, at least, should be). Unfortunately, though, I couldn't find a datasheet for an A620N.
-
Maybe it doesn't matter, because in looking at the actual module I received, it appears to use a different XTAL anyway: A649N.
-
Maybe from a current consumption standpoint, not using an external XTAL crystal, but rather relying on the nRF52832's internal resonator would draw less current? I know that's true for the atmega328p. If so, then that's a trade-off worth examining more carefully.
-
Sorry i have been a little distracted because my waveshare BLE400 and jlink just turned up.
Took a little time to get it running but i loaded up the mockmysensors sketch with all the sensors un commented and pow all 30 odd sensors showed up in domoticz which made me chuckle.
Anyway post your sketch for the consumption testing and i will put it in and see if it works on my board.
The only problem is i can not unplug it from the Ble400 because i have no way of connecting wires to the core board because of the smaller pitch pins.
-
@rmtucker
Here's the sketch I tested with:/* * MockMySensors * * This skecth is intended to crate fake sensors which register and respond to the controller * *** * Barduino 2015, GizMoCuz 2015 */ // Enable debug prints to serial monitor #define MY_DEBUG // Enable and select radio type attached //#define MY_RADIO_NRF24 #define MY_RADIO_NRF5_ESB //#define MY_RADIO_RFM69 //#define MY_RADIO_RFM95 #define MY_NODE_ID 254 #include <MySensors.h> #define RADIO_ERROR_LED_PIN 4 // Error led pin #define RADIO_RX_LED_PIN 6 // Receive led pin #define RADIO_TX_LED_PIN 5 // the PCB, on board LED // Wait times #define LONG_WAIT 500 #define SHORT_WAIT 50 #define SKETCH_NAME "MockMySensors " #define SKETCH_VERSION "v0.5" // Define Sensors ids /* S_DOOR, S_MOTION, S_SMOKE, S_LIGHT, S_DIMMER, S_COVER, S_TEMP, S_HUM, S_BARO, S_WIND, S_RAIN, S_UV, S_WEIGHT, S_POWER, S_HEATER, S_DISTANCE, S_LIGHT_LEVEL, S_ARDUINO_NODE, S_ARDUINO_REPEATER_NODE, S_LOCK, S_IR, S_WATER, S_AIR_QUALITY, S_CUSTOM, S_DUST, S_SCENE_CONTROLLER */ ////#define ID_S_ARDUINO_NODE //auto defined in initialization ////#define ID_S_ARDUINO_REPEATER_NODE //auto defined in initialization // Some of these ID's have not been updated for v1.5. Uncommenting too many of them // will make the sketch too large for a pro mini's memory so it's probably best to try // one at a time. //#define ID_S_ARMED 0 // dummy to controll armed stated for several sensors //#define ID_S_DOOR 1 //#define ID_S_MOTION 2 //#define ID_S_SMOKE 3 //#define ID_S_LIGHT 4 //#define ID_S_DIMMER 5 //#define ID_S_COVER 6 //#define ID_S_TEMP 7 //#define ID_S_HUM 8 #define ID_S_BARO 9 //#define ID_S_WIND 10 //#define ID_S_RAIN 11 //#define ID_S_UV 12 //#define ID_S_WEIGHT 13 //#define ID_S_POWER 14 //#define ID_S_HEATER 15 //#define ID_S_DISTANCE 16 //#define ID_S_LIGHT_LEVEL 17 //#define ID_S_LOCK 18 //#define ID_S_IR 19 //#define ID_S_WATER 20 //#define ID_S_AIR_QUALITY 21 //#define ID_S_DUST 22 //#define ID_S_SCENE_CONTROLLER 23 //// Lib 1.5 sensors //#define ID_S_RGB_LIGHT 24 //#define ID_S_RGBW_LIGHT 25 //#define ID_S_COLOR_SENSOR 26 //#define ID_S_HVAC 27 //#define ID_S_MULTIMETER 28 //#define ID_S_SPRINKLER 29 //#define ID_S_WATER_LEAK 30 //#define ID_S_SOUND 31 //#define ID_S_VIBRATION 32 //#define ID_S_MOISTURE 33 // //#define ID_S_CUSTOM 99 // Global Vars unsigned long SLEEP_TIME = 3600000; // Sleep time between reads (in milliseconds) bool metric = true; long randNumber; //Instanciate Messages objects #ifdef ID_S_ARMED bool isArmed; #endif #ifdef ID_S_DOOR // V_TRIPPED, V_ARMED MyMessage msg_S_DOOR_T(ID_S_DOOR,V_TRIPPED); MyMessage msg_S_DOOR_A(ID_S_DOOR,V_ARMED); #endif #ifdef ID_S_MOTION // V_TRIPPED, V_ARMED MyMessage msg_S_MOTION_A(ID_S_MOTION,V_ARMED); MyMessage msg_S_MOTION_T(ID_S_MOTION,V_TRIPPED); #endif #ifdef ID_S_SMOKE // V_TRIPPED, V_ARMED MyMessage msg_S_SMOKE_T(ID_S_SMOKE,V_TRIPPED); MyMessage msg_S_SMOKE_A(ID_S_SMOKE,V_ARMED); #endif #ifdef ID_S_LIGHT MyMessage msg_S_LIGHT(ID_S_LIGHT,V_LIGHT); bool isLightOn=0; #endif #ifdef ID_S_DIMMER MyMessage msg_S_DIMMER(ID_S_DIMMER,V_DIMMER); int dimmerVal=100; #endif #ifdef ID_S_COVER MyMessage msg_S_COVER_U(ID_S_COVER,V_UP); MyMessage msg_S_COVER_D(ID_S_COVER,V_DOWN); MyMessage msg_S_COVER_S(ID_S_COVER,V_STOP); MyMessage msg_S_COVER_V(ID_S_COVER,V_VAR1); int coverState=0; //0=Stop; 1=up; -1=down #endif #ifdef ID_S_TEMP MyMessage msg_S_TEMP(ID_S_TEMP,V_TEMP); #endif #ifdef ID_S_HUM MyMessage msg_S_HUM(ID_S_HUM,V_HUM); #endif #ifdef ID_S_BARO MyMessage msg_S_BARO_P(ID_S_BARO,V_PRESSURE); //MyMessage msg_S_BARO_F(ID_S_BARO,V_FORECAST); #endif #ifdef ID_S_WIND MyMessage msg_S_WIND_S(ID_S_WIND,V_WIND); MyMessage msg_S_WIND_G(ID_S_WIND,V_GUST); MyMessage msg_S_WIND_D(ID_S_WIND,V_DIRECTION); #endif #ifdef ID_S_RAIN MyMessage msg_S_RAIN_A(ID_S_RAIN,V_RAIN); MyMessage msg_S_RAIN_R(ID_S_RAIN,V_RAINRATE); #endif #ifdef ID_S_UV MyMessage msg_S_UV(ID_S_UV,V_UV); #endif #ifdef ID_S_WEIGHT MyMessage msg_S_WEIGHT(ID_S_WEIGHT,V_WEIGHT); #endif #ifdef ID_S_POWER MyMessage msg_S_POWER_W(ID_S_POWER,V_WATT); MyMessage msg_S_POWER_K(ID_S_POWER,V_KWH); #endif #ifdef ID_S_HEATER //////// REVIEW IMPLEMENTATION //////////// MyMessage msg_S_HEATER_SET_POINT(ID_S_HEATER, V_HVAC_SETPOINT_HEAT); // HVAC/Heater setpoint (Integer between 0-100). S_HEATER, S_HVAC MyMessage msg_S_HEATER_FLOW_STATE(ID_S_HEATER, V_HVAC_FLOW_STATE); // Mode of header. One of "Off", "HeatOn", "CoolOn", or "AutoChangeOver" // S_HVAC, S_HEATER //MyMessage msg_S_HEATER_STATUS(ID_S_HEATER,V_STATUS); //MyMessage msg_S_HEATER_TEMP(ID_S_HEATER,V_TEMP); float heater_setpoint=21.5; String heater_flow_state="Off"; // float heater_temp=23.5; // bool heater_status=false; // V_TEMP // Temperature // V_STATUS // Binary status. 0=off 1=on // V_HVAC_FLOW_STATE // Mode of header. One of "Off", "HeatOn", "CoolOn", or "AutoChangeOver" // V_HVAC_SPEED // HVAC/Heater fan speed ("Min", "Normal", "Max", "Auto") // V_HVAC_SETPOINT_HEAT // HVAC/Heater setpoint #endif #ifdef ID_S_DISTANCE MyMessage msg_S_DISTANCE(ID_S_DISTANCE,V_DISTANCE); #endif #ifdef ID_S_LIGHT_LEVEL MyMessage msg_S_LIGHT_LEVEL(ID_S_LIGHT_LEVEL,V_LIGHT_LEVEL); #endif #ifdef ID_S_LOCK MyMessage msg_S_LOCK(ID_S_LOCK,V_LOCK_STATUS); bool isLocked = 0; #endif #ifdef ID_S_IR MyMessage msg_S_IR_S(ID_S_IR,V_IR_SEND); MyMessage msg_S_IR_R(ID_S_IR,V_IR_RECEIVE); long irVal = 0; #endif #ifdef ID_S_WATER MyMessage msg_S_WATER_F(ID_S_WATER,V_FLOW); MyMessage msg_S_WATER_V(ID_S_WATER,V_VOLUME); #endif #ifdef ID_S_AIR_QUALITY MyMessage msg_S_AIR_QUALITY(ID_S_AIR_QUALITY,V_LEVEL); #endif #ifdef ID_S_DUST MyMessage msg_S_DUST(ID_S_DUST,V_LEVEL); #endif #ifdef ID_S_SCENE_CONTROLLER MyMessage msg_S_SCENE_CONTROLLER_ON(ID_S_SCENE_CONTROLLER,V_SCENE_ON); MyMessage msg_S_SCENE_CONTROLLER_OF(ID_S_SCENE_CONTROLLER,V_SCENE_OFF); // not sure if scene controller sends int or chars // betting on ints as Touch Display Scen by Hek // compiler warnings char *scenes[] = { (char *)"Good Morning", (char *)"Clean Up!", (char *)"All Lights Off", (char *)"Music On/Off" }; int sceneVal=0; int sceneValPrevious=0; #endif #ifdef ID_S_RGB_LIGHT MyMessage msg_S_RGB_LIGHT_V_RGB(ID_S_RGB_LIGHT,V_RGB); MyMessage msg_S_RGB_LIGHT_V_WATT(ID_S_RGB_LIGHT,V_WATT); String rgbState="000000"; //RGB light V_RGB, V_WATT //RGB value transmitted as ASCII hex string (I.e "ff0000" for red) #endif #ifdef ID_S_RGBW_LIGHT MyMessage msg_S_RGBW_LIGHT_V_RGBW(ID_S_RGBW_LIGHT,V_RGBW); MyMessage msg_S_RGBW_LIGHT_V_WATT(ID_S_RGBW_LIGHT,V_WATT); String rgbwState="00000000"; //RGBW light (with separate white component) V_RGBW, V_WATT //RGBW value transmitted as ASCII hex string (I.e "ff0000ff" for red + full white) S_RGBW_LIGHT #endif #ifdef ID_S_COLOR_SENSOR MyMessage msg_S_COLOR_SENSOR_V_RGB(ID_S_COLOR_SENSOR,V_RGB); //Color sensor V_RGB //RGB value transmitted as ASCII hex string (I.e "ff0000" for red) S_RGB_LIGHT, S_COLOR_SENSOR #endif #ifdef ID_S_HVAC MyMessage msg_S_HVAC_V_HVAC_SETPOINT_HEAT(ID_S_HVAC,V_HVAC_SETPOINT_HEAT); MyMessage msg_S_HVAC_V_HVAC_SETPOINT_COOL(ID_S_HVAC,V_HVAC_SETPOINT_COOL); MyMessage msg_S_HVAC_V_HVAC_FLOW_STATET(ID_S_HVAC,V_HVAC_FLOW_STATE); MyMessage msg_S_HVAC_V_HVAC_FLOW_MODE(ID_S_HVAC,V_HVAC_FLOW_MODE); MyMessage msg_S_HVAC_V_HVAC_SPEED(ID_S_HVAC,V_HVAC_SPEED); float hvac_SetPointHeat = 16.5; float hvac_SetPointCool = 25.5; String hvac_FlowState = "AutoChangeOver"; String hvac_FlowMode = "Auto"; String hvac_Speed = "Normal"; //Thermostat/HVAC device //V_HVAC_SETPOINT_HEAT, // HVAC/Heater setpoint //V_HVAC_SETPOINT_COOL, // HVAC cold setpoint //V_HVAC_FLOW_STATE, // Mode of header. One of "Off", "HeatOn", "CoolOn", or "AutoChangeOver" //V_HVAC_FLOW_MODE, // Flow mode for HVAC ("Auto", "ContinuousOn", "PeriodicOn") //V_HVAC_SPEED // HVAC/Heater fan speed ("Min", "Normal", "Max", "Auto") // NOT IMPLEMENTED YET //V_TEMP // Temperature //V_STATUS // Binary status. 0=off 1=on #endif #ifdef ID_S_MULTIMETER MyMessage msg_S_MULTIMETER_V_IMPEDANCE(ID_S_MULTIMETER,V_IMPEDANCE); MyMessage msg_S_MULTIMETER_V_VOLTAGE(ID_S_MULTIMETER,V_VOLTAGE); MyMessage msg_S_MULTIMETER_V_CURRENT(ID_S_MULTIMETER,V_CURRENT); // Multimeter device V_VOLTAGE, V_CURRENT, V_IMPEDANCE // V_IMPEDANCE 14 Impedance value // V_VOLTAGE 38 Voltage level // V_CURRENT 39 Current level #endif #ifdef ID_S_SPRINKLER // S_SPRINKLER 31 Sprinkler device V_STATUS (turn on/off), V_TRIPPED (if fire detecting device) // V_STATUS 2 Binary status. 0=off 1=on // V_ARMED 15 Armed status of a security sensor. 1=Armed, 0=Bypassed // V_TRIPPED 16 Tripped status of a security sensor. 1=Tripped, 0=Untripped #endif #ifdef ID_S_WATER_LEAK #endif #ifdef ID_S_SOUND #endif #ifdef ID_S_VIBRATION #endif #ifdef ID_S_MOISTURE #endif #ifdef ID_S_MOISTURE MyMessage msg_S_MOISTURE(ID_S_MOISTURE,V_LEVEL); #endif #ifdef ID_S_CUSTOM MyMessage msg_S_CUSTOM_1(ID_S_CUSTOM,V_VAR1); MyMessage msg_S_CUSTOM_2(ID_S_CUSTOM,V_VAR2); MyMessage msg_S_CUSTOM_3(ID_S_CUSTOM,V_VAR3); MyMessage msg_S_CUSTOM_4(ID_S_CUSTOM,V_VAR4); MyMessage msg_S_CUSTOM_5(ID_S_CUSTOM,V_VAR5); #endif void setup() { // Random SEED randomSeed(analogRead(0)); wait(LONG_WAIT); Serial.println("GW Started"); } void presentation() { // Send the Sketch Version Information to the Gateway Serial.print("Send Sketch Info: "); sendSketchInfo(SKETCH_NAME, SKETCH_VERSION); Serial.print(SKETCH_NAME); Serial.println(SKETCH_VERSION); wait(LONG_WAIT); // Get controller configuration Serial.print("Get Config: "); metric = getControllerConfig().isMetric; Serial.println(metric ? "Metric":"Imperial"); wait(LONG_WAIT); // Init Armed #ifdef ID_S_ARMED isArmed = true; #endif // Register all sensors to gw (they will be created as child devices) Serial.println("Presenting Nodes"); Serial.println("________________"); #ifdef ID_S_DOOR Serial.println(" S_DOOR"); present(ID_S_DOOR,S_DOOR,"Outside Door"); wait(SHORT_WAIT); #endif #ifdef ID_S_MOTION Serial.println(" S_MOTION"); present(ID_S_MOTION,S_MOTION,"Outside Motion"); wait(SHORT_WAIT); #endif #ifdef ID_S_SMOKE Serial.println(" S_SMOKE"); present(ID_S_SMOKE,S_SMOKE,"Kitchen Smoke"); wait(SHORT_WAIT); #endif #ifdef ID_S_LIGHT Serial.println(" S_LIGHT"); present(ID_S_LIGHT,S_LIGHT,"Hall Light"); wait(SHORT_WAIT); #endif #ifdef ID_S_DIMMER Serial.println(" S_DIMMER"); present(ID_S_DIMMER,S_DIMMER,"Living room dimmer"); wait(SHORT_WAIT); #endif #ifdef ID_S_COVER Serial.println(" S_COVER"); present(ID_S_COVER,S_COVER,"Window cover"); wait(SHORT_WAIT); #endif #ifdef ID_S_TEMP Serial.println(" S_TEMP"); present(ID_S_TEMP,S_TEMP,"House Temperarue"); wait(SHORT_WAIT); #endif #ifdef ID_S_HUM Serial.println(" S_HUM"); present(ID_S_HUM,S_HUM,"Current Humidity"); wait(SHORT_WAIT); #endif #ifdef ID_S_BARO Serial.println(" S_BARO"); present(ID_S_BARO,S_BARO," Voltage"); wait(SHORT_WAIT); #endif #ifdef ID_S_WIND Serial.println(" S_WIND"); present(ID_S_WIND,S_WIND,"Wind Station"); wait(SHORT_WAIT); #endif #ifdef ID_S_RAIN Serial.println(" S_RAIN"); present(ID_S_RAIN,S_RAIN,"Rain Station"); wait(SHORT_WAIT); #endif #ifdef ID_S_UV Serial.println(" S_UV"); present(ID_S_UV,S_UV,"Ultra Violet"); wait(SHORT_WAIT); #endif #ifdef ID_S_WEIGHT Serial.println(" S_WEIGHT"); present(ID_S_WEIGHT,S_WEIGHT,"Outdoor Scale"); wait(SHORT_WAIT); #endif #ifdef ID_S_POWER Serial.println(" S_POWER"); present(ID_S_POWER,S_POWER,"Power Metric"); wait(SHORT_WAIT); #endif #ifdef ID_S_HEATER Serial.println(" S_HEATER"); present(ID_S_HEATER,S_HEATER,"Garage Heater"); wait(SHORT_WAIT); #endif #ifdef ID_S_DISTANCE Serial.println(" S_DISTANCE"); present(ID_S_DISTANCE,S_DISTANCE,"Distance Measure"); wait(SHORT_WAIT); #endif #ifdef ID_S_LIGHT_LEVEL Serial.println(" S_LIGHT_LEVEL"); present(ID_S_LIGHT_LEVEL,S_LIGHT_LEVEL,"Outside Light Level"); wait(SHORT_WAIT); #endif #ifdef ID_S_LOCK Serial.println(" S_LOCK"); present(ID_S_LOCK,S_LOCK,"Front Door Lock"); wait(SHORT_WAIT); #endif #ifdef ID_S_IR Serial.println(" S_IR"); present(ID_S_IR,S_IR,"Univeral Command"); wait(SHORT_WAIT); #endif #ifdef ID_S_WATER Serial.println(" S_WATER"); present(ID_S_WATER,S_WATER,"Water Level"); wait(SHORT_WAIT); #endif #ifdef ID_S_AIR_QUALITY Serial.println(" S_AIR_QUALITY"); present(ID_S_AIR_QUALITY,S_AIR_QUALITY,"Air Station"); wait(SHORT_WAIT); #endif #ifdef ID_S_DUST Serial.println(" S_DUST"); present(ID_S_DUST,S_DUST,"Dust Level"); wait(SHORT_WAIT); #endif #ifdef ID_S_SCENE_CONTROLLER Serial.println(" S_SCENE_CONTROLLER"); present(ID_S_SCENE_CONTROLLER,S_SCENE_CONTROLLER,"Scene Controller"); wait(SHORT_WAIT); #endif #ifdef ID_S_RGB_LIGHT Serial.println(" RGB_LIGHT"); present(ID_S_RGB_LIGHT,S_RGB_LIGHT,"Mood Light"); wait(SHORT_WAIT); #endif #ifdef ID_S_RGBW_LIGHT Serial.println(" RGBW_LIGHT"); present(ID_S_RGBW_LIGHT,S_RGBW_LIGHT,"Mood Light 2"); wait(SHORT_WAIT); #endif #ifdef ID_S_COLOR_SENSOR Serial.println(" COLOR_SENSOR"); present(ID_S_COLOR_SENSOR,S_COLOR_SENSOR,"Hall Painting"); wait(SHORT_WAIT); #endif #ifdef ID_S_HVAC Serial.println(" HVAC"); present(ID_S_HVAC,S_HVAC,"HVAC"); wait(SHORT_WAIT); #endif #ifdef ID_S_MULTIMETER Serial.println(" MULTIMETER"); present(ID_S_MULTIMETER,S_MULTIMETER,"Electric Staion"); wait(SHORT_WAIT); #endif #ifdef ID_S_SPRINKLER #endif #ifdef ID_S_WATER_LEAK #endif #ifdef ID_S_SOUND #endif #ifdef ID_S_VIBRATION #endif #ifdef ID_S_MOISTURE #endif #ifdef ID_S_MOISTURE Serial.println(" S_MOISTURE"); present(ID_S_MOISTURE,S_MOISTURE,"Basement Sensor"); wait(SHORT_WAIT); #endif #ifdef ID_S_CUSTOM Serial.println(" S_CUSTOM"); present(ID_S_CUSTOM,S_CUSTOM,"Other Stuff"); wait(SHORT_WAIT); #endif Serial.println("________________"); } void loop() { Serial.println(""); Serial.println(""); Serial.println(""); Serial.println("#########################"); randNumber=random(0,101); Serial.print("RandomNumber:"); Serial.println(randNumber); // Send fake battery level Serial.println("Send Battery Level"); sendBatteryLevel(randNumber); wait(LONG_WAIT); // Request time Serial.println("Request Time"); requestTime(); wait(LONG_WAIT); //Read Sensors #ifdef ID_S_DOOR door(); #endif #ifdef ID_S_MOTION motion(); #endif #ifdef ID_S_SMOKE smoke(); #endif #ifdef ID_S_LIGHT light(); #endif #ifdef ID_S_DIMMER dimmer(); #endif #ifdef ID_S_COVER cover(); #endif #ifdef ID_S_TEMP temp(); #endif #ifdef ID_S_HUM hum(); #endif #ifdef ID_S_BARO baro(); #endif #ifdef ID_S_WIND wind(); #endif #ifdef ID_S_RAIN rain(); #endif #ifdef ID_S_UV uv(); #endif #ifdef ID_S_WEIGHT weight(); #endif #ifdef ID_S_POWER power(); #endif #ifdef ID_S_HEATER heater(); #endif #ifdef ID_S_DISTANCE distance(); #endif #ifdef ID_S_LIGHT_LEVEL light_level(); #endif #ifdef ID_S_LOCK lock(); #endif #ifdef ID_S_IR ir(); #endif #ifdef ID_S_WATER water(); #endif #ifdef ID_S_AIR_QUALITY air(); #endif #ifdef ID_S_DUST dust(); #endif #ifdef ID_S_SCENE_CONTROLLER scene(); #endif #ifdef ID_S_RGB_LIGHT rgbLight(); #endif #ifdef ID_S_RGBW_LIGHT rgbwLight(); #endif #ifdef ID_S_COLOR_SENSOR color(); #endif #ifdef ID_S_HVAC hvac(); #endif #ifdef ID_S_MULTIMETER multimeter(); #endif #ifdef ID_S_SPRINKLER #endif #ifdef ID_S_WATER_LEAK #endif #ifdef ID_S_SOUND #endif #ifdef ID_S_VIBRATION #endif #ifdef ID_S_MOISTURE #endif #ifdef ID_S_MOISTURE moisture(); #endif #ifdef ID_S_CUSTOM custom(); #endif sendBatteryLevel(randNumber); wait(SHORT_WAIT); Serial.println("#########################"); //wait(SLEEP_TIME); //sleep a bit //sleep(60000); // Sleeps for a minute in deep sleep //sleep(6000000); // Sleeps for 100 minutes in deep sleep sleep(digitalPinToInterrupt(10), FALLING,0); } // This is called when a new time value was received void receiveTime(unsigned long controllerTime) { Serial.print("Time value received: "); Serial.println(controllerTime); } //void door(){} #ifdef ID_S_DOOR void door() { Serial.print("Door is: " ); if (randNumber <= 50) { Serial.println("Open"); send(msg_S_DOOR_T.set((int16_t)1)); } else { Serial.println("Closed"); send(msg_S_DOOR_T.set((int16_t)0)); } #ifdef ID_S_ARMED Serial.print("System is: " ); Serial.println((isArmed ? "Armed":"Disarmed")); send(msg_S_DOOR_A.set(isArmed)); #endif } #endif #ifdef ID_S_MOTION void motion() { Serial.print("Motion is: " ); if (randNumber <= 50) { Serial.println("Active"); send(msg_S_MOTION_T.set(1)); } else { Serial.println("Quiet"); send(msg_S_MOTION_T.set(0)); } #ifdef ID_S_ARMED Serial.print("System is: " ); Serial.println((isArmed ? "Armed":"Disarmed")); send(msg_S_MOTION_A.set(isArmed)); #endif } #endif #ifdef ID_S_SMOKE void smoke() { Serial.print("Smoke is: " ); if (randNumber <= 50) { Serial.println("Active"); send(msg_S_SMOKE_T.set(1)); } else { Serial.println("Quiet"); send(msg_S_SMOKE_T.set(0)); } #ifdef ID_S_ARMED Serial.print("System is: " ); Serial.println((isArmed ? "Armed":"Disarmed")); send(msg_S_SMOKE_A.set(isArmed)); #endif } #endif #ifdef ID_S_LIGHT void light() { Serial.print("Light is: " ); Serial.println((isLightOn ? "On":"Off")); send(msg_S_LIGHT.set(isLightOn)); } #endif #ifdef ID_S_DIMMER void dimmer() { Serial.print("Dimmer is set to: " ); Serial.println(dimmerVal); send(msg_S_DIMMER.set(dimmerVal)); } #endif #ifdef ID_S_COVER void cover() { Serial.print("Cover is : " ); if (coverState == 1) { Serial.println("Opening"); send(msg_S_COVER_U.set(1)); } else if (coverState == -1) { Serial.println("Closing"); send(msg_S_COVER_D.set(0)); } else { Serial.println("Idle"); send(msg_S_COVER_S.set(-1)); } send(msg_S_COVER_V.set(coverState)); } #endif #ifdef ID_S_TEMP void temp() { Serial.print("Temperature is: " ); Serial.println(map(randNumber,1,100,0,45)); send(msg_S_TEMP.set(map(randNumber,1,100,0,45))); } #endif #ifdef ID_S_HUM void hum() { Serial.print("Humitidty is: " ); Serial.println(randNumber); send(msg_S_HUM.set(randNumber)); } #endif #ifdef ID_S_BARO void baro() { const char *weather[] = {"stable","sunny","cloudy","unstable","thunderstorm","unknown"}; //long pressure = map(randNumber,1,100,870,1086);// hPa? //int forecast = map(randNumber,1,100,0,5); long voltage = hwCPUVoltage(); Serial.print("Power source voltage is: " ); Serial.println(voltage); send(msg_S_BARO_P.set(voltage)); //Serial.print("Weather forecast: " ); //Serial.println(weather[forecast]); //send(msg_S_BARO_F.set(weather[forecast])); } #endif #ifdef ID_S_WIND void wind() { Serial.print("Wind Speed is: " ); Serial.println(randNumber); send(msg_S_WIND_S.set(randNumber)); Serial.print("Wind Gust is: " ); Serial.println(randNumber+10); send(msg_S_WIND_G.set(randNumber+10)); Serial.print("Wind Direction is: " ); Serial.println(map(randNumber,1,100,0,360)); send(msg_S_WIND_D.set(map(randNumber,1,100,0,360))); } #endif #ifdef ID_S_RAIN void rain() { Serial.print("Rain ammount is: " ); Serial.println(randNumber); send(msg_S_RAIN_A.set(randNumber)); Serial.print("Rain rate is: " ); Serial.println(randNumber/60); send(msg_S_RAIN_R.set(randNumber/60,1)); } #endif #ifdef ID_S_UV void uv() { Serial.print("Ultra Violet level is: " ); Serial.println(map(randNumber,1,100,0,15)); send(msg_S_UV.set(map(randNumber,1,100,0,15))); } #endif #ifdef ID_S_WEIGHT void weight() { Serial.print("Weight is: " ); Serial.println(map(randNumber,1,100,0,150)); send(msg_S_WEIGHT.set(map(randNumber,1,100,0,150))); } #endif #ifdef ID_S_POWER void power() { Serial.print("Watt is: " ); Serial.println(map(randNumber,1,100,0,150)); send(msg_S_POWER_W.set(map(randNumber,1,100,0,150))); Serial.print("KWH is: " ); Serial.println(map(randNumber,1,100,0,150)); send(msg_S_POWER_K.set(map(randNumber,1,100,0,150))); } #endif #ifdef ID_S_HEATER void heater() { // float heater_setpoint=21.5; // float heater_temp=23.5; // bool heater_status=false; // String heatState="Off"; Serial.print("Heater flow state is: " ); Serial.println(heater_flow_state); send(msg_S_HEATER_FLOW_STATE.set(heater_flow_state.c_str())); // Serial.print("Heater on/off is: " ); // Serial.println((heater_status==true)?"On":"Off"); // send(msg_S_HEATER_STATUS.set(heater_status)); // Serial.print("Heater Temperature is: " ); // Serial.println(heater_temp,1); // send(msg_S_HEATER_TEMP.set(heater_temp,1)); Serial.print("Heater Setpoint: " ); Serial.println(heater_setpoint,1); send(msg_S_HEATER_SET_POINT.set(heater_setpoint,1)); } #endif #ifdef ID_S_DISTANCE void distance() { Serial.print("Distance is: " ); Serial.println(map(randNumber,1,100,0,150)); send(msg_S_DISTANCE.set(map(randNumber,1,100,0,150))); } #endif #ifdef ID_S_LIGHT_LEVEL void light_level() { Serial.print("Light is: " ); Serial.println(map(randNumber,1,100,0,150)); send(msg_S_LIGHT_LEVEL.set(map(randNumber,1,100,0,150))); } #endif #ifdef ID_S_LOCK void lock() { Serial.print("Lock is: " ); Serial.println((isLocked ? "Locked":"Unlocked")); send(msg_S_LOCK.set(isLocked)); } #endif #ifdef ID_S_IR void ir() { Serial.print("Infrared is: " ); Serial.println(irVal); send(msg_S_IR_S.set(irVal)); send(msg_S_IR_R.set(irVal)); } #endif #ifdef ID_S_WATER void water() { Serial.print("Water flow is: " ); Serial.println(map(randNumber,1,100,0,150)); send(msg_S_WATER_F.set(map(randNumber,1,100,0,150))); Serial.print("Water volume is: " ); Serial.println(map(randNumber,1,100,0,150)); send(msg_S_WATER_V.set(map(randNumber,1,100,0,150))); } #endif #ifdef ID_S_AIR_QUALITY void air() { Serial.print("Air Quality is: " ); Serial.println(randNumber); send(msg_S_AIR_QUALITY.set(randNumber)); } #endif #ifdef ID_S_DUST void dust() { Serial.print("Dust level is: " ); Serial.println(randNumber); send(msg_S_DUST.set(randNumber)); } #endif #ifdef ID_S_SCENE_CONTROLLER void scene() { Serial.print("Scene is: " ); Serial.println(scenes[sceneVal]); if(sceneValPrevious != sceneVal) { send(msg_S_SCENE_CONTROLLER_OF.set(sceneValPrevious)); send(msg_S_SCENE_CONTROLLER_ON.set(sceneVal)); sceneValPrevious=sceneVal; } } #endif #ifdef ID_S_RGB_LIGHT void rgbLight() { Serial.print("RGB Light state is: " ); Serial.println(rgbState); send(msg_S_RGB_LIGHT_V_RGB.set(rgbState.c_str())); Serial.print("RGB Light Watt is: " ); Serial.println(map(randNumber,1,100,0,150)); send(msg_S_RGB_LIGHT_V_WATT.set(map(randNumber,1,100,0,150))); } #endif #ifdef ID_S_RGBW_LIGHT void rgbwLight() { Serial.print("RGBW Light state is: " ); Serial.println(rgbwState); send(msg_S_RGBW_LIGHT_V_RGBW.set(rgbwState.c_str())); Serial.print("RGBW Light Watt is: " ); Serial.println(map(randNumber,1,100,0,150)); send(msg_S_RGBW_LIGHT_V_WATT.set(map(randNumber,1,100,0,150))); } #endif #ifdef ID_S_COLOR_SENSOR void color() { String colorState; String red = String(random(0,256),HEX); String green = String(random(0,256),HEX); String blue = String(random(0,256),HEX); colorState=String(red + green + blue); Serial.print("Color state is: " ); Serial.println(colorState); send(msg_S_COLOR_SENSOR_V_RGB.set(colorState.c_str())); } #endif #ifdef ID_S_HVAC void hvac() { // float hvac_SetPointHeat = 16.5; // float hvac_SetPointCool = 25.5; // String hvac_FlowState = "AutoChangeOver"; // String hvac_FlowMode = "Auto"; // String hvac_Speed = "Normal"; Serial.print("HVAC Set Point Heat is: " ); Serial.println(hvac_SetPointHeat); send(msg_S_HVAC_V_HVAC_SETPOINT_HEAT.set(hvac_SetPointHeat,1)); Serial.print("HVAC Set Point Cool is: " ); Serial.println(hvac_SetPointCool); send(msg_S_HVAC_V_HVAC_SETPOINT_COOL.set(hvac_SetPointCool,1)); Serial.print("HVAC Flow State is: " ); Serial.println(hvac_FlowState); send(msg_S_HVAC_V_HVAC_FLOW_STATET.set(hvac_FlowState.c_str())); Serial.print("HVAC Flow Mode is: " ); Serial.println(hvac_FlowMode); send(msg_S_HVAC_V_HVAC_FLOW_MODE.set(hvac_FlowMode.c_str())); Serial.print("HVAC Speed is: " ); Serial.println(hvac_Speed); send(msg_S_HVAC_V_HVAC_SPEED.set(hvac_Speed.c_str())); } #endif #ifdef ID_S_MULTIMETER void multimeter() { int impedance=map(randNumber,1,100,0,15000); int volt=map(randNumber,1,100,0,380); int amps=map(randNumber,1,100,0,16); Serial.print("Impedance is: " ); Serial.println(impedance); send(msg_S_MULTIMETER_V_IMPEDANCE.set(impedance)); Serial.print("Voltage is: " ); Serial.println(volt); send(msg_S_MULTIMETER_V_VOLTAGE.set(volt)); Serial.print("Current is: " ); Serial.println(amps); send(msg_S_MULTIMETER_V_CURRENT.set(amps)); } #endif #ifdef ID_S_SPRINKLER #endif #ifdef ID_S_WATER_LEAK #endif #ifdef ID_S_SOUND #endif #ifdef ID_S_VIBRATION #endif #ifdef ID_S_MOISTURE #endif #ifdef ID_S_MOISTURE void moisture() { Serial.print("Moisture level is: " ); Serial.println(randNumber); send(msg_S_MOISTURE.set(randNumber)); } #endif #ifdef ID_S_CUSTOM void custom() { Serial.print("Custom value is: " ); Serial.println(randNumber); send(msg_S_CUSTOM_1.set(randNumber)); send(msg_S_CUSTOM_2.set(randNumber)); send(msg_S_CUSTOM_3.set(randNumber)); send(msg_S_CUSTOM_4.set(randNumber)); send(msg_S_CUSTOM_5.set(randNumber)); } #endif void receive(const MyMessage &message) { switch (message.type) { #ifdef ID_S_ARMED case V_ARMED: isArmed = message.getBool(); Serial.print("Incoming change for ID_S_ARMED:"); Serial.print(message.sensor); Serial.print(", New status: "); Serial.println((isArmed ? "Armed":"Disarmed" )); #ifdef ID_S_DOOR door();//temp ack for door #endif #ifdef ID_S_MOTION motion();//temp ack #endif #ifdef ID_S_SMOKE smoke();//temp ack #endif break; #endif case V_STATUS: // V_LIGHT: #ifdef ID_S_LIGHT if(message.sensor==ID_S_LIGHT) { isLightOn = message.getBool(); Serial.print("Incoming change for ID_S_LIGHT:"); Serial.print(message.sensor); Serial.print(", New status: "); Serial.println((isLightOn ? "On":"Off")); light(); // temp ack } #endif // #ifdef ID_S_HEATER // if(message.sensor == ID_S_HEATER){ // heater_status = message.getBool(); // Serial.print("Incoming change for ID_S_HEATER:"); // Serial.print(message.sensor); // Serial.print(", New status: "); // Serial.println(heater_status); // heater();//temp ack // } // #endif break; #ifdef ID_S_DIMMER case V_DIMMER: if ((message.getInt()<0)||(message.getInt()>100)) { Serial.println( "V_DIMMER data invalid (should be 0..100)" ); break; } dimmerVal= message.getInt(); Serial.print("Incoming change for ID_S_DIMMER:"); Serial.print(message.sensor); Serial.print(", New status: "); Serial.println(message.getInt()); dimmer();// temp ack break; #endif #ifdef ID_S_COVER case V_UP: coverState=1; Serial.print("Incoming change for ID_S_COVER:"); Serial.print(message.sensor); Serial.print(", New status: "); Serial.println("V_UP"); cover(); // temp ack break; case V_DOWN: coverState=-1; Serial.print("Incoming change for ID_S_COVER:"); Serial.print(message.sensor); Serial.print(", New status: "); Serial.println("V_DOWN"); cover(); //temp ack break; case V_STOP: coverState=0; Serial.print("Incoming change for ID_S_COVER:"); Serial.print(message.sensor); Serial.print(", New status: "); Serial.println("V_STOP"); cover(); //temp ack break; #endif case V_HVAC_SETPOINT_HEAT: #ifdef ID_S_HEATER if(message.sensor == ID_S_HEATER) { heater_setpoint=message.getFloat(); Serial.print("Incoming set point for ID_S_HEATER:"); Serial.print(message.sensor); Serial.print(", New status: "); Serial.println(heater_setpoint,1); heater();//temp ack } #endif #ifdef ID_S_HVAC if(message.sensor == ID_S_HVAC) { hvac_SetPointHeat=message.getFloat(); Serial.print("Incoming set point for ID_S_HVAC:"); Serial.print(message.sensor); Serial.print(", New status: "); Serial.println(hvac_SetPointHeat,1); hvac();//temp ack } #endif break; case V_HVAC_FLOW_STATE: #ifdef ID_S_HEATER if(message.sensor == ID_S_HEATER) { heater_flow_state=message.getString(); Serial.print("Incoming flow state change for ID_S_HEATER:"); Serial.print(message.sensor); Serial.print(", New status: "); Serial.println(heater_flow_state); heater();//temp ack } #endif #ifdef ID_S_HVAC if(message.sensor == ID_S_HVAC) { hvac_FlowState=message.getString(); Serial.print("Incoming set point for ID_S_HVAC:"); Serial.print(message.sensor); Serial.print(", New status: "); Serial.println(hvac_FlowState); hvac();//temp ack } #endif break; #ifdef ID_S_LOCK case V_LOCK_STATUS: isLocked = message.getBool(); Serial.print("Incoming change for ID_S_LOCK:"); Serial.print(message.sensor); Serial.print(", New status: "); Serial.println(message.getBool()?"Locked":"Unlocked"); lock(); //temp ack break; #endif #ifdef ID_S_IR case V_IR_SEND: irVal = message.getLong(); Serial.print("Incoming change for ID_S_IR:"); Serial.print(message.sensor); Serial.print(", New status: "); Serial.println(irVal); ir(); // temp ack break; case V_IR_RECEIVE: irVal = message.getLong(); Serial.print("Incoming change for ID_S_IR:"); Serial.print(message.sensor); Serial.print(", New status: "); Serial.println(irVal); ir(); // temp ack break; #endif #ifdef ID_S_SCENE_CONTROLLER case V_SCENE_ON: sceneVal = message.getInt(); Serial.print("Incoming change for ID_S_SCENE_CONTROLLER:"); Serial.print(message.sensor); Serial.print(", New status: "); Serial.print(scenes[sceneVal]); Serial.println(" On"); scene();// temp ack break; case V_SCENE_OFF: sceneVal = message.getInt(); Serial.print("Incoming change for ID_S_SCENE_CONTROLLER:"); Serial.print(message.sensor); Serial.print(", New status: "); Serial.print(scenes[sceneVal]); Serial.println(" Off"); scene();// temp ack break; #endif #ifdef ID_S_RGB_LIGHT case V_RGB: rgbState=message.getString(); Serial.print("Incoming flow state change for ID_S_RGB_LIGHT:"); Serial.print(message.sensor); Serial.print(", New status: "); Serial.println(rgbState); rgbLight(); // temp ack break; #endif #ifdef ID_S_RGBW_LIGHT case V_RGBW: rgbwState=message.getString(); Serial.print("Incoming flow state change for ID_S_RGBW_LIGHT:"); Serial.print(message.sensor); Serial.print(", New status: "); Serial.println(rgbwState); rgbwLight(); break; #endif #ifdef ID_S_HVAC // hvac_SetPointHeat // hvac_SetPointCool // hvac_FlowState // hvac_FlowMode // hvac_Speed case V_HVAC_SETPOINT_COOL: hvac_SetPointCool=message.getFloat(); Serial.print("Incoming set point for ID_S_HVAC:"); Serial.print(message.sensor); Serial.print(", New status: "); Serial.println(hvac_SetPointCool,1); hvac();//temp ack break; case V_HVAC_FLOW_MODE: hvac_Speed=message.getString(); Serial.print("Incoming set point for ID_S_HVAC:"); Serial.print(message.sensor); Serial.print(", New status: "); Serial.println(hvac_Speed); hvac();//temp ack break; case V_HVAC_SPEED: hvac_FlowMode=message.getString(); Serial.print("Incoming set point for ID_S_HVAC:"); Serial.print(message.sensor); Serial.print(", New status: "); Serial.println(hvac_FlowMode); hvac();//temp ack break; #endif default: Serial.print("Unknown/UnImplemented message type: "); Serial.println(message.type); } }
I selected the board "Nordic nRF52832 DK" in the board manager.
You'll need a separate serial gateway running for it to communicate with, or else it will never get to the section where it sleeps.
-
@rmtucker said in nRF5 Bluetooth action!:
The only problem is i can not unplug it from the Ble400 because i have no way of connecting wires to the core board because of the smaller pitch pins.
For the current measurement, just program it with the above sketch on your Waveshare, then unplug your module from the BLE400 board and power it using a GND dupont wire and a Vcc dupont wire connected through your uCurrent Gold, or whatever it is that you're using to measure current. I should think that would work, wouldn't it?
Or do you only have the main board without the smaller plug-in module?
It actually looks like a nice setup.
-
When you unplug the little board it only has 1.27mm spaced pins and they are not standard dupont size so shy soldering to them which would mean i could not plug it back in to the BLE.
Anyway i am only using a crappy multimeter and with it plugged in and running your sketch i am getting 140uA but i will find a way of unplugging it so hang fire.
-
@rmtucker you could try to just solder 2 tiny wires on top of the board for vcc and gnd pins so you don't mess with the connectors for plugin it back on the main board ?
-
@Nca78
Agreed. It sounds as though the bigger problem is going to be his crappy multimeter, if that's all he has. Maybe a good time for an upgrade?
-
@NeverDie
Ok with my crappy multimeter i am getting 4-5uA with just Vcc and Ground connected.
-
I'll try removing the 32.768Khz crystal from an infor-link module and then re-run the sketch that relies on an external interrupt to wake from sleep. Maybe that will get us closer to the theoretical minimum current of just the nRF52832 chip by itself.
Suggested Topics
-
Welcome
Announcements • • hek