Today I'm going to have a bit of fun. Once again the local supermarket has released a set of cards with pictures of animals on them for children to collect. I've written about certain mathematical aspects of these promotions before.
This time they've added an extra feature to the cards, when swiped through an electronic device, that's also for sale, the sound of the animal on the card is played back for the collector. In this post I'll give a quick explanation of how the device works.
The cards come in a sealed pack of 4 so people can't pick and choose what ones they'll get, it's a random draw. They do however have a bar code printed on the back that allows the sound player to know what card it is, and what corresponding animal sound to play.
|Sealed Animal Collector Card Pack|
The device that reads the barcode from the card and plays the appropriate sound is a simple mass produced device that seems to be rugged and reasonably well built for a six dollar product.
I posted a rather quick teardown of the reader as soon as I bought it. It's not very detailed but it gives you an idea of how It works, and will make the rest of the details make more sense.
The internal construction is what you'd expect from a high volume low price device. I estimate that they probably had somewhere around 100,000 of these readers made, so it's no surprise to see a chip on board solution on a single sided PCB of medium quality. It comes with three no name AAA batteries. I haven't probed the board, but I can't see any voltage regulation. There's a bulk capacitor on the input and there could be a regulator under the black blob.
|Card Reader Construction|
The barcode on the card is sensed by an optical reader that's located on a separate board over the swiping slot. It's held in place by plastic studs that are melted once it's installed. The reader seems to consist of an infra red LED and an optical sensor like a photo-diode. As the card is drawn through the slot under the reader, the amount of light reflected from the barcode changes and can be detected. This is how the barcode is read and the reader know what sound to play.
|Active Optical Sensor|
The part I'm most interested in is the 8 pin SOIC package on the board. It appears to be a Macronix MX25L1605D 16 Mib flash memory IC and is the most likely place to store the sounds played by the device. I'm curious as to how the data is stored on it. There are 108 cards and each card seems to have a unique sound, this means that there are 155 kb for each sound. If we assume a worst case scenario of 4 bit audio (It's a pretty average speaker, any more bits and you'd be wasting them), that means there are about 38 k samples per audio clip. Clips last around 4 seconds so that would mean about 10 k samples per second. Due to Nyquist, this would limit the maximum frequency to 5 kHz. This is a possibility, but I'd really like to get the data off the chip and see for myself. While I'm there I'd also like to know if I could reprogram it and maybe put different audio on it. This post was originally going to be an attempt to do that, but the flash memory reader I ordered hasn't arrived yet. Oh well.
|Sound Card Reader/Player Circuit Board|
In the meantime, if you want to impress your friends (NOTE: if you think this will impress your friends you probably don't have any) you can show them how to read the barcodes on the back of the card to identify the number inside.
The barcode is simple binary and is made up of 13 bits. Each bit is made of a black bar and a white bar. If the bit is a one, the symbol will be a black bar 2 units wide followed by a white bar 1 unit wide. If the bit is a zero, the symbol will be a black bar 1 unit wide followed by a white bar 2 units wide. To put it simply, thin black bar = 0, wide black bar = 1.
After looking at a few cards it was obvious the last bit was always one. Those of you familiar with serial communication will be comfortable with me calling it a stop bit. I initially couldn't tell what the next two bits were, but it became clear that the rest of the code was the number of the card in binary. Once again drawing on my experience with serial communication I assumed that the two bits I didn't understand were parity bits. A pattern started to emerge, if there were an even number of wide black bars in the code these bits would be 01, if there were an odd number of wide black bars, the parity bits would be 10.
As some of the people reading this may not understand how to read binary, I've demonstrated in the image below how to easily read the code. Starting at the bar 4th from the right, put the number 1 under it. Under the bar 5th from the right, put the number 2, continue this pattern, doubling the number each time. i.e. 1, 2, 4, 8, 16, 32, 64, 128, 256, 1024. Once this is done you add the numbers under the wide bars together to get the number of the card.
|Decoding the bar code on the cards|
I've also included an ODS Spreadsheet you can use to generate your own barcodes. Just change the number in the left column and the barcode will automatically generate for that number.