Skip to content

4 / 6 digit display #1

Description

@xygax

LCD/module name

PCF85134

Controller

Other

Module details

Using a PCF85134 i have the following code i wrote myself but would benefit from inclusion into a suitable library its currently used as a clock via an esp8266 the code is below for the display driver. its a bit "raw" but functional

Image

//----------------------------------------------------------------------------------------------------------------
//------------------------------------------Setup PCF 85134-------------------------------------------------------

void SetupPCF_Driver(byte _add){

byte _CMD = 0x80; // control the next byte is a command
byte _DTA = 0x40; // control the next byte is data
byte _LCMD = 0x00; // control the next byte is last command
byte _CFG1 = 0xC9; // configure as single static drive
byte _CFG2 = 0xF0; //
byte _CFG3 = 0xF8;

              Serial.print("\tWire Status: ");
//Wire.flush();
Wire.beginTransmission(_add);                   // I2C call the device
              Serial.print(Wire.status());                    // should return 0

    Wire.write(_CMD);
    Wire.write(_CFG1);
    Wire.write(_CMD);
    Wire.write(_CFG2);
    Wire.write(_LCMD);
    Wire.write(_CFG3);

Wire.endTransmission();
Serial.print(Wire.status());
LCD_connected = true;

Wire.beginTransmission(_add); // I2C
Wire.write(0x80); // command
Wire.write(0b11001101); // address (0) mode set
//Wire.write(0x80); // command
//Wire.write(0b11100000); // address (0) device select
Wire.write(0x80); // command
Wire.write(0b00000000); // address (0) data pointer
Wire.write(_DTA);
Wire.write(sevenSegCode(0x31));
Wire.write(sevenSegCode(0x32));
Wire.write(sevenSegCode(0x33));
Wire.write(sevenSegCode(0x34));
Wire.write(sevenSegCode(0x35));
Wire.write(sevenSegCode(0x36));
Wire.endTransmission();
Serial.print(Wire.status());

}

//----------------------------------------------------------------------------------------------------------------
void showIPByOctet(IPAddress ip, unsigned long waitMs ) {
char buf[5]; // 4 chars + null terminator

for (int i = 0; i < 4; i++) {
if (i < 3) {
snprintf(buf, sizeof(buf), "%03u-", ip[i]); // e.g. 192-
} else {
snprintf(buf, sizeof(buf), "%03u ", ip[i]); // e.g. 042
}
LCD_Segments(buf, segmentBuf);
segmentBuf[7] = 0xF0; // this is the loose leds top 4 bits
segmentBuf[8] = 0x00;
LCD_Output(segmentBuf); // and display
delay(waitMs);
}
}

void showIPScrolling(IPAddress ip, unsigned long waitMs) {
char ipStr[20]; // enough for "255-255-255-255 "
char window[5]; // 4 chars + null terminator

if (WiFi.localIP() == IPAddress(0,0,0,0)){
ip[0] = 192;
ip[1] = 168;
ip[2] = 004;
ip[3] = 001;

}

window[0] = '-';
if (WiFi.localIP() == IPAddress(0,0,0,0)){
window[1] = 'A';
} else{
  window[1] = 'I';
}
window[2] = 'P';
window[3] = '-';
window[4] = 0;
LCD_Segments(window, segmentBuf); 
segmentBuf[7] = 0xF0;                                   // this is the loose leds top 4 bits
segmentBuf[8] = 0x00;
LCD_Output(segmentBuf);                                 // and display
delay(1800);

// Build full IP string (zero-padded like your original)
snprintf(ipStr, sizeof(ipStr), "%03u-%03u-%03u-%03u ",
ip[0], ip[1], ip[2], ip[3]);

int len = strlen(ipStr);

// Repeat scroll 5 times
for (int repeat = 0; repeat < 3; repeat++) {

// Scroll across string
for (int pos = 0; pos < len; pos++) {

  // Build 4-character window
  for (int i = 0; i < 4; i++) {
    int idx = pos + i;

    if (idx < len) {
      window[i] = ipStr[idx];
    } else {
      window[i] = ' ';  // pad with spaces at end
    }
  }
  window[4] = '\0';

  // Display on LCD
  LCD_Segments(window, segmentBuf);
  segmentBuf[7] = 0xF0;
  segmentBuf[8] = 0x00;
  LCD_Output(segmentBuf);

  delay(waitMs);
}

}
}
//------------------------------------------set up the data for the LCD and send----------------------------------

uint8_t initBytes[32];

