Wednesday, April 2, 2014

555 Entropy and Robotic Teddy Bears

Recently I have been keeping busy with a few electronics projects, although it doesn't look like either of them will turn into anything. The first would transmit text wirelessly from a PC to a microcontroller to be displayed on an LCD. For this I planned to hack toy walkie talkies. This is not an ideal way to transfer text but I thought it would be fun to try different ways of making them work to start understanding wireless communication. Unfortunately, in my whole town I could only find one set of walkie talkies and one of them turned out not to work. The data being sent would not be especially sensitive but I still did not want to send it as plain text. This got me wondering about encryption, which I also have no experience with. There are many algorithms but I would need one very easy to compute since the microcontrollers involved would not be very powerful but would have to decrypt and transfer quickly. One solution that intrigued me was using a one time pad. Each microcontroller would have the same list of random numbers that would simply be added or XOR'ed with the data to encrypt and decrypt it. One time pad schemes have the advantage of being truly unbreakable as long as the numbers used are random and never repeated. A bigger advantage for me is that the microcontrollers could simply fetch the numbers from an SD card without having to compute anything. To get truly random numbers, though, I would need a hardware random number generator. These are a common project for hobbysts but not always easy to build correctly. One method uses a transistor in reverse breakdown mode but I decided against this because it requires 15 volts or more. Apparently the transistor also changes with age (perhaps due to being continuously run in a way it was not designed to be) and the characteristics of the numbers generated change too. Another interesting way I found was to measure the output of a 555 timer with a microcontroller ADC as shown here. This made me wonder if I could just measure the length of 555 pulses compared to the oscillator in a microcontroller to use clock drift as an entropy source. I connected a 555 running at 480Hz to the hardware counter of an MSP430 running at 16MHz to measure how many clock cycles each 555 cycle took and dumped 1,000,000 samples out over UART.

The generated numbers varied by about 30 and the least significant two bits were each 1 almost 50% of the time. From this I used the von Neumann extractor method with the least significant bit to generate what I hoped were purely random numbers and the bits in the generated bytes did all occur at almost the same rate. This is the limit of what I know how to test for. To know if the data is truly random I could test it with a program like Diehard but for that I would need 10MB of data. After an hour and a half I had produced only 30kB, meaning I would need a few weeks to get to 10MB. Increasing the 555 speed would help but still not be fast enough to get the few hundred megabytes I would need for the final project.

The next hurdle for this project would be an LCD. The Nokia 1202 LCDs are easy to find and use but at only 96 pixels wide I would not be able to fit enough text on them. Looking on the 43oh forums I found a library for a nice 320x240 LCD but it would be difficult to have them shipped here. No one seems to know what phone those kinds of LCDs come from so I don't know how to find one locally. Searching all the local stores did not turn up anything similar and neither did looking at every LCD for sale on several cell phone repair websites. It uses the ILI9340 controller but there does not seem to be a list anywhere of which phones use that controller. Until I get back to the US in June, there does not seem to be much of an alternative, so I will have to wait a few months to continue this project.

The other project I started working on was a teddy bear for my friend's birthday. My plan was to put the 20x4 LCD I used when I started on my RPN Calculator into the belly with an MSP430 to display text, control LEDs for the eyes and mouth, and play music. The LCD would display messages and tell jokes. One hand would have a button for Yes and the other a button for No to control the interface. The LEDs and backlight for the LCD are controlled by transistors and I was able to add some fade effects with PWM. The piezo is easy to drive using one of the hardware timers of the MSP430. Like with the RPN Calculator I had to generate a pulse to run the negative voltage generator but I did it with a timer and complimentary emitter pair. Before, I didn't want to do this because toggling the pin in an interrupt would be inconvenient, but with hardware PWM the chip can automatically toggle the pin without even needing to fire an interrupt. I got all of this working on a breadboard but my plans for the party changed, so it looks like I won't be finishing this project.

No comments:

Post a Comment