This is my first post so please excuse if it's not perfect.
I'm currently having some problems with hooking up my Arduino Uno board with my Raspberry. I want to create a small personal smart home and for that I want to use some Arduino modules.
I'm already strugling with the first step getting the two systems to exchange data. I have tried all kinds of web guides but nothing has worked for me.
The Arduino output when entering the Serial Screen on port 9600 works fine.
Here is my Python code:
import serial
import time, os
os.system('clear')
s = serial.Serial('/dev/ttyACM0', 9600) # Namen ggf. anpassen
time.sleep(5) # der Arduino resettet nach einer Seriellen Verbindung
s.close()
def loop():
try:
s.open()
print('opened')
except:
print("open")
s.write(b"test")
time.sleep(1)
print(">pre-response")
response = s.readline()
print(response)
print(">past-response")
try:
for i in range(5):
loop()
print(i)
time.sleep(2)
except KeyboardInterrupt:
print("shutting down...")
s.close()`
And here is my Arduino code (C++):
void setup() {
Serial.begin(9600);
}
void loop() {
if (Serial.available()) {
byte nr = Serial.read();
//Serial.print("Folgender char wurde empfangen: ");
Serial.println(nr, DEC);
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…