mkoch
Posts: 2
Joined: Thu Jul 28, 2016 8:35 am

RPi3 serial port

Thu Jul 28, 2016 8:45 am

Hi all,

where can I find clear step-by-step instructions how to enable the serial port (ttyS0) on a RPi3 with Raspbian Jessie?
How can Bluetooth be disabled?

Thanks,
Michael

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

Re: RPi3 serial port

Sat Jul 30, 2016 7:20 pm

To enable the serial port on the Pi 3B running Raspbian Jessie:

Ensure Jessie is up to date by running:

Code: Select all

sudo apt-get update
sudo apt-get upgrade
and follow the prompts.

Reboot.

Using a text editor with root privileges, open '/boot/cmdline.txt', and remove the "console=serial0, 115200" section from the file. Do not split the line when editing, the '/boot/cmdline.txt' file must only contain one line. The line should still contain "console=tty1". This prevents Linux from outputting the boot messages on the serial port, and expecting a log in on the serial port.

Open '/boot/config.txt' for editing, and add the line "enable_uart=1" to the file. Ensure that the line "enable_uart=0" is not present, if it is, remove it. This enables the ttyS0 serial port on the GPIO pins 8 and 10. It also fixes the Pi 3's problem of the changing baud rates on the port.

Reboot.

Verify your work with:

Code: Select all

ls -lh /dev/serial*
which should return:

Code: Select all

lrwxrwxrwx 1 root root 5 Jul 26 19:13 /dev/serial0 -> ttyS0
lrwxrwxrwx 1 root root 7 Jul 26 19:13 /dev/serial1 -> ttyAMA0
That's it!
Refer to your serial port device as: "serial0" in code. This procedure will work on all model Pi's running up to date Raspbian Jessie, so your code can run on any Pi. That's 'serialZero', not 'serialOh'

It is no longer necessary to disable Bluetooth to use the serial port on the Pi 3B, but if you wish to do so add:

Code: Select all

dtoverlay=pi3-disable-bt
to '/boot/config.txt', run:

Code: Select all

sudo systemctl disable hciuart
and reboot.
You should still refer to the serial port as "serial0", but that will now point to 'ttyAMA0' in '/dev'.

Don't forget, the Pi's serial port runs at 3.3V, connecting a 5V serial port will damage, and possibly kill, your Pi.

Hope this helps,
Dave.

mkoch
Posts: 2
Joined: Thu Jul 28, 2016 8:35 am

Re: RPi3 serial port

Tue Aug 02, 2016 6:29 pm

Thank you for this detailed answer!

Michael

aee74
Posts: 1
Joined: Tue Apr 11, 2017 6:28 pm

Re: RPi3 serial port

Wed Apr 12, 2017 3:45 pm

[email protected]:~ $ ls -lh /dev/serial*
lrwxrwxrwx 1 root root 7 Apr 11 18:18 /dev/serial0 -> ttyAMA0
lrwxrwxrwx 1 root root 5 Apr 11 18:18 /dev/serial1 -> ttyS0


This is my output.

[email protected]:~ $ dmesg | grep tty
[ 0.000000] Kernel command line: 8250.nr_uarts=1 bcm2708_fb.fbwidth=656 bcm2708_fb.fbheight=416 bcm2708_fb.fbswap=1 dma.dmachans=0x7f35 bcm2709.boardrev=0xa02082 bcm2709.serial=0xfaa9496 bcm2709.uart_clock=48000000 smsc95xx.macaddr=B8:27:EB:AA:94:96 vc_mem.mem_base=0x3dc00000 vc_mem.mem_size=0x3f000000 dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait
[ 0.001343] console [tty1] enabled
[ 0.950035] 3f201000.uart: ttyAMA0 at MMIO 0x3f201000 (irq = 87, base_baud = 0) is a PL011 rev2
[ 2.379544] systemd[1]: Expecting device dev-ttyS0.device...
[ 2.703015] systemd[1]: Starting system-getty.slice.
[ 2.710010] systemd[1]: Created slice system-getty.slice.
[ 2.712943] systemd[1]: Starting system-serial\x2dgetty.slice.
[ 2.719813] systemd[1]: Created slice system-serial\x2dgetty.slice.


