Bright Sparks NZ
Posts: 20
Joined: Fri Dec 21, 2012 8:11 pm

Command Line Serial Baud Rate Control

Thu Mar 07, 2013 10:17 am

I am (very) new to Pi and Linuxy things in general but have been doing quite a lot in just a few weeks with the Pi just using it as a www / serial interface with tools like Cosm and cURL to get and put data on line in the 'Internet of Things' sort of space and can see some real potential here...

How can I control / set the baud rate of the serial terminal via the serial terminal ?
I know this sounds a little 'hairy' but I am prepared to live with the consequences and expect to get a little 'lost in space' at times. It would simplify things greatly for me and allow PIC / Micro's that generally operate in the gracial 2400 - 9600 baud rate region.

In just a few days I have explored and enjoyed the Great simplicity of 'headless pi' via ssh / hard wire serial, tightVNC and made my own serial interface see:
https://picasaweb.google.com/picaxe/Ope ... dwareIdeas

1/. Some command line examples please from / via the serial port itself
2/. I am not sure but feel 'pretty confident' that until I get things right a re boot / cold start would get me back to 115200. Correct ?
3/. I have found an article on changing the boot files (2 of them) to make the default / boot speed different and could live with this but am an absolute beginner so have not crakced the the 8 levels of permission linux funkyness bits thing and or having permission to edit or being allowed to at all is all a bit of a mystery to me. I think I can handle the txt editor !

If I can't get 1 and 2 working then I will opt for 3/.

Thanks in advance

~ Andrew

User avatar
joan
Posts: 13620
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Command Line Serial Baud Rate Control

Thu Mar 07, 2013 11:07 am

The command to set the serial bit rate is

stty -F /dev/ttyACM0 9600

Use

man stty

for help.

You'll lose the link until you also change the baud rate at your end.

The values will be overwritten back to 115200 when the Pi is rebooted.

User avatar
malakai
Posts: 1382
Joined: Sat Sep 15, 2012 10:35 am
Contact: Website

Re: Command Line Serial Baud Rate Control

Thu Mar 07, 2013 11:11 am

Found some reading for you hope it helps clarify which option might be best for you

http://raspberrypi.stackexchange.com/qu ... uart-speed

This one has the command line to set it

http://www.raspberrypi.org/phpBB3/viewt ... 3&p=304624
http://www.raspians.com - always looking for content feel free to ask to have it posted. Or sign up and message me to become a contributor to the site. Raspians is not affiliated with the Raspberry Pi Foundation. (RPi's + You = Raspians)

Bright Sparks NZ
Posts: 20
Joined: Fri Dec 21, 2012 8:11 pm

Re: Command Line Serial Baud Rate Control

Sat Mar 09, 2013 2:08 am

Thanks people for the responses.

I will update here how we get on when I next get a chance after this weeks trip around the country meeting teachers etc. I should know a heap more about Pi and at least a few more commands by next Saturday !

If people want to 'read between the lines' where I am going with this then suggest look up Cosm (Pachube) via cURL at https://cosm.com/support/examples.
This is well covered elsewhere in the form I think ?

The vision is to develop the ultra low tech devices devices I already have working called 'cicada' These are very low tech low cost devices that idle in the uAmp region. Cicada are made up of just 3 to 4 component parts parts and only need a half dozen lines of code. I have reached nAmps in latest tests which means lithium coin cell operation for a few months / year. Budget solar garden lights "24/7" suitably hacked can also generate sufficient energy with just a 1N4148 and a capacitor to drive these sorts of devices. To help all this along the newer generation Dorji 433MHz RF ASK devices are streaks ahead spec wise in the sensitivity, noise, and range stakes compared with some other frustrating and less than stable devices. Free resources and starter ideas are available here. http://picasaweb.google.com/picaxe

Thanks again.

~ Andrew

DBryant
Posts: 281
Joined: Sat Feb 02, 2013 12:41 pm
Location: Berkshire, UK

Re: Command Line Serial Baud Rate Control

Tue Mar 12, 2013 9:08 pm

You might also want to look at screen; man-page at http://aperiodic.net/screen/man:start.

Bright Sparks NZ
Posts: 20
Joined: Fri Dec 21, 2012 8:11 pm

Re: Command Line Serial Baud Rate Control

Mon Mar 18, 2013 8:14 am

Thanks everyone. I have received some help via e-mail from Vik Olliver
‘The command line program you use is "stty" and "man stty" on a linux box gives all the instructions. You can read them, but ...
Find out *everything* on the port
stty -a -F /dev/ttyUSB0
57600 baud please, 8 bits:
stty -F /dev/ttyUSB0 57600 cs8
There is a small program called "minicom" on Linux which (Ctrl-A Z gives help when it's running) allows you to set things using some sort of menu interface in text mode. I think it's there for the Pi
They use them a lot at http://tangleball.org.nz if you need real gurus.
Vik :v)’

Okay so I have found out that the 'com port I am working with is called AMA0 (0=zero)

1/. stty in above format works but stty by itself tells anyone enough about the port you are on. In the case of Pi out of the box this will look something like:
[email protected]:~$ stty
speed 115200 baud; line = 0;
-brkint ixoff -imaxbel
-iexten
I am only interested in finding the baud rate and this is enough for a picaxe to live with

2/. stty -F /dev/ttyAMA0 9600 is enough to get the baud rate serial speed to 9600
The response will be 'lost in space' until putty or serial port weapon of choice is restarted at 9600 but stty then responds to confirm all is well thus:
[email protected]:~$ stty
speed 9600 baud; line = 0;
-brkint ixoff -imaxbel
-iexten

3/. Yes the com port comes back up at 115200 baud upon power boot. so this is a 'relatively safe' command for people to tinker with

~ Andrew

martinmarty
Posts: 20
Joined: Mon Sep 22, 2014 1:03 am

Re: Command Line Serial Baud Rate Control

Mon Oct 27, 2014 8:05 am

Andrew,

I've been trying to interface my Pi model B with a digital sign and having numerous problems, one of which was the voltage levels of the Pi serial pins versus RS232. This evening I ordered a couple of adapters based on the MAX3232 chip. Then I found your serial interface circuit schematic on Picasa which I was able to put together from parts I had on hand. This enabled me to take my project to the next stage without waiting three or four days for the adapters to arrive. I will probably go with the new adapters when they arrive, but your posts were a big help to me in proving that my Pi could send a message to my sign without waiting for the post office to bring more hardware. :D

THANKS!!!

-Marty

Return to “Advanced users”