shepard11
Posts: 4
Joined: Wed Jul 12, 2017 3:13 pm

ttyS0 Problems

Thu Jul 13, 2017 8:35 am

Hello,
I work on the development of a system using Raspberry Pi3. I had a issue with the ttyS0. I try to make communicate my raspberry with a module GSM.

When I launch my code nothing appears on my screen in spite of my printf.
I have to try to initialize the exit while following various presentations on Internet. But I revealed Bus error.
for example:
I have thus to check that my ports sérial was open. I have also to check in my C++ code which I gave well the good exit.

After that, i use a Python code to see, if my port work.

Code: Select all

import serial
test_string = "Je teste le port série 1 2 3 4 5"
port_list = ["/dev/ttyAMA0", "/dev/ttyAMA0", "/dev/ttyS0", "/dev/ttyS0",]
for port in port_list:
  try:
    serialPort = serial.Serial(port, 9600, timeout = 2)
    print "Port Série ", port, " ouvert pour le test :"
    bytes_sent = serialPort.write(test_string)
    print "Envoyé ", bytes_sent, " octets"
    loopback = serialPort.read(bytes_sent)
    if loopback == test_string:
      print "Reçu ", len(loopback), "octets identiques. Le port", port, "fonctionne bien ! \n"
    else:
      print "Reçu des données incorrectes : ", loopback, " sur le port série ", port, " bouclé \n"
    serialPort.close()
  except IOError:
    print "Erreur sur ", port, "\n" 
I received only error messages. If one people have a idea, that could largely help me.

I thank you for your assistance.
Best regards

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1361
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: ttyS0 Problems

Thu Jul 13, 2017 9:51 am

On a Pi3 in the standard configuration ttyS0 is the "primary" UART (also called /dev/serial0) and is expected to be used as a serial console. However, ttyS0 is disabled by default.

You can use "raspi-config" utility to enable the UART:
1. Under "Interfacing Options", choose "Serial".
2. Say "No" when it asks if you want a login shell over serial.
3. Say "Yes" when asked if you want the hardware enabled.
4. Finish, then accept the offer to reboot.

Behind the scenes, the UART is enabled with "enable_uart=1" in /boot/config.txt, and the serial console is enabled with "console=serial0,115200" (or "console=ttyS0,115200") in /boot/cmdline.txt .

If the UART is disabled /dev/ttyS0 won't exist. If the UART is enabled but the login console is also enabled then you will get permissions errors on /dev/ttyS0. If you want to understand the cause of the problem before trying to fix it, run this and report the output:

Code: Select all

ls -l /dev/ttyS0 /dev/ttyAMA0

bensimmo
Posts: 1821
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: ttyS0 Problems

Thu Jul 13, 2017 9:52 am

Have you enabled the serial port and disabled the console ?
If not you can do this in raspi-config or manually edit the two files.

Why are you testing two ports? To see which Pi you are on. They are still both there on a Pi3.
if you use /dev/serial0 you will get the port connecting to the GPIO pins.


EDIT / What he said above :-)

shepard11
Posts: 4
Joined: Wed Jul 12, 2017 3:13 pm

Re: ttyS0 Problems

Tue Jul 18, 2017 9:15 am

Hello

I used your method to resolve my problem. Indeed, my error bus became a Segmentation Error. I use WirringPi library to send AT command to mmy FTP server. I receive 0 Bytes.

It's possible to see on the table. In the left of TxD and RxD. There are ALT5. Is it normal?
| BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |
+-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
| | | 3.3v | | | 1 || 2 | | | 5v | | |
| 2 | 8 | SDA.1 | IN | 1 | 3 || 4 | | | 5v | | |
| 3 | 9 | SCL.1 | IN | 1 | 5 || 6 | | | 0v | | |
| 4 | 7 | GPIO. 7 | OUT | 0 | 7 || 8 | 1 | ALT5 | TxD | 15 | 14 |
| | | 0v | | | 9 || 10 | 1 | ALT5 | RxD | 16 | 15 |
| 17 | 0 | GPIO. 0 | IN | 0 | 11 || 12 | 0 | IN | GPIO. 1 | 1 | 18 |
| 27 | 2 | GPIO. 2 | IN | 0 | 13 || 14 | | | 0v | | |
| 22 | 3 | GPIO. 3 | IN | 0 | 15 || 16 | 0 | IN | GPIO. 4 | 4 | 23 |
| | | 3.3v | | | 17 || 18 | 0 | IN | GPIO. 5 | 5 | 24 |
| 10 | 12 | MOSI | ALT0 | 0 | 19 || 20 | | | 0v | | |
| 9 | 13 | MISO | ALT0 | 0 | 21 || 22 | 0 | IN | GPIO. 6 | 6 | 25 |
| 11 | 14 | SCLK | ALT0 | 0 | 23 || 24 | 1 | OUT | CE0 | 10 | 8 |
| | | 0v | | | 25 || 26 | 1 | OUT | CE1 | 11 | 7 |
| 0 | 30 | SDA.0 | IN | 1 | 27 || 28 | 1 | IN | SCL.0 | 31 | 1 |
| 5 | 21 | GPIO.21 | IN | 1 | 29 || 30 | | | 0v | | |
| 6 | 22 | GPIO.22 | IN | 1 | 31 || 32 | 0 | IN | GPIO.26 | 26 | 12 |
| 13 | 23 | GPIO.23 | IN | 0 | 33 || 34 | | | 0v | | |
| 19 | 24 | GPIO.24 | IN | 0 | 35 || 36 | 0 | IN | GPIO.27 | 27 | 16 |
| 26 | 25 | GPIO.25 | IN | 0 | 37 || 38 | 0 | IN | GPIO.28 | 28 | 20 |
| | | 0v | | | 39 || 40 | 0 | IN | GPIO.29 | 29 | 21 |
+-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
| BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |
Moreover, I used command ls -l /dev. I receive that message.
crw--w---- 1 root tty 4, 64 juil. 18 10:55 ttyS0
I can't find console=ttyS0, 115200 in the cmdline.txt.
For send my command, i use this function.

Code: Select all

unsigned int SendcommandAT( const char* ATcommand, const char* expected_answer, unsigned int timeout, int handle)
{
	
	 
	unsigned int answer=0;
	char response[100];
	clock_t previous;
	
	memset(response, 0, 100);    // Initialize the string
	
	usleep(100*1000);

	//std::cout << "serialFlush" << std::endl;
	serialFlush( handle );
	std::string str(ATcommand);
	str += '\r';
	//std::cout << "str : " << str << std::endl;
	char c = '0';
	unsigned i=0;
	while( c != '\r' )
	{	
		c = str[i];
		i++;
		serialPutchar( handle, c );
	}
	//std::cout << "commande envoyée" << std::endl;
        unsigned int x = 0;
	previous = clock();

	std::cout << "lecture de la réponse..." << std::endl;
	do
	{
	//		std::cout << "serialDataAvail( handle ) : " << serialDataAvail( handle ) << std::endl;
	//char c;
	//std::cin >> c;
		if( serialDataAvail( handle ) != 0 )
		{
//std::cout << "x" << x  << std::endl;
			response[x] = serialGetchar( handle );
//std::cout << "x" << x  << std::endl;
			std::cout << response[x];
//std::cout << "x" << x  << std::endl;
			x++;
//std::cout << "x" << x  << std::endl;
			if( strstr( response, expected_answer ) != NULL )
			{
				std::cout << std::endl;// << expected_answer << std::endl;
				answer = 1;
			}
		}
	}
	
	while((answer == 0) && ((clock() - previous) < timeout*1000));

        return answer;
};
Can you give me your opinion? I can make an error.

I test two ports because i wanted to find an available port.


Thank you for your help
Best regard

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1361
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: ttyS0 Problems

