Crawling A Dungeon, 64 Pixels At A Time

The trend in video games is toward not being able to differentiate them from live-action theatrical releases, and games studios are getting hard to tell from movie studios. But quality graphics don’t always translate into quality gameplay, and a lot can be accomplished with minimalist graphics. Turn the clock back a few decades and think about the quarters sucked up by classics like Pac-Man, Space Invaders, and even Pong if you have any doubts about that.

But even Pong had more than 64 pixels to work with, which is why this dungeon-crawler game on an 8×8 RGB matrix is so intriguing. You might think [Stolistic]’s game would be as simple as possible but think again. The video below shows it in action, and while new users will need a little help figuring out what the various colors mean, the game is remarkably engaging. The structure of the dungeon is random with multiple levels to unlock via the contents of power-up chests, and there are mobs to battle in a zoomed-in display. The game runs on an Arduino Uno and the matrix is driven by a bunch of 74HC595 shift registers.

It’s fun to see what can be accomplished with as little as possible. Looking for more low-res goodness? Check out this minimalist animated display, or a Geiger counter with a matrix display.

Continue reading “Crawling A Dungeon, 64 Pixels At A Time”

Putting A Poor Man’s Vector Analyzer Through Its Paces

If anything about electronics approaches the level of black magic, it’s antenna theory. Entire books dedicated to the subject often merely scratch the surface, and unless you’re a pro with all the expensive test gear needed to visualize what’s happening, the chances are pretty good that your antenna game is more practical than theoretical. Not that there’s anything wrong with that — hams and other RF enthusiasts have been getting by with antennas that work without really understanding why for generations.

But we’re living in the future, and the tools to properly analyze antenna designs are actually now within the means of almost everyone. [Andreas Spiess] recently reviewed one such instrument, the N1201SA vector impedance analyzer, available from the usual overseas sources for less than $150. [Andreas]’s review does not seem to be sponsored, so it seems like we’re getting his unvarnished opinion; spoiler alert, he loves it. And with good reason; while not a full vector network analyzer (VNA) that will blow a multi-thousand dollar hole in your wallet, this instrument looks like an incredible addition to your test suite. The tested unit works from 137 MHz to 2.4 GHz, so it covers the VHF and UHF ham bands as well as LoRa, WiFi, cell, ISM, and more. But of course, [Andreas] doesn’t just review the unit, he also gives us a healthy dose of theory in his approachable style.

[The guy with the Swiss accent] has been doing a lot of great work these days, covering everything from how not to forget your chores to reverse engineering an IoT Geiger counter. Check out his channel — almost everything he does is worth a watch.

Continue reading “Putting A Poor Man’s Vector Analyzer Through Its Paces”

Entropy And The Arduino: When Clock Jitter Is Useful

What do you do, when you need a random number in your programming? The chances are that you reach for your environment’s function to do the job, usually something like rand() or similar. This returns the required number, and you go happily on your way.

A shift register configured as a pseudo-random number generator.
A shift register configured as a pseudo-random
number generator. [by KCAuXy4p CC0 1.0]
Except of course the reality isn’t quite that simple, and as many of you will know it all comes down to the level of randomness that you require. The simplest way to generate a random number in software is through a pseudo-random number generator, or PRNG. If you prefer to think in hardware terms, the most elementary PRNG is a shift register with a feedback loop from two of its cells through an XOR gate. While it provides a steady stream of bits it suffers from the fatal flaw that the stream is an endlessly repeating sequence rather than truly random. A PRNG is random enough to provide a level of chance in a computer game, but that predictability would make it entirely unsuitable to be used in cryptographic security for a financial transaction.

There is a handy way to deal with the PRNG predictability problem, and it lies in ensuring that its random number generation starts at a random point. Imagine the  shift register in the previous paragraph being initialised with a random number rather than a string of zeros. This random point is referred to as the seed, and if a PRNG algorithm can be started with a seed derived from a truly unpredictable source, then its output becomes no longer predictable.

Selecting Unpredictable Seeds

Computer systems that use a PRNG will therefore often have some form of seed() function alongside their rand() function. Sometimes this will take a number as an argument allowing the user to provide their own random number, at other times they will take a random number from some source of their own. The Sinclair 8-bit home computers for example took their seed from a count of the number of TV frames since switch-on.

The not-very-random result of a thousand analogRead() calls.
The not-very-random result of a thousand analogRead() calls.

The Arduino Uno has a random() function that returns a random number from a PRNG, and as you might expect it also has a randomSeed() function to ensure that the PRNG is seeded with something that will underpin its randomness. All well and good, you might think, but sadly the Atmel processor on which it depends has no hardware entropy source from which to derive that seed. The user is left to search for a random number of their own, and sadly as we were alerted by a Twitter conversation between @scanlime and @cybergibbons, this is the point at which matters start to go awry. The documentation for randomSeed() suggests reading the random noise on an unused pin via analogRead(), and using that figure does not return anything like the required level of entropy. A very quick test using the Arduino Graph example yields a stream of readings from a pin, and aggregating several thousand of them into a spreadsheet shows an extremely narrow distribution. Clearly a better source is called for.

Noisy Hardware or a Jittery Clock

As a slightly old-school electronic engineer, my thoughts turn straight to a piece of hardware. Source a nice and noisy germanium diode, give it a couple of op-amps to amplify and filter the noise before feeding it to that Arduino pin. Maybe you were thinking about radioactive decay and Geiger counters at that point, or even bouncing balls. Unfortunately though, even if they scratch the urge to make an interesting piece of engineering, these pieces of hardware run the risk of becoming overcomplex and perhaps a bit messy.

The significantly more random result of a thousand Arduino Entropy Library calls.
The significantly more random result of a thousand Arduino Entropy Library calls.

The best of the suggestions in the Twitter thread brings us to the Arduino Entropy Library, which uses jitter in the microcontroller clock to generate truly random numbers that can be used as seeds. Lifting code from the library’s random number example gave us a continuous stream of numbers, and taking a thousand of them for the same spreadsheet treatment shows a much more even distribution. The library performs as it should, though it should be noted that it’s not a particularly fast way to generate a random number.

So should you ever need a truly random number in your Arduino sketch rather than one that appears random enough for some purposes, you now know that you can safely disregard the documentation for a random seed and use the entropy library instead. Of course this comes at the expense of adding an extra library to the overhead of your sketch, but if space is at a premium you still have the option of some form of hardware noise generator. Meanwhile perhaps it is time for the Arduino folks to re-appraise their documentation.

The subject of entropy and generating random numbers is one that has appeared on these pages many times. [Voja Antonic] made a in-depth study using uninitialized RAM as an entropy source for microcontrollers. If you have an insatiable appetite for understanding Linux entropy, we point you at [Elliot Williams]’ comprehensive examination of the subject.

[Arduino image: DustyDingo Public domain]

CosmicWatch muon detector

Make A Cheap Muon Detector Using Cosmicwatch

A little over a year ago we’d written about a sub $100 muon detector that MIT doctoral candidate [Spencer Axani] and a few others had put together. At the time there was little more than a paper on arxiv.org about it. Now, a few versions later they’ve refined it to the level of a kit with full instructions for making your own under the banner, CosmicWatch including PCB Gerber files for the two surface mount boards you’ll need to assemble.

What’s a muon? The Earth is under constant bombardment from cosmic rays, most of them being nuclei expelled from supernova explosions. As they collide with nuclei in our atmosphere, pions and kaons are produced, and the pions then decay into muons.  These muons are similar to electrons, having a +1 or -1 charge, but with 200 times the mass.

This pion-to-muon decay happens higher than 10 km above the Earth’s surface. But the muons have a lifetime at rest of 2.2 μs. This means that the number of muons peak at around 10 km and decrease as you go down. A jetliner at 30,000 feet will encounter far more muons than will someone at the Earth’s surface where there’s one per cm2 per minute, and the deeper underground you go the fewer still. This makes them useful for inferring altitude and depth.

