https://iosoft.blog/2018/12/02/ftdi-python-part-1/

https://iosoft.blog/2018/12/05/ftdi-python-part-2/




* Just realized I installed pyftdi in python3 vs. pylibftdi


  https://eblot.github.io/pyftdi/installation.html



*** example run ************************

greg@xubox:~/temp/ftdiWork$ python3

  Python 3.7.3 (default, Oct  7 2019, 12:56:13) 

  >>> from pyftdi.ftdi import Ftdi
  >>> Ftdi().open_from_url('ftdi:///?')

  Available interfaces:
    ftdi://ftdi:232:AK06VDZ3/1   (FT232R USB UART)

  Please specify the USB device

****************************************




* sudo adduser greg dialout



* python -m pylibftdi.examples.list_devices


* sudo apt install python-pip

* pip install pylibftdi


* https://pylibftdi.readthedocs.io/en/0.15.0/installation.html#linux

* 


* Also, I had to install python_pip3

  then run pip3 to get pylibftdi




* Apparently you need to add the file

  /etc/udev/rules.d/

    99-libftdi.rules

------  Begin : contents of 99-libftdi.rules ------------------
SUBSYSTEMS=="usb", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", GROUP="dialout", MODE="0660"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6014", GROUP="dialout", MODE="0660"

------  END   : contents of 99-libftdi.rules ------------------


* gcc first.c -lm -lftdi -o x.out

  x.out

--- Begin : first.c ------------------
/* bitbang_ft2232.c

   Output some flickering in bitbang mode to the FT2232

   Thanks to max@koeln.ccc.de for fixing and extending
   the example for the second channel.

   This program is distributed under the GPL, version 2
*/

#include <stdio.h>
#include <unistd.h>
#include <ftdi.h>

int main(int argc, char **argv)
{
    struct ftdi_context ftdic;
    char buf[1];
    int f,i;

    if (ftdi_init(&ftdic) < 0)
    {
        fprintf(stderr, "ftdi_init failed\n");
        return EXIT_FAILURE;
    }

    f = ftdi_usb_open(&ftdic, 0x0403, 0x6001);
    if (f < 0 && f != -5)
    {
        fprintf(stderr, "unable to open ftdi device: %d (%s)\n", f, ftdi_get_error_string(&ftdic));
        exit(-1);
    }
    printf("ftdi open succeeded : %d\n",f);

    printf("enabling bitbang mode\n");
    ftdi_set_bitmode(&ftdic, 0xFF, BITMODE_BITBANG);


    // Write data
    printf("startloop\n");
    for (i = 0; i < 400000; i++)
    {
        buf[0] =  0x1;
        /* printf("porta: %02i: 0x%02x \n",i,buf[0]); */
        f = ftdi_write_data(&ftdic, buf, 1);
        if (f < 0)
            fprintf(stderr,"write failed on channel 1 for 0x%x, error %d (%s)\n", buf[0], f, ftdi_get_error_string(&ftdic));
        usleep(30303000);

        buf[0] =  0x2;
        /* printf("porta: %02i: 0x%02x \n",i,buf[0]); */
        f = ftdi_write_data(&ftdic, buf, 1);
        if (f < 0)
            fprintf(stderr,"write failed on channel 1 for 0x%x, error %d (%s)\n", buf[0], f, ftdi_get_error_string(&ftdic));
        usleep(69697000);
    }
    printf("\n");

    printf("disabling bitbang mode\n");
    ftdi_disable_bitbang(&ftdic);
    ftdi_usb_close(&ftdic);
    ftdi_deinit(&ftdic);

}

--- End   : first.c ------------------