FTDI FT232x

Fast USB multi-protocol connectivity

Overview

Package ftdi provides support for FT232H/FT232R/FT2232H devices via the Future Technology “D2XX” driver with minimal configuration on your side.

The driver implements:

  • GPIO
  • I²C
  • SPI

Installation

Debian

This includes Raspbian and Ubuntu.

  1. Configure cgo as explained at /platform/linux/#cgo.

Temporary

Run this command after connecting your FTDI device:

sudo rmmod ftdi_sio usbserial

Permanent

Run these commands before connecting your FTDI device:

curl https://raw.githubusercontent.com/periph/host/main/ftdi/debian/98-ft232h.rules > 98-ft232h.rules
sudo cp 98-ft232h.rules /etc/udev/rules.d/
sudo udevadm control --reload-rules
sudo udevadm trigger --verbose

macOS

  1. Configure cgo as explained at /platform/macos/#cgo.
  2. Unload the AppleUSBFTDI kernel driver with one of the two following ways:

Temporary

This temporarily unload Apple’s FTDI driver. This needs to be done after each OS startup:

sudo kextunload -b com.apple.driver.AppleUSBFTDI

Permanently

This permanently disable Apple’s FTDI driver.

  1. Download D2xxHelper.
  2. Run D2xxHelper_xxx.pkg you just downloaded.
  3. Reboot.

Windows

  1. Connect the device.
  2. Windows Update should install the FTDI D2XX driver automatically. Wait for it to occur.

Example

Use SPI on a FT232H.

package main

import (
    "fmt"
    "log"

    "periph.io/x/conn/v3/physic"
    "periph.io/x/conn/v3/spi"
    "periph.io/x/host/v3"
    "periph.io/x/host/v3/ftdi"
)

func main() {
    if _, err := host.Init(); err != nil {
        log.Fatal(err)
    }

    all := ftdi.All()
    if len(all) == 0 {
        log.Fatal("found no FTDI device on the USB bus")
    }

    // Use channel A.
    ft232h, ok := all[0].(*ftdi.FT232H)
    if !ok {
        log.Fatal("not FTDI device on the USB bus")
    }

    s, err := ft232h.SPI()
    if err != nil {
        log.Fatal(err)
    }

    c, err := s.Connect(physic.KiloHertz*100, spi.Mode3, 8)
    write := []byte{0x10, 0x00}
    read := make([]byte, len(write))
    if err := c.Tx(write, read); err != nil {
        log.Fatal(err)
    }
    // Use read.
    fmt.Printf("%v\n", read[1:])
}

Buying

These links are for the FT232H, which is higher speed than the FT232R for nearly the same price:

It is not recommended to buy chips on AliExpress or Amazon (except for the adafruit branded boards). Most of these are cheap counterfeit that have incomplete support. They are often sold under the brand “CJMCU”.

The periph authors do not endorse any specific seller. These are only provided for your convenience.