Apple Falling Division

[Paul Curtis] over at Segger has an interesting series of blog posts about calculating division. This used to be a hotter topic, but nowadays many computers or computer languages have support for multiplication and division built-in. But some processors lack the instructions and a library to do it might be less than ideal. Knowing how to roll your own might allow you to optimize for speed or space. The current installment covers using Newton’s algorithm to do division.

Steve Martin had a famous bit about how to be a millionaire and never pay taxes. He started out by saying, “First… get a million dollar. Then…” This method is a bit like that since you first have to know how to multiply before you can divide. The basic premise is twofold: Newton’s method let you refine an estimate of a reciprocal by successive multiplications and then multiplying a number a reciprocal is the same as dividing. In other words, if we need to divide 34 by 6, you could rewrite 34/6 to 34 * 1/6 and the answer is the same.

Continue reading “Apple Falling Division”

Cracking The Spotify Code

If you’ve used Spotify, you might have noticed a handy little code that it can generate that looks like a series of bars of different heights. If you’re like [Peter Boone], such an encoding will pique your curiosity, and you might set out to figure out how they work.

Spotify offers a little picture that, when scanned, opens almost anything searchable with Spotify. Several lines are centered on the Spotify logo with eight different heights, storing information in octal. Many visual encoding schemes encode some URI (Uniform Resource Identifier) that provides a unique identifier for that specific song, album, or artist when decoded. Since many URIs on Spotify are pretty long (one example being spotify :show:3NRV0mhZa8xeRT0EyLPaIp which clocks in at 218 bits), some mechanism is needed to compress the URIs down to something more manageable. Enter the media reference, a short sequence encoding a specific URI, generally under 40 bits. The reference is just a lookup in a database that Spotify maintains, so it requires a network connection to resolve. The actual encoding scheme from media reference to the values in the bars is quite complex involving CRC, convolution, and puncturing. The CRC allows the program to check for correct decoding, and the convolution enables the program to have a small number of read errors while still having an accurate result. Puncturing is just removing bits to reduce the numbers encoded, relying on convolution to fill in the holes.

[Peter] explains it all in his write-up helpfully and understandably. The creator of the Spotify codes stopped by in the comments to offer some valuable pointers, including pointing out there is a second mode where the lines aren’t centered, allowing it to store double the bits. [Peter] has a python package on Github with all the needed code for you to start decoding. Maybe you can incorporate a Spotify code scanner into your custom Spotify playing mini computer.

Watch Blender Plugin Make Animated PCB Traces (and More)

[Staacks]’s Blender plugin to animate growth is behind the sweet animation seen above. It’s an add-on that cleverly makes creating slick growth animations easier when using Blender. It isn’t limited to PCB images either, although they do happen to make an excellent example of the process.

The add-on isn’t limited to animating PCB traces.

The idea is that one begins with an image texture with a structure showing a bunch of paths (like a maze, or traces on a PCB), and that gets used as an input. The plugin then uses a path finding algorithm to determine how these paths could grow from an origin point, and stores the relevant data in the color channels of an output image. That output is further used within Blender as the parameters with which to generate the actual animation, resulting in the neat self-creating PCB seen above. That PCB isn’t just for show, by the way. It’s the PCB for [Staacks]’s smart doorbell project.

Blender is an amazingly comprehensive tool for modeling and animation, and while we’ve covered using it to create high-quality KiCad renders, this kind of animation is really something else.

Here is the GitHub repository for the Blender growth tool if you’re interested in giving it a spin. If you’d like to see more first, watch the video embedded below for a showcase of what it’s capable of, and how it works.

Continue reading “Watch Blender Plugin Make Animated PCB Traces (and More)”

A Super Speedy Lightweight Lossless Compression Algorithm

[Dominic Szablewski] was tinkering around with compressing RGB images, when he stumbled upon idea of how to make a simple lossless compression algorithm, resulting in the Quite OK Image Format, which seems to offer comparable file sizes to the PNG format but is so simple it runs up to 50 times faster for compression and up to four times faster for decompression. Implementation can be achieved with a miniscule 300 lines of C. Need a bit more detail on the real-world performance? Well [Dominic] has that covered too, with a complete set of benchmarks for your perusal.

Image formats are one of those things these days that are designed by consortium, with so much complexity wedged in making it hard to implement with limited resources, so we find it very refreshing to see someone going back to basics and producing something super lightweight, and plenty good enough in practical terms.

Other uses for the algorithm could be for super simple video compression, for applications where resource is tight and some low-effort bandwidth reduction would be beneficial. Implementation in a small FPGA would also be quite straightforward, since the memory requirement is quite low also.

