7-Segment ht16k33

Happy Good Day :slight_smile:

I have a problem with 7-Segment ht16k33. With the same code. No problem when running on Adafruit 0.56 "4-Digit 7-Segment Display w / I2C Backpack.

Product: 0.56" 4-Digit 7-Segment Display w / I2C Backpack

But I have bought a 1.2-inch 4-Digit 7-Segment LED Display HT16K33 with Ebay. When uploaded same code. No display. I’m trying to change the code. But nothing happened. Test with Adafruit library has no problem.

Product: 1-2-inch-4-Digit-7-Segment-LED-Display-HT16K33-I2C-Clock-Temperature-Display/

Any Idea? :confused:

// Digital speedometer
//
/// VSS on car connects to pin 5
// CLK on display to Analog pin 5
// DAT on display to Analog pin 4

#include "Adafruit_GFX.h"    // Adafruit Core graphics library
#include "Adafruit_LEDBackpack.h" // Seven Segment display library
#include <SPI.h>
#include <Wire.h>

void setBrightness(uint16_t b, byte segment_address) {
  if (b > 16) b = 16; //Max brightness on this display is 16.
  if (b < 1) b = 1; // Brightness of 0 is too dim so make 1 the min.
  Wire.beginTransmission(segment_address);
  Wire.write(0xE0 | b); // write the brightness value to the hex address.
  Wire.endTransmission();  
}

const int hardwareCounterPin = 5;
const int samplePeriod = 1000; //in milliseconds
const float pulsesPerMile = 3100; // this is pulses per mile for Toyota. Other cars are different.
const float convertMph = pulsesPerMile/3600;
unsigned int count;
float mph;
int kph;
int roundedKph;
int previousKph;
int prevCount;


const int numReadings = 30;     // the number of readings for average brightness
int readings[numReadings];      // the readings array for the analog input
int index = 0;                  // the index of the current reading
int total = 0;                  // the running total
int average = 3; 


Adafruit_7segment matrix = Adafruit_7segment();
byte segment_address = 0x70; //This is hex address of the 7 segment display
boolean drawDots = true;

void setup(void) {
  Serial.begin(9600);
  
 // initialize all the brightness readings to 16: 
  for (int thisReading = 0; thisReading < numReadings; thisReading++)
    readings[thisReading] = 16; 
    
  // Start up the 7 segment display and set initial vaules  
  matrix.begin(segment_address);
  setBrightness(16, segment_address);
  matrix.println(0);
  matrix.writeDisplay();  
  
  TCCR1A = 0; //Configure hardware counter 
  TCNT1 = 0;  // Reset hardware counter to zero
}

void loop() {
     
  //SPEEDO-----------------------------------------------------------
  // This uses the hardware pulse counter on the Arduino.
  // Currently it collects samples for one second.
  bitSet(TCCR1B, CS12); // start counting pulses
  bitSet(TCCR1B, CS11); // Clock on rising edge
  delay(samplePeriod); // Allow pulse counter to collect for samplePeriod
  TCCR1B = 0; // stop counting
  count = TCNT1; // Store the hardware counter in a variable
  TCNT1 = 0;     // Reset hardware counter to zero
  mph = (count/convertMph)*10; // Convert pulse count into mph. 10x allows retaining 10th of mph resolution.
  kph = ((unsigned int) mph)*1.6; // Convert to kph and cast to integer. 

  int x = kph / 10;
  int y = kph % 10;

  // Round to whole mile per hour
  if(y >= 5){
    roundedKph = x + 1;
  }else{
    roundedKph = x;
  }

  //If kph is less than 1 kph just show 0kph.
  //Readings of 0.9kph or lower are some what erratic and can
  //occasionally be triggered by electrical noise.
  //if(x == 0){
  if(x < 2){  // 1 was triggered by some noise signal.
    roundedKph = 0;
  }

  // Don't display kph readings that are more than 50 kph higher than the previous reading because it is probably a spurious reading.
  if(roundedKph < 181){
    if((roundedKph - previousKph) > 50) {
      matrix.println(previousKph);
      }else{
      matrix.println(roundedKph);
      
    }
  }
 
  matrix.writeDisplay(); // Write the value to the 7 segment display. 
  
  previousKph = roundedKph; // Set previousMph for use in next loop.
    
}
  //-----------------------------------------------------------------

4_digit_kmh.ino (3.41 KB)

Test with Adafruit library has no problem.

