Tag Archive: Bluetooth

Bluetooth Media Remote

It is finally finished. My Bluetooth Media Remote!

With each module* working as it should, I set out to build it onto my breadboard. Just to make sure that it works together.

*See previous posts for each module and how they work.

The final Micro-controller I decided to use on the final product was a ATMEGA8. In the first post I used an ATMEGA8515. For several reasons I decided not to use this one in the final product. Firstly, it’s a 40 pin package. I do not need that many I/O lines. It draws more power. And finally, I need that one for my studies at uni. So an ATMEGA8 was used.

Here, I noticed a slight problem…
The buttons double press sometimes. Thus sending the data twice. I think this is a limitation of the tactile switches I am using. I’m not quite sure. Later on I might write some code to only allow the data to transmit after a certain amount of time has passed using a timer interrupt on the ATMEGA8. This is for future work though.

From here, I built it on a set of prototype boards. Modular of course. In hind sight this wasn’t a very good idea, because I still hadn’t decided what I was going to enclose it in, but I was excited to build it. And build it I did.

Ahh. Its working on the prototype boards..

Now, the problem that faces every hacker, what to build it in? It’s gotta be classy, something on hand, and easy to put together.

Thanks to a brilliant idea from my mate, Damo, I thought “Why not in one of my broken Xbox controllers?”

After pulling it apart and trying to jiggle the circuits into it, I decided it just wasn’t feasible.

Back to square one.

Then, like a ray of sunshine, I remember I had a broken N64 controller as well. Thus the decision was made. It’s classy, it’s on hand. Easy of assembly went out the window when I realised how awesome it would be to use nostalgia to control my music.

After rebuilding the circuits onto new prototype boards (about the 5th time I had built the same circuit), I attacked the controller with a jigsaw blade and the file on my pocket knife. Not the best tools, but what I had on hand.
And so the N64 Media Remote was born…

And a video just to prove it works…

For those interested. The source code for the remote. The polling of the buttons is not quite neat, but it works.

I might implement an external interrupt to activate the polling, but at the moment, it’s not needed. Even the interrupt polling double transmits.

And thus the project is complete. Any questions, don’t hesitate to ask!

Later on I might get a full circuit diagram. If someone requests it I’ll make it a priority, but until then it’s on the back burner. Uni work has suffered enough…

Onto my next project! A set of analogue panel meters to monitor my CPU and RAM usage with data logged to an SD card. Stay tuned!

EDIT: Debounced the buttons. Thanks for the idea Matthew Wiebe and BohemianHacks! Here’s the updated source code

If you are a faithful reader, you might remember way back to my first post, my server. Now. That server was based on VB 6.0 and, honestly, a really really bad piece of code. So. I decided to completely re-write it in Python script.
Handy little thing python. Cross platform, easy flow control. The moment I got that server working, I knew that this was the way to do it.
To gain serial port control and the ability to import Media Monkey I had to install a couple of other libraries. Pyserial and pywin32.

Source code.

It basically waits for a connection on a specific port. Once it has gotten it, it will poll the serial port for new data and check if the current playing song has changed. When it receives data, it will act correspondingly.
As you can see I have set an escape case, the character “e”. This allows the server to close the connection and wait for a new connection. This allows us to shut down the remote without having the server still listening on the port. If the remote is turned off and then on again without sending the escape character, the remote will not reconnect to the server because the serial port is already open.

All in all, a handy little script that can be modified for any serial comms and Windows interaction.

Next, the final product! Excited? I am.

On to the next module. I had been thinking for a few weeks, what kind of wireless will I use for my remote. Some options include:

  • Xbee modules with a base station connected to computer.
  • One way transmitter connected to base station and a one way receiver connected to remote.
  • Direct Bluetooth connection.

Now, each has its pros and cons.

The Xbee modules are frikken expensive. Add onto that the price of building a base station with another Micro-controller and USART->serial converters. On the up side, I would have AMAZING range for my remote.

The one way transmitters and receivers are cheap. Really cheap. Again though, I would have to build a base station with a USART->serial converters. Also, I cannot guarantee the range or effectiveness of the cheap wireless modules.

The Bluetooth modules can be found cheaply, easy to use and have no need for a base station. The range though, can be rather small, depending on the module chosen.

Taking all this into account, I chose the Bluetooth solution. I found a nice cheap Bluetooth device on eBay, based on the CSR (Cambridge Silicon Radio) chip. It all came on a breakout board for me too! Nice and easy to incorporate into the micro-controller using a USART connection. This also means I don’t need to modify any of my code from Module #1! How good’s that?

It works!
Now pair it with the computer and create a virtual COM port! For those who get the same device, take note that the PIN for these devices is 1234.

If you noticed, it’s name is “WIDE_HK”. What a boring name. This is the name of the people who made the breakout board. Now, I want  to change this. So we need to do some AT commands. TO do this, we need to connect the Bluetooth to the computer via the serial port. Take note, this is NOT via the Bluetooth wireless protocol, but through a USART->Serial converter and into the data lines on the Bluetooth chip. We also need to drive a line on the board high. This line is Pin 11, some soldering to tack a new line on at that point of the chip is required. Drive that to 5V, power it up and connect to it using putty with a baud rate of 38400. Here, we type in the AT commands. For a full list of AT commands, check the data sheet, but to change the name use this one.


This should return “OK”. And you are set!

Turn off the Bluetooth module, disconnect the line on pin 11. There we go! All ready to use!

Thanks to Hack a Day, specifically this post, I discovered a good way to extend the range of my Bluetooth device! Tack an old router antenna onto the aerial onto it! It’s the same frequency, 2.4GHz, so it is the right length for a proper antenna. Using this I get range of maybe 10m through walls. Without it I was lucky to get 2-3m. Thus the disadvantages of buying cheap modules and a cheap Bluetooth dongle for my computer.

Next module is the button switch bank.