Go Down

Topic: FTDI example for the Arduino Due (Read 1 time) previous topic - next topic


Hi, I wanted to control an FTDI-Device by an Arduino Due. I found some post of people with similar need, but no working example.
The Due hat a native USB-port, which can be used as an USBHost. The examples with Keyboard and Mouse work fine, but are not easily extended to other devices. The problem is that USB-Devices have different registers to initialize and control communication. There is the FTDI example for the host-shield by Circuits@Home, but I did not get it to work for the DUE. The third example with the DUE-Host library is the ADK-example, which initialized the pipes on an attached device. After changing VID and PID I found the details of setting the BaudRate and FlowControl in the FTDI example for the shield.
Together I managed to control the FTDI-Device (VID 0403, PID 6001).
The header of a file ftd.h and the ftd.cpp file, which should be placed in ...\Documents\Arduino\libraries\USBHost\src, are in the attachment. (Too long to be placed here)

The example code, which reads out the name of the attached controller, is in the code section.

Code: [Select]
#include "variant.h"
#include <stdio.h>
#include <Usb.h>
#include <ftd.h>

  FTDI Terminal Test

  This demonstrates USB Host connectivity between an
  FTDI-Device and an Arduino Due.

  The FDTI for the Arduino Due is a work in progress.
  The program is inspired and based on the Arduino ADK visit
  and the cdcftdi by Circuits@Home visit

  created April 2017
  by Edmund


// Accessory descriptor. For future.
char applicationName[] = "Arduino_Terminal"; // the app on your phone
char accessoryName[] = "Arduino Due"; // your Arduino board
char companyName[] = "Arduino SA";

// Make up anything you want for these
char versionNumber[] = "1.0";
char serialNumber[] = "1";
char url[] = "http://labs.arduino.cc/uploads/ADK/ArduinoTerminal/ThibaultTerminal_ICS_0001.apk";
boolean First = true;
#define RCVSIZE 128

USBHost Usb;
FTDI ftdi(&Usb, companyName, applicationName, accessoryName, versionNumber, url, serialNumber);

void setup() {
  printf("\r\nFTDI demo start\r\n");

void loop() {
  uint8_t Rbuf[RCVSIZE];
  uint32_t nbread = 0;
  char helloworld[] = "*idn?\r";
  byte rcode;

  /* Set BaudRate and FlowControl */
  if ( Usb.getUsbTaskState() == USB_STATE_RUNNING ) {
    if (ftdi.isReady()) {
      if (First) {
        ftdi.SetFlowControl(FTDI_SIO_DISABLE_FLOW_CTRL, 0, 0);
        First = false;
      else  {
        /* Write hello string to FTDI */
        rcode = ftdi.write(strlen(helloworld), (uint8_t *)helloworld);
        printf("ftdi write: %i, '%s'\r\n", rcode, helloworld);

        /* Read data from FTDI and print  */
        rcode = ftdi.read(&nbread, RCVSIZE, Rbuf);
        printf("ftdi read:  %i, Characters: %i\r\n", rcode, nbread);
        if (nbread > 0) {
          printf("RCV: '");
          for (uint32_t i = 2; i < nbread; ++i) printf("%c", (char)Rbuf[i]);  // First two byte are status lines

Not all functionality of the USB-Port is integrated, but it worked for me.

Unfortunately, I can't control other USB to serial adaptors with this software.
I would like to communicate with other Arduino's, but each has its own USB-adaptor and the documentation for the few instructions needed to set up the communication is rather bad. Moreover, part of the communication with the Prolific USB to RS2323 adaptor (VID_067B PID_2303&REV_0300) (BaudRate and control-lines) works, but I get only junk back, so something seems to be missing.
Maybe, some others can contribute the parts needed for other USB-devices and adaptors or find a source for the commands needed.

Best regards



but I get only junk back
I spent two weeks trying to work something out. It seems that all 4 USB to serial adaptors I have work only in one mode: 1 start bit, 6 data bits and a parity bit (haven't checked whether it's odd or even). That causes junk in return for me. So, I built the adaptor from an FTDI32 chip and MAX232 level converter.

Go Up