Tag-Archive: led

1 Watt constant current LED driver shootout

1 Watt LED drivers

As many electronic hobbyists, I have always been fascinated by LEDs, especially the really bright ones. I could now ramble on about 50W or 100W LEDs, but to connect to the story of my previous post, I will talk a little about driving 1 Watt LEDs, the ones that come on a star shaped heatsink (e.g. the first Luxeon generation). While you could connect those with a current limiting resistor as you do with the small 20mA LEDs, it is not a really wise thing to do as you would need large resistors, withstanding an unhealthy amount of heat. So the device of choice is a constant current source – in this case one that provides 350mA constant current. I have three different ones and took some time to evaluate them from a users perspective (meaning ease of use, etc. – I will not talk about output ripple, stability, surges, etc.).

The good, the bad and the ugly?

1 Watt constant current LED driversI going to look at three different constant current sources:

They all work pretty straight forward, you supply them with a voltage between 9V and 30V (+/-) and they output 350mA of current with which you can drive one or more 1Watt LEDs in series (provided the combined forward voltage doesn’t exceed your input voltage). No suprise here, they all do that and work just fine. But what about dimming the LEDs? Each of the drivers has a dedicated pin for that. And here it get’s complicated…

Meanwell LDD-350L

This one is the most uncomplicated of the bunch. To use the dimming pin, simply apply a PWM signal (in my case from an Arduino), and the driver will dim the LED according to your PWM duty cycle. 10% duty cycle = 10% current (which is not neccesarily 10% brightness as the relationship between brightness and current is not linear with these LEDs), 50% duty cycle = 50% current, 100% duty cycle = 100% current. You catch my drift. The driver will align the output to the duty cycle (and even the PWM frequency) of the DIM pin.

LDD350L with 50% duty cycle on Arduino pin 5

LDD350L with 50% duty cycle on Arduino pin 5

 

LDD350L with 50% duty cycle on Arduino pin 3

LDD350L with 50% duty cycle on Arduino pin 3

Since pins 3/9/10/11 and 5/6 (on the Arduino UNO compatibles) use two different PWM frequencies, this is reflected in the above wave forms.

ANVILEX CCS2

As mentioned in the previous post, the ZETEX chip an this current source is a little odd with regard to PWM control. In my tests, I found out that a duty cycle between 0% and about 45% gives you current control from 0% to 100% (using a 5V PWM signal). If you raise the duty cycle to more than 45%, the driver will exponentially increase the output current, thus overdriving the LED. A duty cycle of 55% will yield more than 520mA output current, guaranteeing premature ageing and death of your LED. So be careful. This driver also copies the PWM frequency from the input source, which is exactly what the datasheet said: Depending upon the control frequency, this will provide either a continuous (dimmed) or a gated output current. Since the PWM frequency is above 300Hz, we see a gated output waveform on the oscilloscope:

Anvilex CCS2 with 40% duty cycle on Arduino pin 3

Anvilex CCS2 with 40% duty cycle on Arduino pin 3

To work with this driver, you have to make sure to limit the PWM duty cycle to a maximum less than 50%, otherwise you might fry your LED (and maybe more…). This driver also produces hissing noises varying on the PWM duty cycle which may annoy you depending on your use case.

No-Name (with XLSemi XL4001 chip)

This is one of the cheap LED drivers you can get on ebay for just a couple of Euros. It has almost the same components as the CCS2, namely input/output smoothing caps, schottky diode, an inductor and some resistors to configure the chip. The only real difference is the XLSemi XL4001 chip that is used on this module. It it not per se a LED driver, it is a multipurpose DC/DC buck converter, but it features a current control loop, so that it can be used as a constant current source too. This driver can be dimmed using PWM as well, but the output waveform has nothing in common with the input waveform. In fact, it looks a little odd:

XLSemi XL4001 output waveform

XLSemi XL4001 output waveform

Dimming this driver offers some pitfalls: the PWM pin is the ENABLE pin of the chip, which is inverted. This means a PWM duty cycle of 0% will cause the driver to output a current level of 100% and a duty cycle of 100% will shut the driver down. Just keep that in mind when designing your sketch or whatever. The other thing: although the datsheet says, that the default state of the ENABLE pin is low, it will not return to that state if the chip already received a PWM signal and the signal wire is disconnected afterwards. Instead, it will spiral upwards, causing the output off excessive amounts of current to the LED, slowly killing it. So when experimenting with it, be sure not to pull out any wires while the circuit is still live.

Conclusion

There is no winner to be named here, these drivers all do what they were made to do. If I had to pick a favorite, it would be the Meanwell LDD-350L because it is *so* uncomplicated to work with and there a no suprises. You can work with the others as well, but be sure to read up on the special traits of each driver/chip so you can avoid nasty surprises.

How to blow up electronics #1 – with power LEDs

So the other day I started working on a custom high power LED strip, using red, green and blue 1 Watt power LEDs. Nothing really fancy, just 7 LEDs in series per color, each driven by a 350mA constant current source at about 24 volts. I decided to throw in an Arduino for brightness control, since the cc sources have PWM dimming capability. Fun fact: I didn’t need to buy any additional components, everything I needed I had lying around somewhere (don’t ask…).

The setup

The setup is pretty straight forward: the thing is powered by 12V DC which is then boosted to 24V by some beefy boost converter. Those 24V are then hooked up to three Anvilex CCS2-350 constant current drivers. Each string of 7 LEDs – with blue haven the highest forward voltage, thus 7×3.5V ~= 24V – is connected to one of these drivers.

Arduino power LED control box

Power LED control box

Dimming with the Arduino

Enter the Arduino: for testing purposes I added a classic Freeduino (Duemilanove clone), connecting it to the 12V input voltage and attaching the PWM ports to the DIM ports of the CCS2s. There are some caveats using the CCS2 and the data sheet doesn’t make it very easy to understand them (either this or I am a rather slow learner…). Anyway. The CCS2 uses the Zetex ZXLD1366 LED driver chip and this chip provides the DIM pin. This pin is some sort of „jack of all trades“ and accepts analog voltages, PWM modulated voltages or PWM gating.

Fun with the ZXLD1366 specs

The ADJ pin will accept either a DC voltage or a PWM waveform. Depending upon the control frequency, this will provide either a continuous (dimmed) or a gated output current. — from the ZXLD1366 datasheet

What the hell does that mean? It means you can either

  • suppy a true analog voltage or
  • a PWM signal which will cause
    • true analog current control at a low frequency (< 300 MHz) or
    • gated output control (meaning „chopped“ on/off/on/off cyles relation to your PWM signal)

Since the lowest PWM frequency you can get on the Arduino is 490 MHz (not using any timer manipulation or soft PWM), we will have gated output control.

That doesn’t sound so bad – but there is another drawback to trip over: the DIM pin can withstand voltages up to 6 volts, BUT the output current will reach the designated maximum value (in my case 350mA) at a voltage of 1.25V. The chip will shutdown to power saving when the voltage drops below 0.2 volts. And (here it comes): anything between 1.25V und 2.5V will further increase the current output up to twice the maximum (700 mA). Voltage increases above 2.5V have no further effect.

Congratulations, we have just found the means of blowing up our LEDs. So I had to limit the PWM range to 0-63 (256 steps/5 Volts * 1.25V ~= 63). No problem here, we are just losing some resolution.

Blowing stuff up

I wrote a small test sketch to see if everything worked an it surely did. I the replaced the bulky Freeduino with a soldered in Pro Mini that will actually fit inside the enclosure. I fired everything up again and there it was: a well audible bzzzt and then silence. Followed by some erratic flashing on the power LED side. The Pro Mini had gone out with a bang (you have to see volume in relation to the size of the components…). But why? Frantically checking everything it turned out the Atmega328 was fried. Interestingly enough, also one of the power LEDs got killed in the process. I realised that when I connected the Freeduino again and the red LED string wouldn’t come on anymore.

I replaced the faulty LED and ran everything again and it all worked fine. I then replaced the Freeduino with another Pro Mini and measured everything without the LEDs attached and it surely would work. I then reattached the LEDs and … bzzzt. Another Pro Mini dead. And another power LED. WTF?

Once more measuring everything after hooking up the Freeduino again. This time I also used my trusty pocket oscilloscope. And what did I find? I was betrayed by my love for cheap components…

WTF? Why?

Some electronic components I fried

The components I fried

So, here’s what happened: I am using a rather cheap 30W 12V power supply. It is supposed to power 21 Watts of LEDs and assuming that to boost converter operates at an optimistic 85% efficiency rate, it would need to provide a least 25 Watts of power. And it does. During a brief period when the circuit is already powered and the Arduino has booted, the CCS2 will power the LEDs at full brightness (I guess that’s by design). So the whole thing draws 25 Watts right from the start. The power supply compensates for the sudden demand, but there is a slight voltage spike of ~13V as it does. That spike is no problem for the 7805 on the Freeduino and it would also be no problem for the MIC5205 (up to 16 Volts VIN) on the Pro Mini had I been using a genuine one and not some cheap clones. The clones come with a MIC5219 or some other cheaper regulator that allows only 12 Volts at VIN.

So the regulator was fried by the voltage spike. That in turn damaged the Atmega chip and made it send more than 2.5V to the DIM pins. The LED current was doubled and one LED sacrified itself so that the others could survive. On the second attempt, uregulated voltage was flowing everywhere and even killed one of the constant current sources. Yay! No…

Lessons learned

So, what do I take with me from this whole mess? Well, I guess I could have avoided those mistakes by thinking a little bit more before soldering. Measure twice, cut once they say. I say: But cutting is more fun than measuring :-). So better luck next time. Here are the two major learnings:

  • Don’t rely on the linear voltage regulator of your Arduino, especially not on tiny, cheap Arduino clones. Either use a standalone 7805 regulator or – and that is the preferred way – use a switching step-down (or even a really fancy step-up/step-down) converter such as the Pololu D24V5F5 or the S10V4F5. They can take at least 18 Volts and are have builtin safeties.
  • Use a voltage divider circuit for the PWM signal on the DIM pin. This gives you the full resolution of 256 steps on the PWM (although atmittedly you really can’t see any difference in brightness using only a single step) and it protects the DIM pin – and your LEDs – against over-voltage/current.

Günstiger H-Quad – Teil 3 – Antrieb und Elektronik

Der finale Aufbau (ohne Batteriehalterung)

Antrieb

Nachdem der eigentliche Rahmen nun zusammengesetzt und die Motore montiert war, konnte es an die Verkabelung des Antriebs und der Steuerung gehen. Der Quad verwendet Turnigy Plush 25A ESCs, die ich mit der BLHeli-Firmware geflasht habe. SimonK ging leider nicht, weil die ESCs Silabs-Chips benutzen und keine Atmel-Chips. BLHeli ist aber auch immer noch eine sehr gute Wahl und steht – meiner persönlichen Meinung nach – SimonK in nur wenigem nach. Die Plush-Regler besitze ich schon eine ganze Weile und sie kamen auch schon bei meinen ersten Quadcopter-Versuchen zum Einsatz.

Einpassen der Regler

Einpassen der Regler

Ziel war es, die Regler samt Stromverteiler in den Raum zwischen unterer unter oberer Platte zu quetschen, damit das ganze Wirrwarr aus dem Weg ist und ich da nicht mehr ran muss. Nach einer ersten Platzierung wurde dann schnell klar, dass der Stromverteiler nicht wirklich groß werden durfte, also entschied ich mich für die „klassische“ Variante und habe für Plus und Minus jeweils einen 1-auf-4-Kabelbaum gelötet. Dessen Verbindungsteil passte gut in die Mitte zwischen die Regler. Um noch mehr Platz und auch Gewicht zu sparen, habe ich die Stromleitungen direkt and die ESCs gelötet und auf dieser Seite auf Stecker verzichtet.

Fertiger Antriebsstrang

Fertiger Antriebsstrang

Danach habe ich dann die Regler alle wieder mit Schrumpfschlauch geschützt und den ganzen Antrieb mit Kabelbindern an der Bodenplatte fixiert. Danach sah es dann auch nicht mehr so chaotisch aus ;-). Da bei so viel Löterei auch mal was schief gehen kann, war es notwendig, die Stromleitungen durchzumessen, um sicher zugehen, dass ich nicht irgendwo einen Kurzschluss verursacht hatte. Nichts ist ärgerlicher als eine Lipo-Explosion auf dem Esszimmertisch 😉

Der Kabelbaum bekam einen XT60-Stecker und pro Pol zwei zusätzliche Abzweigungen mit 2mm-Goldkontaktsteckern. Diese nutze ich später für die Spannungsmessfunktion des KK 2.0-Boards und als Stromanschluss für die LED-Beleuchtung. Wichtig: die Deckplatte sollte erst angeschraubt werden, wenn man die Drehrichtung der einzelnen Motoren verifiziert hat, sonst muss man alles wieder zerlegen wenn man zu spät feststellt, dass ein oder mehrere Motoren falsch herum drehen.

Die Deckplatte wird mit 6 kleinen Holzschrauben befestigt, deren Köpfe versenkt sind. Vorbohren hilft hier, sonst wird evtl. der Rahmen beschädigt. Durch die Verschraubung kann die Platte bei Bedarf wieder abgenommen werden. Der Stromanschluss und die Reglerkabel wurden durch ein Loch in der hinteren Hälfte der Deckplatte nach draußen geführt.

Steuerung

KK 2.0-Controller und Batteriehalterung

KK 2.0-Controller und Batteriehalterung

Da ich bei dem H-Quad in erste Linie auf „Resteverwertung“ setze, musste er mit dem KK-2.0-Board fliegen, dass ich schon seit einiger Zeit rumliegen hatte, mit dem ich aber nie zufrieden war. Das wiederum liegt gar nicht am Board selber sondern an mir, da ich die Lernkurve für die PID-Einstellungen damals noch nicht gemeistert hatte…

Das Board wurde genau in der Mitte der Deckplatte mit Nylonschrauben befestigt. Ich hatte mir zunächst auch einige Sorgen wegen der Batteriebefestigung gemacht: ich bin kein Freund von unter dem Copter montierten Akkus, da immer eine latente Gefahr besteht, dass auch im normalen Betrieb beschädigt werden. Andererseits würde eine über dem Controller montierte Batterie den Schwerpunkt zu weit anheben – zumindest war das meine Befürchtung. Dann aber sah ich ein paar Videos der kleinen Blackout-Racing-Quads, die gerade recht beliebt sind. Die Dinger haben auch den Controller unten und die Batterie oben und deren Flugleistung ist wirklich beeindruckend. Damit war diese Designfrage dann auch gelöst.

Für die Batterie montierte ich einen durchgängigen Steg aus einer 5mm starken und 4cm breiten Holzleiste, die an den Enden über Metallabstandshalter an der Deckplatte befestigt wurden. Um die Abstandshalter stabil zu bekommen habe ich solche mit einem durchgängigen Gewinde verwendet und mit einer recht langen M3-Schraube an der Deckplatte befestigt, die fast komplett durch beide Abstandshalter geht (siehe Foto links). Das gab dem jeweiligen Abstandshalter nochmal zusätzliche Stabilität.

KK 2.0-Board/Motoren anschließen

Steuerung provisorisch montiert für Motortest

Steuerung provisorisch montiert für Motortest

Das KK-Board bekam noch eine zusätzliche Leitung verpasst, mit der die Software die Spannung der Batterie messen kann. Seit Version 2.1 des Board ist dieser Anschluss ganz normal als Steckverbindung verfügbar, beim 2.0 muss man noch ein Kabel an ein schon vorhandenes Pad/Bohrung anlöten.

