Is Your Mental Model Of Bash Pipelines Wrong?

[Michael Lynch] encountered a strange situation. Why was compiling then running his program nearly 10x faster than just running the program by itself? [Michael] ran into this issue while benchmarking a programming project, pared it down to its essentials for repeatability and analysis, and discovered it highlighted an incorrect mental model of how bash pipelines worked.

Here’s the situation. The first thing [Michael]’s pared-down program does is start a timer. Then it simply reads and counts some bytes from stdin, then prints out how long it took for that to happen. When running the test program in the following way, it takes about 13 microseconds.

$ echo '00010203040506070809' | xxd -r -p | zig build run -Doptimize=ReleaseFast
bytes: 10
execution time: 13.549µs

When running the (already-compiled) program directly, execution time swells to 162 microseconds.

$ echo '00010203040506070809' | xxd -r -p | ./zig-out/bin/count-bytes
bytes: 10
execution time: 162.195µs

Again, the only difference between zig build run and ./zig-out/bin/count-bytes is that the first compiles the code, then immediately runs it. The second simply runs the compiled program. Continue reading “Is Your Mental Model Of Bash Pipelines Wrong?”

Clever E-Ink Driver Does 32 Levels Of Grey, Avoids Update Flicker, And More

There’s a lot to like about E-Ink displays, and you might be about to like them even more with [antirez]’s MicroPython driver for the Badger 2040 (or any display based on the UC8151 / IL0373) because it brings all kinds of useful features to your next project.

E-Ink displays are great. They are high contrast, daylight-readable, and require zero power to maintain a displayed image. But a few things come with the territory: displays have slow refresh rates compared to other display types, expect flickering during screen changes, and the displays are monochrome. [Antirez]’s new driver not only provides a MicroPython interface but goes in some fantastic directions that challenge those usual drawbacks.

Probably the most striking is the ability to display greyscale images without relying on dithering, which means the results avoid the charmingly gritty look of old-school dithering. Dithering has its place, but it’s not always the best choice, so options are great.

Similarly, display flicker may be a small price to pay for some, but if the obvious flicker is too boorish and crude-looking one can use an anti-flicker refresh mode that greatly limits flickering at the cost of update speed. Over time some image ghosting will accumulate which necessitates an occasional whole-screen refresh, but the effect is overall much nicer when updating something like a clock face.

How is this all done? It turns out that the controller chips for these displays are highly configurable, and it’s possible to do much more than simply drive the display in known-good and completely approved modes. It’s also entirely possible to permanently damage one’s display by doing so. Part of what makes [antirez]’s work so appealing is that he has already done the work finding workable configurations.

His driver is designed using computed LUTs (look-up tables) that make using and exploring alternative refresh modes easy and efficient, invaluable for exploring the capabilities of a patented, poorly documented technology like E-Paper displays.

We’ve seen the Badger 2040 E-Ink display in a teapot timer and a custom macropad, and [antirez]’s uc8151_micropython project is a fantastic step forward. And don’t miss another of [antirez]’s clever microcontroller hacks: playing audio without a DAC.

AI Image Generation Meets Virtual Dress Up

Image generators have really taken off thanks to machine learning, and all kinds of new ideas have been turned on in people’s heads as a result. OOTDiffusion is one such project, its job being to allow virtual try-ons of clothing by combining a picture of a person and an item of clothing, and doing so in a coherent way.

A model sporting a 2021 Remoticon shirt.

When it comes to AI image generators, maintaining consistency of a particular subject in a picture while changing or combining other parts of the image isn’t a trivial task. (If you’re unfamiliar with the basics of how diffusion-type AI image generators work, we have you covered.)

Virtual try-on of clothing is not a new idea, but it’s also far from being a completely solved problem. It’s easy to feed a system high-quality images of people and clothing and ask it to combine them, but the outputs rarely emerge with all their limbs intact, figuratively speaking.

OOTDiffusion addresses the two big challenges in this area: making sure the outputs look natural and realistic, and preserving as much of the garment’s appearance and qualities as possible in the process.

It seems to to a very good job, and you can try it for yourself in the online demo. Check out the research paper for more details, and the GitHub repository provides all the code if you’d like to get a little more hands-on.

Video Poker Takes Your Money In 10 Lines Of BASIC

It wasn’t easy, but [D. Scott Williamson] succeeded in implementing Jacks or Better Video Poker in 10 lines of BASIC, complete with flashing light and sound! Each round, one places a bet then plays a hand of 5-card draw, hoping to end up with Jacks or better.

This program is [Scott]’s entry into the 2024 BASIC 10 Liner Contest, which at this writing has concluded submissions and expects to announce results on April 6th 2024. Contestants may choose any 8-bit computer system BASIC, and must implement their program within ten lines of code (classically limited to 80 characters per line, but there are different categories with different constraints on line width.)

10 lines of BASIC is truly an exercise in information density.

We’ve seen impressive 10-line BASIC programs before, like this re-implementation of the E.T. video game. (Fun fact: while considered one of the worst video games of all time, there’s a compelling case to be made that while it was a flop, it was ahead of its time and mostly just misunderstood.)

These programs don’t look much like the typical BASIC programs many of us remember. They are exercises in information density, where every character counts. So we’re delighted to see [Scott] also provides a version of his code formatted and commented for better readability, and a logical overview that steps through each line.

He spends a little time talking about the various challenges, as well. For example, hand ranking required a clever solution. IF…THEN conditionals would rapidly consume the limited lines of code, so hands are ranked programmatically. The 52-card deck is also simulated, rather than simply generating random cards on the fly.

The result looks great, and you can watch it in action in the video, just under the page break. If this sort of challenge tweaks your interest, there’s plenty of time to get started on next year’s BASIC 10 Liner Contest. Fire up those emulators!

Continue reading “Video Poker Takes Your Money In 10 Lines Of BASIC”

Vastly Improved Servo Control, Now Without Motor Surgery

Hobby servos are great, but they’re in many ways not ideal for robotic applications. The good news is that [Adam] brings the latest version of his ServoProject, providing off-the-shelf servos with industrial-type motion control to allow for much, much tighter motion tracking than one would otherwise be limited to.

Modifying a servo no longer requires opening the DC motor within.

The PID control system in a typical hobby servo is very good at two things: moving to a new position quickly, and holding that position. This system is not very good at smooth motion, which is desirable in robotics along with more precise motion tracking.

[Adam] has been working on replacing the PID control with a more capable cascade-based control scheme, which can even compensate for gearbox backlash by virtue of monitoring the output shaft and motor position separately. What’s really new in this latest version is that there is no longer any need to perform surgery on the DC motor when retrofitting a servo; the necessary sensing is now done externally. Check out the build instructions for details.

The video (embedded just below) briefly shows how a modified servo can perform compared to a stock one, and gives a good look at the modifications involved. There’s still careful assembly needed, but unlike the previous version there is no longer any need to actually open up and modify the DC motor, which is a great step forward.

Continue reading “Vastly Improved Servo Control, Now Without Motor Surgery”

Apple Vision Pro’s Secret To Smooth Visuals? Subtly Substandard Optics

The displays inside the Apple Vision Pro have 3660 × 3200 pixels per eye, but veteran engineer [Karl Guttag]’s analysis of its subtly blurred optics reminds us that “resolution” doesn’t always translate to resolution, and how this is especially true for things like near-eye displays.

The Apple Vision Pro lacks the usual visual artifacts (like the screen door effect) which result from viewing magnified pixelated screens though optics. But [Karl] shows how this effect is in fact hiding in plain sight: Apple seems to have simply made everything just a wee bit blurry thanks to subtly out-of-focus lenses.

The thing is, this approach of intentionally de-focusing actually works very well for consuming visual content like movies or looking at pictures, where detail and pixel-to-pixel contrast is limited anyway.

Clever loophole, or specification shenanigans? You be the judge of that, but this really is evidence of how especially when it comes to things like VR headsets, everything is a trade-off. Improving one thing typically worsens others. In fact, it’s one of the reasons why VR monitor replacements are actually a nontrivial challenge.

Ancient Instrument Goes Digital: The Digi-Gurdy

The hurdy-gurdy is a fascinating string instrument dating from sometime around the 10th century. There is an active community of modern enthusiasts, but one can’t simply walk into a music shop and buy one. That’s where [XenonJohn] and the Digi-Gurdy come in, bringing some nice features while maintaining all the important elements of the original.

The mechanical keys and crank of the Hurdy-Gurdy are preserved in this modern digital incarnation.

The hurdy-gurdy works by droning strings with a rotating wheel, and the player applies pressure to those strings via keys to play combinations of notes. Here’s a video demonstrating what it sounds like to play one, and one can see a conceptual resemblance to bagpipes, among other things.

The Digi-Gurdy is a modern electronic version that maintains the mechanical elements while sending MIDI signals over USB. It has options for line-out or headphone output. A thriving online community has shaped its development since its inception years ago.

We hope this leaves you wanting to know more because [XenonJohn] has loads of details to share. The main website at digigurdy.com is jam-packed with information about this instrument and its construction, and the project page on Hackaday.io has more nitty-gritty design details and source files for those who crave hardware specifics.

If [XenonJohn]’s name sounds familiar, it’s because we’ve admired his work on DIY self-balancing vehicles over the years. He also submitted an earlier version as an entry into the Hackaday Prize. His careful attention to detail shines through. Check out the two videos (embedded just below the page break): the first demonstrates the Digi-Gurdy, and the second shows off the construction and insides. You’d think a MIDI hurdy-gurdy would be unique, but, actually, we’ve seen more than one.

Continue reading “Ancient Instrument Goes Digital: The Digi-Gurdy”