Pages: [1]   Go Down
Author Topic: I2C Arduino to Arduino Sending Integers  (Read 123 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Global Moderator
Melbourne, Australia
Offline Offline
Brattain Member
*****
Karma: 511
Posts: 19367
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

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

Please post technical questions on the forum - not to me by personal message. Thanks a lot.

Online Online
Edison Member
*
Karma: 45
Posts: 1605
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Doctor, I see Arduino boards everywhere, what can I do ? - Well, I suggest you connect them with I2C.

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Global Moderator
Melbourne, Australia
Offline Offline
Brattain Member
*****
Karma: 511
Posts: 19367
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

Please post technical questions on the forum - not to me by personal message. Thanks a lot.

Online Online
Edison Member
*
Karma: 45
Posts: 1605
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Doctor, I see Arduino boards everywhere, what can I do ? - Well, I suggest you connect them with I2C.

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ty Peter you solved the problem now the I2C communication works fine smiley 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-grin
« Last Edit: September 07, 2014, 06:56:07 am by kameni123 » Logged

Online Online
Edison Member
*
Karma: 45
Posts: 1605
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Doctor, I see Arduino boards everywhere, what can I do ? - Well, I suggest you connect them with I2C.

Pages: [1]   Go Up
Jump to: