#so A2 is connected to D on the amplifier

1 messages ยท Page 1 of 1 (latest)

tidal beacon
#

starting a thread

tulip pilot
#

not quite - it's A2 to A+ ,and A- is to ground.
there isn't D+ or D-

tidal beacon
#

ok sorry

#

i meant A

tulip pilot
#

no worries. but yeah, that's how i have it wired.

#

also - interesting - the big multi color LED is on now, for some reason.

tidal beacon
#

type ctrl-D in the serial window

tulip pilot
#

nothing seems to be happening

tidal beacon
#

hold on, I'm duplicating the setup

tulip pilot
#

here's my setup presently, if that's helpful

tidal beacon
#

ok, tone program has another bug. try this one:

#

pwmio, not pulseio

#

where did you get these examples from? not chatgpt?

tulip pilot
#

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?

tidal beacon
#

please DON't use chatgpt; it can be right, and it can be very wrong

#

and it will be very confident it's right

tulip pilot
#

hah - i can belive that. ๐Ÿ˜‰

tidal beacon
#

are you on Windows, Mac, or Linux?

tulip pilot
#

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

tidal beacon
#

mac is absolutely fine

tulip pilot
#

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.

tidal beacon
#

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

tulip pilot
#

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

tidal beacon
#

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

tulip pilot
#

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?

tidal beacon
#

try pressing the reset button

#

it's making a noise for me, with the same components and same code.py

tulip pilot
#

ah - that did it.

tidal beacon
#

you were probably in the >>> prompt but couldn't see that

tulip pilot
#

it scared the crap out of my friend (sitting next to me) ๐Ÿ˜‰

tidal beacon
#

yep, pretty loud ๐Ÿ™‚

tulip pilot
#

ok, well cool! that's progress!

tidal beacon
#

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

tulip pilot
#

ok, trying now...

#

hm. not having any luck yet.

tried switching switch.value to False, but that didn't seem to do anything

tidal beacon
tulip pilot
#

yah, i just saw that....

tidal beacon
#

you should have seen that in the REPL, which is your friend about reporting errors

#

working for me now

tulip pilot
#

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)

tidal beacon
#

there could be filesystem corruption

tulip pilot
#

shoot.

tidal beacon
#

in the REPL, do:

import storage
storage.erase_filesystem()

that will erase everything. Here is the latest working code.py (with switch disabled)

tulip pilot
#

Mu isn't seeing it anymore...

#

i'm going to re-upload the firmware

tidal beacon
#

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.

tulip pilot
#

i tried doing the BOOTSEL thing, and it's going between NO NAME and RPI-RP2

tidal beacon
tulip pilot
#

yes, trying that now

tidal beacon
#

I have to do some other work. Work on this for a while, and then swing back later

tulip pilot
#

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. ๐Ÿ™‚

tidal beacon
#

ok great!

tulip pilot
#

can't seem to get the button working, though.

did you say that you had it working on your setup?

tidal beacon
#

no I didn't set it up. One end of the button is connected to ground and one to the pin, right?

tulip pilot
#

yup

tidal beacon
#

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

tulip pilot
#

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.

tidal beacon
#

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

tulip pilot
#

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

tidal beacon
#
    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?

tulip pilot
#

i just did now, yes - and now it's behaving as expected!

tidal beacon
#

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

tulip pilot
#

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! ๐Ÿ™‚

tidal beacon
#

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.

tulip pilot
#

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).

tidal beacon
#

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.

tulip pilot
#

right - that makes sense. i was talking about using the other amp (the PAM one), and sending an analog signal to it instead.

tidal beacon
#

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

tulip pilot
#

that makes sense about the amp/pot...

#

but you're saying that there isn't a way to generate a sine wave?

tidal beacon
#

not with PWMOut. You can filter the signal to reduce the harmonics of the square wave, but it is fundamentally a square wave

tulip pilot
#

gotcha.

and PMWOut is my only option with this board?

tidal beacon
#

besides I2SOut, yes. RP2040 does not have DAC for true analog audio

tulip pilot
#

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! ๐Ÿ˜‰

tidal beacon
#

np

#

look up "low pass filter for PWM"

tulip pilot
tidal beacon
#

we don't have bulk output, you probably can't drive it fast enough. I2S is the way to go in the long run

tulip pilot
#

ok. not 100% clear on what you mean by that, but i trust you. ๐Ÿ˜‰

tidal beacon
#

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

#

it will generate sine square, etc.

#

so you don't have to do that "by hand"

tulip pilot
#

ooh, that sounds cool!
checking it out now.

tidal beacon
#

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

tulip pilot
#

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.

tidal beacon
#

well, then I think you will like synthio