I have arduino nano which is near my gate. To it some gate wiring is connected so I can detect the state of the gate (closed, closing, open, opening) and the door (wicket) (open, closed). I have arduino mega in my garage connected to RaspberryPi with HomeAssistant. Now I have only two spare cables left (arduinos have already grounds connected). Now, I wanted to send the state of the gate and the door from nano to mega. I thought about I2C (A4,A5 on nano connected to SDA and SCL on mega). This worked perfectly on a prototype setup when I had some test nano close to my mega. Now after switching to actual nano which is around 10 meters away the mega does not seem to receive signals from nano. I realized that I2C protocol has lenght limitation. I need some ideas how to resolve this problem in a quick way
How many possible states for each are you wanting to communicate?
Not more than 10
Really, 10 states for a gate and a door?
All you need is here:
https://forum.arduino.cc/t/serial-input-basics-updated/382007
@Paul_KD7HB No - gate has 4 states (open, closed, openning, closing), I have also door (open - closed) and in the nearest future I will have another sensor (on, off).
@noobmastha Can I use Serial? The arduino mega already uses Serial for constant communication with RaspberryPi
Personally I like using Can-Bus for longer wired communication as it takes care of many of the issues that will be encountered and I don't have deal with them in my code.
the mega has three spare hardware serial ports , e.g. MultiSerialMega
be careful if you have connected Mega Serial (which uses 5Volt logic) to a RPi (which uses 3.3volt logic) - use level converter or potential divider on the Mega Tx line
for 10meter communication you may need to use RS232 or RS485 depending on local conditions
For the long distance, consider RS422 or RS485; RS422 can be transparent to the current Nano code; RS485 will require modifications.
@horace, a wild guess is that OP is using the USB for the comms with the Pi ![]()
could be - I have used both USB serial and the RPi UART GPIO14 TXD and GPIO15 RXD to connect external microcontrollers in the past
You can try 300 baud (30 chars per second) over much longer cables but should use grounded-shield cables!
One name for bare wire, especially long bare wire is "Antenna".
OTOH you can TX/RX using led and detector if the led has a dark background and the detector view is limited to that background and it can be done 2-way for less than a dollar to achieve maybe 9600 baud or better and wire to serial pins.
RS485
CAN
Ethernet
WIFI (with another Microcontroller for example an ESP8266 or an ESP32 on a makerfriendly board with USB)
Now please respond in a quick way what you have chosen.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.