2

I am trying to get the uart serial to work but when I try to set the parity the following error comes out.

pi@pi3:~ $ python3
Python 3.4.2 (default, Oct 19 2014, 13:31:11) 
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import serial
>>> ser = serial.Serial('/dev/ttyS0')
>>> ser.parity=serial.PARITY_EVEN
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/serial/serialutil.py", line 347, in setParity
    if self._isOpen: self._reconfigurePort()
  File "/usr/lib/python3/dist-packages/serial/serialposix.py", line 413, in _reconfigurePort
    termios.tcsetattr(self.fd, TERMIOS.TCSANOW, [iflag, oflag, cflag, lflag, ispeed, ospeed, cc])
termios.error: (22, 'Invalid argument')
>>> 

I've been looking for similar problems on the web but to no success. Please help!

  • Some possible causes here stackoverflow.com/questions/5496195/… – Steve Robillard Jul 27 '17 at 10:07
  • 1
    You probably have a Python error, but the secondary port doesn't support parity. – Milliways Jul 27 '17 at 12:07
  • Thank you Steve and Milliways. I guess I have to reinstall Python, disable bluetooth and use the primary port. – Oldman Aug 1 '17 at 6:42
1

On a Raspberry Pi 3, the /dev/ttyS0 attached to the GPIO RX/TX header pins is the less capable mini-UART and it doesn't do parity.

Relative the to more capable UART that was repurposed to Bluetooth on the wireless-capable RPi's, the port now has:

  • No break detection
  • No framing errors detection
  • No parity bit
  • No receive timeout interrupt
  • No DCD, DSR, DTR or RI signals

See https://www.raspberrypi.org/documentation/configuration/uart.md or look in section 2.2 of the datasheet at https://www.raspberrypi.org/documentation/hardware/raspberrypi/bcm2835/BCM2835-ARM-Peripherals.pdf

It is possible to use a /boot/config.txt directive to turn off bluetooth, or switch the UART controlling the Bluetooth.

dtoverlay=dtoverlay=pi3-disable-bt
#dtoverlay=dtoverlay=pi3-miniuart-bt

I've tested the /boot/config.txt dtoverlay=dtoverlay=pi3-disable-bt line on my Raspberry Pi Zero W and it works within python-serial minicom to set the port to 1200 7 bit, odd parity, 2 stop bits. I haven't tested the miniUART for Bluetooth on the RPi-Zero-W.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.