Artificial Intelligence Runs On Arduino

Fundamentally, an artificial intelligence (AI) is nothing more than a system that takes a series of inputs, makes some prediction, and then outputs that information. Of course, the types of AI in the news right now can handle a huge number of inputs and need server farms’ worth of compute to generate outputs of various forms, but at a basic level, there’s no reason a purpose-built AI can’t run on much less powerful hardware. As a demonstration, and to win a bet with a friend, [mondal3011] got an artificial intelligence up and running on an Arduino.

This AI isn’t going to do anything as complex as generate images or write clunky preambles to every recipe on the Internet, but it is still a functional and useful piece of software. This one specifically handles the brightness of a single lamp, taking user input on acceptable brightness ranges in the room and outputting what it thinks the brightness of the lamp should be to match the user’s preferences. [mondal3011] also builds a set of training data for the AI to learn from, taking the lamp to various places around the house and letting it figure out where to set the brightness on its own. The training data is run through a linear regression model in Python which generates the function that the Arduino needs to automatically operate the lamp.

Although this isn’t the most complex model, it does go a long way to demonstrating the basic principles of using artificial intelligence to build a useful and working model, and then taking that model into the real world. Note also that the model is generated on a more powerful computer before being ported over to the microcontroller platform. But that’s all par for the course in AI and machine learning. If you’re looking to take a step up from here, we’d recommend this robot that uses neural networks to learn how to walk.

Hackaday Links Column Banner

Hackaday Links: October 13, 2024

So far, food for astronauts hasn’t exactly been haute cuisine. Freeze-dried cereal cubes, squeezable tubes filled with what amounts to baby food, and meals reconstituted with water from a fuel cell don’t seem like meals to write home about. And from the sound of research into turning asteroids into astronaut food, things aren’t going to get better with space food anytime soon. The work comes from Western University in Canada and proposes that carbonaceous asteroids like the recently explored Bennu be converted into edible biomass by bacteria. The exact bugs go unmentioned, but when fed simulated asteroid bits are said to produce a material similar in texture and appearance to a “caramel milkshake.” Having grown hundreds of liters of bacterial cultures in the lab, we agree that liquid cultures spun down in a centrifuge look tasty, but if the smell is any indication, the taste probably won’t live up to expectations. Still, when a 500-meter-wide chunk of asteroid can produce enough nutritionally complete food to sustain between 600 and 17,000 astronauts for a year without having to ship it up the gravity well, concessions will likely be made. We expect that this won’t apply to the nascent space tourism industry, which for the foreseeable future will probably build its customer base on deep-pocketed thrill-seekers, a group that’s not known for its ability to compromise on creature comforts.

Continue reading “Hackaday Links: October 13, 2024”

Creating Customized Diffraction Lenses For Lasers

[The Thought Emporium] has been fascinated by holograms for a long time, and in all sorts of different ways. His ultimate goal right now is to work up to creating holograms using chocolate, but along the way he’s found another interesting way to manipulate light. Using specialized diffraction gratings, a laser, and a few lines of code, he explores a unique way of projecting hologram-like images on his path to the chocolate hologram.

There’s a lot of background that [The Thought Emporium] has to go through before explaining how this project actually works. Briefly, this is a type of “transmission hologram” that doesn’t use a physical object as a model. Instead, it uses diffraction gratings, which are materials which are shaped to light apart in specific ways. After some discussion he demonstrates creating diffraction gratings using film. Certain diffraction patterns, including blocking all of the light source, can actually be used as a lens as the light bends around the blockage into the center of the shadow where there can be focal points. From there, a special diffraction lens can be built.

The diffraction lens can be shaped into any pattern with a small amount of computer code to compute the diffraction pattern for a given image. Then it’s transferred to film and when a laser is pointed at it, the image appears on the projected surface. Diffraction gratings like these have a number of other uses as well; the video also shows a specific pattern being used to focus a telescope for astrophotography, and a few others in the past have used them to create the illusive holographic chocolate that [The Thought Emporium] is working towards.

Continue reading “Creating Customized Diffraction Lenses For Lasers”

Compiling Four Billion If Statements

With modern tools, you have to try very hard to do something stupid, because the tools (rightly) recognize you’re doing something stupid. [Andreas Karlsson] can speak to that first hand as he tried to get four billion if statements to compile.

You may ask what state space requires four billion comparisons to evaluate? The answer is easy: the range of an unsigned 32-bit integer. The whole endeavor started with a simple idea: what if instead of evaluating whether an integer is even or odd with a modulo or bit mask, you just did an if statement for every case? Small ranges like 0-10 are trivial to write out by hand, but you reach for more automated solutions as you pass 8 bits and move towards 16. [Andreas] wrote some Python that outputs a valid C program with all the comparisons. For 16 bits, the source only clocks in at 130k lines with the executable less than 2 MB.

Of course, scaling to 32 bits is a very different problem. The source file balloons to 330 GB, and most compilers barf at that point. Undeterred, [Andreas] modified the Python to output x86_64 assembly instead of C. Of course, the executable format of Windows (PE) only allows executables up to 4 GB, so a helper program mapped the 40 GB generated executable and jumped into it.

What’s incredible about this whole journey is how performant the program is. Even large numbers complete in a few seconds. Considering that it has to thrash 40 GB of an executable through memory, we can’t help but shake our heads at how even terrible solutions can work. We love seeing someone turn a bad idea into an interesting one, like this desoldering setup.

Better Battery Design Through Science

Before the age of lithium batteries, any project needing to carry its own power had to rely on batteries that were much less energy-dense and affordable. In many ways, we take modern lithium technology for granted, and can easily put massive batteries in our projects by the standards of just a few decades ago. While the affordability of lithium batteries has certainly decreased the amount of energy we need to put in to our projects to properly size batteries, there’s still a lot of work to be done if you’re working on a bigger project or just want to get the maximize the efficiency and effectiveness of your DIY battery pack.

The main problem with choosing a battery, as [ionworks] explains, is that batteries can’t be built for both high energy and high power, at least not without making major concessions for weight or cost. After diving in to all of the possible ways of customizing a battery, the battery guide jumps in to using PyBaMM to perform computational modeling of potential battery designs to hopefully avoid the cumbersome task of testing all of the possible ways of building a battery. With this tool virtually all of a battery’s characteristics can be simulated and potential problems with your setup can be uncovered before you chose (or start production of) a specific battery system.

While customizing a battery pack to this extent might not be a consideration for most of us unless the project is going to be big enough to run something like an electric car or a whole-house generator, it’s a worthwhile tool to know about as even smaller projects like ebikes can benefit from choosing the right cell for the application. Some of the nuances of battery pack design can be found in this guide to building packs from the standard 18650 cells.

Header: Lead holder, CC BY-SA 3.0 .

Photoresistor-based Single Pixel Camera

[Hugh] has been going back through episodes of the Hackaday podcast, and Elliot mentioned in episode 67 that it can often be inspiring to go back through the archives of Hackaday to find ideas for new projects. Well, he did just that and came across a single-pixel camera made using an infrared photodiode. He decided to try and hack together his own single-pixel camera, but this time on the cheap and using an ever simpler component – a photoresistor!

His description of the project tickled me – “I’ve used an ESP32, MicroPython, two servos, a peanut butter jar lid, a toilet paper roll, a paper towel roll, magnets and scrap wood for this version.” That’s certainly a much simpler bill of materials than the original (which was written up by Hackaday way back in 2015), which used a nice metal frame to hold everything together. However, there’s absolutely nothing wrong with improvising with things you happen to have to hand.

Continue reading “Photoresistor-based Single Pixel Camera”

USB Dongle Brings Python-Controlled GPIO To The Desktop

Microcontroller dev boards are wonderfully useful items, in testament to which most of us maintain an ample collection of the things. But dragging one out to do a simple job can be a pain, what with making sure you have the whole toolchain set up to support the device, not to mention the inevitable need to solder or desolder header pins. Wouldn’t it be nice if there was a simple plug-and-play way to add a few bits of GPIO to your desktop or laptop machine?

[Nick Bild] thinks so, and came up with the USBgpio. The hardware in the dongle is pretty much what you’d expect — an Arduino Nano 33 IoT. Yes, you could just bust out a Nano and do this yourself, but [Nick] has done all the heavy lifting already. Eleven of the Nano’s IO pins plus 3.3V and ground are broken out to header pins that stick out of the 3D-printed enclosure, and the dongle is powered over the USB cable. [Nick] also built a Python library for the USBgpio, making it easy to whip up a quick program. You just import the library, define the serial port and baud rate, and the library takes care of the rest. The video below shows a quick blinkenlight test app.

Earth-shattering stuff? Perhaps not; [Nick] admits as much by noting the performance doesn’t really dazzle. But that’s hardly the point of the project, and if you need a couple of pins of IO on the desktop for a quick tactical project or some early-stage prototyping, USBgpio could be your friend. Continue reading “USB Dongle Brings Python-Controlled GPIO To The Desktop”