MCP23008-RK
|
Particle driver for MCP23008 8-port I2C GPIO expander
One Side:
Other Side:
Note that the address lines are not biased so you must connect them to GND or VDD to set the address! Normally you'd connect all to GND to set address 0.
Same for /RESET, though you probably want to connect that to VDD to keep the device out of reset.
Here's my test circuit:
Important: Remember the pull-ups on the SDA and SCL lines (4.7K or 10K typically)! While many breakout boards like you'd get from Adafruit or Sparkfun includes the pull-ups on the board, you must add external resistors when using a bare MCP23008.
This library has an API that looks remarkably like the regular GPIO calls.
Typically you create an global object like this in your source:
The first parameter is the interface. It's typically Wire (D0 and D1).
The second parameter is the address of the device (0-7). This corresponds to the value set on the A0, A1, and A2 pins and allows up to 8 separate MCP23008 devices on a single I2C bus.
On the Electron, you can also use Wire1 on C4 and C5:
You must call begin(), typically during setup(), to initialize the Wire interface.
Sets the pin mode of a pin (0-7). Values for mode include:
Note that it does not support INPUT_PULLDOWN, as the MCP23008 only supports internal pull-ups. Also, they're 100K vs. the 40K (-ish) pull-ups in the STM32F205.
Sets the value of a pin (0-7) to the specified value. Values are typically:
Reads the value of the pin (0-7). This will be HIGH (true, 1) or LOW (false, 0).
If used on an output pin, returns the current output state.
Returns the pin mode of pin (0-7), which will be one of:
Returns true if 0 <= pin <= 7.
The full documentation is available in the docs/index.html file or in the [browsable API reference](). This documentation is generated automatically from comments in MCP23008-RK.h using the Doxygen tool.
It's simple!
This example outputs a square wave on pins 0 - 3:
This should result in the following:
You can also connect a jumper from GP7 to one of those pins. It echoes the value on the GP7 input to the blue D7 LED on the Photon, so you can see the different frequencies.
Uses the INT pin and a handler to be notified of changes in a GPIO on the MCP23008 efficiently.
Uses the INT pin and has a handler as a C++ class member function.