pybadge with a speaker

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Minshan
 
Posts: 9
Joined: Sun Dec 06, 2020 11:30 pm

pybadge with a speaker

Post by Minshan »

I connect the Pybadge with a speaker. How can I make it work by Arduino? I don't know how to write the code to let the Pybagde board make sounds.
Attachments
S__50593794.jpg
S__50593794.jpg (246.67 KiB) Viewed 475 times

User avatar
dastels
 
Posts: 15817
Joined: Tue Oct 20, 2015 3:22 pm

Re: pybadge with a speaker

Post by dastels »

See the Arcada examples, specifically: https://github.com/adafruit/Adafruit_Ar ... e_test.ino.

Look at the top of the loop() function (lines 132-136).

The Arcada page in the PyBadge guide has some information as well: https://learn.adafruit.com/adafruit-pybadge.

Dave

User avatar
blnkjns
 
Posts: 963
Joined: Fri Oct 02, 2020 3:33 am

Re: pybadge with a speaker

Post by blnkjns »

It is connected to pin A0, that is a DAC pin: you can generate a 12-bit analog waveform. You can experiment with just using:

Code: Select all

analogWrite(A0,value);
If you write a 440 Hz sine function 10000 times a second, you will get a sine wave for example.
You can take a look here for deeper synthesis:
https://learn.adafruit.com/synthesizer- ... esign-tool
https://learn.adafruit.com/synthesizer- ... on-trellis
Any tutorial on sound synthesis with Arduino on the ATSAMD51 will probably work with minor modifications.

Things depend a bit on your goal: want to make a game with sounds, the Arcade route will probably offer the basics, if you want to dive more into real synthesis, follow the Trellis route. The Arcada library is pretty big though, and asks some serious compilation time, so to just use it for basic sounds it might be overkill.
You also need to cut the pad saying A0 under the built-in speaker to disable that one.

User avatar
blnkjns
 
Posts: 963
Joined: Fri Oct 02, 2020 3:33 am

Re: pybadge with a speaker

Post by blnkjns »

Checked my links on my PyBadge, and I can confirm the code runs on it. One note, it was a little tough to find the Audio.h library, I installed it with the Teensyduino installer as mentioned in the article. It is really awesome stuff, you can make your own virtual synthesizer:
https://www.pjrc.com/teensy/gui/

User avatar
blnkjns
 
Posts: 963
Joined: Fri Oct 02, 2020 3:33 am

Re: pybadge with a speaker

Post by blnkjns »

Another thing to take care off:

Code: Select all

  pinMode(51,OUTPUT);
  digitalWrite(51,HIGH);
Put this code somewhere in the setup, as it gives the amplifier its needed juice.

User avatar
Minshan
 
Posts: 9
Joined: Sun Dec 06, 2020 11:30 pm

Re: pybadge with a speaker

Post by Minshan »

Thanks. It makes sounds successfully. Thanks your suggestion very much.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”