-
-
Notifications
You must be signed in to change notification settings - Fork 640
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Low power example #365
Comments
I believe only need to run LoRa.end() before setting the MCU to deep sleep. |
I guess probably not or how do you make sure to wake up the whole setting when there's a packet sent? |
You want wake up event? Now, I prefer doing like Class A of LoRaWAN. |
I want what Sandeep showed in the video. A low power receiver that wakes up with CAD eg |
I never made a video :) Do you have a link? |
Hi, |
I made that video, including (pt. 1: https://www.youtube.com/watch?v=fP5RO6sIQGk). In the video you can see an implementation of CAD mode that's described in the Semtech SX1276 datasheet on page 42. I never published the code as it's pretty experimental and in this setup with the watch crystal nobody would probably want to try to implement it. I'll tidy up the code that's used in the video and make an example that uses the watchdog instead of the watch crystal for the sleep intervals. Should be ready in a few days in my fork. Would love to see CAD mode in the original arduino-LoRa library! |
@chocotov1 : So eager to wait for your code :-) |
I created the branch cadmode in my fork. It's a working showcase of CAD mode, nothing more! I don't really encourage anyone to use it because there's probably a better way to implement it in the library. I commented out a couple of attachInterrupt() lines, so I definitely broke something in the process. I included the example LoRaReceiverCadDemo328p. Here the watchdog timer of the 328p (UNO) is configured with a 16 ms sleep time. Power consumption: 1.17 mA. Setting the watchdog to 30 ms had a consumption of 680 uA. You can change the sleep time by changing these lines:
Be sure to also check that the preamble is set appropriately in the sender. It must be at least as long as the sleep time:
|
Thanks for your work. I'm getting my RFM95 modules ready and am curious about testing your code. Which sketch would you recommend for the sender unit? |
LoRaSender should work. It's probably best to define the longer preamble there too, for instance like this:
|
I uploaded a new demonstration video that uses the code of my cadmode branch: If nobody else is interested i'd be happy to help to add CAD mode to the upstream repository. Im hesitant because i'm not familiar with how the other interrupt based code works. |
If you check the PRs there are multiple attempts to include CAD detection, that part of the code is fairly straight forward. I'd suggest looking over #334 Would be awesome to finally land a PR for CAD detection. |
Thanks for pointing that out. I'll take a look over there! |
Great!
|
Having this particular software library require an external piece of hardware would be completely prohibitive for multi-device compatibility. Instead establishing a MACRO or extern function to use the best available method for the MCU is use is probably a better approach. |
@morganrallen The CAD is still pending for a release, right? In LoRaWAN, a CAD is useful to detect a packet from any SF of a frequency. |
@morganrallen it was just a question as this timer IC is obiously more power efficeint than the internal watchdog. There are even breakoutboard available for those who don't use selfmade pcbs. To have this at least as an option for low power devices would be great. but chocotov1's example is still in this state awesome and works nice |
The 8 uA power consumption of the watchdog of the 328p (or any other Atmel chip) is so low that trying to optimize it isn't worth it. About parsing the data my latest video: The data of the nodes is packed into a compact format, roughly using the principles that are explained here: https://www.thethingsnetwork.org/docs/devices/bytes.html
Easy solution:
|
Cad mode is working excellent on a receiving only node. But sadly it can't mixed with transmitting code. Have modified the gateway code to act as repeater. So if I were able to have cad mode in addition, (for sleep mode) this would give a nice solar powered repeater... |
I discovered that in my example sketch and the sketch of my video that the ADC was turned on. With it turned off the power consumption dropped to 590 uA (display turned off).
|
Wow ok, where did you put the |
It is in setup() |
@chocotov1 Can you transmit with your CAD-Code? Didn't got it to work yet. |
I didn't try before, but now i've tested it and it worked for me. I modified my example. The new code is commented out, so you need to uncomment it first to send a message like I did. |
Nice! btw Do both Dio0 and DIO1 need interrupt capable pins? I would need at least one interrupt pin on the 328P for something else |
Yea, you need both interrupt pins. Dio1 is for cad detect, so the avr will wake up if a cad occurs. |
@neo7530 I only have dio0 connected to MCU. Can I short circuit DIO0 and DIO1 to use CAD too? |
@IoTThinks you can separate the Dios with a diode, but this wouldn't work with this code, because it have 2 separate int handlers and flags.maybe you can modify the code. Don't have a clue if this works as expected then. |
OK, yes as far as I remind avr/wdt.h won't work an a SAMD21 but as you shown there are other libraries or commands for this purpose. |
Yeah, that should work. You also need make sure the interrupt for DIO0 is setup correctly. I saw the in the video I linked that the power consumption of the mkr1000 in sleep was 580 uA. That's a lot more than the 8 uA I see using the wdt on the 328p. The 328p cadmode demo I presented here uses 590 uA while actively receiving messages. |
Yeah 590µA is amazing. However I need a bigger MCU for menu, display etc. I'm gonna try it with the SAMD21 to get your code running as sone as I got my prototyping board done. Other option is to connect a 328P to a SAMD21 and exchange data over I2C or SPI or so |
@chocotov1 @maxholgasson : The following code is for Arduino only, right?
|
@IoTThinks |
I've tried a SPI relay setup with 2 MCUs (Pro Minis running 8 MHz). I had to look up this technique, but with a little effort I can confirm it can be done. I made a little demo video: https://www.youtube.com/watch?v=vsuVu33MASg As for the alternative with SAMD21, i've bought a couple of SAMD21 boards and looked into that too. The challenge there is not only the Lora part (with cad mode) but more so getting down with the details of the SAMD21. The SAMD21 has some advanced features like the builtin RTC with 32 kHz crystal. Another huge benefit is that it's possible to debug your program with a debugger. The problem is that SAMD21 is more complex, the datasheet is bigger and sadly only a few people (compared to the AVR Arduinos) are using the more advanced features. In the meantime I've tackled the challenge of getting the SAMD21 to sleep for a short time (32 ms for instance). One problem that arises is that you then shouldn't try to use the USB cable anymore. It becomes unusable. Uploading code is then only possible via the SWD pads (all boards seem to have these exposed). You need a programmer for this. I have the Atmel ICE. Some general SAMD21 boards with Lora tips i've gathered so far (note that I still haven't made a CAD MODE solution for SAMD21 yet):
With some tweaks in the SAMD21 Arduino core, I made some board variants with lower clock speeds. This way the SAMD21 boards also work at lower voltages (like with 2x NiMH battery setup). At low voltage the power consumption during sleep is around 250 uA. I suspect it can be lowered a bit with some hardware mods. Since these boards are so expensive I won't mess with them for now. |
My esp32 now can reach 60uA deepsleep with LoRa. You can check how much your LDO consumes to go under 60uA. Btw, I check CAD mode. It costs like a RX around 18mA so I guess we can not use it during deep sleep. |
CAD mode with SAMD21 / MKRZERO: I'll make a similar SAMD21 sketch with serial output instead and put add it to my fork this week. |
@chocotov1
|
@chocotov1 Does anyone have a clue how to transmit and process the data so I can use those two values? |
@maxholgasson For your sensor data you can define a custom message format. For instance the first byte could be the sensor id from 0 till 255. The second byte could be the temperature from 0 till 255.
These values are not so practical, so you are free to organize it in your own format. It's good practice to not waste bytes because then the radio transmissions takes longer. For instance if you have 8 sensors, you'd ony need 3 bits for the sensor id field. See also my reply of 24 May and look here: https://www.thethingsnetwork.org/docs/devices/bytes.html To efficiently organize your sensor data into different bytes you'll have to understand the bit operations: https://playground.arduino.cc/Code/BitMath/ |
@chocotov1 Thanks a lot, it's working now. Nice to play around with those RFM95 boards.
It took quite some time till I understood what you mean but now I got it. Thanks for the hint! |
HI,
I hope to understand that someday and do my very best to follow the ideas. In the datasheet page 38 is a diagram of the CAD mode. Did you use this or how did you proceed? There is written STAND-BY - does that mean the MCU has to sleep at this step for eg 32ms? |
I actually didn't add a SAMD21 example sketch yet, until today! See my fork of arduino-LoRa in the cadmode branch: examples/LoRaReceiverCadDemoZeroDIO0/LoRaReceiverCadDemoZeroDIO0.ino. In this setup I observed a power consumption around 1.2 mA @ 3.3 V during CAD mode. I am hesitant to publish this sketch. I enjoyed the challenge of making it work. But for someone like you, probably just needing something that gets the job done, I think you'd be better off using something less experimental. The SAMD21 is a niche in it's own right, combine that with wanting to use CAD mode of the SX1276 and you'll notice there only 2 people that are interested in that. Before you try to upload that sketch, I need to emphasize that you really need to be using the SWD pads and a programmer like the Atmel ICE to upload the sketch! Putting the MCU to sleep like this sketch does messes up the USB connection. It's better to just don't connect the USB cable at all. In my fork of ArduinoCore-samd I added some board definitions with lower clock speeds and without the bootloader. This way the board still works at low voltages around 2 V. The no bootloader variants also save the hassle of having to separately upload the bootloader each time. Of course, without a bootloader you'll also won't be able upload sketches over the USB cable anymore. This is how I deployed my fork of ArduinoCore-samd on my computer: I had first installed the normal Arduino SAMD21 core using the library manager. Afterwards I cloned my fork in the same folder:
Notice that Serial1 is used in the sketch. You can read from it by using a serial adapter and pin 14 (TX) of the MKRZERO. About page 38 of the datasheet: Yeah, that's where learned the details of CAD mode. The places where it says STANDBY are actually points, where Lora module automatically puts itself in standby mode. |
@chocotov1 Hi, ah cool thanks, I'll have a look and see if I can get it to work. Great to see that it's working with the SAMD21 even it uses much more power than a 328P. A pitty that this has such a small memory.
Actually both is true ;) Since a couple of years I made again and again efforts to have proper low power solution for different ideas I had. I'd like to build small environment sensors which can work outside and are only battery powered or other remote controls where both sender and receiver are battery powered for monitoring. Eg ultrasonic detectors connected to a sound recorder for monitoring bats.🦇 I really would like to understand how that works and your sucesfull working RFM95 CAD code is a great thing. I wish I would understand more and maybe I could contribute some day to the code as soon as I understood more.
Thanks for the important advice, in my case I designed a own pcb with a bare SAMD21 and only a SWD connector for programming - there is no USB. I'm using a modified Arduino Zero as a programmer as I couldn't afford a proper ICE^^ It used to function as a debugger as well but it was to confusing to get it to run - a debugger would probably very handy. |
In that case, i'll gladly keep helping you with the Lora and SAMD21 experiments. Maybe you can make a repository of your project with some background info of the hardware. We can then look at same code and I can maybe verify your problems. That's really advanced with your PCB and SAMD21. Did you get the my example working? You might be seeing lower power consumption values, since the Arduino SAMD21 boards have some extra hardware like the vreg. I checked out my example again, uploading it the normal Arduino way (without programmer). I was surprised to notice that the code doesn't introduce the massive USB problems anymore. The problem must have been solved, since in the published version I took some measures to disable USB. Double press the reset button if you want to upload again. For anyone else interested in trying, I still do advice to only upload the SAMD21 sketch if you also have programmer. After you've uploaded code that breaks the USB connection, the programmer is needed so you can upload other code again. |
Ok I'm trying to make repository(I need to look it up first what I have to include and hwo a repository is built)
Yes I'm very curious. It's a while ago I made the pcbs but put them away as the consumption was too high (during that time I used RX mode without CAD, so all time alive)
I just remembered that I got in trouble first time using the sleep and wakeup by interrupt with the SAMD21. I first had to cut the power after uploading otherwise it didn't work properly. This error was hard to find. |
@chocotov1 |
If unable to reach under 500uA, check the LDO first. Some LDOs have high quiescent current. |
Hi, I don't have a LDO. The MCU is directly connected to a linear power supply. No other wires were attached, disconnected SWD of course for measuring) Edit2: Edit3: |
Awesome! I also found some improvements for my SAMD21 power consumption experiments. The default setup of the pins in wiring.c turns out to be less efficient. By defining VERY_LOW_POWER in boards.txt the power consumption on my Lora CAD mode test dropped from 1.25 mA to 0.75 mA. I checked out the Moteino boads.txt and they do the same thing:
I read about it over here: adafruit/Adafruit_SleepyDog#17 By commenting out the following line I saved around 10 uA in a test sketch with RTC interrupt every 30 ms, EIC (pin change interrupt) and a blinking led:
I was encouraged to remove it after reading https://community.atmel.com/comment/1851566#comment-1851566. One more thing I noticed, is that my MKRZERO has around 100 uA higher power consumption when the voltage is lower than 3.3 V. I suspect it could be caused by the something like the vreg or the battery charging circuit. Summary:
You can change that by editing boards.txt. Change flash_with_bootloader.ld into flash_without_bootloader.ld example:
|
Cool findings. I read about VERY_LOW_POWER and also tried it but didn't know that i was already used in boards.txt Nice summary, didn't expect first to get the SAMD21 so close to the 328P I read here about the peripherals. As far as I understood the adc isn't already disabled in sleep or? |
I think the ADC in Arduino / SAMD is only turned on when you're taking a reading. flash_with_bootloader.ld seems to upload your program to a different location (after the bootloader). The program command of openocd seems to also erase the flash: http://openocd.org/doc/html/Flash-Programming.html#Flash-Programming |
Ah ok,that would be cool unfortunatly I can't test it at the moment as I destroyed my last SAMD21 IC due to a VCC >3.3V |
That's too bad but are you sure it's destroyed? Did it smoke? According to the datasheet 3.8 V would still be ok. I thought I had broken two MKRZEROs after some wiring issues. See https://community.atmel.com/forum/bricked-arduino-mkrzero comment 2 how I fixed the issue.
Take a look at the RTC chapter of the datasheet. If you want to use the calendar I think the RTC needs to be configured to 1 second intervals, that's not good enough for CAD mode. I corrected a misleading comment about the selected interval in LoRaReceiverCadDemoZeroDIO0.ino:
|
Yes I'm pretty sure. It was around 9V and had a consumption of 800mA but it didn't smoke^^ Oh that issue with the MKRZEROs sounds tricky.
Mh I disabled sleeping but not started cad every 30ms. Propably that's the problem and solution. Guess it's best done by watchdog/timer interrupt, or? |
Has there been any progress since? |
My examples are in my cadmode branch: https://github.com/chocotov1/arduino-LoRa/tree/cadmode examples/LoRaReceiverCadDemo328pDIO0 Since then I haven't really looked into it any more. |
Thanks! I was losing hope on battery powered wireless receivers before I stumbled onto this thread. I was looking at waking up the mcu with those low power rf receivers that run on a slow duty cycle to go down to 0.1ma, but this solution is much more versatile |
Hey I would like to ask if anyone managed by chance to add an option to chocotov1's great code an option to receive when the mcu is awake or has an ideo how to do it? Background is at them moment the reception only is working when the mcu is sleeping but if you navigate through an menu and like to set some things it's not possible at the moment taht you receive anything during that time |
Hi, do you have a sample code for the sender and receiver you show on youtube with rfm95 in sleep mode and CAD mode?
Thanks a lot for this awesome example. 0.9mA receiving consumption is great!!
The text was updated successfully, but these errors were encountered: