Sure. I’ve used MCP23017 in a previous project.
Include the i2c library in mos.yml and you just need to initialize it with mongoose I2C functions, here’s my example:
Declare:
#include “mgos_i2c.h”
#define MCP23017 0x20
static void iot_mcp23017_init(){
struct mgos_i2c *i2c = mgos_i2c_get_global();
mgos_i2c_write_reg_b(i2c, MCP23017, 0x00, 0x00); //portA pins like outputs
mgos_i2c_write_reg_b(i2c, MCP23017, 0x01, 0xFF); //portB pins like inputs
mgos_i2c_write_reg_b(i2c, MCP23017, 0x0C, 0xF0); //no pull-ups
mgos_i2c_write_reg_b(i2c, MCP23017, 0x0D, 0x00); //no pull-ups
}
Example of a function to reset my 3G modem attached to MCP23017:
void reset_3g_modem(void){
struct mgos_i2c *i2c = mgos_i2c_get_global();
mgos_i2c_write_reg_b(i2c, MCP23017, 0x12, 0) //sets output to 1;
mgos_msleep(100);
mgos_i2c_write_reg_b(i2c, MCP23017, 0x12, 1 //sets back reset pin to 0);
}
You could also look for a MCP23017 library, it eases things up a bit.
For better compreehension, read the datasheet describing register functions.
Hope it helps.
Edit: You can alter inicialization in different initializing functions, setting as input or output.
There is a limitation for a single i2c address. You could try plugging several MCP23017 in the same address, maybe they’ll just mirror one another. I myself wouldn’t recommend, you can choose between ADD 0x20 and 0x21 for all I know