Thread Carefully: An Introduction To Concurrent Python

The ability to execute code in parallel is crucial in a wide variety of scenarios. Concurrent programming is a key asset for web servers, producer/consumer models, batch number-crunching and pretty much any time an application is bottlenecked by a resource.

It’s sadly the case that writing quality concurrent code can be a real headache, but this article aims to demonstrate how easy it is to get started writing threaded programs in Python. Due to the large number of modules available in the standard library which are there to help out with this kind of thing, it’s often the case that simple concurrent tasks are surprisingly quick to implement.

We’ll walk through the difference between threads and processes in a Python context, before reviewing some of the different approaches you can take and what they’re best suited for.

Continue reading “Thread Carefully: An Introduction To Concurrent Python”

Can You 3D-Print A Stator For A Brushless DC Motor?

Betteridge’s Law holds that any headline that ends in a question mark can be answered with a “No.” We’re not sure that [Mr. Betteridge] was exactly correct, though, since 3D-printed stators can work successfully for BLDC motors, for certain values of success.

It’s not that [GreatScott!] isn’t aware that 3D-printed motors are a thing; after all, the video below mentions the giant Halbach array motor we featured some time ago. But part of advancing the state of the art is to replicate someone else’s results, so that’s essentially what [Scott!] attempted to do here. It also builds on his recent experiments with rewinding commercial BLDCs to turn them into generators. His first step is to recreate the stator of his motor as a printable part. It’s easy enough to recreate the stator’s shape, and even to print it using Proto-pasta iron-infused PLA filament. But that doesn’t come close to replicating the magnetic properties of a proper stator laminated from stamped iron pieces. Motors using the printed stators worked, but they were very low torque, refusing to turn with even minimal loading. There were thermal issues, too, which might have been mitigated by a fan.

So not a stunning success, but still an interesting experiment. And seeing the layers in the printed stators gives us an idea: perhaps a dual-extruder printer could alternate between plain PLA and the magnetic stuff, in an attempt to replicate the laminations of a standard stator. This might help limit eddy currents and manage heating a bit better. Continue reading “Can You 3D-Print A Stator For A Brushless DC Motor?”

GPS III Launching Today But You Can’t Use It Until 2022

Imagine if you bought a new car but they keys were not going to be shipped to you until a few years later. That’s analogous to the situation the U.S. Air Force finds itself in. The first GPS III satellite is finally ready to launch today, December 18, 2018 — a little over 2 years beyond the original schedule. However, most of the unique GPS III features won’t be available until at least 2022, according to a 2017 Government Accounting Office (GAO) report to Congress.

GPS III is a project to launch 32 new satellites that will — for military users — be more difficult to jam. For civilian users, the new GPS satellites will be compatible with other systems, including the EU’s Galileo system. But the big draw? About three times the accuracy of the current system. For civilian use, that means 3 to 10 feet under good conditions as opposed to the current systems’ 10- to 33-foot resolution.

Continue reading “GPS III Launching Today But You Can’t Use It Until 2022”

Does Library Bloat Make Your Smartphone App Look Fat?

While earlier smartphones seemed to manage well enough with individual applications that only weighed in at a few megabytes, a perusal of the modern smartphone software store uncovers some positively monstrous file sizes. The fact that we’ve become accustomed to mobile applications requiring 100+ MB downloads on what’s often a metered Internet connection in only a few short years is pretty crazy if you stop to think about it.

Seeing reports that the Nest app for iOS tipped the scales at nearly 250 MB, [Alexandre Colucci] decided to investigate. On his blog he not only documents the process of taking the application apart piece by piece to find out just what’s eating up all that space, but lists some potential fixes which could shave a bit off the top. Even if you aren’t planning a spelunking expedition into your pocket supercomputer’s particular variant of the Netflix app, the methodology and tools he uses here are fascinating in their own right and might be something worth adding to your software bag of tricks.

By passing the application’s files through a disk usage visualizer called GrandPerspective, [Alexandre] immediately identified some rather large blocks of content. The bundled Apple Watch version of the app takes up 23 MB, video and audio used to walk the user through the device setup weigh in at 22 MB, and localization files for various languages consumes a surprising 33 MB. But the biggest single contributor to the application’s heft is the assorted libraries and frameworks which total up to an incredible 67 MB.

Of course the question is, how much of it is really necessary? It’s hard to be sure from an outsider’s perspective, but [Alexandre] notes that a few of the libraries used seem to be redundant or obsolete. In some cases this could be the result of old code still lurking in the project, but the four different libraries used for user tracking probably aren’t in there by accident. It also stands to reason that the instructional videos could be offloaded to something like YouTube, so that only users who need to view them have to expend their bandwidth on it.

Getting a little deeper into things, [Alexandre] notes that some of the localization images appear to be redundant. As a specific example, he points to the images of the Nest itself displaying Fahrenheit and Celsius temperatures. While logically this should only be two image files, there are actually eight copies of the Celsius image, each filed away as language-specific. These redundant localization images could easily be stripped out, but with gains measured in only a few hundred kilobytes, it probably wasn’t considered worth the effort during development.

In the end there’s really not as much bloat as we might like to believe. There were some redundant files, maybe a few questionable library inclusions, and the Apple Watch version of the app could surely be separated out. All together, it might get you a savings of 30 – 40%, but still not enough to bring it down under 100 MB.

All signs point to the fact that modern smartphone software development is just a lot more burdensome than us hackers might like. Save for projects looking to put control back into the hand’s of the users, it looks like mobile operating systems aren’t going to be slimming down anytime soon.

