I2C Arduino to Arduino Sending Integers

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.

Scroll down to reply #8: "Send and receive any data type".

Do you know these :

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 :stuck_out_tongue:
(While I was writing this, Nick Gammon already mentioned that page, he is the author of it).

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...

Sadly, you have not posted any of your code so we are in the dark as much as you are, possibly more.

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.

Ty Peter you solved the problem now the I2C communication works fine :slight_smile: 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 :smiley:

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.