MCP23008 I2C LCD backpack driver

This driver was written for wide.hk I2C LCD backpacks (picture). They are very small and slim and don’t have any means to configure their I2C address.

If you have another backpack and the driver doesn’t work with this one, please open an issue on GitHub with a link to the backpack and its drivers for Arduino/Raspberry Pi

Sample config.json:

"input":
   [{
     "driver":"mcp23008",
     "kwargs":
      {
       "addr":"0x3f"
      }
   }]

Note

If you provide backpack’s I2C address as a kwarg, you should pass it as a string (as shown above).

To test your screen, you can just run python output/driver/mcp23008.py while your screen is connected to I2C bus (you might want to adjust parameters in driver’s if __name__ == "__main__" section). It will initialize the screen and show some text on it.

class output.drivers.mcp23008.Screen(bus=1, addr=39, debug=False, **kwargs)[source]

A driver for MCP23008-based I2C LCD backpacks. The one tested had “WIDE.HK” written on it.

__init__(bus=1, addr=39, debug=False, **kwargs)[source]

Initialises the Screen object.

Kwargs:

  • bus: I2C bus number.
  • addr: I2C address of the board.
  • debug: enables printing out LCD commands.
  • **kwargs: all the other arguments, get passed further to HD44780 constructor
i2c_init()[source]

Inits the MCP23017 IC for desired operation.

write_byte(byte, char_mode=False)[source]

Takes a byte and sends the high nibble, then the low nibble (as per HD44780 doc). Passes char_mode to self.write4bits.

write4bits(data, char_mode=False)[source]

Writes a nibble to the display. If char_mode is set, holds the RS line high.

setMCPreg(reg, val)[source]

Sets the MCP23017 register.