Tutorial:Serial Communication

From Freepascal Amiga wiki
Revision as of 14:16, 8 December 2018 by Alb42 (talk | contribs) (Inital serial device description)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Start Next

This tutorial shows how to use devices on Amiga which uses serial communication, either by RS232 or USB. As an example an Arduino UNO board is used. Everything shown here is tested on an Amiga 1200 (68030/50 Mhz, OS 3.9) and on MorphOS machine, but should work the same way on a AmigaOS4 or native AROS (i386/x86_64/ARM) installation.

Preparing the serial device

As an example of a serial device we will use an Arduino UNO connected via USB providing a virtual serial port to the Amiga computer. One could also connect the Arduino to the RS232 of the Amiga (if you do not have a USB port) but be aware you can not directly connect the TX/RX of the Arduino to the Amiga RS232 you need some more electronics, search Google for e.g. "RS232 Shield Arduino".

First we need to program the Arduino. As a start we keep it simple and just use a very simple program which just print out a "Hello World" with a number.

const unsigned long BAUD_RATE = 9600;
int count;

void setup() {
  count = 1;

void loop() {
  Serial.print("Hello Amiga (Msg: ");

It sends a "Hello World (Msg: count)" every half second to the serial interface. Which we can easily check with the Arduino IDE Serial Monitor.

Serial output on Amiga

Now we want to see the same on the Amiga, with RS232 you only need to open any terminal program for example NComm[1] set the device to serial.device Unit to 0 and baud rate to 9600 then you should already see the Hello world output.

If you connect the Arduino via USB the installed USB stack (e.g. Poseidon) should automatically find and use the right driver cdcacm.class for the virtual serial port.


If it does not automatically connect the cdcacm.class to it (e.g. on MorphOS) you have to force it by hand to the Endpoint number 0. (open USB Prefs/Trident, Devices, double click "Arduino UNO", Select "CDC control interface (0)", right click "forced binding" "cdcacm.class", acknowledge the warning, disconnect the device, connect the device). This virtual serial port is now available via the usbmodem.device. Now its the same as for the RS232 case, open terminal program choose usbmodem.device, unit 0, 9600 baud and the output should appear.

Serial device with FreePascal