python – Hackaday https://hackaday.com Fresh hacks every day Tue, 25 Feb 2025 19:20:06 +0000 en-US hourly 1 https://wordpress.org/?v=6.7.2 156670177 Import GPU: Python Programming with CUDA https://hackaday.com/2025/02/25/import-gpu-python-programming-with-cuda/ https://hackaday.com/2025/02/25/import-gpu-python-programming-with-cuda/#comments Wed, 26 Feb 2025 03:00:30 +0000 https://hackaday.com/?p=765574 Every few years or so, a development in computing results in a sea change and a need for specialized workers to take advantage of the new technology. Whether that’s COBOL …read more]]>

Every few years or so, a development in computing results in a sea change and a need for specialized workers to take advantage of the new technology. Whether that’s COBOL in the 60s and 70s, HTML in the 90s, or SQL in the past decade or so, there’s always something new to learn in the computing world. The introduction of graphics processing units (GPUs) for general-purpose computing is perhaps the most important recent development for computing, and if you want to develop some new Python skills to take advantage of the modern technology take a look at this introduction to CUDA which allows developers to use Nvidia GPUs for general-purpose computing.

Of course CUDA is a proprietary platform and requires one of Nvidia’s supported graphics cards to run, but assuming that barrier to entry is met it’s not too much more effort to use it for non-graphics tasks. The guide takes a closer look at the open-source library PyTorch which allows a Python developer to quickly get up-to-speed with the features of CUDA that make it so appealing to researchers and developers in artificial intelligence, machine learning, big data, and other frontiers in computer science. The guide describes how threads are created, how they travel along within the GPU and work together with other threads, how memory can be managed both on the CPU and GPU, creating CUDA kernels, and managing everything else involved largely through the lens of Python.

Getting started with something like this is almost a requirement to stay relevant in the fast-paced realm of computer science, as machine learning has taken center stage with almost everything related to computers these days. It’s worth noting that strictly speaking, an Nvidia GPU is not required for GPU programming like this; AMD has a GPU computing platform called ROCm but despite it being open-source is still behind Nvidia in adoption rates and arguably in performance as well. Some other learning tools for GPU programming we’ve seen in the past include this puzzle-based tool which illustrates some of the specific problems GPUs excel at.

]]>
https://hackaday.com/2025/02/25/import-gpu-python-programming-with-cuda/feed/ 4 765574 gpu-main
Cyanotype Prints on a Resin 3D Printer https://hackaday.com/2025/02/22/cyanotype-prints-on-a-resin-3d-printer/ https://hackaday.com/2025/02/22/cyanotype-prints-on-a-resin-3d-printer/#comments Sun, 23 Feb 2025 03:00:57 +0000 https://hackaday.com/?p=759876 Not that it’s the kind of thing that pops into your head often, but if you ever do think of a cyanotype print, it probably doesn’t conjure up thoughts of …read more]]>

Not that it’s the kind of thing that pops into your head often, but if you ever do think of a cyanotype print, it probably doesn’t conjure up thoughts of modern technology. For good reason — the monochromatic technique was introduced in the 1840s, and was always something of a niche technology compared to more traditional photographic methods.

The original method is simple enough: put an object or negative between the sun and a UV-sensitive medium, and the exposed areas will turn blue and produce a print. This modernized concept created by [Gabe] works the same way, except both the sun and the negative have been replaced by a lightly modified resin 3D printer.

A good chunk of the effort here is in the software, as [Gabe] had to write some code that would take an image and turn it into something the printer would understand. His proof of concept was a clever bit of Python code that produced an OpenSCAD script, which ultimately converted each grayscale picture to a rectangular “pixel” of variable height. The resulting STL files could be run through the slicer to produce the necessary files to load into the printer. This was eventually replaced with a new Python script capable of converting images to native printer files through UVtools.

On the hardware side, all [Gabe] had to do was remove the vat that would usually hold the resin, and replace that with a wooden lid to both hold the UV-sensitized paper in place and protect the user’s eyes. [Gabe] says there’s still some room for improvement, but you wouldn’t know it by looking at some of the gorgeous prints he’s produced already.

