PondSkater
Posts: 3
Joined: Mon Oct 23, 2017 10:24 am

PI 3 serial port use

Mon Oct 23, 2017 2:18 pm

I can't believe its so hard to get the serial port working on the RPI 3.
I'm using standard Raspbian software.
The basic setup I have is PuTTY running on a PC connected to the serial port of the PI 3.
The hardware setup works fine, I can login to a standard serial session using PuTTY which proves the port is working in both directions. So the operating system can use the port reliably but why can't I?

Okay I wasted a lot of time trying to use /dev/ttyAMA0 as most web pages suggest this, later I find out this is now the Bluetooth port on a Pi 3. It seems that no one its interested in correcting all the old out of date information.

Then I hit the Python problem, most of the example Python programs don't work for the reason above and also because you can't send a string directly on a serial port using Python 3. You used to be able to with old Python I think hence all the example code, but again all the web examples seem to be out of date.

Okay so I eventually sorted that out and after messing with the Raspberry Pi configuration tool and the
'raspi-config tool and messing directly with the config file then finally changing the permissions for /dev/ttyS0.

I finally, I finally get to be able to send serial data from the PI to the PC. Great big happy smile, its taken 2 days to do something that should have been easy but I finally got some serial communications going from the Pi to the PC. :D

Then disaster struck, I sent a character from the PC to the PI. It was a 'g' I sent but I suspect it could have been anything. Sending this really upset the PI, It caused the Pi to change back to serial console mode. Not only that its changed the config file somewhere so on reboot the serial port is now back in console mode.

I ran rapsi-config again which showed the 'login shell' had been enabled again so I turn this off. Unfortunately this also turns off the port. So I use the Raspberry Pi configuration tool to turn the port back on but this also puts the port back into serial console mode stopping me being able to use the port again.

Arhhh it really shouldn’t be this hard to use the serial port, the Pi is meant to be user friendly for playing about with like this.

Can anyone please point me to an up to date guide on using the port or at least tell me how to get this working in both directions. Please!

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 22660
Joined: Sat Jul 30, 2011 7:41 pm

Re: PI 3 serial port use

Mon Oct 23, 2017 2:36 pm

Is this any help?

https://www.raspberrypi.org/documentati ... on/uart.md


As for websites being out of date - welcome to the internet. If you find any pages on OUR website that are out of date, we have a documentation repo where you can report issues, and even fix them yourself and send them to us.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
"My grief counseller just died, luckily, he was so good, I didn't care."

Heater
Posts: 12595
Joined: Tue Jul 17, 2012 3:02 pm

Re: PI 3 serial port use

Tue Jan 02, 2018 4:25 pm

Before I waste a whole day trying to understand what is going on here: https://www.raspberrypi.org/documentati ... on/uart.md

And wasting another whole day trying to make it work...

Is there an idiots guide to getting use of the UART on the GPIO header and keeping bluetooth working ?

What on Earth happened? It was easier to get serial ports working in MS/DOS. Only had to fix up some I/O addresses and interrupt numbers :)

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 22660
Joined: Sat Jul 30, 2011 7:41 pm

Re: PI 3 serial port use

Tue Jan 02, 2018 5:27 pm

Heater wrote:
Tue Jan 02, 2018 4:25 pm
Before I waste a whole day trying to understand what is going on here: https://www.raspberrypi.org/documentati ... on/uart.md

And wasting another whole day trying to make it work...

Is there an idiots guide to getting use of the UART on the GPIO header and keeping bluetooth working ?

What on Earth happened? It was easier to get serial ports working in MS/DOS. Only had to fix up some I/O addresses and interrupt numbers :)

Bluetooth happened and that uses up a UART. The page you linked is fairly comprehensive, it's probably the best documentation on it.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
"My grief counseller just died, luckily, he was so good, I didn't care."

Heater
Posts: 12595
Joined: Tue Jul 17, 2012 3:02 pm

Re: PI 3 serial port use

Tue Jan 02, 2018 6:04 pm

So that is a "no" then?

I don't want the bluetooth UART I want whatever other one.

Looks like I have to waste two days on it....ah well.

I have been learning different ways to do the same simple thing, over and over, every year or so since 1980. Why stop now?!

sparkie777
Posts: 121
Joined: Tue Nov 27, 2012 4:37 am

Re: PI 3 serial port use

Wed Jan 03, 2018 6:28 am

Heater wrote:
Tue Jan 02, 2018 6:04 pm
Looks like I have to waste two days on it....ah well.
I have been learning different ways to do the same simple thing, over and over, every year or so since 1980. Why stop now?!
what do you expect the RPi? A ready to use product running out of the box? Why don't you buy a commercial product instead?

Using a RPi always encompasses some kind of development. More or less depending on your project. You have to cope with that or leave it.

After finishing your project successfully you should publicitly document that in a way so that others find it helpful.

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 22660
Joined: Sat Jul 30, 2011 7:41 pm

Re: PI 3 serial port use

Wed Jan 03, 2018 10:27 am

Heater wrote:
Tue Jan 02, 2018 6:04 pm
So that is a "no" then?

I don't want the bluetooth UART I want whatever other one.

Looks like I have to waste two days on it....ah well.

I have been learning different ways to do the same simple thing, over and over, every year or so since 1980. Why stop now?!
The linked documentation is the canonical source. If you are finding it difficult to understand, post here why and I can get it updated to be clearer, or you can make your own changes and submit a pull request.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
"My grief counseller just died, luckily, he was so good, I didn't care."

domdetre
Posts: 1
Joined: Wed Feb 28, 2018 5:48 pm

Re: PI 3 serial port use

Wed Feb 28, 2018 6:26 pm

It's either I am a genius or information on the internet got updated since then, but I was able to set up the serial communication in less than a half hour on my pi3-arduino setup.

