0

pybadge with a speaker
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

pybadge with a speaker

by Minshan on Sun May 30, 2021 9:55 am

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 362 times

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

Re: pybadge with a speaker

by dastels on Sun May 30, 2021 10:43 am

See the Arcada examples, specifically: https://github.com/adafruit/Adafruit_Arcada/blob/master/examples/full_board_tests/arcada_pybadge_test/arcada_pybadge_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

dastels
 
Posts: 6840
Joined: Tue Oct 20, 2015 3:22 pm

Re: pybadge with a speaker

by blnkjns on Sun May 30, 2021 10:47 am

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 | TOGGLE FULL SIZE
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.

blnkjns
 
Posts: 663
Joined: Fri Oct 02, 2020 3:33 am

Re: pybadge with a speaker

by blnkjns on Sun May 30, 2021 1:47 pm

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/

blnkjns
 
Posts: 663
Joined: Fri Oct 02, 2020 3:33 am

Re: pybadge with a speaker

by blnkjns on Mon May 31, 2021 11:45 am

Another thing to take care off:
Code: Select all | TOGGLE FULL SIZE
  pinMode(51,OUTPUT);
  digitalWrite(51,HIGH);

Put this code somewhere in the setup, as it gives the amplifier its needed juice.

blnkjns
 
Posts: 663
Joined: Fri Oct 02, 2020 3:33 am

Re: pybadge with a speaker

by Minshan on Thu Jun 03, 2021 10:28 am

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

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

Please be positive and constructive with your questions and comments.