I recently picked up a thermal printer for pretty much only stupid reasons. I was able to get it connected and printing with an Arduino Uno very quickly, but I started running into difficulties when I wanted to send serial data from my Raspberry Pi 3 Model B to the printer.
Pretty much every tutorial/piece of info I could find says that all you have to do is make sure the pi doesn’t have serial console enabled, plug the pins in, and send serial data to
/dev/ttyAMA0. Every time I sent data in that direction, it would crash my current SSH connection into the pi and I’d have to disconnect.
- When the Raspberry Pi 3 came out, Bluetooth and Wifi support were added internally.
- On the Pi 3,
/dev/ttyAMA0is now the Bluetooth TTY, and requires all kinds magic that I’m not interested in.
- GPIO UART is now explicitly disabled in the /boot/config.txt file, meaning that the actual TTY not only ignores connections, but doesn’t exist until you enable it.
- The new GPIO UART TTY is located at
Getting GPIO UART enabled and configured is actually pretty easy on the newest Pi. Just edit the
/boot/config.txt file and change the
enable_uart flag from
To test out if it’s working correctly, after you’ve hooked a serial device to the correct pins, you can set the baud rate of the TTY with:
stty -F /dev/ttyS0
Once you’ve done that, send some text across the TTY with:
echo -e "This is a test.\\n\\n\\n" > /dev/ttyS0
Note: The post I linked to discussed having to change the clock rate of the Pi from 1.2GHZ to 250MHZ to sync baud rate and data transfer. I didn’t have any issues using the processor at the native core frequency, so I don’t believe it’s necessary to make that step.