nunchuck_stereo_control_joystick_w_freq_gen_0.bas (14044Bytes)
Preface: No, this is not a robot. But either I document this project here or on my turf & soil blog. This seems like a better choice. And yes, I use a lot of words. If you want to skip to the good (or at least better) stuff, watch the second video.
I wanted to learn more about some communication protocols and decided that interfacing a Wii nunchuck ("wiichuck") to a Picaxe would be an easy way to try out the I2C commands. I ordered a wiichuck adapter and some 3.3V regulators then borrowed one of the wiichucks from the gameroom (it's not needed to watch Netflix anyway). With the all-knowing internet as my guide, communication between the wiichuck and Picaxe was readily established and suddenly a 2-axis joystick, a 3-axis accelerometer and two buttons were at my disposal. (I didn't even know the nunchuck HAD two buttons.) But now that I had an input device, what to control?
I decided to make a stereo volume controller. This would give me a little experience bit-banging data to a 3-wire serial device. I promptly smoked a couple of PGA2311 Stereo Volume Control chips using my ancient dual-voltage supply and decided to re-think my design. I though back over the many great educators from my youth and asked myself: "Self, what would Forrest Mims III recommend?".
I don't really know what Mr. Mims would do, but I decided to go with simple LM386 audio amplifier circuits - one each for left and right. The 10-kΩ potentiometer that is usually suggested for volume control with the 386 was replaced by a digital potentiometer - the MCP42010 256 Step SPI 10kOhm Digital Potentiometer IC. The MCP42010 has dual potentiometers - one can be used for each of the two stereo channels. For reasons that I no longer recall, I didn't use the shiftout/spiout commands that look to be available for the Picaxe 18M2 - instead I used the manual bit-bang methods introduced in the Picaxe Manual Part 2. Either I had a good reason and have forgotten it, or I wasn't paying attention. At any rate, I mostly understand the process now.
When looking for information on digital potentiometers, I came across this blog with a similar solution for stereo control (though with different chips) and also this writeup on connecting a MCP42XXX device with a Picaxe. These might be useful background information for anyone looking to implement a similar solution.
Although the stereo pre-amp has a stereo input jack to connect to an MP3 player or other device, I wanted to use the Picaxe as a tone generator as well. I wanted to control the tone frequency from the wiichuck joystick, and I wanted the tone to sound continuously rather than for specified note durations and also to continue sounding while the volume was adjusted or other Picaxe commands were issued. The "sound" command native to the Picaxe fails on both counts, so I used the "pwmout" command to generate an output signal into a low-pass filter that was then fed into the 386 pre-am circuit (both channels).
Now why would I want to do all of this work? To control fire, of course.
A few months ago I built a Reubens Tube after scanning MAKE Magazine at the store one day. Basically sound is used to excite resonant frequencies inside a burner manifold and the flame height along the manifold reflects the nodes and antinodes inside the tube. There are many, many videos and writeups of these devices and I won't duplicate another explanation of the physics here.
Many examples of Reubens tubes have a single speaker, but since I had a stereo controller, I thought I'd try to drive the resonances from both end of the tube simultaneously. There is a possibility that this can cause destructive interference, so I added a DPDT switch on one speaker to swap polarity as needed. This is a simple way to affect a 180-deg phase-shift of the audio signal on one end of the tube - in theory. For the stereo version of the Reubens Tube, I used 8-Ω, 3W 40mm full-range speakers from All Electronics - I think JAX recommended them to someone on the ShoutBox one day. Finally - just to give a little extra-umpf to the signal, I ran the output from the 386 pre-amp circuits into a 10x10 watt stereo amplifier (Kit 88 from KitsRUs).
The performance of this setup with the Reubens Tube isn't as good as previous implementations I've tried using other speakers, amplifiers and tone generators. The resonances aren't as clear in the flame patterns - especially at higher frequencies. The PWM signal and a simple passive filter don't provide a very clean sinusoid, and I know I have noise in the amplifier ground along with plenty of other issues. But I get to use a wiimote to control fire, so that's cool. And it all works well enough to move on to a new project - which will probably have nothing to do with any of this.
So what did I learn or re-learn from this little exercise: I2C communication, bit-banging, SPI timing diagrams, Picaxe internal clock conflicts, PWM signals, audio filters, not being afraid to just stick a capacitor across the leads to see what happens, and sometimes it's only the 3rd band on the resistor than's important.
I also learned I suck at video presentations - and you're the one who suffers. For that I am indeed sorry.
https://www.youtube.com/watch?v=A5erOhxVfWM