Go Down

Topic: Dim led segment display  (Read 970 times) previous topic - next topic

matoex

Nov 17, 2015, 12:39 am Last Edit: Nov 17, 2015, 01:00 am by matoex
Hi everyone.
I have got 2 digit led segment display (datasheet). I wired it to Arduino Leonardo and I show temperature from DHT11 sensor on this dislay. I am using multiplexing, and PNP transistors BC556B (datasheet). Transistors are connected like here on diagram.

When time of switching beetween digits is about  2ms (it's enough fast to not to see blinking), unfortunately second digit is really dim. When delay is increased to 100ms both digits are enough bright but blinking disturb.

What is a obstacle? How can I solve this problem, any tips?

My code:
Code: [Select]

#include <LEDDisplay.h>
#include <dht.h>
dht DHT;
#define DHT11_PIN 11

LEDDisplay *led;  
int millisecondsPerCount;  
int counter;
int tempC;
unsigned long lastUpdate;

void setup()  
{
    Serial.begin(9600);
    millisecondsPerCount = 1000;
    int digitFlagPins[] = {8,9};
    int segmentPins[] = {0,1,2,3,4,5,6,7};
    int decimalPointPin = 7;
    led = new LEDDisplay(2, digitFlagPins, segmentPins, decimalPointPin);
}

void loop()  
{
    int chk = DHT.read11(DHT11_PIN);
    tempC=DHT.temperature, 1;
    
    unsigned long now = millis();
    if (now - lastUpdate > millisecondsPerCount)
    {
        lastUpdate = now;
        Serial.println(tempC);
        
    }

    
    for(int i = 0; i < 2; i++)
    {
        led->displayNumber( tempC % 10, i);
        delay(2);
        tempC = tempC / 10;
    }
}

 


Connections ->

Paul__B

The obstacle is that you are not using code designed for the purpose.

You cannot use "for" loops to multiplex displays, you have to use a "state machine" to share the time devoted to your alternate digits.  That is to say, you have to arrange it so that on each pass of the loop, you determine whether it is time to swap digits, and if it is not, you pass on to other tasks in the loop.  This also means that you cannot use the "delay()" function in "real time" programs.

Now this is a general principle that you need to practice for any "real world" application, even if you do as I would next suggest, use a MAX7219 to drive your displays.  Irrespective of whether they are common-cathode or common-anode (which some people erroneously believe is not appropriate), the MAX7219 performs all the multiplexing for you, not requiring you to access it at any time other than when you want to alter the data displayed. :smiley-lol:

PaulRB

#2
Nov 18, 2015, 08:01 pm Last Edit: Nov 18, 2015, 08:10 pm by PaulRB
Hi, try this:
Code: [Select]

#include <LEDDisplay.h>
#include <dht.h>
dht DHT;
#define DHT11_PIN 11

LEDDisplay *led;  
int millisecondsPerCount;  
int counter;
int tempC;
unsigned long lastUpdate;

void setup()  
{
    Serial.begin(9600);
    millisecondsPerCount = 1000;
    int digitFlagPins[] = {8,9};
    int segmentPins[] = {0,1,2,3,4,5,6,7};
    int decimalPointPin = 7;
    led = new LEDDisplay(2, digitFlagPins, segmentPins, decimalPointPin);
}

void loop()  
{
    unsigned long now = millis();
    if (now - lastUpdate > millisecondsPerCount)
    {
        lastUpdate = now;
        int chk = DHT.read11(DHT11_PIN);
        tempC=DHT.temperature;
        Serial.println(tempC);
        
    }

    
    for(int i = 0; i < 2; i++)
    {
        led->displayNumber( tempC % 10, i);
        delay(2);
        tempC = tempC / 10;
    }
}



Paul

Go Up