GithubHelp home page GithubHelp logo

writing to GPIO pins about pyftdi HOT 4 CLOSED

eblot avatar eblot commented on August 24, 2024
writing to GPIO pins

from pyftdi.

Comments (4)

rdpoor avatar rdpoor commented on August 24, 2024

To make it clear, here's a minimal working program written in C using the D2xx library calls. I'd like to replicate this functionality using pyftdi:

/**
 * Test CBUS bitbang interface on FT232 chip.
 *
 * Our goal is to wiggle CBUS bit 3, which in the FTDI USB-RS485 cable
 * controls the 5V drive circuitry on the output wires.
 *
 *   gcc -o bitbang bitbang.c -L. -lftd2xx -Wl,-rpath /usr/local/lib
 * cc bitbang.c -o bitbang -Wall -Wextra -lftd2xx -lpthread -lobjc -framework IOKit -framework CoreFoundation -Wl,-rpath /usr/local/lib -L/usr/local/lib
 */

#include "ftd2xx.h"
#include <WinTypes.h>
#include <stdio.h>
#include <unistd.h>

const UCHAR Drive03Hi=0x88;     /* CBUS03 configured as output, drive hi */
const UCHAR Drive03Lo=0x80;     /* CBUS03 configured as output, drive lo */

int main() {
  FT_HANDLE ftHandle;
  FT_STATUS ftStatus = FT_Open(0, &ftHandle);

  if(ftStatus != FT_OK) {
    fprintf(stderr, "FT_Open failed => %d\n", ftStatus);
    return 1;
  }
  // Repeatedly drive CBUS 03 high and then low
  while(ftStatus == FT_OK) {
    ftStatus = FT_SetBitMode(ftHandle, Drive03Hi, FT_BITMODE_CBUS_BITBANG);
    sleep(3);
    ftStatus = FT_SetBitMode(ftHandle, Drive03Lo, FT_BITMODE_CBUS_BITBANG);
    sleep(3);
  } 
  FT_Close(ftHandle);
}

from pyftdi.

rdpoor avatar rdpoor commented on August 24, 2024

Solved. But some documentation might help. Bitbang for CBUS is a bit strange, since the set_bitmode() mask argument defines the data direction and state of the bits -- there is no separate write function.

Working code example follows:

from pyftdi.ftdi import Ftdi
import time

ftdi = Ftdi()
ftdi.open_from_url('ftdi:///1')
while(True):
    ftdi.set_bitmode(0x88, Ftdi.BITMODE_CBUS)
    time.sleep(3)
    ftdi.set_bitmode(0x80, Ftdi.BITMODE_CBUS)
    time.sleep(3)
# never actually gets here...
ftdi.close()

from pyftdi.

Zibri avatar Zibri commented on August 24, 2024

@rdpoor I get: AttributeError: type object 'Ftdi' has no attribute 'BITMODE_CBUS' :(

from pyftdi.

eblot avatar eblot commented on August 24, 2024

Please do not comment on tickets that are 4 years old, the code has evolved quite a bit since.

If there is an issue that is related to an existing ticket, open a new one and add a reference to it. Thanks.

from pyftdi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.