#so A2 is connected to D on the amplifier
1 messages ยท Page 1 of 1 (latest)
not quite - it's A2 to A+ ,and A- is to ground.
there isn't D+ or D-
no worries. but yeah, that's how i have it wired.
also - interesting - the big multi color LED is on now, for some reason.
type ctrl-D in the serial window
nothing seems to be happening
hold on, I'm duplicating the setup
here's my setup presently, if that's helpful
ok, tone program has another bug. try this one:
pwmio, not pulseio
where did you get these examples from? not chatgpt?
i can't remember exactly, as i've been grabbing things from all over the place.
but no, not gpt - i hadn't considered that...
does that work?
please DON't use chatgpt; it can be right, and it can be very wrong
and it will be very confident it's right
hah - i can belive that. ๐
are you on Windows, Mac, or Linux?
there are so many different (but similar) examples of this kinda stuff all over the net, and from different times, that it's easy to get confused or misled.
i'm on a mac. but i have a pc available, fwiw
our guides in https://learn.adafruit.com are kept up to date. Look there first
mac is absolutely fine
yes - the learn. examples were very helpful in getting started.
it's when i was trying to get the different parts connected/working together that i ran into trouble.
ok, did you try my latest version above? After you write the file, does it start? If you are sitting in the REPL (>>> prompt) in the Serial window, you need to type ctrl-D
i'm not sure if i'm doing it correctly...
i'm opening your code, copying it, swithcing to Mu, selecting all, pasting, and then hittng save
so far, that method seems to have been working for me, but perhaps that's just lucky
it should be fine
but if you are at >>> in the REPL, then it will not restart automatically. It only restarts automatically if the program is already running
ok.
i just tried it again, and nothing seems to be happening.
i'm assuming that as soon as it loads, it should be making a noise, yeah?
try pressing the reset button
it's making a noise for me, with the same components and same code.py
ah - that did it.
you were probably in the >>> prompt but couldn't see that
it scared the crap out of my friend (sitting next to me) ๐
yep, pretty loud ๐
ok, well cool! that's progress!
ok, here is a corrected code.py. not tested, but should be better. It will not play until you press the button. If there are button wiring problems. it will not play. Try replacing if not switch.value with if not False (or if True ๐ ) to get around any button issues for now
ok, trying now...
hm. not having any luck yet.
tried switching switch.value to False, but that didn't seem to do anything
Add import analogio to the top. It was missing
yah, i just saw that....
you should have seen that in the REPL, which is your friend about reporting errors
working for me now
but now something new and weird is happeneing -
the board is coming up a "NO NAME" now, and not CIRCUITPY (or whatever it ususally is)
there could be filesystem corruption
shoot.
in the REPL, do:
import storage
storage.erase_filesystem()
that will erase everything. Here is the latest working code.py (with switch disabled)
that won't help. The firmware is fine, it's CIRCUITPY that might be bad. But just try unplugging and replugging first
and even if it's NO NAME, you should still be able to get to the REPL from Mu, I think.
i tried doing the BOOTSEL thing, and it's going between NO NAME and RPI-RP2
If you want to wipe everything, use the "nuke" UF2 referenced here: https://learn.adafruit.com/welcome-to-circuitpython/troubleshooting#for-the-specific-boards-listed-below-2978458, and then reload Circuitpython. I think Mu should still be able to connect. If not you can use a terminal program like screen or tio. as explained in the Welcome to CircuitPython guide.
yes, trying that now
I have to do some other work. Work on this for a while, and then swing back later
hey - thanks so much for all of your help with this!
i really apprecaite it!
ok, got it back up and running.
it's playing the tone, and the pot is adjusting the volume, which is very exciting. ๐
ok great!
can't seem to get the button working, though.
did you say that you had it working on your setup?
no I didn't set it up. One end of the button is connected to ground and one to the pin, right?
yup
you could add a print statement in the loop just to print the value of the button, before the if that checks its value
i have found that at least some buttons are flaky in breadboards: the pins are rather short and don't necessarily make good contact.
you should use two diagonal button pins. That ensures that no matter its orientation, pressing the button will close the contact between the pins. You could try shorting those two pins with a jumper
that's how i've got it set up - two diagonal pins.
and so far, everything i've tried with just the button (turning the LED on and off) has been working without any issues.
if you include the switch, do you get no sound or always sound. You could try flipping the if from if not switch.value to if switch.value. That would make it go off when pressed.
try the things above. print statements are a great debugging tool
i don't think i understand how to include the switch.
i see that it's set up in the initialize section at the beginning, and i see that it's mentioned in the main loop, but there isn't anything mentioning it specifically in the code in that loop.
so i'm definitely missing something.
i do like the sound of debugging and using print, that makes sense
if not switch.value:
# Read the potentiometer value
pot_value = potentiometer.value
# Adjust the volume using PWM
volume_pwm.duty_cycle = int(pot_value / 65535 * 32768)
else:
# Stop playing the sine wave
volume_pwm.duty_cycle = 0
If the switch is pressed, read the pot value and adjust the duty cycle. If the switch is not pressed, set the duty cycle to 0, to turn off the output.
Because the switch is grounded when pressed, we use not switch.value, because switch.value == False means grounded
you put back the not switch.value, right?
i just did now, yes - and now it's behaving as expected!
so i would say study this program now and understand what each thing does. Look up the documentation if necessary.
find out what PWMOut does if you don't know already
what a pulse-width modulated signl is
yes, that makes sense to me.
PWM is new to me, and if it's what i think it is, i don't think it's what i'm looking for in terms of tone generation.... (i was hoping for something more like a sine wave generator; this sounds more like a square or triangle wave)
but still - this is really great, and i'm much much closer to where i wanted to be.
so again - thank you very much for your time and patience!
very much appreciated! ๐
yes, it's a square wave. So to do a sine wave, you can go back to your sine generation. You won't use PWMOut at all. There is no easy gain control available in I2SOut, except by using a Mixer. Look for examples of that in the Learn guides. Or you can generate a sine wave of a certain amplitude, scaled by the volume reading, but then you have to re-generate it each time you change the volume control.
oh, ok... interesting.
so i wonder if it might make more sense to move the volume control to the analog side, and have it in-line with the amp and speaker (so to speak).
you can't do that with the I2S amp, because the signal is digital. The I2S amp has jumper-selectable gain, but that's very limited (3 values.
right - that makes sense. i was talking about using the other amp (the PAM one), and sending an analog signal to it instead.
yes, you could put the pot at the pin output, and take the signal from the wiper to the amp. Maybe use a 10k or 100k or something in between pot instead of a 1k pot, to reduce the load on the pin
but it will still be a square wave. The amp also has a tiny pot on it you can adjust with a screw driver
that makes sense about the amp/pot...
but you're saying that there isn't a way to generate a sine wave?
not with PWMOut. You can filter the signal to reduce the harmonics of the square wave, but it is fundamentally a square wave
gotcha.
and PMWOut is my only option with this board?
besides I2SOut, yes. RP2040 does not have DAC for true analog audio
understood.
I'm going to dig in and read up on PMW a bit, and see if i can get this sounding any better.
i might also try a different speaker.
thanks again! ๐
ok.
i also just found this - https://www.adafruit.com/product/935 -
wondering if that might be worth trying out (to get nicer-sounding waves)
we don't have bulk output, you probably can't drive it fast enough. I2S is the way to go in the long run
ok. not 100% clear on what you mean by that, but i trust you. ๐
You can generate a sine wave digitally. I2S is digital, like a CD (very roughly!). The I2S amp has a DAC built in that converts the digital data to analog and drives the speaker
actually, synthio may help you a lot, and it's brand new: <
https://learn.adafruit.com/circle-of-fifths-euclidean-synth-with-synthio-and-circuitpython>
it will generate sine square, etc.
so you don't have to do that "by hand"
ooh, that sounds cool!
checking it out now.
this is a complicated project, I'm not sure where to find simpler synthio examples...
try the exmaples there. You will switch to the I2S amp. It needs several connections, so read the guide for it carefully
i actually do know a thing or two about analog synthesizers, so a lot of these terms are familiar to me
granted, it is complete overkill for what i'm after. ๐
but - just to give you some context - this will be a version 3.0 of an existing beep box, which i've been using for the past year or so.
it's completely analog, and uses an analog wave generator board (https://www.amazon.com/ICQUANZX-Precision-Generator-Adjustable-Frequency/dp/B07V674HZY), a small amp, and a speaker.
it's quite chunky (about the size of a brick), and isn't as sturdy as I'd like it (it goes in and out of cases regularly).
so i figured i'd try to make a smaller, "digital" version, with smaller parts. and here we are. ๐
the old one does sound pretty nice, though.
well, then I think you will like synthio