What do you mean? What sketch did you use? What library does your sketch use, if any? (I can't download .ino files on my phone, please read the forum guidelines in the sticky post to find out how to post code correctly.)

Try the Arduino "i2c scanner" sketch. Do both displays report the same address?

Try connecting the "i2c hi" pin to the Vcc pin.

Thanks for reply PaulRB,

Q : What do you mean? What sketch did you use? What library does your sketch use, if any?
Adafruit_LED_Backpack

/*************************************************** 
  This is a library for our I2C LED Backpacks

  Designed specifically to work with the Adafruit LED 7-Segment backpacks 
  ----> http://www.adafruit.com/products/881
  ----> http://www.adafruit.com/products/880
  ----> http://www.adafruit.com/products/879
  ----> http://www.adafruit.com/products/878

  These displays use I2C to communicate, 2 pins are required to 
  interface. There are multiple selectable I2C addresses. For backpacks
  with 2 Address Select pins: 0x70, 0x71, 0x72 or 0x73. For backpacks
  with 3 Address Select pins: 0x70 thru 0x77

  Adafruit invests time and resources providing this open source code, 
  please support Adafruit and open-source hardware by purchasing 
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries.  
  BSD license, all text above must be included in any redistribution
 ****************************************************/

#include <Wire.h> // Enable this line if using Arduino Uno, Mega, etc.
#include <Adafruit_GFX.h>
#include "Adafruit_LEDBackpack.h"

Adafruit_7segment matrix = Adafruit_7segment();

void setup() {
#ifndef __AVR_ATtiny85__
  Serial.begin(9600);
  Serial.println("7 Segment Backpack Test");
#endif
  matrix.begin(0x70);
}

void loop() {
/* 
  // try to print a number thats too long
  matrix.print(10, DEC);
  matrix.writeDisplay();
  delay(500);
  


  // print a hex number
  matrix.print(0xBEEF, HEX);
  matrix.writeDisplay();
  delay(500);
 

 
  // print a floating point 
  matrix.print(12.34);
  matrix.writeDisplay();
  delay(500);
*/

  
  // print with print/println
  for (uint8_t counter = 0; counter > 20; counter++) {
    matrix.println(counter);
    matrix.writeDisplay();
    delay(10);
  }

  // method #2 - draw each digit
  uint8_t blinkcounter = 0;
  boolean drawDots = false;
  for (uint16_t counter = 0; counter < 9999; counter ++) {
    matrix.writeDigitNum(4, (counter / 1000), drawDots);
    matrix.writeDigitNum(3, (counter / 100) % 10, drawDots);
    matrix.drawColon(drawDots);
    matrix.writeDigitNum(2, (counter / 10) % 10, drawDots);
    matrix.writeDigitNum(1, counter % 10, drawDots);
   
    blinkcounter+=50;
    if (blinkcounter < 500) {
      drawDots = false;
    } else if (blinkcounter < 1000) {
      drawDots = true;
    } else {
      blinkcounter = 0;
    }
    matrix.writeDisplay();
    delay(10);
  }
}

Q :Try the Arduino “i2c scanner” sketch. Do both displays report the same address?


I check 0x70

Q : Try connecting the “i2c hi” pin to the Vcc pin.

A : Seller says : Fifth pin is I2C bus pull high which was already short to 5v that we confirmed earlier. All you need is 12v power supply and I2C two wire

Sorry, I have no more ideas.

I just stumbled across this old thread that wasn't really answered, so I thought I could add my 2cents. LED displays that are over one inch high use multiple led's in series, so they require more voltage than the smaller ones. Red displays will work OK on 5 volts, but greens take at least 6 and blues take 8 or more, and the ht16k33 chip has a maximum voltage rating of 5.5 volts. Means if the displays are green or blue there needs to be buffering circuitry to switch the higher voltage to the displays and a separate display minus or display plus wire.

The OP's link does not work any more, but it sounds to me, from post #2, like the OP was supplying 12V to the module. I would guess it contains a regulator to supply the ht chip with 5V or 3.3V, and the high voltage buffers you mentioned. But maybe my guess is also worth $0.02!

The module is a 5v module, I have it in my LED driver library.

Module description

I found this similar item. The red version 5V but the green version says it needs 9V. Perhaps the OP found a blue or white version which required 12V.

PaulRB: I found this similar item. The red version 5V but the green version says it needs 9V. Perhaps the OP found a blue or white version which required 12V.

The interface is probably the same, the driver on the green version is non-inverting.