Created
November 25, 2018 00:55
-
-
Save rudrathegreat/aa474c3e1cdb1a3b8433af94c8983ab5 to your computer and use it in GitHub Desktop.
Raspberry Pi Serial Communication
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
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