ESP32 Deep Sleep: Ultra-Low Power Coprocessor

  Переглядів 28,271

atomic14

atomic14

День тому

We're taking an even deeper loop into deep sleep in this video. As always, big thanks to PCBWay for sponsoring this video - check them out at www.PCBWay.com/?from=atomic.
We're following on the previous deep sleep deep dive video ( • Mastering ESP32 Deep S... ) and taking a look at the Ultra Low Power (ULP) coprocessor.
The ULP coprocessor is a really interesting part of the ESP32 device. It's a really powerful additional processor that can run even when the main device is in deep sleep.
I had to learn how to use this to get deep sleep working well in my DIY e-Reader project ( • DIY eBook Reader - Bui... ).
There is a plugin for the Arduino IDE that will add support for the ULP assembler - github.com/duff2013/ulptool and there's also a C compiler that will generate ULP assembly code - github.com/jasonful/lcc
[0:00] Why are we here?
[1:14] What are we doing in this video?
[2:14] What is this ULP thing anyway?
[3:00] The ULP instruction set
[6:30] How to use it with PlatformIO
[8:50] How to use it with the Arduino IDE
[9:13] Waking up the main processors
[10:13] Reading GPIO pins from the ULP
[13:00] Sharing data between the ULP coprocessor and the main processors
[14:02] Writing to GPIO pins - Blink on the ULP
GitHub repo with the code is here: github.com/atomic14/esp32-ulp
Thanks for watching - I'll see you in the next video!
----
Patreon: / atomic14
ko-fi: ko-fi.com/atomic14

