Serial Port Use - SteveCossy/IOT GitHub Wiki

Put the following two files into the same folder:

Note that the routines used here always detects port /dev/ttyAMA0. On Pi 3, Zero, or later, /dev/ttyAMA0 is used by Bluetooth. This article (updated November 2019) suggests that a Pi running 'latest operating system software' should always use /dev/serial0 . This will address the GPIO pins, regardless of Pi model. https://raspberrypi.stackexchange.com/questions/45570/how-do-i-make-serial-work-on-the-raspberry-pi3-or-later-model/45571#45571

This sequence shows the result of plugging four UARTs into a Pi 3B ver 1.2

pi@raspberrypi:~/IOT/LoRaReAd $ python3 SerialTest.py Onboard port is:/dev/ttyAMA0 USB port(s):

pi@raspberrypi:~/IOT/LoRaReAd $ python3 SerialTest.py Onboard port is:/dev/ttyAMA0 USB port(s):USB0,

pi@raspberrypi:~/IOT/LoRaReAd $ python3 SerialTest.py Onboard port is:/dev/ttyAMA0 USB port(s):USB0,USB1,

pi@raspberrypi:~/IOT/LoRaReAd $ python3 SerialTest.py Onboard port is:/dev/ttyAMA0 USB port(s):USB2,USB0,USB1,

pi@raspberrypi:~/IOT/LoRaReAd $ python3 SerialTest.py Onboard port is:/dev/ttyAMA0 USB port(s):USB3,USB2,USB0,USB1,

To assign the correct serial port value, regardless of Pi model, use something like:

from MQTTUtils import PiSerial SERIAL_PORT = PiSerial()['Onboard']

Example is here: https://github.com/SteveCossy/IOT/blob/master/LoRaReAd/LoRa_to_MQTT.py