Stay at Home, HOPE and DEF CON Will Come to You

We’ve often heard conferences like HOPE and DEF CON called Hacker Summer Camp (although there are certainly more camp-like camps that also fit the bill). As we get into the hot parts of the summer, heading indoors for security talks, workshops, and untold shenanigans sounds like a good idea… if it weren’t for an ongoing pandemic. The good news is that you can still get a strong dose of these cons over the next three weekends as they’re being offered virtually.

Hackers on Planet Earth (HOPE) is a biennial conference hosted in NYC. After much drama about the dank Hotel Pennsylvania hiking prices astronomically for the con, a new venue was found and we all breathed a sigh of relief. The best laid plans, etc. etc. — you know how this turns out. But beginning this Saturday, July 25th, over 100 speakers will present in HOPE’s first-ever live online presentation. Hackaday is a proud sponsor of HOPE 2020.

DEF CON happens every year, and every year we tell you that DEF CON has been cancelled. What do you do if it has actually been cancelled when the boy constantly cries wolf? Well it’s not cancelled, it’s morphed into what is called DEF CON Safe Mode — an online offering for all to enjoy. Go head, hook your computer up to the online version of DEF CON, what could go wrong? Find out when the virtual con goes live starting August 6th.

These are not the same as meeting up IRL. There are so many chance interactions and spectacles to see that you simply cannot spark with a virtual offering. However, the platform for presenters, the coming together to talk, learn, and share about privacy, security, and internet freedom are meaningful and worth our time. So support your favorite cons by joining in, even when it’s from the comfort of your own couch.

source https://hackaday.com/2020/07/21/stay-at-home-hope-and-def-con-will-come-to-you/

Model Hydroelectric Plant is an Illuminating Educational Tool

There’s more than one way to light up a strip of LEDs. Have you tried building your own hydroelectric power plant to do it? Well, now you can. Replicating [Matic Markovič]’s entry into the 2020 Hackaday Prize is bound to teach you something, if not many things, about the way hydroelectric power is generated and the way the variables play into it.

In [Matic]’s model, water from an adjustable-height reservoir flows into a 3D-printed Pelton turbine. The water jet hits the turbine’s cupped fins at a 90° angle, causing the assembly to spin around rapidly. This mechanical energy charges a brushless DC motor that’s connected to an Arduino Nano, which rectifies the AC from the generator and uses it to light up an RGB strip like an equalizer display that represents the power being generated.

This is easily one of the coolest educational displays we’ve ever seen. The reservoir can move up and down over a 55 cm (21.6″) range with the flick of a three-way toggle, which makes it easy to see that the higher the reservoir, the more power is generated. [Matic] has the STLs and INOs in the usual places if you want to make your own. Flow past the break for a demonstration, followed by an exploded render that gets put back together by invisible hands.

Your hydroelectric setup doesn’t need to be fancy, it just needs to work. One man’s trash can be another man’s off-grid phone charger.

source https://hackaday.com/2020/07/21/model-hydroelectric-plant-is-an-illuminating-educational-tool/

Model Hydroelectric Plant is an Illuminating Educational Tool

There’s more than one way to light up a strip of LEDs. Have you tried building your own hydroelectric power plant to do it? Well, now you can. Replicating [Matic Markovič]’s entry into the 2020 Hackaday Prize is bound to teach you something, if not many things, about the way hydroelectric power is generated and the way the variables play into it.

In [Matic]’s model, water from an adjustable-height reservoir flows into a 3D-printed Pelton turbine. The water jet hits the turbine’s cupped fins at a 90° angle, causing the assembly to spin around rapidly. This mechanical energy charges a brushless DC motor that’s connected to an Arduino Nano, which rectifies the AC from the generator and uses it to light up an RGB strip like an equalizer display that represents the power being generated.

This is easily one of the coolest educational displays we’ve ever seen. The reservoir can move up and down over a 55 cm (21.6″) range with the flick of a three-way toggle, which makes it easy to see that the higher the reservoir, the more power is generated. [Matic] has the STLs and INOs in the usual places if you want to make your own. Flow past the break for a demonstration, followed by an exploded render that gets put back together by invisible hands.

Your hydroelectric setup doesn’t need to be fancy, it just needs to work. One man’s trash can be another man’s off-grid phone charger.

