Hello again, this is my third post here. It is regarding the GPS clock using 7 segment display. (code)
This is the diagram i am following which uses shift registers to drive the 7 seg's, through arudino. The four shift register are daisy chained as shown above. Time is extracted through Neo 6m module.
Old Forum
Problem:
This is the error i am receiving (flickering).
9v Power supply is used here and the display work fine without the gps code down here:
#include <SoftwareSerial.h>
#include <TinyGPS++.h>
const int SER_Pin = 2; // serial data input pin
const int SRCLK_Pin = 3; // shift register clock input pin
const int RCLK_Pin = 4; // storage register clock input pin
const int GPS_RX_Pin = 10; // GPS module RX pin
const int GPS_TX_Pin = 11; // GPS module TX pin
SoftwareSerial gpsSerial(GPS_RX_Pin, GPS_TX_Pin); // RX, TX pins of GPS module
TinyGPSPlus gps;
const int displayCount = 4; // number of 7-segment displays
const byte digitFont[] = { // seven segment display font for digits 0 to 9
B11111100, // 0
B01100000, // 1
B11011010, // 2
B11110010, // 3
B01100110, // 4
B10110110, // 5
B10111110, // 6
B11100000, // 7
B11111110, // 8
B11100110 // 9
};
byte displayData[displayCount] = { // data for each display
0, 0, 0, 0
};
void setup() {
pinMode(SER_Pin, OUTPUT);
pinMode(SRCLK_Pin, OUTPUT);
pinMode(RCLK_Pin, OUTPUT);
Serial.begin(9600);
gpsSerial.begin(9600);
}
void loop() {
while (gpsSerial.available() > 0) {
if (gps.encode(gpsSerial.read())) {
if (gps.time.isValid() && gps.date.isValid()) {
updateDisplay(gps.time.hour(), gps.time.minute());
}
}
}
}
void updateDisplay(int hours, int minutes) {
// update displayData array with new values
displayData[0] = digitFont[hours / 10];
displayData[1] = digitFont[hours % 10];
displayData[2] = digitFont[minutes / 10];
displayData[3] = digitFont[minutes % 10];
// update all displays with new data
for (int i = 0; i < displayCount; i++) {
digitalWrite(RCLK_Pin, LOW); // set storage register clock input low
shiftOut(SER_Pin, SRCLK_Pin, MSBFIRST, displayData[i]); // send data for this display
digitalWrite(RCLK_Pin, HIGH); // set storage register clock input high
delay(1); // delay to avoid ghosting
// enable this display and disable all others
for (int j = 0; j < displayCount; j++) {
digitalWrite(i, (i == j) ? LOW : HIGH); // enable/disable display
}
}
}
Before going any further, add a 100nF ceramic de-coupling capacitor on the power pins on each register.
Make sure you add current limiting resistors on each/all the segments.
i know, i created the topic for the software (code) specific problem
pert
May 9, 2023, 4:39pm
5
Hi @engineergang . It is OK to make separate forum topics for discrete aspects of a project.
However, there are some requirements for this to be done in a manner compliant with the rules of the forum and respectful of the people offering free help:
Avoid convergence
Even when the topics start out on discrete subjects, they have a tendency to converge to parallel discussion over time. Parallel discussions are harmful because they waste the time of the helpers who unknowingly duplicate the previous efforts from the other topic. For this reason, you must manage the scope of the discussion to prevent this from happening. If discussion starts to stray into the territory of the other topic, then redirect the participants over to the other to continue that discussion.
Cross-reference
The readers of one topic won't necessarily be aware of the content in the other. If information in one topic is relevant to the discussion in another, help your helpers by mentioning it there with a link.
2 Likes
Sure mod, will cross refrence and mention a link here as well.
1 Like
#include <SoftwareSerial.h>
#include <TinyGPS++.h>
const int SER_Pin = 2; // serial data input pin
const int SRCLK_Pin = 3; // shift register clock input pin
const int RCLK_Pin = 4; // storage register clock input pin
const int GPS_RX_Pin = 10; // GPS module RX pin
const int GPS_TX_Pin = 11; // GPS module TX pin
SoftwareSerial gpsSerial(GPS_RX_Pin, GPS_TX_Pin); // RX, TX pins of GPS module
TinyGPSPlus gps;
const int displayCount = 4; // number of 7-segment displays
const byte digitFont[] = { // seven segment display font for digits 0 to 9
B11111100, // 0
B01100000, // 1
B11011010, // 2
B11110010, // 3
B01100110, // 4
B10110110, // 5
B10111110, // 6
B11100000, // 7
B11111110, // 8
B11100110 // 9
};
byte displayData[displayCount] = { // data for each display
0, 0, 0, 0
};
void setup() {
pinMode(SER_Pin, OUTPUT);
pinMode(SRCLK_Pin, OUTPUT);
pinMode(RCLK_Pin, OUTPUT);
Serial.begin(9600);
gpsSerial.begin(9600);
}
void loop() {
while (gpsSerial.available() > 0) {
if (gps.encode(gpsSerial.read())) {
if (gps.time.isValid() && gps.date.isValid()) {
updateDisplay(gps.time.hour(), gps.time.minute());
}
}
}
}
void updateDisplay(int hours, int minutes) {
// update displayData array with new values
displayData[0] = digitFont[minutes % 10];
displayData[1] = digitFont[minutes / 10];
displayData[2] = digitFont[hours % 10];
displayData[3] = digitFont[hours / 10];
// update all displays with new data
for (int i = 0; i < displayCount; i++)
shiftOut(SER_Pin, SRCLK_Pin, MSBFIRST, displayData[i]); // send data for this display
digitalWrite(RCLK_Pin, HIGH); // set storage register clock input high
delay(1); // delay to avoid ghosting
digitalWrite(RCLK_Pin, LOW); // set storage register clock input low
}
gcjr
May 9, 2023, 11:17pm
9
engineergang:
for (int i = 0; i < displayCount; i++) {
digitalWrite(RCLK_Pin, LOW); // set storage register clock input low
shiftOut(SER_Pin, SRCLK_Pin, MSBFIRST, displayData[i]);
shouldn't 8 bits be sifted out for each of the 4 displays?
system
Closed
November 5, 2023, 11:17pm
10
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.