OpenGL In 500 Lines (Sort Of…)

How difficult is OpenGL? How difficult can it be if you can build a basic renderer in 500 lines of code? That’s what [Dmitry] did as part of a series of tiny applications. The renderer is part of a course and the line limit is to allow students to build their own rendering software. [Dmitry] feels that you can’t write efficient code for things like OpenGL without understanding how they work first.

For educational purposes, the system uses few external dependencies. Students get a class that can work with TGA format files and a way to set the color of one pixel. The rest of the renderer is up to the student guided by nine lessons ranging from Bresenham’s algorithm to ambient occlusion. One of the last lessons switches gears to OpenGL so you can see how it all applies.

Continue reading “OpenGL In 500 Lines (Sort Of…)”

Cheap Spot Welder Teardown

It used to be hard to dump enough electricity through two pieces of metal to meld them together. But a lithium-ion battery can do it. The question is, should it? [The Signal Path] takes a cheap battery-based spot welder apart to see what’s inside and tries to answer that question. You can see the teardown in the video below.

The cheap welder has some obvious safety problems so the first thing was to trim down some wires and also retinning some of the PCB traces to ensure they are the lowest possible resistance. Of course, the less resistance in the wiring, the more current is available for welding.

Continue reading “Cheap Spot Welder Teardown”

Tired Of 3D Printed Skirts? Try Kisses

One popular option when 3D printing is to have the printer draw a loop or two around the print before starting. This serves several purposes: it clears the print head for one thing. It also marks the area of the print bed in use and many people use it to adjust the leveling if necessary. However, the little scraps of plastic do add up. [Makers Mashup] decided to try something different and now uses what he dubs the landing strip and kisses method.

The landing strip turns out to be a piece of blue tape and the kiss in question is like the chocolate kind and does not involve pressing your lips against the nozzle. There’s a wizard that generates startup code for you that has the style of purge if you like.

Continue reading “Tired Of 3D Printed Skirts? Try Kisses”

triggered spark gap

Spark Plug And Plumbing Parts Bring Nitrogen Laser Under Control

When it comes to high-speed, high-voltage switching, there are a wealth of components to choose from — MOSFETS, thyristors, IGBTs, and even vacuum tubes like thyratrons. But who needs all that expensive silicon (or glass) when all you need to build a high-voltage switch is some plumbing fixtures and a lathe?

At least that’s the approach that budget-minded laser experimenter [Les Wright] took with his latest triggered spark gap build. We’ve been watching his work for a while now, especially his transversely excited atmospheric (TEA) lasers. These are conceptually simple lasers that seem easy to build, at least compared to other lasers. But they do require a rapid pulse of high voltage across their long parallel electrodes to lase, and controlling the pulse is where this triggered spark gap shines.

The spark gap is made from brass plumbing fittings on either end of a short PVC coupler. [Les] used his lathe to put a thread into one of the caps to accept a spark plug, the center electrode of which pokes through a small hole in the metal cathode. To trigger the spark gap, [Les] built a trigger generator that outputs about 15,000 volts, which arcs from the spark plug electrode to the spark gap cathode in the low-pressure nitrogen environment. Little spark leads to big spark, big spark discharges a capacitor across the laser electrodes, and you’ve got a controlled single-shot laser. Check it out in the video below.

Honestly, the more we see of [Les]’ videos, the more we want to play with lasers and high voltage. From DIY doorknob caps to blasting Bayer arrays off cheap CCD cameras, there’s always something fun — and slightly dangerous — going on in [Les]’s lab.

Continue reading “Spark Plug And Plumbing Parts Bring Nitrogen Laser Under Control”

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”