I ordered a FEZ Panda and have wanted to see if I could get it to generate tones via a morse code rythym. I have the morse code part of the program working with the LED, but I’m having trouble figuring out how to get a tone generated from one of the audio ports.
I saw a project about FEZ being able to play audio: (link removed). Based on what I saw in that project, I hooked a TRS audio connector to the ground and A3 ports of the FEZ Panda. I changed my code to use
new OutputPort((Cpu.Pin)FEZ_Pin.AnalogOut.An3,false);
as the OutpoutPort. All it’s doing is sending true when the morse code is on and false when the morse code is off. I can faintly hear the rythym of the morse code, but only if I hold the speaker up to my ear.
What do I need to do to be able to generate a tone to send to the speaker?
Ben - The analog out can drive VERY little current… are you connecting this to a “line in” like on a stereo, or directly to speakers/headphones? It needs to be connected to an amplifier.
@ Patrick I’m connecting to a speaker that is self-powered, so I figure that it is its own amplifier (also, it appears that the speaker in the project I referenced wasn’t going through an amplifier before interacting with the FEZ device).
I understand that true and false are not “audio”; that’s why I’m asking how to generate a tone to send. In my initial test, I just wanted to replace the led output with the analog output to see if I could hear [italic]something[/italic]. The true/false was part of the led output. My goal now is to figure out how to send a tone instead of simply true/false, and that’s where I’m stuck.
Did you look at the sample code on the page you just posted? That would be a start, since it actually plays audio
If you want to generate your own tones (vs playing wave files) you should look at how audio files are constructed - they’re literally “waves” (sine waves, for example.)
The speakers in the photo have a power light, so they are amplified.
I did look at the sample code. I opened it up and tried to learn how it was sending signals to the analog output port. I ran into stumbling blocks in two places:
[ol]The sample project is playing wave files and I need to generate tones instead. I’m not sure how to do that and what tones “look like” in code.[/ol]
[ol]I was also confused at how to use the AnalogOut out object from the sample code in my application. I think I was missing an assembly reference.[/ol]
I think I’ve found the assemblies I need to add to be able to work with AnalogOut, but I still don’t know what a “wave” looks like in code to be able to generate a tone. Any ideas?
I did look at the sample code. I opened it up and tried to learn how it was sending signals to the analog output port. I ran into stumbling blocks in two places:
[ol]The sample project is playing wave files and I need to generate tones instead. I’m not sure how to do that and what tones “look like” in code.[/ol]
[ol]I was also confused at how to use the AnalogOut out object from the sample code in my application. I think I was missing an assembly reference.[/ol]
I think I’ve found the assemblies I need to add to be able to work with AnalogOut, but I still don’t know what a “wave” looks like in code to be able to generate a tone. Any ideas?
I was able to find the following assemblies (GHI version 4.1.1.0) and reference them in my project:
using GHIElectronics.NETMF.Hardware;
using GHIElectronics.NETMF.IO;
using GHIElectronics.NETMF.System;
That allowed me to see the AnalogOut object. However, it seems to behave differently in my project than in the sample project. The implementation in the sample project has:
Whereas when I try to use AnalogOut in my project, AnalogOut.Set only takes one parameter, an int named value. I feel like I moved a step forward by referencing the right assemblies, but now I’m confused as to why AnalogOut seems different in my project than in the sample project.
I had thought that I had a more recent version of the SDK, but it appears I may be behind a few versions. (EDIT: I must have had the previous [italic]stable[/italic] version of the SDK, which was still several versions behind the existing beta versions).
Great tip on using PWM, by the way. I didn’t realize that PWM was exactly what I needed to generate a tone; I’m still very much a newbie at this stuff :-). I had a little bit of trouble figuring out what to do with duty cycle, but when I set it to 1, it seemed to work fine for generating my morse code tone.