Our Favorite Things: Binary Search

You might not think that it would be possible to have a favorite optimization algorithm, but I do. And if you’re well-versed in the mathematical art of hill climbing, you might be surprised that my choice doesn’t even involve taking any derivatives. That’s not to say that I don’t love Newton’s method, because I do, but it’s just not as widely applicable as the good old binary search. And this is definitely a tool you should have in your toolbox, too.

Those of you out there who slept through calculus class probably already have drooping eyelids, so I’ll give you a real-world binary search example. Suppose you’re cropping an image for publication on Hackaday. To find the best width for the particular image, you start off with a crop that’s too thin and one that’s too wide. Start with an initial guess that’s halfway between the edges. If this first guess is too wide, you split the difference again between the current guess and the thinnest width. Updated to this new guess, you split the differences again.

But let’s make this even more concrete: an image that’s 1200 pixels wide. It can’t get wider than 1200 or thinner than 0. So our first guess is 600. That’s too thin, so we guess 900 — halfway between 600 and the upper limit of 1200. That ends up too wide, so we next guess 750, halfway between 600 and 900. A couple more iterations get us to 675, then 638, and then finally 619. In this case, we got down to the pixel level pretty darn fast, and we’re done. In general, you can stop when you’re happy, or have reached any precision goal.

[Ed note: I messed up the math when writing this, which is silly. But also brought out the point that I usually round the 50% mark when doing the math in my head, and as long as you’re close, it’s good enough.]

What’s fantastic about binary search is how little it demands of you. Unlike fancier optimization methods, you don’t need any derivatives. Heck, you don’t even really need to evaluate the function any more precisely than “too little, too much”, and that’s really helpful for the kind of Goldilocks-y photograph cropping example above, but it’s also extremely useful in the digital world as well. Comparators make exactly these kinds of decisions in the analog voltage world, and you’ve probably noticed the word “binary” in binary search. But binary search isn’t just useful inside silicon. Continue reading “Our Favorite Things: Binary Search”

Eight RS232 Ports, One Ethernet Port

When it comes to impromptu enclosures, [Paul Wallace] is a man after our own hearts, for his serial-to-Ethernet converters allowing him to control older test equipment were housed in takeaway curry containers. Once the test equipment pile had grown it became obvious that a pile of curry containers was a bit unwieldy, even if the curry had been enjoyable, so he set about creating an all-in-one multiway serial to Ethernet box.

Reminiscent of the serial terminal access controllers that were found in dumb terminal sites back in the day, it’s a box with eight DB-9 connectors for serial ports and a single RJ45 Ethernet port. Inside is a Teensy 4.1 which packs a PHY and eight hardware serial ports, and a pile of MAX232 level converter modules. These have a small modification to wire in the CTS and RTS lines, and the whole is clothed in a custom 3D printed case.

The result is a very neat, almost commercial standard box that should save him quite a bit of space. Not everyone has eight devices to drive, so if you have just one how about using an ESP8266?

Linux Fu: Simple Pipes

In the old days, you had a computer and it did one thing at a time. Literally. You would load your cards or punch tape or whatever and push a button. The computer would read your program, execute it, and spit out the results. Then it would go back to sleep until you fed it some more input.

The problem is computers — especially then — were expensive. And for a typical program, the computer is spending a lot of time waiting for things like the next punched card to show up or the magnetic tape to get to the right position. In those cases, the computer was figuratively tapping its foot waiting for the next event.

Someone smart realized that the computer could be working on something else while it was waiting, so you should feed more than one program in at a time. When program A is waiting for some I/O operation, program B could make some progress. Of course, if program A didn’t do any I/O then program B starved, so we invented preemptive multitasking. In that scheme, program A runs until it can’t run anymore or until a preset time limit occurs, whichever comes first. If time expires, the program is forced to sleep a bit so program B (and other programs) get their turn. This is how virtually all modern computers outside of tiny embedded systems work.

But there is a difference. Most computers now have multiple CPUs and special ways to quickly switch tasks. The desktop I’m writing this on has 12 CPUs and each one can act like two CPUs. So the computer can run up to 12 programs at one time and have 12 more that can replace any of the active 12 very quickly. Of course, the operating system can also flip programs on and off that stack of 24, so you can run a lot more than that, but the switch between the main 12 and the backup 12 is extremely fast.

So the case is stronger than ever for writing your solution using more than one program. There are a lot of benefits. For example, I once took over a program that did a lot of calculations and then spent hours printing out results. I spun off the printing to separate jobs on different printers and cut like 80% of the run time — which was nearly a day when I got started. But even outside of performance, process isolation is like the ultimate encapsulation. Things you do in program A shouldn’t be able to affect program B. Just like we isolate code in modules and objects, we can go further and isolate them in processes.

