Serial Console Cable on MacOS
To communicatie with a "headless" devices (a device without keyboard or monitor) such as a Arduino, Raspberry Pi or network device, you might talk to it via a serial cable.
Usually you do this to bootstrap the device before it has network access.
You need three things:
- A serial cable, also known as a console cable
- A driver for the cable (or actually for the chipset in the cable, or in the device).
- A terminal program
If you are lucky, the device has a micro-USB or mini-USB port, and you can just use a normal USB cable. Just make sure it's not a cheap charging-only USB cable. I once spend too long trying to figure out why the device did power up, but I could not talk to it :).
In case the serial port is a DB-9 connector or RJ45 connector, you need a USB-to-serial adapter. I bought a Icidu C-707607 USB to Serial cable. Like mine, the actual conversion from USB to serial is done by a Prolific PL-2303 USB to Serial Bridge Controller buried in the connector. The Prolific PL-2303 is a very common controller, and one I recommend.
Make sure to also purchase a null modem cable, or a female-to-female DB9 connector. A null modem cable is a cable with DB9-female connectors on both ends. The USB-to-serial cable, as well as the network device will have a DB9-male connector. You can also buy a female-to-female DB9 connector, but make sure that the internal wiring is cross-over like is the case with a null modem. If the connector is about 4 centimeter long, this is probably the case. If it is about 1 centimeter long, the cabling is "straight" and it will not work as a serial cable (these straight connectors are used to extend old VGA cables).
In case your serial port is a RJ45 connector (which may be the case on network hardware), you also need a DB-9 to RJ-45 convertor. There are cables or adapters that plug into a regular UTP cable. As with the null modem cable, beware that you might need a cross-over UTP cable. If you create your own UTP cables, you can easily make one yourself.
The driver you need depends on the chipset you are communication with. These drivers are often called Virtual COM Port (VCP) drivers. You will likely encounter on of these:
- FTDI FT232,
- Prolific PL2303,
- Silicon Laboratories CP210x (CP2102), or
- Nanjin QinHeng Electronics CH341 (CH340G).
For a USB-to-serial adapter with Prolific PL-2303 controller, you can download the driver from the Prolific website or from the manufacturer you bought the cable from. The Prolific driver version 1.4.0 created a new device socket under Mac OS X, /dev/cu.usbserial.
For most development boards (such as the Arduino or Pycom), you most likely need the USB FTDI driver. Since this driver is preinstalled on macOS Maverick and higher, it may just work out of the box. Just connect your development board and look for a device in the /dev/ directory (e.g. /dev/cu.usbserial or /dev/cu.usbserial-DQ008BU0).
Some other development boards come with a CP2102 serial controller, including NodeMCU and a Doodle Bot I bought. For these, you need the CP210x USB to UART Bridge VCP driver.
First check if your USB cable is correct. Especially cheaper USB cables can only be used for powering a device, while the data wires are simply not connected.
Since mac OS High Sierra (10.13 and up), you need to allow the driver in the System Preferences Privacy tab, immediately after installation.
Since mac OS 10.15, Kernel Extensions are replaced with System Extensions. At the time of this writing (spring 2020) no System Extension drivers are available yet, but the Kernel Extensions continue to work (albeit with a warning to the user).
The build-in FTDI driver on Mac OS High Sierra had some issues: no device was detected. I resolved this by installing the VCP driver from FTDI Chip. Even that did not work out of the box, I had to disable the MacOS native driver, enable the FTDI driver and reboot before it worked.
sudo kextunload -b com.apple.driver.AppleUSBFTDI sudo kextload -b com.FTDI.driver.FTDIUSBSerialDriver sudo shutdown -r now
If that also fails, you can also buy a third party driver from https://www.mac-usb-serial.com/. While this is paid, it does come with support for many devices: PL2303, CP2102, as well as CH340G. I bought these, but in the end, used the drivers created by the manufacturer.
You can simply communicate with the port using the cu (call-up) program:
cu -s 9600 -l /dev/cu.usbserial
If you want to log the console output:
cu -s 9600 -l /dev/cu.usbserial | tee console.log
You can also use the screen utility:
screen /dev/cu.usbserial 19200
A tool with a better terminal emulation is picocom: