Hello. I read that the difference between a serial communication (uart) and IC2 is that IC2 is only one way, that is, it only sends or receives and not both at the same time.
I am interested in doing serial communication with the RX TX pins, not USB. I have already done it with USB and it works.
I want to do something like the following in Python (it works with 1 USB, I haven't tried it with RX and TX). Who helps me? I don't want to burn anything:
For identification and addressing of one of multiple stations a special protocol is required. Such a protocol is implemented in I2C and can be implemented on top of UART in RS-485 as MODBUS demonstrates.
In no case you can have full duplex communication on a network with more than 2 nodes. An Arduino Mega has 4 UARTs and could communicate full duplex with 4 other stations. Dunno how many UARTs your RasPi has.
1- That is, with the two I2C pins (SDA, SCL) I can use many devices and with the two UART pins (RX, TX) I can only use one device, right?
2- Another question, in the case of I2C, how do I send and receive signals? I do it with serial from my computer, when I press a key my arduinos respond.
import serial
import time
print("Loading")
ser = serial.Serial("/dev/ttyUSB0", 115200, timeout=0)
time.sleep(1)
x = input("Enter data: ")
if x == "a":
ser.write(b'1\n')
data = ser.readlines()
print(data)
As you can see, I am sending signals to the serial monitor and at the same time reading what it receives. Can I do that with I2C? How?
Note: I can use USB for serial communication since the USB ports are numbered, but I think it would be better to use pins directly (besides learning something new doesn't hurt).
But, it only shows how to send the data not how to receive it. I am reading the library documentation: smbus2 · PyPI
... says to use: read_i2c_block_data
Has anyone here used it? Is it the same as serial or is it different? It is not clear to me if I should print the data in Arduino with serial or what I should do.