High-Power Relay Shield, MCP23008 I/O question



Hi CE community,

I have the Photon High-Power Relay Shield, 2-Channel SPST 30-Amp, my question is about  how to set the GP pins as Input and Output.  Is there any example code somewhere? Most codes reported by Mr Google are for the Arduinos assuming that the MCP23008 is not wired to the uController yet,  which is no the case for the High-Power Relay Shield. 

I know how to program the Photon itself, how to use the I/O pins, etc., but I am not familiar with MCP23008 already attached to the Photon. Something don’t click for me here. 

Thank you,

Alex

UPDATE:

I'm making some progress,  I got the "Hello world"(blink an LED) going. I am sure there is a better way to do it. 

 

#define Addr 0x20
void setup()
{
  Wire.begin();

Wire.beginTransmission(Addr);
  Wire.write(0x00);// Select IODIR register
  Wire.write(0x00);// All pins are configured as outputs
  Wire.endTransmission();// Stop I2C transmission
  }

void loop()
{

Wire.beginTransmission(Addr);// Start I²C Transmission
  Wire.write(0x09);
  Wire.write(0x4); // Set GP2 HIGH
  Wire.endTransmission();// Stop I²C transmission
  delay(1000);
   Wire.beginTransmission(Addr);// Start I²C Transmission
  Wire.write(0x09);
  Wire.write(0x0); // Set GP2 LOW
  Wire.endTransmission();// Stop I²C transmission
  delay(1000);
}

 

 

 

 

 

Target Product: 
MCP23008_SCIO4R430
T

Hi,

Yes we have sample libraries for the board in the Particle Community Libraries on build.particle.io  Search community libraries there for:

NCD4Relay

If you take a look at the setAddress function in the code that is where the IO directions are set.  The first 4 IOs are set to outputs and the other 4 are set to inputs.  I did not write in an argument where these could be passed to the function although that could easily be done.

The github repo for the library is here:

https://github.com/ControlEverythingCom/NCD4Relay

Take a look at firmware/NCD4Relay.cpp

Here you will see the setAddress function which is where the IO directions are set.  Look at line 35 Wire.write(0xF0);  Each of the 8 IO lines on the MCP23008 has a bit representation in that byte(0xF0).  To set an IO line as an output you set the bit to 1, to set it as an output you set the bit to 0.  So if you set lines 1, 2, 3, and 4 to outputs that makes the byte 0xF0 or 15.  You can alter this byte to set the remaining 4 lines as outputs as well if you like, but I recommend leaving the first 4 set to outputs since they drive the on board relays.

Also take a look at line 41 where you will see the exact same byte being written to another register.  This pulls the IO input lines up so they can be used for reading dry contact closures to ground.

Of course you can read all about this in the MCP23008 datasheet but this should give you a good place to start.

If you have any other questions please let me know.

Thank you,

Travis Elliott

I

 

Thank you, Travis, for your reply.   I checked the link you mentioned, I got some ideas from it. Right now I am using the MCP23008 AdaFruit library,  this library provides me  the information  I need for my project.  

One thing I'd like to have is the schematic for this boards.  Do you guys provides that?   I'd like to know how the board is inter-connected, like  pins connections, etc.  

I wan to add that I so happy with CE's products, top notch  products at very good price, and the best part: Made in the USA!

Alex

 

 

 

 

T

Hi Alex,

I will check with another engineer here to see if I can get a schematic to you.  Will be back shortly.

And yes our products are 100% designed and manufactured right here in the good old US of A :D

Thank you Alex,

Travis Elliott

T

I

 

Thank you, Travis, for the schematic,  that is exactly what I was looking for.  

Alex