Saturday, December 3, 2022
HomeElectronicsASCII Annihilator - Information - SparkFun Electronics

ASCII Annihilator – Information – SparkFun Electronics

A modification to SparkFun’s Binary Blaster results in expanded gameplay!




One among my favourite SparkFun merchandise is the Binary Blaster. It’s a beautiful little soldering equipment, which, when accomplished, is a enjoyable recreation to assist the consumer follow changing from decimal and hex to binary! I picked one up and had enjoyable placing it collectively and taking part in it, however discovered that slightly shortly I mastered each recreation modes and wished extra of a problem!

Image of binary blaster next to ascii annihilator

Introducing the ASCII Annihilator (Asc Blaster for brief)! Primarily based on the board for the Binary Blaster, this mod provides an extra recreation mode, a 4 character alphanumeric show, and may quiz you on a big swath of binary, hexadecimal, and even ASCII! You possibly can even combine and match recreation modes and difficulties by holding completely different mixtures of buttons on boot.

The one new half required for the mod is the alphanumeric show itself and some bits of wire to make use of as jumpers! Performing the mod requires modifying the PCB by chopping and modifying traces and bending the show pins. In the event you really feel as much as the duty, you should buy a binary blaster, no matter shade show you need, head on over to the github web page, and comply with the directions! First although, lemme sit ya down and stroll ya by way of the design!

The binary blaster solely has 4 lit buttons on it, simply sufficient to enter a binary ‘nibble’. That solely permits you to be quizzed as much as 15 in decimal or F in hex (0b1111). The show, nonetheless, consists of two 7-segment characters, sufficient to show as much as 99 in decimal or FF in hex! I spotted that with an additional change, one may toggle the lit buttons between two nibbles, sufficient for a full byte! I shortly carried out this and sacrificed the unique sound change and buzzer for this ‘nibble change’. (Sooner or later I would launch the code for this model, however I managed to lose it so it’ll should be rewritten)

The inventory blaster can solely quiz as much as 15, however with a nibble change, it will probably go as much as 99!This was enjoyable for some time longer, however after a while I began to be irritated that whereas I may enter as much as 255 on the buttons, the show may nonetheless solely present as much as 99 in decimal. Plus, a full byte can be utilized for extra than simply numbers! ASCII, easy shade values, and even meeting directions for some architectures will be saved in a byte! Because it occurred, SparkFun had simply began promoting a 4-character, 14-segment alphanumeric show, and as quickly as I noticed it, I knew the ultimate type of my modified Binary Blaster: I might add a type of shows and quiz the consumer on all of ASCII! I purchased one, freed it from its Qwiic-based driver board, and instantly set to work incorporating it.

My first hurdle was a scarcity of pins. With one pin for the nibble change, one pin for sensing every button, one other for driving every button’s led, and as much as 17 for the show, that makes 26 pins. That is little bit of an issue with the keyed ATMEGA328 solely having 21 pins accessible. There are just a few methods to get round this, the best of which might be to maintain the Qwiic driver board on the show and discuss to it over I2C. That strategy, nonetheless, appeared difficult and boring. The strategy I settled on was much more difficult, however a lot much less boring: charlieplexing!

Charlieplexing is a very cool technique of multiplexing that takes benefit of two info:

  1. Diodes will solely enable present to stream a technique.

  2. While you set a pin on a microcontroller as an enter, it places that pin in a “high-impedance state”. That’s to say it successfully disconnects that pin from the circuit.

Utilizing this data and a few fancy routing, one can obtain surprisingly excessive multiplexing effectivity with only a bunch of diodes. Now, more often than not this isn’t too helpful, because it’s a lot simpler and cheaper to simply purchase a chip that does the muxing for you than to purchase a diode for every of your outputs. Nevertheless on this case the show and lit buttons all use LEDs anyway, so we get these diodes without spending a dime!

The subsequent step was structure; I wished to maintain the {hardware} modifications so simple as potential. This meant minimizing the quantity and size of jumpers to make it compact and straightforward to do. This half was actually enjoyable! I printed off some photos of the PCB structure and doodled on them with a pen till I’d discovered one of the best ways to change the board.

[doodled PCB layout]

alt text

With the {hardware} modifications all executed, it was time to maneuver on to programming! I may have modified the Binary Blaster code (that’s what open supply is for, in fact!), however I actually wished to launch the code underneath GPLV3+, which the Blaster’s CC-BY-SA license is incompatible with. This meant a complete rewrite, however I definitely took some inspiration from the Blaster code. Significantly, the unique Binary Blaster’s show implementation was fantastic, assigning all the show pins to sequential pins within the microcontroller’s registers. This enables one to simply set a given show state just by writing a byte on to the registers suddenly. My code is by necessity a bit much less elegant, as I needed to do some funky {hardware} routing. I nonetheless tried to adapt the strategy Pete took to my design and wrote a helper perform that addresses the show as a pair of bytes, every little bit of which represents a section of the show.

If I used to be addressing the show the extra widespread approach, with every pin on the microcontroller going to at least one pin of the show, I may have used any of the numerous fantastic libraries folks have written to make use of shows like this, however since I charlieplexed the show into the buttons, I needed to write it from scratch. Scripting this perform was undoubtedly the toughest a part of the venture, because it requires changing the given bytes right into a sequence of pin states, with particular pins excessive, low, or high-Z, which the micro then steps by way of one by one to provide the phantasm that the entire show is lit within the desired configuration without delay.

[slow-mo video of annihilator with all segments on]

After plenty of different work implementing fundamental helper capabilities and the skeleton of the code, I obtained to my subsequent fascinating problem: shuffling the questions! That is principally notable as a result of I just like the algorithm I discovered to do it: the Knuth/Fisher-Yates shuffle algorithm. The good factor about this algorithm is that it shuffles the questions in place and as one goes, so there’s no prolonged shuffling course of initially, and it retains observe of which questions have already been requested. All one wants for a Fisher-Yates shuffle is an array containing all of the questions, and an index holding observe of the place one is within the array. It goes like this:

alt text

The Fisher-Yates algorithm runs in 0(N) time complexity. Picture:

Utilizing this algorithm, one not solely shuffles the questions shortly and with somewhat additional reminiscence, however one shuffles the questions as they go. This ended up being a lifesaver later within the venture when I discovered that the randomness accessible initially of the sport was virtually nonexistent.

That brings us to the subsequent hurdle: randomness. The commonest technique to seed the RNG of a venture like that is both from variations in timings and durations of consumer enter, or by polling a floating pin’s analog worth. On boot, the one choice accessible is to ballot a floating pin, however sadly this proved to be inadequate by itself. My answer was to ballot the floating pins in a loop till they modified, after which use the time that they modified to seed the RNG. This will get us a lot of the approach there, however simply to verify the shuffle is random, I reseed the RNG after every query with the time in microseconds that the final query was answered. Since this harvests randomness instantly from the consumer, it’s loads random sufficient for our functions, particularly because the shuffling algorithm picks a random query each time as a substitute of simply shuffling the questions initially.

With the {hardware} and the software program executed, the one factor left to do was play it — and it was wonderful! The tip product is enjoyable to play with, and has various ranges of issue to maintain gameplay recent! The one different factor I added was somewhat card that flips up from the again of the sport with an ASCII cheat sheet on one aspect and a dec-to-hex cheat sheet on the opposite.

One closing notice: other than truly soldering the factor collectively, all of the designing and programming for this venture was carried out on the hour-long bus commutes to and from work whereas balancing my laptop computer, the annihilator, and a multimeter on my lap. The event took round 2ish weeks, over which I attracted fairly just a few curious or involved glances from fellow bus patrons! A dialogue over lunch with Pete Lewis, the designer of the unique Binary Blaster, revealed that growth on public transportation is a typical theme with this venture, with the unique Binary Blaster having been largely coded on a flight to his honeymoon!

When making the ascii annihilator for the pictures right here, I took a timelapse. Get pleasure from!

The Binary Blaster Package, together with the Binary Blaster PCB, programmed ATMEGA328, and PTH Buzzer together with another supplies, is offered and able to be tinkered with!

SparkFun Binary Blaster Package

In inventory



Have you ever made any modifications to SparkFun merchandise for additional functionality? We would like to see! Shoot us a tweet @sparkfun, or tell us on Instagram, Fb or LinkedIn.



Please enter your comment!
Please enter your name here

Most Popular

Recent Comments