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?