Tue Jul 18, 2017 9:19 am

The permissions on /dev/ttyS0 make me think that getty has created a console on it. Run these commands and post the results:

Code: Select all

sudo apt-get install lsof
sudo lsof /dev/ttyS0
cat /proc/cmdline

shepard11
Posts: 4
Joined: Wed Jul 12, 2017 3:13 pm

Re: ttyS0 Problems

Tue Jul 18, 2017 9:37 am

I execute all of your command.

sudo lsof /dev/ttyS0
lsof: WARNING: can't stat() fuse.gvfsd-fuse file system /run/user/1000/gvfs
Output information may be incomplete.
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
agetty 624 root 0u CHR 4,64 0t0 1158 /dev/ttyS0
agetty 624 root 1u CHR 4,64 0t0 1158 /dev/ttyS0
agetty 624 root 2u CHR 4,64 0t0 1158 /dev/ttyS0
cat /proc/cmdline
8250.nr_uarts=1 bcm2708_fb.fbwidth=1280 bcm2708_fb.fbheight=1024 bcm2708_fb.fbswap=1 vc_mem.mem_base=0x3dc00000 vc_mem.mem_size=0x3f000000 wc_otg.lpm_enable=0 console=ttyS0,115200 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait
After that, i execute my code. I find a Bus error.

bensimmo
Posts: 1821
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: ttyS0 Problems

Tue Jul 18, 2017 9:39 am

8250.nr_uarts=1 bcm2708_fb.fbwidth=1280 bcm2708_fb.fbheight=1024 bcm2708_fb.fbswap=1 vc_mem.mem_base=0x3dc00000 vc_mem.mem_size=0x3f000000 wc_otg.lpm_enable=0 console=ttyS0,115200 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait



Have another look in
/boot/cmdline.txt

for console=ttyS0,115200 ( or console=serial0,115200 )

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1361
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: ttyS0 Problems

Tue Jul 18, 2017 9:43 am

Yes, bensimmo is correct. The lsof commands shows that agetty is using /dev/ttyS0, which is explained by your cmdline.txt which includes "console=ttyS0,115200" or "console=serial0,115200". Just delete that part and try again.

shepard11
Posts: 4
Joined: Wed Jul 12, 2017 3:13 pm

Re: ttyS0 Problems

Tue Jul 18, 2017 10:24 am

Thank you very much! :D
My problem has been destroy!

pablok
Posts: 37
Joined: Thu Dec 26, 2013 4:46 pm
Location: Westerkwartier, Groningen (NL)

Re: ttyS0 Problems

Sat Nov 11, 2017 11:28 am

Dear Forum Members,

I am learning about the esp8266 and a serial connection to it. Found the 3.3Volts from the raspberry pi type A probably has a handicap.
I moved the setup to a raspberry zero in the hope that works better, but found "plymouth.ignore-serial-consoles" in the /boot/cmdline.txt and have no idea what the consequences of this mention in the file are for the serial connection I need.

Please advise,

pablok

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1361
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: ttyS0 Problems

Sat Nov 11, 2017 11:39 am

Plymouth is the application that shows the splash-screen during booting. "plymouth.ignore-serial-consoles" tells it not to send any tracing or diagnostic output to serial consoles.

If you want any more help you'll have to explain what you are trying to achieve, what you have done so far, and what happened.

pablok
Posts: 37
Joined: Thu Dec 26, 2013 4:46 pm
Location: Westerkwartier, Groningen (NL)

Re: ttyS0 Problems

Sun Nov 12, 2017 2:56 pm

What I want is to use my raspberry, in stead of some arduino. I became inspired by the videos and site from Andreas Spiess 'the guy with the Swiss accent' and www.sensorsiot.org/.
The first thing I wanted to do is to use the eps8266 as a wi-fi connection on my pi (zero). When the esp8266 is powered it starts a wi-fi signal but I want to use it in my own home network.

