Accurate Cycle Counting On RP2040 MicroPython

The RP2040 is a gorgeous little chip with a well-defined datasheet and a fantastic price tag. Two SDKs are even offered: one based on C and the other MicroPython. More experienced MCU wranglers will likely reach for the C variant, but Python does bring a certain speed when banging out a quick project or proof of concept. Perhaps that’s why [Jeremy Bentham] ported his RP2040-based vehicle speedometer to MicroPython.

The two things that make that difficult are that MicroPython tries to be pretty generic, which means some hackery is needed to talk to the low-level hardware, and that MicroPython doesn’t have a reputation for accurate cycle counting. In this case, the low-level hardware is the PWM peripheral. He details the underlying mechanism in more detail in the C version. On the RP2040, the PWM module can count pulse edges on an input. However, you must start and stop it accurately to calculate the amount of time captured. From there, it’s just edges divided by time. For this, the DMA system is pulled in. A DMA request can be triggered once the PWM counter rolls over. The other PWM channel acts as a timer, and when the timer expires, the DMA request turns off the counter. This works great for fast signals but is inaccurate for slow signals (below 1kHz). So, a reciprocal or time-interval system is included, where the time between edges is captured instead of counting the number of edges in a period,

What’s interesting here is how the hardware details are wrapped neatly into pico_devices.py. The uctypes module from MicroPython allows access to MMIO devices such as DMA and PWM. The code is available on GitHub. Of course, [Jeremy] is no stranger to hacking around on the RP2040, as he has previously rolled his own WiFi driver for the Pico W.

Tesla Door Phone Decoded (Not That Tesla)

[Danman] has digital door phones manufactured by Tesla — or at least, a Tesla, as they’re not to be confused with the carmaker, though. The problem is if someone comes to the door when no one’s home, there’s no remote indicator. The answer? Reverse engineer the protocol and fix it.

A quick dump on a storage scope showed the data clearly, but it wasn’t obvious what protocol it was using. After a little analysis, it proved the datastream used 4 PWM pulses as symbols with three symbols: one, zero, and stuffing sequence.

Once you can read the bits, it is easy to determine that each frame consists of a 16-bit destination and source address, along with a command byte and a checksum byte. Each station can have an ID from 000 to 999 although you can only dial up to number 323. Some nodes are special, and there are ways to address particular units.

Connecting to the hardware took a transformer for isolation. Honestly, unless you have this exact hardware, this isn’t likely to be something you can directly use. However, it is a great example of how you can figure out a specialized device and bend it to your will.

We love reverse engineering projects. In some cases, it is easier if you have a CT scan.

Converting A B&W Enlarger For Colour Analog Photo Printing

[Koraks tinkers] was gifted a gargantuan photographic enlarger, a Durst Laborator 138 s, which is a unit designed specifically for black and white usage only. This was not good enough for [Koraks] so down the rabbit hole of conversion to colour we go! The moral of the story is this: if you can’t find it, build it. The hacker mentality. After wasting time and effort trying to source a period colour head for the thing, [Koraks] did the decent thing and converted what was already in front of them.

A hacked Chinese-sourced COB array. This is no use.

Now, if you’re thinking this process is simply a matter of ripping out the tungsten bulb and sticking a high-power RGB array in there, then you’re going to be disappointed! You see, colour photography of the era — specifically the RA4 process in this case — requires careful colour calibration and is heavily biased towards the red end of the visible spectrum, due to the colour curve of those tungsten bulbs we touched upon earlier.

Attempt 2: With a heavy bias towards the red end of the spectrum

The first attempt at using an off-the-shelf COB array was a bust — it simply wasn’t bright enough once the light had passed through the diffuser plate, and the light path losses were too high to expose the RA4 paper sufficiently, especially at the red end of the spectrum. Quite simply this is due to the reduced energy of red photons (compared to blue) making the desired chemical reaction rate too low. The solution is more power.

Another issue that quickly raised itself was that 8-bits of PWM control of the RGB components was inadequate since the ratio of blue to red required was so skewed, that only a few effective bits of blue channel control were usable, and that was far too granular to get the necessary accuracy.

[Koraks’] approach was to custom build an LED array with twenty red 3W LEDs and eight each of the green and blue devices. 12-bits of PWM resolution was delivered via a PCA9685 PWM controller, that also handily controlled the cooling fans. The whole thing was hooked up to an Arduino Nano, with an MCP23016 expander board performing the duty of interfacing the rotary encoders and trigger footswitch. In fact, several iterations of the LED array have been constructed and this four-part blog series (Part1, Part2, Part3, Part4) lays out the whole story in all its gory detail for your entertainment. Enjoy!

COB LED arrays are pretty nifty, checkout turning them into 7-segment displays, just because. If all you want is raw power, we reckon that 100W “should be enough for anyone…”

Thanks [macsimski] for the tip!

Update: Corrected the article header from ‘exposer head’ to ‘enlarger’ for clarity at the request of the project author.

Op Amp Challenge: An Op-Amp Buck Regulator

