Skip to content

Instantly share code, notes, and snippets.

@lesp
Created March 11, 2017 16:05
Show Gist options
  • Save lesp/84cc3b91fca3b26149aab81262bb8181 to your computer and use it in GitHub Desktop.
Save lesp/84cc3b91fca3b26149aab81262bb8181 to your computer and use it in GitHub Desktop.
Code to interact with the serial
import serial, time
#Change the port to match the port that you will be using, Windows uses COM3 etc
port = "/dev/ttyACM0"
baud = 115200
while True:
s = serial.Serial(port)
s.baudrate = baud
s.parity = serial.PARITY_NONE
s.databits = serial.EIGHTBITS
s.stopbits = serial.STOPBITS_ONE
data = s.readline()
#Prints the datatype of the variable. I use this to check what is coming from the micro:bit
print(type(data))
#Modify the data being sent and ensure that it is a string
data = str(data)
print(data)
time.sleep(1)
#Looks for a word in the data variable, I used hello
if "Hello" in data:
print("\n Josh smells")
time.sleep(2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment