6

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?

piaaw
  • 69
  • 1
  • 1
  • 5

3 Answers3

4

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/

Anushree M
  • 56
  • 2
1

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

AlexP
  • 111
  • 1
-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.

goldilocks
  • 58,859
  • 17
  • 112
  • 227
matt
  • 1
  • 4
    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 08 '17 at 16:00