In the cmdline.txt I removed the terms with ttySomeThing.
In the config.txt I checked that uart is enabled.
The setting for the serial login shell is disabled and the serial interface is enabled by way of raspi-config.

Installed esptool.py and last night provided for a seperate power supply for the esp8266.

Code: Select all

sudo esptool.py --chip esp8266 --port /dev/ttyAMA0 -b 74880 chip_id
esptool.py v2.1
Connecting........_____....._____....._____....._____....._____....._____....._____....._____....._____....._____

A fatal error occurred: Failed to connect to ESP8266: Invalid head of packet ('\xba')
As it is busy I can see the blue led flashing.

This was what I got back after a reset. Most of the times I receive
"A fatal error occurred: Failed to connect to ESP8266: Timed out waiting for packet header"

This is/was true for the raspi A without seperate power as well.

Please give some guidance,

pablok

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1361
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: ttyS0 Problems

Mon Nov 13, 2017 2:59 pm

Discussing ttyAMA0 problems in a thread about ttyS0 is a bit misleading, but anyway...
In the cmdline.txt I removed the terms with ttySomeThing.
Have you also checked for serial<n>? serial0 is an alias for the primary/console UART and serial1 refers to the other UART, used for Bluetooth on Pi 3B and Zero W. On a Zero, serial0 = ttyAMA0 and serial = ttyS0.

Code: Select all

sudo esptool.py --chip esp8266 --port /dev/ttyAMA0 -b 74880 chip_id
Is 74880 the correct initial baud rate ?:

Code: Select all

    # Default baudrate. The ROM auto-bauds, so we can use more or less whatever we want.
    ESP_ROM_BAUD    = 115200
...
        initial_baud = min(ESPLoader.ESP_ROM_BAUD, args.baud)  # don't sync faster than the default baud rate
Because 74880 is less than 115200 it is used as the initial baudrate, which presumably will only work if the ESP8266 agrees.

pablok
Posts: 37
Joined: Thu Dec 26, 2013 4:46 pm
Location: Westerkwartier, Groningen (NL)

Re: ttyS0 Problems

Mon Nov 13, 2017 7:49 pm

What would be the best location for a thread concerning ttyAMA0?
I am quite willing to change.

My cmdline.txt reads:
dwc_otg.lpm_enable=0 root=/dev/mmcblk0p7 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait modules-load=dwc2,g_ether quiet splash plymouth.ignore-serial-consoles

ls -l /dev/serial0 /dev/ttyAMA0
lrwxrwxrwx 1 root root 7 nov 12 16:58 /dev/serial0 -> ttyAMA0
crw-rw---- 1 root dialout 204, 64 nov 13 18:30 /dev/ttyAMA0

The question about the baud rate seems very valid. It seems I have made a huge mistake. Read somewhere it was the most probable rate for log notations. Probably made a stupid error in typing.

But lets change the thread to another location first.

Thanks so far.
pablok

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1361
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: ttyS0 Problems

Mon Nov 13, 2017 8:02 pm

What would be the best location for a thread concerning ttyAMA0?
How about a thread called "ttyAMA0 problems?" It's not terribly descriptive but it is accurate. Even better would be "Problems interfacing with ESP8266", but that would be better started in the "Interfacing..." forum.

pablok
Posts: 37
Joined: Thu Dec 26, 2013 4:46 pm
Location: Westerkwartier, Groningen (NL)

Re: ttyS0 Problems

Fri Nov 17, 2017 11:20 am

Dear members,
I am returning here because of a weird baud rate I used in an earlier post; 74880. Found the origin of this baud rate on the github site of espressif/esptool:
The ESP8266 boot rom writes a log to the UART when booting. The timing is a little bit unusual: 74880 baud
.
But this is probably not where I first came across it. Most likely it was on the site: www.esp8266.com. A simple search there came up with 395 matches for 74880.
Glad I found this and do not have to be ashamed for using it.

pablok

Return to “Device Tree”

Who is online

Users browsing this forum: No registered users and 2 guests