
          Arduino Due as a RPI/Libre Computer/... Terminal Server
          =======================================================
                

1. Design Goal: Provide a terminal  server for  Raspberry Pi, Libre  Computer,
   and other  single board  computers  with 3.3V serial  ports, using  readily
   available  off-the-shelf   components,  without  requiring   customization,
   soldering, firmware replacement.

2. Target audience: beginners rigging their own headless RPI setup.

3. Parts list:

   - one RPI running a recent Raspbian version,
   
   - micro-USB cable,
   
   - male-to-female jumper cables,
   
   - one Arduino Due (Mouser.com)
   
   - up to 3 Libre Computer Project boards, and/or up to 12 RPIs.

4. Connect the RPI to the Due's programming port, i.e. the USB port right next
   to the barrel  power  connector.  Do not use the native port,  further away
   from the barrel connector, right next to the reset button.
   
5. On the RPI  controlling  the  Arduino  Due,  install  the  Arduino IDE (apt
   install -y arduino).

6. Invoke the  Arduino  (either, in a shell, run  "arduino",  or drop down the
   application menu, Programming->Arduino IDE).

7. Add Due support through board manager (Tools->Boards->Boards  Manager, look
   for  "Arduino SAM Boards (32 bits ARM Cortex M3)"; do not install  "Arduino
   SAMD (32 bits ARM Cortex M0+)").

8. Tell the IDE which port the Due is using (Tools->Port->/dev/ttyACM0).

9. Extract the termserv.tgz archive into your $HOME/Arduino. This creates

pi@pi4b02:~/Arduino/termserv$ pwd
/home/pi/Arduino/termserv
pi@pi4b02:~/Arduino/termserv$ ls -ls
total 100
 4 -rw-r--r-- 1 pi pi 3290  Dec 6 11:38 fifo.h
12 -rw-r--r-- 1 pi pi 12259 Jan 7 08:28 makefile
 4 -rw-r--r-- 1 pi pi 2108  Dec 7 14:24 soft_uart.cpp
64 -rw-r--r-- 1 pi pi 65120 Dec 6 11:43 soft_uart.h
12 -rw-r--r-- 1 pi pi 9883  Feb 7 12:42 termserv.ino
 4 -rw-r--r-- 1 pi pi 3087  Feb 7 15:06 termserv.txt
pi@pi4b02:~/Arduino/termserv$

10. Open the sketch using File->Open->termserv.ino  (might have to navigate to
    the  $HOME/Arduino/termserv  first).  Compile and upload the sketch to the
    Due (Sketch->Upload).

11. Alternatively, open a terminal window, go to  $HOME/Arduino/termserv,  use
    the  included  makefile  to compile  and upload the  sketch.  The  targets
    provide by the makefile are:

    - clean : removes objects, libraries, hex and bin files,
    - termserv.bin : compile and link the sketch, then convert for upload,
    - flash : compile, link, convert and upload the sketch.
    
    Invoke make with one of these targets, like:
    
    make clean make flash
    
12. To talk to the terminal server, pick any terminal  program, connect to the
    same port used to upload the  executable (in our case,  /dev/ttyACM0),  at
    115.200bps,  8N1. The code  initially  talks to  Serial1.  Switch to other
    serial ports using Ctrl-@  (Ctrl-2), then a digit (1-9) or character (a-c)
    for  other  ports.  The  hardware  ports  (1-3) are  configured  to run at
    115kbps, the software ports at 9.6kbps. Hardware serial ports are found on
    the single-row  connection, labeled as RX1, TX1 through RX3, TX3. Software
    serial ports are found on the dual-row  header at the board's  narrow end.
    Receive pins are even  numbered,  facing away from the edge, transmit pins
    are  odd-numbered,  right next to the edge. The first software serial port
    uses pin 22 to  receive,  23 to send.  Make  sure to also  wire up  ground
    (GND).