I've connected my serial device through a ttl to rs232 converter but still no communication.

How can I troubleshoot if my rpi3 (jessie lite) is capable of receiving?

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

Re: RPi3 serial port

Wed Apr 12, 2017 8:07 pm

aee74 wrote:I've connected my serial device through a ttl to rs232 converter but still no communication.
Post a link to the model of ttl to rs232 converter you are using. Many of these operate at 5V, and this can damage a Pi if connected to it's GPIO pins.

Also, post the output of these three commands:

Code: Select all

uname -a
cat /boot/cmdline.txt
grep uart /boot/config.txt
Dave.

sreeuma
Posts: 1
Joined: Sat Nov 25, 2017 8:22 am

Re: RPi3 serial port

Sat Nov 25, 2017 8:30 am

[email protected]:~ $ ls -lh /dev/serial*
lrwxrwxrwx 1 root root 7 Nov 25 07:51 /dev/serial0 -> ttyAMA0
lrwxrwxrwx 1 root root 5 Nov 25 07:51 /dev/serial1 -> ttyS0
[email protected]:~ $ uname -a
Linux raspberrypi 4.9.59-v7+ #1047 SMP Sun Oct 29 12:19:23 GMT 2017 armv7l GNU/Linux
[email protected]:~ $ cat /boot/cmdline.txt
dwc_otg.lpm_enable=0 console=tty1 root=PARTUUID=55afe4b2-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait quiet splash plymouth.ignore-serial-consoles logo.nologo vt.global_cursor_default=0
[email protected]:~ $ grep uart /boot/config.txt
enable_uart=1
[email protected]:~ $ dmesg | grep tty
[ 0.000000] Kernel command line: 8250.nr_uarts=1 bcm2708_fb.fbwidth=1024 bcm2708_fb.fbheight=768 bcm2708_fb.fbswap=1 vc_mem.mem_base=0x3ec00000 vc_mem.mem_size=0x40000000 dwc_otg.lpm_enable=0 console=tty1 root=PARTUUID=55afe4b2-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait quiet splash plymouth.ignore-serial-consoles logo.nologo vt.global_cursor_default=0
[ 0.000309] console [tty1] enabled
[ 0.770312] 3f201000.serial: ttyAMA0 at MMIO 0x3f201000 (irq = 87, base_baud = 0) is a PL011 rev2
[email protected]:~ $ ^C
[email protected]:~ $


I am also hv a same problem to communicate serial...I got a garbage value..pls reply..

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

Re: RPi3 serial port

Sat Nov 25, 2017 6:05 pm

@sreeuma,
Can you post the output of:

Code: Select all

grep -v -e ^$ -e ^# /boot/config.txt
Thanks,
Dave.

rjie
Posts: 4
Joined: Sun Sep 09, 2018 8:22 pm

Re: RPi3 serial port

Sun Sep 09, 2018 8:24 pm

Hello.
Is anybody still here in this branch?

PhatFil
Posts: 1308
Joined: Thu Apr 13, 2017 3:55 pm
Location: Oxford UK

Re: RPi3 serial port

Mon Sep 10, 2018 12:12 am

rjie wrote:
Sun Sep 09, 2018 8:24 pm
Hello.
Is anybody still here in this branch?
Doubt it .. its an old dead thread, if your having problems your probably better off starting your own discussion..


welcome to the forum btw ..

rjie
Posts: 4
Joined: Sun Sep 09, 2018 8:22 pm

Re: RPi3 serial port

Mon Sep 10, 2018 11:35 am

PhatFil wrote:
Mon Sep 10, 2018 12:12 am


welcome to the forum btw ..
Thanks.

Well, you're still here, right?(:
I'm not sure how this works, because yesterday I wrote a message here, still can't see it.
Anyway, i've got a question about serial port. maybe, somebody knows..
I've got a cable, RJ45 to USB. Have no idea where it came from and never used it. Is there a way to connect a serial device to USB port of RP3 with it to listen and capture serial data?

Thank you in advance.
Best regards.

PhatFil
Posts: 1308
Joined: Thu Apr 13, 2017 3:55 pm
Location: Oxford UK

Re: RPi3 serial port

Mon Sep 10, 2018 2:36 pm

rjie wrote:
Mon Sep 10, 2018 11:35 am
PhatFil wrote:
Mon Sep 10, 2018 12:12 am


welcome to the forum btw ..
Thanks.

Well, you're still here, right?(:
I'm not sure how this works, because yesterday I wrote a message here, still can't see it.
Anyway, i've got a question about serial port. maybe, somebody knows..
I've got a cable, RJ45 to USB. Have no idea where it came from and never used it. Is there a way to connect a serial device to USB port of RP3 with it to listen and capture serial data?

Thank you in advance.
Best regards.
Probably not, afaik the RS485 protocol cabling shares the same/similar rj45 connectors as your network and patch cables.
https://en.wikipedia.org/wiki/RS-485
http://www.powersoft-audio.com/en/docma ... port/file
However you can get usb to rj45/network sockets that will allow a usb to lan connection
https://uk.rs-online.com/web/p/products ... lsrc=aw.ds

which is for providing network coms via a usb port not serial coms the other way,,

as a new contributor, your first posts may be under admin scrutiny to check your not a spam-bot, or other such malicious entity,

To achieve your goal a usb/ftdi device that suports 3.3v vcc and coms, such as https://www.ebay.co.uk/i/262285972686?chn=ps Not a recommendation of the seller...can be used to connect to the pi for just what you want.

rjie
Posts: 4
Joined: Sun Sep 09, 2018 8:22 pm

Re: RPi3 serial port

Mon Sep 10, 2018 2:57 pm

PhatFil wrote:
Mon Sep 10, 2018 2:36 pm

Probably not, afaik the RS485 protocol cabling shares the same/similar rj45 connectors as your network and patch cables.
https://en.wikipedia.org/wiki/RS-485
http://www.powersoft-audio.com/en/docma ... port/file
However you can get usb to rj45/network sockets that will allow a usb to lan connection
https://uk.rs-online.com/web/p/products ... lsrc=aw.ds
Thanks for the answer.

But wait. I am sure that device I need to connect uses RS232 protocol. And I use self-made RJ45 to RJ45 cable to connect a couple of those devices. One of those is connected to the laptop via RJ45 to DB9 cable. I'm considering use of RP3 instead of laptop..
Cannot I just use this USB to RJ45 cable to connect the device to RP3, reprogram a USB port and that's it?

Thank you in advance.
Best regards.

PhatFil
Posts: 1308
Joined: Thu Apr 13, 2017 3:55 pm
Location: Oxford UK

Re: RPi3 serial port

Tue Sep 11, 2018 7:03 am

if the cable works with a pc to establish a serial connection via usb, Yes it should work just the same plugged into a pi usb port.

just be mindful of the different operating voltages of different standards rs232 iirc is mainly 12v, usb 5v, and if connecting directly to Rx/Tx on the pi its a 3v3 system.

I am far from expert only being aware of the fact a 5v coms system connected to a 3v3 pi directly is likely to let out all the magic smoke.
the pi usb ports are standard 5v just not the gpio/comms pins

rjie
Posts: 4
Joined: Sun Sep 09, 2018 8:22 pm

Re: RPi3 serial port

Tue Sep 11, 2018 5:22 pm

Oh, alright. Thank you very much.
I need to think about all that..

Return to “Interfacing (DSI, CSI, I2C, etc.)”