Update Time on a Raspberry Pi Pico w/CIrcuitPython: Parse JSON, format dates/times, & schedule jobs

แชร์
ฝัง
  • เผยแพร่เมื่อ 7 มี.ค. 2023
  • UPDATE: I probably should have accessed the time with get_time(), scheduled at "02:01" instead of "00:00", since daylight savings time is adjusted at 2am. If you use 12:00am, your time won't adjust properly for the first day of daylight savings time.
    We build on our earlier lesson accessing data over the Internet by parsing out the date and time, converting time to our timezone, converting time to readable formats, updating the Pico W's internal real time clock, and we schedule and run jobs at specified times and intervals.
    Part of Prof. John Gallaugher's Physical Computing course. See gallaugher.com/physical-compu... for details.

ความคิดเห็น • 11

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

    I probably should have accessed the time, scheduled at "02:01" since daylight savings time is adjusted at 2am. If you use 12:00am, your time won't adjust properly for the first day of daylight savings time.

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

    Thats a lot to digest at the speed you run through it. Theres excellent real world uses for this code, Ive done many projects with very similar code. It’s a necessary lesson. Time is hard to do no matter what language you use. Learning time functions can be as complicated as multidimensional arrays (tuples, lists, dicts).

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

      We’ll build on this creating a box that lights up when it’s time to take medications and turns off when the lid is opened. We’ll also access open weather’s api. So hopefully there will be chances for students to practice to make sure concepts are understood well enough for. their own projects. As always thanks foe your e courage,ent and kind words. Cheers!

  • @mrburgercz
    @mrburgercz 8 หลายเดือนก่อน +1

    Hi, it show me this:
    Traceback (most recent call last):
    File "", line 2, in
    File "circuitpython_schedule.py", line 54, in
    MemoryError: memory allocation failed, allocating 154 bytes
    I know there is problem with the scheduling library, but how to fix that? Thank you

  • @xprmntlav8r
    @xprmntlav8r 6 หลายเดือนก่อน

    Hi Professor, thanks so much for the TIME episode - it answered most of my questions and will work for me in my application. However, many times I'll be in the back country (no internet) where I'll need to update my RTC. I'll have my Mac with me and could get time off of the Mac's system clock but thus far I've been unable to figure this out. Do you have any ideas on how to get time off the Mac before unplugging the USB cable for operations. I have a DS3231 battery powered RTC that will do the time keeping in all cases. Thanks.

    • @profgallaugher
      @profgallaugher  6 หลายเดือนก่อน

      Hi. I’ve not done what you’re trying but the first thing to come to mind is you could run an MQTT server from your Mac and write a script to act as a subscriber getting clock requests and a publisher sending out the answer. Or you could just publish every minute but that might be a battery drain. I used to have students control a full Linux running Raspberry Pi with the Mosquitto MQTT broker on it and they’d write a Python script to act as a subscriber. The same should technically work on the Mac. But I’d check on Adafruit’s Discord since this sounds convoluted and there might be others who know of a lighter way to pull this off. Hope that helps. Also thanks for the kind words on the lesson. I appreciate it!

    • @xprmntlav8r
      @xprmntlav8r 6 หลายเดือนก่อน

      Wow!!! That was a fast response. I'll check out both avenues. MQTT server is probably way over my head at this point but persistence will prevail. Thanks again.

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

    Hi John. Have you ever used 'Adafruit PiCowbell Adalogger for Pico - MicroSD, RTC & STEMMA QT' (#5703)? This adds quite a few handy peripherals for $8. Gives a battery-backed RTC, microSD card slot and a Stemma QT connector and has CircuitPython & Arduino libraries. I use it to log data and it seems to work great. Are you aware of any issues with it?
    In this video you give some scheduler code but I'm not fully understanding it. The way you have it, it must run continuously which means I can't have any other code running. I guess you could add your own code in the While loop but in order for the scheduler to run you would have to ensure your code gives control back at least as fast as your scheduled task are to run. Is there any way you are aware of to allow the scheduler to run in it's own task so it could share the Pico with other things you need to do? I'm guessing Asyncio could allow something like this (but it's still in beta). Any other options?

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

      I haven’t used the Adalogger. It seems like a neat board. I had ordered the SD card and STEMMA QT cables before this came out. I may have chosen this if it was available. It does raise the height of the build which is restricting for a few. I would have to look back at the schedule code and likely won’t get to that in a while. It should be possible to do other things while the scheduler waits. This specific build doesn’t do much but wait for a time and turn on a light when needed. There may be some sample code in the community library that shows things you may find useful. Unsure. Good luck!

  • @TroyBrophy
    @TroyBrophy 4 หลายเดือนก่อน

    None of the "tm_" attributes is working for me. It causes an error when I try to use them.

    • @profgallaugher
      @profgallaugher  4 หลายเดือนก่อน

      What are the errors? I’m currently teaching in Australia but if you check out Adafruit Discord and post the error there you should get quick help. Good luck!