13

Is it possible to set the baud rate for Macs in a terminal? If yes, how to set the baud rate in terminal through the terminal?

I am trying to talk to the Mac using an Arduino (open source microcontroller), an XBee (wireless communicator) to type in the terminal through the serial monitor. The only problem I am having is the baud rate of the serial monitor and terminal are different. I can easily change the baud rate for the serial monitor in the Arduino, but I do not know what the baud rate is for the terminal in Mac.

Mike
  • 47,263
  • 29
  • 113
  • 177
luca590
  • 460
  • 2
  • 5
  • 25
  • I don't understand what you're asking. – Cody Gray - on strike Apr 04 '11 at 13:35
  • 1
    Well what i am trying to do is talk to the mac using an arduino (open source microcontroller), an xbee (wireless comunicator) to type in terminal through the serial monitor. The only problem i am having is the baud rate of the serial monitor and terminal are different. I can easily change to baud rate in the serial monitor but i do not know how to change the baud rate in the terminal. – luca590 Apr 04 '11 at 14:09
  • you should add that information to your question. – HaskellElephant Apr 04 '11 at 20:59

4 Answers4

17

On Mac OS, stty seemingly can only change terminal settings for an ongoing access.

It works to either:

  • Access the serial interface, e.g. cat /dev/cu.usbserial, the default settings will be used at first. On a different terminal use stty, e.g. stty -f /dev/cu.usbserial 230400 to set the baud rate, the settings of the terminal accessed before will change.

  • There is a small time window after executing stty, in which the access can be performed with the desired parameters, e.g. stty -f /dev/cu.usbserial 230400 & cat /dev/cu.usbserial executes stty, detaches it and then immediately performs the access to the serial device.

  • For one line command logging serial port /dev/tty.usbserial-X's output to cat.out and terminating the logging by pressing Ctrl+C, here is the solution: trap 'kill $(jobs -p)' SIGINT ; cat /dev/tty.usbserial-X | tee cat.out & stty -f /dev/tty.usbserial-X 115200. You can type Ctrl+C to terminate logging to cat.out. (edited)

This only seems to work for the /dev/cu.* device files. I don't know the difference from /dev/tty.* files.

David
  • 7,005
  • 2
  • 22
  • 29
jon911
  • 186
  • 1
  • 5
  • I was looking for a solution to this problem for MONTHS! Your solution did it for me. I am using `screen` to connect to a dev board with 460800 Baud. The first way (using two terminals) you provided didn't work (`device busy`). But the second one with sending `stty` to the background did work: `stty -f /dev/cu.usbserial-141A 460800 & screen /dev/cu.usbserial-141A 460800` – Stefan D. Feb 02 '16 at 15:08
  • I should add that `screen` or any other terminal program usually doesn't have problems to set the proper baudrate. But there seems to be a bug in OSX that normally doesn't allow to set baudrates higher than 230400. The problem is independent of the terminal program and the driver that is used. I wrote about it [here](https://cervisial.wordpress.com/2016/02/02/using-serial-adapters-with-baudrates-230400-on-osx/). But with your second solution it is possible to use these higher baudrates. Thanks again! – Stefan D. Feb 03 '16 at 12:54
  • https://discussions.apple.com/thread/3798003?tstart=0 "(...)In OS X and other versions of UNIX, closing the serial port restores it to its default settings. (...)" – Micha Herrmann Nov 18 '19 at 20:58
  • I tried this on macOS Catalina but it didn't work, maybe they changed something? – Lewis Peel May 07 '20 at 19:18
1

Minicom is an excellent tool that does exactly what you're asking for. You can get it using apt on ubuntu but should check this Tutorial out for Mac.

Keep the serial reset issue in mind if you plan on sending data to the Arduino. see http://arduino.cc/playground/Main/DisablingAutoResetOnSerialConnection

ZnArK
  • 1,533
  • 1
  • 12
  • 23
0

stty 19200 or so.

Check man stty, you can set stop bits, speed, etc.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
clt60
  • 62,119
  • 17
  • 107
  • 194
  • you cant set them this command only allows you to see them. When trying to set the baud rate i get illegal option – luca590 May 08 '11 at 00:43
  • 1
    now checked it thru null modem cable and serial port. stty **can set** the baud rate. – clt60 May 08 '11 at 01:07
  • That would be great, except it doesn't work: `> stty -f /dev/tty.usbserial-A96HPNJJ speed 115200` `9600` `> stty -f /dev/tty.usbserial-A96HPNJJ ` `speed 9600 baud;` `lflags: -icanon -isig -iexten -echo` `iflags: -icrnl -ixon -ixany -imaxbel -brkint` `oflags: -opost -onlcr -oxtabs` `cflags: cs8 -parenb` – Jeff Sep 30 '13 at 12:09
  • Sorry for the formatting problems. I couldn't get it to format terminal output. – Jeff Sep 30 '13 at 12:11
0

Surprised that no one mentioned picocom which could set higher bard rate up to 4000000.

pandy.song
  • 51
  • 3
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/30414080) – Abhishek Dutt Nov 26 '21 at 02:52