КОМЕНТАРІ: 94
@soufianeboulachgour3965
@soufianeboulachgour3965 2 роки тому
The thumbnail is so hilarious
@TD-er
@TD-er 2 роки тому
As far as I know, this is the most extensive video on ESP32 ULP programming. Thanks!
@piconano
@piconano 2 роки тому
Epic video. Can't wait for the ADC and I2C video.
@atomic14
@atomic14 2 роки тому
Hopefully in the next couple of weeks :)
@piconano
@piconano 2 роки тому
@@atomic14 👍
@remy-
@remy- 2 роки тому
@@atomic14 my god. The hw i2c function is the most unsupported ever from Espressif haha. Very curious if you can let it run. Nice video this one!!
@chuckcrizer
@chuckcrizer 2 роки тому
Much appreciated. This was a very well done technical video. Watched it a number of times.
@iiilllii140
@iiilllii140 Рік тому
This was a very well explained, in depth video. I was lacking some prerequisites, but now after some study (assembly,bit operators,...), and rewatching your video this makes totally sense. I will take a look into the rtc register, thanks for the provided link 👍
@Magic-Smoke
@Magic-Smoke 2 роки тому
So glad you've done this. Roll on the I2C work :)
@atomic14
@atomic14 2 роки тому
Should be soon - might do the ADC first, I'll see how they progress.
@yurievi4
@yurievi4 2 роки тому
as always informative and marvelous!
@atomic14
@atomic14 2 роки тому
Thanks!
@andrew2004sydney
@andrew2004sydney 2 роки тому
Excellent video! Thanks for making it
@theworldopenthenext
@theworldopenthenext 2 роки тому
Man, haven’t you just explained Assembly basics in three minutes or so? Amazing
@ei23de
@ei23de 2 роки тому
Super useful for low power IOT devices! Thank you!
@atomic14
@atomic14 2 роки тому
The ESP32 keeps on surprising me with what it can do.
@ei23de
@ei23de 2 роки тому
@@atomic14 Yep, there is a lot to discover! The TOF feature of the ESP32-S2 also got me interested.
@NotMarkKnopfler
@NotMarkKnopfler 2 роки тому
This is gold thank you!
@atomic14
@atomic14 2 роки тому
Thanks!
@theruisu21
@theruisu21 Рік тому
this video is great!
@CagnPolat
@CagnPolat Рік тому
An other great video. Thank you...
@Bianchi77
@Bianchi77 2 роки тому
Creative video, thanks :)
@amazingtechnology1961
@amazingtechnology1961 2 місяці тому
Thank you!
@sharpbends
@sharpbends 2 роки тому
Good explanation thank you :-)
@atomic14
@atomic14 2 роки тому
Thanks :)
@theunderdog2205
@theunderdog2205 2 роки тому
Another very well put together video, thanks for your efforts. I have one question where did the video go showing how u setup your linux audio server? I have the esp32 setup just need instructions on the server side. Thanks in advance
@atomic14
@atomic14 2 роки тому
I'm not sure I did a video on it - there's instructions here: github.com/atomic14/esp32_audio#server - let me know if you have any problems.
@WistrelChianti
@WistrelChianti 2 роки тому
thanks that's super useful. I want to go back over my previous ULP code now with a hopeful renewed understanding of what it's doing. Might see if I can pass a var back and forth too... (was only controlling pins before).
@WistrelChianti
@WistrelChianti 2 роки тому
what I'm a little unsure of still is what config state the pins are in during main code/cores execution after the ULP has been playing with them. A nice example would be to cover how to (elegantly - fairly certain I badly hacked it) pass control of a pin back and forth between the ULP and the main processors. Interested to know a little more about running them both (main cores and ULP) at the same time too. What was the 5 second thing doing incidentally? waiting 5 seconds before deep sleeping and starting the ULP?
@WistrelChianti
@WistrelChianti 2 роки тому
ah, having watched your deep sleep video I think I get it now. So in essence all pin states are dropped whenever you enter deep sleep. The only way to maintain them, is to set the hold bit on each pin you want to maintain the state of. If you want to change the pin state though via the ULP when the main cores are sleeping, you need to unset the hold bit, make your change, and then ensure you set it again before halting... presumably, if you didn't, and the pin was high, it would just switch off as soon as the ULP hits halt? When you get back to main core code, presumably everything about a pin with the hold bit set is maintained (direction, pullups, state)? Does this sound right or am I still getting confused? Presumably, if both the ULP and main cores are running at the same time, the hold bit is irrelevant?
@atomic14
@atomic14 2 роки тому
That's correct, if you don't set the hold bit as soon as the ULP program halts the pin would switch off. That is a good question about when you come out of sleep - and I'm actually not sure on the answer. Needs investigation.
@WistrelChianti
@WistrelChianti 2 роки тому
@@atomic14 thanks! Glad I'm not asking daft things! (could easily happen!)
@remy-
@remy- 2 роки тому
I’m full into studying the esp32-s3 now, because it has a c-programmable ulp..
@zolar7a
@zolar7a 2 роки тому
I haven't used assembly since 1991, I'm going to have to dust off the cobwebs. Thanks for the video.
@atomic14
@atomic14 2 роки тому
I used to do a bunch on my old ZX Spectrum - that's a long time ago now :)
@TobiasWerner1
@TobiasWerner1 2 роки тому
Thanks for this great video! When explaining the LD/ST commands, shouldn't the last example call be "ST R1, R2, 0"?
@BerthaProt
@BerthaProt Рік тому
I agree, should be ST, R1, R2, 0
@victoralberti198
@victoralberti198 2 роки тому
I have one question about that hold bit at 14:34 , because I notice that register exists in source code, however it's not present into the technical reference manual. How did you know that you needed to set/clear this hold bit into this register? Thanks for another great video, it's certainly the most valuable video I ever found about ULP.
@victoralberti198
@victoralberti198 2 роки тому
JFY, in the page 85 of the reference: www.espressif.com/sites/default/files/documentation/esp32_technical_reference_manual_en.pdf, it says the bit 25-31 are reserved and it doesn't mention a lot of information about holding the output.
@NotMarkKnopfler
@NotMarkKnopfler 2 роки тому
I'm going to be trying this out tonight. I am in a hotel (by myself) for the next few days and I brought an ESP32 with me. Time to play....
@atomic14
@atomic14 2 роки тому
I've got into the habit of packing an ESP32 on my all my trips - keeps me out of trouble...
@YTbxg
@YTbxg 2 роки тому
A really useful video and very interesting. (plus I may now boast that I have done some assembly language code - better be careful or someone my think I'm a real programmer :-)
@atomic14
@atomic14 2 роки тому
Proper old school development :)
@juandeMTO
@juandeMTO 2 роки тому
Good Video!! What should be the changes to use the Platformio IDE with the Arduino framework instead of the esp-idf?
@atomic14
@atomic14 2 роки тому
With platformio you only have support for the ULP if you are using ESP-IDF framework. But you can add the Arduino library as a component. It's not for the faint hearted, but the instructions are here: docs.espressif.com/projects/arduino-esp32/en/latest/esp-idf_component.html I will do a video on this at some point and run through the instructions to make sure they work!
@ishdemon_
@ishdemon_ 2 роки тому
@@atomic14 looking forward to that
@MPElectronique
@MPElectronique 2 роки тому
Hello. Does it work with esp32 core 1.0.5 of Arduino IDE? Thanks. Marc.
@davidkleng1711
@davidkleng1711 2 роки тому
High, great video. Do you have any about begining with ESP32 programming? I only program it with arduino.
@atomic14
@atomic14 2 роки тому
The ESP-IDF GitHub repo has some good examples, most things translate across quite easily. A lot of the difficulty is that a lot of libraries assume that you are building on top of Arduino. You can run Arduino as an ESP-IDF component. And there's also nothing stopping you using ESP-IDF functions when using the Arduino framework.
@edgull_tlt
@edgull_tlt 2 роки тому
Спасибо
@RGPinger
@RGPinger 2 роки тому
is it possible to use ULP coprocessor with ultrasonic distance sensor (HC-SR04 or JSN-SR04T) that have Trigger and Echo pin? I want to use ULP coprocessor to measure distance between sensor and water level each 5 minutes and then wake up Xtensa and send data via HTTPS POST request to webserver. I was thinking how to program it. This video gave me really good answers to questions how to start, but I am unable to do it :-) I was never programming in Assembly.
@lowkuleeuwner2815
@lowkuleeuwner2815 2 роки тому
Wow this is awesome. I am really into this. I have one question. I want to count pulses using the ULP. I want to sleep in the ULP for x amount of time and every time a gpio int is triggered then increment counter and go back to sleep (not necessarily wake the main mcu). But the only way I have found to do this so far is to wake the main mcu for a very short time after the interrupt, check if it was woken by the timer or the interrupt and go back to sleep. Do you think this is possible with only the ULP.
@atomic14
@atomic14 2 роки тому
The only way I know how to do this is have the ULP wake up quite often and poll the GPIO to detect if it has changed and count a pulse. At the same time maintain a count of how often the ULP has woken - this will give you a rough measure of how much time has passed and you can wake the main mcu when you want to.
@lowkuleeuwner2815
@lowkuleeuwner2815 2 роки тому
@@atomic14 Thank you so much for the reply. I actually have an external timer that manages my Sleep time. So in theory I want to have absolute minimum power usage while counting the pulse pin, and then when the other pin is triggered turn main mcu on. I guess my question is, can the ULP go into a sort of sleep mode and get woken up by pin interrupts, and decide whether to go back to sleep (after incrementing counter) or wake main MCU.
@atomic14
@atomic14 2 роки тому
@@lowkuleeuwner2815 Unfortunately not, there's no interrupt wakeup for the ULP. I did find this forum post where someone was trying to do pretty much what you are talking about www.esp32.com/viewtopic.php?t=16493
@WistrelChianti
@WistrelChianti 2 роки тому
@@atomic14 I'm guessing the ULP is low enough in power it's almost considered to an interrupt in it's own right... but a slightly more intelligent one. That being the case... maybe just have it run code that checks the input pin for state changes constantly and maintaining a count, then have it wake the main cores when it's over threshold. When programming counters on the ULP, keep in mind the small size of the registers though. You'll possibly blow your way up to 65536 pretty fast.
@WistrelChianti
@WistrelChianti 2 роки тому
@@lowkuleeuwner2815 just been having a read around on this and indeed as atomic said, can't be done. You can only wake the ULP from a timer, not an interrupt. Not what you are after but for bonus fun, apparently you can have more than one ULP program. You can also have the ULP program control how long it sleeps for in between executions (5 configurable options see sleep command). So for example you could have a long delay before it initially starts, then shorter delays between subsequent runs. You could have logic in your program that changes which delay is being used, so possibly this functionality may be used to allow longer or shorter sleep periods depending on the state of things that you care about.
@TheEmbeddedHobbyist
@TheEmbeddedHobbyist 2 роки тому
Nice, currently having problems with ESP8266RTOS and Eclipse IDE which is driving me mad. with some projects the IDE can't resolve the include files. so shows errors that arn't there, but of course the complier can so they build fine. 😞
@atomic14
@atomic14 2 роки тому
I hate it when that happens - the tools are conspiring against us!
@TheEmbeddedHobbyist
@TheEmbeddedHobbyist 2 роки тому
@@atomic14 The worst of it is it's a well known fault with windoze. all fixes i can find don't fix it. the bugger is some projects don't have the issue with the same includes ?
@atomic14
@atomic14 2 роки тому
@@TheEmbeddedHobbyist VSCode sometimes has the same problem with C++ Occasionally it just forgets how to autocomplete or find headers. Or it starts using gigabytes of RAM! I think C++ is just a hard problem :)
@thexht7927
@thexht7927 5 місяців тому
1:08 at this point, I usually just add nmos to flip the logic to active high 😂
@ulis.1544
@ulis.1544 2 роки тому
Isn't there an issue on the esp32 ulp when using i2c that prevents you from reading low bytes. Have a look on the esp32 forum
@atomic14
@atomic14 2 роки тому
Interesting - I'll take a look - could save me a lot of headscratching!
@browaruspierogus2182
@browaruspierogus2182 2 роки тому
similar code was written years ago. ULP can even do I2S and I2C
@atomic14
@atomic14 2 роки тому
Definitely I2C - there are even people bit-banging I2C to support 16 bits communication. I haven't seen anyone doing I2S though I'm sure it's possible,
@WistrelChianti
@WistrelChianti 2 роки тому
How much memory is available to the ULP? You mentioned there is 8k (or was it 16k?) RTC/recovery memory available to store data in during deep sleep in your deep sleep video (usable via a prefix to a variable declaration). Can the ULP also reach this memory? or is it the same memory even?
@atomic14
@atomic14 2 роки тому
Yes, the ULP can read the same memory, from ESP32-DevKitC v4 onwards it's 16Kb, before that it's 8Kb. So probably safest to stick to just 8Kb unless you know what your code will run on.
@WistrelChianti
@WistrelChianti 2 роки тому
@@atomic14 if you mean the dev board, I'm using a DOIT v1 IIRC however I suspect you mean something else... e.g. the actual chip? any way to determine what I have?
@nikkismith8750
@nikkismith8750 2 роки тому
Thanks for such a great video! Have you had any success in getting the ULP I2C_RD instruction working? or do we have to bit-bang in software?
@atomic14
@atomic14 2 роки тому
I haven't done it myself yet - from reading around the biggest limitation is that it will only do 8 bits. So if you want 16 bits you have to bit-bang.
@nikkismith8750
@nikkismith8750 2 роки тому
@@atomic14 thanks so much for the quick reply :) I'm just writing a ULP program that needs ADC and I2C, so I wish I could jump into the future and watch your next video in this series. lol
@iambyrdman
@iambyrdman 2 роки тому
If you help me with some ESP programing, I'll cut you into the payout I'll have for a patent I have that I need help programing a chip for simple stuff. Listening for sounds to slow, then cutting power when it slows. Can you help? New sub here. Love your stuff. I owned a Commodore vic 20 when it was a new product, how long I've been a geek...
@johntilghman
@johntilghman 2 роки тому
Which ESP32 board are you using, could I get a link to it?
@zyghom
@zyghom 2 роки тому
I was so hopeful seeing the subject of this video and then ... I got lost after 3rd minute or so... time to go back to school ;-(
@WistrelChianti
@WistrelChianti 2 роки тому
There were some mistakes at the start that may have thrown you. The narration doesn't match what is being highlighted near the start. e.g. he talks of a command taking a register and a register as input while highlighting the form that takes a register and a value, or vice versa. I'm not sure if the add command was whack or not too. There is a mistake too with ST command where he stores at the memory location of R0 instead of R2 (as illustrated in the memory diagram).
@zyghom
@zyghom 2 роки тому
@@WistrelChianti no no, it is my who knows nothing - not about bad video ;-)
@atomic14
@atomic14 2 роки тому
You're right - the MOV from immediate is highlighted when the move from register should be. And the ST example has a bug in it.
@peter.stimpel
@peter.stimpel 2 роки тому
nice topic. fiddling with power consumption caused a few more grey hair, here
@atomic14
@atomic14 2 роки тому
Indeed, there's a lot of variables to play with and a lot depends on the board you are using and how well it's been designed.
@poepflater
@poepflater 2 роки тому
I would like a way to run a PWM pin while in deep sleep mode
@atomic14
@atomic14 2 роки тому
I think the only way to do that would be by bit-banging with the ULP. What frequency do you need to run at?
@lemingtai3747
@lemingtai3747 2 роки тому
I clicked the video just because of the thumbnail
@atomic14
@atomic14 2 роки тому
I hope you weren't disappointed :)
@lemingtai3747
@lemingtai3747 2 роки тому
@@atomic14 I wasn't, thanks for the video
@majid505
@majid505 2 роки тому
I smashed the like for the thumbnail only. Video didn’t watch 😂
@EmilFihlman
@EmilFihlman 2 роки тому
I doubt that comment about .S vs .s
@atomic14
@atomic14 2 роки тому
github.com/duff2013/ulptool “Typically in Arduino you can compile assembly files using the '.S' extension. Using the ESP32 Arduino core framework these files would correspond to the Xtensa processors whose toolchain is incompatible with the ULP coprocessor. Luckily, Arduino provides a fairly easy series of recipes for building the ULP assembly files by using the '.s' extension which Arduino will let you create.”
@EmilFihlman
@EmilFihlman 2 роки тому
@@atomic14 yeah so like I said, you can use either, it's not a hard coded limitation, by changing the configs to select the correct files. I bet you can use .s in platformio just fine by changing the makefiles etc to use .s instead of .S etc.
@atomic14
@atomic14 2 роки тому
@@EmilFihlman In platform.io you can yes - but not in Arduino. Even though you can use whatever you want in platform.io it's probably best to stick with what the ESP-IDF documentation suggests?
@rubialugattimoreira1978
@rubialugattimoreira1978 Рік тому
Not for beginners 😘
PlatformIO: All you need to know in 10 Minutes!
10:56
J's e-shack
Переглядів 276 тис.
EEVblog 1524 - The 10 CENT RISC V Processor! CH32V003
19:55
EEVblog
Переглядів 297 тис.
#266 ESP32 Deep Sleep Project - Door Open/Closed Detection with ESP-NOW
25:18
#363 Which ESP32 pins are safe to use?
11:53
Andreas Spiess
Переглядів 123 тис.
The Cheapest Microcontroller? Getting started with the 10 cent Puya PY32.
21:36
Latch Circuit - Wake up + 0 Power Consumption (useful circuit)
9:16
Electronoobs
Переглядів 134 тис.
DIY eBook Reader - Build your own Kindle using an ESP32
7:55
atomic14
Переглядів 40 тис.
Геймер с самым быстрым интернетом
1:00
ЖЕЛЕЗНЫЙ КОРОЛЬ
Переглядів 389 тис.
300 000 за🚀МОЩНЫЙ, Но МЕРТВЫЙ ноут из Китая. Ремонт cyberpowerpc tracer 7 EDGE. Нюансы китай ноутов.
46:12
ААНТ КОНТАКТ Сервис по ремонту техники в ЕКБ, СПБ
Переглядів 59 тис.
GOOGLE СДЕЛАЛИ НЕВОЗМОЖНОЕ! Это круче любого Samsung, Apple и Xiaomi…
13:16
Thebox - о технике и гаджетах
Переглядів 67 тис.
Как открыть дверь в Jaecoo J8? Удобно?🤔😊
0:27
Суворкин Сергей
Переглядів 622 тис.