Module: i2c

This module provides access to all I2C GPIO expansion pins via a 32 bit bus. The expansion module has 2 ports and each port has 2 banks which are 8 bits wide. These are mapped onto a single 32 bit value that can be read and written. http://ww1.microchip.com/downloads/en/DeviceDoc/21952b.pdf E.g. Switch on watchdog led => DIR:0=out: i2cset -y 1 0x21 0x0 0xB0 i2cset -y 1 0x21 0x12 0x40 Close Valve 0 DIR:0=out: i2cset -y 1 0x20 0x1 0xFE i2cset -y 1 0x20 0x13 0x1 Flow 7 0x21 0x13 0x80 31 In Flow 6 0x21 0x13 0x40 30 In Flow 5 0x21 0x13 0x20 29 In Flow 4 0x21 0x13 0x10 28 In Flow 3 0x21 0x13 0x8 27 In Flow 2 0x21 0x13 0x4 26 In Flow 1 0x21 0x13 0x2 25 In Flow 0 0x21 0x13 0x1 24 In Watchdog Halt 0x21 0x12 0x80 23 In Watchdog LED 0x21 0x12 0x40 22 Out 0 = On //Heater 0x21 0x12 0x20 21 Out 1 = On //Heater 0x21 0x12 0x10 16 Out 1 = On Heater 0x21 0x12 0x02 17 Out 1 = On Relay ? 0x20 0x13 0x80 15 Out Relay ? 0x20 0x13 0x40 14 Out Relay ? 0x20 0x13 0x20 13 Out Pump 0 0x20 0x13 0x10 12 Out 0 = On Valve 6 0x20 0x13 0x8 11 Out 0 = Open Valve 4 0x20 0x13 0x4 10 Out 0 = Open Valve 2 0x20 0x13 0x2 9 Out 0 = Open valve 0 0x20 0x13 0x1 8 Out 0 = Open Valve 1 0x20 0x12 0x80 7 Out 0 = Open Valve 3 0x20 0x12 0x40 6 Out 0 = Open Valve 5 0x20 0x12 0x20 5 Out 0 = Open Valve 7 0x20 0x12 0x10 4 Out 0 = Open Pump 1 0x20 0x12 0x8 3 Out Relay ? 0x20 0x12 0x4 2 Out Relay ? 0x20 0x12 0x2 1 Out Relay ? 0x20 0x12 0x1 0 Out
Author:
  • Dave Leitch

Requires

Methods


<static> init()

Initialise an individual bit. type {{number: number - Bit number [0:31], dir: number - [DIR_INPUT | DIR_OUTPUT], value: number - [0 | 1]}} bitInfo

<static> readBit(n, cb)

Read any single bit
Parameters:
Name Type Description
n number Bit number [0:31]
cb function Callback(err, result)

<static> setDir(n, value)

Set direction of a single bit
Parameters:
Name Type Description
n number Bit number [0:31]
value number DIR_INPUT | DIR_OUTPUT

<static> toggleBit(n)

Toggle any bit
Parameters:
Name Type Description
n number Bit number [0:31]

<static> writeBit(bit, value)

Set or clear any bit
Parameters:
Name Type Description
bit number Bit number [0:31]
value number 0 or 1