Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
11 years, 7 months ago.
Arduino + Mbed i2c?
Hello.
I am currently working on a project that requires me to send data from the mbed to the arduino using i2c... Does anyone have an idea of how i can do this? This is what i have tried so far.
mbed master code
#include "mbed.h" Serial rn42(p9,p10); DigitalOut myled(LED1); I2C i2c (p28,p27); int x; int main() { rn42.baud(115200); while (1) { if (rn42.readable()) { x = rn42.getc(); printf("%d\n",x); myled = !myled; i2c.start(); i2c.write(0xC0); i2c.write(x); i2c.stop(); } } }
arduino slave code
#include <Wire.h> byte y; void setup() { Serial.begin(115200); Wire.begin(0xC0); } void loop() { Wire.onReceive(receiveEvent); } void receiveEvent(int howMany) { y = Wire.read(); Serial.println (y); }
Thank you very much.
2 Answers
6 years, 7 months ago.
Be aware that mBed i2c addresses are shifted 1 bit to the left. So if you use the I2C address 0x0F (00001111) on the arduino, it will be 0x1E (00011110) on mBed
8 years, 11 months ago.
I'm in the same boat. Arduino (Master) sending messages to mbed (slave or another master). Has this already been mastered?