PCF8574, I2C and the mbed

A user on the mbed site asked for some help getting an I2C application to work with the mbed.

He's using a PCF8574 port expander which is driven from one of the mbed's I2C busses, which is on pins p9 and p10.

He wants to turn a LED on when a button is pushed. The button is connected to P4 on the port expander; the LED is attached to pin 5.

Here's the breadboarded circuit under manual test :)


And here's the code:


#include "mbed.h"
#include "PCF8574.h"



PCF8574 io(p9,p10,0x40);


int main() {
    while(1) {
        io.write(0x30);
        if ((io.read() & 0x20) == 0) {
            io.write(0x20);
        }
    }
}

Comments

  1. Thanks for sharing this :)

    Just what i needed to get another 6 GPIO's !

    Thanks,
    Theo

    http://mbed.org/users/ekelmans/

    ReplyDelete

Post a Comment

Popular posts from this blog

Controlling a Raspberry Pi Pico remotely using PySerial

Five steps to connect Jetson Nano and Arduino

Raspberry Pi Pico project 2 - MCP3008