I'm working on a custom sensor that is wired to a couple of MCP23S17 gpio expanders, which are in term connected to a Raspberry Pi 4 via the SPI pins i.e. SPI_MOSI, SPI_MISO, SPI_SCLK and CE0 pin.
I'm trying to read/write to these expanded pins via some python code, preferably using 'wiringpi' but I can't seem to find any information about using these expander boards with SPI, all the tutorials I can find talk about connecting it via I2C in stead.
More specifically, I'd like to use SPI to address the expander pins and read analog voltages. I'll include an example of my Python code for clarity's sake:
selectorPins = [65, 66, 67, 68, 69, 70, 71, 72] analogReadPins = [89, 90, 91, 92] i2c1_pin_base = 65 i2c1_address = 0b001 i2c2_pin_base = 81 i2c2_address = 0b000 wiringpi.wiringPiSetup() wiringpi.mcp23017Setup(i2c1_pin_base, i2c1_address) wiringpi.mcp23017Setup(i2c2_pin_base, i2c2_address) for x in selectorPins: wiringpi.pinMode(x, 1) for x in analogReadPins: wiringpi.pinMode(x, 0) # select sensor wiringpi.digitalWrite(selectorPins, 0) wiringpi.digitalWrite(selectorPins, 1) # ... sensorValue = wiringpi.analogRead(analogReadPins) # ...
Though this obviously doesn't work since the expanders are connected via SPI and I'm not using I2C at all. Indeed If i try to run this I just get an error
Unable to open I2C device: No such file or directory
I'm running raspbian buster lite and have SPI set up properly (I hope) as I can do
pi@mySensorPi:~ $ ls -l /dev/spi* crw-rw---- 1 root spi 153, 0 Oct 15 11:59 /dev/spidev0.0 crw-rw---- 1 root spi 153, 1 Oct 15 11:59 /dev/spidev0.1
I'm not sure if I'm missing something, I haven't worked with gpio expanders before. Any help and info is welcome!
P.S. the wiring is embedded in a custom board for this sensor so changing the pins is a costly option I'd like to avoid if possible.