A BASIC Interpreter For The Raspberry Pi Pico

It’s pretty easy to program the Raspberry Pi Pico in Python, or you can use C or C++ if you so desire. However, if you fancy the easy language of yesteryear, you might like PiccoloBASIC from [Gary Sims].

Putting it simply, piccoloBASIC is a BASIC interpreter that runs on the Raspberry Pi Pico. It features all the good bits of BASIC such as GOTO and GOSUB commands, that fancier languages kind of look down upon. It’s also got enough built-in routines to handle regular programming life, like sleeps, delays, a basic pseudorandom number source, trigonometric functions, and the ability to deal with floating point numbers. As far as microcontroller tasks go, it’s got rudimentary support for talking to GPIOs right now via the pinon and pinoff commands. However, it’s probably not the way to go if you want to bit-bang an SD card to within an inch of its speed rating.

Down the road, [Gary] hopes to add support for features like the Pico’s I2C, SPI, and PIO hardware, along with networking protocols and Bluetooth. PEEK and POKE are also hopefully on the way for those that like to fiddle with memory directly.

Meanwhile, if you’re looking for a different yet similar take, explore the port of MMBasic to the Pico platform. Video after the break.

Continue reading “A BASIC Interpreter For The Raspberry Pi Pico”

Pi Microcontroller Still Runs A Webserver

At first glance, the Raspberry Pi Pico might seem like a bit of a black sheep when compared to the other offerings from the Raspberry Pi Foundation. While most of the rest of their lineup can run Linux environments with full desktops, the Pico is largely limited to microcontroller duties in exchange for much smaller price tags and footprints. But that doesn’t mean it can’t be coerced into doing some of the things we might want a mainline Pi to do, like run a web server.

The project can run a static web page simply by providing the Pico with the project code available on the GitHub page and the HTML that you’d like the Pico to serve. It can be more than a static web page though, as it is also capable of running Python commands through the web interface as well. The server can pass commands from the web server and back as well, allowing for control of various projects though a browser interface. In theory this could be much simpler than building a physical user interface for a project instead by offloading all of this control onto the web server instead.

The project not only supports the RP2040-based Raspberry Pi Pico but can also be implemented on other WiFi-enabled microcontroller boards like the ESP8266 and ESP32. Having something like this on hand could greatly streamline smaller projects without having to reach for a more powerful (and more expensive) single-board computer like a Pi 3 or 4. We’ve seen some other builds on these boards capable of not only running HTML and CSS renderers, but supporting some image formats as well.

Continue reading “Pi Microcontroller Still Runs A Webserver”

Videos Teach Bare Metal RP2040

When we write about retrocomputers, we realize that back in the day, people knew all the details of their computer. You had to, really, if you wanted to get anything done. These days, we more often pick peripherals and just assume our C or other high level code will fit and run on the CPU.

But sometimes you need to get down to the bare metal and if your desire is to use bare metal on the RP2040, [Will Thomas] has a YouTube channel to help you. The first video explains why you might want to do this followed by some simple examples. Then you’ll find over a dozen other videos that give you details.

Any video that starts, “Alright, Monday night. I have no friends. It is officially bare metal hours,” deserves your viewing. Of course, you have to start with the traditional blinking LED. But subsequent videos talk about the second core, GPIO, clocks, SRAM, spinlocks, the UART, and plenty more.

As you might expect, the code is all in assembly. But even if you want to program using C without the SDK, the examples will be invaluable. We like assembly — it is like working an intricate puzzle and getting anything to work is satisfying. We get it. But commercially, it rarely makes sense to use assembly anymore. On the other hand, when you need it, you really need it. Besides, we all do things for fun that don’t make sense commercially.

We like assembly, especially on platforms where most people don’t use it. Tackling it on a modern CPU is daunting, but if you want to have a go, we know someone who can help.

Continue reading “Videos Teach Bare Metal RP2040”

Pi Pico Calculates Water Usage

Modern WiFi-enabled microcontrollers have made it affordable and easy to monitor everything from local weather information to electricity usage with typically no more than a few dollars worth of hardware and a little bit of programming knowledge. Monitoring one’s own utility data can be a little bit more difficult without interfering with the metering equipment, but we have seen some clever ways of doing this over the years. The latest is this water meter monitoring device based on a Raspberry Pi Pico.

The clever thing here isn’t so much that it’s based on the tiniest of Raspberry Pis, but how it keeps track of the somewhat obscured water flow information coming from the meter. Using a magnetometer placed close to the meter, the device can sense the magnetic field created as water flows through the meter’s internal sensors. The magnetic field changes in a non-obvious way as water flows through it, so the program has to watch for specific peaks in the magnetic field. Each of these specific waveforms the magnetometer detects counts to 0.0657 liters of water, which is accurate for most purposes.

For interfacing with a utility meter, this is one of the more efficient and elegant hacks we’ve seen in a while. There have, of course, been other attempts to literally read the meter using web cams and computer vision software, but the configuration for these builds is much more complex than something like this. You can interface with plenty of utility meters other than water meters, too, regardless of age.