Der Anschluss der Motoren gestaltete sich einfach. Motor 1 ist der Motor links vorne, die anderen folgen dann im Uhrzeigersinn. Die Steckleiste für die Motoren beim KK ist die rechts neben dem Display. Sie beginnt oben mit Motor 1 und alle weiteren Motoren werden jeweils darunter angeschlossen. Zu beachten sind zwei Dinge: a) die Signalleitung muss zum inneren des Boards zeigen, der Minuspol zu Rand. b) Das KK-Board bezieht seinen Strom ausschließlich über den BEC vom Regler von Motor 1. Alle anderen BEC-Pluspole sind im KK-Board nicht angeschlossen. Für diejenigen unter Euch, die Opto-Regler ohne BEC benutzen, heißt dass, dass ihr einen gesonderten BEC braucht und den über den Anschluss für den ersten Motor einschleifen müsst.

Empfänger anschließen

Alle Komponenten montiert

Alle Komponenten montiert

Da das KK 2.0-Board ein recht einfacher Flug-Controller ist, reicht für die Steuerung ein 4-Kanal-Empfänger aus. Die einzige Sonderfunktion, für die man einen 5. Kanal nutzen könnte, ist – zumindest in der Standardsoftware von KapteinKuk – Autolevel. Das lässt sich aber auch über ein Stick-Kommando aktivieren, also muss man mit 4 Kanälen auf nichts verzichten. Ich verwende einen Spektrum AR400-Empfänger. Angeschlossen wurde der Empfänger an die Leiste links neben dem Display. Auch hier gilt wieder: Signal nach innen, Masse nach aussen. Von oben nach unten wurden angeschlossen: Aileron/Querruder, Elevator/Höhenruder, Throttle/Gas, Rudder/Seitenruder. Der Anschluss für AUX bleibt leer, dafür war ja kein Kanal mehr frei.

Abschlussarbeiten

Danach wurde noch der Buzzer am KK 2.0-Board angeschlossen und das Kabelchaos mit Hilfe einiger Klebesockel und Kabelbindern eingedämmt. Da der H-Quad vollkommen symmetrisch ist und ich ihn nicht lackieren wollte, musste eine andere Orientierungshilfe her. Vorne und hinten habe ich daher einen durchgängigen LED-Streifen angebracht. Da die Streifen mit 12 Volt betrieben werden können, ließen sie sich direkt an die Batterie anschließen. Bei Betrieb leuchtet der Copter vorne blau und hinten rot – und das recht hell. Damit sollte die Fluglage auch aus einiger Entfernung noch erkennbar sein.

Damit war die eigentliche Arbeit am Quad beendet, es konnten Einstellungsarbeiten für das KK 2.0-Board, die Fernsteuerung und die PID-Werte folgen.

 

 

Bildergalerie für diesen Bauabschnitt

Quadcopter-Elektronik und Batteriehalterung

HobbyKing Multirotor Control Board mit Stromverteiler

HobbyKing Multirotor Control Board mit Stromverteiler

Ein kurzes Update aus der Werkstatt: die Elektronik für den Quadcopter ist jetzt da. Die eigentliche Steuerung übernimmt ein HobbyKing Multi-Rotor Control Board und damit ich nicht noch eine Kabelpeitsche löten muss, die nirgendwo hinpasst, übernimmt die Stromverteilung ein HobbyKing Quadcopter Power Distribution Board. Passenderweise lassen sich die EC3-Stecker, die ich schon vorher auf die ESCs gelötet hatte, genau passend auf den Stromverteiler stecken. Glück gehabt, ich hatte mir schon Sorgen gemacht, ob das mit den EC3-Steckern nicht etwas verfrüht war.

Bevor die Elektronik allerdings montiert werden kann, muss der Rahmen komplettiert werden, sonst kann das Ding nicht fliegen. Es bleiben vier Punkte zu erledigen:

  1. Eine Befestigungsmöglichkeit für die Batterie finden, die möglichst leicht ist und die Batterie auch noch bei unsanften Landungen vor Schäden bewahrt.
  2. Ein Landegestellt bauen
  3. Die Elektronik auf der oberen Platte montierbar machen
  4. Dem Quadcopter ein „Vorne“ zuweisen, durch Lackierung, andersfarbige Propeller oder LEDs
Prototyp der Bodenplatte mit Batteriehalter und Landehilfe

Prototyp der Bodenplatte mit Batteriehalter und Landehilfe

