Confused by SoftI2C

Im wanting to use SoftI2C to connect 2 arduino Unos together.
I need all analogue pins for other use in program so i need to change to different pins from analogue 4&5 (the hardware SCL/SDA lines on the uno)

the code i am using is the wire master/slave examples.
where wire allows the setting of an address to listen to and master writes to it
im not 100% sure how this is done using SoftI2C.

Ie. Wire.begin(4); // join i2c bus with address #4

Receiver Code

#include <Wire.h>

void setup()
  Wire.begin(4);                // join i2c bus with address #4
  Wire.onReceive(receiveEvent); // register event
  Serial.begin(9600);           // start serial for output

void loop()

// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany)
  while(1 < Wire.available()) // loop through all but the last
    char c =; // receive byte as a character
    Serial.print(c);         // print the character
  int x =;    // receive byte as an integer
  Serial.println(x);         // print the integer

And Master

#include <Wire.h>

void setup()
  Wire.begin(); // join i2c bus (address optional for master)

byte x = 0;

void loop()
  Wire.beginTransmission(4); // transmit to device #4
  Wire.write("x is ");        // sends five bytes
  Wire.write(x);              // sends one byte  
  Wire.endTransmission();    // stop transmitting


A simple straight forward example code for a SoftI2C approach to bothe the master and slave above would be very much appreciated.

I knew i was a genius, i have obviously asked something way beyond the intelligence of the forum.


Hi Drew,

The only example i have of softI2CMaster is this for reading a realtime clock

#include <I2cMaster.h>

// select software or hardware i2c
#define USE_SOFT_I2C 0

#if defined(__AVR_ATmega1280__)\
|| defined(__AVR_ATmega2560__)
// Mega analog pins 4 and 5
// pins for 168/328 shield on Mega
#define SDA_PIN 58
#define SCL_PIN 59

#elif defined(__AVR_ATmega168__)\
// 168 and 328 Arduinos analog pin 4 and 5
#define SDA_PIN 18
#define SCL_PIN 19

#else  // CPU type
#error unknown CPU
#endif  // CPU type
// An instance of class for software master
SoftI2cMaster rtc(SDA_PIN, SCL_PIN);
#else // USE_SOFT_I2C
// hardware master with pullups enabled
TwiMaster rtc(true);
#endif  // USE_SOFT_I2C

void setup(void) {

  uint8_t add = 1;

  // try read
  do {
    if (rtc.start(add | I2C_READ)) {
      Serial.print("Add read: ");
      Serial.println(add, HEX);;
    //add += 2;
  } while (add);

  // try write
  //add = 0;
  do {
    if (rtc.start(add | I2C_WRITE)) {
      Serial.print("Add write: ");
      Serial.println(add, HEX);
    //add += 2;
  } while (add);

void loop(void){}

As you can see from my earlier post it dosent follow the same format as the wire I2C
the library is posted here

a kindergarten idiot guide would be much appreciated.
i would like to be able to send from the master 1 byte to any slave by its address
and for a slave being poled by the master to receive the byte of data.

i would really appreciate some assistance


I want to use the Ardunio to its max. i need 6 digital pins for relay control, 2 digital pins for soft serial/RS485 and 6 analogue inputs , 2 pins for I2C bus to connect motor servos (MD03s) and an IMU6050. leaving the 2 hardware serial pins for reprogramming if reqd.

I build my own Arduino boards using a boot loaded ATMEGA328 so i can fit as much circuitry as i can to a control board. i could use the Arduino mega instead but i would have to use the mega board instead of my own build- limited expertise and all that

Im still messing around with submersible vehicles and this configuration will save me at least £400 as i wont need a PC104 single board PC on board my vehicle.

i was hoping that someone out on the ether had connected 2 arduinos with softI2C, searched for ages and found nothing. you mentioned the code was just the Master.

is there a way i can have the master join the bus as channel 0 and for eg transmit to address 4 with a value of 200. if i can get this far i can change the slave to use the hardware wire library instead. cheers Jason