canalrun
Posts: 8
Joined: Fri Jun 10, 2016 2:45 am

Pi 3 Serial Issues

Tue Jun 14, 2016 3:00 am

I just received a Pi 3 about a week ago.
Everything seems to be working well except I can't get serial working (using the Rx and Tx pins).

I've had some success, but I'm getting scrambled data.

It would be a great first step if I could just view the reboot console output in a Windows PC terminal window.

My setup:
I have a Windows 10 PC running the RealTerm terminal program. I have tried two different USB to TTY serial adapters. Both do the same thing. I have the RealTerm set up to the correct serial port at 115200 baud, no parity, one stop bit.

Pi 3:
I have the RX, TX, and ground of the serial adapter tied to the TX, RX, and Gnd pins of my 40 pin GPIO Pi breakout proto-board. The Pi 3 is running Jesse, the serial port is enabled in Preferences (I guess this turns on console output).

Using a VNC virtual desktop connection I can open a terminal window and enter "sudo reboot". I watch the console terminal output as the Pi reboots.

The terminal output is about half scrambled characters and half correct looking output. On the RealTerm application window I see their Error LED flashing quite often (This says there was a data error).

After reboot is complete, if I type characters in the RealTerm window, the Pi echoes a nonsense character or sometimes the correct character.

The next thing I will look at is the voltage levels with a scope for the RX and TX. Both USB/serial adapters, I have tried, claim to be 3.3 V on these two pins. As far as I can tell the Pi also likes 3.3 V logic levels.

I've seen some noise that the GPIO adapter converts everything to 5 V logic levels, but I'm not sure of that. Can anyone confirm or deny that the GPIO adapter converts things to 5 V logic?

Can anyone offer some suggestions as to what the problem might be?

Thanks,
Barry.

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

Re: Pi 3 Serial Issues

Tue Jun 14, 2016 11:01 am

Check that the line:

Code: Select all

enable_uart=1
appears in your your "/boot/config.txt" file.
canalrun wrote:I've seen some noise that the GPIO adapter converts everything to 5 V logic levels, but I'm not sure of that. Can anyone confirm or deny that the GPIO adapter converts things to 5 V logic?
The Pi's serial port (and all other GPIO's) work at 3.3V only. Connecting them to a 5V source will destroy your Pi.

Hope this helps,
Dave.

sparkyhall
Posts: 112
Joined: Mon Aug 27, 2012 9:14 am

Re: Pi 3 Serial Issues

Tue Jun 14, 2016 11:37 am

Doesn't the USB to TTY converter expect + & - voltage levels rather than 0V to 3V3 ?

I think you will need a level translater between your GPIO pins and the USB to TTY converter


canalrun
Posts: 8
Joined: Fri Jun 10, 2016 2:45 am

Re: Pi 3 Serial Issues

Tue Jun 14, 2016 2:42 pm

Bingo! Thanks.

They mentioned setting the core frequency to 250, but then one post suggested doing a rpi-update to update to the latest firmware. I did the update to my Pi 3.

The console output now looks correct and when I use a PC RealTerm terminal to connect to the GPIO Rx and Tx I am able to communicate with the console.

One thing I noticed: before the firmware upgrade, when I had selected serial disabled in the Preferences – Interfaces, after boot it created the /dev/ttyS0 and I was able to transfer characters between a minicom on the Pi and a RealTerm terminal on the PC – although the baud rate was wrong, so the characters were garbled.

After the firmware upgrade, the /dev/ttyS0 is no longer created when I choose serial disabled in the Preferences – Interfaces and reboot.

If I choose serial enabled, the /dev/ttyS0 is created, but it is attached to the console and anything I send to it gets treated as console input.

My long-term goal is to have the Pi sending serial data to a PC for display. I could either use the GPIO Rx/Tx /dev/ttyS0 interface or preferably I could use the onboard Bluetooth interface (I haven't tried yet, but does this connect to /dev/ttyAMA0 ?).

I guess I am wondering two things:
1) If I set serial disabled in Preferences – Interface is there a way to create /dev/ttyS0 so that it connects to the GPIO Rx/Tx?
2) Can I use the onboard Bluetooth in SPP mode if I send/receive serial data to /dev/ttyAMA0?

Thanks for the help?
Barry.

User avatar
Cancelor
Posts: 751
Joined: Wed Aug 28, 2013 4:09 pm
Location: UK

Re: Pi 3 Serial Issues

Tue Jun 14, 2016 4:25 pm

So you want to disable system boot messages to the serial port and stop getty using it (i.e. stop the OS from using it) ... but you don't want to disable the port it's self.

Have a look here:- http://elinux.org/RPi_Serial_Connection

and here:- http://elinux.org/Serial_port_programming
Can't find the thread you want? Try googling : YourSearchHere site:raspberrypi.org

canalrun
Posts: 8
Joined: Fri Jun 10, 2016 2:45 am

