Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

LED Matrix


  • Please log in to reply
30 replies to this topic

#1 Stanislav Husár

Stanislav Husár

    Advanced Member

  • Members
  • PipPipPip
  • 99 posts

Posted 12 May 2012 - 11:37 AM

Hi,

I am going to drive two-dimensional LED matrix from Shield Base. I have read, that one pin on shield base can feed up to 25 mA. That is enough for a LED. But it cannot drive more than 125 mA together on all pins. So, I may not light up more LEDs at once. But, how can I achieve this ? I have managed it to this code, but it is not working as needed:
using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware.NetduinoGo;
using NetduinoGo;
namespace Display
{
    public class Display
    {
        public int ColumnCount { get; private set; }
        public Cpu.Pin[] ColumnPins {get;private set;}
        ///<summary>
        /// WARNING: Do not write anything to column OutputPorts.
        /// Doing this will cause LED matrix to malfunction.
        /// </summary>
        public OutputPort[] Columns { get; private set; }

        public int RowCount { get; private set; }
        public Cpu.Pin[] RowPins { get; private set; }
        ///<summary>
        /// WARNING: Do not write anything to row OutputPorts.
        /// Doing this will cause LED matrix to malfunction.
        /// </summary>
        public OutputPort[] Rows { get; private set; }

        private bool[][] data;
        public bool this [int X, int Y]
        {
            get { return data[X][Y]; }
            set { data[X][Y] = value; }
        }

        private Thread DisplayThread;

        public int Delay { get; set; }
        public Display(int rows, int columns, int delay)
        {
            data = new bool[columns][];
            for(int x = 0;x < columns;x++)
                data[x] = new bool[rows];
            ColumnCount = columns;
            RowCount = rows;
            DisplayThread = new Thread(new ThreadStart(DisplayThreadWorker));
            Rows = new OutputPort[rows];
            Columns = new OutputPort[columns];
            Delay = delay;
        }
        public Display(int rows, int columns) : this(rows, columns, 5) { }
        public void StartDisplayThread()
        {
            DisplayThread.Start();
        }
        public void SetColumnPins(params Cpu.Pin[] pins)
        {
            ColumnPins = pins;
            for (int x = 0; x < ColumnCount; x++)
                Columns[x] = new OutputPort(ColumnPins[x],false);
        }
        public void SetRowPins(params Cpu.Pin[] pins)
        {
            RowPins = pins;
            for (int x = 0; x < RowCount; x++)
                Rows[x] = new OutputPort(RowPins[x], false);
        }
        private void DisplayThreadWorker()
        {
            //TODO: Make sure only one LED is on all the time!
            while (true)
            {
                for(int y = 0;y < RowCount;y++)
                    for (int x = 0; x < ColumnCount; x++)
                    {
                        for (int a = 0; a < RowCount; a++)
                            Rows[y].Write(a != y);
                        Columns[x].Write(this[x, y]);
                        Thread.Sleep(Delay);
                        Columns[x].Write(false);
                        for (int a = 0; a < RowCount; a++)
                            Rows[y].Write(false);
                    }
            }
        }
    }
}


Remarks: LED matrix is built as something similar to a grid. Row and column ends are connected to IO pins. LEDs are at cells of a grid, with cathode on rows, and anode on columns. Total 4 columns and 6 rows in this case. This makes 24 LEDs. Also, on columns, between IO pin and first LED, there are 220R resistors. I attached picture of LED matrix, resistors are on back side and are not visible therefore.

Attached Files



#2 Stanislav Husár

Stanislav Husár

    Advanced Member

  • Members
  • PipPipPip
  • 99 posts

Posted 12 May 2012 - 01:50 PM

Hi,

So I think I found one solution. At initialization of OutputPort for rows, change initial state to true. Columns initial state should remain false.
Then, code of DisplayThreadWorker will be this:
private void DisplayThreadWorker()
        {
            while (true)
            {
                for(int y = 0;y < RowCount;y++)
                    for (int x = 0; x < ColumnCount; x++)
                    {
                        Rows[y].Write(!this[x, y]);
                        Columns[x].Write(this[x, y]);
                        Thread.Sleep(Delay);
                        Rows[y].Write(this[x, y]);
                        Columns[x].Write(!this[x, y]);
                        
                    }
            }
        }



But, I will be glad, if somebody can review this new code. I want to be sure, that nothing will burn, when I run this code on freshly new Netduino Go .

#3 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 12 May 2012 - 02:10 PM

