Showing posts with label bl-328. Show all posts
Showing posts with label bl-328. Show all posts

Wednesday, July 10, 2013

BL-328 Computer: The keyboard

I was going to integrate this into the megapost for BL328, but there was enough here that I wanted to give it its own post.

For a while, I was thinking that I wanted to use a PS2 keyboard for my BL-328 computer.  This would have worked well; being just software serial to receive PS2 messages from the keyboard, and sending down RS232 keys, or just integrating it right into the main board of the device, using the above.  Space was getting tight on the main board, but I could have made it work.

One fateful trip up to Active Surplus up on Queen Street in Toronto, Canada changed that idea.  (NOTE: this is one of the reasons I love browsing there.  I wish they were closer!)


I found this.  It's a Commodore 16 keyboard.  I remember looking up Commodore 64 keyboards at one point, and they were a simple matrix.

Keyboard matrices work pretty simply. You have a grid of wires in the horizontal and vertical.  At each intersection, there's a switch (one key on the keyboard).  To "read" it, you send out a signal on each of the horizontal lines, then read in through each of the vertical lines. If you see the signal on the vertical line, you know that the intersection of that vertical with the horizontal that you sent out the signal on is where there's a key that's pressed down.



I made an interface for this using an old serial Arduino board, a Seeed Studio shield kit, and a bunch of wire. Above you can see the early version of this before I had everything figured out.  The above worked somewhat, but had to be directly plugged in to an Arduino.  I've since added a FTDI header for communications, as well as switching around one line to he header.  On the Arduino boards (and on this board) Digital 13 was broken out to an LED for display.  This interfered with the keyboard scanning, so I had to rewire it a bit.  The topmost red line was swapped down to be just below the bottommost line.  It made the code a little confusing, but it all worked out.

In a testing configuration, directly wired in to an Arduino Pro.  Notice that I'm using a Commodore 64 keyboard instead of the Commodore 16 keyboard purchased/shown earlier.

Detail showing that one rewired line on the controller board.  This is also after I mounted the Arduino, Shield and keyboard on a piece of lexan.  Rubber feet on the bottom, underneath the keyboard keep it nice and sturdy.  This also shows the three-wire serial at the top of the image, which connects it to the host computer.

Hooked up to a test display to get a feel for how it would work.
And as a part of the completed system.  CPU board is in the red project box, with a battery pack sticking out from it.  Keyboard and controller sit on the bottom of the image.  Between the two is the video display module, sitting on its plexiglass monitor stand. I also settled upon a color scheme for the keyboard as well.


Monday, March 4, 2013

Arduino EEProm Explorer

NOTE: there would be a screenshot right here, but there's really no point. It'd just be a terminal window showing something like this:
> 
Anyway... while working on the BL-238 uComputer, I wanted to add EEProm support to load and save programs. One of the things I needed was a way to probe into the EEProm to see if everything in there looked correct, or if things were going awry, a way to reformat it and so on.  In the process, I created this EEProm Explorer which is available on github.

It presents a shell interface over the serial connection, that has a few commands that can be typed in.  Perhaps some of you out there can use it to help snoop at the data for your own programs, or whatever.  I may be adding in functionality to this (along with in TinyBasicPlus) to load and save EEProm data directly to SD Cards as well, but that's in the future.

Commands are:

  • format - clear the EEProm - fill it with 0x00 (zeroes)
  • dump - display a fancy hexdump of the EEProm contents, hex values and ascii equivalents
  • print - display the contents as though they were a text file (ascii only)
  • record - capture user input until a "." starts a line.  Great for filling with textual content.
  • poke A D - poke the data value "D" into address "A".   Both values are decimal numbers.
  • ? - display the help message, along with RAM/EEProm sizes.

So, download this sketch to your Arduino, and connect via the serial monitor, and just type in the commands to use them.

Be aware that different micros have different amounts of EEProm storage.  The 168-based devices have 512 bytes, while the 328-based devices have 1024 bytes.  Arduino DUE (Arm CPU) devices have no EEProm (so far.)

Future versions of this may change the builtin commands, or add to them.  (Current version as of this post is v002.)

Hope y'all have use for this little tool!

Thursday, October 18, 2012

Building the BL-328 Computer: Part 1: Introduction and CPU


I recently decided to work on a physically small project. I decided to take the sort of ethics of the classic computer systems from the 1970s, which by design were considered what we now woud call "homebrew" and apply them to modern computing. I tried to keep things as stock and off-the-shelf as possible, so that this was easily reproducible by others.

To me, building a standard x86 PC from boards is not really in the same neighborhood of what I wanted to do here.  I want to do something with the feel of the Apple I for example.  Buying components, making wiring harnesses, writing firmware to control it, and having the primary user interface for it be a BASIC environment, much like the home computers of the 1970s and 1980s.

The name "BL-328" is taken in the same way that the TRS-80 got its name (Tandy/Radio Shack Z80 based computer.) For this, I went with "BL" signifying "BleuLlama", the nickname I use for IRC, and "328" signifying the ATMega 328 AVR microcontroller in the form of an Arduino.

I should note that Ben Heckendorn recently did a similar project, which you can watch his project on The Ben Heck Show.

To follow along with this first step, all you will need for the first step is an Arduino board, available from Adafruit, Sparkfun, Radio Shack, homemade, etc.   The one I'm using is one I bought a few years ago from Sparkfun, the Arduino Pro.


This one has the pin header on the right side there which connects to an FTDI cable to a host computer.  I will also be using this connector to power the entire system through the use of the FTDI-USB cable, AA Battery holder, or rechargable battery pack.

To start off, I took "TinyBasic" which had been ported for use on the Arduino by Michael Field, and I have since expanded upon(github project link).  I have added SD card support with loading and saving, data pin IO, as well as graphic functions specific to this project, but I'm getting ahead of myself.

Downloading that project's TinyBasicPlus.ino to the Arduino will give you a Basic interface with few hundred bytes of program space free.  You can use the "Serial Monitor" which is bundled with the Arduino IDE to interact with it.

The Arduino has 13 digital IO pins, some of which can be used for pseudo-analog output through the use of PWM,  as well as 6 analog Input pins, which can also be used for Digital IO.  A simple program to print out 10 results from Analog input 3, and turn on digital output 5 is as follows: (Note, that this assumes a new feature of TinyBasicPlus, "autoconfigure" is enabled)

10 REM example program
20 DWRITE 5, HIGH
30 FOR A = 0 TO 10
40 b = AREAD 3
50 PRINT B
60 NEXT A

You can write programs that will read port pins, write to port pins, and then load and save to an SD card, if you have FileIO enabled.  The SD interface I went with from this was the SeeedStudio SD Card Shield which was reasonably priced at Radio Shack.  It is hard-configured for its "select" to be on pin 10, which is shown in the TinyBasicPlus.ino file.  You will need to comment out the #undef for fileio and SD card support, and remove the comment for the related #define.  In its current state, it uses the SD library included with the Arduino package, this uses 9k bytes of program space, which is a lot.  I need to find a smaller SD library.

Now that this is enabled, the above program could be saved out to the SD card like so:
SAVE example1.bas

And then re-loaded later like so:
LOAD example1.bas

Recently, a feature was added to TinyBasicPlus that lets programs be autoloaded when you power on.  This is especially useful if you want to write your program (or programs) in BASIC on the device itself, rather than through the Arduino IDE in C.  This is accomplished by enabling the AUTORUN feature in TinyBasicPlus.ino, and by saving your startup program as "autorun.bas".

You can go a step further and have the end of your program "chain" to another program.  That is to say, you could have it load and run another program. eg:

the file "autorun.bas":
10 PRINT "Hello"
20 CHAIN "two.bas"

the file "two.bas":
10 PRINT "World!"
20 CHAIN "autorun.bas"

This will start up, run the "autorun.bas", which will then load the "two.bas" program, which will chain to the "autorun.bas" program, forever.

Enough with the software though.  I'll now get into a bit of the hardware, namely the power system.
As mentioned before, there are a few ways we can power the system.  Currently, since the only interaction you have with it is through the serial port/FTDI interface, you'll have it powered through that, but once we bring this thing into a standalone configuration, we'll want battery power.

The first power pack is a 4AA battery pack with a switch that I picked up from Adafruit. This has the power lines wired to a 6-pin interface like the FTDI interface has.  This lets me use standard AA batteries (rechargable or not) to power the device.

Next up is a USB-based rechargable battery I picked up at the local supermarket for $20.  It's a rechargable (Lithium Ion, perhaps?) battery with Mini USB input for charging, then standard USB for output.  I could use the FTDI cable off of this, but instead, I decided to make a tiny adapter so that I can plug it directly in through the same 6 pin interface:
I have no idea how long either of these will power the system for.  I'm guessing a substantial number of hours.  I've also since made a cable that connects between the battery pack and that header, rather than that little widget pictured above, which is essentially a USB cord whose power lines are wired directly to the FTDI connector.

Using the above, you can hook up an LED to digital pin 5, and do a version of the "Blink" program included with Arduino:

the file "autorun.bas":
10 REM Basic Blinker
20 DWRITE 5, HIGH
30 DELAY 500
40 DWRITE 5, LOW
50 DELAY 500
60 GOTO 30


Then, disconnect the FTDI cable, hook up the battery, and it should blink the LED forever.


That's it for this time.  Soon, we'll convert an old Commodore 64 keyboard into an input device for the computer, add LCD modules for output, and other goodies so that we'll be able to go standalone and not need a host computer at all!