---

Friday, November 23, 2012

Using .NET Gadgeteer Modules with Arduino - Relay

The .NET Gadgeteer system has spawned a wide range of low cost and useful modules form places like GHI Electronics and Seedstudio.

I have a load of Gadgeteer modules, sitting in a cupboard, so I thought it would be good to see how hard it would be to use them with an Arduino. I decided to start with a nice easy one, this relay module from Seedstudio. It has four relays, each with an indicator LED.

The Gadgeteer modules are all connected by 10 way ribbon cable connectors. So clearly, the first thing we need is to make a lead that we can use to connect the module to breadboard.

I cut a lead in half and stripped the 10 wires from the half of the lead with the connector notch to the left. This turned out to be pretty easy. I was rather expecting it to go wrong and the leads end up all sorts of different lengths - but the wires stripped really easily.

I found that using a craft knife to separate the leads helped.
I then tinned the stripped wires and soldered them to a length of 10 pin header stuck into breadboard to stop it moving.

There we go, a lead that we can use with any Gadgeteer module.

The Gadgeteer system has many different types of pinout for these connectors. The relay module uses a type-Y socket, which is a general purpose IO arrangement. There are other types for serial, USB, I2C, analog and all sorts. They all use the same connectors, but have different pinouts.

You can find full details of all the pinout options here.

The pinouts for the type-Y are as below:



Here is a section of the Eagle schematic for the relay module (Open Source).

Although Gadgeteer modules are often 3.3V, this design will have no problem using 5V levels, so all looks promising. The control pins for the relays are connected to Gadgeteer pins 3, 4, 5 and 6.

The schematic shows the relay coils being supplied from 5V (pin 2), but testing with a multimeter, I found that the 'top' connection of the relay coil was actually connected to pin 1 (3.3V). I don't really understand this discrepancy, but no problem, in this case we can supply 5V from the Arduino to pin 1 of the module. That would be a bad thing to do for most types of Gadgeteer module - be Warned!

Here is the wired up breadboard:



  • Pin 1 of the Gadgeteer connector goes to Arduino 5V
  • Pin 10 of the Gadgeteer connector goes to Arduino GND
  • Pins 3, 4, 5 and 6 of the Gadgeteer connector goes to Arduino D2, D3, D4 and D5 respectively
Here is a little test sketch that lets you turn each Relay on and off using the Serial Monitor.




// Gadgeteer Relay Board

int relayPins[] = {2, 3, 4, 5};

void setup()
{
  for (int i = 0; i < 4; i++)
  {
    pinMode(relayPins[i], OUTPUT);
  }
  Serial.begin(9600);
  while (!Serial);
  Serial.println("A, B, C, D to turn relay on");
  Serial.println("a, b, c, d to turn relay off");
}

void loop()
{
  if (Serial.available())
  {
    char ch = Serial.read();
    if (ch >= 'A' && ch <= 'D')
    {
      digitalWrite(relayPins[ch - 'A'], HIGH);
    }
    if (ch >= 'a' && ch <= 'd')
    {
      digitalWrite(relayPins[ch - 'a'], LOW);
    } 
  }
}



Conclusion
Now that I have a lead, I need to think about which Gadgeteer module to try next!

Perhaps one of the I2C modules?

                        
About the Author
These are my books. Click on the image below to find out more about them.




                                                                 

1 comment:

RorschachUK said...

Rather than carve up a cable, it's MUCH easier and less messy to use GHI's cheap Extender module with a row of breadboard pin headers soldered on. This module can be used to either hook up non-Gadgeteer components to a Gadgeteer mainboard, or to hook up a Gadgeteer module to an Arduino (or RPi). To use your Seeed Relay module with an Extender, you'd connect the cable from the relay module into the outgoing socket of the Extender, plug the Extender into your breadboard, and its PCB would handily tell you what each pin was supposed to be. Some Gadgeteer modules will even work straight away with Arduino libraries, for instance I've had GHI's HD44780-based LCD character display working fine with Arduino's LiquidCrystal library just using the Extender module.