TM1637 problems

I have not used a Xenon in a while, but wanted to knock up a simple stop watch and count down timer using a 4 digit TM1637 display. With a few Xenons around in my box, I thought I would breath a bit of life into one of them, but I can not get anything useful out of it.

The display has 4 connections, 5v, GND, CLK and DIO, with the latter two connected to D2 and D3.

I have two displays to test from. One gives garbled output, with seemingly random segments lit, and the other gives no output.

This is the code:

/* 
 * Project myProject
 * Author: Your Name
 * Date: 
 * For comprehensive documentation and examples, please visit:
 * https://docs.particle.io/firmware/best-practices/firmware-template/
 */

// Include Particle Device OS APIs
#include "Particle.h"
#include "TM1637Display.h"

// Do not connect to the cloud
SYSTEM_MODE(MANUAL);

SerialLogHandler logHandler(LOG_LEVEL_INFO);

// Hardware settings
int led = D7;
#define CLK D2
#define DIO D3

// The amount of time (in milliseconds) between tests
#define TEST_DELAY   2000

const uint8_t SEG_DONE[] = {
	SEG_B | SEG_C | SEG_D | SEG_E | SEG_G,           // d
	SEG_A | SEG_B | SEG_C | SEG_D | SEG_E | SEG_F,   // O
	SEG_C | SEG_E | SEG_G,                           // n
	SEG_A | SEG_D | SEG_E | SEG_F | SEG_G            // E
	};

TM1637Display display(CLK,DIO);

// setup() runs once, when the device is first turned on
void setup() {
  // Put initialization like pinMode and begin functions here
  pinMode(led, OUTPUT);
  display.setBrightness(0x0f);
}

// loop() runs over and over again, as quickly as it can execute.
int frate=1000;
int count=0;


void loop() {
  int k;
  uint8_t data[] = { 0xff, 0xff, 0xff, 0xff };
  uint8_t blank[] = { 0x00, 0x00, 0x00, 0x00 };
  display.setBrightness(0x0f);

  // All segments on
  display.setSegments(data);
  delay(TEST_DELAY);

  // Selectively set different digits
  data[0] = display.encodeDigit(0);
  data[1] = display.encodeDigit(1);
  data[2] = display.encodeDigit(2);
  data[3] = display.encodeDigit(3);
  display.setSegments(data);
  delay(TEST_DELAY);

  // Legacy bits left over from basic blink example
  display.showNumberDec(count);
  count++;
  digitalWrite(led, HIGH);
  //Log.info("Blink");
  delay(frate);
  digitalWrite(led, LOW);
  //Log.info("Blink");
  delay(frate);
}

I have done the usual things like swap the wires, swap the module, try different GPIO ports. I am getting nothing useful.

I tried the same code on an Arduino Nano, and both modules worked fine. Is there anything particular about the Xenon that would make it incompatible with one of these displays?

There is a possibility that this display will damage a Gen 3 or Gen 4 device! The device is powered by 5V (VUSB), but the library assumes pull-up resistors on CLK and DIO. There are two possibilities:

  • The display has pull-up resistors to 5V, which can damage your Particle device as Gen 3 devices are not 5V tolerant.
  • The display does not have pull-up resistors, in which case you have to add them externally to 3V3, but it should probably work if you add them, as long as the display accepts 3.3V as digital high. Without pull-up resistors the display will probably display random segments.

The TM1637 library was originally written for the Spark Core, and Gen 1 and Gen 2 devices are 5V tolerant, so the pull-up to 5V would work properly and not damage the device.

Thank you, that has done the trick, second option with pull up resistors. I tried at 3.3v but got no output.

So now the connections are powered via VUSB and for both DIO and CLK

5v-------10k resistor ----------- D2
                          |------ CLK