[TUT] [PC] Writing PC programs that control your AVR project

Go To Last Post
11 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Attached is an article I recently wrote which describes how to use a scripting language to create a PC program. For those that are unfamiliar with them, scripting languages are interpreted languages and are usually designed such that they can be quickly learned and can produce a working program with a minimum of effort. They have the added benefit that the generated program can run (often with no changes) across multiple platforms, such as Windows, MAC OS or Linux. Also, most of them are available for free.

I have been using scripting languages for a number of years, both at work and at home. My most recent AVR project was a Mega128 based control interface to a whole-house audio system. The hardware is directly controlled by a server, written in the Tcl/Tk scripting language, which runs on a Win2K based PC. A client program, also written in Tcl/Tk, communicates with this server through a socket interface and separate instances of it run on various other systems throughout the house. There is even a client that runs on a wireless PDA, allowing hand-held remote control capabilities.

In the article I try to introduce the user to the capabilities of scripting languages. A simple but complete example, including both AVR and PC sides is presented which anyone with an STK500 can actually try out. Hopefully the article will help others get started when they need to create a custom control program for their AVR project.

Dave

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It has been pointed out that it is rather difficult to copy the source files from the PDF, so I am attaching a zip file that includes the PC (tcl) and STK500 (asm) files.

Dave

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Which version of TCL/TK did you write the scripts in? It seems there might be some incompatibilities with the most recent releases from Active State.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

pwillard wrote:
Which version of TCL/TK did you write the scripts in? It seems there might be some incompatibilities with the most recent releases from Active State.

I'll check when I get home tonight. What sort of incompatabilities are you seeing?

Dave

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well, for example, the hello.tcl (initial example) will not function (throws errors) with the latest version of Active State's TCL. It seems they have made TCL a bit more strict.

That said, the AVRCONTROL.TCL script will not throw errors and bring up the gui just fine.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What platform are you running on? Windows or Linux or ?? I just checked Active State and it looks like the latest version for Windows is 8.4.13.0, which is what I have installed on my XP box here at work. I just tried the following:

tk_messageBox -message "Hello, World!" -type ok
exit

It worked as I would have expected. I also tried it without the "exit" line and it did the same thing (although you do have to kill the popup "wish" window manually by clicking on the "X" in the upper right hand corner).

You say that it throws errors. I just forced this by typing "-msg" instead of "-message" to verify that it puts up an error message. You should be seeing a popup that says something in the title like "Error in startup script" and then there is a dialog box with the error message. If you could post this error message it would help a lot in figuring out what is going on.

Dave

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

OMG! Microsoft Word Strikes again! QUOTATION MARKS!

I think I figured it out. I also use 8.4.13.0 and XP.

Stupid Me... I tried to save time by "cutting" your example into my editor versus typing it. Microsoft Word seems to have taken your example and converted the "" quotes to make them pretty... and completely foreign to a scripting language.

This is the first time I've had this happen. hopefully someone else can learn from this.

LOOK CAREFULLY AT QUOTES.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm afraid I'm going to have to share the "blame" with Microsoft on this one. I never looked carefully at the quotes that Word embedded into the document. If I had, I would have seen that the close quotes were of a different style than is used with simple text. Worse, I didn't include a copy of this "one-liner" in the ScriptSource.zip files since it was so simple! (How many times have I relearned that lesson).

Many thanks for your feedback - hopefully it will keep anyone else from tripping over the same problem.

Dave

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I much appreciate this article. I am very comfortable with script languages but I never had any exposure to TCL till now. Your article does a great job at introducing this powerful language and how it can be used with micro controllers.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Dave,

Great tutorial. I forgot how useful Tcl/Tk was. I worked at Digi International for a short time and used it to debug and test serial to ethernet converters. It's especially nice for writing test scripts used in regression testing.

Randy

edited to fix spelling.