Is there a Real Time Clock in PicoBricks?

Just thinking about my own future projects and wondering if there is any way to set/get current date/time data? I'm using MicroBlocks for now... Maybe the Raspberry PI Pico chip has an embedded RTC?

Comments

  • There's an rtc in the pico 2040, but there are to issues with it:

    • it is not sub-second capable
    • there is no built-in battery, so it cannot persist.
    • also. from MicroBlocks, there is no block to accees the rtc component of the processor.

    However, as usual, there are always workarounds:

    Under FIle/Open/Examples/Network there is a project called "Online Clock Example".

    Starting with that, and adopting it to work with the ESP01 WIFI module, you can implement a clock logic that can initialize itself upon startup, with the network time. Since MB is capable of the ticking at millisec level, it might end up being better than the Pico rtc option.

    There is also a timer project in the PicoBricks activities that implements a countdown timer, which can be modified to serve as the basis of a clock logic.

    Of course, you are also free to experiment with many other methods that can be implemented using the Python or Arduino interfaces.

    I think, this is the beauty of these microprocessors and simple programming methods that allows one to try out many different things.

  • Thanks @Turgut ! The WiFi module appraoch sounds encouraging. Years ago (actually 40+ years :) ), I used a small IC from Dallas Semiconductor that had a RTC with built-in battery offering 10+ years retention. I imagine they've got even more capabilities now...

  • @Turgut thanks for the info! Where do we find the library(s) needed to support the ESP8266 WiFi module? I do see Libraries->Network->WiFi, but no sign of any code blocks that start with "ESP01_".

    That Online Clock Example also states it requires a TFT display. I assume the little OLED display that came with PB is not a TFT display - so would need to rewrite that as well?

    Why was that particular example included if the hardware requirements are different than what ships with our PB kits?

  • "Why was that particular example included if the hardware requirements are different than what ships with our PB kits?"

    Using MicroBlocks you can program a lot of different boards. https://wiki.microblocks.fun/boards/supported, not just Raspberry Pi Picos.

    The example @Turgut showed was made with another board/screen in mind. You could change it so it works with the OLED screen of your PicoBricks.

  • @PeterMathijssen that's what I was guessing :) Would be nice if the code was redone for the PB product...

    BTW - where do we find the library for the ESP8266 (WiFi module)?

  • Turgut
    edited November 2022

    There is no library code for the ESP01. Instead there is a project #25 Smart Green House that uses the ESP01 as a server. All the ESP011 codes needed for that project is under Custom Blocks. This project is an advanced project and it will require a bit of knowledge on data communications with Serial Protocol.

    You can study that project and also read a bit about the ESP01 AT codes to see how all is put together.

    Since there is only a single project with ESP01, we did not make it into a library yet. However, you are free to use it and modify it to send and receive messages as shown in the WIFI example. It will require a bit of "programming" to achieve the same functionality. As you mentioned, the other WIFI project was meant for a unit with a TFT display. But the OLED in the PicoBricks is very similar in blocks usage to the TFT library. So you can easily replace the TFT display blocks with OLED display blocks and achieve similar output. After all, what is the fun in just copy / pasting all the code !

    Raspberry organization also created a WIFI version of the Pico board. Because of this, the future apps will be gravitating towards this new processor and utilize the WIFI library that the Online Clock example uses.

    If you decide to tackle your project, we are here to help you out as you get stuck in various different ways! The result will be worth trying!

    😎

  • Oh, how disappointing to learn there is no library for the ESP8266 WiFi module :( That was one module that I planned on using a LOT. Oh well, I'll see if I can make any sense of the MicroBlocks code that is in Project #25 - but it's very confusing for a newbie (which all of us are at this point)...

  • Turgut
    edited November 2022

    @ReedMikel

    There is no difference between having a library and using custom blocks (My Blocks). All libraries start out as custom blocks and then get exported.

    If you want to or plan to use ESP01 a lot, you are going to need much more than just the library. In cases like ESP01 comms, there is also the need for what I call "glue" logic that makes coordination of events work. These are never in the library. You are not in an environment where you make sequential library calls and string them together as in Python or Arduino IDEs.

    Best approach is to first study the example and understand the comm flow, msg handling, msg parsing, etc. Then you can modify the behavior to your needs.

    Please keep in mind that you are working in a very memory constrained micro processor environment in a real time fashion. There is no compiling and optimizing code by a compiler. There are limits to size of code and libraries. Therefore, when working in MicroBlocks with advanced projects one needs to get good in understanding of the environment and restrictions. We simply cannot put everything into a Library; it would be huge and will not fit. So work needed has to be split between some custom block code and some application coordination logic.

    However, that does not mean one cannot do serious stuff in MB. The perfect example is the OLED library that I have written, which performs at C++ levels or better, is 26K+ in size and is TOTALLY written in MicroBlocks, manipulating the hardware. You can open read each and every block of it. There is no hidden magic behind the scenes.

    The PicoBricks kit and the block programming paradigms provided are primarily a learning environment where experimentation and exploration is the key learning approach. If you are only comfortable with running examples and don't feel like experimenting, then you might not be happy with the exploratory approach, and might be better served by the Python or Arduino environments, with their compiled, linked, and downloaded approach to programming. and relatively less memory restrictions.

    I understand the overwhelming amount of "NEW" that needs to be absorbed, understood, and applied. I will try to coordinate a few WEB presentation sessions to cover the complicated projects, as it is rather lengthy and hard to write about each and every detail. I believe an interactive session with interested users like yourself will be more productive.

    Many ways to skin a cat...

  • ReedMikel
    edited November 2022

    Interesting how important memory still is when developing apps for Pico. I used to write in assembly language (8086, 8051, Z80 etc) and developed/sold a modem communications library for use by programmers working with Microsoft’s FoxPro database language. My library supported up to 16 COM ports being used simultaneously. My library was about 35k in size and had over 30,000 lines of code… This is bringing back memories:)

  • What is the approximate upper memory limit of the Pico chip?

  • When you have an empty project and pico I get this


    The free memory block is in the advanced section of the data category.

    This project

    Leaves this much free space


    The PicoBricks demo project in the examples leave this much free space


  • Turgut
    edited November 2022

    You can check the specs for the PICO2040 chip (https://datasheets.raspberrypi.com/rp2040/rp2040-datasheet.pdf) for memory limits.

    If you are playing in the Arduino / Python IDE environment with compilers etc, you will go by those limits.

    However, remember that while in MicroBlocks, those do not mean much, as the MB VM (virtual machine), user programs, libraries, variables, user functions all need to use a slice of the big pie. So there are other limits imposed by the MicroBlocks to make sure everything runs real-time with all the events firing on time, and still allow the users to modify the running code.

    There are a few holy numbers:

    Individual script size: 1000 bytes; Strings: about 800 bytes; Numbers: 32 bit limit (actually 30 bits); IO buffers: change depending on method used, but still bracketed by the 1000 byte limit.

    @PeterMathijssen s memory numbers are related to runtime memory for the user programs and their data structure needs, but is not indicative of the numbers I have provided. VM needs its space as well, and will complain when things are not quite sufficient, which is very dependent on what processor board you are running on. The style of code you write impacts the memory use and dynamics a lot. For small programs, nothing really matters much. But as you get into bigger tasks, you will have to abide by the limits and use the proper techniques, or things will simply not be the way you want it.

    When one is working in microsecond resolution event driven environment all in blocks, one tends to forget that it is not the same as the compiler optimized code running in other IDEs.

    Back behind the chips and circuits, it is a wild wild world! And we love it, of course!

  • So of the 264KB SRAM memory, over 200KB is being used by the MicroBlocks VM?

    I see there are at least 3 variations of Pico, do any have more SRAM?

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!