More digital outputs

Hi,
I need 12 digital outputs for my project with Photon,
potentionaly I can use 2 Photon, but it sounds not good for me, because of synchronization,

My question is, is possible to have 12 digital outputs with Photon? (like use analog as digital output?)

Thanks so much
Peter

Yes, you can use the analog outputs as digital outputs.

The documentation for the digitalWrite and digitalRead functions says you can and I’ve used A0 and A1 as digital outputs myself.

https://docs.particle.io/reference/firmware/photon/#input-output

Note: All GPIO pins (D0…D7, A0…A7, DAC, WKP, RX, TX) can be used as long they are not used otherwise (e.g. as Serial1 RX/TX).

What drwheetos said is true. And, if you need even more inputs or outputs in the future, you can use an I2C GPIO Expander, [SparkFun sells one] (https://www.sparkfun.com/products/13601) that adds 16 additional input or output pins only using the I2C interface (D0/D1) on the Photon.

1 Like

To use the I2C GPIO Expander from SparkFun I have to modify the code or I can write the code as I would do with an arduino ?

You can use the Arduino library for that one. I normally use the MCP23008 or MCP23017 chips directly now and this library:

The link is for the instructions; the library is also in the community libraries as MCP23008-RK.

2 Likes

Hi Rickas7

I want to use 2 pieces of MCP23008 (addresses 0x20 and 0x21 and suspect that I then have to write:
MCP23008 gpio(Wire, 0); //0x20
MCP23008 gpio(Wire, 1); //0x21

correct?

And how can I then set up the two separate chips with pinMode?

void setup() {
Serial.begin(9600);

gpio.begin(0); //0x20
gpio.pinMode(0, OUTPUT);
gpio.digitalWrite(0, HIGH);

gpio.begin(1); //0x21  is this correct?
gpio.pinMode(0, OUTPUT); // and what must be here?
gpio.digitalWrite(0, HIGH); // and here?

}

Many thanks for your answer

Greetings Martin

Hey Martin, I think you can write:

MCP23008 gpio0(Wire, 0); //0x20
MCP23008 gpio1(Wire, 1); //0x21

then you can refer to one or the other as gpio0 and gpio1.

2 Likes

Hi Gusgonnet

Many thanks.
The penny has dropped. :slightly_smiling_face:

Greetings Martin

1 Like