Arduino2arduino communication

Hi together,
I need to communicate with 2 arduinos bi-directional in an environment and distance that Bluetooth, LAN, WLAN is no option (50 m with lots of concrete&steel in between). The only hard-wire connection I have is a single 220V powerline between both points.
Factual I need to transfer a 4 digit number in one direction and a 2 digit number in the other every 1-3 seconds.
I tried the KQ330, but they are working only half-duplex and I do not have an idea, how to synchonize them. Theoretical I could switch them from receiving to transmitt using a control-pin; but I'm stuck how to solve this. Or do you have an enlighting idea how to solve my problem?
Or is there an alternative solution? The sunroom 1187 module had an auto-switching mode, but I don't know, where to find them.
Any idea is appreciated.
Yours
Willythecat

Welcome to the forum.

Can you tell more ?
How many wires has that 220V power line ?
What is a sunroom 1187, can you give a link to it ?

In these situations it is best to choose something that is known to work reliable.
Can you put a shielded Cat5 or Cat6 cable there ? It is cheap and the 50 meters is okay for a RS-485. A 4-20mA signal will also work.

Communication over the mains power line is not 100% reliable. For example adding a 2000W chop saw might stop the communication.

Can you get antennas above, line of sight, at both ends? 50m is doable line of sight, so if you can get the elevation, you might be fine.
C

KQ330 : https://sharvielectronics.com/product/kq-330-power-line-carrier-communication-module/
Is there a schematic for that module ?

The half-duplex communication should not be a problem, as long as one Arduino board has the control over the communication.
The main Arduino board could send a command with data or ask for data and wait some time for it.

Many thanks for your first replies and the advice to find alternatives. I'm simply afraid, there are none.
The sunroom1187 is described here: sunrom-601000 - PDFCOFFEE.COM.

I have only the 220 V line (it goes from a basement to the 5th floor) - 3 wires (Ground, Zero, Phase); and this is app. 50 m long.

I have no chance to put an additional cable (otherwise I would have considered the RS 485 or a CAT cable). And I have no chance for antennas in the line of sight (I remember that I built some years ago a WiFi Single beam antennas). The powerline is the only path I have.
I just need to transmitt the value of 2 temperatures (4 digit number) and return two values (one or two digit number) to control 2 power relay. And this only in 1-3 sec time interval.

The KQ330 specs can be found here: Dropbox - KQ330.pdf - Simplify your life

I think, I'm a good beginner in Arduino programming (with 64 :wink: ) and I'm an electronic engineer but only practising hobby wise. I have no clue about C programming.

I connected the both arduinos directly via RS 232 and all worked fine. THe issue is the correct usage of the KQ330 and the correct timing or switching with the modes (receive and transmitt).

Isn't this a classic token ring arrangement with only 2 nodes?
Once one node has finished sending data it send a token then switches to receive mode.
The other node receives the token and switches to transmit mode.

Is it possible to run a 3-core cable along the path of the 220V power line? If so, you can try asyncRS232 protocol.

Hi,
So you have a heating system, with the heat source on or under ground level and the place you want to heat 50m vertically away?
Am I reading that correctly?

What was in place before you had to think of a solution like this?
What was between the room thermostat and the heat source?

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

You could, of course, run a network connection on the 220V mains leads

The timing between the bytes and the half-duplex are no problem. That is just a matter of programming.
If possible, use Arduino Leonardo / Micro / Pro Micro boards. They are 5V boards and have a spare serial port.

The actual baudrate for the KQ330 is 100bps. That means 10 bytes per second.
The manual is confusing.
Luckily someone has done the hard work :smiley: https://github.com/Ixtalo/GarageSensorNode

First try to send data from one Arduino to another via the mains wires, then implement a two-way half-duplex communication.

The token ring by mikb55 with just two nodes will turn out to be almost same thing as I wrote where one board controls the communication. I also like the network-over-mains as mentioned by UKHeliBob.

Hi TomGeorge, yes nearly, but upside-down. :grinning: 5 floors are app 20 meter but in a larger complex building. I CANNOT bring in any other cable. THis is going also x-wise within the complex building and walls.
Before there was just a heating switch (the 3 main cables I have today).
I want a thermostat and intelligent plus a pressure water pump (means, two electric usage systems (pump and Heating) and the heating controlled.

Hi UKHeliBob, Yes, the unidirectional communication is working. I can send from one to the other, but not bi-directional

The bi directional half duplex is my problem. I have no idea how to manage this

Show both the sketches.

Here the roof Mega 256 with the sub-routines
Trans_Temp() = Trnsfer the temperature to the main Unit
Read_Cmd() = to receive the data to switch relays for Pump and heating

I used the structure to build in delays without stopping the entire arduino to transfer the date with controlled delay: "tTime" as a counter , and "tT" as a delay definition) same with "rTime" and "rT".

void Trans_Temp()
{
switch (tTime){ //tTime = transfer timer to avoid timeing conflict
case 0 ... (tT-1):
tTime ++;
break;
case (tT):
int T_Temp = ((W_Temp*100) + A_Temp);
itoa(T_Temp, Temp_Trans,10);
Serial.print ("Temp_Trans =");
Serial.println (Temp_Trans);
Serial3.print (Temp_Trans); // the serial transfer
tTime = 0;
}
}

void Read_Cmd() //Pump & Heater Status
{

switch (rTime) //tTime = transfer timer to avoid timeing conflict
{
case 0 ... (rT-1):
rTime ++;
break;
case (rT):
if (Serial3.available())
{
r_Data = Serial3.parseInt();
Serial3.flush();
Heating = r_Data/10;
Pump = (r_Data - (Heating *10));
if (Heating == 2) digitalWrite (Heat_Pin, HIGH);
if (Pump == 2 ) digitalWrite (Pump_Pin, HIGH);
}
Serial.print ("r_Data =");
Serial.println(r_Data);
Serial.print ("Heat_Status ");
Serial.println (Heating);
Serial.print ("Pump_Status ");
Serial.println (Pump);

rTime= 0;

break;
}
}

And here the main Unit which receives the temp data and transmitts the pump&heating relay data

/******************************************************************//

  • @brief _____Transmit Values
  • @param[in] None
  • @return None
    *********************************************************************/
    void Transmit()
    {
    switch (tTime){ //tTime = transfer timer to avoid timeing conflict
    case 0 ... (tT-1):
    tTime ++;
    break;
    case (tT):
    int t_stat = (t_heat + t_pump);
    itoa (t_stat, t_Data,10);
    Serial2.print(t_Data);
    Serial.print ("t_Stat ");
    Serial.println (t_stat);
    Serial.println (t_Data);
    tTime = 0;
    break;
    }
    }

/******************************************************************//

  • @brief _____ Receive Values

  • @param[in] None

  • @return None
    *********************************************************************/
    void Receive()
    {
    switch (rTime){ //rTime = transfer timer to avoid timeing conflict
    case 0 ... (rT-1):
    rTime ++;
    break;
    case (rT):
    if (Serial2.available())
    {
    r_Data = Serial2.parseInt();

    Serial.print ("r_Data =");
    Serial.println (r_Data);
    iWater_temperature = r_Data/100;
    Air_Temperature = (r_Data - (iWater_temperature*100));
    // Serial.println (iWater_temperature);
    // Serial.println (Air_Temperature);
    }
    rTime = 0;
    break;
    }
    }

the main unit is a ESP32 with level-shifter. In direct connection both is working fine

So I wonder that the 100bps is "VERY" slow?

mega = serial 3, ESP32 = serial2

and I transfer as a temperature just i.e. 6021 = 60 for the water and 21 for the air;
return 11, 12, 21 or 22 for either pump and/or heating off/on

I don't know anything about the KQ330, however, having a look at the wiring diagrams in the link that Koepel posted, it seems like you could just connect the RX and TX lines of both the Arduino’s, to the RX and TX lines of both KQ330.

So basically this diagram, but with the TX line that I added in. You would have that same wiring configuration for BOTH arduino’s. The only difference is the code. (You can also obviously ditch the other stuff, like the humidity sensor)

Since it is half duplex, you could have a Master requester and a Slave responder system. There can only be 1 Master Arduino, and 1 or more slave Arduino’s.

Master Arduino sends the sensor data to the Slave Arduino. Once that data is sent, the master makes a request for data from the slave. The master waits for data to be sent by the slave. Once the slave sends data, the Master can send the sensor data again, and the process repeats indefinitely.

If it’s really that simple of a process, you may just be able to use a RS485 library to do the communication, as both RS485 and KQ330 use the UART protocol.

Such as these one’s; https://www.gammon.com.au/forum/?id=11428, which implement the master/slave approach I talked about, and adds in error checking protocols.

Here's another example, which might be easier to understand;

You would just need to adjust the baud rate to match a usable transmission speed of the KQ330 module's.

Only difference is that RS485 module’s have a pin to enable and disable sending. I don’t know if this KQ330 has one of those, but judging from the diagram from that link, it may not use them.