Sunday, December 26, 2010

Forth embedded board via USB serial

Terminals

My normal serial terminal program (ZTerm) doesn’t appear to allow manual control of DTR+RTS (as far as I can tell). I, however, need this control for a ByVac BV511 LPC ARM + Forth board http://www.byvac.com/bv3/index.php?route=product/product&path=20&product_id=49 which uses them to control the reset and program-enable lines. (I first saw the BV511 sold on ebay.co.uk by ByVac).

I tried to install minicom via MacPorts, but for some reason it wouldn’t set up (via sudo minicom -s)

Anyway, found CoolTerm, which allows things like manual RTS & DTR line control and also line delay.

http://freeware.the-meiers.org/ (There is both a Mac and Windows version).

Working with the BV511

CoolTerm was set up to 115200, 8N1.

I also set the end of line delay to a huge number (50) to allow the target to compile when pasting in text.

Copied some I/O code and got the on-board led to toggle that’s on I/O port 0.31 ... very cool (if somewhat simple!)

Saturday, November 27, 2010

Mice that run

We ran but didn't complete the maze...

Decimus 1 & 2

Maze solver competition

Wall follower board

Line follower than runs quick but misses lines

Line follower

Tuesday, October 19, 2010

Getting started with Python

Links
Official web site: http://python.org/
This tutorial is really cool: http://docs.python.org/tutorial
Reference: http://python.org/doc/

A dynamic language. Interpreted not compiled. Sort of C-like syntax, close enough that certainly I felt comfortable in it. Also used as a scripting language. Easy to learn.

Like C .... except the whitespace is significant in front of expressions: so no braces { } Don't mix tabs and spaces before statements because you'll get it wrong. Intent consistently and you'll be fine. It appears most people love the idea (everything is correctly formatted!). Then hate it when they start. Then love it once they've been doing it for a while.

Here is some Python 2.x code (they are currently working on Python 2.x and 3.x in parallel).


def hello():
print "hello"

hello()


Summary: Define a function. Print hello. Call the function. Notice the tab/spaces before print.

Other features:
  • Lists are sort of like C arrays, but more powerful. They use array-style syntax. These are the general purpose container of Python and get used all over the place to store stuff. Pretty efficient (e.g. faster to add characters to a list than a string). sid[3] = 5
  • There is a big library that does pretty much everything. Send emails, get web pages, regex, web servers, etc. etc.
  • Types are inferred rather than specified explicitly. 'Duck' typing. Strong typing.
  • It's an OO language. Naturally. But also supports imperative (procedural) and to a lesser extent functional programming.
  • Automatic memory management
  • There are dictionary which do map-style key-value look up. Used occasionally.
  • It's in the same class of languages (dynamic, interpreted, scripting) as Perl, Ruby, Tcl, PHP, etc.
  • In my opinion: Fast to program. As fast (or faster) than BASIC, and probably > 4x faster to program than C or C++ for the general case.
  • Interpreted = sometimes slow to run. But we have fast computers, so that doesn't matter.

Why?

We are using Python 2.x because that's what one of the interpreters that comes by default with Mac OS X, although for the work here you can use any operating system.

We are using to run a couple of things for our current weather program, which talks to hardware weather stations.

http://lightsoft.co.uk/LWC/

Specially, I'm writing a file converter - from other formats to LWC format.

(We've also got web page scrapers, called 'Decoders' written in Python. They need to be easy to change, hence Python.)


The Python Interpreter

On Mac OS X you'll have Python installed. On Windows you'll need to install it: http://python.org/download/
Some Linux and BSD distribution have it installed - otherwise that link will do it as well.

MacOSX Version = Python Version
10.3 = 2.3.0
10.4 = 2.3.5
10.5 = 2.5.1
10.6 = 2.6.1 (typing python2.5 gets you python2.5.4)

For MacOSX, if you go to Terminal (that's in Application/Utilities if it's not in your doc) and type 'python --version' then it will show you the Python version installed. You can do a similar thing in Windows from the Command Prompt.

I've installed Python 2.6.6 for reasons I can't remember. It's unlikely that this is critically important and probably relates to some unrelated work I was doing. Yeah, I think it was PyGame stuff.


The Editor and Execution environment - ECLIPSE

You can edit python files (.py) in anything - they are straight text files. For instance on Windows Visual Studio works (but it doesn't know how to chroma code it by default...) and on MacOSX Xcode knows how to chroma code Python files.

You can run the code in the Terminal by typing 'python file.py' or 'file.py' (depending on various things).

However, both of these, whilst functional, suck slightly in various ways.

So I've started editing with Eclipse. http://www.eclipse.org/

This started life as a Java development environment, but I've used it elsewhere for embedded C/C++ and I use it also for Python development.

Get it here: http://www.eclipse.org/downloads/

It doesn't really matter what version you download - I have the 'Eclipse IDE for C/C++ Developers' installed (for various reasons), so I'd suggest that one.

Once you boot up Eclipse, you'll need to create a workspace. Create this somewhere like your Document folder. A workspace is a place to work (duh!) that contains, usually, multiple related projects and the settings for the whole environment (for that particular workspace). The actual project may or may not be inside the workspace folder.


PyDev

There are a few ways of getting Python to work with Eclipse. I'm using http://pydev.org/

The basic instruction are, from within Eclipse... (see http://pydev.org/manual_101_install.html for screenshots of this process)

1. Go to the Help Menu
2. Go to 'Install New Software...'
3. Click Add next to 'Work with' .... add 'PyDev' and 'http://pydev.org/updates'
4. Follow the Instructions on that link above... (yeah, tired of typing :-D)


Create a Python Project

File -> New -> Pydev Project

Project name: test_project
you might need to configure a python interpreter...
Auto config should work...
If not ... New... Python2.5 then (on MacOSX) browse to /System/Library/Frameworks/Python.framework/Versions/2.x/Resources/Python.app/Contents/MacOS/Python and on Windows it will be in your Program Files folder.

Create '.py' file inside the project directory.

Type this into it....

def main():
print "Hello"

main()


Right click on the file Run As... Python Run.
It should show 'Hello' in the Console window down the bottom.

You should also be able to put Debug As... Python Run.
Might help if you set a break-point.

(If you go into debugger view, you can click the 'PyDev' button on the top-right to switch back to editor mode.)


Summary

Phew!

Hopefully at this point you'll have a working Python, Eclipse IDE and PyDev. You can create Python projects, run them and debug them.

Saturday, July 24, 2010

A story about IDE problems

So making changes to source files. Discover I need to set a Python file to UTF-8 from MacRoman. Look at nested settings ... workbench settings, project settings, file settings. Make some changes.

Try to edit a file an Eclipse hangs. Force quit and launch ... look at settings - all seem ok ... try to edit... Eclipse hangs. Launch eclipse ... try to save the settings ... waiting on something else....

The user operation is waiting for background work to complete
Saving workbench state.
Model provider updating pythonpath
Initializing Java Tooling
Configuring classpath containers

OK ... try searching for last two items in Google, with various combinations of additional phrases. No real info. Check Eclipse log files, etc. Nothing interesting. Tried a few things.

Ok, so this is not happening. Check the .project and .pydevproject with their baseline. Hmmm .... no major changes. Wish I'd booked my workbench into Subversion...

So ... create another workbench. Import Python project into that new workbench. First thing; No Python interpreters configured in that workbench. Ok, bit of a PITA navigating to the actual python binary - it's in a bundle a long way down ...

/System/Library/Frameworks/Python.framework/Versions/2.6/Resources/Python.app/Contents/MacOS/Python

Ok ... so do that for 2.5 as well.

But now colours in Python source files are all wrong! Hmmm... oh, why didn't I book it into Subversion.

Go for coffee and talk away from the computer for a minute. One coffee turns into two. Hang on... I HAVE got a backup ... duh! In Time machine!

Make a copy of the old workbench folder just in case....

Had to go back a few times in time machine before I got one that worked... Then had to add new debug configurations (I added 2.6 a few days ago).

And we are back to doing what I was meant to be doing...



P.S. I also notice the second release candidate of Eudora OSE, version 1.0rc2 has just been released. Haven't tried Eudora OSE at all yet. Might have to give it a go this weekend .... http://www.eudora.com/betas/
Newer›  ‹Older