Go Down

Topic: I2C Arduino to Arduino Sending Integers (Read 148 times) previous topic - next topic

kameni123

If someone knows how to send integers over I2C with the Wire.h library I was tring it for several days but it was all a big fail..
I want the master to request a number and the slave shoud send that number to the master... Any help comes good.

Nick Gammon

http://www.gammon.com.au/i2c

Scroll down to reply #8: "Send and receive any data type".
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Peter_n

Do you know these :
http://arduino.cc/en/Tutorial/MasterWriter
http://arduino.cc/en/Tutorial/MasterReader

There are two ways to do this:
1 ) The master requests data with Wire.requestFrom(), and the slave returns data from an interrupt with a function set by Wire.onRequest(). This is not very fast, since the master is waiting until the data is received.
2 ) The master tells the slave that data is needed. The slave turns temporarely into a master and transmits the data to the master.

Try to study this page : http://gammon.com.au/i2c
When you get to the end of that page, you know a lot more about i2c  :P
(While I was writing this, Nick Gammon already mentioned that page, he is the author of it).

kameni123

Hi again I studied what you told me Nick and Peter and I tried  "Send and receive any data type". but when I look at the serial monitor of my slave device it just prints
?.ÿÿþ?ÿ6oþ6xø¹ÿ?µú"?=ý¹ÿm©ø?Ð7?ÿ?µô" all the time...

Nick Gammon

Sadly, you have not posted any of your code so we are in the dark as much as you are, possibly more.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Peter_n

Probably the baud rate is wrong.
Look in the sketch for this line: Serial.begin (115200);
It sets the baudrate to 115200. Set the serial monitor on the computer also to 115200, or change that number into 9600.

kameni123

#6
Sep 07, 2014, 01:46 pm Last Edit: Sep 07, 2014, 01:56 pm by kameni123 Reason: 1
Ty Peter you solved the problem now the I2C communication works fine :) ty for help all yet I only have to make that so when the master requests data the slave sends it to the master. I needed this because I want to make a reciver  that schoud get data with the VirtualWire.h library from a rc transmiter (im bulding a quadcopter and  a joystick from scratch). But I coud not use just one arduino because it cant use Servo.h and VirtualWire librarys at the same time :/. Anyway thankkk you for support :D

Peter_n

Well, I have a seperate Arduino to receive with VirtualWire, and a Master that request the data via I2C..... so feel free to ask.
My 'Master' is a Arduino Mega with Ethernet shield. At this moment I have only two modules via I2C. One with VirtualWire, the other one with sensors.

Go Up