Skip to content
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

First version of a DeepSleep state for the RP2040 #4976

Merged
merged 10 commits into from
Oct 8, 2024

Conversation

TheMalkavien
Copy link
Contributor

Hi,

As I use mainly RP2040 with solar power, I needed a way to reduce power consumption, or being able to put the node to sleep during very low battery charge.

The RP2040 can be put to deepsleep, I did not find a lot of example (well precisely I did find multiple way to do so, but not always very clear to me), so I worked on a first version based on the multiple examples I found.

My changes are based on parts of the pico-extra lib (https://github.com/raspberrypi/pico-extras/).

What it does :

  • RP2040 is now able to "shutdown" (forever sleep)
  • RP2040 is now able to DeepSleep for a given time - works well when power state is LowBatt !

What is does not :

  • RP2040 cannot fully restore its state after being awoken, so it just reboots to become operational again.

I measured the power consumption during deep sleep to around 3 mah. Its still high, but way better than the 30-35 when it is awake.

There is A LOT of place for improvement, I'm not sure I can do better myself cause I'm not an expert of this device, nor a good developer, but it is really a good start (and works for me).

I updated some RP2040 libraries to be able to use pico-extra.

Issue : Rarely, the radio chip does not want to go to sleep, even after the 30 seconds delay. Maybe this delay is to short, maybe the channel is too occupied, I dont know.

P.S. : Sorry my Trunk addon for VS does not work anymore, it crashes so the code may not be very clean.

Regards,

@TheMalkavien
Copy link
Contributor Author

Hum I see that the rak11310 misses a #define ledOff(pin) pinMode(pin, INPUT) in variants.h.

Maybe the best is for now to limit my changes for the RP2040-lora only ? I did not test on another rp2040 devices.
What do you think ?

@thebentern thebentern merged commit a0dd7b4 into meshtastic:master Oct 8, 2024
44 of 45 checks passed
panaceya added a commit to mesh-mk-ua/meshtastic-firmware that referenced this pull request Oct 8, 2024
* Add RAK4631 Ethernet Gateway with working JSON output to MQTT

* Update platformio.ini

Fix default build environment

* Fix default build platform

* Fix #ifndef and rename the variant

* Fix traceroute, neighborinfo and waypoint

* Disable SCREEN and enable TZ

* Fix platformio.ini conflict

* Fix formatting

* Another try to get the code format correct.

* Trunk fmt

* Remove accelerometer lib

* Toggle Bluetooth with Fn+b shortcut (meshtastic#4977)

* Toggle Blutooth with Fn+b shortcut

Problem:
As many are aware, ESP32 devices are known for their high power consumption. For instance, the Heltec ESP32 V3 draws around 110mA when powered on with the screen active and connected to a phone via Bluetooth. The Bluetooth radio alone is responsible for approximately 50mA of that consumption. For keyboard-based standalone devices, which rarely need Bluetooth other than for changing settings, users were forced to keep Bluetooth on regardless of necessity. There was no way to toggle Bluetooth on or off without physically connecting the device to a computer via serial or using the admin channel, which required another node for access.

Solution:
I implemented a new feature that allows users to turn off Bluetooth on keyboard devices by pressing Fn+b and turn it back on when needed. This enhancement significantly improves power efficiency for these devices.

Result:
With Bluetooth off, the device now consumes only 55mA. When combined with Power Save mode, the consumption can drop as low as 11mA, a substantial reduction from the previous 110mA. Users can still easily reconnect to a phone using the shortcut when necessary, offering greater flexibility and extended battery life.

* Remove 1 reboot at least.

I was able to prevent a reboot using the disableBluetooth(); command, current tested at 47-55mA, it doesn't require a reboot to turn off, but it does need reboot to turn back on.

* Update CannedMessageModule.cpp

* Add health telemetry module (meshtastic#4927)

* Add stub health telemetry module

* Add detection for MAX30102 Health Sensor

It lives on I2C bus at 0x57, which conflicts with an existing
sensor. Add code to check the PARTID register for its response 0x15
per spec.

* Add detection for MLX90614

An IR Temperature sensor suitable for livestock monitoring.

* Add libraries for MLX90614 and MAX30102 sensors

* Fix Trunk

* Add support for MLX90614 IR Temperature Sensor

* Add support for MAX30102 (Temperature)

* Make it build - our first HealthTelemetry on the mesh.

If a MAX30102 is connected, its temperature will be sent to the
mesh as HealthTelemetry.

* Add spo2 and heart rate calculations to MAX30102

* Switch MLX90614 to Adafruit library

Sparkfun was having fun with SDA/SCL variables which we can avoid
by switching to this highly similar library.

* Enable HealthTelemetry if MLX90614 detected

* Change MLX90614 emissivity for human skin.

* Add health screen!

* Remove autogenerated file from branch

* Preparing for review

* Fix MeshService master sync from before.

* Prepare for review

* For the americans

* Fix native build

* Fix for devices with no screen

* Remove extra log causing issues

---------

Co-authored-by: Tom Fifield <[email protected]>

* In shutdown, on button press, wake back to application rather than into the loader. (meshtastic#4997)

Suggested by lyusupov and implemented by todd-herbert.
meshtastic#4651

* De-conflict MLX90614_ADDR macro

* First version of a DeepSleep state for the RP2040 (meshtastic#4976)

* Adding pico-extra utils

* RP2040 can now go to deepsleep

* First RP2040 DeepSleep code - TODO : do better and restore

* FIX RAK11310 compilation (revert SDK + missing defines)

---------

Co-authored-by: Ben Meadors <[email protected]>

* Posthumous tronkination

* No idea why trunk wants to disturb these PNGs but...

* preliminary Othernet Dreamcatcher Support (meshtastic#4933)

* preliminary Othernet Dreamcatcher 2206 Support
Need to adapt to 2301 final version

* second target for latest revision

* preliminary Othernet Dreamcatcher 2206 Support
Need to adapt to 2301 final version

* second target for latest revision

* preliminary Othernet Dreamcatcher 2206 Support
Need to adapt to 2301 final version

* second target for latest revision

* address comments

---------

Co-authored-by: Ben Meadors <[email protected]>
Co-authored-by: Tom Fifield <[email protected]>

---------

Co-authored-by: beegee-tokyo <[email protected]>
Co-authored-by: Bernd Giesecke <[email protected]>
Co-authored-by: Ben Meadors <[email protected]>
Co-authored-by: GUVWAF <[email protected]>
Co-authored-by: GUVWAF <[email protected]>
Co-authored-by: Jonathan Bennett <[email protected]>
Co-authored-by: Tom Fifield <[email protected]>
Co-authored-by: HarukiToreda <[email protected]>
Co-authored-by: jhps <[email protected]>
Co-authored-by: Thomas Göttgens <[email protected]>
Co-authored-by: TheMalkavien <[email protected]>
panaceya added a commit to mesh-mk-ua/meshtastic-firmware that referenced this pull request Oct 9, 2024
* Add RAK4631 Ethernet Gateway with working JSON output to MQTT

* Update platformio.ini

Fix default build environment

* Fix default build platform

* Fix #ifndef and rename the variant

* Fix traceroute, neighborinfo and waypoint

* Disable SCREEN and enable TZ

* Fix platformio.ini conflict

* Fix formatting

* Another try to get the code format correct.

* Trunk fmt

* Remove accelerometer lib

* Toggle Bluetooth with Fn+b shortcut (meshtastic#4977)

* Toggle Blutooth with Fn+b shortcut

Problem:
As many are aware, ESP32 devices are known for their high power consumption. For instance, the Heltec ESP32 V3 draws around 110mA when powered on with the screen active and connected to a phone via Bluetooth. The Bluetooth radio alone is responsible for approximately 50mA of that consumption. For keyboard-based standalone devices, which rarely need Bluetooth other than for changing settings, users were forced to keep Bluetooth on regardless of necessity. There was no way to toggle Bluetooth on or off without physically connecting the device to a computer via serial or using the admin channel, which required another node for access.

Solution:
I implemented a new feature that allows users to turn off Bluetooth on keyboard devices by pressing Fn+b and turn it back on when needed. This enhancement significantly improves power efficiency for these devices.

Result:
With Bluetooth off, the device now consumes only 55mA. When combined with Power Save mode, the consumption can drop as low as 11mA, a substantial reduction from the previous 110mA. Users can still easily reconnect to a phone using the shortcut when necessary, offering greater flexibility and extended battery life.

* Remove 1 reboot at least.

I was able to prevent a reboot using the disableBluetooth(); command, current tested at 47-55mA, it doesn't require a reboot to turn off, but it does need reboot to turn back on.

* Update CannedMessageModule.cpp

* Add health telemetry module (meshtastic#4927)

* Add stub health telemetry module

* Add detection for MAX30102 Health Sensor

It lives on I2C bus at 0x57, which conflicts with an existing
sensor. Add code to check the PARTID register for its response 0x15
per spec.

* Add detection for MLX90614

An IR Temperature sensor suitable for livestock monitoring.

* Add libraries for MLX90614 and MAX30102 sensors

* Fix Trunk

* Add support for MLX90614 IR Temperature Sensor

* Add support for MAX30102 (Temperature)

* Make it build - our first HealthTelemetry on the mesh.

If a MAX30102 is connected, its temperature will be sent to the
mesh as HealthTelemetry.

* Add spo2 and heart rate calculations to MAX30102

* Switch MLX90614 to Adafruit library

Sparkfun was having fun with SDA/SCL variables which we can avoid
by switching to this highly similar library.

* Enable HealthTelemetry if MLX90614 detected

* Change MLX90614 emissivity for human skin.

* Add health screen!

* Remove autogenerated file from branch

* Preparing for review

* Fix MeshService master sync from before.

* Prepare for review

* For the americans

* Fix native build

* Fix for devices with no screen

* Remove extra log causing issues

---------

Co-authored-by: Tom Fifield <[email protected]>

* In shutdown, on button press, wake back to application rather than into the loader. (meshtastic#4997)

Suggested by lyusupov and implemented by todd-herbert.
meshtastic#4651

* De-conflict MLX90614_ADDR macro

* First version of a DeepSleep state for the RP2040 (meshtastic#4976)

* Adding pico-extra utils

* RP2040 can now go to deepsleep

* First RP2040 DeepSleep code - TODO : do better and restore

* FIX RAK11310 compilation (revert SDK + missing defines)

---------

Co-authored-by: Ben Meadors <[email protected]>

* Posthumous tronkination

* No idea why trunk wants to disturb these PNGs but...

* preliminary Othernet Dreamcatcher Support (meshtastic#4933)

* preliminary Othernet Dreamcatcher 2206 Support
Need to adapt to 2301 final version

* second target for latest revision

* preliminary Othernet Dreamcatcher 2206 Support
Need to adapt to 2301 final version

* second target for latest revision

* preliminary Othernet Dreamcatcher 2206 Support
Need to adapt to 2301 final version

* second target for latest revision

* address comments

---------

Co-authored-by: Ben Meadors <[email protected]>
Co-authored-by: Tom Fifield <[email protected]>

* Ignore packets coming from the broadcast address (meshtastic#4998)

---------

Co-authored-by: beegee-tokyo <[email protected]>
Co-authored-by: Bernd Giesecke <[email protected]>
Co-authored-by: Ben Meadors <[email protected]>
Co-authored-by: GUVWAF <[email protected]>
Co-authored-by: GUVWAF <[email protected]>
Co-authored-by: Jonathan Bennett <[email protected]>
Co-authored-by: Tom Fifield <[email protected]>
Co-authored-by: HarukiToreda <[email protected]>
Co-authored-by: jhps <[email protected]>
Co-authored-by: Thomas Göttgens <[email protected]>
Co-authored-by: TheMalkavien <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants