FORTH on the PicoCalc

Also, @tabemann , haha - yes, the emacs influence is clear! Luckily in my day job I can use emacs on a Mac, and TRAMP can come to the rescue for remote machines.

In other news, I have just been playing about on my lunch break and seem to have run into a bit of an error with loading code from fat32 - please excuse the photograph (I’ve added some crs to try and make it more legible).

This is using the “default” fat32 filesystem rather than the psram. I’ll see if I can dig a bit deeper this evening to check if I’m missing something.

That error is because of naming – fat32-tools::load-file takes a file object not a path. If you want to use a path to load a source file, use fat32-tools::included ( path-addr path-bytes – ).

It seems that I can’t edit comments older than a certain age. I would recommend for the most up-to-date directions going by USING_THE_PICOCALC.md in the picocalc-devel branch as mentioned.

Aha! Thanks for that - I figured it’d be user-error on my part.

The naming wasn’t well-chosen on my part, but included is the standard word for evaluating files by ( path-addr path-bytes – ) in Forth (but in zeptoforth it is not part of the default wordlist/module).

Hmm… now I can go back and edit my old posts (this is likely because I have now been granted ‘member’ status), so I have updated my initial post about the zeptoforth PicoCalc terminal emulator with new information, including mentioning extra/rp_common/picocalc_term_common.fs and the text-only PicoCalc terminal emulator.

I have added extra/rp_common/picocalc_fat32.fs for incorporating convenient filesystem access. It automatically compiles to flash and reboots, so there is no need to issue compile-to-flash before it.

It should be loaded after extra/common/setup_blocks_fat32.fs and, if you are using a Pimoroni Pico Plus 2 or Pico Plus 2 W, extra/rp2350/setup_pico_plus_2_psram_fat32.fs.

It adds the words blocks-fs@ ( – fs ) and blocks-fs: ( – ), if extra/common/setup_blocks_fat32.fs has been loaded; sd-fs@ ( – fs ) and sd-fs: ( – ), unless an identifier no-sd-fs is defined; and psram-fs@ ( – fs) and psram-fs: ( – ), if extra/rp2350/setup_pico_plus_2_psram_fat32.fs has been loaded.

blocks-fs@, sd-fs@, and psram-fs@ return FAT32 filesystem objects.

blocks-fs:, sd-fs:, and psram-fs: change the current filesystem to the selected FAT32 filesystem.

blocks-fs@ and blocks-fs: pertain to the FAT32 filesystem in on-board block storage. sd-fs@ and sd-fs: pertain to the FAT32 filesystem on the SD card. psram-fs@ and psram-fs: pertain to the FAT32 filesystem in PSRAM.

Warning: from trying out an old microSDHC card of mine that I had previously used with zeptoforth on my microSD({H,X}C) adapter board as test, it seems that there may be issues with the zeptoforth FAT32 implementation, because I ran into invalid date errors reported by zeptoforth, and when I ran the card through dosfsck a good few errors were listed and it ended up corrupting the card further to the point that I had to run mkdosfs. As a result, before using an SD card with zeptoforth I suggest backing up its contents if you care about them. If you get any errors with SD cards aside from things such as simple timeout errors which are unlikely to be filesystem-related, please report them to me so I can sort out any issues with the zeptoforth FAT32 implementation.

Updates:

I have identified a couple significant bugs in the zeptoforth FAT32 implementation which I am busy putting together a 1.13.2 release to fix. These fixes will not break your existing FAT32 filesystems but will reduce the chances of breakage and increase compatibility with outside FAT32 filesystems on SD cards.

Another update:

zeptoforth 1.13.2 is out. This release updates the USB VID:PID for the USB CDC console (note that you will not most likely be using this for the PicoCalc), adds online help for zeptoed, fixes bugs with parent directory handling and new directory cluster initialization w.r.t. FAT32 support, and fixes a bug in flush-console w.r.t. the USB CDC console that was causing stack underflows. It is highly recommended you install this, particularly as it includes important fixes to compatibility with existing FAT32 filesystems (previously .. support was broken, and many garbage files would appear if you attempted to run fsck.fat against an SD card which had been used with zeptoed; note that this does not fix existing directories created with zeptoforth in the past).

Note that this release does not contain PicoCalc support, which is still limited to the picocalc-devel branch, as this is still beta and will be until I get the chance to test it on my own PicoCalc.

Yet another update:

If you are using the graphical PicoCalc terminal emulator, take a look at Turtle graphics in extra/rp_common/turtle_picocalc.fs. This enables conveniently drawing on the display using words similar to those traditionally available in Logo.

1 Like

@jwmcq How did you get fat32-tools to automatically import? I have to do fat32-tools import before I can use list-dir. It’s been a couple months since I used zeptoforth, maybe I’m forgetting something simple.

Edit: I wonder if it’s because you’re on the rp2350_16mib build whereas I’m using the rp2350 build on the Pico2W.

To automatically import fat32-tools on boot enter:

compile-to-flash
: init-import-fat32-tools fat32-tools import ;
initializer init-import-fat32-tools
reboot

When you do this your PicoCalc will reboot, and fat32-tools will automatically be imported on boot from that point forward.

Note that this has nothing to do with rp2350 versus rp2350_16mib builds.

Thanks so much! Works like a charm. I suppose I could modify this for other imports, like pin?

I got my PicoCalc today and I’m feeling so grateful that zeptoforth already runs! Soon after I started learning zeptoforth I was looking for a handheld to use it standalone, so I had my fingers crossed that you might one day support it. It was a great joy to see that this is something you’ve already been working on :slight_smile:

Sure! This can easily be modified for other imports such as pin. Just do the same with pin import or any other modules you want to import. (Note that as it seems you already have compiled the above, it is unnecessary to repeat fat32-tools import.)

1 Like

Just a note to meet your request for feedback: the pin module is working nicely based on my initial basic usage. It’s pretty special to program electronics directly from a standalone forth-based handheld!

1 Like

Aye, I added it to the initializer as @tabemann mentioned.

I am continuing to explore Zeptoforth on the Picocalc and, I have to say, I am continuing to be delighted. I’ve been away from home for work for a few days, and having all-in-one device to play with and an e-reader loaded up with the (remarkably thorough) Zeptoforth docs and a couple of Leo Brodie books has been a joyful way to get stuck into Forth!

One thing I’ve not been able to glean from the docs, though, is whether there’s already a good way to switch back from the picocalc term after having run picocalc-term::term-console. Once it’s in ‘pico-mode’ (so to speak), it seems that the system is no longer willing to play nicely with codeload3.sh, send-file.sh etc., which I guess makes sense.

Also, I do wonder if there’s a way to get in touch with the folks at Clockwork and see if they can expedite sending a kit out to Travis. He’s worked wonders even without the hardware in his hands, but I think that Zeptoforth and Picocalc is such a compelling combination that they really need to make it happen!

Good to hear that you’ve been enjoying using zeptoforth on your PicoCalc! Also, the fact that you have been using zeptoforth on the PicoCalc for an extended period of time means that you’ve effectively been more extensively testing zeptoforth on the PicoCalc than I probably have been. Thank you!

BTW, you can always switch to the serial console by executing serial::serial-console (if one has a full_usb build installed you can also switch to the USB CDC console by executing usb::usb-console, but this is not recommended for the PicoCalc). After you have done this you can use utils/codeload.sh, utils/send_file.sh, utils/recv_file.sh, and like. Once you are done you can switch back to the PicoCalc terminal emulator with picocalc-term::term-console.

On another note, one bit of good news is that the issue where Break (Shift-Escape) z to send an exception to the main task may no longer cause a crash to occur, from my local testing from issuing Control-T z on the serial console with my emulated PicoCalc setup. This was something that I was anticipating as being a blocker for formally releasing the PicoCalc terminal emulator, so as this appears to be fixed (I had reworked the way the PicoCalc terminal emulator uses streams) that means that a significant blocker has been removed.

Note that the reason I have been able to make the progress I have made is that I already had an SPI ST7789V display very similar to the display in the PicoCalc on hand which I had already written a graphics driver for, and I also had a 32 GB microSDHC card and microSD card adapter, and I wrote a keyboard emulator capability into my PicoCalc keyboard driver, so I was able to effectively emulate much of the functionality of a PicoCalc without having an actual PicoCalc. The only things I really cannot easily test with my setup are the PicoCalc keyboard key code to terminal keyboard escape code mappings, as my keyboard emulator does not provide a convenient way to map from multibyte terminal keyboard escape codes as generated by my terminal emulator back to PicoCalc keyboard key codes.

I have updated the documentation in USING_THE_PICOCALC.md to bring it up to date and make it more complete, including things I have discussed in this forum and other important notes about installing and using zeptoforth on the PicoCalc.

I loaded zeptoforth_full_usb-1.13.1.uf2 on my RP2350 and was able to start playing.

Now my picocalc has arrived, and I tested the hardware with the stock pico mite on the provided rp2040. However, I’m unable to get any response from zeptoforth on the picocalc. I’m probably missing something simple.
I loaded zeptoforth_full-1.13.2.uf2 (not the USB build) per the instructions in
zeptoforth-picocalc-devel
However, after the .uf2 window closes, I have no connection to the picocalc. I don’t see any COMx port on windows, and I don’t see any /dev/ttyUSB0 or /dev/ttyACM0 on linux.

Could you point out what I’m missing? Thanks!

Have you switched to the USB socket on the Picocalc mainboard rather than the one on the Pico board itself?

1 Like

As jwmcq says, zeptoforth_full-1.13.2.uf2 on the PicoCalc has the console on the PicoCalc’s USB-C port, to which UART0 is directed, so you should after flashing your PicoCalc disconnect from the USB port on your RP2350 board itself and connect to the USB-C port on the PicoCalc. Then you should be able to connect your terminal emulator or upload code to your PicoCalc.

I should note that the reason for this recommendation is that it has been found that if the batteries are in your PicoCalc being connected to the USB port on your board itself (rather than the USB-C port on your PicoCalc) can overcharge the batteries in your PicoCalc. As one very likely will want to use the console for uploading code, it is best just to use serial on UART0 redirected to the USB-C port.

Edit:

I have now updated USING_THE_PICOCALC.md to explicitly mention that you must switch from the USB port on your board to the USB-C port on the PicoCalc after flashing it before you can proceed.

Tried both on win10 and linux. Which is expected to work? Again, is the NON-USB image expected to respond over USB? This seems counter intuitive.
EDIT: I will try again, but if I remember correctly I used the “full” (without USB) and the USB-C port on the Picoccalc was not detected as a serial connection. I might also try the “FULL_USB” image to at least get the code loaded to access the picocalc keyboard and screen.

The full build works over USB-C because the full build defaults the console to UART0, and the PicoCalc redirects UART0 to USB-C. It may be counterintuitive, but it is what it is.

If you are attempting to connect to the USB-C port and no tty device is showing up then something is definitely wrong, especially because this tty device itself is not generated by zeptoforth at all. I would almost think that you might have a bad motherboard in your PicoCalc or like, unfortunately.

Edit:

Please try with the full_usb image just as a test to see if your PicoCalc is working, because if it is then you should be able to install the zeptoforth PicoCalc software on your PicoCalc and get it working using the USB port on your RP2350 board that way.