树莓派Google Assistant启动报错求助:GPIO通道占用及代码异常
Fixing Raspberry Pi Google Assistant Startup Errors
Hey there, let's work through these issues with your Raspberry Pi Google Assistant setup. I’ve helped troubleshoot similar problems before, so let’s break this down step by step.
1. Resolve the GPIO Channel In Use Warning
That RuntimeWarning is telling you the GPIO pin 25 is already being used by another process—Python will keep running, but this can cause unexpected behavior later. Here are two ways to fix it:
- Temporarily disable warnings: Add this line right after importing the GPIO library in
main.py, before theGPIO.setupcall:import RPi.GPIO as GPIO GPIO.setwarnings(False) # Add this to suppress the warning GPIO.setmode(GPIO.BCM) GPIO.setup(25, GPIO.OUT) - Root cause fix (find the conflicting process): Identify which program is using GPIO25 with these commands:
You’ll get a PID (process ID) from the output. Kill that process withsudo lsof /dev/gpiomem # Or sudo fuser /dev/gpiomemsudo kill <PID>to free up the pin permanently.
2. Troubleshoot the Assistant Initialization Traceback
Your truncated traceback points to an error when creating the Assistant instance at line 52 of main.py. These are the most common fixes for this:
- Check credential file paths: Make sure the credentials file (usually
credentials.jsonor a token file) is in the correct location, and the path in yourAssistantsetup code is accurate. For example, if it’s in/home/pi/, double-check that the code references it properly (no typos in the path). Also, ensure the file has read permissions for the user running the script:chmod 644 /home/pi/credentials.json - Update or reinstall dependencies: Outdated or mismatched library versions often break the Assistant SDK. Run these commands to refresh the required packages:
sudo pip3 install --upgrade google-assistant-library google-assistant-sdk[samples] grpcio - Verify script permissions: If you’re using
sudoto run the script, some files (like your main.py or credentials) might be owned by thepiuser instead of root. Adjust ownership to avoid permission issues:sudo chown pi:pi /home/pi/main.py /home/pi/google-assistant-init.sh
Start with the GPIO warning first, then work through the Assistant initialization checks—this should get your Google Assistant up and running.
内容的提问来源于stack exchange,提问作者JustAnotherBitcoin




