English Amiga Board


Go Back   English Amiga Board > Support > support.Hardware > Hardware mods

 
 
Thread Tools
Old 02 February 2014, 07:59   #1
modrobert
old bearded fool
 
modrobert's Avatar
 
Join Date: Jan 2010
Location: Bangkok
Age: 56
Posts: 735
Lightbulb Amiga in the lab...

I've recently completed coding an Arduino variant of Txtzyme for Teensy++ 2.0 which can be used via UART to Serial with the Amiga. Instead of relying on USB alone, this version can do both, simultaneously by queueing the commands from both USB and UART ports on the Teensy. There are some other changes as well allowing longer command strings etc. I call this version AmiZyme.

This is great when you want to read/write the TTL and PWM pins on the Teensy (Atmel microcontroller) via simple commands over serial from the Amiga, and you can have another computer hooked up the same time via USB if needed, sharing the same Teensy device.

For example, to blink a LED you can issue this command in Txtzyme syntax.

Code:
5{ 6d 1o 100m 0o 100m }
This command blinks the Teensy LED (on pin D6) 5 times in 1 second ('m' = milliseconds, 'u' = microseconds) .


Here's the command list which can be triggered with 'h' when hooked with your Amiga terminal program, like NComm V3.06 (keyfile).

Code:
AmiZyme commands:
-------------------
0-9<num>    enter number
<num>p        print number via uart
<num>P        print number via usb
<pin*>i        digital read input
<pin*><num>o    digital write output
<num>m        msec delay
<num>u        usec delay
<num>{}        repeat
k<num>        loop count
_<words>_    print words via uart
-<words>-    print words via usb
<pin*>s        analog read input (0-1023)
<pin*><num>w    analog write output (0-1023)
v        print version via uart
V        print version via usb
h        print help via uart
H        print help via usb
(* Arduino pin reference is used followed by a 'd', eg. '6d' for the LED.
For more examples of usage, check Ward Cunningham's project page on Github:

https://github.com/WardCunningham/Txtzyme


Here's the AmiZyme source code for Arduino.

Code:
// AmiZyme v1.2 by modrobert 2014
// Based on Txtzyme by Ward Cunningham
//
// Changelog:
// 1.2 
// * Added [w] digitalWrite command.
// * Updated [h]elp info.
// 1.1 
// * Rewrote UART and USB handling to allow simultaneous input,
//   commands are queued.
// * Changed project name from AmigaZyme to AmiZyme.
// 1.0
// * Initial release.

const int BUFSIZE = 1024;
unsigned int x = 0;
int d = 13;

// This line defines a "Uart" object to access the serial port
HardwareSerial Uart = HardwareSerial();

void setup() {
  // USB serial, baudrate below is meaningless, 12mbit.
  Serial.begin(9600);
  // Teensy++ 2.0 pin 2 RX, Pin 3 TX.
  Uart.begin(38400);
}

void loop() {
  char buf[BUFSIZE];
  while (1) {
    if (Uart.available() > 0) {
      txtUartRead(buf, BUFSIZE);
      break;
    }
    if (Serial.available() > 0) {
      txtSerialRead(buf, BUFSIZE);
      break;
    }
  }
  txtEval(buf);
}

void txtUartRead (char *p, unsigned int n) {
  unsigned int i = 0;
  while (i < (n-1)) {
    while (!Uart.available());
    char ch = Uart.read();
    if (ch == '\r' || ch == '\n') break;
    if (ch >= ' ' && ch <= '~') {
      *p++ = ch;
      i++;
    }
  }
  *p = 0;
  Uart.print("\r\n");
}

void txtSerialRead (char *p, unsigned int n) {
  unsigned int i = 0;
  while (i < (n-1)) {
    while (!Serial.available());
    char ch = Serial.read();
    if (ch == '\r' || ch == '\n') break;
    if (ch >= ' ' && ch <= '~') {
      *p++ = ch;
      i++;
    }
  }
  *p = 0;
  Serial.print("\r\n");
}

void txtEval (char *buf) {
  unsigned int k = 0; 
  char *loop;
  char ch;
  while ((ch = *buf++)) {
    switch (ch) {
    case '0':
    case '1':
    case '2':
    case '3':
    case '4':
    case '5':
    case '6':
    case '7':
    case '8':
    case '9':
      x = ch - '0';
      while (*buf >= '0' && *buf <= '9') {
        x = x*10 + (*buf++ - '0');
      }
      break;
    case 'p':
      Uart.println(x);
      break;
    case 'P':
      Serial.println(x);
      break;
    case 'd':
      d = x;
      break;
    case 'i':
      x = digitalRead(d);
      break;
    case 'o':
      digitalWrite(d, x%2);
      break;
    case 'm':
      delay(x);
      break;
    case 'u':
      delayMicroseconds(x);
      break;
    case '{':
      k = x;
      loop = buf;
      while ((ch = *buf++) && ch != '}') {
      }
    case '}':
      if (k) {
        k--;
        buf = loop;
      }
      break;
    case 'k':
      x = k;
      break;
    case '_':
      while ((ch = *buf++) && ch != '_') {
        Uart.print(ch);
      }
      Uart.println();
      break;
    case '-':
      while ((ch = *buf++) && ch != '-') {
        Serial.print(ch);
      }
      Serial.println();
      break;
    case 's':
      x = analogRead(x);
      break;
    case 'w':
    // Analog write takes 0-255, analog read 0-1023, hence the division below.
      analogWrite(d, x/4);
      break;
    case 'h':
      Uart.print("AmiZyme commands:\r\n-------------------\r\n0-9<num>\tenter number\r\n<num>p\t\tprint number via uart\r\n<num>P\t\tprint number via usb\r\n<pin*>i\t\tdigital read input\r\n<pin*><num>o\tdigital write output\r\n<num>m\t\tmsec delay\r\n<num>u\t\tusec delay\r\n<num>{}\t\trepeat\r\nk<num>\t\tloop count\r\n_<words>_\tprint words via uart\r\n-<words>-\tprint words via usb\r\n<pin*>s\t\tanalog read input (0-1023)\r\n<pin*><num>w\tanalog write output (0-1023)\r\nv\t\tprint version via uart\r\nV\t\tprint version via usb\r\nh\t\tprint help via uart\r\nH\t\tprint help via usb\r\n(* Arduino pin reference is used followed by a 'd', eg. '6d' for the LED.\r\n");
      break;
    case 'H':
      Serial.print("AmiZyme commands:\r\n-------------------\r\n0-9<num>\tenter number\r\n<num>p\t\tprint number via uart\r\n<num>P\t\tprint number via usb\r\n<pin*>i\t\tdigital read input\r\n<pin*><num>o\tdigital write output\r\n<num>m\t\tmsec delay\r\n<num>u\t\tusec delay\r\n<num>{}\t\trepeat\r\nk<num>\t\tloop count\r\n_<words>_\tprint words via uart\r\n-<words>-\tprint words via usb\r\n<pin*>s\t\tanalog read input (0-1023)\r\n<pin*><num>w\tanalog write output (0-1023)\r\nv\t\tprint version via uart\r\nV\t\tprint version via usb\r\nh\t\tprint help via uart\r\nH\t\tprint help via usb\r\n(* Arduino pin reference is used followed by a 'd', eg. '6d' for the LED.\r\n");
      break;
    case 'v':
      Uart.println("AmiZyme v1.2 for Teensy++ 2.0 by modrobert in 2014.");
      Uart.println("Created with classic computers like the Amiga in mind.");
      Uart.println("A variant of Txtzyme with support for both UART and USB serial.");
      break;
    case 'V':
      Serial.println("AmiZyme v1.2 for Teensy++ 2.0 by modrobert in 2014.");
      Serial.println("Created with classic computers like the Amiga in mind.");
      Serial.println("A variant of Txtzyme with support for both UART and USB serial.");
      break;
    }
  }
}
To interface the A1200 with the UART port on the Teensy++ 2.0 I use a custom made MAX3232 circuit on a perfboard, but you can buy pre-built "RS-232 to TTL (UART)" serial devices really cheap, eg. ebay or dealextreme. You might need a gender changer for the Amiga serial port as well depending on the serial cable used.


Thanks to the wonders of AREXX in AmigaOS (WB3.1) I've also made a REXX script using NComm to send the commands directly from the Amiga shell using 'rx amizyme.rexx <"command">', or for use by other programs/scripts, here it is:

Code:
/* amizyme arexx script! */

options results /* Turn on result codes */

address 'ncomm' /* Our port name */

inactivity 2 /* Even if we didn't receive a linefeed, we will get a copy
                of the last (current) line after 2 seconds of inactivity.
                If you only want to receive a line when a linefeed is
                received, set inactivity to 0 */

l="rmh.library";if ~show("L",l) then;if ~addlib(l,0,-30) then exit

if ~RMHReadArgs("CMD/A,SAY/S") then do
    call PrintFault()
    exit
end                

cmd = parm.0.value"\n"

if RC == 20 then exit /* Exit if user selected quit NComm */

clearbuffer

send cmd

do forever /* for (;;) */
   address 'ncomm' wait /* Wait for anything, return current line */
   if RC == 20 then exit /* Exit if user selected Quit NComm */
   if parm.1.flag then say result           /* Write line to CLI window */
   else leave
end

First I was thinking about posting a thread specifically about AmiZyme here at EAB, but since I'm curious about other users here using Amiga in their lab (actually my hardware "lab" is more of a small shack with a soldering iron, but it sounds nicer calling it a "lab"). Amiga is great with its serial and parallel port for these types of projects.

Please share your projects here, if you use the Amiga as a tool in your hardware (electronics) projects, and how you do it. Even if software related, for example, if you wrote or ported software for Amiga to interface with certain hardware devices.

Last edited by modrobert; 02 February 2014 at 09:00. Reason: Spelling/grammar and stuff.
modrobert is offline  
Old 05 February 2014, 16:45   #2
Tiago
Registered User
 
Join Date: Oct 2011
Location: Estoril/Portugal
Age: 46
Posts: 115
I have an Arduino Uno and 2 Nano. I have done some small projects with them.
but i dont know what is this Txtzyme, can you explain a bit what it is?
You connect an Arduino with a db25 port or something like that?

That would be great to join both Miggy and Arduino!
Tiago is offline  
Old 06 February 2014, 05:13   #3
modrobert
old bearded fool
 
modrobert's Avatar
 
Join Date: Jan 2010
Location: Bangkok
Age: 56
Posts: 735
Txtzyme is mainly an interpreter to control the TTL pins on an AVR device, so instead of writing code and flashing it to the device each time you have a small project (eg. read input of a pin and then set another pin high, or just send a series of states to one pin), with Txtzyme you can just send commands over the serial port instead, either from a terminal program, or from software you coded on the computer.

In general it makes "trial and error" testing a lot faster, just edit the command a bit, and send again.

Here are some syntax examples of usage from Ward Cunningham's project page.

Quote:
Commands are read line at a time from a flow-controlled USB stream into a sixty character buffer from which they are interpreted. Unrecognized commands do nothing, improperly used commands will try to do someing predictable if not useful.
  • 0-9 replaces x with the 16-bit unsigned integer formed from this and subsequent digits.
  • p prints the x register, followed by crlf.
Input from the host is normally embedded in programs as literal digits that are simply regerated when inputs change. Output goes back to the host over the USB where it may or may not be read. There is some buffering but unread output will eventually be discarded.
  • a-f selects i/o port a-f, and pin x, for subsequent i/o.
  • i reads the selected pin, leave it as 0-1 in x.
  • o write the selected pin from x mod 2.
Input from pins and output to pins automatically set the data direction for the individual pin. The impedance of the input state is influenced by the last output data (0o for highest impedance). The LED pin (D6) is selected on reset and by convention at the end of scripts.
  • m delays x milliseconds.
  • u delays x microseconds.
A delay precise delay of, say 14.666 milliseconds can be written as the program 14m666u. The command interpreter overhead is about 2.5 microseconds per character.
  • { starts a loop to be executed x times.
  • } ends a loop that will be executed zero or more times.
  • k sets x to the remaining loop count, decremented as each loop starts.
Loops can't (yet) be nested, nor can loops span lines. The x that controls the loop need not be literal. For example, 3bi{ ... } describes a loop that will be executed only when pin B3 is high.

The program 11{kp1000m} counts down by seconds from 10 to 0. The program 8{kbip} prints each bit of input port B, from B7 to B0.
  • _ outputs characters to the USB host, up to the next _ character or end of line.
The underscore was chosen over single or double quotes for the simple reason that they need not be escaped in command line arguments. A crlf follows the quoted output.
  • s samples analog input from mux channel x, replacing x with the sampled data.
Input is referenced to vcc and ranges from 0 to 1023. Teensy mux channels correspond to pins in the order they appear on the edge of the board: F0, F1, F4, F5, F6, F7, B6, B5, B4, D7, D6, D4. Any operation of the LED is likely to interfere with using D6 as an analog input.
  • v outputs the MCU version, as set by, for example, MCU = atmega32u4 in the Makefile.
Each Teensy uses a different MCU as follows: at90usb162: Teensy 1.0, atmega32u4: Teensy 2.0, at90usb646: Teensy++ 1.0, at90usb1286: Teensy++ 2.0.
  • h outputs a summary of available commands.
Each command is listed with a signature indicating pre and post conditions and followed with a word or two of description. Command signatures and descriptions will not be change unless the commands themselves change so that drivers can sense remote capability by parsing this output.
Note that my AmiZyme version uses the Arduino pin assignments for the device, not the same as when programming C (eg. avr-gcc), so instead of B0 or F7, all pins have the 'd' abbrevation (and it goes higher than 7).

Also, the command buffer is 1024 Bytes instead of 60 as Txtzyme. I did that mainly because the command buffer also serves as a queue in AmiZyme, from both USB and UART serial ports.

Last edited by modrobert; 06 February 2014 at 06:04. Reason: Added bullet points for the examples.
modrobert is offline  
Old 10 February 2014, 11:38   #4
bubbob42
Registered User
 
Join Date: Oct 2012
Location: Germany
Posts: 585
I connected an Arduino to my Amiga 4000D via the "mystery header" a while ago. The Arduino reads a few temperature sensors inside the case and transfers the data to the Amiga (It can only send, not receive).

You can find pictures and description here: http://www.a1k.org/forum/showthread....t=mysteryduino

It's in german, but google translate does a fairly good job. I'll come up with a better translation, if someone's interested.
bubbob42 is offline  
Old 10 February 2014, 12:59   #5
Tiago
Registered User
 
Join Date: Oct 2011
Location: Estoril/Portugal
Age: 46
Posts: 115
Hi,
what is the:
"A4000D (and only on the non-cr version). "

CR is cost reduction ? I have an 4000D Rev B

Only works with A4000 non-cost reduction?
Tiago is offline  
Old 10 February 2014, 13:39   #6
hooverphonique
ex. demoscener "Bigmama"
 
Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 1,526
Quote:
Originally Posted by Tiago View Post
CR is cost reduction ?
Yes

Quote:
Originally Posted by Tiago View Post
Only works with A4000 non-cost reduction?
The CR doesn't have the "mystery header".
hooverphonique is offline  
Old 10 February 2014, 16:22   #7
bubbob42
Registered User
 
Join Date: Oct 2012
Location: Germany
Posts: 585
What hooverphonique said. CRs are quite rare compared to Rev 2 / Rev B, though.
bubbob42 is offline  
Old 11 February 2014, 15:36   #8
modrobert
old bearded fool
 
modrobert's Avatar
 
Join Date: Jan 2010
Location: Bangkok
Age: 56
Posts: 735
I love it...hehe -> "Mysterious girl, I wanna get close to you ..."
modrobert is offline  
Old 11 February 2014, 17:25   #9
Leffmann
 
Join Date: Jul 2008
Location: Sweden
Posts: 2,267
That's a great use of ARexx. It's cool how you can just tap into programs' functionality and glue them together. ARexx was definitely under-appreciated on the Amiga.
Leffmann is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
V-Lab Motion documentation salax54 request.Other 3 09 April 2023 15:28
Atari C-lab Falcon For Sale!! SPARKYPETE MarketPlace 22 11 September 2008 01:49

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 08:53.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2023, vBulletin Solutions Inc.
Page generated in 0.09378 seconds with 12 queries