10 years, 2 months ago.

How do I make I2C on LPC1768 board work?

I am a young student, inexperienced with the mbed but familiar with coding.

For the past week I have spent my time trying to use the I2C serial pinout from my mbed LPC1768 to light up an external LED light. I know the LED circuit is correct because it lights when apply a voltage directly to it; however, I am seriously struggling to get an I2C output that will work.

WHAT AM I MISSING?

I currently have the LED circuit straight into the pin, however my hunch is that I need to pass it through something, but I cannot figure out what I need to pass it through. if this is my main issue, what do you recommend? and how should I configure the circuit?

If i don't need a "middle man," then how should I code this?

4 Answers

10 years, 2 months ago.

Daniel, It is not clear what your 'LED circuit' is exactly. I assume it is just an LED. You should never connect an LED to any mbed pin without a serial resistor. Start reading up on DigitalOut in the handbook, you may also want to get one of the books on mbed before frying your hardware by experimenting without understanding the electronics.

Accepted Answer
10 years, 2 months ago.

I don't think I2C is what you should be using to light an LED. I doubt that it will work the way you might hope it would. I don't have time to get detailed, but I2C is a serial communications interface. It's pretty simple to find out resources that describe it (via links here on mbed.org).

I suggest using a basic GPIO pin configured with the DigitalOut library. This is also easy to learn about on the mbed.org Handbook pages.

Good luck.

What about using I2C for multiple pancake actuators (small motors)? Any advice on that? I am unsuccessful in researching a helpful code/explanation/example. A question that I thought of is: can I activate a motor from I2C? or does it have to use communications? I know communications will be sent in binary or hex, but will they be able to activate the motor by turning on voltage?

anything helps

posted by Daniel Huber 05 Feb 2014
10 years, 2 months ago.

Okay so I guess I took the completely wrong approach to my problem. My END goal is to control pancake actuators with this I2C output and I was only using the LEDs because I figured that they would be a good way to tell if I was able to talk out of the I2C port without hurting the mbed in case I wired something wrong. So let me change my question:

How do I talk to several pancake actuators (just small motors essentially that have two wires, positive and negative/ground, for control)?????? I want to be able to control different motors at different times, depending on input conditions I will feed it.

The solution depends on your needs: are you looking for simple on/off or also direction control and possible speed control. You could use I2C port expanders to drive very small motors or drive a relays or solid state driver for larger motors (depends on motor current). The cookbook page has examples for drivers. Speed control is done best using PWM. There are some I2C expanders that support PWM also (intended for LEDs in fact).

posted by Wim Huiskamp 05 Feb 2014
10 years, 2 months ago.

The main part where people get it wrong interfacing which i2c is addressing because every platform has its own method , Mbed is like the Arduino for addressing.

Most of my interfacing with i2c is for the mcp23008 , mcp23016 / mcp23017 chips From the manual on address the mcp23017 it`s address is 0100,a2,a1,a0,r/w

So make all the addressing pins High ( + 3.3v ) so the address is 01001110 0x4E

i2c_1 = 0x4e

char read_gpio(char reg)

{ i2c_1.start(); Start

i2c_1.write(i2c_1_address); A write to device

i2c_1.write(0x12 + reg); Register to read

i2c_1.start();

i2c_1.write(i2c_1_address + 1); Read from device

char data = i2c_1.read(0); Read the data

i2c_1.stop();

return data; }

void set_pullups(char reg , char value) reg 0 or 1

{ i2c_1.start(); Start i2c_1.write(i2c_1_address); write , address i2c_1.write(reg + 0x0c ); write , which reg i2c_1.write(value); write , value i2c_1.stop(); } So that is basically how to talk to a i2c device

and don`t forget about the pullup resistor on both the clk and sda ( 2.2k - 4.7k )