• Linux and C

    Keith11/08/2025 at 18:15 0 comments

    Having wasted hours on the Python route, I downloaded the manufacturer's example software from here:

    https://ftdichip.com/software-examples/ft4222h-software-examples/

    I compiled the Linux program that reads and writes to an I2C EEPROM, and it worked straight away.

    I thought this looked like a good working starting point for controlling other devices such as the MCP32017 chip, but I ended up wasting a lot of time trying to convert it. They are significantly different in the way they are accessed. Eventually, after a lot of Google AI prompting, I got some working code.

  • Linux and Python

    Keith11/08/2025 at 17:06 0 comments

    Python is popular for writing test scripts so I tried getting this going first.

    I am fairly new to Python, so some of this log will be common knowledge to many. On the plus side, it will be useful to newbies like myself.

    I asked Google AI for help getting started. It told me install various libraries using pip, but my Linux Mint version 22 did not have pip, so I installed pip. Then I got messages refusing to use pip, saying installation is externally managed.

    Google AI explained that this is done for good software management reasons. Suppose you have two programs that need two different versions of the same library. One of them is going to have a problem. If one of those programs is the operating system, it is a big problem. It is impractical to force many different Python programs to use identical libraries.

    This probably explains why my Linux has a Software Manager program. Presumably it has checked the programs it knows about for incompatibilities.

    The solution to the Python library issue is to give projects their own programming environment to store their own libraries. This is called a "virtual environment". I presume the "real environment" is the actual operating system. 

    My first thoughts were that this was going to use a lot of memory to create the environment, and that all the libraries would need reloading every time it was initialised. 

    To start a project, commands like this are needed:

    # Navigate to your home directory or a projects folder
    cd ~
    
    # Create a new directory for your project
    mkdir mcp_project
    cd mcp_project
    
    # Create a virtual environment named 'venv_mcp'
    python3 -m venv venv_mcp
    
    # Activate the virtual environment
    source venv_mcp/bin/activate
    

    On my PC, this creates a directory called venv_mcp which has 13.8 megabytes of files in it. Which is "a lot" to oldies like myself that remember home computers with 64K memory spaces. But my PC has  gigabytes of RAM and terabytes of disk space. It is not a lot anymore. If you want to be frugal, you can always delete that directory afterwards because it doesn't take more than a second to recreate and reload the libraries.

    I can now run pip in this virtual environment:

    pip install pyftdi Adafruit-Blinka adafruit-circuitpython-mcp230xx
    

     and create this program:

    # mcp_blink.py
    import time
    # The 'board' module is provided by Adafruit-Blinka, installed in your venv
    from board import I2C
    import busio
    import digitalio
    # The MCP23017 library is also installed in your venv
    from adafruit_mcp230xx.mcp23017 import MCP23017
    
    # 1. Initialize the I2C bus using pyftdi backend
    try:
        # This automatically finds the FTDI device (UMFT4222EV)
        i2c = busio.I2C(I2C()._clock, I2C()._data)
    
    except Exception as e:
        print(f"Error initializing I2C bus: {e}")
        print("Please ensure the UMFT4222EV is connected, configured for I2C, and recognized by the system.")
        exit()
    
    # 2. Initialize the MCP23017 (default address 0x20)
    try:
        mcp = MCP23017(i2c, address=0x20)
    except ValueError:
        print("Could not find MCP23017 at address 0x20. Check your I2C connections and address pins (A0, A1, A2).")
        i2c.deinit()
        exit()
    
    # 3. Configure a pin (e.g., GPB0, which is index 8) as an output
    led_pin_index = 8
    led_pin = mcp.get_pin_by_number(led_pin_index)
    led_pin.direction = digitalio.Direction.OUTPUT
    
    print(f"Blinking LED on MCP23017 pin GPB0 (index {led_pin_index})...")
    print("Press Ctrl+C to stop.")
    
    # 4. Blink the LED
    try:
        while True:
            led_pin.value = True  # Turn on
            time.sleep(0.5)
            led_pin.value = False # Turn off
            time.sleep(0.5)
    except KeyboardInterrupt:
        print("\nBlink program stopped by user.")
    finally:
        # Clean up resources
        i2c.deinit()
    

    and try to run it:

    python mcp_blink.py

    but then I got this:

    (venv_mcp) keith@mister-biggie:~/mcp_project$ python mcp_blink.py
    Traceback (most recent call last):
      File "/home/keith/mcp_project/mcp_blink.py", line 4, in <module>
        from board import I2C
    ImportError: cannot import name 'I2C' from 'board' (/home/keith/mcp_project/venv_mcp/lib/python3...
    Read more »

  • Windows 10 operation

    Keith11/21/2020 at 03:19 0 comments

    2020-11-20 

    Windows 10 driver installation.

    After wading through documentation, this was very easy.

    Some documentation said that all you need to do is plug the module in and Windows 10 would install the software. I didn't get the expected pop-up windows saying 'new device detected'.

    Fortunately the documentation said you could install the drivers simply by running a single setup.exe program. I did this without problems.

    The module is now visible in the device manager, as a USB device with two FT2223 ports.

  • Initial work

    Keith11/16/2020 at 03:12 0 comments

    2020-11-16

    Downloaded libft4222-linux-1.4.4.9.tgz and unzipped it. Ran the command:

    sudo ./install4222.sh

    and got no complaints.

    In the examples/get-version.c file, there are instructions for Linux:

    cc get-version.c -lft4222 -Wl,-rpath,/usr/local/lib
    sudo ./a.out

    It reports no devices found. So now I need an FT4222 module to play with.

    2020-11-17

    I read that Linux can use the I2C interface in the VGA port. This could bypass the need for a USB-to-I2C module. 

    https://blog.atx.name/twilight-vga-i2c-breakout-board/

    Ran a command to list the I2C adapters, and ten were reported.

    ls /sys/class/i2c-adapter
    i2c-0  i2c-1  i2c-2  i2c-3  i2c-4  i2c-5  i2c-6  i2c-7  i2c-8  i2c-9

     Tried to detect devices:

    for i in $(seq 0 8); do sudo i2cdetect -y $i ; done The program 'i2cdetect' is currently not installed. You can install it by typing: sudo apt-get install i2c-tools

    This installation command worked. Tried to detect devices again, but got permission denied. Had to become a super user with the 'su' command. This allowed devices to be detected. I don't have any devices attached yet, so all I got was ten lots of this:

         0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
    00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
    10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
    20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
    30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
    40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
    50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
    60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
    70: -- -- -- -- -- -- -- --  

    I checked that my video card has a VGA output, as these are going obsolete. Fortunately, mine does.

    Time to look for an old VGA cable... 

    2020-11-17

    Ordered two UMFT4222EV-D modules from Mouser. Despatched from Germany, they arrived 2 days later.

    2020-11-22

    Compiled and ran the example code that gets the hardware version from the module. Success!

    The I2C master example writes and reads a serial EEPROM. I have one but VCC is 5V, not the necessary 3V3. That code would simply prove the interface works. I shall examine the code and see how I could get it talking to one of the I2C slave modules I have.

    2020-11-23

    I had expected my USB-to-I2C module to show up as an I2C bus in the Linux file system., and wondered why it did not. On my laptop, I listed the busses found like so:

    i2c-3    unknown       i915 gmbus panel                    N/A
    i2c-1    unknown       i915 gmbus ssc                      N/A
    i2c-8    unknown       DPDDC-B                             N/A
    i2c-6    unknown       i915 gmbus dpd                      N/A
    i2c-4    unknown       i915 gmbus dpc                      N/A
    i2c-2    unknown       i915 gmbus vga                      N/A
    i2c-0    unknown       SMBus I801 adapter at 3040          N/A
    i2c-7    unknown       DPDDC-A                             N/A
    i2c-5    unknown       i915 gmbus dpb                      N/A

     None of these have FTDI in the name. There is one with vga in the name, and two with DDC in the name.  I could scan those buses, then attach an I2C device to the VGA port, and see which bus had changed. The easiest way was to connect my laptop to the VGA port of my monitor. No soldering needed!

    My laptop LCD panel blinked briefly. If I go to the system settings, it now knows it has two displays. Even if my desktop monitor is in use through its DVI port. I also see that devices appear at addresses 30, 37, 4a, 4b and 50 responded on i2c-7 (the DPDDC-A bus). 50 is the configuration ROM.

    sudo i2cdump -y -r 0-127 8 0x50 b
         0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f    0123456789abcdef
    00: 00 ff ff ff ff ff ff 00 10 ac 79 a0 53 59 43 30    ........??y?SYC0
    10: 05 1d 01 04 a5 34 20 78 e0 ee 95 a3 54 4c 99 26    ?????4 x????TL?&
    20: 0f 50 54 a1 08 00 81 40 81 80 a9 40 b3 00 d1 c0    ?PT??.?@???@?.??
    30: 01 01 01 01 01 01 28 3c 80 a0 70 b0 23 40 30 20    ??????(<??p?#@0 
    40: 36 00 06 44 21 00 00 1a 00 00 00 ff 00 59 50 50    6.?D!..?.....YPP
    50: 59 30 39 31 54 30 43 59 53 0a 00 00 00 fc 00 44    Y091T0CYS?...?.D
    60: 45 4c 4c 20 55 32 34 31 32 4d 0a 20 00 00 00 fd    ELL U2412M? ...?
    70: 00 32 3d 1e 53 11 00 0a 20 20 20 20 20 20 00 c0    .2=?S?.?      .?

    I now know that I can use the Linux i2c tools to access I2C devices through...

    Read more »