Documentation ¶
Overview ¶
Package mcp23xxx provides driver for the MCP23 family of IO extenders
Datasheet ¶
https://ww1.microchip.com/downloads/en/DeviceDoc/20001952C.pdf
Example ¶
// Make sure periph is initialized. if _, err := host.Init(); err != nil { log.Fatal(err) } // Open default I²C bus. bus, err := i2creg.Open("") if err != nil { log.Fatalf("failed to open I²C: %v", err) } defer bus.Close() // Create a new I2C IO extender extender, err := mcp23xxx.NewI2C(bus, mcp23xxx.MCP23017, 0x20) if err != nil { log.Fatalln(err) } for _, port := range extender.Pins { for _, pin := range port { err = pin.In(gpio.Float, gpio.NoEdge) if err != nil { log.Fatalln(err) } level := pin.Read() fmt.Printf("%s\t%s\n", pin.Name(), level.String()) } } if err != nil { log.Fatalln(err) }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Dev ¶
type Dev struct { // Pins provide access to extender pins. Pins [][]Pin }
Dev his a handle for a configured MCP23xxx device.
type Pin ¶
type Pin interface { gpio.PinIO // SetPolarityInverted if set to true, GPIO register bit reflects the same logic state of the input pin. SetPolarityInverted(p bool) error // IsPolarityInverted returns true if the value of the input pin reflects inverted logic state. IsPolarityInverted() (bool, error) }
Pin extends gpio.PinIO interface with features supported by MCP23xxx devices.
type Variant ¶
type Variant string
Variant is the type denoting a specific variant of the family.
const ( // MCP23008 8-bit I2C extender. Datasheet: https://www.microchip.com/wwwproducts/en/MCP23008 MCP23008 Variant = "MCP23008" // MCP23S08 8-bit SPI extender. Datasheet: https://www.microchip.com/wwwproducts/en/MCP23S08 MCP23S08 Variant = "MCP23S08" // MCP23009 8-bit I2C extender. Datasheet: https://www.microchip.com/wwwproducts/en/MCP23009 MCP23009 Variant = "MCP23009" // MCP23S09 8-bit SPI extender. Datasheet: https://www.microchip.com/wwwproducts/en/MCP23S09 MCP23S09 Variant = "MCP23S09" // MCP23016 16-bit I2C extender. Datasheet: https://www.microchip.com/wwwproducts/en/MCP23016 MCP23016 Variant = "MCP23016" // MCP23017 8-bit I2C extender. Datasheet: https://www.microchip.com/wwwproducts/en/MCP23017 MCP23017 Variant = "MCP23017" // MCP23S17 8-bit SPI extender. Datasheet: https://www.microchip.com/wwwproducts/en/MCP23S17 MCP23S17 Variant = "MCP23S17" // MCP23018 8-bit I2C extender. Datasheet: https://www.microchip.com/wwwproducts/en/MCP23018 MCP23018 Variant = "MCP23018" // MCP23S18 8-bit SPI extender. Datasheet: https://www.microchip.com/wwwproducts/en/MCP23S18 MCP23S18 Variant = "MCP23S18" )
Click to show internal directories.
Click to hide internal directories.