Can Magnets Replace The Spring In A Pogo Stick?

Betteridge’s law of headlines states that any headline that ends in a question mark can be answered by the word ‘no’. It’s the case with articles asking if Millennials are responsible for all of the world’s ills, or if some technology is the future. So we come to this fascinating case of native content (amusing, veiled advertising) from a store that sells really, really powerful magnets. The title of the article asks if magnets can replace the spring in a pogo stick. The answer, of course, is no, but it does provide a fascinating look at linear versus exponential growth.

A pogo stick is simply a spring with a set of handles and footholds that is the subject of a great number of hilarious YouTube videos, at least one of which is impressive. The physics of a pogo stick is determined entirely by Hooke’s Law, and is a linear equation, not counting the strength of a spring and the yield point of steel, but this is a pogo stick we’re talking about. Magnets, on the other hand, obey the inverse square law. Is it possible to fit an exponential function to fit a linear function? No. No, it is not.

I refuse to believe this is the first use of the phrase, ‘immensely disappointing pogo stick’

But a lack of understanding of the basic forces of nature never stopped anyone, so the folks at K & J Magnetics made a really neat test. They printed out a 1/8th scale pogo stick, complete with a spring. It worked like any pogo stick would. Then they took out the spring and put a few magnets where the spring should go. How did that work? Well, it bottomed out and was an immensely disappointing pogo stick.

If a problem is worth solving, it’s worth solving wrongly, so more magnets were added. Mounting three magnets onto a pogo stick gave the same exponential force, but still not enough. Four, five, and six magnets were added to the model pogo stick, and while six magnets gave this model pogo enough force to be ‘bouncy’, there simply wasn’t enough space for the pogo stick to compress.

The takeaway from this experiment is extremely obvious in retrospect, but probably too subtle for a lot of people. There’s a difference between a linear relationship and and exponential relationship. There’s also a video, you can check that out below.

Continue reading “Can Magnets Replace The Spring In A Pogo Stick?”

Tired Of Killing Houseplants? Try Using WiFi.

Here at Hackaday, we have to admit to neglecting a few houseplants in our time. Let’s face it… a cold, hard, thinking machine can care for our green friends better than you can. Why not team up? [cabuu]’s WiFi-enabled soil moisture sensor will do the trick in case you, too, want happy plants.

This is one of those projects which would have been much more difficult even five years ago, and really shows how lucky we are to have accessible technology at our fingertips. It’s conveniently constructed from off-the-shelf electronics modules, and nestled inside a 3D-printed case. The design is attractive as well as functional, showing the status LED and allowing access to the USB charging port.

The brain is a WeMos D1 mini, while a D1 battery shield and 14500 Li-ion battery supplies power. A key point of this build is the use of a capacitive moisture sensor, which doesn’t suffer the same long-term corrosion problems that destroy cheaper resistive probes. And no project is complete without an LED, so a WS2812 shows green for good, red for dry and blue for too wet. To extend battery life, the sensor supports a sleep mode, which tests the soil periodically, and presumably disables the LED.

Of course, if you’re a habitual plant-neglector, simply having a moisture probe won’t help; those can be as easy to ignore as the plant itself. That’s where WiFi comes in. [cabuu] wrote a Blynk app to monitor the sensor on a smartphone. The app shows current moisture levels and allows you to change the wet and dry warning thresholds. When the reading exceeds these levels, the app notifies you — this feature is the one that will keep your plants around.

Continue reading “Tired Of Killing Houseplants? Try Using WiFi.”

Hacker Makes A Flawless Booby Trap, Strikes Back Against Package Thieves

[Mark Rober] was fed up with packages going missing. He kept receiving notifications that his shipments had been delivered, but when checking his porch he found nothing there. Reviewing the CCTV footage revealed random passers-by sidling up to his porch and stealing his parcels. It was time to strike back. Over six months, [Mark] and his friends painstakingly designed, prototyped and iterated the perfect trap for package thieves, resulting in a small unit disguised as an Apple HomePod. The whole scheme is wonderfully over-engineered and we love it.

The main feature of the device is a spinning cup on the top which contains a large amount of glitter. When activated, it ejects glitter in every directions. You could say it’s harmless, as it’s just glitter. But then again, glitter has a way of staying with you for the rest of your life — turning up at the least expected times. It certainly leaves an emotional impression.

Activation is quite clever; the fake package sits on the porch until an accelerometer detects movement. At that point, GPS checks to see if the package has traveled outside a geo-fence around [Mark]’s house. A signal is then sent to the four smartphones to start recording — yes, that’s right, there are 4 phones inside, one on each side to capture the reaction of the thief.

How can [Mark] be so confident that he’ll be able to recover the four phones and their footage? That’s answered by GPS tracking and a can of fart spray actuated by a 3D printed cam and DC motor, ensuring the thief won’t want this package around for long. This actuator and the glitter motor are controlled by a custom PCB, which also triggers the phones to start recording through their headphone jacks and detects the opening of the package with some microswitches. This is truly a masterpiece that outsmarts the package thieves in a way that leaves an impression while still being playful.

(Editor’s Note 2: On 12/20/18 it was announced that two of the five thieves shown in the originally video were staged, apparently without [Mark Rober’s] knowledge. Here is his statement on the matter.)

(Editor’s Note 1: [Sean Hodgins] wrote in with bonus video on how the Glitter Bomb works and how it was made.)

If booby traps are your thing, we’ve got you covered. Check out this ticking bomb style puzzle, or this crate challenge which is rigged to blow.

Continue reading “Hacker Makes A Flawless Booby Trap, Strikes Back Against Package Thieves”