Mutually-exclusive switch driver Example :
Now that we have the I2C scanner program that can help us to detect our I2C devices is time to move to some driver examples
I think everybody know already the famous PCF8574. I have also cover it extendely in the previous Articles about, here for I/O input and here for output I/O.
Now is time to put it at work also in ESP8266 Basic and see how is working.
The example for today is a implementation of a mutually-exclusive switch that can be handy for many, many things as for example for doing the selection of a source in a Audio mixer or a any other analog path. Or driving Power relays.
Mutually exclusive switch means that when the corresponding switch button is pressed ON must also automatically turn the other sources OFF.
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:
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
button "1",  'Define push buttons for each I/O pin
button "2", 
button "3", 
button "4", 
button "5", 
button "6", 
button "7", 
button "8", 
button "OFF",  'Button for turning OFF all
i2c.begin(address) 'Start I2C communication with device at 'address'
i2c.write(255) 'write the corresponding I/O pin value to register
i2c.end() 'end I2C communication
This is how is looking the interface in the Web Browser after running the above program: