Spectrum Analyzer – Part III: Finally, the Software!

You can read parts 1 and 2 of the series here and here.

When we left off, we had a working spectrum analyzer … except, it didn’t do anything. Which is why this is the fun part.

Basically, all the code had to do was poll the radio module for the signal strength on each channel. This was fairly simple, especially with the radio functions at ea4eoz.ure.es . You can see the first revision of the code here:

Main sketch: http://codetidy.com/910/
LCD Header: http://codetidy.com/911/
Rssi library header (rssi.h): http://codetidy.com/912/
Rssi Library (rssi.cpp) : http://codetidy.com/913/

So I uploaded the code, and with a little tinkering, it worked! I walked around the house and was able to see my router, cordless phone, bluetooth speakers and wireless mouse all transmitting! I even saw a huge blip for the radiation from my microwave oven when I cooked some popcorn. Here is a video of the early hardware:

Now that the basic functionality was working, I decided to add some extra features, because a battery powered, handheld microcontroller with an LCD is a pretty powerful platform to make a neat little device. I wrote a quick ADC routine to make it act as a simple oscilloscope, and a multimeter. I then played around with some different ways of reacting to the signal, and got the idea from the radio site above to draw the highest recorded value for each channel, only increasing, and never decreasing. I left this on for around half an hour, and it gives a interesting picture of long-term spectrum use in the area. Lastly, I added a push button connected to one of the hardware interrupts on the Atmega, to switch between modes.

One of the reasons why I love prototyping with Arduino is the community. I posted about this project there, and got a lot of very, very clever suggestions from forum members that made the code much, much faster. Thanks especially to Rob and Chris for their input. These fixes aren’t implemented in the code above, but you can read about them here (just keep scrolling – there’s a bunch). http://arduino.cc/forum/index.php/topic,67218.0.html One optimization of my own which I made was changing the LCD logic voltage from 5 to 3 volts. While it says it can work at up to five, I noticed a significant improvement in speed drawing to the LCD with the change in levels.

Well, that just about concludes my spectrum analyzer series! If you have a questions or comments, don’t forget to comment or write me at thinkfortytwo at gmail dot com.

 

Spectrum Analyzer – Part II

You can read part 1 of this project here. So, at the end of the last post we established that we can use the radio module to scan all channels on the 2.4ghz band and have a basic spectrum analyzer, but how does it all get put together? Well, the only real requirement of the project is that it be able to communicate with the radio module (over SPI) and a display, I could go with just about any microcontroller (read: the chip that is the brain of the project). So, I turned to my favorite chip that I use for the vast majority of my projects: the Atmega328 (in case you have no idea what that is, my intro to microcontrollers is coming soon) , and so that I could easily share my project with a large community and prototype the code really quickly, I went with the Arduino bootloader. So now that we have the micro and the radio chip, we just need a display. I went with the Nokia 5110 LCD, a very cheap graphic LCD that uses SPI, the same interface as the radio module.

Nokia LCD

Now that I have all the necessary parts, there’s just one catch: the LCD and the radio module both communicate with 3 volt logic levels, and the Atmega uses 5 volt signaling. Since I didn’t want to fry either of them, I grabbed a few mosfets to bring the 5 volts down to 3 volts and vice versa. So an hour or so of painstaking breadboarding later, I was left with this:

Isn't it beautiful?

Time to turn it on! I wired it up to power, and… then came the magic blue smoke . I had wired the backlight LEDs of the LCD to 5 volts instead of 3. Oops! I fixed the wire at fault and powered it up to see a functioning (albeit dimmer) display.

One annoying dilemma I had was that the radio module’s pins are spaced 2mm apart, instead of the universally standard .1 inches. I mean, clearly whoever was designing the module just wanted to be inconvenient. So I came up with the following elegant solution:

I call it, Chip on Wire

With that done, I shifted it all over to a permanent circuit board, and ta-da! My only additions were 5 volt and 3 volt regulators and a button to switch between modes, which I will discuss in the third post, on software.

That’s my thumb!

And there you have it. My final post of the series will be (finally) about the software that runs the contraption. If any of the hardware-speak scared you, I promise, help is on the way! I’m working on an intro to embedded electronics which I will post soon. Until then, enjoy the spectrum analyzer!

2.4ghz Spectrum Analyzer – Keep an Eye on Your WiFi

(If you want to get a shorter summary of this build explanation, my project was written about here and here , and you can find my original post on the subject here )

Over the summer, I got bored. To be precise, I got bored a lot. One of the times I got bored, I pulled out my magic parts bin, and found this:

Oooh a circuit board!

