riverside
Posts: 6
Joined: Tue Jul 05, 2016 1:18 pm

Troubleshooting the serial port connection

Tue Jul 05, 2016 1:25 pm

As a newbie, I am trying to connect a serial device to the Raspberry Pi3 using a MAX3232 adapter (RS232 to TTL). Since even after following the simple steps at http://www.hobbytronics.co.uk/raspberry-pi-serial-port, I am not able to get anything appear on the terminal screen.
Minicom status is shown as offline and no action is happening on the key presses.
Minicom is setup as described in http://processors.wiki.ti.com/index.php ... _in_Ubuntu for serial device /dev/ttyAMA0 (Bps/Par/Bits - 9600 8N1, Hardware and Software Flow Control set to "No")

For troubleshooting to ensure that there are no hardware issues (I tried with two different Pi3 also) with the MAX3232 adapter or the Pi3 itself, I tried to connect the UART TXD and RXD pins - 8 & 10 and was trying minicom again on the Pi.
minicom -b 9600 -D /dev/ttyAMA0, but the results are the same.

Following the posts on this forum, I had made sure the following:
1. Disabled the serial console, using "sudo raspi-config", set enable_uart=1 in /boot/config.txt
2. Disabled the login prompt by disabling the serial getty service

Code: Select all

sudo systemctl stop serial-getty@ttyAMA0.service
sudo systemctl disable serial-getty@ttyAMA0.service
Would really appreciate some help on troubleshooting this.

dgordon42
Posts: 788
Joined: Tue Aug 13, 2013 6:55 pm
Location: Dublin, Ireland

Re: Troubleshooting the serial port connection

Tue Jul 05, 2016 9:07 pm

Report the output of:

Code: Select all

uname -a
and

Code: Select all

cat /boot/cmdline.txt
Dave.

User avatar
liudr
Posts: 687
Joined: Sat Jun 01, 2013 12:11 am
Location: Central MN, USA
Contact: Website

Re: Troubleshooting the serial port connection

Wed Jul 06, 2016 1:33 am

Can you confirm that this device actually works on a windows machine (or whatever OS you use on your main computer)?

If you type "groups" and do you see "dialout" in the response?
Arduino data loggers, user interface, printed circuit board designer since 2009, RPI 3B 2B 2B Zero Jessie, assembly/C/C++/java/python programmer since the 80's

riverside
Posts: 6
Joined: Tue Jul 05, 2016 1:18 pm

Re: Troubleshooting the serial port connection

Wed Jul 06, 2016 7:42 am

Here are the outputs of:

Code: Select all

uname -a
Linux raspberrypi 4.4.13-v7+ #894 SMP Mon Jun 13 13:13:27 BST 2016 armv7l GNU/Linux

cat /boot/cmdline.txt
dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p7 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait
Also, dialout is listed in the groups.

Even before I connect the actual serial device to the Raspberry Pi, I want to ensure that the GPIO serial ports and the adaptors, wires etc. are working fine. Hence I am doing these tests. The inventory list is
1. RS232 to TTL converter module containing a MAX3232 chip
2. RS232 Serial to USB cable

I tried to follow the post http://www.instructables.com/id/Read-an ... pberry-Pi/ and the python scripts are not working. The serial_write.py is not even going through the while loop, may be because it is not able to write to serial.

User avatar
bensimmo
Posts: 4550
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: Troubleshooting the serial port connection

Wed Jul 06, 2016 7:49 am

Try connectinng to /dev/serial0 instead

dgordon42
Posts: 788
Joined: Tue Aug 13, 2013 6:55 pm
Location: Dublin, Ireland

Re: Troubleshooting the serial port connection

Wed Jul 06, 2016 10:28 am

Unfortunately, all the tutorials you have linked to were written before the launch of the Pi 3B, and the Pi 3B uses a different serial bus configuration than previous models.

Your posted '/boot/cmdline.txt' file is configured correctly for serial port use.
Confirm that you have the line

Code: Select all

enable_uart=1
in your '/boot/config.txt' file. It's usually near the end.
If it's not there, or if it says "enable_uart=0', fix it and reboot.

In your Python code, or anywhere you see "/dev/ttyAMA0" or "/dev/ttyS0" in tutorials or instructions, change it to read (as suggested by bensimmo above)

Code: Select all

/dev/serial0
Hope this helps,
Dave.

riverside
Posts: 6
Joined: Tue Jul 05, 2016 1:18 pm

Re: Troubleshooting the serial port connection

Wed Jul 06, 2016 1:15 pm

Thanks for the inputs. I have changed the python scripts to point to /dev/serial1 (there is no /dev/serial0 available)

Code: Select all

pi@raspberrypi:~ $ ls -la /dev/serial1
lrwxrwxrwx 1 root root 7 Jul  6 16:41 /dev/serial1 -> ttyAMA0
pi@raspberrypi:~ $ ls -la /dev/ttyAMA0
crw-rw---- 1 root dialout 204, 64 Jul  6 16:41 /dev/ttyAMA0
/boot/config.txt does have the entry enable_uart=1

Still the python scripts mentioned in http://www.instructables.com/id/Read-an ... pberry-Pi/ does not work!

dgordon42
Posts: 788
Joined: Tue Aug 13, 2013 6:55 pm
Location: Dublin, Ireland

Re: Troubleshooting the serial port connection

Wed Jul 06, 2016 4:38 pm

On the standard setup in a Pi 3B, '/dev/ttyAMA0' and '/dev/serial1' are, as you have discovered, one and the same thing. They are used to talk to the Bluetooth hardware.

Verify that the only 'uart' command in '/boot/config.txt' is "enable_uart=1" with the command:

Code: Select all

grep uart /boot/config.txt
Do you have the file '/dev/ttyS0'?

Have you added any Device Tree entries to '/boot/config.txt'?

If you are unsure, post the output of:

Code: Select all

grep -v "#" /boot/config.txt
Thanks,
Dave.

riverside
Posts: 6
Joined: Tue Jul 05, 2016 1:18 pm

Re: Troubleshooting the serial port connection

Wed Jul 06, 2016 5:04 pm

Dave,

Please find the outputs as you mentioned.

Code: Select all

pi@raspberrypi:~ $ grep uart /boot/config.txt
enable_uart=1
pi@raspberrypi:~ $ ls -la /dev/ttyS0
crw-rw---- 1 root dialout 4, 64 Jul  6 18:46 /dev/ttyS0
pi@raspberrypi:~ $ grep -v "#" /boot/config.txt














dtparam=audio=on

hdmi_force_hotplug=1
enable_uart=1

dgordon42
Posts: 788
Joined: Tue Aug 13, 2013 6:55 pm
Location: Dublin, Ireland

Re: Troubleshooting the serial port connection

Wed Jul 06, 2016 5:41 pm

The outputs you posted are all correct to have a serial port working on a Pi 3B called '/dev/serial0' (that's serial(zero) not serial(Oh))

Does your serial port work if you call it

Code: Select all

/dev/ttyS0
in code?

Thanks,
Dave.

riverside
Posts: 6
Joined: Tue Jul 05, 2016 1:18 pm

Re: Troubleshooting the serial port connection

Thu Jul 07, 2016 7:28 am

Still no luck! Listing the steps I followed.
1.Disabled the serial console, using "sudo raspi-config"
2.Rebooted the Pi

Code: Select all

pi@raspberrypi:~ $ more /boot/cmdline.txt
dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p7 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait
pi@raspberrypi:~ $ dmesg |grep console
[    0.000000] Kernel command line: 8250.nr_uarts=1 dma.dmachans=0x7f35 bcm2708_fb.fbwidth=640 bcm2708_fb.fbheight=480 bcm2709.boardrev=0xa02082 bcm2709.serial=0x95ae101a smsc95xx.macaddr=B8:27:EB:AE:10:1A bcm2708_fb.fbswap=1 bcm2709.uart_clock=48000000 vc_mem.mem_base=0x3dc00000 vc_mem.mem_size=0x3f000000  dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p7 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait
[    0.001334] console [tty1] enabled
3.Ensured that in /boot/config.txt, enable_uart=1
4.Also disabled the ModemManager service, after reading other posts

Code: Select all

systemctl disable ModemManager.service
4.Changed the port to /dev/ttyS0 in the python script

Code: Select all

pi@raspberrypi:~ $ more serial_write.py
#!/usr/bin/env python

import time
import serial

ser = serial.Serial (
        port='/dev/ttyS0',
        baudrate=9600,
        parity=serial.PARITY_NONE,
        stopbits=serial.STOPBITS_ONE,
        bytesize=serial.EIGHTBITS,
        timeout=1
        )
counter=0
while 1:
        print 'writing'
        ser.write('Write counter: %d \n'%(counter))
        time.sleep(1)
        counter += 1
5. The Serial read script is set to read from USB port (GPIO pins connected through the MAX3232 Adapter and USB serial cable)

Code: Select all

pi@raspberrypi:~ $ more serial_read.py
#!/usr/bin/env python

import time
import serial

ser = serial.Serial(
        port='/dev/ttyUSB0',
        baudrate=9600,
        parity=serial.PARITY_NONE,
        stopbits=serial.STOPBITS_ONE,
        bytesize=serial.EIGHTBITS,
        timeout=1
        )

while 1:
        print 'Reading'
        x=ser.readline()
        print x

dgordon42
Posts: 788
Joined: Tue Aug 13, 2013 6:55 pm
Location: Dublin, Ireland

Re: Troubleshooting the serial port connection

Thu Jul 07, 2016 2:16 pm

I'm still not clear why you do not seem to have '/dev/serial0' in your Pi 3B with 'enable_uart=1' in your '/boot/config.txt' file.
Post the output off:

Code: Select all

ls -l /dev/serial*
To successfully run the scripts you linked to here, you would need 2 Pi's. Do you have 2 Pi's connected together, and if so are they both Pi 3B's? How are they connected together?

I'm going to put together a script to check out your serial ports, it will take me a little time to set up and test.

Later,
Dave.

riverside
Posts: 6
Joined: Tue Jul 05, 2016 1:18 pm

Re: Troubleshooting the serial port connection

Thu Jul 07, 2016 4:12 pm

Dave, here is the output:

Code: Select all

pi@raspberrypi:~ $ ls -l /dev/serial*
lrwxrwxrwx 1 root root 7 Jul  5 05:54 /dev/serial1 -> ttyAMA0
In the linked example http://www.instructables.com/id/Read-an ... pberry-Pi/, only one Raspberry Pi is being used with the Serial port connected to the RS232 to TTL Adapter and then the RS232 to USB cable connected back to the same Pi's USB port. I can do the experiment with two Pi3 Bs tomorrow, once I get a second one.

User avatar
bensimmo
Posts: 4550
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: Troubleshooting the serial port connection

Thu Jul 07, 2016 5:04 pm

Might be daft and time consuming.

But could you setup a fresh Raspian image and start again once all the tinkering of the old style, messed something up.

There is a lot of old Raspian pre-Pi3/Jessie era info that does not work anymore, out there if you Google search for instructions.

Just an idea as serial0 really should be there.

I gave up on my Pi3 for serial and my GPS as I transitioned from a wheezy setup through all the updates to Raspian to a now stable UART setup and option and I started to get confused what was and wasn't happening.
I'm happy in pre-Pi3 setup (only thing that ever worked properly for me during that time was to disable the Bluetooth and revert everything back to Pi2 style setup.
dtoverlay=pi3-miniuart-bt

Not a permanent fix for full usage but worth a try

dgordon42
Posts: 788
Joined: Tue Aug 13, 2013 6:55 pm
Location: Dublin, Ireland

Re: Troubleshooting the serial port connection

Thu Jul 07, 2016 6:18 pm

@riverside,
A Raspberry Pi 3B running a kernel 4.4.13, with "enable_uart=1" in '/boot/config.txt' should have the following entries in '/dev':
'serial0', a soft link to 'ttyS0'
'serial1', a soft link to 'ttyAMA0'
'ttyS0', the serial port exposed on pins 8 & 10 of the GPIO connector.
'ttyAMA0', the serial port used internally to talk to the Bluetooth hardware.

Yours clearly does not, so I would suspect your OS and recommend you put a fresh copy of NOOBS (or just Raspbian, your choice) from here as bensimmo suggests above.
riverside wrote:In the linked example http://www.instructables.com/id/Read-an ... pberry-Pi/, only one Raspberry Pi is being used with the Serial port connected to the RS232 to TTL Adapter and then the RS232 to USB cable connected back to the same Pi's USB port. I can do the experiment with two Pi3 Bs tomorrow, once I get a second one.
Ah, now I see what you are doing with the USB to serial converter. This should work with the 2 python scripts running independently on the one Pi.

I do think you have to find the missing 'serial0' before you will get any of this to work.

With a fresh copy of Raspbian you should only have to:
1. Ensure it's up to date with the apt-get update and upgrade commands.
2. Remove "console = serial0 115200" from '/boot/cmdline.txt'
3. Add "enable_uart=1" to the end of '/boot/config.txt'
4. Reboot
to get your serial port working.

Dave.

1593584
Posts: 20
Joined: Mon Jul 04, 2016 4:55 am

Re: Troubleshooting the serial port connection

Fri Jul 08, 2016 10:38 am

I am having the same problem.
When I try to get my Pi tanking to my arduino it just times out on ser.readline() and get stuck on ser.write().
I2C does not work as well.

dgordon42
Posts: 788
Joined: Tue Aug 13, 2013 6:55 pm
Location: Dublin, Ireland

Re: Troubleshooting the serial port connection

Fri Jul 08, 2016 11:17 am

@1593584,
Can you post the output of:

Code: Select all

cat /boot/cmdline.txt
uname -a
grep -v "#" /boot/config.txt
as well.

Thanks,
Dave.

dgordon42
Posts: 788
Joined: Tue Aug 13, 2013 6:55 pm
Location: Dublin, Ireland

Re: Troubleshooting the serial port connection

Fri Jul 08, 2016 4:29 pm

I've managed to reproduce the problem of the missing '/dev/serial0' and '/dev/ttyS0' files.
It's caused by selecting "Disable shell & kernel messages on the serial connection" in the "raspi-config" configuration application.

Run

Code: Select all

sudo raspi-config
and select Advanced Options -> Serial -> and answer YES to the question "Would you like a login shell to be accessible over serial?"
The program should reply with: "The serial interface is enabled"
Reboot.
You will now have to take out the section "console=serial0,11520" from '/boot/cmdline.txt' with a text editor.
cmdline.txt must only contain one line, don't split the line while editing, or try to add comments.
You will still need "enable_uart=1" in '/boot/config.txt', but it should be there from before.
Reboot.
You should now have:

Code: Select all

serial0 -> ttyS0
serial1 -> ttyAMA0
ttyAMA0
ttyS0
in the '/dev' directory, and you serial port should work in code if you call it "/dev/serial0"

Hope this helps,
Dave.

1593584
Posts: 20
Joined: Mon Jul 04, 2016 4:55 am

Re: Troubleshooting the serial port connection

Sat Jul 09, 2016 5:20 am

@dgordon42

Code: Select all

pi@raspberrypi:~ $ cat /boot/cmdline.txt
dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p7 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait
pi@raspberrypi:~ $ uname -a
Linux raspberrypi 4.4.13-v7+ #894 SMP Mon Jun 13 13:13:27 BST 2016 armv7l GNU/Linux
pi@raspberrypi:~ $ grep -v "#" /boot/config.txt

dtparam=audio=on

hdmi_force_hotplug=1
enable_uart=0
pi@raspberrypi:~ $
I already removed "console=serial0,115200".
Also I have reinstalled Raspbian about 5 or 6 times by now.

1593584
Posts: 20
Joined: Mon Jul 04, 2016 4:55 am

Re: Troubleshooting the serial port connection

Sat Jul 09, 2016 5:59 am

Thanks for your suggestion. I've tried it, but I still have the problem, and no data is being transmitted. ttyS0 now links to serial0. Also my python program no longer gets stuck on ser.write().

dgordon42
Posts: 788
Joined: Tue Aug 13, 2013 6:55 pm
Location: Dublin, Ireland

Re: Troubleshooting the serial port connection

Sat Jul 09, 2016 12:46 pm

1593584 wrote:pi@raspberrypi:~ $ grep -v "#" /boot/config.txt

dtparam=audio=on

hdmi_force_hotplug=1
enable_uart=0
Change "enable_uart=0" to "enable_uart=1" in '/boot/config.txt', and reboot.

Dave.

1593584
Posts: 20
Joined: Mon Jul 04, 2016 4:55 am

Re: Troubleshooting the serial port connection

Sun Jul 10, 2016 11:00 am

Thanks again but that did not make a difference.

dgordon42
Posts: 788
Joined: Tue Aug 13, 2013 6:55 pm
Location: Dublin, Ireland

Re: Troubleshooting the serial port connection

Sun Jul 10, 2016 12:42 pm

@1593584,
Can you run a loop back test?
You will have to:
Power down your Pi
Disconnect your Arduino
Connect physical pins 8 and 10 together on the Pi
Reboot

Run this script:

Code: Select all

#!/usr/bin/env python

# Serial port testing

import serial

test_string = "Testing 1 2 3 4"

port_list = ["/dev/serial0", "/dev/serial0", "/dev/ttyS0", "/dev/ttyS0",]

for port in port_list:

    try:
        serialPort = serial.Serial(port, 115200, timeout = 2)
        print "Opened port", port, "for testing:"
        bytes_sent = serialPort.write(test_string)
        print "Sent", bytes_sent, "bytes"
        loopback = serialPort.read(bytes_sent)
        if loopback == test_string:
            print "Received", len(loopback), "valid bytes, Serial port", port, "working \n"
        else:
            print "Received incorrect data", loopback, "over Serial port", port, "loopback\n"
        serialPort.close()
    except IOError:
        print "Failed at", port, "\n"
Dave.

1593584
Posts: 20
Joined: Mon Jul 04, 2016 4:55 am

Re: Troubleshooting the serial port connection

Wed Jul 13, 2016 6:51 am

Thanks Dave. Sorry about the late reply.

Code: Select all

Opened port /dev/serial0 for testing:
Sent 15 bytes
Received incorrect data  over Serial port /dev/serial0 loopback

Opened port /dev/serial0 for testing:
Sent 15 bytes
Received incorrect data  over Serial port /dev/serial0 loopback

Opened port /dev/ttyS0 for testing:
Sent 15 bytes
Received incorrect data  over Serial port /dev/ttyS0 loopback

Opened port /dev/ttyS0 for testing:
Sent 15 bytes
Received incorrect data  over Serial port /dev/ttyS0 loopback


dgordon42
Posts: 788
Joined: Tue Aug 13, 2013 6:55 pm
Location: Dublin, Ireland

Re: Troubleshooting the serial port connection

Wed Jul 13, 2016 9:36 am

Your results indicate that either physical pins 8 and 10 are not connected together, or one (or both) of them has been damaged.

What type of Arduino had you connected to the Pi, and how was it connected. Did you use any form of level shifter on the pins?

Dave.

Return to “Troubleshooting”