Skip to content

Instantly share code, notes, and snippets.

@mthri
Created October 26, 2020 12:20
Show Gist options
  • Save mthri/77cc6bd946c1b451affe518eae44c3c2 to your computer and use it in GitHub Desktop.
Save mthri/77cc6bd946c1b451affe518eae44c3c2 to your computer and use it in GitHub Desktop.
PySerial Arduino
import serial
ser = serial.Serial('/dev/ttyACM0', baudrate=9600, timeout=1)
data = ser.readline()
data = str(data, encoding='utf-8')
data = data.strip()
ser.close()
ser.open()
ser.write(b'1')
void setup() {
Serial.begin(9600);
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
if(Serial.available()){
char Command = Serial.read();
if(Command == '1')
digitalWrite(LED_BUILTIN, HIGH);
else
digitalWrite(LED_BUILTIN, LOW);
}
}
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.println("Hello From Arduino");
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment