Close

We Have Blinkenlights!

A project log for 2:5 Scale KENBAK-1 Personal Computer Reproduction

Make a working reproduction of the venerable KENBAK-1 with a fully integrated development environment including an Assembler and Debugger.

Michael GardiMichael Gardi 04/17/2021 at 17:183 Comments

With the wiring complete I wrote a small program in Python to test the lights, buttons, and switches on the front panel. To be clear this is NOT the KENBAK-2/5 emulator running a program (yet). 

As it turns out I did have to replace one of the LEDs which wasn't working.

The Python script communicates with the MCP23017 32 Channel I/O Expansion HAT through the Python wiringpi library. Here is the code for my test program. 

#!/usr/bin/python

import wiringpi as wiringpi
from time import sleep

# Set the base number of ic1.
ic1_pin_base = 65
# Pin number to code number:
# 1 = 65, 2 = 66, 3 = 67, 4 = 68, 5 = 69, 6 = 70, 7 = 71, 8 = 72, 9 = 73, 10 = 74, 11 = 75, 12 = 76, 13 = 77, 14 = 78, 15 = 79, 16 = 80

# Define the i2c address of ic1.
ic1_i2c_addr = 0x24

# Set the base number of ic2.
ic2_pin_base = 81
# Pin number to code number:
# 1 = 81, 2 = 82, 3 = 83, 4 = 84, 5 = 85, 6 = 86, 7 = 87, 8 = 88, 9 = 89, 10 = 90, 11 = 91, 12 = 92, 13 = 93, 14 = 94, 15 = 95, 16 = 96

# Define the i2c address of ic2.
ic2_i2c_addr = 0x20

# Initialize the wiringpi library.
wiringpi.wiringPiSetup()
# enable ic1 on the mcp23017 hat
wiringpi.mcp23017Setup(ic1_pin_base,ic1_i2c_addr)
# enable ic2 on the mcp23017 hat
wiringpi.mcp23017Setup(ic2_pin_base,ic2_i2c_addr)

# Setup led pins.
light_stop = 65
light_store = 66
light_set = 67
light_clear = 68

light_0 = 73
light_1 = 74
light_2 = 75
light_3 = 76
light_4 = 77
light_5 = 78
light_6 = 79
light_7 = 80

# Setup toggle pins.
toggle_off = 69
toggle_on = 70
toggle_unl = 71
toggle_lock = 72

# Setup button pins
button_stop = 81
button_start = 82
button_store = 83
button_read = 84
button_set = 85
button_display = 86
button_clear = 87 

button_0 = 89
button_1 = 90
button_2 = 91
button_3 = 92
button_4 = 93
button_5 = 94
button_6 = 95
button_7 = 96

# Set the pin mode to an output for all the leds.
wiringpi.pinMode(light_stop,1)
wiringpi.pinMode(light_store,1)
wiringpi.pinMode(light_set,1)
wiringpi.pinMode(light_clear,1)
wiringpi.pinMode(light_0,1)
wiringpi.pinMode(light_1,1)
wiringpi.pinMode(light_2,1)
wiringpi.pinMode(light_3,1)
wiringpi.pinMode(light_4,1)
wiringpi.pinMode(light_5,1)
wiringpi.pinMode(light_6,1)
wiringpi.pinMode(light_7,1)

# Set all the leds off to start with.
wiringpi.digitalWrite(light_stop,0)
wiringpi.digitalWrite(light_store,0)
wiringpi.digitalWrite(light_set,0)
wiringpi.digitalWrite(light_clear,0)
wiringpi.digitalWrite(light_0,0)
wiringpi.digitalWrite(light_1,0)
wiringpi.digitalWrite(light_2,0)
wiringpi.digitalWrite(light_3,0)
wiringpi.digitalWrite(light_4,0)
wiringpi.digitalWrite(light_5,0)
wiringpi.digitalWrite(light_6,0)
wiringpi.digitalWrite(light_7,0)


# Set the pin mode to an input for all the switches and buttons.
wiringpi.pinMode(toggle_off,0)
wiringpi.pinMode(toggle_on,0)
wiringpi.pinMode(toggle_lock,0)
wiringpi.pinMode(toggle_unl,0)

wiringpi.pinMode(button_stop,0)
wiringpi.pinMode(button_start,0)
wiringpi.pinMode(button_store,0)
wiringpi.pinMode(button_read,0)
wiringpi.pinMode(button_set,0)
wiringpi.pinMode(button_display,0)
wiringpi.pinMode(button_clear,0)
wiringpi.pinMode(button_0,0)
wiringpi.pinMode(button_1,0)
wiringpi.pinMode(button_2,0)
wiringpi.pinMode(button_3,0)
wiringpi.pinMode(button_4,0)
wiringpi.pinMode(button_5,0)
wiringpi.pinMode(button_6,0)
wiringpi.pinMode(button_7,0)

# Enable the internal pull-ups on all the inputs
wiringpi.pullUpDnControl(toggle_off,2)
wiringpi.pullUpDnControl(toggle_on,2)
wiringpi.pullUpDnControl(toggle_lock,2)
wiringpi.pullUpDnControl(toggle_unl,2)

wiringpi.pullUpDnControl(button_stop,2)
wiringpi.pullUpDnControl(button_start,2)
wiringpi.pullUpDnControl(button_store,2)
wiringpi.pullUpDnControl(button_read,2)
wiringpi.pullUpDnControl(button_set,2)
wiringpi.pullUpDnControl(button_display,2)
wiringpi.pullUpDnControl(button_clear,2)
wiringpi.pullUpDnControl(button_0,2)
wiringpi.pullUpDnControl(button_1,2)
wiringpi.pullUpDnControl(button_2,2)
wiringpi.pullUpDnControl(button_3,2)
wiringpi.pullUpDnControl(button_4,2)
wiringpi.pullUpDnControl(button_5,2)
wiringpi.pullUpDnControl(button_6,2)
wiringpi.pullUpDnControl(button_7,2)

