pybadge with a speaker
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- Minshan
- Posts: 9
- Joined: Sun Dec 06, 2020 11:30 pm
pybadge with a speaker
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 (246.67 KiB) Viewed 475 times
- dastels
- Posts: 15817
- Joined: Tue Oct 20, 2015 3:22 pm
Re: pybadge with a speaker
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
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
- blnkjns
- Posts: 963
- Joined: Fri Oct 02, 2020 3:33 am
Re: pybadge with a speaker
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:
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.
Code: Select all
analogWrite(A0,value);
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: 963
- Joined: Fri Oct 02, 2020 3:33 am
Re: pybadge with a speaker
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/
https://www.pjrc.com/teensy/gui/
- blnkjns
- Posts: 963
- Joined: Fri Oct 02, 2020 3:33 am
Re: pybadge with a speaker
Another thing to take care off:
Put this code somewhere in the setup, as it gives the amplifier its needed juice.
Code: Select all
pinMode(51,OUTPUT);
digitalWrite(51,HIGH);
- Minshan
- Posts: 9
- Joined: Sun Dec 06, 2020 11:30 pm
Re: pybadge with a speaker
Thanks. It makes sounds successfully. Thanks your suggestion very much.
Please be positive and constructive with your questions and comments.