Skip to content

Instantly share code, notes, and snippets.

@rudrathegreat
Created November 25, 2018 00:55
Show Gist options
  • Save rudrathegreat/aa474c3e1cdb1a3b8433af94c8983ab5 to your computer and use it in GitHub Desktop.
Save rudrathegreat/aa474c3e1cdb1a3b8433af94c8983ab5 to your computer and use it in GitHub Desktop.
Raspberry Pi Serial Communication
'''
This program is designed to be used on the Raspberry
Pi only or any other device which accepts Python and
can do serial communication.
You will not find the module serial in your Python
which has been downloaded. You need to download it
seperately.
This code originally came from the repository Zumo
Robots, link below -
https://github.com/rudrathegreat/Zumo-Robots
And this program is decoding whatever the Arduino
is trying to tell it (in that case, hello!)
'''
import serial
from time import sleep
PORT = '/dev/ttyUSB0' # Or /dev/ttyACM0
BAUD = 9600
s = serial.Serial(PORT)
s.baudrate = BAUD
s.parity = serial.PARITY_NONE
s.databits = serial.EIGHTBITS
s.stopbits = serial.STOPBITS_ONE
while True:
data = s.readline().decode('UTF-8')
data_list = data.rstrip().split(' ')
print(data_list[0])
sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment