-1

I'd like to display a sentence character by character on a single seven-segment display. What happens is that if my sentence is longer than 48 characters the central segment doesn't light up.

It works properly if I take out a letter from my string.

I have an Elegoo Uno R3, and am working on Windows, on the last version (2.0.3) of the Arduino IDE.

Is there a way to solve this issue?

Here's my code:

# include "SevSeg.h"

SevSeg  sevseg;
char    *str = "Per colpa di qualcuno non si fa credito a nessuno";
int     len = 50;



void setup(){
    byte numDigits = 1;
    byte digitPins[] = {};
    byte segmentPins[] = {6, 5, 2, 3, 4, 7, 8, 9};
    bool resistorsOnSegments = true;

    byte hardwareConfig = COMMON_CATHODE; 
    sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments);
    sevseg.setBrightness(90);
}

void loop(){
  int i = 0;

  while (i < len)
  {
    sevseg.setChars(&(str[i]));
    delay(1000);
    sevseg.refreshDisplay();
    ++i;
  }
}

Thanx in advance,

Fab

4
  • 1
    Why is digitPins an empty array? You have numDigits as 1, not zero.
    – Nick Gammon
    Feb 28, 2023 at 6:13
  • The tutorial states that it should be left empty for a single digit display. This is the tutorial: circuitbasics.com/arduino-7-segment-display-tutorial I'm gonna follow the official Arduino tutorial to see if the problem comes from the way I connected the wires to the pins: arduino-france.site/7-segments
    – Fab_x
    Mar 1, 2023 at 21:19
  • OK. It works properly if I take out a letter from my string. - what happens if you put a lot of spaces in the string? Is something possibly overheating?
    – Nick Gammon
    Mar 2, 2023 at 1:18
  • I didn't try honestly, I tried with an English sentence like "We are such stuff As dreams are made on, And our little life Is rounded with a sleep." and all worked fine. I started anew. Thanx a lot for your support
    – Fab_x
    Mar 5, 2023 at 20:12

1 Answer 1

-1

It looks like setChars is expecting a string, not a single character.

So I would be doing something like:

  while (int i = 0; i < len; i++)
  {
    char buf [2];
    buf [0] = str[i];
    buf [1] = 0;  // null terminator
    sevseg.setChars(buf);
    sevseg.refreshDisplay();
    delay(1000);
  }

See: https://github.com/DeanIsMe/SevSeg/blob/master/SevSeg.cpp

6
  • 1
    but a pointer to char is same as pointer to c-ctring. and the setChar function uses only numDigits chars from the input string. and numDigits is 1 in this case
    – Juraj
    Feb 27, 2023 at 10:25
  • @NickGammon Thanx for your help, but It didn't solve the problem, or at least both approaches print the same thing, as if the problem came from the location in memory where the string is stored.
    – Fab_x
    Feb 27, 2023 at 18:18
  • @juraj what's numDigits eactly? I found it in the setChars() function in the library but can't understand where it comes from
    – Fab_x
    Feb 27, 2023 at 18:19
  • it is the count of seven-segment modules. the count of digits.
    – Juraj
    Feb 27, 2023 at 18:56
  • @Juraj thanx, I get it now.
    – Fab_x
    Mar 1, 2023 at 9:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.