I don't see myself as a genius, I guess it has somethng to do with the fact, I work as a software engineer and that gives me a lot of experience in the field. Even though I owe my first raspberry pi 3 for a few weeks, and I have very little knowledge in raspberry.

the docs are not outdated, but different versions of pi works slightly different, so when you google for the information you need to filter by yourself the pi version it targets. It was quite easy to make it work, and my bluetooth running just fine, I used my bt keyboard to type the commands.

I opened the pi terminal used the raspi-config, enabled the serial, but disabled the tty login on the serial, then rebooted. Elevated my privs with sudo su, to avoid permission problems while testing. Connected my arduino to the pi serial via a level shifter. Then opened a python terminal and used the serial package.

Code: Select all

import serial
s = serial.Serial('/dev/serial0', 9600)
s.write('Help;')
s.read(205);
and my help messages just appeared on the screen :)

Note: I didn't use the serial.open method, since it was already open by the system.

Well first of all, because I knew my pi is version 3 and when I searched the docs for the gpio I found a lot docs for pi2 and pi1, I assumed the examples and docs for the old one, so I improvized when absorbed them. Never follow an example or code letter by letter, always try to translate it to your needs.

BTW, arduino has 5V UART and pi has 3.3V uart, so I had to use a protecition circuit, and as far as I know the PC UART uses 12V, which could damage your serial ports on your pi if you connect them directly. Did you use a level shifter or something?

Surbhigupta
Posts: 2
Joined: Mon May 14, 2018 2:18 pm

Re: PI 3 serial port use

Fri May 25, 2018 8:18 am

what level shifter you use?

X0rrify
Posts: 1
Joined: Thu Sep 27, 2018 10:15 am

Re: PI 3 serial port use

Thu Sep 27, 2018 10:21 am

RPi should be straight forward, especially for such trivial tasks like using UART and Bluetooth.
I wasted a lot of time doing my project just to run the Bluetooth on RPi. No, i don't want to use external Bluetooth module, i payed money for this RPi and i want convenient and fast setup. Previously i have used Microchip PIC MCU with Microchip RN-42 Bluetooth module over UART and everything went fine. I setup virtual COM port on my laptop and I was able to send commands from the laptop to the PIC MCU over Bluetooth.
RPi team, you have no excuse, Bluetooth is not an excuse. You should put more effort and fix such stupid problems!
Last edited by X0rrify on Tue Nov 06, 2018 2:30 pm, edited 1 time in total.

davethomaspilot
Posts: 104
Joined: Tue Apr 29, 2014 6:18 pm

Re: PI 3 serial port use

Mon Nov 05, 2018 10:19 pm

I'm having trouble using the PL011 uart on RPi 3B+.

I've disabled bluetooth using this in config.txt (I first tried with the enable_uart=1 before the dtoverlay line)

Code: Select all

#enable_uart=1
dtoverlay=pi3-disable-bt
enable_uart=1
pi3-disable-bt disables the Bluetooth device and restores UART0/ttyAMA0 to GPIOs 14 and 15. It is also necessary to disable the system service that initialises the modem so it doesn't use the UART: sudo systemctl disable hciuart.
I disabled the hciuart, here's the status:

Code: Select all

 sudo systemctl status hciuart
* hciuart.service - Configure Bluetooth Modems connected by UART
   Loaded: loaded (/lib/systemd/system/hciuart.service; disabled; vendor preset: enabled)
   Active: inactive (dead)

Here's my cmdline.txt (to prevent serial0 being assigned as a console):

Code: Select all

dwc_otg.lpm_enable=0 console=tty1 root=PARTUUID=4e6661ed-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait
My c code can open and configure /dev/serial0) (aka "ttyAMA0" without issues.

I can write to the resulting file descriptor, and get a return with the expected numbers of characters written. But, I'm monitoring the TxD pin on an oscope--there's no activity.

The TxD pin goes high when I open /dev/serial0 and goes low when I close it. So, I figure I'm on the right pin (GPIO14) and my instrumentation is working.

I just tried this (after writing all the stuff above):

Code: Select all

dmesg | grep serial
[    0.029638] uart-pl011 3f201000.serial: could not find pctldev for node /soc/[email protected]/uart0_pins, deferring probe
[    1.105365] uart-pl011 3f201000.serial: cts_event_workaround enabled
[    1.113026] 3f201000.serial: ttyAMA0 at MMIO 0x3f201000 (irq = 87, base_baud = 0) is a PL011 rev2
[  413.349384] uart-pl011 3f201000.serial: no DMA platform data
[ 1566.271455] uart-pl011 3f201000.serial: LightTree sets custom speed on ttyAMA0. This is deprecated.
So, I'll try again with a standard baud rate. But, if that's the issue, it's a killer for me, since I have to receive from a device that has a non-standard baud rate (20833).

davethomaspilot
Posts: 104
Joined: Tue Apr 29, 2014 6:18 pm

Re: PI 3 serial port use

Mon Nov 05, 2018 10:42 pm

So, that message is irrelevant. It occurs during the boot process, long before I try writing to /dev/serial0.

But, I tried using a standard baud rate--no difference.

It's like I'm communicating with the UART, but its TxD pin isn't on the header.

I'm stuck at this point.

Any suggestions on how to continue debug would be appreciated!

This is on Stretch, rpi 3B+.

davethomaspilot
Posts: 104
Joined: Tue Apr 29, 2014 6:18 pm

Re: PI 3 serial port use

Tue Nov 06, 2018 12:32 am

I switched rpis, and it's now working as expected (with the swap, haven't tried the BT-disable version yet)

Maybe the TxD output driver was damaged somehow.

Thanks for reading

Return to “Troubleshooting”