Linux Fu: Scripting for Binary Files

If you ever need to write a binary file from a traditional language like C, it isn’t all that hard to do. About the worst thing you might have to deal with is attempts to fake line endings across Windows and Linux, but there’s usually a way to turn that off if it is on by default. However, if you are using some type of scripting language, binary file support might be a bit more difficult. One answer is to use a tool like xxd or t2b (text-to-binary) to handle the details. You can find the code for t2b on GitHub including prebuilt binaries for many platforms. You should be able to install xxd from your system repository.

These tools take very different approaches. You might be familiar with tools like od or hexdump for producing readable representations of binary files. The xxd tool can actually do the same thing — although it is not as flexible. What xxd can even reverse itself so that it can rebuild a binary file from a hex dump it creates (something other tools can’t do). The t2b tool takes a much different approach. You issue commands to it that causes it to write an original hex file.

Both of these approaches have some merit. If you are editing a binary file in a scripting language, xxd makes perfect sense. You can convert the file to text, process it, and then roll it back to binary using one program. On the other hand, if you are creating a binary file from scratch, the t2b program has some advantages, too.

I decided to write a few test scripts using bash to show how it all works. These aren’t production scripts so they won’t be as hardened as they could be, but there is no reason they couldn’t be made as robust as you were willing to make them.

Continue reading “Linux Fu: Scripting for Binary Files”

A LIDAR Scanner Build in Glorious Detail

LIDAR is a very exciting technology that is only just now starting to become accessible to the DIY market. Think radar, but with lasers. There’s a few different modules starting to pop up for just a few hundred dollars. But what is one to do with a LIDAR module? Well, [David] decided to build a room scanner with his Garmin LIDAR Lite, and it’s a wonderful sight to behold.

The scanner consists of a rotating platform, which is driven by a stepper motor. The platform then contains a second motor which runs a tilt axis, upon which the LIDAR is mounted. By aiming the LIDAR in various directions, and recording the detected range, it’s possible to build a point cloud representation of the surrounding area.

The build uses a couple of STM32 chips to do motor control and interface with the LIDAR, but where this build really shines is the mechanical side of things. [David] goes into serious detail about the machining of the parts that make up the rotating system, and there’s plenty of cool bits and pieces like slip rings to make it all work. There’s even some home casting going on here! Be warned, though: there’s some rather juicy close-ups of lathes in action, so put the kids to bed before watching this one all the way through.

We love to see a well-executed build, and even more so when we get to watch the intricate details of how it came together. If you’re still looking for some more inspiration, we’ve seen other LIDAR room scanners before, too.

Box Joint Jig Does Barcodes

Woodworking is the fine art of turning dead tree carcasses into precision instruments. That means breaking out the saws and chisels and making many, many precise cuts over and over. If you have a table saw, every problem becomes a piece of wood, or something like that, and we’ve seen some fantastic jigs that make these precision cuts even easier. We’ve never seen something like this, though. It’s a box joint jig for a table saw, it’s automated, and it puts barcodes on boxes.

[Ben] built this box joint jig a few years ago as a computer-controlled device that slowly advances a piece of wood on a sled, allowing him to create precise, programmable box joints. The design is heavily influenced from [Matthias Wandel]’s screw advance box joint jig, but instead of wood gears (heh), [Ben] is using the Internet of Things. Or a Raspberry Pi, stepper motor, and a few LEDs. Same difference.

Although [Ben]’s previous box joints were all the same size, a programmable box joint jig can do some weird-looking joints. That’s where [Ben] got the idea to encode a barcode in walnut. After using a web app to create a barcode that encodes the number 255 — this is important for later — [Ben] programmed his jig to cut a few slots.

The box was finished as you would expect, but there’s a neat addition to the top. It’s a combination lock that opens when the combination is set to 255. It’s brilliant, and something that could be done with some handsaws and chisels, but this jig makes it so easy it’s hard to think the jig wasn’t explicitly designed for this project.