Skip to content

Code And Go! Olduino/Z is Styling Now!

March 13, 2016

Last week I had a go at automating the program load for the Olduino/Z to be like the 1802 Olduino.  I rewrote the python code today and it’s pretty serviceable.  The hardest thing was figuring out how to write a progress bar as the transfer happens.  My spouse actually figured out the algorithm for it.

In the video below, the editor window on the right is textpad with the helloworld.c program open. On the left is Br@y Terminal which is initially disconnected.  When I click the first button the compiler runs.  When I click the second button a dos window opens for the python bootloader.  It resets the Z80 then sends the compiled code over xmodem.  When that closes I click on the Terminal window, it connects, and we see the output.

The Python code looks worse than it is. There’s probably only 10 lines doing anything useful and the rest is just cruft of one sort or another.

from __future__ import print_function
import sys
import logging
logging.basicConfig()
import serial
try:
    from cStringIO import StringIO
except:
    from StringIO import StringIO
from xmodem import XMODEM, CRC
from time import sleep
import os
if len(sys.argv)>1:
    filename=sys.argv[1]
else:
    filename="a_code.bin"
fileSize=os.path.getsize(filename)
print ("File Size is",fileSize)
xpect=(fileSize/128)

def getc(size, timeout=1):
    return port.read(size)
xcount=0
xprog=0
def putc(data, timeout=1):
    global xcount,xprog
    port.write(data)
    if (len(data)==128): # if it's a block
    	xcount=xcount+1
    	newprog=(xcount*50)/xpect
    	for x in range(newprog-xprog):
            sys.stdout.write("#")
        sys.stdout.flush()
        xprog=newprog
    sleep(0.001) # give device time to send ACK

#Main program starts here - define the serial port, set RTS off, then open it

port = serial.Serial(parity=serial.PARITY_NONE,
                     bytesize=serial.EIGHTBITS,
                     stopbits=serial.STOPBITS_ONE,timeout=5,xonxoff=0,
                     rtscts=0,dsrdtr=0,baudrate=9600)
port.rts=False
port.port='COM3'
port.open()
port.rts=True
sleep(0.001)
port.rts=False
sleep(0.1)
port.read(1) #ditch the 1st char - always seems to be 0

#open the file to be loaded
stream = open(filename,'rb')

#transfer the file
result=XMODEM(getc, putc).send(stream, quiet = 1)

stream.close()
port.close()

if result:
    print ("\ntransfer successful")
    sleep(.25)
else:
    print ("\ntransfer unsuccessful")
    x=raw_input("press enter to continue...");
Advertisements

From → Olduino/Z

One Comment

Trackbacks & Pingbacks

  1. Olduino/Z Hardware Walkthrough | olduino

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: