Each one uses an arduino r4 wifi to drive a DFplayer mini to play back audio and a h-bridge to drive the bell in the phone.
They need to communicate with each other to ring at the same time and to detect when one has been answered or if the phone is off the hook.
Initially I was going to use wifi to connect them and to use the RTC on each device to sync the ringing.
The wifi tests I did were too unreliable - they wouldn't always connect and so I've decided to go with a wired solution.
My intention is to use I2C to send the hook (phone picked up) state between the two devices and for the master device to trigger ringing on the slave.
I' don't have any experience with I2C but have just tried some simple examples to no avail.
After checking it seems there's an issue with the SCA and SDL pins on the digital header of the r4 wifi in that they don't have pullup resistors.
I'm going to play around with them a bit but does anyone have experience of using these.
I have the SDA & SCL pins on both devices connected and they are grounded together. Perhaps I'm missing something simple!
Have tried this example using the A4 & A5 pins and still nothing.
master->
#include <Wire.h>
void setup()
{
Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(9600);
Serial.println("master begin");
}
byte x = 0;
void loop()
{
Serial.println("master 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);
}
Slave ->
#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
Serial.println("slave begin");
}
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
Serial.println("slave event");
}
Will there be wires between the phones ?
How many phones do you want to connect ?
The I2C bus is not what you think it is.
You can not put data in at one end and expect that data comes out at the other end.
It is not Serial/UART bus. You can not just check Wire.available() to check if something has arrived. It is not possible to only use Wire.read() to read something. It is not possible to only use Wire.write() to write something.
The SDA and SCL are digital signals, and the I2C bus can not deal with crosstalk between those two signals. It is best to keep them away from each other.
I've fixed your code tags; please pay a little attention and check after you have made your post
I have no experience with the R4 so can't help.
You are aware that I2C is not intended for use over long distances (something over 25 cm)? You might now have them next to each other but on the expo a few meters apart. People do manage to get it working over long distances (with or without I2C extenders).
How will you ring the bells ?
Do you want to use the coil with the switch. That will cause sparks and so much electric noise, that your Arduino board might stop work.
Is there a way to drive the coil directly from the H-bridge ?
I guess I'll just use serial comms then.
I thought (for some reason - not sure why) that using I2C was better for this for some reason - also hadn't used is to decided to play around. But I can just use software serial I guess.
I've a distance of 3m to run so not sure if this is a problem here too.
I'll just be sending a flag from the slave to the master to say if the device has been picked up
and from the master I'll be sending a trigger flag and a similar flag if it has been picked up.
yes - this bit is all good.
I use a square wave from the arduino and a boost convertor (seen on the top board) to drive the h-bridge and generate a roughly 70Vac square wave.
Is one or two digital signals (plus a GND wire) enough ? Just a digital pin going high.
You can protect the inputs of the Arduino with a resistor in the signal line. For example 1kΩ.
Have you managed to excnage data between two UNOR4WiFi using Software UART Port (SUART)? The SUART netwrok works well even within 30 m using TTL logic.