How to catch 7 segment signal?

Hello !.

I need to read 7 segment signal of 9 digits then sent print to serial port
*7 segment , common Anode.

my circuit ****** I just test 1 digit only

  1. A-G legs of 7 segment connect to (-) of Opto , ( +) leg of Opto to +5V
  2. common Anode leg of 7 segment (Digit) connect to (+) of Opto ,( +) leg of Opto to Gnd
  3. Output of Opto connect to 6-12 (A-G) legs of Arduino and Pull-up with +5V
  4. Output of Opto (Common Cathod ) connect to D2 of Arduino.

This is my code but it don’t work.

#include <LiquidCrystal.h>
#include <EEPROM.h>
//#include <EEPROMAnything.h>

LiquidCrystal lcd(22, 24, 26, 28, 30, 32);
int buttonPins[] = {6,7,8,9,10,11,12} ;
int buttonStates[7];      
int i;
int A=0;
int B=0;
int C=0;
int D=0;
int E=0;
int F=0;
int G=0;
String total="";

void setup() {
  Serial.begin(9600);
for (i=0; i<7; i++)
{
   pinMode(buttonPins[i], INPUT);     
}
  pinMode(2,INPUT);  
  pinMode(3,INPUT);   
  pinMode(4, INPUT); 
  pinMode(5, INPUT); 
  lcd.begin(16, 2);


}

void loop() {
  val1 = digitalRead(2);  // read input value
  
if (val1 == LOW )
{     

  buttonStates[0] = digitalRead(buttonPins[0]);
  buttonStates[1] = digitalRead(buttonPins[1]);
  buttonStates[2] = digitalRead(buttonPins[2]);
  buttonStates[3] = digitalRead(buttonPins[3]);
  buttonStates[4] = digitalRead(buttonPins[4]);
  buttonStates[5] = digitalRead(buttonPins[5]);
  buttonStates[6] = digitalRead(buttonPins[6]);                           
  EEPROM.write(0,(buttonStates[6]));
  EEPROM.write(1,(buttonStates[5]));
  EEPROM.write(2,(buttonStates[4]));
  EEPROM.write(3,(buttonStates[3]));
  EEPROM.write(4,(buttonStates[2]));
  EEPROM.write(5,(buttonStates[1]));
  EEPROM.write(6,(buttonStates[0]));   
if (val1 == HIGH )
 {
     A= EEPROM.read(6);
     B= EEPROM.read(5);
     C= EEPROM.read(4);
     D= EEPROM.read(3);
     E= EEPROM.read(2);
     F= EEPROM.read(1);
     G= EEPROM.read(0);
     total=String(A)+String(B)+String(C)+String(D)+String(E)+String(F)+String(G);
     Serial.println(total);  
     lcd.print(total); 
     lcd.setCursor(0, 1);
 }

}

Picture

  • I tried to sent “9” to 7 segment but my program show as below.

What is the refresh rate on the display?

Are the optoisolators fast enough to catch the pulses?

I suspect that the digitalReads() might be too slow to catch all of the bits before they change. You might want to use Direct Register Access so you can grab all 8 pins at once.

You probably shouldn't use EEPROM cells for variables since they have a limited lifetime (100,000 writes?).

Your wiring will allow you to capture one digit at a time but gives you no indication of which digit you are getting. You should probably have a separate input pin for one of the digits so you can synchronize your (to be implemented) digit counter.

Thanks you johnwasser for advise to me. Now I can chatch signal 7 segment to display on my app (Visual basic)
but sometime my program wrong display as my photo, I think have noise in circuit .

This is my circuit ,Could you modify something for reduce noise ?

This is my app

Hello Matsuo!,

This issue is really interesting, I have the same problem when reading data from a 7 segments.
How did you fix it?
Could you share your code?

Thank you!!

Enrique