Raspberry Pi RP2040: Hands-On Experiences From An STM32 Perspective

The release of the Raspberry Pi Foundation’s Raspberry Pi Pico board with RP2040 microcontroller has made big waves these past months in the maker community. Many have demonstrated how especially the two Programmable I/O (PIO) state machine peripherals can be used to create DVI video generators and other digital peripherals.

Alongside this excitement, it raises the question of whether any of this will cause any major upheaval for those of us using STM32, SAM and other Cortex-M based MCUs. Would the RP2040 perhaps be a valid option for some of our projects? With the RP2040 being a dual Cortex-M0+ processor MCU, it seems only fair to put it toe to toe with the offerings from one of the current heavyweights in the 32-bit ARM MCU space: ST Microelectronics.

Did the Raspberry Pi Foundation pipsqueak manage to show ST’s engineers how it’s done, or should the former revisit some of their assumptions? And just how hard is it going to be to port low-level code from STM32 to RP2040? Continue reading “Raspberry Pi RP2040: Hands-On Experiences From An STM32 Perspective”

3D Printer Control Board Packs A Raspberry Pi Compute Module 4

Traditionally, 3D printer control boards have used simplistic 8-bit microcontrollers to command the stepper drivers and ultimately move the machine where it needs to go. Newer boards have switched over to 32-bit microcontrollers, but they’re still relatively limited computationally. Because of this, a Raspberry Pi running OctoPrint is usually used to provide more complex features such as remote management and live video.

Looking to combine these different devices into a single all-in-one board, [pkElectronics] developed the Sigmoid S7P. With an STM32 microcontroller, TMC2209 stepper drivers, a Raspberry Pi Compute Module 4, and plenty of room for expansion, it promises to be a drop-in upgrade for essentially any 3D printer running on an open source firmware that could be ported over.

An earlier concept for the Sigmoid

According to [pkElectronics], the idea for the Sigmoid had been floating around for several years, but never got off the ground due to the difficulties in dealing with the SO-DIMM interface used by previous iterations of the Compute Module. But with the switch to smaller and denser connector for the CM4, the board finally started to take shape.

Whether you just used it as a convenient way to integrate OctoPrint into your printer, or want to get into something more advanced like Klipper, the Sigmoid S7P looks like a very exciting project. [pkElectronics] says they are considering producing the board commercially if there’s interest, so if you want one of these for your own custom 3D printer build, let them know.

Bare-Metal STM32: Please Mind The Interrupt Event

Interruptions aren’t just a staple of our daily lives. They’re also crucial for making computer systems work as well as they do, as they allow for a system to immediately respond to an event. While on desktop computers these interrupts are less prominent than back when we still had to manually set the IRQ for a new piece of hardware using toggle switches on an ISA card, IRQs along with DMA (direct memory access) transfers are still what makes a system appear zippy to a user if used properly.

On microcontroller systems like the STM32, interrupts are even more important, as this is what allows an MCU to respond in hard real-time to an (external) event. Especially in something like an industrial process or in a modern car, there are many events that simply cannot be processed whenever the processor gets around to polling a register. Beyond this, interrupts along with interrupt handlers provide for a convenient way to respond to both external and internal events.

In this article we will take a look at what it takes to set up interrupt handlers on GPIO inputs, using a practical example involving a rotary incremental encoder.

Continue reading “Bare-Metal STM32: Please Mind The Interrupt Event”

Your Plants Can Take Care Of Themselves Now

One of [Sasa]’s life goals is to be able to sit back in his home and watch as robots perform all of his work for him. In order to work towards this goal, he has decided to start with some home automation which will take care of all of his house plants for him. This project is built from the ground up, too, and is the first part of a series of videos which will outline the construction of a complete, open-source plant care machine.

The first video starts with the sensors for the plants. [Sasa] decided to go with a completely custom module based on the STM32 microcontroller since commercial offerings had poor communications designs and other flaws. The small board is designed to be placed in the soil, and has sensors for soil moisture as well as other sensors for amount of light available and the ambient temperature. The improvements over the commercial modules include communication over I2C, allowing a large number of modules to communicate over a minimum of wires and be arranged in any way needed.

For this build everything is open-source and available on [Sasa]’s GitHub page, including PCB layouts and code for the microcontrollers. We’re looking forward to the rest of the videos where he plans to lay out the central unit for handling all of these sensors, and a custom dashboard for controlling them as well. Perhaps there will also be an option for adding a way to physically listen to the plants communicate their needs as well.

Continue reading “Your Plants Can Take Care Of Themselves Now”

Reliable Frequency Reference From GPS

GPS technology is a marvel of the modern world. Not only can we reliably locate positions on the planet with remarkable accuracy and relatively inexpensive hardware, but plenty of non-location-based features of the technology are available for other uses as well. GPS can be used for things like time servers, since the satellites require precise timing in order to triangulate a position, and as a result they can also be used for things like this incredibly accurate frequency reference.

This project is what’s known as a GPSDO, or GPS-disciplined oscillator. Typically they use a normal oscillator, like a crystal, and improve its accuracy by pairing it with the timing signal from a GPS satellite. This one is a standalone model built by [Szabolcs Szigeti] who based the build around an STM32 board. The goal of the project was purely educational, as GPSDOs of various types are widely available, but [Szabolcs] was able to build exactly what he wanted into this one including a custom power supply, simple standalone UI, and no distribution amplifier.

The build goes into a good bit of detail on the design and operation of the device, and all of the PCB schematics and source code are available on the projects GitHub page if you want to build your own. There are plenty of other projects out there that make use of GPS-based time for its high accuracy, too, like this one which ties a GPS time standard directly to a Raspberry Pi.

Open-Source Thermostat Won’t Anger Your Landlord

[Nathan Petersen] built a Hackable Open-Source Thermostat to smooth out temperature fluctuations caused by the large hysteresis of the bimetallic strip thermostat in his apartment. While it may be tempting to adjust the “anticipator” to take care of the problem or even replace the bimetallic thermostat with an electronic version, building your own thermostat from scratch is a good way to add to your project portfolio while making your way through college. Plus, he got to hone his hardware and software design chops.

The hardware is designed around the STM32, using a cheap, minimal variant since the device just needs to sense temperature and control the furnace in on-off mode. The TMP117 high-accuracy, low-power, temperature sensor was selected for temperature measurement since accuracy was an essential feature of the project. Dry-contact output for the furnace is via a normally-open solid state relay (opto-isolator). For the user interface, instead of going the easy-route and using an I2C/SPI OLED or LCD display, [Nathan] used three 7-segment LED displays, each driven by an 8-channel constant current driver. The advantage is that the display can be viewed from across the room, and it’s brightness adjusted via PWM. Temperature set-point adjustment is via a simple slide potentiometer, whose analog voltage is read by the micro-controller ADC. To remind about battery replacement, a second ADC channel on the micro-controller monitors the battery voltage via a voltage divider. The PCB components are mostly surface mount, but the packages selected are easy enough to hand solder.

[Nathan]’s Github repo provides the hardware and firmware source files. The board is designed in Altium, but folks using KiCad can use either the awesome Altium2KiCad converter or the online service for conversion. (The results, with some minor errors that can be easily fixed, are quite usable.) Serendipitously, his PCB layout worked like a charm the first time around, without requiring any rework or bodge wires.

The firmware is a few hundred lines of custom bare-metal C code, consisting of drivers to interface with the hardware peripherals, a UI section to handle the user interface, and the control section with the algorithm for running the furnace. [Nathan] walks us through his code, digging into some control theory and filtering basics. After making a few code tweaks and running the thermostat for some time, [Nathan] concludes that it is able to achieve +0.1°F / -0.5°F temperature regulation with furnace cycles lasting about 10-15 minutes (i.e. 4-6 cycles per hour). Obviously, his well insulated apartment and a decent furnace are also major contributing factors. Moving on, for the next version, [Nathan] wants to add data collection capabilities by adding some memory and SD card storage, and use an RTC to allow seasonal adjustments or time-based set-points.

This is his first attempt at a “functional’ useful project, but he does love to build the occasional toy, such as this POV Top.

Hackaday Links Column Banner

Hackaday Links: January 31, 2021

There are an awful lot of machines on the market these days that fall under the broad category of “cheap Chinese laser cutters”. You know the type — the K40s, the no-name benchtop CO2 cutters, the bigger floor-mount units. If you’ve recently purchased one of these machines from one of the usual vendors, or even if you’re just thinking about doing so, you’ll likely have some questions. In which case, this “Chinese Laser Cutters 101” online class might be right up your alley. We got wind of this though its organizer, Jonathan Schwartz of American Laser Cutter in Los Angeles, who says he’s been installing, repairing, and using laser cutters for a decade now. The free class will be on February 8 at 5:00 PM PST, and while it’s open to all, it does require registration.

We got an interesting tip the other day that had to do with Benford’s Law. We’d never heard of this one, so we assumed was a “joke law” like Murphy’s Law or Betteridge’s Rule of Headlines. But it turns out that Benford’s Law describes the distribution of leading digits in large sets of numbers. Specifically, it says that the leading digit in any given number is more likely to be one of the smaller numbers. Measurements show that rather than each of the nine base 10 digits showing up about 11% of the time, a 1 will appear in the leading digit 30% of the time, while a 9 will appear about 5% of the time. It’s an interesting phenomenon, and the tip we got pointed to an article that attempted to apply Benford’s Law to image files. This technique was used in a TV show to prove an image had been tampered with, but as it turns out, Hollywood doesn’t always get technical material right. Shocking, we know, but the technique was still interesting and the code developed to Benford-ize image files might be useful in other ways.

Everyone knew it was coming, and for a long time in advance, but it still seems that the once-and-for-all, we’re not kidding this time, it’s for realsies shutdown of Adobe Flash has had some real world consequences. To wit, a railroad system in the northern Chinese city of Dalian ground to a halt earlier this month thanks to Flash going away. No, they weren’t using Flash to control the railroad, but rather it was buried deep inside software used to schedule and route trains. It threw the system into chaos for a while, but never fear — they got back up and running by installing a pirated version of Flash. Here’s hoping that they’re working on a more permanent solution to the problem.

First it was toilet paper and hand sanitizer, now it’s…STM32 chips? Maybe, if the chatter on Twitter and other channels is to be believed. Seems like people are having a hard time sourcing the microcontroller lately. It’s all anecdotal so far, of course, but the prevailing theory is that COVID-19 and worker strikes have lead to a pinch in production. Plus, you know, the whole 2020 thing. We’re wondering if our readers have noticed anything on this — if so, let us know in the comments below.

And finally, just because it’s cool, here’s a video of what rockets would look like if they were transparent. Well, obviously, they’d look like twisted heaps of burning wreckage on the ground is they were really made with clear plastic panels and fuel tanks, but you get the idea. The video launches a virtual fleet — a Saturn V, a Space Shuttle, a Falcon Heavy, and the hypothetical SLS rocket — and flies them in tight formation while we get to watch their consumables be consumed. If the burn rates are accurate, it’s surprising how little fuel and oxidizer the Shuttle used compared to the Saturn. We were also surprised how long the SLS holds onto its escape tower, and were pleased by the Falcon Heavy payload reveal.