bridystone / SevSegShift

Seven segment display controller library for Arduino
MIT License
31 stars 9 forks source link

Multiple String allocations causes corrupted display #12

Open mrclypto opened 6 months ago

mrclypto commented 6 months ago

Using an Arduino Nano Every, Common Anode 4 digit 7segment display '3461BS', and 8-bit shift register sn74hc595, I ran into issues while using the Strings class.

I have distilled it down to its most basic form. Below is my setup code, which was taken almost verbatim from the example.

If I comment out both String allocations, the display behaves as expected, and shows 1238. With just one String allocation, the display still behaves as expected. As soon as there are two String allocations in the loop, the display becomes corrupted. Only some segments turn on.

When removing the 8-bit shift register and hooking up the segments directly to the Arduino (and changing to the underlying SevSeg library), everything works as expected.

- SevSegShift sevsegshift(SHIFT_PIN_DS, SHIFT_PIN_SHCP, SHIFT_PIN_STCP, 1, true);
+ SevSeg sevsegshift;

Code:

#include <SevSegShift.h>

//Digit pins
#define DIG_ONE_PIN 14
#define DIG_TWO_PIN 15
#define DIG_THREE_PIN 16
#define DIG_FOUR_PIN 17

//Shift arduino pins
#define SHIFT_PIN_SHCP 10
#define SHIFT_PIN_STCP A4
#define SHIFT_PIN_DS A5

//Shift internal pins
#define SEG_A_PIN 0
#define SEG_B_PIN 1
#define SEG_C_PIN 2
#define SEG_D_PIN 3
#define SEG_E_PIN 4
#define SEG_F_PIN 5
#define SEG_G_PIN 6
#define SEG_DP_PIN 7

SevSegShift sevsegshift(SHIFT_PIN_DS, SHIFT_PIN_SHCP, SHIFT_PIN_STCP, 1, true);

unsigned long delayStartTime = 0;
const unsigned long delayDurationBrightness = 2000;

void sevSegShiftSetup() {
  const int sevSegBrightness = 5;
  byte numDigits = 4;
  byte digitPins[] = { DIG_ONE_PIN, DIG_TWO_PIN, DIG_THREE_PIN, DIG_FOUR_PIN };
  byte segmentPins[] = { SEG_A_PIN, SEG_B_PIN, SEG_C_PIN, SEG_D_PIN, SEG_E_PIN, SEG_F_PIN, SEG_G_PIN, SEG_DP_PIN };
  bool resistorsOnSegments = false;
  byte hardwareConfig = COMMON_ANODE;
  bool updateWithDelays = false;
  bool leadingZeros = false;
  bool disableDecPoint = false;

  sevsegshift.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments, updateWithDelays, leadingZeros, disableDecPoint);
  sevsegshift.setBrightness(sevSegBrightness);
}

void setup() {
  sevSegShiftSetup();
}

void loop() {
  sevsegshift.setNumber(1238);
  sevsegshift.refreshDisplay();
  String stringOne;
  String stringTwo;
}