Um Punkt 1 besser planen zu können, habe ich eine Kopie der Unterplatte aus HobbyColor erstellt und dann dafür eine Halterung in Form eines Rahmens entworfen. Dieser wird mit M6x50 Plastikschrauben und Abstandshaltern an der Unterplatte befestigt. Die Plastikschrauben übernehmen dann auch noch die Funktion einer Landehilfe für die Mittelsektion. Ob diese Konstruktion wirklich ausreichend stabil ist wird sich dann zeigen. Wenn ich für die Platten in der Mitte auf Carbon umsteigen sollte, ist auch eine zusätzliche Platte zu Stabilisierung und zum Schutz gewichtsmäßig drin, mit dem jetzigen Platinenmaterial wird das alles zu schwer.

Als Material für ein leichtes Landegestellt habe ich hier Isolierung für Heizungsrohre herumliegen, ich denke, dass ich diese Schaumrohre zuschneiden und an den Auslegern befestigen kann. Für den Anfang reicht das hoffentlich und verbessern kann man das immer noch.

Den Rest der Punkte adressiere ich später, jetzt mache ich mich erstmal an die Herstellung der Batteriehalterung aus Platinenmaterial.

Presenting the ICMI MAX7219 Arduino library

For my current project, the ICMI Service Status Monitor, I have chosen the Maxim MAX7219 IC to drive the indicator LEDs. This little chip comes with several nice out of the box features such as adjustable LED current, 16 level brightness control, special decode mode for seven segment displays and so on. The main reason I chose it is because it contains a multiplex scan mechanism implemented in hardware. This frees my own code from a lot of additional complexity that I would encounter if I chose to implement multiplex scanning in software (which is not impossible of course and I’ve already done it – check the code samples for my ICMI Seven Segment Board – but it’s nice not having to do it and besides that, the focus of this projects lies more on the PC/Arduino communication).

Control issues

The downside of using the MAX7219 is the more complex communication with the chip required to make things work. The IC uses various registers to store its configuration state and when sending data, you also have to address the proper register and pass the data in a format specified in the data sheet. To make things easier, I chose to implement this communication in form of an Arduino library that makes using the MAX7219 a whole lot easier by hiding the complexity behind a neat API. Others have implemented such a library before more of course and some of them also offer additional functionality such as multi-chip configuration or CODE B digit decoding. I do not intend to compete with them (at least not yet), I merely took the opportunity of extending my skills.

The code for this library along with example code is available on github at https://github.com/hmbusch/ICMI-MAX7219-Arduino

API description

This section describes the methods available to the user when importing this library. Again: don’t get confused by the uint8_t data type – it is the same as byte in Arduino and can hold an integer value between 0 and 255.

Constructor Max7219(uint8_t dataPin, uint8_t clockPin, uint8_t loadPin, uint8_t digitCount)

This constructor is used to create a new „control instance“ for the connected MAX7219 chip. The IC required 3 Arduino pins – the data pin, the clock pin and the load pin (pins 1, 13 and 12 of the MAX7219) that you need to pass to the constructor. In addition, you have to tell it, how many digits (when using seven segment displays) or rows (that’s what we want) are connected to the driver. This value is used internally to verify the parameters of later method calls. Example (Arduino connected with pins 5, 6 and 7):

 

Method void enable(boolean enable)

The whole LED driver can be shutdown by disabling it. All its settings and the current state are preserved, the chip just ceases to operate. After a power reset, the chip is disabled by default so you will need to call max7219.enable(true) (assuming the control instance was constructed with the name  max7219  as in the constructor example above) if you want it to show something. If you omit this call, all your configuration commands will still configure the chip but you simply won’t see it. Enabling and disabling the driver can also be used to flash the whole display.

Methods void setDigitRaw(uint8_t which, uint8_t value) / void setRow(uint8_t which, uint8_t value)

These two methods are actually only one method with two names. I introduced these names so a user could call whichever method best fits in the context of his program. If your program controls a LED matrix, calls to setDigitRaw() might seem a little strange so you could use setRow() instead.