source https://hackaday.com/2020/07/21/model-hydroelectric-plant-is-an-illuminating-educational-tool/

Model Hydroelectric Plant is an Illuminating Educational Tool

There’s more than one way to light up a strip of LEDs. Have you tried building your own hydroelectric power plant to do it? Well, now you can. Replicating [Matic Markovič]’s entry into the 2020 Hackaday Prize is bound to teach you something, if not many things, about the way hydroelectric power is generated and the way the variables play into it.

In [Matic]’s model, water from an adjustable-height reservoir flows into a 3D-printed Pelton turbine. The water jet hits the turbine’s cupped fins at a 90° angle, causing the assembly to spin around rapidly. This mechanical energy charges a brushless DC motor that’s connected to an Arduino Nano, which rectifies the AC from the generator and uses it to light up an RGB strip like an equalizer display that represents the power being generated.

This is easily one of the coolest educational displays we’ve ever seen. The reservoir can move up and down over a 55 cm (21.6″) range with the flick of a three-way toggle, which makes it easy to see that the higher the reservoir, the more power is generated. [Matic] has the STLs and INOs in the usual places if you want to make your own. Flow past the break for a demonstration, followed by an exploded render that gets put back together by invisible hands.

Your hydroelectric setup doesn’t need to be fancy, it just needs to work. One man’s trash can be another man’s off-grid phone charger.

source https://hackaday.com/2020/07/21/model-hydroelectric-plant-is-an-illuminating-educational-tool/

Beyond Printf(): Better Logging Practices for Faster Debugging

All of us who do some programming know that logging is a time-tested way to output messages about the internal state of our code. With varying degrees of adjustable granularity, these messages allow us to keep track of not only the state of the application, but also its overall health. When things do end up going FUBAR, these log messages are usually the first thing we look at as a software equivalent of a Flight Data Recorder in an airplane.

Spending some time and care in not only designing the logging system, but also in deciding what should be logged and at what level, can make our future self appreciate life a lot more. We’re all familiar with the practice of ‘printf-debugging’, where logging is added as part of the usual post-crash autopsy as one tries to figure out what exactly went wrong. It’s one way of doing it, and eventually it works, but we can do much better.

People are lazy, and you’re only going to stick to good logging practices if they are at least as easy if not easier than sprinkling printf() statement throughout the code. Yet at the same time we want to be able to handle things like log levels and newlines without too much extra typing. The most successful logging libraries are built with this

Setting the Context

Not every application calls for the same kind of logging. Consider the context of your project when deciding on the logging that will fit your needs.

Many embedded platforms are highly application-specific. Whether it’s a simple 8-bit MCU inside a washing machine or a powerful SoC-based system, it follows that a microwave’s MCU firmware does not require the same level of logging as a car’s ECU or an industrial PID controller. However, they all benefit from good logging practices, whether those messages are being stored, or only visible when actively debugging the hardware.

For server applications, logging is a pretty central part of operations, as a system administrator will want to read out the logs from a central location for all services that run on the servers for which they are responsible. This implies that these logs should only contain the information that a system administrator might find useful, which is not the same information developers will be looking for.

Desktop platforms are similar, where on most platforms a central logging service will record the standard output from any running services. For regular applications (i.e. not services), any logging output tends to either be a more ephemeral thing. Either the standard output is displayed in a terminal window, or vanishes into the void without a terminal or other output associated with it. For the sake of this article we will assume that we just have to write to stdout without concerning us with any further details.

As a small aside, mobile platforms are a rather special case when it comes to logging. They are more similar to server platforms, in the sense that every application’s standard output is logged. This way one gets the logging for every single service and application that is running, without having to configure anything. The exact details of how to obtain this log on mobile platforms like Android, iOS, Tizen, or ChromeOS will differ per platform.

Use Log Levels Wisely

Why have log levels, you may ask? Because you want to differentiate between the importance of log messages, possibly even filter just for particular types of messages. Common log levels are:

  1. Fatal.
  2. Critical.
  3. Error.
  4. Warning.
  5. Notice.
  6. Info.
  7. Debug.
  8. Trace.

Normally you’d run a service at a log level of at most ‘Info’ level, but if the service is too ‘chatty’ at this log level one might want to bump it down to Notice or even just Warning. The onus is hereby on the developer to properly consider what log level the message they’re about to add to the code should exist at. Is it an informational message? A notice that should be looked at at least once? Or is it a warning that must be addressed?

Obviously, an Error level message is bad news, but we have two more levels beyond that. Here ‘Critical’ level should be used for errors that fall between ‘well, bugger’ and ‘the system just caught on fire’. It follows then that ‘Fatal’ messages involve the service reaching an unrecoverable state, a fatal runtime error, and anything else which might mean that a sysadmin is about to get paged out of bed at 3 AM on a Saturday.

Finally, the ‘Debug’ level is for information that is useful while debugging the code, like values of certain variables and verbose logging of application activity. For truly fine-grained debug output, there is the ‘Trace’ level, which is for tedious information. This is generally used for maximum verbosity logging.

Using Poco::Logger; — A Practical Server-Based Example

Over the years, I have had to add logging to both hobby and commercial projects. Among my favorites was an embedded server project that would run on countless headless systems around the world, with the only feedback being the built-in logging that could be read out with the right software and sent back to HQ. For this I used Poco::Logger from the libPoco library. It takes care of the more tedious stuff, such as herding different logging streams (channels) together and other logistics.

The right logging was essential not just for myself to diagnose problems, but also for colleagues who could use the same logging to figure out where (and why) things had begun to catch on fire by tracking requests and their data. It worked well and and I’ve ended up using the same kind of logging in some of my hobby projects, including NymphRPC, a Remote Procedure Call (RPC) library in C++.  The part that I implemented is contained in nymph_logger.h and nymph_logger.cpp. It allows NymphRPC-based applications to write to the log as follows:


NYMPH_LOG_DEBUG("Added new connection with handle: " + NumberFormatter::format(handle));

The NYMPH_LOG_DEBUG () part is a preprocessor macro, which is defined in nymph_logger.h as:

#define NYMPH_LOG_DEBUG(msg) \
	if (NymphLogger::priority >= Poco::Message::PRIO_DEBUG) { \
		NymphLogger::logger(loggerName).debug(msg, __FILE__, __LINE__);\
	}

Here we can see how the line is replaced with an if-statement that checks at which log level the application is supposed to be logging at. The preprocessor statement saves us from typing all of this every single time, while also expanding the __FILE__ and __LINE__ text into the current filename and line in the (unprocessed) source code where the log statement is used. The static NymphLogger::logger() call returns a specific logger, which is an instance of Poco::Logger.

A single NymphLoggerChannel (inherited from Poco::Channel) is provided to Poco::Logger as an output channel. This channel merely passes a formatted string along with the log level to an externally provided function pointer, from where it can be printed to stdout, written to a file, stored in a database, or whatever else is appropriate.

The formatting code:

	string msgStr;
	msgStr = NumberFormatter::format(msg.getPid());
	msgStr += "." + NumberFormatter::format(msg.getTid());
	msgStr += "\t" + msg.getSource() + "\t";
	msgStr += NumberFormatter::format(msg.getSourceLine()) + "\t";
	msgStr += msg.getText() + "\t\t- ";
	msgStr += msg.getSourceFile();
	
	(*loggerFunction)(level, msgStr);

When we then run the NymphRPC test client and server, we can see log output like the following:

6 - 14524.2     NymphSession    130     Read 37 bytes.          - src/nymph_session.cpp
6 - 14524.2     NymphMessage    79      Method ID: 2.           - src/nymph_message.cpp
6 - 14524.2     NymphMessage    93      Message flags: 0x0              - src/nymph_message.cpp
6 - 14524.2     NymphUtilities  170     NYMPH_TYPE_STRING               - src/nymph_utilities.cpp
6 - 14524.2     NymphTypes      306     String value: callbackFunction.         - src/nymph_types.cpp
6 - 14524.2     NymphSession    148     Calling method callback for message ID: 0x3             - src/nymph_session.cpp
6 - 14524.2     NymphMethod     92      Calling callback for method: helloCallbackFunction              - src/nymph_method.cpp

Looking at the test server’s code we can see that the first number is the log level (6: Debug), with the rest being the previously formatted string. This contains the process ID, the thread in this process which logged the message, the name of the logger, the line in the source, the message, and finally the relative path (from the Makefile) to the source file.

Final thoughts

I have found that having to regularly eat one’s own dogfood and dealing with commentary from colleagues and customers about the logging output from one’s code has been highly motivating to polish the rough spots. The one which this article cannot cover is what is important to log in your code. That is something which you, the dev, either knows already or will find out through bitter experience while digging through a log file.

That said, a hobby project is a good place to get started with trying out different logging approaches. Once you find yourself working on a commercial project, it is definitely too late to get creative. On the positive side, once you figure out how to do logging right in different situations, it can turn weekend-long bug hunting sessions into a brief, 10-minute log-reading-code-tweaking and CI-bothering session on a Friday afternoon.

source https://hackaday.com/2020/07/21/beyond-printf-better-logging-practices-for-faster-debugging/

Flipping a Coin 10,000 Times With A Dedicated Machine

Flipping a coin is often the initial example used to help teach probability and statistics to maths students. Often, there is talk of how, given a fair coin, the probability of landing heads or tails should approach 0.5. Of course, if you want to test this, it pays to have a machine do the hard work for you. [Andrew Consroe] has the rig to do just that.

The build consists largely of 3D printed parts. A large cylindrical shroud is used to keep the coin within the flipping area. A spring-loaded dowel is actuated by a stepper motor spinning a cam, which flips the coin. Once the coin has landed, it is photographed with a webcam. An image processing pipeline then determines whether the coin landed heads or tails. A black spot is used on one side of the coin to aid analysis, as the poor-quality webcam images weren’t good enough to recognise the coin in its standard form. Once the flip has been analysed, a sliding aperture is used to push the coin back towards the flipper for the next cycle.

The machine completes a flip approximately every two seconds, meaning 10,000 flips would take approximately 2.5 days. Unfortunately, due to noise and occasional coin escapes, [Andrew] hasn’t yet been able to achieve his goal. He aims to increase speed significantly before making an all-out attempt.

Coin flips can make for decent random numbers, but if you need better ones, perhaps NIST can help you out. Video after the break.

source https://hackaday.com/2020/07/21/flipping-a-coin-10000-times-with-a-dedicated-machine/

A Stylish Raspberry Pi Camera

The Raspberry Pi HQ camera module is an exciting product that for the first time puts something close to a decent quality interchangeable lens camera into the hands of hardware hackers. It’s already attracted the attention of those who have a wish to explore the boundaries of camera form factors. Our latest entrant in this field comes courtesy of [BBまどーし], who has opted for a very good 3D-printed analog of a conventional compact camera.

On the front as you might expect is the module, concealed behind a smart plastic ring. Behind that is a battery compartment, concealing not the brace of 18650s or the bare LiPo pouch that you might expect, but a 10,400 mAH USB power bank. Behind that is something approaching a conventional Raspberry Pi case, designed to take a Hyperpixel screen. The battery might seem an unadventurous choice, but it serves to highlight just how much bang for your buck can now be found in compact power banks. It may not have a hacker aesthetic, but you can’t argue with its cost and simplicity.

The details are the interesting part of this design, for instance it has a standard accessory shoe printed into its top. There is also a shutter button, but they admit to not being a software wizard enough to get it working. Perhaps a quick look at this Pi Camera in a 1970s Merlin game would be in order.

source https://hackaday.com/2020/07/21/a-stylish-raspberry-pi-camera/

A Simple Soft Power Switch Using Common Modules

If you want to easily control the power in a circuit, you’ll probably reach for the classic toggle switch. While there’s certainly nothing wrong with that, physical toggles are a bit dated at this point. A soft power switch that turns your gadget on and off at the tap of a finger is far more 21st century. You might think this kind of modern trickery is too difficult to implement on a DIY project, but as [Sasa Karanovic] shows, it’s actually a lot easier than you might think.

Now to be fair, that wasn’t actually his goal. All [Sasa] was trying to do was come up with a slick way to control the LED lighting in his 3D printer enclosure. Which, as you can see in the video below, he accomplished. But the hacked together circuit he used to do it could easily be adapted for other electronic projects. If you’re using a LM2596 DC-DC converter module to power your gadget, you can add a touch sensitive soft switch for literally pennies.

