Wednesday, 1 January 2014

Switching Band-Specific Elements

This post describes some initial experiments to add extra GPIO pins to the Arduino using a Microchip GPIO Expander.

My band-specific plug-in modules (as used on my multi-band BITX and Occam's Dagger rigs) are all very well...

But - let's face it - plugging and un-plugging is hardly in the spirit of the rest of the micro-controlled system.

With the Christmas and New Year festivities fading into memory, it is time to get back to the bench and play some games and the idea of switching band-specific functions (like low- and band-pass filtering) had bubbled up to the top of my list. It is a game I've played before - but this time I intend to have the filter board respond to I2C commands, rather than a parallel digital input.

In all my "Arduino" controlled rigs, I've already run out of Input/Output pins - so it was my intention to hang an input/output expander chip on the I2C bus. Whilst there are other devices available, I planned to use the Microchip parts and had ordered an MCP23017 device to play with a few weeks back.

There are good resources on the internet teaching you how to use this part - I used and recommend the excellent tutorial here.

Before I could do anything, I needed to be able to parallel the I2C lines with the LCD module - so I made up a little scrap of stripboard which allows me to hang three devices on the same "bus" (comprised of power, clock and data lines)...

The MCP23017 was plugged into a solderless breadboard, which also housed a single general-purpose NPN transistor (in my case a 2N3904) to switch a little relay. Here's the breadboard...

and here are the DPDT relays I intend to use when I get round to building permanent I2C-switched filter boards...

Coding for the GPIO expansion is very easy (see the tutorial in the link above).

I set up an array of "codes" which I want to write to the GPIO device...

This array will be used to assert one of the GPIO device's outputs for each band - the asserted output will turn on the transistor which will in turn turn on two relays to patch in the intended band-specific filter. One of these transistor / relay combinations was implemented on the breadboard (above) for my experiments.

My software (both for the "Occam's Dagger" CW rig and the subsequent BITX SSB rig) has an integer variable describing which band is in use - so this variable is used to index into the BandSwitch array to choose the appropriate code for the GPIO device. However, before the device can be used, it must first be initialised...

The GPIO device has three hardware address pins, which are tied to 0 or 5V to set the I2C address. My LCD is already on address 0x20 - so I had to select something different. Setting all three address lines high gives an address of 0x27 (you can learn about this in the tutorial if you're not au fait with I2C). With the address defined, initialisation is simplicity itself...

You use the Arduino "Wire" library to talk to the GPIO expander. You need first to specify if the ports are to be used as inputs or outputs - in our case they'll be outputs. I am only going to use up to 8 bits but in the following code, I set all 16 of the available pins on the MCP23017 as outputs.

This "initialisation" code should appear in the "setup" phase of the Arduino sketch - in my case I added it at the very end of "setup"

The code also sets the GPIO outputs to that appropriate for the initial band - in my code the band in use is described by the value of MenuOption[3], so BandSwitch[MenuOption[3]] is the code relevant to the starting band.

Subsequently, whenever the band is changed (i.e. when MenuOption[3] changes value), the following code should be called...

This can be added into the code that runs as a specific action on leaving menu mode after a band change.

Here's the whole shebang on the bench...

I found that one relay coil draws 18mA from the 12V supply - so I anticipate that the power consumption of the whole rig will go up by around 60mA when the bandswitching is fully automated.

Here's a schematic illustrating the "spirit" of my experiment - it uses an MCP23008 rather than the MCP23017, but that's what I plan to use eventually.

Now to design some filter boards.

.... -. -.-- de m0xpd

1 comment:

  1. This is a good addition to the Ardunio DDS, you can buy a kit intended for a Rasberry Pi from Maplin N98NQ that uses the same chip as you have used but you could also use 2off 74HC595's in cascade and control all the modes and 9 band switchs. You could also control the RX/TX line as well

    Regards Ray Koster G7BHQ