Switching regulators have delivered such convenience and efficiency compared to their linear siblings, that it’s now becoming rare to see an old-style three-terminal regulator. Modern designs have integrated to such an extent that for many of us the inner workings remain something of a mystery. It’s still possible to make switching regulators from first principles though, which is what [Aaron Lager] has done by designing a buck regulator from a quad op-amp IC,

It’s an entry in our Op Amp Challenge and it appears to be a work in progress, but the design is solid enough. We’re no fans of the schematic style of representing an op-amp chip as a rectangle rather than individual op-amps, but it’s simply a PWM generator with a final op-amp used as a driver for the usual diode-inductor-capacitor network. We’re guessing that the op-amp driver won’t make this the most powerful of switchers, but in this case that’s hardly the point. Build this if you’re interested in taking an op-amp out of its normal sphere, or if you’re interested in the workings of a buck converter.

Need more in the way of switching regulators from first principles? We’ve got you covered, with the ultimate regulator kit of parts, the Fairchild UA723.

Spin Up To Speed With This Stroboscope

A stroboscope is not the most common tool, and while they can be purchased fairly inexpensively from various online stores, they are straightforward enough tools that plenty of us could build our own mostly from parts laying around. The basic idea is to shine a flashing light on a spinning object, and when it appears stationary the stroboscope will indicate the rotational speed. There are a few specialty parts that might not be in everyone’s parts drawers, though, and [John] shows us the ins-and-outs of his own DIY stroboscope.

The effect relies on extremely precise timing, and as such the most important part of a build like this is making sure to get the LED circuitry correct so its duty cycle and frequency can be tightly controlled. [John] is using a PT4115E driver board for the LED, and is using it to power a 1W white LED which also includes its own heat sink and lens. The controls for the stroboscope are handled by an ATtiny1614 microcontroller which shows its pulse rate on a small screen. The user can control the rate the LED flashes with simple controls, and when the spinning object appears to come to a stop the only thing left to do is read this value off of the screen.

While it might seem like an overly niche tool, stroboscopes have plenty of day-to-day uses. Older cars that used a central distributor made use of a specialty stroboscope called a timing light in order to properly advance the ignition timing of the engine. They also retain some use in medical applications, and plenty of older readers may be familiar with their use adjusting the speed on record players. They can also be used to make sure the shutter speeds on cameras are calibrated correctly.

Continue reading “Spin Up To Speed With This Stroboscope”

DIY Fume Extractor With ATtiny13 Speed Control

Let’s be honest, commercially-available soldering fume extractors are cheap enough that you probably don’t need to build one yourself. But it still makes for a good starter project, especially if you go out of your way to really flex your maker muscles like [Arnov Sharma] did with this tidy build.

All the hallmarks of modern hardware making are on display here — you’ve got the 3D printed enclosure, a motor salvaged from a cheap toy quadcopter, and a custom PCB which uses the ATtiny13 and an AO4406 MOSFET to implement a PWM speed control.

The first press of the button starts the motor off at max speed, but keep pushing it, and the motor’s speed will ramp down until it turns off entirely. There’s even a TP4056 charge controller to top off the internal 18650 cell when the fume extractor is connected to a USB power source.

Is it over-engineered? Perhaps. But projects like these are a great opportunity to practice your skills, whether it’s PCB design or creating bespoke 3D printed enclosures. In the era of cheap 32-bit microcontrollers, it’s also refreshing to see hackers still dragging the ATtiny from time to time.

Continue reading “DIY Fume Extractor With ATtiny13 Speed Control”

Monochrome LCD Video Hacks Galore!

[Wenting Zhang] is clearly a fan of old school STN LCD displays, and was wondering how various older portable devices managed to drive monochrome LCDs panels with multiple grey levels. If the display controller supports multiple bits per pixel, it can use various techniques, such as PWM, in order to produce a pseudo-grayscale image. But, what if you have a monochrome-only display controller? With a sufficiently high pixel clock, can you use software on the application side of things to flip those pixels in such a manner as to give a reasonable looking grayscale image?

Simple dithering – don’t look too close!
PDM greyscale approximation in a 1-bit display

[Wenting] goes through multiple techniques, showing the resulting image quality in a clear, systematic manner. The first idea is to use a traditional dithering technique. For each pixel, it is set to black if the grey value is below some threshold. The resulting error value, is then propagated to neighbouring pixels. This error diffusion process smears the error out over the whole display, so spatially speaking, on average the pixel values correspond roughly to the original gray values. But, the pixels themselves are still either on or off. This isn’t quite enough. The next idea is to PWM the individual pixels over multiple frames, to approximate different grey levels. But, that gives a worst case effective refresh rate of 8 Hz with a PWM period of 15 frames, at 120 fps, and that flickers. Badly. One way to mitigate that is to switch to PDM (pulse density modulation) which selects different length sequences to give the same duty cycle but at higher frequency, at least for some grey values. Slightly better, but there’s more that can be done. Continue reading “Monochrome LCD Video Hacks Galore!”