Arduino's I/O Expander Shield from cutedigi.com - Page 1
Forum section: electronics / beginners

author: carloszoom3000
author_rank: Newbie
timestamp: October 04, 2016, 04:16:13 pm
content: Hi.I'm using the I/O Expander shield from cutedigi.com (http://store.cutedigi.com/i-o-expander-shield-for-arduino-pcduino/).It shows additional pins on the digital side of the Arduino.If no code is uploaded to the Arduino, the pins DA7 and DA6 can be turned ON and OFF by the DIP 4 and 3 switches.The pin DA5 is always high.The rest of the pins are low.When trying to program it, enabling the additional pins, using the DB# and DA# pins, it shows that the variable was not declared.Ex:void setup() {pinMode(B2, OUTPUT);}void loop() {digitalWrite(B2, HIGH);}When using the DA7 to DA0 pins, it allows you to compile and upload the code, however the pins are not enabled as expected.Any help will be appreciated.Regards.

author: NandGate
author_rank: Newbie
timestamp: October 04, 2016, 05:12:57 pm
content: The tutorial for that board includes a code example. Did you check that out?http://learn.linksprite.com/arduino/shields/io-expander-shield-for-arduino/

author: carloszoom3000
author_rank: Newbie
timestamp: October 04, 2016, 07:02:35 pm
content: Thanks for answering.I uploaded the code shown there.And i see they declare some pins as inputs.They get 2 High levels and one low.I though it was as easy as with the Arduino itself, so you just dopinMode(13, OUTPUT);//declare digital pin as outputand thendigital Write(13, HIGH); set the digtal pin to 5V.I know it might look like very well explained in the link you shared, but If there is any other example it would make things more clear.Thanks in advance.Regards,

author: NandGate
author_rank: Newbie
timestamp: October 04, 2016, 10:09:56 pm
content: The extra pins on that shield are only accessible over I2C. So you won't be able to use pinMode or digitalWrite.Code:Wire.beginTransmission(mcp_address);Wire.write((byte)IODIRA); // IODIRA registerWire.write((byte)0x03); // set GPIOA-0/GPIOA-1 to inputsWire.endTransmission();That changes the directions of the A pins. 0x03 represents a bitfield of all the pins, where a bit of 1 means that pin will be input, and a bit of 0 will be output.Code:Wire.write(GPIOA); // address bank AWire.write((byte)0x04); // value to send GPIOA-2 HIGHWire.endTransmission();That sets the output states for all the A pins. Again, just a bitfield, so you're setting the output state (HIGH or LOW) for all the pins at once.

author: KL27x
author_rank: Super Contributor
timestamp: October 04, 2016, 10:21:35 pm
content: I don't know Arduino, but if that is true it sounds like a halfbaked product.First thing I did when needing to expand I/O with I2C is to write port emulator code. Reading/writing to I2C port expander is identical to any other port, other than the up to 10ms latency. Essentially all of my preexisting code will work on these new virtual ports, which have their own tristate, latch, and read registers which function exactly like a normal port.The physical shield part? Ha. For what it really is I'm sure it will be fine. An introduction to I2C with some starting sample code.

author: NandGate
author_rank: Newbie
timestamp: October 04, 2016, 10:33:19 pm
content: Ahh, looks like good ole Adafruit provides a library that emulates more normal Arduino code:https://github.com/adafruit/Adafruit-MCP23017-Arduino-LibraryAnd it looks like that library will work as-is with the default configuration on that board.Example code is included in Adafruit's repo, for example:https://github.com/adafruit/Adafruit-MCP23017-Arduino-Library/blob/master/examples/toggle/toggle.ino

author: KL27x
author_rank: Super Contributor
timestamp: October 04, 2016, 10:44:57 pm
content: Clearly I'm in the wrong business.Spend 1 or 2 days designing an Arduino Shield.Let someone else write the software.Profit.