Setup the Gigatron loader with Arduino and Python

Using, learning, programming and modding the Gigatron and anything related.
Forum rules
Be nice. No drama.
Post Reply
WattSekunde
Posts: 24
Joined: 22 May 2018, 10:25

Setup the Gigatron loader with Arduino and Python

Post by WattSekunde »

After some long hours setting up my iMac (El Capitan), Python and an Ardunio Micro to communicate with the Gigatron i decided to write some of my experiences. Maybe I can help someone to getting this faster. :lol:

Gigatron:
========
1. Load the Gigatron tools from Github: https://github.com/kervinck/gigatron-rom
2. Place the folder gigatron-rom-master wherever you want.
3. Goto: gigatron-rom-master/Utils/LoaderTest/

Arduino:
========
1. Get the Arduino IDE from here: https://www.arduino.cc/en/Main/Software
2. Install the PS2Keyboard library from Menu: Sketch->Include Library->Manage Libraries...

Python:
========
1. Python 2.7 (already installed on OS X)
2. If you don't have it, get it from here: https://www.python.org
3. Install Python...
4. Open the Terminal in OS X and something similar on Windows or Linux ;)
5. Test if pyserial is installed: >python -m serial.tools.list_ports
6. If not then load and install the serial module pyserial.
(That was the hardest part for me, because there was no PIP on my OS X and easy_install doesn't work. :( After a long time ... I choose the manual installation and it was so easy... :roll: )
7. load pyserial from https://pypi.org/project/pyserial/#files
- For the next steps you have to be administrator at the machine or know the admin password!
8. unpack it somewhere with a double click (OS X) or >sudo tar -xzf pyserial-2.7.tar.gz
9. go into the folder: >cd pyserial-2.7
10. install: >sudo python setup.py install
11. test the installation: >python -m serial.tools.list_ports

I also have to comment out the Wait for prompt command in sendGt1.py. It doesn't get any prompt from the Gigatron on my system and wait forever?

Code: Select all

...
#-----------------------------------------------------------------------
#       Send program
#-----------------------------------------------------------------------

print 'Open file:', args.filename
if args.filename:
  try:
    fp = open(args.filename, 'rb')
  except Exception, e:
    print 'Failed: ' + str(e)
    exit(1)
else:
  fp = sys.stdin

#print 'Wait for prompt...', port
#sendCommand() # Wait for prompt

print 'Reseting Gigatron'
sendCommand('R')

print 'Starting Loader'
sendCommand('L')
...

Arduino Uno:
========
- Connect the Uno and the Gigatron DB9 connector with 4 wires
- Use this one for example: https://www.reichelt.de/?ARTICLE=127440
- Here you will find the exact wiring scheme: https://hackaday.io/project/20781-gigat ... typewriter

Arduino Micro:
========
- Connect the Micro and the Gigatron DB9 connector with 4 wires.
- Use this one for example: https://www.reichelt.de/?ARTICLE=177387
-- Gigatron DB9-Pin8 (GND) <- with -> Arduino Micro ICSP port pin 6
-- Gigatron DB9-Pin2 (SER_DATA) <- with -> Arduino Micro ICSP port pin 3
-- Gigatron DB9-Pin3 (SER_LATCH) <- with -> Arduino Micro ICSP port pin 1
-- Gigatron DB9-Pin4 (SER_PULSE) <- with -> Arduino Micro ICSP port pin 4

Code: Select all

--------------------+
              Reset |
Arduino       +---+ |
 Micro        | O | |
              +---+ |
                    |
              2 4 6 |
       ICSP-> o o o |
       Port  .o o o |
              1 3 5 |
--------------------+
- Edit the Arduino source file LoaderTest.ino to match the differences between Uno and Micro.
- Find and replace all
-- "PORTB5" with "SER_DATA"
-- "PORTB4" with "SER_LATCH"
-- "PORTB3" with "SER_PULSE"
- then add the source below the original Arduino Uno comment (line46):

Code: Select all

...
/*
 *  Link to Gigatron using its serial game controller port
 */

// Arduino AVR    Gigatron Schematic Controller PCB              Gigatron
// Uno     Name   OUT bit            CD4021     74HC595 (U39)    DB9
// ------- ------ -------- --------- ---------- ---------------- -------- --------
// Pin 13  PORTB5 None     SER_DATA  11 SER INP 14 SER           2
// Pin 12  PORTB4 7 vSync  SER_LATCH  0 PAR/SER None             3
// Pin 11  PORTB3 6 hSync  SER_PULSE 10 CLOCK   11 SRCLK 12 RCLK 4

//#define SER_DATA  PORTB5
//#define SER_LATCH PORTB4
//#define SER_PULSE PORTB3

// Arduino AVR    Gigatron Schematic Controller PCB              Gigatron SPI Pin
// Micro   Name   OUT bit            CD4021     74HC595 (U39)    DB9      Name
// ------- ------ -------- --------- ---------- ---------------- -------- -------
// SCLK    PORTB1 None     SER_DATA  11 SER INP 14 SER           2        (SCLK)
// MISO    PORTB3 7 vSync  SER_LATCH  0 PAR/SER None             3        (MISO)
// MOSI    PORTB2 6 hSync  SER_PULSE 10 CLOCK   11 SRCLK 12 RCLK 4        (MOSI)

#define SER_DATA  PORTB1
#define SER_LATCH PORTB3
#define SER_PULSE PORTB2

// Game controller button mapping. The kit's controller gives inverted signals.
...
========
Now you are ready to upload .gt1 files or send some commands via the Arduino IDE build in serial terminal. 115200 Baud & new line. Then type h for help...

If you use sendGt1.py turn of the Arduino IDE serial terminal before. It blocks the serial port!

Have fun with gt1... :lol:

Michael
Attachments
Arduino Micro.jpg
Arduino Micro.jpg (595.58 KiB) Viewed 2994 times
Last edited by WattSekunde on 04 Jun 2018, 07:25, edited 4 times in total.
User avatar
marcelk
Posts: 488
Joined: 13 May 2018, 08:26

Re: Setup the Gigatron loader with Arduino and Python

Post by marcelk »

Thanks for the write up! These help tremendously in making hacking accessible.

I just updated LoaderTest.ino so that fewer edits are required: just select the configuration in the top of the file. I hope I didn't mess up.

I'm somewhat puzzled why there is no prompt. Perhaps the Arduino Micro doesn't reset when establishing a serial connection, while my Arduino Uno always does that. I created an issue for it. Simplest solution is indeed to remove it, but it might cause a synchronisation problem when it is not understood. So I pushed an update that waits for at most 2 seconds for this, and then continues anyway. There was already a 2 second sleep in there which is now removed. Lets see how that works out.

[Edit: "LoaderTest" got renamed into "BabelFish"]
WattSekunde
Posts: 24
Joined: 22 May 2018, 10:25

Re: Setup the Gigatron loader with Arduino and Python

Post by WattSekunde »

Both solutions work stable. Thanks for the fast integration.

Yes, the Arduino Micro has a different USB behavior to the Uno because there is no dedicated USB controller.
Automatic (Software) Reset and Bootloader Initiation
Rather than requiring a physical press of the reset button before an upload, the Micro board is designed in a way that allows it to be reset by software running on a connected computer. The reset is triggered when the Micro's virtual (CDC) serial / COM port is opened at 1200 baud and then closed. When this happens, the processor will reset, breaking the USB connection to the computer (meaning that the virtual serial / COM port will disappear). After the processor resets, the bootloader starts, remaining active for about 8 seconds. The bootloader can also be initiated by pressing the reset button on the Micro. Note that when the board first powers up, it will jump straight to the user sketch, if present, rather than initiating the bootloader.
Source https://store.arduino.cc/arduino-micro#Documentation
Post Reply