EasyTransfer-I2C 2-way Master<->Slave Communication

I have an application where I would like to establish 2-way communicate between two Arduino Nanos using I2C using “EasyTransfer”. EasyTransfer comes with an I2C library, but when trying to establish 2-way communication using it failed I opened up the library and from what I can tell the library did not support this. I posted a message on the author’s website here: Topic: EasyTransfer-I2C two-way communication « The Mind of Bill Porter

What lead me to believe that 2-way communication had not been worked out was the fact that the EasyTransferI2C::sendData contained code specific for sending data from a Master to a Slave and the receiveData contained code specific for receiving data from a Master to a Slave.

My solution was to modify this library and make i2c_address inputs to ::sendData() and ::receiveData() as optional. If the input is supplied, then it assumes Master → Slave communication. If no input is supplied the code assumes that the Slave is responding to a Master request.

Attached is the library and the code. I think I’m close, but currently only Master → Slave communication is working properly. My example code is an expansion of the original example code. Here is the gist of the processes (how it should work):

  1. Master declares random “blinks” and “pause” variable
  2. Master sends Slave this data
  3. Slave receives the data, blinks and pauses the LED_INDICATOR based on the data
  4. Master requests the Slave send data back to it
  5. Slave send back the “blinks” and “pause” variables
  6. Master receives the “blinks” and “pause” variables, proceeds to blink and pause.
  7. Delay 5000, repeat.

I’m about to pull out the o-scope to see if I can troubleshoot this some more.

Thanks for your help! I apologize in advanced for my poor spelling in my comments.

EasyTransferI2C_NL.cpp (3.92 KB)

EasyTransferI2C_NL.h (2.21 KB)

EasyTransfer_Master_2way_Example.ino (3.63 KB)

EasyTransfer_Slave_2way_Example.ino (2.59 KB)

From what I can tell from the O-Scope and adding some “Serial.print” debug lines in my library code, the only thing my slave is transmitting is the value 255, 6 times…

Not sure why…

Hmmm..this is...weird. OK, I might just be missing...something but I think I'm zeroing in on the problem.

For a Master to queue to data to be sent to a Slave, the Master can call Wire.write() as many times as it likes. If going the other direction (Slave responding to a request for data from the master), you can seemingly only call Wire.write() once in response to the request.

Take a look at the I2C "MasterReader" example: http://arduino.cc/en/Tutorial/MasterReader

If you change the line in the Slave code: Wire.write("hello ") with:
Wire.write(' ')

The code will fail.

Solution? Probably rewrite the ::sendData() code to collect everything into an array of bytes and then transmit with one Wire.write() call. Working on that now.

Woohoo! Got it working.

I’ll be submitting my code to Bill Porter for inclusion in his library. Hit me up with a PM if you need it. This makes 2-way communication over I2C using any data structure (<256 bytes) a breeze!

If you change the line in the Slave code: Wire.write("hello ") with:
Wire.write(’ ')

The code will fail.

That is a known issue.


Wasn't known to me until just the other day, but thanks.


IF you have a fix for my library, submit it as a pull request on github so I can add it to the main library code, then everybody will have it!


already have a corrected version?

Any chance to upload the revised code here, don't see it on Bills github.

Hey Nickerbocker, I would love to get a copy of your updated version. Im in the same position as you were (cant get data from a slave).
Thanks man.


Asking on a very old post but I love this library.
I use this library for couple of projects and it is great!

The ">28 byte bug" is an issue though and was wondering if anyone figured it out by now?

Could anyone upload the working version of his code?
I can't send him PM.

Could anyone upload the working version of his code?
I can't send him PM.

Here's some sample code for bi-directional communication between i2c Slave and Master.