No word yet on whether or not future versions of the project will support direct-to-potato imaging.

]]>
https://hackaday.com/2025/02/22/cyanotype-prints-on-a-resin-3d-printer/feed/ 15 759876 cyanoresin_feat
Could Non-Planar Infill Improve The Strength Of Your 3D Prints? https://hackaday.com/2025/02/01/could-non-planar-infill-improve-the-strength-of-your-3d-prints/ https://hackaday.com/2025/02/01/could-non-planar-infill-improve-the-strength-of-your-3d-prints/#comments Sun, 02 Feb 2025 00:00:01 +0000 https://hackaday.com/?p=757087 When you’re spitting out G-Code for a 3D print, you can pick all kinds of infill settings. You can choose the pattern, and the percentage… but the vast majority of …read more]]>

When you’re spitting out G-Code for a 3D print, you can pick all kinds of infill settings. You can choose the pattern, and the percentage… but the vast majority of slicers all have one thing in common. They all print layer by layer, infill and all. What if there was another way?

There’s been a lot of chatter in the 3D printing world about the potential of non-planar prints. Following this theme, [TenTech] has developed a system for non-planar infill. This is where the infill design is modulated with sinusoidal waves in the Z axis, such that it forms a somewhat continuous bond between what would otherwise be totally seperate layers of the print. This is intended to create a part that is stronger in the Z direction—historically a weakness of layer-by-layer FDM parts.

Files are on Github for the curious, and currently, it only works with Prusaslicer. Ultimately, it’s interesting work, and we can’t wait to see where it goes next. What we really need is a comprehensive and scientific test regime on the tensile strength of parts printed using this technique. We’ve featured some other neat work in this space before, too. Video after the break.

]]>
https://hackaday.com/2025/02/01/could-non-planar-infill-improve-the-strength-of-your-3d-prints/feed/ 24 757087 Non-Planar Infill for Stronger 3D-Prints now Opensource! 1-40 screenshot
Robot Air Hockey Player Predicts Your Next Move https://hackaday.com/2024/12/16/robot-air-hockey-player-predicts-your-next-move/ https://hackaday.com/2024/12/16/robot-air-hockey-player-predicts-your-next-move/#comments Tue, 17 Dec 2024 06:00:06 +0000 https://hackaday.com/?p=738140 Air hockey is a fun game, but it’s one you can’t play by yourself. That is, unless you have a smart robot hockey player to act as your rival. [Zeroshot] …read more]]>

Air hockey is a fun game, but it’s one you can’t play by yourself. That is, unless you have a smart robot hockey player to act as your rival. [Zeroshot] built exactly that.

The build is based around a small 27-inch air hockey table—not exactly arcade-spec, but big enough to demonstrate the concepts at play. The robot player moves its mallet in the X and Y axes using a pair of NEMA17 stepper motors and an H-belt configuration. To analyze the game state, there’s a Raspberry Pi 3B fitted with a camera, and it has a top-down view of the board. The Pi gives the stepper motors commands on how to move the mallet via an Arduino that communicates with the stepper drivers.  The Pi doesn’t just aim for the puck itself, either. With Python and OpenCV, it tries to predict your own moves by tracking your mallet, and the puck, too. It predicts the very-predictable path of the puck, and moves itself to the right position for effective defence.

Believe it or not, we’ve featured quite a few projects in this vein before. They’ve all got their similarities, and their own unique quirks. Video after the break.

[Thanks to hari wiguna for the tip!]

]]>
https://hackaday.com/2024/12/16/robot-air-hockey-player-predicts-your-next-move/feed/ 21 738140 I built an air hockey robot that PREDICTS your next move 6-42 screenshot (1)
Lasers, Galvos, Action: A Quest for Laser Mastery https://hackaday.com/2024/11/22/lasers-galvos-action-a-quest-for-laser-mastery/ https://hackaday.com/2024/11/22/lasers-galvos-action-a-quest-for-laser-mastery/#comments Sat, 23 Nov 2024 00:00:59 +0000 https://hackaday.com/?p=735230 Custom built RGB laser firing beamIf you’re into hacking hardware and bending light to your will, [Shoaib Mustafa]’s latest project is bound to spike your curiosity. Combining lasers to project multi-colored beams onto a screen …read more]]> Custom built RGB laser firing beam

If you’re into hacking hardware and bending light to your will, [Shoaib Mustafa]’s latest project is bound to spike your curiosity. Combining lasers to project multi-colored beams onto a screen is ambitious enough, but doing it with a galvanomirror, STM32 microcontroller, and mostly scratch-built components? That’s next-level tinkering. This project isn’t just a feast for the eyes—it’s a adventure of control algorithms, hardware hacks, and the occasional ‘oops, that didn’t work.’ You can follow [Shoaib]’s build log and join the journey here.

