Getting back into the hobby...got some more learning to do! Starting back with RGB

eagletalontimeagletalontim Posts: 1,380
edited 2019-02-10 - 08:03:04 in Propeller 1
Been quite some time since I have posted here and now I am quite rusty! Not sure what all has changed, but I had some old PCB's with the Prop soldered to them and started dabbling with SPIN code again. Never could grasp Assembly :(

A worker of mine is interested in doing an RGB or ARGB sound activated controller. After doing a bit of research, I have located an interesting IC...the MSGEQ7 which apparently is an amazing IC and can easily split the spectrum of an audio signal to 7 different spectrums. I really don't need all 7, but hey, if they are offered, why not use them. We would like to have the RGB change color based on the spectrum, not volume.

https://www.sparkfun.com/datasheets/Components/General/MSGEQ7.pdf

Problem I have is properly communicating with the MSGEQ7 from the Prop. I really suck at fully understanding datasheets and putting the information in them to proper use. I can see there are 2 pins that are Reset and Strobe which I believe are the signal needed from the Prop to get data out from the MSGEQ7.

So from what I gather is I need to do something like? :
CON
        _clkmode = xtal1 + pll16x                                               'Standard clock mode * crystal frequency = 80 MHz
        _xinfreq = 5_000_000

OBJ
  Pst    : "Parallax Serial Terminal"  ' to be used for testing
  adc : "adc0831_fast"

VAR
  LONG adcArray[6]      ' Array to hold spectrum data from ADC
  BYTE i

PUB main
  dira[reset_pin]~~      ' set to output
  dira[strobe_pin]~~    ' set to output
  outa[reset_pin] := 0  ' ensure pin is off
  outa[strobe_pin] := 0  ' ensure pin is off

  adc.start(cs, clk, data, sample_rate, @adcValue)
  pause(10)    '  Let ADC initialize

  ' initialize MSGEQ7
  outa[reset_pin] := 1
  outa[strobe_pin] := 1
  pause(2)
  outa[strobe_pin] := 0
  pause(2)
  outa[reset_pin] := 0

  i := 0
  repeat
    outa[strobe_pin] := 1
    pause(2)
    outa[strobe_pin] := 0
    pause(2)    '  allow time for ADC to update?
    adcArray[i] := adcValue
    pause(2)
    i++
    if i == 7  ' array 0 to 6 for 7 spectrum data
      i := 0

So none of this code is tested at all since I have not bought the MSGEQ7 just yet. This is off the top of my head :P Maybe there is a better option out there for what I am trying to do :) I seen another project using the same IC, but there is no code to go by.

Comments

  • That's an interesting chip to play with. The code you have so far seems reasonable for controlling the chip and converting the outputs to digital. Now you need to come up with a plan to convert those readings to intensity values for the RGB leds. Do keep in mind that the output readings are going to be proportional to the volume (voltage) of each part of the spectrum so if you use those values to control the intensities of the RGB leds the intensity of the individual R, G, or B leds will vary with the voltage from that frequency band, and the resulting color will vary with the ratio between those voltages.
    In science there is no authority. There is only experiment.
    Life is unpredictable. Eat dessert first.
  • eagletalontimeagletalontim Posts: 1,380
    edited 2019-02-10 - 17:15:37
    I was reading that too which is going to be another interesting problem to over come as the input level will more than likely be adjusted. Not sure if I can do a software filter or if I need to use some sort of other hardware method to avoid this issue. My thoughts are to adjust the input filtering on Pin 5 (IN) to Peak the ADC value (255) with the volume at the highest listening level, then use software to get the average of all 7 of the spectrum values or use the Peak signal to display the RGB color.
    BYTE rgbColor
    BYTE R_intensity
    BYTE G_intensity
    BYTE B_intensity
    
    PUB getAverage(the_array, sample_count) | i, arraysum  ' May not use this function
        arraysum := 0
        repeat i from 0 to sample_count
          arraysum += long[the_array][i]
        return arraysum / sample_count
    
    PUB getPeak(the_array, sample_count) | i, peak    ' get most dominant spectrum.
        arraysum := 0
        peak := 0
        repeat i from 0 to sample_count
          if peak =< long[the_array][i]
            peak := long[the_array][i]
        return i  ' may also use peak instead of i
    
    PUB calculateRGB | peak, peak_val, addto, i
      peak := getPeak(@adcValue, 7)
      peak_val := long[@adcValue][peak]  ' not sure if this line would work
      addto := 255 - peak_val  ' figure amount to add to other values to increase Volume.  This might cause problems...
    
      repeat i from 0 to 2  ' R - G - B
        case i
          0:
            IF peak == 0 OR peak == 1
              R_intensity := long[@adcValue][peak] + addto
            ELSE
              R_intensity := long[@adcValue][0] + addto   ' default if not peaking in this range
          1:
            IF peak == 2 OR peak == 3 OR peak == 4
              G_intensity := long[@adcValue][peak] + addto
            ELSE
              G_intensity := long[@adcValue][3] + addto   ' default if not peaking in this range
          2:
            IF peak == 5 OR peak == 6
              B_intensity := long[@adcValue][peak] + addto
            ELSE
              B_intensity := long[@adcValue][6] + addto   ' default if not peaking in this range
    


    This code has not been tested either, but should represent the idea. If the "peak" is in the low range, Red will light up more intense than the rest of the ranges.

  • ...... If the "peak" is in the low range, Red will light up more intense than the rest of the ranges.


    My guess is that the average peak value for each of the 7 bands will vary quite a bit, so getting a nice display may not be so easy, but since it can be done with code instead of hardware you can do a lot of experimenting. Using an array of 2811/2812 led strips with the right software would make for an awesome display. Imagine using some of the bands for color and one or two for shapes or led addressing on an xy array of leds.
    In science there is no authority. There is only experiment.
    Life is unpredictable. Eat dessert first.
Sign In or Register to comment.