The trick is utilizing the enable pin on the LM2596. The common buck converter modules tie this pin to ground so the regulator is always enabled, but if you lift the pin off the PCB and connect it to the output of a TTP223 capacitive touch sensor, you can simply tap the pad to control the regulator. Power for the touch sensor itself is pulled from the input side of the regulator, so even when the power is cut off downstream, the sensor is still awake and can kick the chip back into gear when you need it.

If you’re not interested in touch control, you could try connecting the enable pin on the regulator to an ESP8266 and making a cheap Internet-controlled DC power supply.

source https://hackaday.com/2020/07/21/a-simple-soft-power-switch-using-common-modules/

Life Size Lancer Becomes Gears of War Motion Controller

Gears of War is a franchise famous for its giant gun with a big chainsaw on the front. [Eric] laid his hands on a toy replica, and decided it had to become a usable motion controller for the game.

The build is straightforward, following the usual format for motion controller builds. Fitted with a gyroscope and accelerometer, it’s interfaced to the PC using a microcontroller. The toy has a trigger which is hooked up to the fire button in game. Additional buttons were added to the shell for movement and other actions such as reloading and finding cover. As a nice final touch, the large pull handle on the left of the weapon is used to activate the chain saw in-game.

While it’s unlikely to be competitive with a mouse or even gamepad in practice, it’s hard to argue against the fun of wielding a full-size, 10-pound weapon when playing Gears of War 5. [Eric] has also shared a basic controller hacking guide for those eager to get into similar builds themselves. We’ve featured [Eric]’s work before, too – with this epic Minecraft pickaxe build. Video after the break.

source https://hackaday.com/2020/07/20/life-size-lancer-becomes-gears-of-war-motion-controller/

Can A 3D Printer Print Better Filament For Itself?

3D printed parts are generally no way near the strength of an equivalent injection moulded part and techniques such as a sustained heat treatment, though effective usually distort the part beyond use.

[CNC Kitchen] was investigating the results of a recent paper, that described a novel ABS filament reinforced by a “star” shaped Polycarbonate core, an arrangement the authors claim is resilient to deformation during the annealing process often necessary to increase part strength. While the researchers had access to specialised equipment needed to manufacture such a composite material, [CNC Kitchen’s] solution of simply using his dual extruder setup to directly print the required hybrid filament is something we feel, strongly resonates with the now old school, RepRap “print your printer” sentiment.

The printed filament seems to have reasonable dimensional accuracy and passing the printed spool through a heater block without the nozzle attached, ensured there would be no obvious clogs. The rest of the video focuses on a very thorough comparison of strength and deformation between the garden variety Polycarbonate, ABS and this new hybrid filament after the annealing process. Although he concludes with mixed results, just being able to combine and print your own hybrid filament is super cool and a success in its own right!

Interested in multi-material filaments? Check out our article on a more conventional approach which does not involve printing it yourself!

source https://hackaday.com/2020/07/20/can-a-3d-printer-print-better-filament-for-itself/

Skee-Ball Scoring with Coin Slot Switches

Bowling is great and all, but the unpredictability of that little ball jump in Skee-Ball is so much more exciting. You can play it straight, or spend a bunch of time perfecting the 100-point shot. And unlike bowling, there’s nothing to reset, because gravity gives you the balls back.

In one of [gcall1979]’s earlier Skee-Ball machines, gravity assisted the scoring mechanism, too: each ball rolls back to the player and lands in a lane labeled with the corresponding score, which is an interesting engineering challenge in its own right. He decided to build automatic scoring into his newest Skee-Ball machine.

At the bottom of each cylinder is an arcade machine coin door switch with a long wire actuator. These had to be mounted so they’re close enough to the hole, but out of the way of the balls.

Each switch is wired up to an Arduino Mega along with four large 7-segments for the score, and a giant 7-segment to show the number of balls played. Whenever the game is reset, a servo drops a door to release the balls, just like a commercial machine.

The arcade switches work pretty well, especially once he bent the wire into hook shape to cover more area. But they do fail once in a while, maybe because the targets are full-size, but the balls are half regulation size. For the next one, [gcall1979] is planning to use IR break-beam targets which ought to work with any size ball. If you prefer bowling, you won’t strike out with break-beam targets there, either.

source https://hackaday.com/2020/07/20/skee-ball-scoring-with-coin-slot-switches/