8 x Independent switches driver Example :
After doing last time the Mutually exclusive 8x Switch driver example, now is time for a 8 x independent switches implementation .
What we will need:
- ESP8266 nEXT EVO Board
- ESP8266 nEXT EVO - Analog Extension Board - AN1 (PCF8574 onboard)
- 8 LED Port Tester as described in the related Article
- For programming and uploading the driver and the software we will use ESP8266 Basic .
This is how is looking the setup on a breadboard, for a better visibility:
Software implementation:
Something to remember:
- PCF8574 can SINK but NOT SOURCE much current - 100uA only (it cannot output high, if you want). Look at the above example how is connected the LED for SINKING current.
- Each of the 8 GPIOs have a minimum guaranteed sinking current of 10 mA per bit at 5 V.
- Each pin needs its own limiting resistor to prevent damage to the device!! keep under 25mA/pin.
- Maximum device limit sink current in about 80mA. If you need more, look after PCA8574 (200mA max sink current!)
For more details please take a look at the PCF8574 Datasheet
ESP8266 Basic code:
let address = 32 'PCF8574 I2C Address
i2c.begin(address)
ss = 0 xor 255 'XOR - Bit masking for the desired I/O pins
i2c.write(ss)
i2c.end()
button "1", [1]
button "2", [2]
button "3", [3]
button "4", [4]
button "5", [5]
button "6", [6]
button "7", [7]
button "8", [8]
button "OFF", [9]
wait
[9]
i2c.begin(address)
ss = 0 xor 255 'XOR - Bit masking for the desired I/O pins
i2c.write(ss)
i2c.end()
wait
[1]
i2c.begin(address)
ss = ss xor 1 'XOR - Bit masking for the desired I/O pins
i2c.write(ss)
i2c.end()
wait
[2]
i2c.begin(address)
ss = ss xor 2
i2c.write(ss)
i2c.end()
wait
[3]
i2c.begin(address)
ss = ss xor 4
i2c.write(ss)
i2c.end()
wait
[4]
i2c.begin(address)
ss = ss xor 8
i2c.write(ss)
i2c.end()
wait
[5]
i2c.begin(address)
ss = ss xor 16
i2c.write(ss)
i2c.end()
wait
[6]
i2c.begin(address)
ss = ss xor 32
i2c.write(ss)
i2c.end()
wait
[7]
i2c.begin(address)
ss = ss xor 64
i2c.write(ss)
i2c.end()
wait
[8]
i2c.begin(address)
ss = ss xor 128
i2c.write(ss)
i2c.end()
wait
This is how is looking the interface in the Web Browser after running the above program:
PS: credit for the XOR Bit masking goes this time to Forlotto from the esp8266.com forum who posted quicker than me this elegant solution :)