Hello Stanislav. I have no experience with the Go!, nor I'm sure about your led-grid circuit (a rough schematic could help). Anyway, I guess that you're going to "multiplex" the leds, so that a row (or column) will be active for a fraction of the cycle. The orthogonal pattern should be issued properly. All that is cycling very fast, thus there's no waving-effects. BTW, by simply driving the leds with the IOs, you can't achieve a "decent" current. Now I'm supposing that you're driving a row at once, and issuing the row-pattern accordingly. But you have four cols, so each col is driven with a 25% duty-cycle (1 of 4). That's 4x current as a "statically" activation. That's much worse than your pain! Sorry to say, but you must add some transistor. Cheers
Biggest fault of Netduino? It runs by electricity.

#4 Stanislav Husár

Stanislav Husár

    Advanced Member

  • Members
  • PipPipPip
  • 99 posts

Posted 12 May 2012 - 05:20 PM

Hi Mario,

I am driving one LED at once. I think that I do not need a transistor, because Shield Base IO pins can drive 25 mA. I have read it here: http://forums.netdui...ls-shield-base/
Or that is not enough?

What I want to do, is that I will turn one LED on, wait a while, turn it off, turn on another LED, and so on, one after another.

Also, I have attached schematics, hope that it will be useful.

EDIT: I forgot to add resistors to the schematics, they are on those four column ends.

Attached Files



#5 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 12 May 2012 - 06:06 PM

I've realized later that you posted a revised version of the code. However, the problem is still alive. You won't have any current issue, because activating one led at once, there's no problem. Instead, the problem is on the "equivalent" brightness. When any of the led is activated you'll feed roughly 10mA, but that's for a small fraction of time: in your code is 5ms. Now, your matrix has 24 leds in total, which are cycled as fast as possible. So, each led will lit for 1/24 of the whole period, and the "average current" is 10/24mA (=400uA) for each led. The led will lit, but you probably won't see enough light. You should reason as the opposite: supposing the "average brightness" as every led would have 10mA, how much should be the "peak" current for a short period as 1/24 (of duty-cycle)? Pretty straightforward: 10*24 = 240mA That's clearly not achievable by using a normal IO port. I also would suggest to use an higher voltage as supply, so that the current would be easier to regulate (resistor value). Hope it helps. Cheers
Biggest fault of Netduino? It runs by electricity.

#6 Stanislav Husár

Stanislav Husár

    Advanced Member

  • Members
  • PipPipPip
  • 99 posts

Posted 13 May 2012 - 04:29 PM

Hi,

If I feed one LED with 60 mA over a duty cycle of 1 / 6, won't it burn?
And also, if I draw 60 mA from single pin on Shield Base over a duty cycle of 1 / 6, will it burn, or not ?

Answer only if you are 100% sure, please.

#7 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 14 May 2012 - 03:41 AM

Hi,

If I feed one LED with 60 mA over a duty cycle of 1 / 6, won't it burn?
And also, if I draw 60 mA from single pin on Shield Base over a duty cycle of 1 / 6, will it burn, or not ?

Answer only if you are 100% sure, please.


For the led, there's no problem. For a short period, even 100mA (or more) does not harm the diode.
But a led is the load: the source is the shield IO pin...and that's unable to give you so much current. It's not a problem of time, but the current limitation. Above a certain current, the port auto-limits the current, for health safety.

Also bear in mind that, yes, the led could reliably work with peaks of 60+ mA, but...you must be sure that your app does not halt! Suppose you place a breakpoint in the scan routine, then the program breaks with a certain column/row active. At that point, the led(s) are constantly active, with a current much above their limit. They could burn.

Cheers
Biggest fault of Netduino? It runs by electricity.

#8 PhyliciaSchnee

PhyliciaSchnee

    New Member

  • Members
  • Pip
  • 2 posts

Posted 17 May 2012 - 09:27 AM

I don't care about anything you have to say that is not a price. Don't even bothering looking at this question if your are planning to put anything but an answer to this question. My question is, I have led's, and I mod controllers, not rapid fire but led's. What sounds like a reasonable price for that service.

#9 Stanislav Husár

Stanislav Husár

    Advanced Member

  • Members
  • PipPipPip
  • 99 posts

Posted 14 June 2012 - 05:07 PM

Hi, Mario, you were right. I tried it with only LEDs and resistors, and the LEDs are dimmed. So, I think I can solve this( NPN and PNP transistors, less ohms resistors on LEDs, and some resistors on transistors). I think I can even calculate proper values for the resistors. But what I have no idea is, how to protect the LEDs when the Netduino stops responding(for example on exception) ? Are there some resettable fuses for this ? Or what ?

#10 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 14 June 2012 - 05:17 PM

Stanislav, before I were able to give you an answer, you should answer to me to this question first: You are going to realize this "led-matrix project": do you need any led-matrix board to be connected to the Netduino (regardless of the way used), or are you just going to learn how to solve a certain circuit? In the first case, I'll suggest a certain chip that solves your problem, or either a complete board, with leds and drivers. In the second case, no matter the size of the circuit, but the only important thing is to *understand* how to move, and the circuit should be solved using very basic pieces (even maybe many of them). I'll wait for the answer...
Biggest fault of Netduino? It runs by electricity.

#11 Stanislav Husár

Stanislav Husár

    Advanced Member

  • Members
  • PipPipPip
  • 99 posts

Posted 14 June 2012 - 05:41 PM

Mario, I simply want to drive the LED matrix on the picture posted before with the Shield Base. Maybe I can use some IC, but only if it is common enough and in DIP package. Me and my father had problems with soldering that LED matrix, so soldering some smaller IC will be impossible for us two. And if I use some IC, that LED matrix is designed so that columns are on with +5V, and rows are on when grounded.

#12 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 15 June 2012 - 06:51 AM

What I'm asking to you is either:

1- here is a led-matrix board for a very low price: I own one of this. Everything you have to do is write a driver, maybe helping it with a little hardware "trick". That's because using Netduino is not straightforward, but doable. This way yields a quick-and-dirty solution, full featured, without losing time with "useless" tasks, such as bumping your head against the wall.
http://www.sureelect...ods.php?id=1095

2- you actually don't need a full featured board, nor are in a hurry. You want to build a simple led-matrix board, but mainly for learning how to do that. So how to design the transistor stages, how to calculate resistors, how to keep the leds safe, etc.
There's no DIP or small components problems, but of course you'll have to assemble the final circuit.

What is your preferred context?
Biggest fault of Netduino? It runs by electricity.

#13 Stanislav Husár

Stanislav Husár

    Advanced Member

  • Members
  • PipPipPip
  • 99 posts

Posted 15 June 2012 - 12:19 PM

Hi Mario, 1)I have to use something low-cost and what is available for me. By low-cost I mean something about 10 € . No more, I do not have my own money, and my father will not accept something more expensive. 2)I already have LED matrix builded(I have posted picture and schematics before, do you remember?). What I need is some driver for it. You have said me, that if I feed LEDs with 25mA over some duty cycle, they will be dimmed, what is right. I have some BC546B and BC556B. This is no problem for me. What I want to know, is how to protect the LEDs from burning when Netduino stops responding, because this will feed the LEDs with stable current of much more than what a LED can handle.

#14 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 15 June 2012 - 05:34 PM

At this point there are too many constraints.
Here are in brief:
- the circuit should be pretty simple, without "special" parts, such as small chips, etc.
- the cost has to be less than 10 Euro;
- the reliability of the hardware (i.e. the leds) should be high enough;
- the software should be pretty easy to write, and should *not* yield to any damage to the external circuit;
- the transistors that you have a limited current allowable (up to 100 mA);
- you are not enough expert to solve a so strict problem (and that could yield to $$$ pains);
- anything else?


A (led) matrix has convenience whereas the number of lines is an issue, but the driver circuit is more complex than the "classic" way.
There would be several solutions, but -at a glance- none of them fits all the contraints above. My suggestion is detach the leds from the matrix board, and connect them simply using many 74HC595 shift-registers. You'll need just 3 of them, plus 24 resistors: I guess that won't be more than 5 Euro, and the success is guaranteed.
The only real problem is detaching all the leds, or trash them and buy another set of leds.


I am sorry to be so frank, but I would avoid to promise you somthing that could you waste time, money or else.
Hope it helps.
Cheers
Biggest fault of Netduino? It runs by electricity.

#15 Stanislav Husár

Stanislav Husár

    Advanced Member

  • Members
  • PipPipPip
  • 99 posts

Posted 16 June 2012 - 05:56 AM

Oh Mario, I know, how I would drive the LEDs, I have some transistors(as I said before), and I can calculate resistor values for them. The problem is how to protect the LEDs. Nothing more.




Btw, I have no idea what exactly would be on PCB, if I would use shift registers.

#16 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 17 June 2012 - 05:27 AM

