Domotica in home

I would suggest you use one of the readily available RS485 modules, usually with a MAX485 line driver/receiver chip on it. There are a lot of existing help guides and tutorials on the web & youtube for Arduino & RS485.

If you are referring to the board above the Pi in your image, then I suspect it's simply implying that the USB-RS485 board is using one of the FTDI FT232 series of chips to handle the USB-serial interface.

but the mega and the uno, have the RX and TX ports onboard, so why to use other prints with it

I'm not sure what you mean by this? Did you mean pins?

EDIT: When using an Arduino UNO (your image in post #20), with only one hardware serial port, it is not advisable to use that same port (ie the Tx & Rx pins) for your RS485 comms. If you were to use SoftwareSerial or AltSoftSerial to create a second serial port for your RS485 comms, then that would leave the original hardware serial port for sketch loading and debugging etc. Note the limitations of a software serial port - max baud rate of 9600 or maybe 19200 if you are lucky.

sorry, with prints, i mean motherboards
its only to make a pin from the slave high or low, so 9600 is good enough

Are you referring to the RS-485 bus direction control lines?

Ok, so if i'm understanding you now, the reason that there are other boards involved (the RS485 modules), is that you have more than 2 devices exchanging data.

For 2 devices you can simply connect board #1 TX -> board #2 RX, and board #1 RX to board #2 TX. That would work over short distances.

Your drawing in post #20 shows 3 UNOs and a PI communicating over some as yet unknown distance using a half duplex RS485 bus. That would be a suitable hard wired way of exchanging data between devices.

the largest distance will be around the 30 mtrs
in total, i want to use 7 slaves

No problem for RS485. I would still suggest you look at the MySensors website as a lot of the work is done for you.

i have found a lot on the site from DroneBot Workshop
so i got 2 arduinos talking with eachother, now working at the next problem, to send commands about ports from the master to the slave

but what to change in the sketch, when i will change a port status on the master and send that to my slave

What sketch? Perhaps post the sketch you are referring to.

I'm not sure I understand your terminology here. From my limited use of another home automation package called Domoticz, there is the fancy PC application front end (I think that is referred to as the controller), there is the interface device between the PC application and your slaves (I think that is referred to as the gateway - perhaps this is your mega?), and then there are your slaves (your UNOs?).

by means of a push button on the master, the master should give a command to one of the slaves, which should make a pin high or low on a slave ( mega or uno )
maybe, i can find out by myself, to what slave the master will send the commando.

this is the sketch for the slave

type or paste code here

/*
I2C Slave Control Demo
i2c-slave-demo-control.ino
Demonstrate use of I2C bus
Receives potentimeter position data
Controls LED blink rate
DroneBot Workshop 2019
https://dronebotworkshop.com
*/

// Include Arduino Wire library for I2C
#include <Wire.h>

// Define Slave I2C Address
#define SLAVE_ADDR 8

// Define LED Pin
int LED = 13;

// Variable for received data
int rd;

// Variable for blink rate
int br;

void setup() {

pinMode(LED, OUTPUT);

// Initialize I2C communications as Slave
Wire.begin(SLAVE_ADDR);

// Function to run when data received from master
Wire.onReceive(receiveEvent);

// Setup Serial Monitor
Serial.begin(9600);
Serial.println("I2C Slave Demonstration");
}

void receiveEvent() {
// read one character from the I2C
rd = Wire.read();
// Print value of incoming data
Serial.println(rd);

}
void loop() {
delay(50);

// Calculate blink value
br = map(rd, 1, 255, 100, 2000);

digitalWrite(LED, HIGH);
delay(br);
digitalWrite(LED, LOW);
delay(br);

}

> Blockquote

this for the master

Blockquote
/*
I2C Master Control Demo
i2c-master-demo-control.ino
Demonstrate use of I2C bus
Master sends potentimeter position data
DroneBot Workshop 2019
https://dronebotworkshop.com
*/

// Include Arduino Wire library for I2C
#include <Wire.h>

// Define Slave I2C Address
#define SLAVE_ADDR 8

// Analog pin for potentiometer
int analogPin = 0;
// Integer to hold potentiometer value
int val = 0;

void setup() {

// Initialize I2C communications as Master
Wire.begin();

}

void loop() {
delay(50);

// Read pot value
// Map to range of 1-255 for flash rate
val = map(analogRead(analogPin), 0, 1023, 255, 1);

// Write a charatre to the Slave
Wire.beginTransmission(SLAVE_ADDR);
Wire.write(val);
Wire.endTransmission();

}

Blockquote

`

So you have one master Arduino (an UNO or a Mega) and several slave Arduinos (which can also be UNOs or Megas). These are all linked together by a half-duplex RS485 link?

the master is a mega
they are linked bij the sda and the scl ports

Ah, you've switched to using I2C as your method of communication.

A couple of comments on your slave code off the top of my head:

  1. I think that receiveEvent is called as part of interrupt handling so you shouldn't print inside that function.
  2. You might want to declare the variable rd as volatile.

I'm confused. You talk about a pushbutton, but your code for the "master" is reading an analogue value from the A0 pin. It appears that one sketch reads the position of the potentiometer, sends it over the I2C bus to a second sketch which varies the rate at which an LED flashes.

thats true, these sketches, are for me, where i try to work further with
So instead of an analogue value, i will use some push buttons
the same number as the slaves

i have switched now to RS485, bcz of the distance
so i must start again with all

Looks like ModBus..
did some myself, few months ago..

ModBus Units

maybe it helps..

good luck.. ~q