Can't get buzzer code to run

Installed the buzzer module for my Rasoberry Pi 3 model B plus, downloaded the two samples of coding, but neither of them runs. here is what I get:

%Run Buzzer-Play-tones-and-change-volume.py
Traceback (most recent call last):
File “/home/pi/02-PiicoDev/Buzzer-Play-tones-and-change-volume.py”, line 4, in
from PiicoDev_Buzzer import PiicoDev_Buzzer
File “/home/pi/.local/lib/python3.7/site-packages/PiicoDev_Buzzer.py”, line 1, in
from PiicoDev_Unified import *
File “/home/pi/02-PiicoDev/PiicoDev_Unified.py”, line 8

<!DOCTYPE html>
^

SyntaxError: invalid syntax

1 Like

That syntax error indicates that you have downloaded a web page instead of program code.

What is the address of the site where you are doing the download, and what exactly is the procedure you are using to download the code and execute it?

An alternative is to type the code in - it is likely not very long.

Thanks for your reply.

  1. I got the buzzer code from the Core Electronics guide, as per instructions.
  2. I had checked that I2C was enabled, and that I had the current version of Piicodev installed.
  3. I had also tried typing the code, as you suggested, but I got the same error messages.
  4. Here is what it says in the "Assistant panel:

SyntaxError: invalid syntax
PiicoDev_Unified.py, line 8
Python doesn’t know how to read your program.
Small ^ in the original error message shows where it gave up, but the actual mistake can be before this.
Let Thonny developers know
Click on the feedback link at the bottom of this panel to let Thonny developers know about your problem. They may add support for such cases in future Thonny versions.

Warnings
May help you find the cause of the error.
PiicoDev_Unified.py
Possibly bad file name
Your working directory /home/pi/02-PiicoDev contains a file named ‘PiicoDev_Unified.py’.
When you try to import library module PiicoDev_Unified, your file will be imported instead.
Rename your ‘PiicoDev_Unified.py’ to make the library module visible again.

Was it helpful or confusing?
General advice on dealing with errors.

  1. I had previously bought and installed other modules (the PiicoDev ambient light sensor VEML6030 and the 3x RGB LED module) and ran the sample codes without any problems. Also modified the codes and they still worked.

Do you have a link to those instructions? The error message refers to a statement that occurs at the top of a web page - it should not be part of your code.

The example code for the buzzer is on GitHub:
GitHub - CoreElectronics/CE-PiicoDev-Buzzer-MicroPython-Module

There is a tutorial here:
https://raw.githubusercontent.com/CoreElectronics/CE-PiicoDev-Buzzer-MicroPython-Module/main/main.py

Hi Jeff and @George198863,

It sounds like everything is close to working, it will just be a minor issue like a file that’s trying to be accessed but not saved where the program is looking for it.

For reference the instructions and video guide for using the PiicoDev buzzer with the Raspberry Pi single-board-computers can be found here:

Hi Trent and Jeff. Thanksf for your suggestions and links. What Trent wrote put me on the right track, regarding file location. I’m a newbie in all of this, and it seems that I had saved the two sample files in a “PiicoDev” folder which I had created, but they wouldn’t run from that location. When I copied one of the files to a folder I had created for my own experimenting etc, it worked fine. So I copied the other one over, and it also worked fine. That also explains why my own stuff works fine from “My-stuff”.
Now I have to figure out why they didn’t run from the original location where I had them.