Articole similare

Configurare Raspberry Pi pentru utilizarea interfetei seriale

pyserial-logoraspi tutorial

Descarca pyserial-2.6.tar.gz de aici pypi.python.org/pypi/pyserial, dezarhiveaza-l si instaleaza-l:

wget http://pypi.python.org/packages/source/p/pyserial/pyserial-2.6.tar.gz
tar -zxvf pyserial-2.6.tar.gz
cd pyserial/pyserial-2.6
sudo python setup.py install

Editeaza fisierul de configurare /boot/cmdline.txt: sudo nano /boot/cmdline.txtsi eliminia urmatoarele linii:

console=ttyAMA0,115200
kgdboc =ttyAMA0,115200

Editeaza fisierul /etc/inittab sudo nano /etc/inittabsi elimina urmatoarea linie:

#T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100

Exemplu de utilizare port serial pe Raspberry Pi in Python

import serial

serialPort = serial.Serial(port="/dev/ttyAMA0", baudrate=115200, timeout=0.5, rtscts=False, dsrdtr=False, xonxoff=False, bytesize=serial.EIGHTBITS, parity=serial.PARITY_NONE)

if not serialPort.isOpen():
        serialPort.open()
        
        #write to serial port 
        serialPort.write(txdatabuffer)
        serialPort.flush()
        
        #read from serial port
        while serialPort.inWaiting()>0:
            #inWaiting() returns characters in receive buffer
            rxdatabuffer += serialPort.read([receivebytescount])
            #if receivebytescount missing, will read until EOF
    
        #alternatively you can use readline()
        serialPort.readline()
        rxdatabuffer = rxdatabuffer.decode( "UTF-8" )
        
        serialPort.close()

Nota: ai nevoie de un transceiver de nivel (ex. SP3223), de la 3.3V acceptat de pinii GPIO ai lui Rapsberry Pi la nivel +12V ("0" logic") / -12V ("1" logic) conform standardului RS-232