Last entry: 2012-09-11 20:41
38 entries written
446 comments have been made
36 visitor(s) this month
1 visitor(s) today
6 visitor(s) online
Saturday, March 31. 2012
Interfacing with radio controlled ... Posted by Fanjita in Arduino at 22:39
My last post discussed receiving and decoding signals from the Maplin socket controller. Here, I'll describe how I went the opposite way - faking the signal to control the sockets directly with an Arduino.
As it turned out, this was a lot simpler than receiving. For one thing, the transmitter module is just 4 pins rather than 8, and can be directly driven from the Arduino with no further components. For another, I already had a representation of what the signal needed to look like - I just had to drive the transmitter input pin with the right timings.
So, here's some trivial code to do just that - it turns channel 3, ID 2 on for 3 seconds, then off for 10 seconds, repeatedly. The transmitter module plugs directly into analogue pins A3-A5, as shown in the photo. The antenna pin is left unconnected for the time being - in practice, you'd probably want to connect a suitable antenna (or just a short piece of wire, as per the data sheet) to get optimal range.Continue reading "Interfacing with radio controlled mains sockets - part 2"
Thursday, March 29. 2012
Interfacing with radio controlled ... Posted by Fanjita in Arduino at 22:17
Maplin have recently had special offers on remote-controlled mains sockets - as cheap as £5 for a socket and controller pair. Since the control frequency is on the standard 433MHz band, and I had a pair of Arduino-friendly 433MHz transmitter/receiver modules lying around, I thought I'd have a play to see if the control protocol can easily be reverse-engineered for use with the Arduino.
So, I dutifully hooked the receiver module up to 5V and an oscilloscope, and started pressing buttons on the controller. Things looked promising - a simple ASK pulse train, probably Manchester encoded.
Continue reading "Interfacing with radio controlled mains sockets - part 1"
A single data packet. Not shown is the leading low pulse between each packet - approx 13ms.
Monday, March 5. 2012
A slight sidetrack from Arduino stuff, but a friend asked me to write up how I did this - so here it is.
At the weekend, I helped my son build a "junkbot" - a little moving toy, built from odds and ends, and intended to look like a robot. It was inspired by this post on Hack-A-Day, plus Frankie's delight whenever I "invent" something for him.
The gist is really straightforward : stick a vibration motor on top of a base, add a coin cell for a power source, and whatever extra ornamentation you feel like. The spirit is to hack something together out of old junk you have lying around. The "robot" jiggles around due to the vibrations, and moves in random motions. It's pretty cool for such a simple little thing. Continue reading "Making a junkbot"
Sunday, February 26. 2012
Twinkle Twinkle Little Star Posted by Fanjita in Arduino at 12:54
I posted previously about a cool ATTiny project by ELM, which implemented wave table synthesis. After playing with that, I decided that at some point I'd like to take it a little further. That point came last night.
My kids' favourite tune is Twinkle Twinkle Little Star, and we usually sing it at bedtime. I recently picked up a cheap moon-shaped wall-mounted night light from Homebase for £5 (no link, sorry - it doesn't seem to be on their website. Also available from B&Q, but again, nothing on the website), and it's pretty useless in its standard form - the batteries last for no time at all, because it uses an incandescent light bulb. So I decided to put it to better use, and convert it to LED lighting, and to put in a music box version of Twinkle Twinkle at the same time.Continue reading "Twinkle Twinkle Little Star"
Monday, February 13. 2012
When I last looked at my musical instrument tuner, I was having difficulty with real-world waveforms from the instrument : all the harmonics meant that zero-crossing analysis wasn't accurate for capturing the fundamental frequency.
This post describes my approach to solving that problem in the analogue domain - so that I don't need to worry about fast A to D conversion (although that would be an interesting problem in itself).
The standard approach is to implement a low-pass filter, with the stop frequency tuned around the desired fundamental, to get rid of those troublesome harmonics. A passive filter would only achieve 6dB/octave roll-off, which is unlikely to be enough. And you can't sensibly cascade passive filters to improve that. Time to roll out the op-amps, and implement active filters, which are easily cascadable, and in the simplest form, are usually 2nd order so 12dB/octave. Cascading two of those together should give 24dB/octave, which should be plenty of attenuation. Continue reading "Instrument Tuner - Programmable Filter"
Wednesday, February 8. 2012
SPI addressing with minimal pins Posted by Fanjita in Arduino at 23:17
I picked up some digital potentiometers, partly as a building block for making a programmable filter for the ukulele tuner, but also just to play around with, as they seem pretty cool.
They act exactly like a traditional potentiometer (i.e. there's an end-to-end resistance of 10KΩ, with a 'wiper' that can travel from one end of the resistance to the other), but the position of the wiper can be controlled via digital signals. It seems that they do actually use physical resistors internally, in some fancy switched network. Anyway, these can normally be used to generate a variable voltage, but I'm also interested in being able to dynamically change resistance in order to tune a filter.
Originally, I assumed these would be an I2C interface (previous models I'd seen were), and didn't pay too much attention to the datasheet. I2C is great, because you can use 2 pins to control a whole string of devices, so long as they all have unique addresses. But it turns out that they're actually SPI, which is not so good for small microcontrollers, as even in its minimal form, it uses 3 wires per slave device. I'd ideally like to control 4 digital potentiometers with a single ATTiny85 - with just 5 data pins available (6 if I don't care about being able to reprogram more than once).
So - is it possible to control 4 or more SPI devices, using a single ATTiny85? Yeah, of course it is - with a bit of jiggery-pokery. Continue reading "SPI addressing with minimal pins"
Sunday, February 5. 2012
More ICSP laziness : the Frankentiny Posted by Fanjita in Arduino at 00:13
It's all well and good being able to place an ATTiny in my universal ZIF ICSP board, flash it, and then put it back in the circuit being prototyped. But wouldn't it be better to be able to flash it in place, without all that tedious plugging and unplugging from sockets?
Well, I could add a 6-pin ICSP header to all my projects, which would make that possible. But it's a bit of a pain to do that, and once the project is complete, that header will never be used again. Seems like a waste.
And so, partly inspired by a post at JeeLabs (although I'd independently been thinking along the same lines), I came up with a different approach - the Frankentiny.
The principle is to create a small daughter board, comprising an 8 pin socket, and ICSP header, which can plug into another 8 pin socket. This way, I can plug the ATTiny under development into the Frankentiny board, and plug that board into the socket in the circuit being developed. When I need to reflash, I just disconnect the power, connect the ICSP cable, and click "upload". As far as the prototype circuit is concerned, this board indistinguishable from an ATTiny.
This takes a little bit of caution to make sure that there are no delicate components connected to the ATTiny pins used by ICSP, but that's not much to ask in return for the convenience.
Here's a picture of the ugly beast:
Saturday, February 4. 2012
Duplo traffic lights Posted by Fanjita in Arduino at 23:57
[UPDATE: And overnight, it was chosen to be featured as an Editor's Pick! I'm delighted.]
I just published my first ever Instructable, after being inspired by following their channel on Flipboard for the last couple of months.
Here it is : How to build your own Duplo traffic lights, using an ATTiny, switch, 3 LEDs and a few bits of Lego.
Thursday, February 2. 2012
Even lazier ICSP programming Posted by Fanjita in Arduino at 23:00
The previous post discussed my gradual drift to using a dedicated ICSP programmer to reflash AVR chips. This post describes how to make useful ICSP slave boards, to make life easier yet.
First up, some pinouts. I'm mostly interested in the 6-pin ICSP header, and the ATTiny85 (absolutely tiny, not many I/O pins), ATTiny2313 (a bit bigger, tiny memory, but built-in UART and more I/O pins), and ATmega328 (as used in Arduino). These are all drawn on a Mac in "Shapes", by the way. Another experiment, and it seems OK for basic diagrams, if a little buggy. £2.99 from the App Store.
I've only marked the pins that are important for ICSP. Connecting one of these up to an ICSP header is trivial - just connect the corresponding pin labels together between the ICSP header, and an IC socket. Notes:
Ah - but see how a lot of the pins are all in roughly the same place and order? Well, I wondered if you could connect up a single socket in such a way that it can be used to program any of these 3 chips? Luckily, we can! Continue reading "Even lazier ICSP programming"
Thursday, February 2. 2012
Making it easy to program an ATTiny Posted by Fanjita in Arduino at 22:15
Larry Wall once said that laziness is one of the 3 main virtues of a programmer. I guess that makes me a great programmer... Anyway, this post describes my ongoing quest to make programming an ATTiny as painless as possible, something that I seem strangely driven to achieve.
First, a note of explanation of the technique behind all of this. AVR chips include functionality called In Circuit System Programming (or ICSP, sometimes shortened to ISP). In essence, this allows the non-volatile memory on the chip to be reprogrammed at any time, even when it's already embedded in a circuit. ICSP works by holding the /RESET line low, which disables the normal operation of the chip, and then manipulating some special data lines to effectively communicate with an in-built primitive bootloader. AVR sell a number of programmer boards that implement ICSP, but they can be quite pricey (~ £50). All modern Arduino boards include a 6-pin ICSP header, clearly labelled, which allows your Arduino to be reflashed in situ, if you have such a programmer. To avoid confusion, I'm going to refer to the device that is generating ICSP control signals as the ICSP master, and the device being programmed as the ICSP slave.
The cheapest way to start programming any AVR chip, assuming that you have an Arduino already, is to use the Arduino as an ICSP master, using a sketch that simulates one of AVR's branded boards. This is all documented very well here.
Important note: The ArduinoISP sketch delivered with Ardunio 1.0 is broken. The easiest solution is to install Arduino 022 alongside your 1.0 installation, and follow those instructions (rather than the 1.0 instructions on the same site).
That works pretty well, but there are drawbacks:
Surely we can do better than this... Continue reading "Making it easy to program an ATTiny"
Tuesday, January 31. 2012
Automatic USB disconnector Posted by Fanjita in Arduino at 23:30
I use a Linux box with a cheap (but extended-range) bluetooth dongle to monitor the invertor for my solar panels, and also my central heating monitor. This is fine, except that occasionally the bluetooth dongle seems to crash, and it needs to be physically unplugged to recover. Since there doesn't seem to be any comprehensive way to do this through software (you can reset the device, but it doesn't perform a power interruption so doesn't recover it sufficiently), I decided to make a little hardware dongle to do it for me.
The design is extremely simple - just use an ATTiny to periodically (perhaps once a day) interrupt the 5V USB line. All other USB lines (data +/-, GND) pass straight through. Rather than power the attached device directly from an ATTiny I/O pin (which can only source ~40mA) I drive the attached device's power line through a PNP transistor (in this case rated at ~ 200mA, which is enough for my purposes, but 500mA would be needed for general purpose USB loads). Continue reading "Automatic USB disconnector"
Monday, January 30. 2012
Wavetable synthesis with an ATTiny45/85 Posted by Fanjita in Arduino at 23:20
Here's something to aspire to - being able to wring miracles out of the ATTiny as well as this guy: Electronic Lives Manufacturing.
Using just an ATTiny45 and a loudspeaker, he's able to produce a full, polyphonic musical box using wavetable synthesis, capable of playing tunes with over 300 notes. It's a far cry from those musical greetings cards inserts, which are usually just monophonic square wave tone generators and a piezo transducer.
To achieve the necessary speed and compactness (just 4KB of flash space), it's all written in AVR assembler. I'm not sure I've got time, or room in my head, to learn yet another assembler instruction set, but this is certainly some pretty serious inspiration to get the most of these amazing little chips.
Given that I've got ATTiny85s, with double the flash space, I'd quite like to tinker and add some simple extra functionality to this (e.g. deep sleep mode, playing one cycle of the tune for each press of the reset button; and my own choice of tune) but that might have to wait a while.
Sunday, January 29. 2012
Instrument Tuner - Zero Crossing ... Posted by Fanjita in Arduino at 00:30
Having captured audio over a microphone, and converted to a voltage suitable for the Arduino ADC, the next challenge is capturing the analogue data and converting it into an estimation of the frequency of the current note being heard. That's a fairly tricky problem, as it turns out.
Firstly, the default Arduino analogRead() function is way too slow. At 100 microseconds per read, that's a maximum sample rate of 10kHz - and even that is only possible when tight-looping doing reads, and nothing else. According to Nyquist's theorem, at a bare minimum I need to be able to sample at at least twice the highest note's fundamental frequency, which is probably going to be about 1kHz, so double up to 2kHz. I'd ideally like to sample at least 5-6 times the highest fundamental, and calculating the incoming frequency requires some maths too. So, I decided to look into alternative approaches.
A naive approach to frequency counting is to count zero-crossings in a given direction - i.e. observe the waveform, and everytime it goes from negative to positive, increment a counter. Counting the number of crossings in a given time directly gives you the frequency. It turns out that both the ATTiny85 and the ATmega328 (Arduino) chips both contain an analogue comparator, hooked up in such a way that zero crossing counting can be done extremely efficiently. Continue reading "Instrument Tuner - Zero Crossing analysis"
Saturday, January 28. 2012
Instrument Tuner - Audio Input Stage Posted by Fanjita in Arduino at 00:36
I've been experimenting with creating some sort of instrument tuning helper device, as it seemed like a good mix of analog and digital, as well as a useful thing to have around the house after the arrival of a Ukulele shortly after Christmas.
More on the trials and tribulations at the code level later, but I thought I'd experiment with the Fritzing circuit design package as a means of recording my more complex circuits, starting with the AF input stage for the tuner. At first glance, Fritzing seems like everything I need:
Thursday, January 26. 2012
Servo toy Posted by Fanjita in Arduino at 22:36
Most recent first... Yesterday it occurred to me that I haven't ever played with servo motor control, despite having received one in my Sparkfun starter kit.
Since I'd just received a Wii Nunchuck breakout adapter from ThingM Labs, I figured I'd kill two birds with one stone and have a bash at controlling a servo with a nunchuck.
The circuit couldn't be much simpler, just connect the servo power to 0V, 5V and digital pin 9, and plug the breakout board (after soldering on a simple 4-pin header) into analogue pins A2-A5:
Continue reading "Servo toy"
If you have found my site or software useful, please consider donating a small amount of money using the button below.