This topic contains 14 replies, has 2 voices, and was last updated by  Michael P. Flaga 3 years, 4 months ago.

Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #3498

    marigold
    Member

    Hi there-

    I had one other question about the v1053 shield.. I’m trying to patch the audio back into the Arudino, to  control an LED. For some reason, this code isn’t working, though..any ideas?

     

    #include <SPI.h>
    #include <SdFat.h>
    #include <SdFatUtil.h>
    #include <SFEMP3Shield.h>

    SdFat sd;
    SFEMP3Shield MP3player;

    byte result;

    const int ledPin = 9;
    int sensorPin = 1;
    int sensorValue = 0;

    void setup() {

    Serial.begin(115200);

    result = sd.begin(SD_SEL, SPI_FULL_SPEED);

    result = MP3player.begin();

    MP3player.setVolume(20, 20);

    randomSeed (millis()); // set a more random seed for the random function

    Serial.println(“Hello”);

    pinMode(ledPin, OUTPUT);

    }

    void loop() {

    int brightness;

    MP3player.playTrack(random(5)); // range of tracks to randomly play.

    while (MP3player.isPlaying());

    {sensorValue = analogRead(sensorPin);

    Serial.println(sensorValue);

    analogWrite(ledPin, sensorValue);

    }

    MP3player.stopTrack();// stop track

    }

    #3499

    I do not believe it may be as simple and straight forward as your attempt may be.

    First electrically you don’t say what the schematic of it is. Note that the signal is AC and can be very small ranging from milli volts to 1vpp peak to peak. Note sure if you are isolating it through a cap. I believe that will need to be done, somewhere. The output amplifer of the 1053 is not isolated. And that will make it +/-. the minus will likely need to be clip the negative. So the ac signal will range from zero to positive peak, with a max of +1vp.

    the above code should likely map to rescale the analog input to the output scale.

    Also note about the Analog output; that it is really a duty cycle of a pulse. so if the signal was max of 1 vp, then that would be one fifth of the cycle. and noting even at max the signal is sinusoidal and only about a small portion is near peak.

    The other aspect of concern is your update rate. there is no delay between samples and updates of the analog-write. So your code is constantly re-writing the duty cycle, way more time then an actual cycle. I believe the default cycle is around 490 hertz ish. So you may re-writing it hundreds of times per cycle. And that may be freaking it out. Not sure. Just a guess.

    I would pass the audio input through a cap and low pass filter it. As to smooth/average out the audio energy and then sample that at 2 or 10 per second and then map (aka re-scale) that to a range that was visibly pleasing.

     

    #3500

    marigold
    Member

    Electrically, I’m using this basic arrangement for the LED: https://www.arduino.cc/en/uploads/Tutorial/ExampleCircuit_sch.png

    From there, I’m hardwiring the output of the shield (right channel) to the Analog Input (sensorPin) through 1 uF cap.

    Is there a recommended way to do the rescaling of volt-to-PWM? What about slowing the sampling rate? I’m not sure I know how to do these procedures. I’m sorry for the newbie questions, I’m sure this is a huge waste of time for you – but I know you are helping out of the goodness of your heart and I appreciate it a great deal. I’m still learning.

    #3501

    I would recommend starting with the first code shown at

    https://learn.adafruit.com/adafruit-microphone-amplifier-breakout/measuring-sound-levels

    The 2nd code is the same but has extra code for a matrix display. But look at that to. As it should store it for time.

    Also note that the 1053 and this library has a feature for measuring the transmitted power level at any time, called VUmeter.

    setVUmeter’s enable. then occasionally poll the getVUlevel and use this to replace the analogread data. Scale the output of the getVUlevel and then send it to analogwrite.

    There are set and get VU examples in both MP3Shield_Library_Demo.ino and FilePlayer.ino

     

    #3502

    marigold
    Member

    Thank you, Mr. Flaga.. I’m still a little confused about the difference between “getVUlevel” and “getVUmeter” and how to properly implement them in this code.. shouldn’t something like this work?

    void loop() {
    MP3player.playTrack(random(5)); // range of tracks to randomly play.
    while (MP3player.isPlaying());
    {

    MP3player.setVUmeter(1);
    Serial.println(MP3player.getVUmeter());
    }

    MP3player.stopTrack();// stop track

    }

    #3507

    marigold
    Member

    hi there-

    i’m trying to simplify the code, just to get the getVUmeter reading in the “while” loop….but i’m just getting a bunch of garbled text and then a stream of zeroes. any ideas?

     

     

    #include <SPI.h>

    #include <SdFat.h>

    #include <SdFatUtil.h>

    #include <SFEMP3Shield.h>

    SdFat sd;

    SFEMP3Shield MP3player;

    byte result;

     

    void setup() {

    Serial.begin(115200);

    result = sd.begin(SD_SEL, SPI_FULL_SPEED);

    result = MP3player.begin();

    MP3player.setVolume(20, 20);

    randomSeed (millis()); // set a more random seed for the random function

    Serial.println(“Hello”);

    }

    void loop() {

    MP3player.playTrack(random(5)); // range of tracks to randomly play.

    while (MP3player.isPlaying()){

    Serial.println(MP3player.getVUmeter());

    }

    MP3player.stopTrack();// stop track

    }

     

    #3508

    marigold
    Member

    There may be a larger problem – the demo code did not seem be reading the VU meter either…

    #3509

    Not sure about it not working. Honestly has been over a year since I last fired it up. I recall testing it before committing it. hmm. It may require the DSP patches, as I see it is a read of SCI_AICTRL3 . a register in the DSP and those are affected by the patches.

    about “getVUlevel” and “getVUmeter”. The later basically reads back if it is enabled. where getVUlevel returns the actual VU level on the line. note in the demo code it enables it with

    MP3player.setVUmeter(1);

    then polls it

    vu.word = MP3player.getVUlevel();

    notice that it returns a word and the union splits that into a Left and Right for the print.

    #3511

    I see right there in my documentation of the code at http://mpflaga.github.io/Sparkfun-MP3-Player-Shield-Arduino-Library/class_s_f_e_m_p3_shield.html#aed2dc5833ab0fa71c2994cf89e598f35

    get current measured VU Meter

    Returns the calculated peak sample values from both channels in 3 dB increaments through. Where the high byte represent the left channel, and the low bytes the right channel.

    Values from 0 to 31 are valid for both channels.

    Warning :This feature is only available with patches that support VU meter.

    So I suspect that there are two issues. 1) need the patches and 2) use getVUlevel.

    Hope that helps.

    #3512

    marigold
    Member

    Ah..so, I need a certain kind of patch to also be loaded on the SD card, in order for the VU to work? Then I need to use VSLoadUserCode? What kind of patch is this? I’m sorry that I’m confused..

     

     

    #3513

    Please see step #2 in the documentation at http://mpflaga.github.io/Sparkfun-MP3-Player-Shield-Arduino-Library/#Installation

    The plugin patches are located in the repo at: https://github.com/mpflaga/Sparkfun-MP3-Player-Shield-Arduino-Library/tree/master/plugins

    The libraries initializing code of the VS1053 looks optionally for the “patches.053” in the root of the SdCard. If not found it issues a warning and moves on, as it is not needed for basic functions.

    #3514

    marigold
    Member

    Ah, I think I see now. Is there anywhere that gives the specifications of the output signal from the 1053 shield? I’m having trouble finding out what sort of bias I’m dealing with or what the p-to-p values are.

     

     

    #3515

    Extrace from http://www.vlsi.fi/fileadmin/software/VS10XX/vs1053b-patches.pdf

    Where the below documentation is from the current patch from their website and is more recent patch. That I have not converted to the SFEMP3 file binary format. So the library has the old version. There is a vs_plg_to_bin.pl in the repo for creating new binary files from their patches.

    VU Meter

    SCI_STATUS bit 9 enables VU meter, which calculates a leaking peak sample value from both channels and returns the values in 1 dB resolution through SCI_AICTRL3. The high 8 bits represent the left channel, the low 8 bits the right channel.

    Note that the following has changed from the previous release.

    Values from 0 to 96 are valid for both channels. 0 means no sound, 96 is highest level. In practise the highest value will be 95, the signal is probably clipping if you get 96.

    The calculation does not take the volume setting into account.

    The VU meter takes about 0.6MHz of processing power with 48 kHz samplerate.

    _______

    from wikipedia i read:

    <span style=”color: #252525; font-family: sans-serif; font-size: 14px; line-height: 22.4px;”>0 VU is equal to +4 [dBu], or 1.228 </span>volts<span style=”color: #252525; font-family: sans-serif; font-size: 14px; line-height: 22.4px;”> </span>RMS<span style=”color: #252525; font-family: sans-serif; font-size: 14px; line-height: 22.4px;”> across a 600</span>ohm<span style=”color: #252525; font-family: sans-serif; font-size: 14px; line-height: 22.4px;”> </span>load<span style=”color: #252525; font-family: sans-serif; font-size: 14px; line-height: 22.4px;”>, or about 2.5 milliWatts</span>

    #3516

    marigold
    Member

    Sorry, I meant voltage-wise, what are the maximum values for the signal?

    I’m looking at the output of the VS1053 in a scope right now and it only seems to be operating at about +/- 0.2v.

    #3517

    not much of an expert on audio signals. I believe LINE is typically 1V peak to peak. So +/- 0.2 equal 0.4Vpp. ruffly half. And then noting that the output of the VS1053 is not LINE, but a driver for low impedance speakers. either 8 or 16 Ohm. And think is some kind of D type amplifier.

    If you need more power I recall documenting somewhere in the github doc an API to change to mono and add the currents of both the outputs into one channel. Someone did this for a stuffed toy. So it would appear to be more current based then voltage.

Viewing 15 posts - 1 through 15 (of 15 total)

You must be logged in to reply to this topic.