The nitty-gritty is where it gets fascinating. Shoaib digs into STM32 Timers, explaining how modes like Timer, Counter, and PWM are leveraged for precise control. From adjusting laser intensity to syncing galvos for projection, every component is tuned for maximum flexibility. Need lasers aligned? Enter spectrometry and optical diffusers for precision wavelength management. Want real-time tweaks? A Python-controlled GUI handles the instruments while keeping the setup minimalist. This isn’t just a DIY build—it’s a work of art in problem-solving, with successes like a working simulation and implemented algorithms along the way.

If laser projection or STM32 wizardry excites you, this build will inspire. We featured a similar project by [Ben] back in September, and if you dig deep into our archives, you can eat your heart out on decades of laser projector projects. Explore Shoaib’s complete log on Hackaday.io. It is—literally—hacking at its most brilliant.

]]>
https://hackaday.com/2024/11/22/lasers-galvos-action-a-quest-for-laser-mastery/feed/ 1 735230 rgb-laserprojector-1200
Artificial Intelligence Runs on Arduino https://hackaday.com/2024/10/24/artificial-intelligence-runs-on-arduino/ https://hackaday.com/2024/10/24/artificial-intelligence-runs-on-arduino/#comments Thu, 24 Oct 2024 18:30:20 +0000 https://hackaday.com/?p=729698 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 …read more]]>

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.

]]>
https://hackaday.com/2024/10/24/artificial-intelligence-runs-on-arduino/feed/ 23 729698 ai-lamp-main
Hackaday Links: October 13, 2024 https://hackaday.com/2024/10/13/hackaday-links-october-13-2024/ https://hackaday.com/2024/10/13/hackaday-links-october-13-2024/#comments Sun, 13 Oct 2024 23:00:39 +0000 https://hackaday.com/?p=727119&preview=true&preview_id=727119 Hackaday Links Column BannerSo 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 …read more]]> Hackaday Links Column Banner

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.

Speaking of billionaires, there’s been a lot of buzz in the news lately about using small modular nuclear reactors to power things like cryptocurrency mines and AI data centers. We suspect this trend has as much to do with tech-bro street cred as it does with saving the planet from the extreme power requirements of these endeavors. But as cool as it would be to put on a black turtleneck and cut the ribbon at the first nuke-powered server farm, how much cooler would it be to break a bottle of champagne on the prow of your very own nuclear-powered superyacht? Cool enough, apparently, that none other than Lloyd’s Register, the storied maritime and shipping concern that started in a London coffeehouse in 1760, is starting to think about what nuclear power means to the maritime world, especially for commercial shipping but also for the ultimate in pleasure craft. While it’s true that nuclear-powered vessels have been plying the seas for the better part of a century now, the factors that justify the massive up-front expense have so far limited the viable use cases to nation-states looking to project power and with the ability to create unlimited amounts of money at will. The need for a yacht that can cruise the world ocean for years on end without refueling isn’t clear, but perhaps that’s missing the point. After all, we’ve already seen a tech billionaire build a company to make rockets so he can go to Mars, so it’s not unthinkable that some billionaire will take his yacht nuclear just for the flex.

For various reasons, we’ve done a lot of articles on space topics over the years, despite the fact that getting the technical details that we assume our readers crave as much as we do isn’t easy. One resource we’ve come to depend on is Gunter’s Space Page, which is a treasure trove of information on just about everything that’s ever gone into space, including the stuff that tried but didn’t make it. This is one of those no-nonsense sites that doesn’t have a lot of cruft messing things up and just serves up the details you need. Want to see every launch in 1982? Need a list of everyone who has ever flown to space? Gunter has you covered. Fair warning, though; there are plenty of rabbit holes to fall down on this site, as well as Gunter’s other sites on US Navy ships and steam locomotives.

And finally, another indispensable resource is Grant Sanderson’s wonderful “3Blue1Brown,” a YouTube channel dedicated to showing how math works. There’s plenty of crossover between demographics for Hackaday and 3B1B, so chances are good that you’ve seen Grant’s amazing work, and if you’re like us, you’ve wondered exactly how he goes about creating those wonderful animations. Well, wonder no more — this in-depth video dives into Manim, the custom math animation library Grant created to make his signature look. If you’ve ever wondered what’s going on behind the scenes with such fascinating videos as how complex Fourier series can draw anything or why pi hides inside the collisions of bouncing blocks, you need to check this one out.

]]>
https://hackaday.com/2024/10/13/hackaday-links-october-13-2024/feed/ 10 727119 Hackaday Links