First point: driving the matrix. Let's suppose that your multiplex select one row a time, by shorting the signal to the ground using a NPN transistor. So, 6 rows are 6 NPN to drive. Similarly, the columns have to be driven by using 4 PNP (or else 4 NPN). Assuming a nominal current of 10mA per led, that is the equivalent current for statically powering a led, every row NPN transistor has up to 4 leds to lit. But the game is to scan the rows quickly, and since the cycle is made by 6, the current has to be scaled by 6. All that bring us to consider a current of *at least* 4 * 6 * 10mA = 240 mA for each row NPN transistor, which is far beyond the max allowable current stated for the BC546B. At this point, you should change transistor model to a BC337, for instance, which is rated for 800 mA. By the way, if you were powering all the 24 leds in parallel, without multiplex, you would have the same current: 24 * 10 mA = 240 mA. The computations match. Similarly, every column sees a current of 60 mA, which is within the max allowable bound for the BC556B. Second point: keep the leds safe. Suppose that you are lighting all the matrix, so the columns are fully powered all the cycle time long. Each column current is 60 mA, and it's correct: you can add some hardware to limit the current *above* this threshold, but not *below*. Now, what if the scan cycle breaks for any reason?...simply there's no limitation for the current, and all of it will flow through a single led. Now, a single led usually can't hold a current of 60 mA for a relatively long time. Let's say that there's no damage if you apply it for 100-200 ms, or so. Solutions? Not easy. You should add some hardware to detect that the cycle is stopped, and consequently powers off the whole matrix, for instance. Is it doable? Of course, yes. Thrid point: column's transistor polarization. You can use both PNP or NPN. I'd suggest PNP, because using NPN you will have overheat due the excessive power dissipation. Since the Netduino output can reach +3.3V, your PNP should have its emitter lead to +3.3V. Let's wrap up some voltage drop across the matrix... The row's NPN, being saturated, will drop about 0.5 V (check BC337 specs). The led about 1.5 V (I'd say even more because the high current). The column's PNP, even saturated, also 0.5 V (check BC556B specs). All that makes about 2.5 V which is too close to the +3.3 V, because the residual drop is about 0.8 V, and it's very low for having a good tuning of the current flowing. Moreover, the +3.3 V given by the Netduino aren't suitable for a 240 mA load, because the embedded regulator will get hot. So, you should move to +5V, or -better- to Vin, because the +5V regulator will also get hot. At this point, your PNP could not be driven directly by the Netduino output, but you should add a NPN stage for level shifting. However, you may use an external +5V supply, but the level shifters are needed. Fourth point: is it worthwhile? You only have to decide, but here my Eurocent... Multiplex-way: 24 leds, 6 NPN (rows), 4 PNP + 4 NPN (columns), several resistors, safety circuit to protect the leds. Classic-way: 24 leds, 3 74HC595, 24 resistors. Again, all that is the reason because my original question: is that for learning or either having the circuit ready-to-go? If you just want to learn, money usually are secondary (although not wasted). Then the multiplex way is a good exercise for learn how to design a circuit, although pretty hard for a novice, IMHO. Instead, if you are looking right to solve a certain problem, of sure the multiplex way is far more complex -and expensive- than the classic way. I do *not* want to stop you from creating your led-matrix board. I love to teach/help you to go up, as far I can do it. I only express my warnings on this solution compared to another one, since you have a very limited budget. Cheers
Biggest fault of Netduino? It runs by electricity.

#17 Stanislav Husár

Stanislav Husár

    Advanced Member

  • Members
  • PipPipPip
  • 99 posts

Posted 17 June 2012 - 05:29 PM

Oh, OK Mario, now I understand, why it is not so easy. I will move to shift registers way, but not in a few next days, because of some personal problems, which I am not going to explain.

#18 Stanislav Husár

Stanislav Husár

    Advanced Member

  • Members
  • PipPipPip
  • 99 posts

Posted 11 August 2012 - 12:59 PM

Hi Mario, I think that it may be easier for me to do it using what I already have and with transistors. Why? Using shift registers, I will have to either enlarge the display, or m ake very dense printed circuits on the PCB. Can you teach me how to do it with transistors, please? Including something for the LEDs to not burn, if Netduino stops responding.

#19 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 11 August 2012 - 03:42 PM

Welcome back, Stanislav. Well, I suppose you have still some constraint, such as the overall price, reliability, and simplicity...Is that right? I have an idea in mind, but I should think over it a bit before. At first glance, I can't ensure you will be able to match everything you expect. For instance, whereas money and display compactness are rigid constraints, I guess you'll need some (inexpensive) extra-logic for driving the leds. That means such a small PCB for holding the additional chips. I hope that will be acceptable. Let me know. Cheers
Biggest fault of Netduino? It runs by electricity.

#20 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 18 August 2012 - 12:20 PM

Stanislav, I did not forget this circuit. I only need some part for wrap up a prototype, but both the two shops I'm using to buy them are closed for holidays. They should open in a week, so be patient. Cheers
Biggest fault of Netduino? It runs by electricity.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.