Hey! A radio module! That’s neat. I can use that to send data wirelessly. One problem: I only had one of them. That would be one lonely (or schizophrenic) radio module, talking to itself all day. So, I turned to my good friend, the datasheet (a lengthy document that exists for just about everything electronic, detailing everything about it), for ideas. You’d be surprised how many cool things you can learn from those hopelessly long, boring, behemoths of seemingly useless information (also, they are a remarkable cure for even the most persistent of insomnias). And after some painful sorting through confusing diagrams, lo and behold, I found an idea! Now, I know you’re jumping out of your chair because you can’t wait to hear this idea, but I want to harness that excitement to give a quick disclaimer: I said this blog was about programming, and it is, amongst other things. However, some of my favourite things to program are things I’ve built myself, and well, I have to build them first. So if you’re terrified of embedded electronics, if you don’t even know what embedded electronics are, or if you’re already completely lost, hang tight. I’ll try to make the rest of this post fairly accessible, and I hope to have my introduction to embedded electronics post available soon.

Now: back to the thrilling saga of the lonely wireless module. Well, I learned two big things from the datasheet. First, the module operates in the 2.4ghz range, which is neat. What this means is that this chip is used to send and receive data along some of the same frequencies (think of them like stations on a TV or radio) that WiFi routers, cordless house phones, bluetooth, RC cars, cameras, and many other things transmit on. Relating to this, I found the second cool thing, which is that this module has digital RSSI (Received Signal Strength Indicator). Acronym-free translation: I can tell it to go to any channel (station) on the airwaves (in the 2.4 range), and it will give me the total power of everything transmitting on that station in the area. Boom! I had my project. If I could make it scan through all of those channels really quickly, and then display it, I can make a poor man’s spectrum analyzer, a tool used to give the user a detailed picture of all the wireless things operating in the area. Commercial grade, fast versions of these sell for anywhere between $50 and $1000.

Stay tuned for part two (hardware), and part three (software)!

Steganography (or, how to be a secret agent)

Encryption is boring. No matter how many bits of AES you have, or how big of a prime number is keeping your super-secret data (or lolcat photos) secure, it’s still obvious that you have something to hide. That’s why the ancient Greeks invented steganography, the practice of hiding one message inside another. (Of course, they were sending messages about rebellion – not nearly as important as lolcats). Since its invention, steganography has been used to conceal messages in everything from a tattoo on someone’s head to the yarn in a sweater. Of course, this is all very cumbersome and time-consuming. Now enter the computer. A whole new medium to send secret messages! (and look at cat photos). Digital data provides an excellent opportunity to hide messages, because what a user sees when he opens, say, a picture, is very different from how the data is stored (in o’s and 1′s), and we can use this to our advantage. We can now examine how a digital image can be used to conceal text, or even other files (Disclaimer: I only use this to show off to friends. Now, be a good person and don’t do anything illegal with your new secret-agent powers, please! As Google used to say, don’t be evil!)

A digital image is made up of pixels, thousands or millions of solid-color points that together form an image. And the color of each pixel is represented by four digital values (red, green, blue and alpha), each of which is a binary byte. Now, the neat thing about binary numbers is that, they’re…well, binary. Each digit can only be a zero or a one, and each digit’s value, or weight, increases  as you go right to left. This means that the rightmost digit (least significant bit – LSB) in a binary number can only change a number by 1. And since an unsigned byte has a maximum value of 255, changing the LSB of a pixel can only change the brightness of the color of that pixel by 1/256, or  less than .4%. Ta-da! We now have a perfect place to hide our message. Furthermore, a normal digital photo contains (600 x 800 pixels * 4) 1,920,000 such LSBs, it is possible to hide almost a 2MB file in a normal image, and here’s how:

Just as a picture is stored as binary data on a computer, so is everything else. So, if we take the image we want to hide our message in, and replace each LSB in each byte of the picture with a bit from the file we want to hide, we get an image that looks identical, but now conceals a secret file.  This can be done in virtually any programming language, and is a really neat way to learn about digital data and encoding. Plus, now you can hide pictures of lolcats inside other pictures of lolcats! (lolcatception).

Unfortunately, there are people out there who use steganography for evil purposes. Don’t be one of them.

Happy new year!

Hello world!

WordPress gave me a hello world post, so I’m going to use it.

If you didn’t know, hello world is a well established tradition in computer programming. Its a basic sanity check for whatever new platform you’ve just built. So here’s mine.

Hello world!

Or, as Mr. B. W. Kernighan put it in the first ever known use of hello world:

main( ) {
extrn a, b, c;
putchar(a); putchar(b); putchar(c); putchar('!*n');
}
a 'hell';
b 'o, w';
c 'orld';

There you have it. Not enough? This better be. And by the way, what’s with scientists using their initials? Save it for secret agents, really. I mean, B.W. is so boring! If I were him, I’d go by B-Dubs.

But thats just me. So, hello!

Tagged
Follow

Get every new post delivered to your Inbox.