Re: Pi 3 Serial Issues

Tue Jun 14, 2016 5:45 pm

Cancelor wrote:So you want to disable system boot messages to the serial port and stop getty using it (i.e. stop the OS from using it) ... but you don't want to disable the port it's self.

Have a look here:- http://elinux.org/RPi_Serial_Connection

and here:- http://elinux.org/Serial_port_programming
Great info! Thanks.

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

Re: Pi 3 Serial Issues

Tue Jun 14, 2016 5:52 pm

canalrun wrote:I guess I am wondering two things:
1) If I set serial disabled in Preferences – Interface is there a way to create /dev/ttyS0 so that it connects to the GPIO Rx/Tx?
2) Can I use the onboard Bluetooth in SPP mode if I send/receive serial data to /dev/ttyAMA0?
I understand that you have a Pi 3B, and that it's your first Pi. The history of the Pi's serial ports might help to answer your question:
The Broadcom SOC's in all Pi's come with 2 serial ports, a full port and a mini port. Before the model 3, neither of theses were used internally, so the full port was routed out to the GPIO connector, and called ttyAMA0.

The Pi 3 requires a serial port to talk to it's Bluetooth device, and the Pi's engineers decided to use the full serial port to talk to the Bluetooth chip as it was more capable then the mini serial port, and so the mini serial port was brought out to the GPIO connector, and called ttyS0. This has caused a few problems.

The mini serial port's baud rate is hard wired to the GPU's clock, and so when the GPU's clock speed changed, the baud rate of ttyS0 changed as well. The Pi 3 adjusts it's clock frequencies as demand goes up and down, and with it, ttyS0's baud rate. This is probably what caused the scrambled data in your first post.

The first fix for this problem was to lock down the GPU's clock to a fixed frequency. This was done by adding the line: "core_freq=250" to 'config.txt'. This locks the baud rate of ttyS0, at the cost of a small decrease in the Pi's performance.

The second fix the Pi engineers came up with, was the problem of software backward compatibility with previous model Pi's. Any software written using ttyAMA0 would not work on a Pi 3B, as it calls it's port ttyS0. The second fix was to rename the serial ports on all models to 'serial0', and 'serial1'. On a Pi 3, ttyS0 is mapped to serial0, and on previous models ttyAMA0 is mapped to serial0. This means that software which refers to serial0 will work on all models.

Finally, the line "enable_uart=1" automatically locks the core frequency in a Pi 3, so "core_freq=250" is no longer required. Enabling the serial port in "Preferences" (raspi-config) will automatically add this line if required.

So, to summarize, to use the serial port on all model Pi's running an updated OS, add the line: "enable_uart=1" to '/boot/config.txt, and refer to the port as '/dev/serial0' in code. SystemD normally starts a terminal on this serial port which you are using but, if you don't want a terminal remove the section "console=serial0,115200" from '/boot/cmdline.txt'.

Using this procedure, Bluetooth works normally on the Pi 3.

More here.

Hope this makes sense,
Dave.

User avatar
kolban
Posts: 152
Joined: Fri Dec 04, 2015 1:45 am
Location: Texas, USA

Re: Pi 3 Serial Issues

Tue Jun 14, 2016 9:44 pm

Dave,
MANY thanks for that post ... a VERY informative article. Thank you.
FREE book on Raspberry Pi usage and programming

https://leanpub.com/pi

canalrun
Posts: 8
Joined: Fri Jun 10, 2016 2:45 am

Re: Pi 3 Serial Issues

Wed Jun 15, 2016 1:26 am

dgordon42 wrote: ...
So, to summarize, to use the serial port on all model Pi's running an updated OS, add the line: "enable_uart=1" to '/boot/config.txt, and refer to the port as '/dev/serial0' in code. SystemD normally starts a terminal on this serial port which you are using but, if you don't want a terminal remove the section "console=serial0,115200" from '/boot/cmdline.txt'.

Using this procedure, Bluetooth works normally on the Pi 3.

More here.

while /dev/serial1 points to the other - the BT UART on a Pi3

Hope this makes sense,
Dave.
Thanks for the excellent post.

It's been decades since I played around with anything UNIX-like.

I am convinced my baud rate problems on the console during boot are solved and I could disable the console then communicate with a PC over this serial port.

The next step is to use the Pi 3 onboard Bluetooth and SPP to xfer data to a PC (or Android).

It seems that after pairing and connecting the Pi 3 Bluetooth with my Win10 PC and opening a RealTerm on the PC to the com port associated with the PC's Bluetooth, I should be able to "sudo echo asdf > /dev/serial1" on the PI from a terminal window. I would guess it would send the 4 chars to the PC com via the Bluetooth connection.

However when I try this the Pi terminal window hangs waiting for the action to complete.

For grins I tried "sudo echo asdf > /dev/serial0". It did not hang, but returned "permission denied".

Do I have to configure something else to use the onboard Bluetooth as an SPP serial connection?

Thanks,
Barry.

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

Re: Pi 3 Serial Issues

Wed Jun 15, 2016 2:53 am

canalrun wrote:Do I have to configure something else to use the onboard Bluetooth as an SPP serial connection?
Sorry, can't help with Bluetooth, never used it.

Dave.

x92127
Posts: 6
Joined: Mon Dec 28, 2015 4:56 pm

Re: Pi 3 Serial Issues

Sat Jun 18, 2016 6:15 pm

Love this article as it's the most complete I've seen yet. However, I'm still not connecting via RPI3 serial.

SerialException: could not open port /dev/ttyS0: [Errno 13] Permission denied: '/dev/ttyS0'

ls -l /dev/ttyS0 gives the following results:
crw--w---- 1 root tty 4, 64 June 19 01:21 /dev/ttyS0

groups give the following results:
pi adm dialout cdrom sudo audio video plugdev games users input netdev gpo i2c spi

I have done:
apt-get update
apt-get upgrade
rpi-update

Why is it still not working?

UPDATE: Here's the solution:
http://spellfoundry.com/2016/05/29/conf ... ment-66323

DuncanG
Posts: 3
Joined: Tue Sep 06, 2016 3:22 pm

Re: Pi 3 Serial Issues

Tue Sep 06, 2016 3:32 pm

Debian Jessie - enabling serial on GPIO but without Bluetooth

I'm a bit nervous about posting this but it has worked for me on 3 different Pi models; Pi1B+, Pi2B and Pi3B. Over the last week I had read many column metres of forum posts but nothing worked for my Pi3B so I spent a while doing the following step by step approach and then found it worked on my older Pi models as well. I'm new to Linux so do not claim to know the subtleties but hope this helps.

RS232 serial is all things to all people and was causing me problems over 30 years ago when there was a mix of both 9 and 25 way connectors and we used 'dumb' modems as well. The PC (intelligent) transmits its data on a male 9 pin D type on pin 3 (see http://pinouts.ru/SerialPorts/Serial9_pinout.shtml) and receives on pin 2. To communicate with another intelligent device pin 2 at one end must be connected to pin 3 at the other - transmit to receive - and similarly 3 to 2. The cable to do this is known as a crossed or null-modem cable and has 9 way female connectors at both ends.

Note also that there is a system called flow control which might muddy the waters. To make sure that the device at the other end was ready to accept data there are 2 lines in a full interconnection called RTS and CTS. One end asserts RTS (Ready to Send) and the other end responds with CTS (Clear to Send). There is another method called DTR (Data Terminal Ready) and DSR (Data Set Ready) which use wires in the interconnecting cable. Yet another method of flow control is Xon/Xoff. The point of mentioning this is that you should disable all of these at both ends of your comms link - in Realterm for example hardware flow control should be None and neither Transmit nor Receive should be ticked in Software flow control.

Note also if using Realterm on the PC as I do that, when you have selected the port (Com4 - Prolific Serial in my case), the baud rate (115200) and parity None, 8 Data Bits and 1 Stop bit, you must click on Change for the parameters to take effect. Similar instruction apply to puTTY on the PI and are detailed below.

My plan was to use a Pi as a terminal to display the serial output of some PIC based test equipment that I design and use and I set up a PC running Realterm at 115200N81 - other PC terminal programmes may be simpler - and connected it to the Pi3 using a Serial Pi Plus https://www.abelectronics.co.uk/product ... al-Pi-Plus using a crossed (null modem) lead. The Pi Plus board performs the NECESSARY voltage level translation from the 3.3V used by the Pi logic to the + and - 5V (or greater) used by RS232 in the cable. Do NOT connect RS232 wiring direct to the Pi as it may well destroy it. Note that the PC and the Pi both have 9 pin male connectors which is why the crossed lead is required (or an ordinary 9 pin serial lead plus a null modem adaptor and a gender changer if you must). I have since also used eBay interfaces instead of the Serial Pi Plus (search for max3232 DB9) and they are fine but note that TxD0 on the Pi GPIB header goes to TxD0 on the interface board and RxD0 to RxD0. Be careful to get a male version if using a crossed lead and make sure you use the 3.3V supply on the GPIO header and NOT the 5V or the outputs of the MAX3232 could rise to 5V and damage the Pi. If you get a female version you can use a 'normal' 9 pin RS232 lead but, as the Pi is an intelligent device the convention is that its serial should be a male.

I used the inbuilt Pi console (login shell) output to make sure my hardware was correct before configuring the Pi - as explained below.

Before starting the configuration do sudo rpi-update/sudo apt-get update/sudo apt-get upgrade(rpi-update is firmware)

Use desktop > preferences > Pi Configuration to enable interfaces > serial if it isn't already. Reboot if requested.

Use sudo raspi-config option 1 to expand file system and option 9 then Advanced option A7 to enable 'login shell' (console) if it isn't already - reboot.

If 'login shell' is enabled on the Pi and the hardware and cabling is correct you will see roughly the same text as appears on the Pi monitor during the boot appearing on the PC Realterm screen. At the end of this you can login to your Pi from Realterm (but you will have to click in the Realterm screen first) using Pi and Raspberry defaults. If all of that works you have proved that you can communicate in both directions over the GPIO serial RS232 connection. If it doesn't work, stop here and go back and check your interface & cable.

Use sudo raspi-config 9) Advanced A7) disable login shell (console) - reboot.

For the Pi3 only - use nano to add dtoverlay=pi3-miniuart-bt to the end of /boot/config.txt and reboot. This disables Bluetooth

While you are editing /boot/config.txt you will see that enable_uart=0 appears at the end of config.txt; comment it out - #enable_uart=0 and reboot: this I do not understand but I have not been able to get serial comms on the GPIO pins unless it is commented out!

Install puTTY terminal programme - sudo get-apt install puTTY

Configure puTTY > Category > Session - for serial 115200 on /dev/serial0 and Category > Serial > Speed = 115200, Data = 8, Stop = 1, Parity = N and Flow Control = none. (I recommend that you highlight “Default Settings” in Category > Session and Save). Note that Jessie uses aliases for the serial as you will see if you list devices - ls /dev

Pi->PC should now work and PC->Pi should also work in puTTY @ 115200 Changing the baud rate is simple. If writing in Python use serial0 and neither ttyS0 nor ttyAMA0. The kernel does the translation and your code is more portable.

There are probably more re-boots in there than required but I was keeping tabs on the devices at each step using ls /dev to find when serial(s) appeared and disappeared.

I hope this is of use to Pi users and saves some time and much frustration. If you find an error or omission please let me know and, if you can throw more light on the subject please do!

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

Re: Pi 3 Serial Issues

Wed Sep 07, 2016 8:31 am

@DuncanG, Interesting post. There are a few points I would like to comment on.
DuncanG wrote:For the Pi3 only - use nano to add dtoverlay=pi3-miniuart-bt to the end of /boot/config.txt and reboot. This disables Bluetooth
This does not disable Bluetooth on a Pi 3B, it simply changes which one of the two serial ports built into the Pi's Broadcom SOC processor that is used to talk to the Bluetooth hardware.
If you wish to disable Bluetooth on the Pi 3B, add "dtoverlay=pi3-disable-bt" to the end of '/boot/config.txt'.
Details of all the device tree overlay commands can be found on your Pi in the file '/boot/overlays/README'. It's a long file, this is what it says about the above commands:
/boot/overlays/README wrote:Name: pi3-disable-bt
Info: Disable Pi3 Bluetooth and restore UART0/ttyAMA0 over GPIOs 14 & 15
N.B. To disable the systemd service that initialises the modem so it
doesn't use the UART, use 'sudo systemctl disable hciuart'.
Load: dtoverlay=pi3-disable-bt
Params: <None>


Name: pi3-miniuart-bt
Info: Switch Pi3 Bluetooth function to use the mini-UART (ttyS0) and restore
UART0/ttyAMA0 over GPIOs 14 & 15. Note that this may reduce the maximum
usable baudrate.
N.B. It is also necessary to edit /lib/systemd/system/hciuart.service
and replace ttyAMA0 with ttyS0, unless you have a system with udev rules
that create /dev/serial0 and /dev/serial1, in which case use
/dev/serial1 instead because it will always be correct.
Load: dtoverlay=pi3-miniuart-bt
Params: <None>
By adding "dtoverlay=pi3-miniuart-bt" you have switched the full UART, ttyAMA0, from Bluetooth to the GPIO pins. As ttyAMA0 does not suffer from the fluctuating baud rate problems that plague ttyS0, you are getting away without adding "enable_uart=1" to '/boot/config.txt' to fix the GPU core clock speed. However, Bluetooth is still enabled, and working off ttyS0.
DuncanG wrote:Use sudo raspi-config 9) Advanced A7) disable login shell (console) - reboot.
...
While you are editing /boot/config.txt you will see that enable_uart=0 appears at the end of config.txt; comment it out - #enable_uart=0 and reboot: this I do not understand but I have not been able to get serial comms on the GPIO pins unless it is commented out!
This is, in my opinion, the last 'big problem' with the serial port usage on the Pi. The wording used in 'raspi-config' - "shell and kernel messages on the serial connection" - has lead many (including myself) to think that this will simply prevent a log-in prompt being sent over the serial port to an attached device. However, on a Pi 3B at least (I have not checked earlier models, it's on my to-do list), it completely disables the serial port on the GPIO's by adding "enable_uart=0" to '/boot/config.txt'. I think you have seen this using your excellent troubleshooting tip of monitoring the '/dev' directory between config changes.
To use the serial port on a Pi 3B, you need to enable "shell and kernel messages on the serial connection" in 'Advanced Options'.
DuncanG wrote:If writing in Python use serial0 and neither ttyS0 nor ttyAMA0. The kernel does the translation and your code is more portable.
This is excellent advice and should, as you say, ensure that your code works in all models of the Pi running an up to date OS.

At the risk of repeating myself:
dgordon42 wrote:So, to summarize, to use the serial port on all model Pi's running an updated OS, add the line: "enable_uart=1" to '/boot/config.txt, and refer to the port as '/dev/serial0' in code. SystemD normally starts a terminal on this serial port which you are using but, if you don't want a terminal remove the section "console=serial0,115200" from '/boot/cmdline.txt'.

Using this procedure, Bluetooth works normally on the Pi 3.
I hope this clears a little more mud from the water,
Dave.

DuncanG
Posts: 3
Joined: Tue Sep 06, 2016 3:22 pm

Re: Pi 3 Serial Issues

Wed Sep 07, 2016 10:33 am

Dave,

Thanks for the helpful reply but, please can you help a bit more. Remember, I am only 1 week into actually using a Pi at "low level" as opposed to helping my grandson with his Scratch programmes, so I apologise in advance if some of my observations are a bit dumb.

I wrote that dtoverlay=pi3-miniuart-bt disabled Bluetooth because the Bluetooth icon greyed out, and clicking on it produced "No Bluetooth Adaptor Found" so I do not appear to be able to use Bluetooth although you say "Bluetooth is still enabled, and working off ttyS0". I note that I can edit /lib/systemd/system/hciuart.service as per your quote, in fact it reads as if it would be necessary (and I assume Pi3 with Jessie is udev), but, until I do - no Bluetooth. As I suggested early in my post I do not want Bluetooth so this is academic to me but please can you help clarify for other users.

You suggest that, if you don't want a terminal "remove console=serial0,115200" but does my version "Use sudo raspi-config 9) Advanced A7) disable login shell (console)" not do the same thing?

And, finally, you suggest adding enable_uart=1 to '/boot/config.txt to use /dev/serial0. As I have got away from the fluctuating clock/Baud rate why do I need enable_uart=1. It appears that /dev/serial0 works without enable_uart=1 at least in puTTY and simple Python?

Thanks lots,

Duncan

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

Re: Pi 3 Serial Issues

Thu Sep 08, 2016 5:45 pm

Hi Duncan,
DuncanG wrote:I wrote that dtoverlay=pi3-miniuart-bt disabled Bluetooth because the Bluetooth icon greyed out, and clicking on it produced "No Bluetooth Adaptor Found" so I do not appear to be able to use Bluetooth although you say "Bluetooth is still enabled, and working off ttyS0". I note that I can edit /lib/systemd/system/hciuart.service as per your quote, in fact it reads as if it would be necessary (and I assume Pi3 with Jessie is udev), but, until I do - no Bluetooth. As I suggested early in my post I do not want Bluetooth so this is academic to me but please can you help clarify for other users.
First thing to bear in mind, a Bluetooth service which does not work due to an incorrect configuration is not the same as a Bluetooth service which has been disabled.
The next thing to check is how up to date the version of Raspbian running on your Pi is. Run the command "uname -a" in a terminal, you should get a response like:

Code: Select all

Linux RaspberryPi 4.4.13-v7+ #894 SMP Mon Jun 13 13:13:27 BST 2016 armv7l GNU/Linux
If the version number and date are the same as mine (at the time of writing), then you are up to date.
If the version number and date are earlier than mine, you can update Raspbian with the commands:

Code: Select all

sudo apt-get update
sudo apt-get upgrade
and follow the prompts.
The reason you need an up to date Pi is because of your assumption:
DuncanG wrote:and I assume Pi3 with Jessie is udev
"udev" is a Linux set of rules. They are called whenever Linux detects a new piece of hardware, and tell Linux what to do with that hardware. The Pi people have changed the udev rules for the serial ports several times since the release of the Pi 3, and I suspect that they may change again in the future.
If you are running an up to date version of Raspbian, your '/lib/systemd/system/hciuart.service' file will refer to the serial port as "serial1", older versions will refer to it as "ttyAMA0". I suspect yours has "ttyAMA0".
Booting your Pi with "dtoverlay=pi3-miniuart-bt" in '/boot/config.txt' switches the Bluetooth chip from the default ttyAMA0 full UART to the ttyS0 mini UART. If the '/lib/systemd/system/hciuart.service' file calls the serial port "ttyAMA0", Linux will not be able to find the Bluetooth chip, and may corrupt your serial port by attempting to send Bluetooth data to the port.
If the '/lib/systemd/system/hciuart.service' file calls the serial port "serial1", The updated udev rules will ensure that Linux will always find the Bluetooth chip regardless of which port it's on.

I believe if you update your Pi, your Bluetooth device will no longer appear to be disabled.

If you wish to disable Bluetooth, use "dtoverlay=pi3-disable-bt" instead of "dtoverlay=pi3-miniuart-bt" in '/boot/config.txt', issue the once off command:

Code: Select all

sudo systemctl disable hciuart
in the Terminal, and reboot.
This will do several things. It will disable Bluetooth the way the Pi Software Engineers meant it to be disabled. It will switch the ttyAMA0 full UART onto the GPIO serial port pins, rather than the ttyS0 mini UART. It will remove the need to limit the VideoCore clock to 250MHz, allowing it to go to 450MHz when it's busy, improving video performance (although I've never noticed any difference in practice). In short, it makes the serial port on a Pi 3B the same as the serial port on previous models. (You should still refer to your serial port as "serial0", not "ttyAMA0", although "ttyAMA0" will still work).

I hope this helps to clear up what exactly "dtoverlay=pi3-miniuart-bt" does on a Pi, and why it's not the way to go to disable Bluetooth.
DuncanG wrote:You suggest that, if you don't want a terminal "remove console=serial0,115200" but does my version "Use sudo raspi-config 9) Advanced A7) disable login shell (console)" not do the same thing?
Yes, it does. In the past I, and several posters on here, have had problems using 'raspi-config' to disable a log-in on the serial port. Instead of just disabling the log-in, we found that it disabled the whole port. At the time it took quite a bit of troubleshooting effort to discover this, so I tend not to use or recommend raspi-config, and disable the log-in the "old-fashioned way". If it works for you - fine.
DuncanG wrote:And, finally, you suggest adding enable_uart=1 to '/boot/config.txt to use /dev/serial0. As I have got away from the fluctuating clock/Baud rate why do I need enable_uart=1. It appears that /dev/serial0 works without enable_uart=1 at least in puTTY and simple Python?

If you are using "dtoverlay=pi3-disable-bt" or "dtoverlay=pi3-miniuart-bt" in your '/boot/config.txt' file, than you are using the ttyAMA0 UART as a serial port, and you don't need to use "enable_uart=1". Indeed, using "enable_uart=1" in your configuration will fix the VideoCore clock at 250MHz limiting video performance (although I've never noticed any difference in practice). However, users who wish to use the serial port on a Pi 3 without using either of theses Device Tree Overlays will need to use "enable_uart=1", and I suspect that the majority of users will fall into this category. It is also possible that, in the future, "enable_uart=1" will be required in all models of Pi to enable the serial port.

I don't use Bluetooth on my Pi 3B, but I do use the serial port. I use the "enable_uart=1" method, and I call my Serial Port "serial0" in code. I am aware that I'm taking a small theoretical performance hit in both the serial port and video performance by doing this, but I have not seen any performance problems in reality. The advantage of this method is that I can make full use of Bluetooth in the future without changing anything, and it's simple.
If you wish to disable Bluetooth completely, then use the "dtoverlay=pi-disable-bt" method. This will give you the full performance from both the VideoCore, and the serial port, at the expense of Bluetooth.
If you use the "dtoverlay=pi3-miniuart-bt" method, you get full performance from the VideoCore and the Serial Port, at the expense of a possible reduction in Bluetooth performance. While this is not a problem at the moment, it could become one when Bluetooth drivers for more complex devices then keyboards and mice become available for the Pi.
DuncanG wrote:Remember, I am only 1 week into actually using a Pi at "low level"
You seem to have picked up a lot more on your first week than I did!

Hope this helps,
Dave.

eugene28
Posts: 3
Joined: Wed Sep 14, 2016 1:57 pm

Re: Pi 3 Serial Issues

Wed Sep 14, 2016 2:30 pm

Hi.
Got some issues with connecting my arduino nano v3 to Rpi3.
I got Latest Raspbian. Done distro upgrade.
Added strings to /boot/config.txt
enable_uart=1
dtoverlay=pi3-disable-bt

Disabled
sudo systemctl disable hciuart
sudo systemctl mask [email protected]
And I still get some serial commands(getty or something else) to my Arduino cheap which is on ttyUSB0. I have RPI3 connected with ethernet cable and ssh logged into it.

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

Re: Pi 3 Serial Issues

Wed Sep 14, 2016 5:32 pm

eugene28 wrote:And I still get some serial commands(getty or something else) to my Arduino cheap which is on ttyUSB0
You have connected your Arduino's USB connector to your Pi's USB connector, right?
This means that all the configuration changes you have made, such as:
eugene28 wrote:Added strings to /boot/config.txt
enable_uart=1
dtoverlay=pi3-disable-bt

Disabled
sudo systemctl disable hciuart
sudo systemctl mask [email protected]
have absolutely no effect on your Arduino, as they only affect the Pi's Serial Port on GPIO pins 8 & 10. I suggest that you undo what you have done by running:

Code: Select all

sudo systemctl enable hciuart
sudo systemctl unmask [email protected]
removing the lines:

Code: Select all

enable_uart=1
dtoverlay=pi3-disable-bt
and rebooting.
This will restore your Pi 3B back to it's default condition.

You should be able to communicate with your Arduino via USB using the Arduino IDE, which is available in Raspbian Jessie. (I don't use the Arduino IDE on my Pi's, so I can't test this)

Do not attempt to connect the Pi's Serial Port directly to the Arduino's Serial Port. You must use a Level Converter, otherwise you will destroy your Pi.

Hope this helps,
Dave.

eugene28
Posts: 3
Joined: Wed Sep 14, 2016 1:57 pm

Re: Pi 3 Serial Issues

Wed Sep 14, 2016 7:38 pm

Thank you for your reply. Unfortunately your help is not what I am after. I do not need to have Arduino ide to communicate with Arduino nano. Basically I need to get reed off interference with serial line communication. Arduino nano has built in usb-ttl adapter. When I get it connected it shows up as ttyUSB0 and I get some unwanted serial garbage input.

AppU
Posts: 1
Joined: Tue Oct 04, 2016 12:20 pm

Re: Pi 3 Serial Issues

Fri Oct 07, 2016 9:39 am

Hey everybody,

i am searching for a good and clear instruction for disabling the Bluetooth. I am new in programming and working with raspi 3 too, but there are so many instructions online beginning in march till now and everyone says something else.

so what i want to do is, to sent and receive some messages over the RX and TX pins with a C script. I have found some scripts to start with, but i don't know, if the script is wrong or i have made some wrong settings. to test if i can send and receive, i bridged the pins (with a resistor). I tried that on a pi 2, too, and it works fine, but i know that there are some problems with the new pi 3.

adding to that, i don't need the bluetooth. i wish i could rip it of with a pliers...
i even read that if it is disabled, it already tries to send, or give some sendings in between.
Linux raspberrypi 4.4.21-v7+ #911 SMP Thu Sep 15 14:22:38 BST 2016 armv7l GNU/Linux
thats the info about the Pi i am using.

and all i have done is adding
dtoverlay=pi3-disable-bt
to the config.txt and adding
# Bluetooth abschalten
blacklist btbcm
blacklist hci_uart
to raspi-blacklist.conf. and the line as root
systemctl disable hciuart
is this right? or anything to add? or take away?
the next step is to send and receive with a arduino or other MC. but that is somewhere in the future...
i have found some script s but nothing of it will work and i dont know why. is it the code of the script? or because changing the settings...

does anybode have a code, or can give me a script, to send and receive messages or signals over the TX and RX pins, where i can build on? any ideas or hints?

i am very thankful to you

User avatar
Douglas6
Posts: 4370
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Pi 3 Serial Issues

Fri Oct 07, 2016 1:19 pm

As far as Bluetooth goes, it has nothing to do with UART. But if you really want to 'rip it out with pliers', the 'dtoverlay=pi3-disable-bt' is really all that's needed. The hciuart service will simply fail, but you can disable it if you feel better. I don't believe you need to blacklist anything.
You can test the UART with a program like minicom (you'll need to install it).

Code: Select all

minicom -D /dev/ttyS0
If you can see what you are typing, it's working.

aarushi_mittal
Posts: 40
Joined: Wed Jul 05, 2017 10:16 am
Location: Delhi, India

Re: Pi 3 Serial Issues

Tue Jul 11, 2017 10:48 am

Hi .
I am sending sensor data from arduino to raspberry pi , using a usb.
I want to catch that readings into my java program .

How can it be done ?

I am using a raspberry pi 3 , and it already has enable_uart=1.
I am following this code : http://pi4j.com/example/serial.html

Is there a problem with the code or are the settings for serial communication not done properly on my pi ?
The code only outputs console.print lines , but not the serial.write lines.

Kindly help :?
Aarushi

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

Re: Pi 3 Serial Issues

Tue Jul 11, 2017 11:20 am

aarushi_mittal wrote:Hi .
I am sending sensor data from arduino to raspberry pi , using a usb.
I want to catch that readings into my java program .

How can it be done ?

I am using a raspberry pi 3 , and it already has enable_uart=1.
I am following this code : http://pi4j.com/example/serial.html

Is there a problem with the code or are the settings for serial communication not done properly on my pi ?
The code only outputs console.print lines , but not the serial.write lines.

Kindly help :?
Aarushi
You should start a new thread for a new question.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Please direct all questions to the forum, I do not do support via PM.

Leandro82
Posts: 2
Joined: Tue Jul 18, 2017 8:19 pm

Re: Pi 3 Serial Issues

Tue Jul 18, 2017 8:27 pm

AppU wrote:Hey everybody,

i am searching for a good and clear instruction for disabling the Bluetooth. I am new in programming and working with raspi 3 too, but there are so many instructions online beginning in march till now and everyone says something else.

so what i want to do is, to sent and receive some messages over the RX and TX pins with a C script. I have found some scripts to start with, but i don't know, if the script is wrong or i have made some wrong settings. to test if i can send and receive, i bridged the pins (with a resistor). I tried that on a pi 2, too, and it works fine, but i know that there are some problems with the new pi 3.

adding to that, i don't need the bluetooth. i wish i could rip it of with a pliers...
i even read that if it is disabled, it already tries to send, or give some sendings in between.
Linux raspberrypi 4.4.21-v7+ #911 SMP Thu Sep 15 14:22:38 BST 2016 armv7l GNU/Linux
thats the info about the Pi i am using.

and all i have done is adding
dtoverlay=pi3-disable-bt
to the config.txt and adding
# Bluetooth abschalten
blacklist btbcm
blacklist hci_uart
to raspi-blacklist.conf. and the line as root
systemctl disable hciuart
is this right? or anything to add? or take away?
the next step is to send and receive with a arduino or other MC. but that is somewhere in the future...
i have found some script s but nothing of it will work and i dont know why. is it the code of the script? or because changing the settings...

does anybode have a code, or can give me a script, to send and receive messages or signals over the TX and RX pins, where i can build on? any ideas or hints?

i am very thankful to you
Hi friend,

1° Step) In Preferences -> Raspberry Pi Configuration ->
Interfaces, choose Serial: Enabled and OK.

2º Step) sudo nano /boot/cmdline.txt
Change: console=serial0,115200
For: console=serial1,115200
Reboot...

3º Step) Sorry, I can't program in C, the Python
code for simple byte transfer in Serial GPIO:

#************** SIMPLE BYTE TRANSFER *************
# -*- coding: utf-8 -*-
import serial

ser = serial.Serial('/dev/serial0')
ser.baud = 9600
ser.parity = serial.PARITY_NONE
ser.stopbits = serial.STOPBITS_ONE
ser.bytesize = serial.EIGHTBITS
ser.timeout = 1

print(ser.name) # check which port was really used

dec_num = 55
dado = bytes([dec_num])
ser.write(dado)

ser.close()

'''
Function serial.Serial()
Parameters:
port – Device name or None.
baudrate (int) – Baud rate such as 9600 or 115200 etc.
bytesize – Number of data bits. Possible values: FIVEBITS, SIXBITS, SEVENBITS, EIGHTBITS
parity – Enable parity checking. Possible values: PARITY_NONE, PARITY_EVEN, PARITY_ODD PARITY_MARK, PARITY_SPACE
stopbits – Number of stop bits. Possible values: STOPBITS_ONE, STOPBITS_ONE_POINT_FIVE, STOPBITS_TWO
timeout (float) – Set a read timeout value.
xonxoff (bool) – Enable software flow control.
rtscts (bool) – Enable hardware (RTS/CTS) flow control.
dsrdtr (bool) – Enable hardware (DSR/DTR) flow control.
write_timeout (float) – Set a write timeout value.
inter_byte_timeout (float) – Inter-character timeout, None to disable (default).

Raises:
ValueError – Will be raised when parameter are out of range, e.g. baud rate, data bits.
SerialException – In case the device can not be found or can not be configured.
'''
#************************ END *************************

You can use a osciloscope in Pin 39(Ground) and Pin 8
(TxD USART GPIO) for monitoring the send byte.

Good Luck,
Leandro

User avatar
marciokoko
Posts: 257
Joined: Sat Aug 27, 2016 4:33 pm

Re: Pi 3 Serial Issues

Tue May 15, 2018 4:17 pm

Ok so if i've read this post by dgordon42 and the one linked by x92127 correctly, ttyS0 is software wired to the GPIO pins 14 & 15 (to which ttyAMA0 was hard wired before it was stolen for bt), correct?

And I can indeed still talk serially to that port according to x92127's linked article I would need to (on a rpi3 jessie 2017):

1. Enable GPIO in sudo nano /boot/config.txt

Code: Select all

enable_uart=1
2. In code (python presumable) use serial0 which will reference ttySO on rpi3 (or ttyAMA0)

3. Disable the console:

Code: Select all

sudo systemctl stop [email protected]
sudo systemctl disable [email protected]
4. Remove the console references in sudo nano /boot/cmdline.txt:
dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes root wait
by removing the text in bold.

And then I should be able to do:

Code: Select all

sudo echo asdf > /dev/serial0
in order to send that text from the rpi3 serially out to say an hm10 module to which the rpi3 is connected to over bluetooth?

Return to “General discussion”

Who is online

Users browsing this forum: No registered users and 39 guests