How does CosmicWatch detect these muons? The working components of the detector consist of a plastic scintillator, a silicon photomultiplier (SiPM), a main circuit board which does signal amplification and peak detection among other things, and an Arduino nano.

As a muon passes through the scintillating material, some of its energy is absorbed and re-emitted as photons. Those photons are detected by the silicon photomultiplier (SiPM) which then outputs an electrical signal that is approximately 0.5 μs wide and 10-100 mV. That’s then amplified by a factor of 6. However, the amplified pulse is too brief for the Arduino nano and so it’s stretched out by the peak detector to roughly 100 μs. The Arduino samples the peak detector’s output and calculates the original pulse’s amplitude.

Their webpage has copious details on where to get the parts, the software and how to make it. However, they do assume you can either find a cheap photomultiplier somewhere or buy it in quantities of over 100 brand new, presumably as part of a school program. That bulk purchase makes the difference between a $50 part and one just over $100. But being skilled hackers we’re sure you can find other ways to save costs, and $150 for a muon detector still isn’t too unreasonable.

Detecting muons seems to have become a thing lately. Not too long ago we reported on a Hackaday prize entry for a detector that uses Russian Geiger–Müller Tubes.

Sferics, Whistlers, And The Dawn Chorus: Listening To Earth Music On VLF

We live in an electromagnetic soup, bombarded by wavelengths from DC to daylight and beyond. A lot of it is of our own making, especially further up the spectrum where wavelengths are short enough for the bandwidth needed for things like WiFi and cell phones. But long before humans figured out how to make their own electromagnetic ripples, the Earth was singing songs at the low end of the spectrum. The very low frequency (VLF) band abounds with interesting natural emissions, and listening to these Earth sounds can be quite a treat.

Continue reading “Sferics, Whistlers, And The Dawn Chorus: Listening To Earth Music On VLF”

Review: IoT Data Logging Services With MQTT

For the last few months, I had been using Sparkfun’s Phant server as a data logger for a small science project. Unfortunately, they’ve had some serious technical issues and have discontinued the service. Phant was good while it lasted: it was easy to use, free, and allowed me to download the data in a CSV format. It shared data with analog.io, which at the time was a good solution for data visualization.

While I could continue using Phant since it is an open-source project and Sparkfun kindly releases the source code for the server on Github, I thought it might be better to do some research, see what’s out there. I decided to write a minimal implementation for each platform as an interesting way to get a feel for each. To that end, I connected a DHT11 temperature/humidity sensor to a NodeMCU board to act as a simple data source.

Continue reading “Review: IoT Data Logging Services With MQTT”

Hackaday Prize Entry: An Open Radiation Detector

For his Hackaday Prize entry, [Carlos] is pushing the boundaries of what can be built with PCBs. He’s designed a very low-cost radiation detector that leverages pick and place machines, off-the-shelf components, and very simple electronics. It’s a novel ion chamber design, and if you ever needed a low-cost, easily manufacturable radiation detector, this is the project you want.

Instead of a Geiger tube or a spark detectors, this radiation detector uses an ionization chamber to detect radiation. This project was inspired by the work of [Charles Wenzel] and [Alan Yates], and the implementation is actually pretty simple. A metal can — or some other type of enclosure — is electrified, and a single wire is stuck right into the middle of the can. When alpha and beta particles enter the can, air molecules are ionized, and attracted to either the can or the wire by a difference in voltage. A tiny bit of current flows between the can and the wire, which can be detected if you have a sufficiently sensitive circuit.

The basic idea is well-publicised and well-understood. What [Carlos] is doing with this project is making an ionization chamber easily manufacturable. He’s doing this entirely with standard PCBs and solder instead of paint cans, RF connectors, and deadbugged transistors of the earlier experiments. The resulting PCB actually looks like something that wasn’t put together in a garage (even though it probably was), and is an amazing entry for the Hackaday Prize.