This is the method that actually tells the driver what to display. You have to specify the index of the row/digit that you want to set (ranging from 0-7, limited by the row/digit count you gave in the constructor) and the value you want to set it to. To make things easier, the method performs a bit level translation of the value from your value to what the MAX7219 expects. This way, the bit order equals the segment or column order. Bit 0 (the rightmost bit, also called the least significant bit) corresponds to segment A (column 1), bit 1 corresponds to segment B (column 2) and so on. To display the number 7 on the fourth digit of a seven segment display, you would pass 3 as the index and  B00000111  (segment A-C lit).

Although the MAX7219 supports it, the library currently does not offer a way to pass a BCD number to the chip. When using BCD mode, you could display a 7 by actually passing a 7 as value and the chip will take care of the decoding to segments. This feature may be included in future releases. The current lack of this feature is the reason why this method is called  setDigitRaw()  and not just setDigit() .

Method void setIntensity(uint8_t level)

The MAX7219 offers a built-in brightness control for the display with a 16 step resolution. This method allows you to set the brightness level for the display and accepts value from 1 (darkest) to 16 (brightest). Any value below 1 will be treated as 1, any value above 16 will be treated as 16. It is not possible to switch off the display, even the darkest setting is still visible and does not stand for „off“. If you want to turn of the display, call  enable(false)  instead. The constructor will set the chip to the highest brightness. This is a sort of safety precaution I created, because the IC’s initial brightness setting defaults to the lowest level. During testing, I wrecked my head trying to figure out why the LEDs were so dim, not realising the brightness settings. For others to avoid this mistake, I reversed the default brightness value in my library implementation.

Method  void testDisplay(boolean testDisplay)

This method can be used to toggle the internal test mode of the MAX7219 on and off. When enabling test mode, the IC switches on all LEDs (regardless of the row/digit count passed to the constructor) and sets brightness to maximum. Enabling the test mode will not overwrite any settings made before entering the test mode, which means when switching back to normal mode, the display will revert to the exact setting that it hade before entering test mode. This method is useful for verifying your LED display and to be able to quickly switch to a fully lit LED panel without having to change each row and saving the state of the display in order to return to that state later.

Method void clearDisplay()

This method does exactly what the name promises: it clears the display by turning all LEDs in all rows off. This operation cannot be undone, that means once you clear the display, you have to reprogram it again, you cannot simply switch back to a previous state.

Method uint8_t version()

In order to provide some hint to a users program regarding the compatibility of the library, this method returns the current version number of the library. This can be used to check programmatically, if the user needs to update to a newer version and it can be used to prevent incompatibility issues.

Using the library

Using this library for your own projects is a two-step process. First, you need to install the library to your Arduino IDE and then you need to import it into you sketch.

Installing the library to the Arduino IDE

Use a file manager to navigate to the directory where your Arduino IDE resides (e.g. D:\Development\Arduino-1.0). Go into the folder called libraries and create a new folder there called ICMIMax7219. Copy the Max7219.cpp and .h files as well as the examples folder into the newly created directory. If your IDE was running at that time, you have to restart it for the changes to take effect. After the restart, go the File => Examples menu. If everything succeeded, you should see and entry called ICMIMax7219 and you can open the BasicFunctionExample from there.

Note: If you have another library for the MAX7219 installed, you may encounter naming clashes when the files of the other library are also named Max7219.*. When encountering this, remove the other MAX7219 library from your Arduino IDE. I will address this problem in the second release of the library.

Using the library in your code

To use the library in your own sketch, you need to import the header file. Do this by placing the line

at the very top of your sketch. This enables you to access the libraries functionality. In order to do so, you need to create an instance of the Max7219 class somewhere in you project. You can do this by calling the constructor as follows

First, the example defines some integer constants to represents the Arduino pins the IC is connected to and the digit/row count. The last line then creates an instance with the name max7219 which can subsequently be used to control the IC with calls like

In order to see a full, working sketch that uses the library, please refer to the BasicFunctionDemo sketch in the examples folder. The video embedded at the start of the post shows you what the output of this sketch will look like on an 8×8 LED matrix.