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()
{
delay(100);
}
// 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 = Wire.read(); // receive byte as a character
Serial.print(c); // print the character
}
int x = Wire.read(); // 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
x++;
delay(500);
}
A simple straight forward example code for a SoftI2C approach to bothe the master and slave above would be very much appreciated.
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 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