Batman Dialer Part 2 - Hardware Testing
2024 September 12

Lets continue on with my batman dialer project. The entire goal here is to hide a secret control panel in some kind of statue. What that control panel does is completely up in the air. So here’s my current progress. I have gotten the analog rotary dialer working. I have also gotten sound working using the MAX98357A breakout board.

The Dialer

For getting the analog dialer to work I went with a simple 3 resister plan on my breadboard. I used the resisters since I was missing jumpers to connect the switch wires to my breadboard and they were the first handy thing I found to solder on.

An analog dialer works by connecting a switch so many times together. There’s up to 8 to 10 pulses per second with the dialer. However it seems that we need to debounce it. Mine also seems to return 4 pulses per digit. I’m betting the handset itself included something to cut down on the number of pulses and my dial is missing that part. I can’t find anything about why my dialer would have more pulses than usual but I’m going with the emperical measurements.

I hooked it up like a standard switch to my device. I had to use GPIO 15 because I used countio and some pwm magic to actually count the pulses.

CountIO allows me to count rising or falling edges.

import countio
import board

# Count rising edges only.
pin_counter = countio.Counter(board.GP15, edge=countio.Edge.FALL)
# Reset the count after 100 counts.
last_value = 0
time_last_number_added = time.monotonic_ns()
MAX_TIME_BETWEEN_DIGITS = int(1e9 * 4)
LAST_INCREMENT_THRESHOLD = int(1e9 * 0.25)
last_increment = 0

def dialer_check():
    global last_value, time_last_number_added, last_increment
    count = pin_counter.count

    # It has been incremented
    if count > last_value:
        last_increment = time.monotonic_ns()
        print("Count incr", count, "Last Increment: ", last_increment / 1e9, last_value)
    
    # Always update
    last_value = count

    
    # We will wait for up to half a second to see if the count is stable
    delta_t = time.monotonic_ns() - last_increment
    if delta_t > LAST_INCREMENT_THRESHOLD and count != 0:
        print("Count: ", count, delta_t / 1e9)
        pin_counter.reset()

        excess = count % 4
        actual_number = count // 4

        print("Conforming ", actual_number, " Excess: ", excess)

        return actual_number
    return None

I decided to have my dialer check return a number or nothing instead of being responsible for anything else.

Because I soldered on resisters to use as pins to the terminals I’ve been experiencing issues with actually getting a good secure read. I ordered some terminal blocks to replace the existing solution and plan on updating it with them.

Anyways enough about that. The extra parts I need should arrive next week from eBay.

Audio Setup

I’m using the MAX98357A amp to make sound. It communicates over the I2S protocol. I followed the tutorial here. I’m using the included synthio library to generate useful sounds. It’s nothing beyond basics at the moment, but I definitely find it very interesting how it actually works.

import audbusio
import synthio

# Create the output
audio = audiobusio.I2SOut(board.GP0, board.GP1, board.GP2)

# Create the synth instance
synth = synthio.Synthesizer(channel_count=1, sample_rate=22050)

# Play the audio output.
audio.play(synth)

I certainly find it weird that I can pick and choose when sounds are sent and they are played continiously. I find it useful that it’s nonblocking, but it would be nice to have non-blocking operations when making network requests. I haven’t quite figured that out yet.

Conclusion

In the video below you can see the current result of where I’m at.

The next step is working on building the actual statue itself.


Remember you can also subscribe using RSS at the top of the page!

Share this on → Mastodon Twitter LinkedIn Reddit

A selected list of related posts that you might enjoy:

*****
Written by Henry J Schmale on 2024 September 12
Hit Counter