I have Arduino UNO with expansion board where installed BL module and LED. But now I would like to send some info via USB to work with LED. I have such code for python:
port = serial.Serial(port='...', baudrate=115200, timeout=.1)
print("waiting for arduino...")
line=b""
while not b"READY" in line:
line = port.readline()
port.write(struct.pack('bb', 3, -10))
res = port.readline()
print(res)
for i in range(10):
port.write(struct.pack('bb', 3, 10*i))
res = port.readline()
print(res)
time.sleep(0.5)
port.write(struct.pack('bb', 3, 10))
res = port.readline()
print(res)
and for Arduino:
struct Position {
int8_t freq, color;
};
int8_t color;
int8_t val = -1;
void setup() {
Serial.begin(115200);
pinMode(LED_BUILTIN, OUTPUT);
Serial.println("READY");
pinMode(3, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
}
void loop() {
size_t nb;
if (Serial.available()) {
struct Position pos;
nb = Serial.readBytes((char *)&pos, sizeof(struct Position));
color = pos.color;
val = pos.freq;
}
}
the problem is that when I install this additional board over the Arduino I stop receiving data from the port. I understand that I close RX/TX ports and that’s why I can’t receive anything. But how to do it for communication with board with this expansion board?