Lightuino 5 with audio sheild PROBLEM please help

69 views
Skip to first unread message

Joel

unread,
Jul 30, 2012, 7:04:10 PM7/30/12
to toasted-circu...@googlegroups.com
Hi.
I am using a Lightuino 5 and want to utilize an audio spectrum analyzer shield by Bliptronics.  The lightuino works by itself, and the spectrum analyzer works fine on an arduino mega 2560. 
However the problem is:  when I plug the shield on to the lightuino it does not work properly. 

 Specifically the variables returned by the library function designed to read the level of audio of a particular frequency band is unaffected by the audio coming in.  However, when i run the same code with the shield plugged into the arduino mega, it returns variables that are in sync with the audio input. 

Is there something special i need to do to make sure these interface together?  Do i have to do something special to make sure it is engaging with the correct pins on the lightuino?

Thanks a bunch of your help.
Joel

Joel

unread,
Jul 30, 2012, 11:02:18 PM7/30/12
to toasted-circu...@googlegroups.com
I think it might have something to do to the pin delcarations from the .cpp file in the library for the spectrum analyzer.    There is no declaration for the lightuino.   

it says:  



/******************************************************************************
 * SPI Defines
 ******************************************************************************/

// Duemilanove and mini w/328
#if defined(__AVR_ATmega328P__)
#define SPI_PORT PORTB
#define SPI_DDR  DDRB
#define SPI_PIN  PINB
#define SPI_MOSI 3       // Arduino pin 11.
#define SPI_MISO 4       // Arduino pin 12.
#define SPI_SCK  5       // Arduino pin 13.
#define SPI_SSN  2       // Arduino pin 10.
#define DATA_PIN 11
#define SLAVE_PIN 12
#define CLOCK_PIN 13
#define LATCH_PIN 10

// Diecimila, Duemilanove, Nano w/ ATmega168
#elif defined(__AVR_ATmega168__)
#define SPI_PORT PORTB
#define SPI_DDR  DDRB
#define SPI_PIN  PINB
#define SPI_MOSI 3       // Arduino pin 11.
#define SPI_MISO 4       // Arduino pin 12.
#define SPI_SCK  5       // Arduino pin 13.
#define SPI_SSN  2       // Arduino pin 10.
#define DATA_PIN 11
#define SLAVE_PIN 12
#define CLOCK_PIN 13
#define LATCH_PIN 10

// Mega.
#elif defined(__AVR_ATmega1280__)          
#define SPI_PORT PORTB
#define SPI_DDR  DDRB
#define SPI_PIN  PINB
#define SPI_MOSI 2       // Arduino pin 51.
#define SPI_MISO 3       // Arduino pin 50.
#define SPI_SCK  1       // Arduino pin 52.
#define SPI_SSN  0       // Arduino pin 53.
#define DATA_PIN 51
#define SLAVE_PIN 50
#define CLOCK_PIN 52
#define LATCH_PIN 53
#endif



To get things to compile at all I added the following to define the pins similar to the Duemilanove AVR_ATmega328P. 

#else // Lightuino
#define SPI_PORT PORTB
#define SPI_DDR  DDRB
#define SPI_PIN  PINB
#define SPI_MOSI 3       // Arduino pin 11.
#define SPI_MISO 4       // Arduino pin 12.
#define SPI_SCK  5       // Arduino pin 13.
#define SPI_SSN  2       // Arduino pin 10.
#define DATA_PIN 11
#define SLAVE_PIN 12
#define CLOCK_PIN 13
#define LATCH_PIN 10


This was apparently poor guesswork.   Is this the problem?  what should i put instead?

Thanks.

G. Andrew Stone

unread,
Jul 31, 2012, 3:36:09 PM7/31/12
to toasted-circu...@googlegroups.com
The Lightuino is a __AVR_ATmega328P__ so you are ok there.

I think the problem is that I am also using pins 4 and 5 (see lightuino5.h):

#define Lightuino5_CLOCK_PIN 7
#define Lightuino5_SER_DATA_LEFT_PIN 6
#define Lightuino5_SER_DATA_RIGHT_PIN 4
#define Lightuino5_BRIGHTNESS_PIN 5

#define Lightuino5_SRC_CLOCK_PIN 8
#define Lightuino5_SRC_DATA_PIN 4
#define Lightuino5_SRC_STROBE_PIN 6

(also IR pin is 2)

It is possible to switch the Lightuino's pins, but it will probably be a lot easier to switch the pins for the spectrum analyzer.  The reason is that to achieve high PWM rates the Lightuino code bit-bangs the pins with direct register writes rather then use the digitalWrite().

Cheers!
Andrew

Joel

unread,
Jul 31, 2012, 4:23:07 PM7/31/12
to toasted-circu...@googlegroups.com
Hi Andrew.  Thanks for your help.
I still don't understand what I need to do.  Is it in the defines in the .cpp for the spectrum analyzer that I need to change some of the pins so that they dont use pins 4,5,and 2, which is what the lightuino uses.    if so what do i change them to and how can i know?      is this what needs changing?:

#else // Lightuino
#define SPI_PORT PORTB
#define SPI_DDR  DDRB
#define SPI_PIN  PINB
#define SPI_MOSI 3       // Arduino pin 11.
#define SPI_MISO 4       // Arduino pin 12.
#define SPI_SCK  5       // Arduino pin 13.
#define SPI_SSN  2       // Arduino pin 10.
#define DATA_PIN 11
#define SLAVE_PIN 12
#define CLOCK_PIN 13
#define LATCH_PIN 10

As an experiment I changed the 4,5,and 2 from above to 0, 1 and 9 because it looked like those pins were not being used by lightuino.h.  I was not surprised when this did not make the analyzer work, still no reaction to audio.   the spectrum analyzer did not come with good documentation and I am not really sure how it works and so I am having trouble knowing what to change and how to change it.   do you have any suggestions.   if you dont know how i should change the freq analyzer but know how I could change the lightuino, even if it is a bit more complicated i am definetly open to any solution that will work.  
Thanks a bunch for your help.
Joel

Andrew Stone

unread,
Aug 1, 2012, 10:57:58 AM8/1/12
to toasted-circu...@googlegroups.com
Hi Joel,

I can't do a whole lot blind but you are welcome to send me a board :-).

But these pins are the physical connections so if you change the pin in code, you have to actually reroute them using jumper wires.  For now, pull the shield off the Lightuino and use jumper wires.  Connect GND and 5v.  Next connect analog 0 and 1.  Finally (this is the difference) connect Lightuino 0,1 to pins 4,5 on the shield.  ASIDE: Honestly I would use analog 2,3 (yes you can use the analog input pins as digital outputs -- search for it in the Arduino forums) -- but only because its nice to leave the UART (Serial.begin()) alone in case you need it later. 

This is the code I got from website (see below).  You'd now go through this and change every reference to pin 4 to 0 and pin 5 to 1.  At that point it should work!  Get your whole sketch working at this point to make sure you don't run out of CPU speed or memory.

When ready, you can think about how to do it permanently (i.e. with the shield plugged in).  If you look just above the digital pins on the Lightuino, you will see a bunch of tiny holes.  These are the same digital pins in the header, so you could solder jumpers there.  Then its often possible to gently bend the pins on the shield that you don't want to go straight thru (in this case pins 4,5).  Or worst case you can clip them or bend 'em 90 degrees so they stick straight out.  Now bring your jumper wires around the top and plug them into the header at 4,5 on the shield (or solder them to the bent pins).


// Spectrum analyzer read values will be kept here.
int SpectrumLeft[7];
int SpectrumRight[7];

  //Setup pins to drive the spectrum analyzer. It needs RESET and STROBE pins.
  pinMode(5, OUTPUT);
  pinMode(4, OUTPUT);

  //Init spectrum analyzer
  digitalWrite(4,LOW);  //pin 4 is strobe on shield
  digitalWrite(5,HIGH); //pin 5 is RESET on the shield
  digitalWrite(4,HIGH);
  digitalWrite(4,LOW);
  digitalWrite(5,LOW);


// Function to read 7 band equalizers
 
void readSpectrum()
{
  // Band 0 = Lowest Frequencies.
  byte Band;
  for(Band=0;Band <7; Band++)
  {
    SpectrumLeft[Band] = analogRead(0); //left
    SpectrumRight[Band] = analogRead(1) //right
    digitalWrite(4,HIGH);  //Strobe pin on the shield
    digitalWrite(4,LOW);    

Joel

unread,
Aug 1, 2012, 2:08:15 PM8/1/12
to toasted-circu...@googlegroups.com
Thank you so much!!   This solution works great thus far.    I am still writing the sketch and am still using jumpers wires.  But serial USB is now returning values that correspond with the audio frequencies as it should.  

 I am using your original pin suggestion of lightuino pins 0,1 to 4,5 on sheild and not the lightuino AN2,AN3 pins.  However, the Serial.begin() function seems to still work fine, as i am using the usb serial to see the variables on my computer.   Did you expect there would be a problem with the serial.begin with these pins? 

Again thank you so much for you help,  I spent a  lot of unproductive time trying to solve that issue, and now it appears to be solved.

Joel

Andrew Stone

unread,
Aug 1, 2012, 2:48:07 PM8/1/12
to toasted-circu...@googlegroups.com
Hi Joel,

The Lightuino's serial-thru-USB will work fine (Usb.begin()).  But the Lightuino actually has 2 serial ports: the Arduino's "Serial.begin()" is on pins 0 and 1... that one won't work.  But it does not sound like this will affect you.


On Wed, Aug 1, 2012 at 2:08 PM, Joel <awe.in...@gmail.com> wrote:
Thank you so much!!   This solution works great thus far.    I am still writing the sketch and am still using jumpers wires.  But serial USB is now returning values that correspond with the audio frequencies as it should.  

 I am using your original pin suggestion of lightuino pins 0,1 to 4,5 on sheild and not the lightuino AN2,AN3 pins.  However, the Serial.begin() function seems to still work fine, as i am using the usb serial to see the variables on my computer.   Did you expect there would be a problem with the serial.begin with these pins? 

Again thank you so much for you help,  I spent a  lot of unproductive time trying to solve that issue, and now it appears to be solved.

I would not call it unproductive even if progress was not obvious; you're becoming an embedded SW & hardware hacker!  :-)

Cheers!
Andrew

 

Joel

unread,
Aug 9, 2012, 8:56:31 PM8/9/12
to toasted-circu...@googlegroups.com
I am having a bizar problem now.   The audio input from specrtum analyzer shield only reads properly when I have println() in the function that  calls it.  The same funtion with the "println(0)" commented out causes things to not work, ie the audio does not read properly and matrix lights do not come on, (exact same code works fine when println(0) is in the loop that calls a function to read the frequency levels).  Very confusing, and i have verified this in many ways.   My work around has been to include "println(0)" in the code.  but this significantly slows down the code, and because the code powers a lighting matrix I really need that speed to avoid flickering.     

Is this because I utilized jumpers on the serial port pins to get my spectrum analyzer shield to work (as recommended and discussed previously in this thread).   Is there a solution to my new problem.   is there a work around in code, or will perhaps utilizing different pins help me?

Thanks so much for your help.
Joel

Andrew Stone

unread,
Aug 9, 2012, 9:53:23 PM8/9/12
to toasted-circu...@googlegroups.com
This is going to be impossible for me to debug without having the shield.  However, I wonder if the Lightuino's interrupt driven refresh is interfering with the analogInput.  There is no reason it should that I can tell...but its worth a try.  To try it, remove the "StartAutoLoop()" call.  But now in order to PWM the LEDs you will have to call pwm.loop() explicitly yourself.  So you cannot call "delay" (for example), but instead would need to write your own "mydelay" function that does something like "for (int i=0;i<count;i++) pwm.loop();".  And if you have time consuming code, you may need to sprinkle "pwm.loop()" calls throughout it (or see flicker).

Cheers!
Andrew

Joel Horne

unread,
Aug 10, 2012, 3:19:25 AM8/10/12
to toasted-circu...@googlegroups.com
Thanks for the reply Andrew.  I will try soon. 

Joel

unread,
Aug 14, 2012, 7:51:46 AM8/14/12
to toasted-circu...@googlegroups.com
Hi Andrew.   I am not using  "StartAutoLoop()" in my code and thus cant remove it. is there anything else?  perhaps something related to the serial port or library?     

Joel

unread,
Aug 14, 2012, 10:12:43 AM8/14/12
to toasted-circu...@googlegroups.com

Serial.end() seamed to do the trick. 
Reply all
Reply to author
Forward
0 new messages