# Test
step = 0
while True:
    # Check for button presses.
    if not wiringpi.digitalRead(button_0):
        wiringpi.digitalWrite(light_0,1)
    else:
        wiringpi.digitalWrite(light_0,0)
        
    if not wiringpi.digitalRead(button_1):
        wiringpi.digitalWrite(light_1,1)
    else:
        wiringpi.digitalWrite(light_1,0)
    
    if not wiringpi.digitalRead(button_2):
        wiringpi.digitalWrite(light_2,1)
    else:
        wiringpi.digitalWrite(light_2,0)
        
    if not wiringpi.digitalRead(button_3):
        wiringpi.digitalWrite(light_3,1)
    else:
        wiringpi.digitalWrite(light_3,0)
    
    if not wiringpi.digitalRead(button_4):
        wiringpi.digitalWrite(light_4,1)
    else:
        wiringpi.digitalWrite(light_4,0)   
    
    if not wiringpi.digitalRead(button_5):
        wiringpi.digitalWrite(light_5,1)
    else:
        wiringpi.digitalWrite(light_5,0)
        
    if not wiringpi.digitalRead(button_6):
        wiringpi.digitalWrite(light_6,1)
    else:
        wiringpi.digitalWrite(light_6,0)
    
    if not wiringpi.digitalRead(button_7):
        wiringpi.digitalWrite(light_7,1)
    else:
        wiringpi.digitalWrite(light_7,0)
        
    if not wiringpi.digitalRead(button_stop):
        wiringpi.digitalWrite(light_stop,1)
    else:
        wiringpi.digitalWrite(light_stop,0)
    
    if not wiringpi.digitalRead(button_start):
        wiringpi.digitalWrite(light_stop,1)
    else:
        wiringpi.digitalWrite(light_stop,0)
        
    if not wiringpi.digitalRead(button_store):
        wiringpi.digitalWrite(light_store,1)
    else:
        wiringpi.digitalWrite(light_store,0)
    
    if not wiringpi.digitalRead(button_read):
        wiringpi.digitalWrite(light_store,1)
    else:
        wiringpi.digitalWrite(light_store,0)
        
    if not wiringpi.digitalRead(button_set):
        wiringpi.digitalWrite(light_set,1)
    else:
        wiringpi.digitalWrite(light_set,0)
    
    if not wiringpi.digitalRead(button_display):
        wiringpi.digitalWrite(light_set,1)
    else:
        wiringpi.digitalWrite(light_set,0)
        
    if not wiringpi.digitalRead(button_clear):
        wiringpi.digitalWrite(light_clear,1)
    else:
        wiringpi.digitalWrite(light_clear,0)
        
    if not wiringpi.digitalRead(toggle_on):
        wiringpi.digitalWrite(light_clear,1)
    else:
        wiringpi.digitalWrite(light_clear,0)
    
    if not wiringpi.digitalRead(toggle_off):
        wiringpi.digitalWrite(light_set,1)
    else:
        wiringpi.digitalWrite(light_set,0)
        
    if not wiringpi.digitalRead(toggle_lock):
        wiringpi.digitalWrite(light_store,1)
    else:
        wiringpi.digitalWrite(light_store,0)
        
    if not wiringpi.digitalRead(toggle_unl):
        wiringpi.digitalWrite(light_stop,1)
    else:
        wiringpi.digitalWrite(light_stop,0)
        
    if step == 0:
        wiringpi.digitalWrite(light_7,0)
        wiringpi.digitalWrite(light_0,1)
    elif step == 1:
        wiringpi.digitalWrite(light_0,0)
        wiringpi.digitalWrite(light_1,1)
    elif step == 2:
        wiringpi.digitalWrite(light_1,0)
        wiringpi.digitalWrite(light_2,1)
    elif step == 3:
        wiringpi.digitalWrite(light_2,0)
        wiringpi.digitalWrite(light_3,1)
    elif step == 4:
        wiringpi.digitalWrite(light_3,0)
        wiringpi.digitalWrite(light_4,1)
    elif step == 5:
        wiringpi.digitalWrite(light_4,0)
        wiringpi.digitalWrite(light_5,1)
    elif step == 6:
        wiringpi.digitalWrite(light_5,0)
        wiringpi.digitalWrite(light_6,1)
    elif step == 7:
        wiringpi.digitalWrite(light_6,0)
        wiringpi.digitalWrite(light_7,1)
    step = (step + 1) % 8
        
    # Wait a bit.
    sleep(.2)

Sometimes I miss  the bad old days where new things seldom worked on the first try and you really had to slog for it, but as is more often than not the case these days everything worked as expected out of the gate (for the exception of the bad LED).

I'm running Eclipse with PyDev for development on my Windows machine using the Remote Systems feature of Eclipse to save the target .py scripts on the Raspberry Pi 4.  From there I simply run the programs on the Pi via SSH or VNC. 

Discussions

Cees Meijer wrote 04/18/2021 at 20:09 point

Nice ! But I think the Raspberry Pi4 may be a little overkill. I suppose Pi Zero would do just as well ?

  Are you sure? yes | no

Michael Gardi wrote 04/18/2021 at 20:19 point

It is overkill if all I was doing is KENBAK-1 emulation. But I’m also writing an Integrated Development Environment with Assembler and Debugger that will work in conjunction with the hardware, and that needs a Pi to run on. 

  Are you sure? yes | no

Cees Meijer wrote 04/18/2021 at 20:22 point

Ah, you are going to run it all on the Pi. Then it makes sense.

  Are you sure? yes | no