ASCII Annihilator – Information – SparkFun Electronics

Certainly one of my favourite SparkFun merchandise is the Binary Blaster. It’s a beautiful little soldering package, which, when accomplished, is a enjoyable sport to assist the consumer follow changing from decimal and hex to binary! I picked one up and had enjoyable placing it collectively and enjoying it, however discovered that reasonably rapidly I mastered each sport modes and needed extra of a problem!

Introducing the ASCII Annihilator (Asc Blaster for brief)! Primarily based on the board for the Binary Blaster, this mod provides a further sport mode, a 4 character alphanumeric show, and may quiz you on a big swath of binary, hexadecimal, and even ASCII! You may even combine and match sport modes and difficulties by holding totally different combos 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. Should you really feel as much as the duty, you should purchase a binary blaster, no matter colour show you need, head on over to the github web page, and observe the directions! First although, lemme sit ya down and stroll ya by the design!
The binary blaster solely has 4 lit buttons on it, simply sufficient to enter a binary ‘nibble’. That solely means that you can 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 noticed that with an additional change, one might toggle the lit buttons between two nibbles, sufficient for a full byte! I rapidly 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 need to be rewritten)
The inventory blaster can solely quiz as much as 15, however with a nibble change, it may go as much as 99!This was enjoyable for some time longer, however after a while I began to be aggravated that whereas I might enter as much as 255 on the buttons, the show might nonetheless solely present as much as 99 in decimal. Plus, a full byte can be utilized for extra than simply numbers! ASCII, easy colour 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’d 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 a couple of methods to get round this, the best of which might be to maintain the Qwiic driver board on the show and speak to it over I2C. That method, nonetheless, appeared sophisticated and boring. The strategy I settled on was much more sophisticated, however a lot much less boring: charlieplexing!
Charlieplexing is a very cool technique of multiplexing that takes benefit of two information:
-
Diodes will solely enable present to circulation a method.
-
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 only purchase a chip that does the muxing for you than to purchase a diode for every of your outputs. Nonetheless on this case the show and lit buttons all use LEDs anyway, so we get these diodes totally free!
The following step was format; I needed to maintain the {hardware} modifications so simple as potential. This meant minimizing the quantity and size of jumpers to make it compact and simple to do. This half was actually enjoyable! I printed off some photographs of the PCB format and doodled on them with a pen till I’d found out one of the simplest ways to change the board.
With the {hardware} modifications all executed, it was time to maneuver on to programming! I might have modified the Binary Blaster code (that’s what open supply is for, after all!), however I actually needed 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. Notably, the unique Binary Blaster’s show implementation was fantastic, assigning all the show pins to sequential pins within the microcontroller’s registers. This permits one to simply set a given show state just by writing a byte on to the registers abruptly. 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 method Pete took to my design and wrote a helper operate 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 1 pin of the show, I might have used any of the various 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 operate was undoubtedly the toughest a part of the challenge, 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 separately to present the phantasm that the entire show is lit within the desired configuration directly.
After a variety of different work implementing primary helper capabilities and the skeleton of the code, I received 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 originally, and it retains monitor 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 preserving monitor of the place one is within the array. It goes like this:
The Fisher-Yates algorithm runs in 0(N) time complexity. Picture: sebhastian.com
Utilizing this algorithm, one not solely shuffles the questions rapidly and with just a little additional reminiscence, however one shuffles the questions as they go. This ended up being a lifesaver later within the challenge when I discovered that the randomness accessible originally of the sport was nearly nonexistent.
That brings us to the subsequent hurdle: randomness. The commonest solution to seed the RNG of a challenge 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 possibility 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 many 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 immediately from the consumer, it’s lots random sufficient for our functions, particularly because the shuffling algorithm picks a random query each time as an alternative of simply shuffling the questions originally.
With the {hardware} and the software program executed, the one factor left to do was play it — and it was wonderful! The top product is enjoyable to play with, and has various ranges of issue to maintain gameplay contemporary! The one different factor I added was just a little 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 last be aware: other than truly soldering the factor collectively, all of the designing and programming for this challenge 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 a couple of curious or involved glances from fellow bus patrons! A dialogue over lunch with Pete Lewis, the designer of the unique Binary Blaster, revealed that improvement on public transportation is a typical theme with this challenge, with the unique Binary Blaster having been largely coded on a flight to his honeymoon!
Moreover, I took a timelapse of the development of an ascii annihilator, head on over to twitter to test it out:
Need to see a SparkFun modification challenge? Funion Juno made some adjustments to our Binary Blaster to extend performance and increase gameplay! #sparkfun #electronics pic.twitter.com/grKcs4nA52
— SparkFun Electronics (@sparkfun) November 2, 2022
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!
Have you ever made any modifications to SparkFun merchandise for additional functionality? We might like to see! Shoot us a tweet @sparkfun, or tell us on Instagram, Fb or LinkedIn.