void LCD_Segments(const char *displayStr, uint8_t segmentByte[8]){

int i;                                            // counter
int digit;                                        // digit counter
int len;                                          // Input string length
uint8_t code;                                     // Seven segment code



for(i=0; i < 8; i++){                           // all good here 8 x 00
  segmentByte[i] = 0;                             // clear the output bytes
}

//Serial.print("\nD");
len = strlen(displayStr);                         // Length of input string

digit = 0;
for(i=0; i < len ; i++){                          // i is the digit counter
  
    if(displayStr[i] == '.')                      // Is this a period, and does this position have a period?
    { 
      if (state != CLOCK){
        segmentByte[digit-1] |= ( 1 << 0 );             // Set the period for the previous digit bit 7
      }

      
      if(state == CLOCK &&(Digits == 6||(Digits == 4 && digit == 2))){ 
        if (tm.tm_sec %2 != 0) {                        // flash the DP
        segmentByte[digit-1] |= ( 1 << 0 );             // Set the period for the previous digit bit 7 
        } 
      }                      
    }else{
    
      code = sevenSegCode(displayStr[i]);                      
      segmentByte[digit] |= code;                       // Set the segments to display this digit
      
      //Serial.print("   0x");
      //if (segmentByte[digit] < 16){Serial.print("0");}
      //Serial.print(segmentByte[digit],HEX);
      
      digit ++;
    }
}
return ;

}

void LCD_Output(uint8_t segmentByte[8]){
int j; // counter
//Serial.print("\tWire Status ");
Wire.flush();

  #ifdef  First
  Wire.beginTransmission(0x38);             // I2C

  #else
  Wire.beginTransmission(0x39);             // I2C

  #endif
  //Serial.print(Wire.status());
  
  Wire.write(0x80);           // command
  Wire.write(0b11001101);     // address (0) mode set
  //Wire.write(0x80);           // command
  //Wire.write(0b11100000);     // address (0) device select
  Wire.write(0x80);           // command
  Wire.write(0b00000000);     // address (0) data pointer
  //Wire.write(0x80);           // command
  //Wire.write(0b11111000);     // address (0) bank select
  //Wire.write(0x80);           // command
  //Wire.write(0b11110000);     // address (0) blink pointer
  Wire.write(0x40);           // data
  
  //Serial.print("\nI");
  for(j=0; j<8; j++){                       // j is the digit counter
    Wire.write(segmentByte[j]);
    delay(2);
  //Serial.print("   0x");
  //if (segmentByte[j] < 16){Serial.print("0");}
  //Serial.print(segmentByte[j],HEX);
        
  }
  Wire.endTransmission(); 
  //Serial.print("\tWire Status ");
  //Serial.print(Wire.status());

}

// sevenSegCode
//
// Given a hexadecimal digit, return the segment code that will
// display that digit on our LCD. Returns 0xff if digit is not valid.
//
uint8_t sevenSegCode(char c)
{
uint8_t code = 0;

switch(toupper(c))
{
    case ' ': code = 0x00; break;
    case '-': code = 0x40; break;
    case '0': code = 0x3F; break;
    case '1': code = 0x06; break;
    case '2': code = 0x5B; break;
    case '3': code = 0x4F; break;
    case '4': code = 0x66; break;
    case '5': code = 0x6D; break;
    case '6': code = 0x7D; break;
    case '7': code = 0x07; break;
    case '8': code = 0x7F; break;
    case '9': code = 0x6F; break;
    case 'A': code = 0x77; break;
    case 'B': code = 0x7C; break;
    case 'C': code = 0x39; break;
    case 'D': code = 0x5E; break;
    case 'E': code = 0x79; break;
    case 'F': code = 0x71; break;
    // "extended" chars
    case 'G': code = 0x6f; break;
    case 'H': code = 0x76; break;
    case 'I': code = 0x06; break;
    case 'J': code = 0x0e; break;
        //case 'K':
    case 'L': code = 0x38; break;
        //case 'M':
    case 'N': code = 0x54; break; // this one's a stretch
    case 'O': code = 0x3f; break;
    case 'P': code = 0x73; break;
        //case 'Q':
        //case 'R':
    case 'S': code = 0x6d; break;
    case 'T': code = 0x78; break; // eh? 
    case 'U': code = 0x3E; break;
        //case 'V':
        //case 'W':
        //case 'X':
    case 'Y': code = 0x6e; break;
        //case 'Z':

    default:
        code = 0xff; break;      // Invalid 
}

// if(code != 0xff) { // Was it a valid digit?
// code <<= 1; // Our segments are in upper 7 bits.
// }
// flip the byte
code = (code & 0xF0) >> 4 | (code & 0x0F) << 4;
code = (code & 0xCC) >> 2 | (code & 0x33) << 2;
code = (code & 0xAA) >> 1 | (code & 0x55) << 1;

return code;

}

Segment mapping progress

No response

Expected API

No response

Hardware access

I can test on real hardware

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions