Adding a speaker to a V5: my journey

I have an idea. It’s a crazy one, and I love it. I want to find a library that can do digital to analog output so we can use the vex speakers. It’d be great to play dancing queen by abba while we’re decimating our enemies with our autonomous. I do believe you can import the library once I get it very easily, if I need to do any debugging then I’ll do it (or try to) and then post everything that you can possibly fix. I have no idea if it’ll work by the way.

https://www.cplusplus.com/forum/general/280063/

I hate to burst your bubble, but it’s a hardware issue, not software. The V5 does not have the necessary digital to analog conversion hardware, the best you would be able to do is interface the V5 with another external device (arduino with sound shield etc.) to trigger sounds.

Now, if you can wait for VEX EXP, that will have an internal speaker, same for IQ gen 2.

16 Likes

Lucky☹️

1 Like

For clarification, IQ gen 2 will have similar sound capabilities as IQ gen 1, that is, a number of pre-installed sounds and tones that can be triggered by the user program. We might allow installation of additional sounds in a future update, but that’s very much still to be decided.

EXP is much more flexible and has more potential for user installed sounds, however, we allowed that back in the RobotC/Cortex days and it was not always easy to get the sounds into the correct format, so we need to be careful that it doesn’t create too many support issues for us if we allow that.

8 Likes

I swear to god you have burst my bubble very much. That sucks. Since you seem to be a person from vex (I guess if you’re saying you’re deciding things) would I be able to connect a light speaker I have (less than 100 grams) that’s not from vex? Powered by the brain and VEX battery. Rule wise

that’s a fairly short journey i suppose

21 Likes

Underrated comment ngl

Different speaker hack: Print a replacement for the gear cartridge that has ridges the motor rubs with an arm on the drive gear. Motor speed == sound frequency.

2 Likes

I think you missed a very important point. The V5 Brain does NOT have the hardware to convert digital (data the brain utilizes) to analog (the signal that a speaker needs). So running a speaker from the V5 brain isn’t possible, regardless of whether it is the VEX speaker or another speaker. The only way to do it is to have your speaker run from another brain such as an Arduino, but I believe that you would not be allowed to have the Arduino on a competition robot if you are at any level below VEX U.

5 Likes

well you could use a purely digital square wave so you didn’t need a DAC. could that work?

Explain good sire. I wish to know more about this

Forgive me if I’m mistaken here. I’m lighter on my computer science knowledge than I would want to be.

Could you not use all the digital output ports on the brain to create a single 8 bit signal out(256 possible combinations each cycle) in order to control the vex speaker?

1 Like

You’d need 256 digital out ports to do that – each port is one bit.

You could use the 8 3-wire ports on the brain to drive something like a resistor ladder DAC, but in practice I doubt you could reproduce much audible sound from such a setup – looks like the 3-wire ports update at ~100 Hz, which is way less than the sample rate of an audio file (usually in the tens of kHz).

(Disclaimer – I’m no electrical engineer, the above may be wrong)

2 Likes

Normal audio from a speaker is described as an analog waveform. It has varied peaks and that describes the frequency and amplitude of a sound. In essence, this is how music is recorded. A vinyl record stores this physically with small vibrations in the groove which are translated into the needle and then amplified into speakers.


As Jpearman established above, the V5 brain is incapable of creating this waveform because of the lack of an analog output. To my understanding, all of the brain’s output is digital. Therefore, the brain couldn’t create the waveform above.

Instead, possibly the brain could create a square wave form:
image
As you can see, this wave only has digital components. In theory, the brain could output this waveform because it does not require analog output. You could use the 3 wire ports as digital output and connect that directly to a speaker. I have done this with an arduino’s digital output by using the tone() function and connecting the digital out pin to a Piazo speaker.
This is easier said than done, however. For example, to play the note A4, one would need to enable and disable the pin 440 times per second for a frequency of 440Hz. By default, in the drive loop, there is a 20-millisecond delay. To play a constant A as described above, it would be identical to having a loop that enables and disables the output every 2.27 milliseconds. This seems possible although it would very possibly take too much of the brain’s resources to play this sound in order to put this on a competition robot. It’s probably still possible, however.

6 Likes

Oh my lord Jesus Christ you are a genius HOW DO I DO THIS

1 Like

Pretty sure the update rate on the 3 wire ports isn’t nearly that fast. Think 100hz

Also I don’t actually think that is how the vex speaker works? Pretty sure the speaker converts voltage level into the frequency of the audio, so pulsing at a random frequency would just pulse when the sound was on not change the tone. Also you would be stuck at the tone created from a 5V high signal, which you could maybe tweak with a resistor?

6 Likes

For that explanation, I was assuming you wouldn’t use the vex speaker. I have no idea how it works and since it isn’t competition legal anymore, using it serves little purpose.

Are the digital audio pins being used for something else because the Cortex A9 has a digital audio module on the chip. I know pins can be assigned to different outputs so was that the case or are they just unused outputs?

Important and correct.

Seems this part I am probably wrong on. I am too used to not embedded devices, where you would send some frequency command and a lower level device would track the curve you desired.
@nickmertin points out that the signal being sent to the vex speaker is certainty as you described still. Where the cortex is commanding the wave directly, not the frequency domain sorta scheme I was envisioning. So you could bit bang the wave (poorly and slowly) and control the vex speaker.

7 Likes

If you’re planning on interfacing with the ADI ports on the brain, it’s a M0 not an A9.