Go Down

Topic: Advice on LedControl library (Read 944 times) previous topic - next topic

carpenterbee

I'm using LedControl library to control a 4 digit LED unit to display temperature captured from a Dallas 18B20 sensor. I've gotten enough to do this pretty good.  I can create a LedControl variable with the pins used to control the LED unit:

LedControl lc=LedControl(12,11,10,1);

arduino pin 12 is Datain
arduino pin 11 is CLK
arduino pin 10 is LOAD or CS
fourth arg indicates only one display is in use

Now I've got two of these displays and I'd like to use them both.  I'm using a BMP085 sensor which gives pressure and temperature ouput. I want to display the temp on one display and the pressure on the other.  I can't figure out from the LedControl online reference how to set this up.

Do I have to use a different variable in the declaration statement? In my statement above "lc" is the variable declared to be LedControl. To setup a second display with different pins do I have to use a different variable?
It doesn't make sense since the statements used in the library to control the displays all seem to have a argument to select which display they are operating on.

Or...... do you simply add the additional pins in the LedControl declaration statement?

LedControl lc=LedControl(12,11,10, 9, 8, 7, 2);

9, 8, 7 being the  arduino pins connected to the second display and the last arg "2" being the number of displays.

Wouldn't appear so as the compiler complains there are too many args.


LedControl lc=LedControl(12,11,10,2);
LedControl lc1=LedControl(9,8,7,2);


This will get past the compiler but then I have to use either the lc variable or the lc1 variable depending on which display I want a command to operate on.  This makes no sense when almost all the commands contain an argument specifying which display to operate on. Darn, I'm repeating myself! I wish there were a better explanation of how to use the neat library.

A little sunshine on this subject would sure cheer me up.  :)
Walt
North Carolina

johnwasser

I suspect the library expects multiple units to be daisy-chained.  The DataOut of the first unit feeds the DataIn of the second unit and they share the CLK and CS pins.

Can you give a pointer to where you find the LedControl library?  It's not built in to Arduino 1.0.

Can you give a pointer to the specification for your LED unit?
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

carpenterbee

I purchased the modules here: http://embedded-lab.com/blog/?p=4935

And the LedControl reference page is here: http://www.arduino.cc/playground/Main/LedControl

Hmmmmmmm, daisy chained.   Why didn't I think of that. I'm gonna try that right now.  I'll get back
to you.  heheheh

Thanks;

Walt
North Carolina

johnwasser

OK, looks like the 4th argument is the number of MAX72xx LED controllers daisy-chained together.  You'd have to poke around to find the DataOut from the MAX72xx on the first module so you can connect it to the DataIn of the second module.  If you do daisy-chain two modules, only digits 0,1,2,3 and 8,9,10,11 are likely to work since each 4-digit module has an 8-digit controller.
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

carpenterbee

Yep, daisy chained just showed the same info on both displays.  I doubt I'll have to poke around on the hardware for an output unless they guy who made these things didn't consider using more than one.  I'm going to have to contact him and see.  He does sell a board with two 4 digit leds.  All you'd have to do is add another as the Max led driver will handle a 8 by 8 matrix.  For our purposes 8 digits by 8 segments(one decimal point each digit). So it is very possible he didn't consider using two of his 4 digit modules together and didn't have an output to go to the second boards input.  Considering that his 4 digit modules were in effect wasting half of the MAX led driver, he might also have had trouble finding an output to go to another 4 digit module since the MAX driver  probably only output the inverted O15 bit for chaining to another MAX driver. Yup, just pulled up the MAX7219 data sheet and dOUT is pin 24 and is not used on the board. Would be unable to use it with two 4 digit boards as the data on dOUT is only valid after 16.5 clock cycles. So you can only daisy chain the 8 digit modules. Oh well.

Thanks for the thoughts.
Walt
North Carolina

johnwasser

As I said, if you daisy-chain two 4-digit modules you'll just have to ignore digits 4-7.  To display "1234.5678" you'd have to:

Code: [Select]

LedControl lc=LedControl(12,11,10,2);  // Two modules daisy-chained

void setup() {
   lc.setScanLimit(0, 4);   // Use only 4 digits on the first module
   lc.setScanLimit(1, 4);   // Use only 4 digits on the second module

   lc.setDigit(0, 0, 1, false);
   lc.setDigit(0, 1, 2, false);
   lc.setDigit(0, 2, 3, false);
   lc.setDigit(0, 3, 4, true);  // Decimal point
   lc.setDigit(1, 0, 5, false);
   lc.setDigit(1, 1, 6, false);
   lc.setDigit(1, 2, 7, false);
   lc.setDigit(1, 3, 8, false);
}
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

carpenterbee

#6
Aug 23, 2012, 11:22 pm Last Edit: Aug 24, 2012, 01:42 am by carpenterbee Reason: 1
Yup, I believe you are absolutely right. Since this is just a mock up of a full blown home brew weather station it's something I don't need right now.  I'll just throw it on the big LCD I've got that drives me crazy with the U8glib. heheheh

This is the first part of my current project: http://www.flickr.com/photos/73766535@N00/7841721962/in/photostream/lightbox/

I was just going to put the second module beside it. I don't want to have to tag fly wire off module one to module two right now.

This is the large LCD I'm playing with right now: http://www.flickr.com/photos/73766535@N00/7810659332/in/photostream/lightbox/

I ordered a couple of Hall effect angle sensors last night to start designing the wind direction vane.
Walt
North Carolina

Riva

To Daisychain two or more of these displays you would link CS & CLK to all the displays in parallel and then the tricky part is you need to connect pin 24 of the MAX7219 from the first display to the MOSI of the second display and so on. A bit short sighted of the designers to not break this pin out. As John says your MAX7219 is designed to handle 8x 7 segments so chaining two together you would need to address digits 1,2,3,4 & 9,10,11,12.

Go Up