Introduction: Bluetooth Wireless Voltage Meter Using Wiimote + Pic Chip + AutoIt
In this tutorial I'm going to be showing you how you can send voltage values to your pc using a Pic chip, Wiimote, and Autoit3 scripting language. The process works by wiring a pic chip to the button pads of a wiimote. Then using the pic chips Analog to Digital Converter, we obtain a 10bit binary value. We will then send that value to Autoit in the form of button presses using the wiimote as a data interface. On the PC side we will use a library I wrote to receive the data from the wiimote. The library is basically just a port to Wiiuse by Michael Laforest set up in a way to make scripting with the wiimote very easy.
Most pic chips are equiped with multiple Analog to Digital channels. This lets us monitor multiple voltages values if we want to. The total amount of channels sampled will depend on different factors like how many channels the chip has. Channels are sampled one at a time so the more voltages you monitor, the less samples per second you get.
How the Analog to Digital Converter works
The pic chip A/D Converter works by comparing the voltage you're measuring to a known voltage. In our case the known voltage is the voltage supply 5v. The 10bit value measured is a ratio of the pic chips known voltage 10bit value. So for example a sample thats 10bit value is 387, the voltage value would be V = (5v/1024) * 387 which equals 1.89v
Step 1: Experience, Tools and Parts Needed
• Basic understanding of electronics. (Ohms law for example..)
• How to use a bread board and voltage meter.
• How to solder.
• A little knowledge of pic chips will help, but is not really required since all the pic chip code for the examples is already written.
• Triwing Screwdriver for wimote. ($2 on ebay)
• Soldering Iron, solder
• Breadboard and Jumper wires
• Pic Chip Programmer (Im using the “Enhanced PICKit 2”)
• PC with Bluetooth
Parts: ($20 + $1 + $1 + $5 + $7) = $34
• Wiimote - note that while generic wiimotes will work, a genuine wiimote has best compatibility. (< $20)
• Transistors 2N3904 or any General Purpose NPN Qt: 11 ($1)
• Resistor values 470K (390K to 560K will work): Qt: 11 ($1)
• Pic Chips (any of these will work since I have included multiple examples)
- PIC12F683-I/Por PIC12F675-I/P – 2 examples ($1.25)x2
- PIC16F616-I/P - - 2 examples - ($1.10)x2
- shipping for all 4 pic chips ($7)
• 5v supply for the Pic Chip
Step 2: Software
Download and install the following software: (click links to download)
• HI-TECH C Compiler for PIC10/12/16 MCUs(Free Lite Version. Registration is required)
• Wiimote ADC.zip(Note: The html link is just an easy way for me to share, update, and track downloads. Open the .html file and a download dialog will display.)
The Wiimote_ADC.zip contains the following:
• WiimoteMT.au3 - Autoit Library used for communicating with the wiimote.
• Wii Pair.exe - used to pair the wiimote to your pc.
• ScitePIC Startup.exe - A custom standalone Scite Editor that I set up just for working with the pic chips. It has options to compile and program the pic chip for you. I will get into how to use those options later.
• 6 AutoIt script examples along with the Pic chip code that goes with each example.
• 4 Pic chip Hi-Tech C example programs. (2 supporting 12F683 and 12F675, 2 supporting 16f616.
Step 3: Pairing the Wiimote
To pair the wiimote to your pc you have two choices. You can either do a temporary pair, or you can do a permanent authenticated pair. The difference between temporary and permanent pairing is that if you power off, or disconnect the wiimote from your pc and the wiimote is not authenticated, the next time you want to connect you will have to do the pairing procedure again. If it is authenticated, your pc will remember the wiimote, and the wiimote will remember your pc. Needless to say i recommend doing a permanent pair.
-Launch Wii Pair.exe (located in Wiimote_ADC.zip)
-Press the sync button on the wiimote located under the battery cover. The leds on wiimote will begin flashing.
-Press Easy Pair button.
- When the wiimote has been successfully paired you will see the address of your wiimote in the list and Connected, Remembered and Authenticated will all say true. Once it has verified that the wiimote is authenticated it will launch a wiimote example.
- NOTE: IF at any time during the pairing process the wiimotes leds stop flashing, PRESS THE SYNC BUTTON AGAIN.
-Go into your bluetooth panel and select "add a new device". Press the sync button. When it asks you about the pairing code, select the option to pair without using a code.
Step 4: Programming the Pic Chip
As mentioned in the intro, the .zip file contains a custom Scite Editor with options to compile and program the pic chip. Use the file ScitePIC Startup.exe to launch the editor. This small startup app is important as it makes sure this standalone editor does not interfere with the other scite version (for autoit) installed.
To use the compile and program options is very simple. If you want it compile your pic program place the comment //picwrapper= and whatever chip you are using somewhere in the script. To have it program your chip, add comment //pk2cmd=y somewhere in your code.
Both options are already written in all the code examples, just make sure the chip is the one you're using. Open what ever example you are going to do and Press F7 or select Build under the Tools menu. This will compile the example and program the chip.
One thing that you are going to want to adjust is the delay time between the button presses. A button must be pressed for so many milliseconds before the wiimote will register it as an actual button press. How many milliseconds will vary for different wiimotes. I have two of these set up and one of them I'm able to get the delaytime as low as 7ms before I start getting too many errors. On the other one I need to keep it at about 17ms. Big difference. All the examples print the statistics to the console window every 5 seconds which includes how many samples have been received vs how many samples were corrupt.
Step 5: Soldering Connections
Each button on the wiimote is a simple push button that when pressed, creates a path between two pads allowing the current to flow. The current travels out of one pad and in to the other. We need to figure out which pad is out and which is in . To do this, use your volt meter to measure the voltage on each pad. One side should be about 3v, the other will be very, very low, but not 0v. 0v is ground and none of the button pads go to ground.
The collector pin will go to the high voltage pad and the emitter pin to the other. The Base pin connects to the 470k resistor that then goes to the pic chip. How you wire it up is up to you. I find that while it might look a little sloppy, soldering the transistors and resistors straight to the wiimote lets your bread board have way less wires going on and helps keep the wiring very clear. And way less moving wires around if you try doing it with different Pic chips. Doing it this way Pin “*” goes straight to Button “*”. Simple.
Step 6: Running Examples
To run the examples I set up, open them up using Scite4Autoit3. Each example will have a connections section in the header that states which pins go to which buttons and which pins are your analog inputs. Connect all the connections on your bread board. Once you have made sure each pin is connected to the correct button, power up the pic chip and then launch the Autoit script by pressing F5 in Scite4Autoit.
If I left something out or you have problems drop me a line and I will look into it as soon as I can.