5

I have a Raspberry Pi B and a Raspberry Pi 3. I am trying to get the Raspberry Pi 3's serial port working. I have put a jumper across pins 8 and 10 to check the serial port is working.

I've executed the following code:

import serial
import time

port = serial.Serial("/dev/ttyS0", baudrate = 9600, timeout = 2)

port.write("test data")

time.sleep(1)

rcv = port.read(9)
print "received", rcv

My problem is that I'm not receiving anything.

I have tried the same code on /dev/ttyAMA0 on the Pi B and it works fine.

I have disabled the console from using the serial port in raspi-config and rebooted.

What could I be doing wrong?

  • Have you seen this raspberrypi.stackexchange.com/questions/45570/… – Steve Robillard Apr 23 '16 at 20:43
  • Thank you for your input. I have switched to using /dev/serial0 and introduced the core_freq=250 line to no avail. – piaaw Apr 23 '16 at 21:11
  • Having the same problem, only using Cpp and wiringPi serial. Similarly I tested it with Pi 2 and the code was working but Pi 3 seems to require some tricks. – ozgeneral May 24 '16 at 23:36
  • where is your "while Ture:" what was the error exactly? – yangfan Mar 8 '17 at 11:36
  • Sounds like you're missing enable_uart=1 in /boot/config.txt. – Dmitry Grigoryev Aug 8 '17 at 16:15
3

Its because in RPI3 ttyS0 is disabled by default. enable the ttyS0 in file sudo nano /boot/config.txt and at the bottom of file change 0 to 1 to enable ttyS0 enable_uart=1 and reboot.

I followed this: https://spellfoundry.com/2016/05/29/configuring-gpio-serial-port-raspbian-jessie-including-pi-3/

0

Make sure the login shell is off and that the harwdare is enable: Use the raspi-config for that. the login shell keeps changing the permission of your port and will cause problems

check the group of /dev/ttyS0 with the command ls -la /dev/ttyS0. The group should be dialout. If not, setup the proper permission with sudo chgrp dialout /dev/ttyS0

-1

first, list all your serial files:

$ ls -l /dev/serial*

then, change /dev/ttyS0 to /dev/serial0 if your serial0 is your ttyS0 device.

  • 3
    This is not exactly an answer to the question, and probably not a good idea. If you want to use a different name, use a symlink (ln -s /dev/ttyS0 /dev/serial0), don't move or delete the original node. – goldilocks Jul 8 '17 at 16:00

protected by Community Jul 24 '18 at 13:22

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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