From 4f0ac084488bbf7eab04fb58633a4a52800580c9 Mon Sep 17 00:00:00 2001 From: Andrew Scheller Date: Thu, 23 Nov 2023 15:22:32 +0000 Subject: [PATCH] Fix Build HAT library to work on Raspberry Pi 5 --- buildhat/serinterface.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/buildhat/serinterface.py b/buildhat/serinterface.py index af1ab1b..fbed704 100644 --- a/buildhat/serinterface.py +++ b/buildhat/serinterface.py @@ -5,6 +5,7 @@ import tempfile import threading import time +import os from enum import Enum from threading import Condition, Timer @@ -105,6 +106,11 @@ def __init__(self, firmware, signature, version, device="/dev/serial0", debug=Fa self.rampftr.append([]) self.motorqueue.append(queue.Queue()) + # On a Pi 5 /dev/serial0 will point to /dev/ttyAMA10 (which *only* + # exists on a Pi 5, and is the 3-pin debug UART connector) + # The UART on the Pi 5 GPIO header is /dev/ttyAMA0 + if device == "/dev/serial0" and os.readlink(device) == "ttyAMA10": + device = "/dev/ttyAMA0" self.ser = serial.Serial(device, 115200, timeout=5) # Check if we're in the bootloader or the firmware self.write(b"version\r")