5 Digit 7-Segment Display Writing Error

I took your time, but the result came out like this. After the data is gone, it always comes back to the same result.

00000

11111


22222


12345


my fault, i forgot "B" before binary bytes. try now.

1 Like

After the data is gone, it returns to the same screen except 0. The number written on the screen does not remain on the screen. Single digit numbers are written as zero. Numbers with 2 digits and more are written with 1 digit missing. Numbers with 5 digits and more are written as 4 digits. The left side of the screen always remains as 0.Thanks for your help, I'm tired of you

0


00

1


12


123


1234


12345


123456

1234567


is this you original sketch or my?

this looks like your original sketch output.
it do again one additional Zero on the left too much, actually it do number"034567" and 7 will shove out

This is the result of the last program you corrected. Single digit numbers do not appear in the first program I created. The largest digit of 2 and above digit numbers is not visible. In 6 and more digit numbers, the number of the smallest 5 digits is written. I could not find where I missed the first number. The data 1234567 appears as 34567. Thank you for your efforts.

1234567

12345

#include <SPI.h>
#include <SoftwareSerial.h>


int exctDigit(byte input);

void dataWrite(int st);
int latchPin = 5;   // to pin 12
int clockPin = 6;  // to pin 11
int dataPin = 4;  // to pin 14
SoftwareSerial mySerial(7, 8); // RX, TX

boolean sayi[10][8] =
{
{0,1,1,1,1,1,1,1},
{0,1,1,0,0,0,0,1},
{1,0,1,1,0,1,1,1},
{1,1,1,1,0,0,1,1},
{1,1,1,0,1,0,0,1},
{1,1,0,1,1,0,1,1},
{1,1,0,1,1,1,1,1},
{0,1,1,1,0,0,0,1},
{1,1,1,1,1,1,1,1},
{1,1,1,1,1,0,1,1}
};
boolean dizi[] = {
  1, 0, 0, 0, 0, 0, 0, 1,
  1, 0, 0, 1, 0, 0, 1, 1,
  1, 0, 0, 1, 0, 0, 1, 1,
  1, 0, 0, 1, 0, 0, 1, 1,
  1, 0, 0, 1, 0, 0, 1, 1};  //sadece "1"lerden ve "0"lardan oluşan dizi
byte b1 = 0;        // byte place holders for each shift register
byte b2 = 0;        // extracted from "light"
byte b3 = 0;
byte b4 = 0;
byte b5 = 0;
int x = 0;
unsigned long sa = 2541;

int parseIntArray[5];


void setup() {
  Serial.begin(9600);
  mySerial.begin(9600);
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT);  
  pinMode(clockPin, OUTPUT);
  for (int i = 0 ; i < 5 ; i++)     
  {
    for(int k = 0;k <8;k++)
    {
      
       x =  sayi[0][k];                    //for dönügü boyunca dizinin i. değeri x'e atanır
    
    digitalWrite(dataPin, x);       //datapin'e x değeri verilir
    digitalWrite(clockPin, 1);      //saat darbesi ile yazma ve kaydırma işlemi yapılır
    digitalWrite(clockPin, 0);
    }
    
  }
  digitalWrite(latchPin, 1);        //8 bitli dizi çıkışa verilir


}

void loop() {
 byte buffer[8];
  // put your main code here, to run repeatedly:

  
   int numberOfData = mySerial.available() ;
   
    if(numberOfData>0)
      {
      unsigned long  k=0;
      
      for(int i=1;i<=numberOfData;i++)
      {
         unsigned long ust =1;
         for(int s =0;s<numberOfData-i;s++)
         {
          ust = ust * 10;
         }
         k +=(unsigned long) exctDigit (mySerial.read())*(unsigned long)ust;
          
      }
     
      dataWrite(k);
      buffer[0] =0;
      buffer[1] =0;
      buffer[2] =0;
      buffer[3] =0;
    

 }
}
void dataWrite(unsigned long st)
{
    digitalWrite(latchPin, 0);        //latchpin "0" konumuna getirilir
    
 parseIntArray[4]= (st%1000)/100;
 parseIntArray[3]= (st%10000)/1000;
 parseIntArray[2]= (st%100000)/10000;
 parseIntArray[1]= (st%1000000)/100000;
 parseIntArray[0]= (st%10000000)/1000000;

 
 for (int i = 0 ; i < 5 ; i++)     
  {
    for(int k = 0;k <8;k++)
    {
      
       x =  sayi[parseIntArray[i]][k];                    //for dönügü boyunca dizinin i. değeri x'e atanır
    
    digitalWrite(dataPin, x);       //datapin'e x değeri verilir
    digitalWrite(clockPin, 1);      //saat darbesi ile yazma ve kaydırma işlemi yapılır
    digitalWrite(clockPin, 0);
    }
    
  }
  digitalWrite(latchPin, 1);        //8 bitli dizi çıkışa verilir

}
int exctDigit(byte input)

{
  switch(input)
        {
                case '0':       return 0;
                case '1':       return 1;
                case '2':       return 2;
                case '3':       return 3;
                case '4':       return 4;
                case '5':       return 5;
                case '6':       return 6;
                case '7':       return 7;
                case '8':       return 8;
                case '9':       return 9;
                
        }
        return 0; 

}

What are your serial settings?

1 Like

Because when I tested it by printing the results out to the serial port, it was displaying the correct data.
I am suspecting your serial formatting is different.
i.e. you. don't have CR or Newline enabled.

1 Like

use this

#include <SoftwareSerial.h>
SoftwareSerial mySerial(7, 8); // RX, TX
//#define mySerial Serial
#define dataPin  4
#define latchPin 5
#define clockPin 6
unsigned long sa = 88888UL;

const uint8_t digit[] =
{
  //  uGFEDCBA  Segments      7-segment map:
  0b00111111, // 0   "0"          AAA
  0b00000110, // 1   "1"         F   B
  0b01011011, // 2   "2"         F   B
  0b01001111, // 3   "3"          GGG
  0b01100110, // 4   "4"         E   C
  0b01101101, // 5   "5"         E   C
  0b01111101, // 6   "6"          DDD
  0b00000111, // 7   "7"
  0b01111111, // 8   "8"
  0b01101111,  // 9   "9"
  0b00000000
};
void setup() {
  mySerial.begin(9600);
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  Display(sa);
  delay(1000);
  Display(0);
  mySerial.println();
}

void loop() {
  if (mySerial.available() > 0) // Do we have any data?
  {
    delay(10);
    sa = mySerial.parseInt();
    while (mySerial.available() > 0)mySerial.read();
    Display(sa);
    delay(1000);
  }
}

void Display(uint32_t num) {
  byte seq[5];
  num %= 100000UL; // number bigger as 99999 show only last 5 digits
    mySerial.println(num );
  for (byte i = 0 ; i < 5 ; i++)  { // reverse digit order
    seq[i] = num % 10;
    num /= 10;
  }
  if (!seq[4]) {
    seq[4] = 10;
    if (!seq[3]) {
      seq[3] = 10;
      if (!seq[2]) {
        seq[2] = 10;
        if (!seq[1])seq[1] = 10;
      }
    }
  }
  // Display the data in our array now.
  for (byte i = 0 ; i < 5 ; i++)
    shiftOut(dataPin, clockPin, MSBFIRST, digit[seq[i]] << 1);
  digitalWrite(latchPin, 0);
  digitalWrite(latchPin, 1);
}

1 Like

It worked. I had given up hope that it would work. I couldn't solve this alone. I hope one day I can reach your level. Thank you very much for your help. My main goal was to print data from Modbus. I have no knowledge about this. If I reach a certain level, I may disturb you.




1 Like

It was a pleasure to help you.

I do hope that your project continues to go well.

1 Like

I'll pay attention there from now on. Thank you very much for your help. I couldn't come to the right conclusion on my own. I hope one day I can reach your level.

We are all learning.

And with time and study I am sure you could easily surpass me.

1 Like

grafik

it has feedback same number despite how big, now it say back only what will appear on the display - only last 5 digits.

1 Like

Yes, it writes numbers of 5 or less digits. It writes the smallest 5 digits of numbers larger than 5 digits. I have not tried how it behaves with letters and other characters. Thank you

when not number, it shows zero, but show 5 digits when you send "11223abcdefkjsdfhskljdfhlasdjkfh"

Yes. It is as you said. In Letter + Number, it only shows the number. In Number + Letter + Number, it shows the first number group. Only in the letter, it is 0. Now I noticed that it also writes the screen output to the Bluetooth Terminal. Thanks for the simulation.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.