Rotary dial pulse counting

Hmm .. Seems like the board has suggested like questions, but they appear locked.

So I've popped up a few times here, and you've all been helpful.

I'm not actually "doing" anything .. just learning the code, starting with the basics and trying to expand and implement instructions to "do" something simple with a test circuit.

I did get my 2x20 line VFD clock working after figuring out the serial comm had to be inverted with a transistor.

I know it's one-oh-one, and drifty with the delay statement as master time, but I like what I've written. Probably no use to any of you who aren't using the same Futaba display, but here it is anyway - the simplest clock I could write.

int s = 45; int m = 59; int h = 12; int x = 1;                 // time will start at 12:59:54 PM. X is AM/PM flag.  .
void setup() {
  pinMode(3, INPUT); pinMode(4, INPUT);                        // buttons on pin 3 and 4, normally high through 10K pull up.'
  Serial.begin(9600, SERIAL_8N1);                              // config serial TX pin 1.
}

void loop() {
 Serial.write(0x12);Serial.write("  Time ");                   // clear display and center time.
 if(h<10)Serial.write("0");                                    // correct 2 digits.
 Serial.print(h); Serial.write(":");                           // print hours then colon.
 if(m<10)Serial.write("0");                                    // correct 2 digits.
 Serial.print(m); Serial.write(":");                           // print minutes then colon.
 if(s<10)Serial.write("0");                                    // correct 2 digits.
 Serial.print(s);                                              // print seconds.
 if(x==0) Serial.write(" AM");if(x==1) Serial.write(" PM");    // solve AM/PM displayed.
 Serial.write("    HAVE A GREAT DAY");                         // print whatever, second line.
 (s++);                                                        // increment count time.
 if(s==60){s=0; m=m+1;}                                        // solve count, overflow, and handling.
 if(m==60){m=0; h=h+1;}
 if(h==13){ h=1; x=x+1; if(x==2)x=0;}                          // AM/PM overflow.
 if (digitalRead(3) == LOW && digitalRead(4) == HIGH) {(h++);} // buttons to set time.
 if (digitalRead(4) == LOW && digitalRead(3) == HIGH) {(m++);}
 if (digitalRead(4) == LOW && digitalRead(3) == LOW) {both();} // do something else if both pushed.
 delay (968);                                                  // master second delay.
}

void both(){Serial.write(0x12);Serial.write("Error");          // here if both buttons pushed.
  
}

Next month I'll be better still.

So the actual question ..

Note that electronics are not my weak hand, just learning the Arduino parlez by connecting to random things.

Today's bench play is interfacing an X/Y keypad .. I can figure that one out .. and an old rotary phone dial which has two pair of contacts. The pair of interest makes and breaks at 20 pulses per second proportional to the number dialed . ie, seven is seven pulses at 20Hz.

I'm drawing a blank how to actually count pulses though.

I'm pretty certain I could just use if/digitalRead and increment with something as "slow" as 20Hz .. but it seems somehow messy.

Not asking for anyone to do my homework that I can CTRL+C, just a nudge or thought as to where in the sandbox I need to dig.

As always, thanks.

Jimbo.

Actually the ONLY open at 20 pulses per second. Care to show us a schematic of your project?

1 Like

I have no schematic .. not even certain in what bin I have the dial, or did I remembered whether the pulse contacts were NO or NC. Probably ten years since I used the thing in some novel counting circuit, doing a Youtube vid over Kentucky bourbon. Either way .. that's for the breadboard side of things. Meh .. so consider the schematic a NC momentary switch/button between GND and pin 2 with a 10K pullup.

I seem to recall these things being exceptionally good at not bouncing .. Go Western Electric 1951! but I can also debounce if necessary.

My conundrum is counting with the code .. say a woodpecker is either opening or closing switch contacts at close to 20 Hz. How many times?

if (digitalRead(2) == HIGH) {(x++)}; 

Should probably work at such low frequency .. just wondering if there was a better way I'm not immediately seeing.

It's a bit more complicated than that. The pulses last a long time compared to the speed of the Arduino, so you need to count ONLY once after the pin is low.

Have a look at the "StateChangeDetection" example in the Arduino IDE.

That does what you are wanting to do.

It does need modifying to make it work with a 20Hz signal, you need to change the following:

// Delay a little bit to avoid bouncing
    delay(50);

Reduce that delay to 10ms.
50ms is a whole period of a 20Hz signal.

I moved your topic to an appropriate forum category @Micro-snob.

In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.

This is an important part of responsible forum usage, as explained in the "How to get the best out of this forum" guide. The guide contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

Recently I read it is 10 Hertz in France. What standard is your rotary dial? Or are you gettinhpg to 20 counting both edges?

When rotary was in, we'd impress people by dialing with the switch hook. The receiving circuits were reasonable tolerant of some speed variation.

But yeah, debounce and count, no different than counting button presses, but as @JohnLincoln points out, a shorter debounce constant will be necessary.

Kinda amazing to know how far they got with that kinda stuff. Buildings full of relays.

wokwi has a rotary diaper dialer part, see

a7

1 Like

Not for the casual user.

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