Old 3D CAD Mouse Gets New Lease Of Life

[Jacek Fedorynski] had an old Magellan/SpaceMouse 3D mouse with a serial interface which made it impossible for him to use with modern hardware and software. The problem he faced was two pronged – the absence of serial interfaces in the hardware and the lack of appropriate drivers for the operating system. So he built a low cost, simple adapter to use his RS-232 Magellan/SpaceMouse with modern software.

The hardware required to build the adapter was minimal. A Raspberry Pi Pico, a MAX3238 based RS-232 adapter, a null modem adapter and a DB9 gender changer. Of course, a combination null modem – gender changer would have made things even simpler. Four of the GPIO pins from the Pico are mapped to the serial RX, TX, RTS and CTS pins.

On the software side, the code emulates a 3DConnexion SpaceMouse Compact, so it can be used with software like Fusion 360, 3ds Max, SolidWorks, Inventor, Maya and many others. On the host computer, only the standard 3DxWare driver package is needed. On the host computer, the old Magellan/SpaceMouse 3D will appear like a modern SpaceMouse Compact connected over USB. The only downside to this is that the SpaceMouse Compact has just two programmable buttons, so only two of the many buttons on the old Magellan mouse can be mapped.

Flashing the code to the Pico is also straightforward using the BOOTSEL mode. Hold down the BOOTSEL button when plugging in the Pico and it appears as a drive onto which you can drag a new UF2 file. Just drag-n-drop [Jacek]’s magellan.uf2 firmware and you’re done.

If you’d rather build your own, modern 3D mouse, check out the DIY Cad Mouse You Can Actually Build.

Loki Is Part Cyberdeck, Part Sinclair Spectrum, And Pretty Tricky

You’ve got to watch out for Loki — he’s a trickster, after all, and he might make you think this semi-cyberdeck mash-up machine is named after him, when the backstory on this build is more interesting than anything in the current Marvel scene.

According to [Steve Anderson], Loki was the name of a mocked-up machine that Sinclair teased in the mid-1980s as a competitor for the Amiga. [Steve] coveted the vaporware machine and never quite got over it, but rather than pine for something that never existed, he created his own Loki. He only loosely qualifies the machine as a cyberdeck — it has some features of the genre, like a Raspberry Pi and a cast-off iPad screen for a display, but isn’t really intended to be as portable as a real cyberdeck. To scratch his Sinclair itch, the machine also includes a ZX Uno, which is an FPGA emulator of the Sinclair Spectrum. The keyboard is hand-wired using mechanical switches, and is backed up by a Pico running custom software so it can talk both USB and PS/2.

[Steve] has much more detail on Loki and his other cyberdeck builds over on his blog, which you should probably check out. Somewhat surprisingly, it doesn’t look like he’s entered Loki in our new Cyberdeck Contest that just launched. Hopefully that’s just an oversight.

Pico Makes Capable Logic Analyzer

A common enough microcontroller project is to create some form of logic analyzer. In theory, it should be pretty easy: grab some digital inputs, store them, and display them. But, of course, the devil is in the details. First, you want to grab data fast, but you also need to examine the trigger in real time — hard to do in software. You may also need input conditioning circuitry unless you are satisfied with the microcontroller’s input characteristics. Finally, you need a way to dump the data for analysis. [Gusmanb] has tackled all of these problems with a simple analyzer built around the Raspberry Pi Pico.

On the front and back ends, there is an optional board that does fast level conversion. If you don’t mind measuring 3.3 V inputs, you can forego the board. On the output side, there is custom software for displaying the results. What’s really interesting, though, is what is in between.

The simple PCB is completely optional.

The Pico grabs 24 bits of data at 100 MHz and provides edge and pattern triggers. This is impressive because you need to look at the data as you store it and that eats up a few instruction cycles if you try to do it in software, dropping your maximum clock rate. So how does this project manage it?

It uses the Pico’s PIO units are auxiliary dedicated processors that aren’t very powerful, but they are very fast and deterministic. Two PIO instructions are enough to handle the work for simple cases. However, there are two PIOs and each has four separate state machines. It still takes some work, but it is easier than trying to run a CPU at a few gigahertz to get the same effect. The fast trigger mode, in particular, abuses the PIO to get maximum speed and can even work up to 200 MHz with some limitations.

If you want to try it, you can use nothing more than a Pico and a jumper wire as long as you don’t need the level conversion. The project page mentions that custom software avoids using OpenBench software, which we get, but we might have gone for Sigrok drivers to prevent having to reinvent too many wheels. The author mentions that it was easier to roll your own code than conform to a driver protocol and we get that, too. Still, the software looks nice and even has an SPI protocol analyzer. It is all open source, so if you want other protocols before the author gets to them, you could always do it yourself.

If you do want a Pico and Sigrok, we’ve covered a project that does just that. Most of the logic analyzers we use these days we build into our FPGA designs.