Doubled-Edged Sword

But that’s also a problem. Presumably, if you want to have two programs cooperate, they need to affect each other in some way. You could just use a file to talk between them but that’s notoriously inefficient. So operating systems like Linux provide IPC — interprocess communications. Just like you make some parts of an object public, you can expose certain things in your program to other programs.

Continue reading “Linux Fu: Simple Pipes”

Layer Line Removal Putty Reviewed

[Teaching Tech] is not alone in hating layer lines in 3D prints and also hates sanding. He recently tried Incredafill putty, a UV-curable putty that you can use to cover up lines in prints. Once covered and cured, you sand the putty smooth. You can see what he thought of the product in the video below.

As many people suggested in the video comments, you can pull the same trick with UV resin thickened with some other substance. We’ve even covered using diluted resin to get a similar effect. The putty has more of the appearance of hair cream or some kind of ointment, so it was easy to spread around with a gloved finger. A brush also worked. UV curing was done by a small flashlight or the handy sun. However, you’ll see later that he used a UV curing station and that works well if you have one.

Of course, even after applying the putty, you still have to sand. We are assuming the sanding is easier than trying to sand the actual layer lines smooth. On the other hand, the resin dust is probably pretty toxic, so there is a trade-off involved.

The results did look good. Of course, since there was still sanding involved, how good it looks will depend on your sanding tools, your technique, and — perhaps most importantly — your patience. Sanding can do a lot for 3D prints. We might not trust it completely with resin dust, but you could get rid of at least some of the dust with a downdraft table.

Continue reading “Layer Line Removal Putty Reviewed”

The Nine Dollar Laser Bed

A laser cutter bed has to be robust, fireproof, and capable of adequately supporting whatever piece of work is being done on the machine. For that reason they are typically a metal honeycomb, and can be surprisingly expensive. [David Tucker] has built a MultiBot CNC machine and is using it with a laser head, and his solution to the problem of a laser bed is to turn towards the kitchen ware store.

The answer lay in an Expert Grill Jerky Rack, a wire grille with a baking tray underneath it. Perfect lasering support but for its shininess, so it was painted matte back to reduce reflections and a handy set of clips were 3D printed to secure the grille to the tray.

We like this solution as it’s both effective and cheap, though we can’t help a little worry at the prospect of any laser cutter without adequate enclosure for safety. Having been involved in the unenviable task of cleaning an encrusted hackerspace laser cutter bed, we also like the idea that it could be disposed of and replaced without guilt. Do you have any tales of laser cutter bed cleaning, or have you found a cheap substitute of your own? Let us know in the comments!

Rotary Phone MIDI Controller Still Makes Calls

[Kevin] has long wanted to do something musical with a vintage rotary phone and an Arduino, and has finally done so and committed the first of several experiments to HTML in a five-part series. He found a nice old British Telecom number, but it had been converted to plug and socket wiring to work on the modern system. Because of this, [Kevin] wanted to keep it completely functional as a phone. After all, it ought to work fine until 2025, when pulse dialing will no longer be supported in [Kevin]’s locality.

As you can likely understand, [Kevin] was keen to interface with the phone from the outside and leave the inside untouched. He used a sacrificial ADSL filter’s PCB to break out the socket, and added a pull-up resistor between the pin and 5 V.

Pretty quickly, [Kevin] figured out that when the phone is on the hook, it gives a constant high signal, where as the picking up the phone presents as a high signal going low, and dialing each number results in pulses of that quantity that alternate between high and low. Continue reading “Rotary Phone MIDI Controller Still Makes Calls”

In 2045: Alpha Centauri

We’ve talked about project Breakthrough Starshot which aims to send a solar sail probe to Alpha Centauri within 20 years. A little basic math and knowing that Alpha Centauri is 4.3 light years away means you are going to need to travel over 20% of the speed of light to make the trip in that time. Some new papers have proposed ways to address a few of the engineering problems.

The basic idea is simple. A very small probe is attached to a very large sail. But calling it a solar sail is a bit of a misnomer. The motive power for the sail would be a powerful laser, which provides more reliable power to the tiny probe’s propulsion system. The problems? First, the thin sail could tear under constant pressure. The answer, according to one of the papers, is to shape the sail like a parachute so it can billow under pressure.

The other problem is not burning the sail up. Space is a hard environment to dump waste heat into since radiation is the only way to transfer it. Another paper suggests that nanoscale patterns on the sail will allow it to release waste heat into the interstellar environment.

Continue reading “In 2045: Alpha Centauri”