ESP32 Deep Sleep: Ultra-Low Power Coprocessor

แชร์
ฝัง
  • เผยแพร่เมื่อ 20 พ.ค. 2024
  • 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 ปีที่แล้ว +5

    The thumbnail is so hilarious

  • @TD-er
    @TD-er 2 ปีที่แล้ว +16

    As far as I know, this is the most extensive video on ESP32 ULP programming.
    Thanks!

  • @chuckcrizer
    @chuckcrizer 2 ปีที่แล้ว +2

    Much appreciated. This was a very well done technical video. Watched it a number of times.

  • @piconano
    @piconano 2 ปีที่แล้ว +16

    Epic video. Can't wait for the ADC and I2C video.

    • @atomic14
      @atomic14  2 ปีที่แล้ว +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!!

  • @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 👍

  • @theworldopenthenext
    @theworldopenthenext 2 ปีที่แล้ว

    Man, haven’t you just explained Assembly basics in three minutes or so? Amazing

  • @andrew2004sydney
    @andrew2004sydney 2 ปีที่แล้ว

    Excellent video! Thanks for making it

  • @yurievi4
    @yurievi4 2 ปีที่แล้ว

    as always informative and marvelous!

  • @CagnPolat
    @CagnPolat ปีที่แล้ว

    An other great video. Thank you...

  • @amazingtechnology1961
    @amazingtechnology1961 3 หลายเดือนก่อน

    Thank you!

  • @theruisu21
    @theruisu21 ปีที่แล้ว

    this video is great!

  • @Magic-Smoke
    @Magic-Smoke 2 ปีที่แล้ว +3

    So glad you've done this. Roll on the I2C work :)

    • @atomic14
      @atomic14  2 ปีที่แล้ว +1

      Should be soon - might do the ADC first, I'll see how they progress.

  • @ei23de
    @ei23de 2 ปีที่แล้ว +1

    Super useful for low power IOT devices! Thank you!

    • @atomic14
      @atomic14  2 ปีที่แล้ว +1

      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.

  • @Bianchi77
    @Bianchi77 2 ปีที่แล้ว

    Creative video, thanks :)

  • @MPElectronique
    @MPElectronique 2 ปีที่แล้ว

    Hello. Does it work with esp32 core 1.0.5 of Arduino IDE?
    Thanks.
    Marc.

  • @NotMarkKnopfler
    @NotMarkKnopfler 2 ปีที่แล้ว +1

    This is gold thank you!

  • @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.

  • @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.

  • @sharpbends
    @sharpbends 2 ปีที่แล้ว +1

    Good explanation thank you :-)

    • @atomic14
      @atomic14  2 ปีที่แล้ว

      Thanks :)

  • @edgull_tlt
    @edgull_tlt 2 ปีที่แล้ว

    Спасибо

  • @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.

  • @remy-
    @remy- 2 ปีที่แล้ว +1

    I’m full into studying the esp32-s3 now, because it has a c-programmable ulp..

  • @TobiasWerner1
    @TobiasWerner1 2 ปีที่แล้ว +1

    Thanks for this great video! When explaining the LD/ST commands, shouldn't the last example call be "ST R1, R2, 0"?

    • @BerthaProt
      @BerthaProt ปีที่แล้ว +1

      I agree, should be ST, R1, R2, 0

  • @johntilghman
    @johntilghman 2 ปีที่แล้ว

    Which ESP32 board are you using, could I get a link to it?

  • @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 ปีที่แล้ว +1

      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

  • @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.

  • @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 ปีที่แล้ว +1

      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!)

  • @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...

  • @YTbxg
    @YTbxg 2 ปีที่แล้ว +1

    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 :)

  • @lowkuleeuwner2815
    @lowkuleeuwner2815 2 ปีที่แล้ว +1

    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.

  • @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 ปีที่แล้ว +1

      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

  • @zolar7a
    @zolar7a 2 ปีที่แล้ว +1

    I haven't used assembly since 1991, I'm going to have to dust off the cobwebs. Thanks for the video.

    • @atomic14
      @atomic14  2 ปีที่แล้ว +1

      I used to do a bunch on my old ZX Spectrum - that's a long time ago now :)

  • @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 :)

  • @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!

  • @thexht7927
    @thexht7927 5 หลายเดือนก่อน

    1:08 at this point, I usually just add nmos to flip the logic to active high 😂

  • @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?

  • @NotMarkKnopfler
    @NotMarkKnopfler 2 ปีที่แล้ว +1

    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 ปีที่แล้ว +2

      I've got into the habit of packing an ESP32 on my all my trips - keeps me out of trouble...

  • @browaruspierogus2182
    @browaruspierogus2182 2 ปีที่แล้ว

    similar code was written years ago. ULP can even do I2S and I2C

    • @atomic14
      @atomic14  2 ปีที่แล้ว +1

      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,

  • @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?

  • @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 ปีที่แล้ว +1

      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.

  • @majid505
    @majid505 2 ปีที่แล้ว

    I smashed the like for the thumbnail only. Video didn’t watch 😂

  • @lemingtai3747
    @lemingtai3747 2 ปีที่แล้ว

    I clicked the video just because of the thumbnail

    • @atomic14
      @atomic14  2 ปีที่แล้ว +1

      I hope you weren't disappointed :)

    • @lemingtai3747
      @lemingtai3747 2 ปีที่แล้ว +2

      @@atomic14 I wasn't, thanks for the video

  • @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 😘