The project is very new and already there are some tweaks happening to the format, so the GitHub project code may change without warning to reflect any corrections [Dominic] feels necessary.

Thanks [David] for the tip!

Arduino Library Makes Digital Rain Like It’s 1999

There’s going to be a new Matrix movie in theaters next month, and you know what that means: we’re about to see a whole new generation get obsessed with the franchise’s iconic “Digital Rain” effect. Thanks to modern advertisement technology, expect to see lines of glittering text pouring down the displays of everything from billboards to gas pumps pretty soon.

Doesn’t get much easier than that.

For those of us who’ve just been looking for an excuse to break out the old Matrix screensavers, you might as well get a jump on things using this handy Arduino library for the ESP8266 and ESP32. Developed by [Eric Nam], it lets you start up a digital rainstorm on displays supported by the TFT_eSPI library as easily as running digitalRainAnim.loop().

You can even install the library through the Arduino IDE, just open the Library Manager and search for “Digital Rain” to get started. You’ve still got to hook the display up to your microcontroller, but come on, [Eric] can’t do it all for you.

Looking at the examples, it seems like various aspects of the animation like color and speed can be configured by initializing the library with different values. Unfortunately we’re not seeing much in the way of documentation for this project, but by comparing the different examples, you should be able to get the high points.

While our first choice would certainly be a wall of green alphanumeric LED displays, we can’t help but be impressed with how easy this project makes it to spin up your own little slice of the Matrix on the workbench.

Continue reading “Arduino Library Makes Digital Rain Like It’s 1999”

Hacking Multiplication With Karatsuba’s Algorithm

People tend to obsess over making computer software faster. You can, of course, just crank up the clock speed and add more processors, but often the most powerful way to make something faster is to find a better way to do it. Sometimes those methods are very different from how a human being would do the same task, but it suits the computer’s capabilities. [Nemean] has a video explaining a better multiplication algorithm known as Karatsuba’s algorithm and it is actually quite clever. You can see the video below.

To help you understand the algorithm, the video shows a simple two-digit by two-digit multiplication. You can see that the first and last digits are essentially the result of one multiplication. It is all the intermediate digits that add together. The only thing that might change the first digit is a carry.

Continue reading “Hacking Multiplication With Karatsuba’s Algorithm”

Hexagonal Mirror Array Hides Hidden Message

[Ben Bartlett] recently got engaged, and the proposal had a unique bit of help in the form of a 3D-printed hexagonal mirror array, whose mirrors are angled just right to spell out a message with the reflections. A small test is shown above projecting a heart, but the real deal was a bigger version reflecting the message “MARRY ME?” into sand at sunset. Who could say no to something like that? Luckily for all of us, [Ben] shared all the details of what went into designing and building such a thoughtful and fascinating device.

Mirrors on the 3D-printed array are angled just right to reflect light into a message.

Essentially, the array of mirrors works a bit like a projector. Each individual reflection can be can be thought of as a pixel, and the projected position of each can be modified by the precise angle of each mirror. With the help of some Python code, [Ben] calculated the exact angles needed to spell out “MARRY ME?” and generated the necessary 3D model. A smaller-scale test (shown in the header image above) was successful, and after that it was just a matter of printing the array and gluing on some mirrors.

Of course, that’s the short version. In practice there were quite a few troublesome issues that demonstrated the value of using early tests to discover hidden problems. For one thing, mirror angle and alignment is crucial, which meant that anything that could affect the shape of the array was a potential problem. Glue that expands or otherwise changes shape as it dries or cures could slightly change a mirror’s angle, so cyanoacrylate (CA) glue was preferred. However, the tiniest bit of CA glue will mess up a mirror’s surface in a hurry, so care was needed during assembly.

The gleaming hexagonal mirrors are reminiscent of the James Webb Space Telescope.

Another gotcha was when [Ben] suddenly realized, twenty hours into printing the final assembly, that the message needed to be reversed! As designed, the array he was printing would project “?EM YRRAM” and this wasn’t caught during testing because the test pattern (a heart) was symmetrical. Fortunately there was time to correct the error and start again, but it was close. [Ben]’s code has an optional visualization function, which was invaluable for verifying that things would actually turn out as expected. As it happens, the project took right up to the last minute to complete and there wasn’t quite time to check everything 100% before the big moment, but it all turned out alright. What’s life without a little mystery and danger, anyway?

The pictures are great, but you won’t regret taking the time to read through the project page (don’t miss the annotated Python code) because [Ben] goes into just the right level of detail. The end result looks fantastic, and makes an excellent keepsake with a charming story.