Go Down

Topic: 7 segment display flickering (Read 85 times) previous topic - next topic


Hi all, i'm new in forum. I have a problem with 7 segment display and arduino SevSeg library; infact i don't understand how to increase refresh rate of led to eliminate flashing.
Here my code.
Code: [Select]
#include "EmonLib.h"  // Include Emon Library
#include "SevSeg.h"

SevSeg sevseg;
EnergyMonitor emon1; 

void setup()

  byte numDigits = 2;   
  byte digitPins[] = {10, 11};
  byte segmentPins[] = {2, 3, 4, 5, 6, 7, 8, 9};

  sevseg.begin(COMMON_ANODE, numDigits, digitPins, segmentPins);
  emon1.current(5, 29);             // Current: input pin, calibration.

void loop()
  double Irms = emon1.calcIrms(1480);  // Calculate Irms only

  int Pot = ((Irms*235)+50)/100;
    sevseg.setNumber(Pot, 1);

  //Serial.print(Pot);         // Apparent power
  //Serial.print(" ");
  //Serial.println(Irms);          // Irms

P.s i'm using also emonLib to measure current with sct013 sensor; perhaps increase output speed from emonlib could be a solution, but i have no idea how to do it.
Someone could help me?

Thank you and sorry for my english


This floating point operation is going to be slow
Code: [Select]
double Irms = emon1.calcIrms(1480);  // Calculate Irms only
and then you convert it to an int.

Although it is probably not the whole problem, try eliminating the calcIrms call by putting in a dummy value and Irms and see if that speeds up your refresh. That will also tell you if the slowness is in the emon library.
Arduino Libraries http://arduinocode.codeplex.com
Parola for Arduino http://parola.codeplex.com
Arduino++ blog https://arduinoplusplus.wordpress.com


Jul 23, 2016, 06:27 am Last Edit: Jul 23, 2016, 06:32 am by OldSteve
The Irms calculation takes 244ms in this:-
(Not sure if that's really the problem though.)
Code: [Select]
#include "EmonLib.h"  // Include Emon Library

EnergyMonitor emon1;

void setup()
    emon1.current(5, 29);               // Current: input pin, calibration.
    unsigned long start = millis();
    double Irms = emon1.calcIrms(1480); // Calculate Irms only
    unsigned long end = millis();
    unsigned long elapsed = end - start;
    Serial.println(elapsed);            // Prints 244

void loop() {}

Perhaps looking at 'refreshDisplay()' in the "SevSeg.h" library might shed some light?
Please do not PM me for help. I am not a personal consultant.
And others will benefit as well if you post your question publicly on the forums.


The problem, I believe, is the parameter of 1480 that is passed to calcIrms(). This causes it to loop nearly 1500 times, reading an analog input and performing floating point calculations in each iteration. This prevents refresh() from smoothly multiplexing the display.

So try half that value, 740, or perhaps one quarter, 320 or one eighth 160 and see at what point the display stops flickering. This will make the reading less smooth and it may display some noise.

If that happens, you have two options. One is to modify the library code to allow for more frequent display updates while a 1480 sample average is taken. The other option is to use a chip to drive the display multiplexing so that the Arduino can concentrate on calculating the reading. Max7219 would be a good option.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131