0

MCP2221 read error
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Re: MCP2221 read error

by pnw on Sun Jan 05, 2020 7:02 pm

adafruit2 wrote:pnw, does it work in a script and not repl?


It seems to produce the same results whether I type the commands into REPL or put them in a file and execute with 'python filename'.

pnw
 
Posts: 4
Joined: Wed Apr 16, 2014 7:57 pm

Re: MCP2221 read error

by adafruit2 on Sun Jan 05, 2020 7:05 pm

hmm! can u post the output trace when it fails? even if its the same as the OP - we're not sure what it is yet...

adafruit2
Site Admin
 
Posts: 19043
Joined: Fri Mar 11, 2005 7:36 pm

Re: MCP2221 read error

by Hulker on Tue Jan 21, 2020 10:00 am

To put in my situation, I get the same issues using MCP2221 as the OP. Here is a copy of running in the REPL

Python 3.6.8 (tags/v3.6.8:3c6b436a57, Dec 24 2018, 00:16:47) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import board
>>> import busio
>>> i2c = busio.I2C(board.SCL, board.SDA)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "M:\Python\lib\site-packages\busio.py", line 18, in __init__
self.init(scl, sda, frequency)
File "M:\Python\lib\site-packages\busio.py", line 32, in init
self._i2c = I2C(frequency=frequency)
File "M:\Python\lib\site-packages\adafruit_blinka\microcontroller\mcp2221\i2c.py", line 7, in __init__
self._mcp2221.i2c_configure(frequency)
File "M:\Python\lib\site-packages\adafruit_blinka\microcontroller\mcp2221\mcp2221.py", line 264, in i2c_configure
12000000 // baudrate - 3]))
File "M:\Python\lib\site-packages\adafruit_blinka\microcontroller\mcp2221\mcp2221.py", line 56, in _hid_xfer
return self._hid.read(64)
File "hid.pyx", line 122, in hid.device.read
OSError: read error
>>>

I'm using current hidapi and blinka python releases on Windows 10 Pro v1909

As with the OP, all the initial checks for the board and the hid device works as per your instructions on the learn page, but as soon as I try to use either the I2C or the GPIO I get the "hid.pyx" hid.device.read error.

Hulker
 
Posts: 13
Joined: Thu Jul 20, 2017 9:30 am

Re: MCP2221 read error

by adafruit2 on Tue Jan 21, 2020 1:38 pm

@hulker, does it work from within a script? we're not sure why this is happening yet!

adafruit2
Site Admin
 
Posts: 19043
Joined: Fri Mar 11, 2005 7:36 pm

Re: MCP2221 read error

by Hulker on Tue Jan 21, 2020 3:39 pm

When I run using a python script I get:-
Code: Select all | TOGGLE FULL SIZE
M:\>python\python -m read-bme680-i2c.py
Traceback (most recent call last):
  File "M:\python\lib\runpy.py", line 183, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "M:\python\lib\runpy.py", line 109, in _get_module_details
    __import__(pkg_name)
  File "M:\read-bme680-i2c.py", line 7, in <module>
    i2c = I2C(board.SCL, board.SDA)
  File "M:\python\lib\site-packages\busio.py", line 18, in __init__
    self.init(scl, sda, frequency)
  File "M:\python\lib\site-packages\busio.py", line 22, in init
    if detector.board.ftdi_ft232h:
  File "M:\python\lib\site-packages\adafruit_platformdetect\board.py", line 600, in ftdi_ft232h
    return self.id == FTDI_FT232H
  File "M:\python\lib\site-packages\adafruit_platformdetect\board.py", line 339, in id
    chip_id = self.detector.chip.id
  File "M:\python\lib\site-packages\adafruit_platformdetect\chip.py", line 65, in id
    'set, but no MCP2221 device found')
RuntimeError: BLINKA_MCP2221 environment variable set, but no MCP2221 device found

The python script file uses BME680 connected on STEMMA and has the code:-
Code: Select all | TOGGLE FULL SIZE
import time
import board
from busio import I2C
import adafruit_bme680
 
# Create library object using our Bus I2C port
i2c = I2C(board.SCL, board.SDA)
bme680 = adafruit_bme680.Adafruit_BME680_I2C(i2c, address=0x76, debug=False)
 
# change this to match the location's pressure (hPa) at sea level
bme680.sea_level_pressure = 1013.25
 
while True:
    print("\nTemperature: %0.1f C" % bme680.temperature)
    print("Gas: %d ohm" % bme680.gas)
    print("Humidity: %0.1f %%" % bme680.humidity)
    print("Pressure: %0.3f hPa" % bme680.pressure)
    print("Altitude = %0.2f meters" % bme680.altitude)
 
    time.sleep(1)

Hope this helps.

Hulker
 
Posts: 13
Joined: Thu Jul 20, 2017 9:30 am

Re: MCP2221 read error

by adafruit2 on Wed Jan 22, 2020 1:41 am

please use the code tag for code segments so its more readable

try unplugging the MCP from usb, connecting it to the BME680, replugging into USB, then re-run the script

adafruit2
Site Admin
 
Posts: 19043
Joined: Fri Mar 11, 2005 7:36 pm

Re: MCP2221 read error

by Hulker on Wed Jan 22, 2020 11:44 am

Believe me I've tried unplugging from USB then plugging back in (with the STEMMA connected to the BME680 and not). I've tried different USB ports (both USB 2 and USB 3 and both on a USB hub and not). I've tried three separate PCs and laptops (all running Windows 10), but I cannot get beyond the errors the OP and myself have experienced with the MCP2221. I have a Binho Nova and a FT232H and after proper configuration and set up these both work great. I just cannot get the MCP2221 board to work. Shame because as a much lower cost alternative and with it not needing any special USB drivers on Windows 10 it is very attractive for use with Blinka.

Hulker
 
Posts: 13
Joined: Thu Jul 20, 2017 9:30 am

Re: MCP2221 read error

by adafruit_support_carter on Wed Jan 22, 2020 12:14 pm

@Hulker Can you check what versions of the libraries you are using? For adafruit-blinka and adafruit-platformdetect. Also, did you set an environment variable BLINKA_FT232H?

@adafruit2 Is something happening with platformdetect? Why is it failing down the FT232H branch?

[EDIT] @all Try running the following interactively via the Python REPL to test basic MCP2221 connectivity.
Code: Select all | TOGGLE FULL SIZE
$ python3
Python 3.6.9 (default, Nov  7 2019, 10:44:02)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import hid
>>> dev = hid.device()
>>> dev.open(0x04D8, 0x00DD)
>>>

and post the full text of any stack traces that happen.

adafruit_support_carter
 
Posts: 14475
Joined: Tue Nov 29, 2016 2:45 pm

Re: MCP2221 read error

by adafruit2 on Wed Jan 22, 2020 2:45 pm

also make you have the very latest version of adafruit-blinka and adafruit-platformdetect, a *lot* of churn has occured recently and you could be desynced - i just tested MCP2221 on my win10

adafruit2
Site Admin
 
Posts: 19043
Joined: Fri Mar 11, 2005 7:36 pm

Re: MCP2221 read error

by Hulker on Wed Jan 22, 2020 4:29 pm

After running the set up checks for MCP2221 instructions:-

Code: Select all | TOGGLE FULL SIZE
G:\IoTLab\Binho\BinhoUSB>python
Python 3.7.5 (tags/v3.7.5:5c02a39a0b, Oct 15 2019, 00:11:34) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import hid
>>> dev = hid.device()
>>> dev.open(0x04D8, 0x00DD)
>>> import board
>>> dir(board)
['G0', 'G1', 'G2', 'G3', 'I2C', 'SCL', 'SDA', 'SPI', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'ap_board', 'board_id', 'detector', 'pin', 'sys']
>>>


Versions of Python modules I am using:-

Code: Select all | TOGGLE FULL SIZE
G:\IoTLab\Binho\BinhoUSB>pip list
Package                          Version
-------------------------------- -------------
Adafruit-Blinka                  3.7.0
adafruit-circuitpython-bme680    3.1.2
adafruit-circuitpython-busdevice 4.1.1
Adafruit-PlatformDetect          2.1.0
Adafruit-PureIO                  1.0.4
hidapi                           0.7.99.post21


No BLINKA environ variables except BLINKA_MCP2221 set to value 1 (definitely neither BLINKA_NOVA nor BLINKA_FT232H are set).

I have used a FT232H in the past but have uninstalled the USB drivers for this already. As you say, why PlatformDetect is choosing the FT232H I don't know.

Hulker
 
Posts: 13
Joined: Thu Jul 20, 2017 9:30 am

Re: MCP2221 read error

by adafruit2 on Wed Jan 22, 2020 4:37 pm

ok you have the right versions, and in the REPL its working - can you try the script that reads the BME680 again?

adafruit2
Site Admin
 
Posts: 19043
Joined: Fri Mar 11, 2005 7:36 pm

Re: MCP2221 read error

by Hulker on Wed Jan 22, 2020 5:06 pm

Sure, running from a script:-

Code: Select all | TOGGLE FULL SIZE
G:\IoTLab>set BLINKA_MCP2221=1

G:\IoTLab>python --version
Python 3.7.5

G:\IoTLab>python -m read-bme680-i2c.py
Traceback (most recent call last):
  File "C:\Python37\lib\runpy.py", line 183, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "C:\Python37\lib\runpy.py", line 109, in _get_module_details
    __import__(pkg_name)
  File "G:\IoTLab\read-bme680-i2c.py", line 7, in <module>
    i2c = I2C(board.SCL, board.SDA)
  File "C:\Python37\lib\site-packages\busio.py", line 18, in __init__
    self.init(scl, sda, frequency)
  File "C:\Python37\lib\site-packages\busio.py", line 22, in init
    if detector.board.ftdi_ft232h:
  File "C:\Python37\lib\site-packages\adafruit_platformdetect\board.py", line 304, in ftdi_ft232h
    return self.id == boards.FTDI_FT232H
  File "C:\Python37\lib\site-packages\adafruit_platformdetect\board.py", line 27, in id
    chip_id = self.detector.chip.id
  File "C:\Python37\lib\site-packages\adafruit_platformdetect\chip.py", line 39, in id
    raise RuntimeError('BLINKA_MCP2221 environment variable ' + \
RuntimeError: BLINKA_MCP2221 environment variable set, but no MCP2221 device found


Running through the REPL, step by step:-

Code: Select all | TOGGLE FULL SIZE
G:\IoTLab>python
Python 3.7.5 (tags/v3.7.5:5c02a39a0b, Oct 15 2019, 00:11:34) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import time
>>> import board
>>> from busio import I2C
>>> import adafruit_bme680
>>> i2c = I2C(board.SCL, board.SDA)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python37\lib\site-packages\busio.py", line 18, in __init__
    self.init(scl, sda, frequency)
  File "C:\Python37\lib\site-packages\busio.py", line 32, in init
    self._i2c = I2C(frequency=frequency)
  File "C:\Python37\lib\site-packages\adafruit_blinka\microcontroller\mcp2221\i2c.py", line 7, in __init__
    self._mcp2221.i2c_configure(frequency)
  File "C:\Python37\lib\site-packages\adafruit_blinka\microcontroller\mcp2221\mcp2221.py", line 264, in i2c_configure
    12000000 // baudrate - 3]))
  File "C:\Python37\lib\site-packages\adafruit_blinka\microcontroller\mcp2221\mcp2221.py", line 56, in _hid_xfer
    return self._hid.read(64)
  File "hid.pyx", line 122, in hid.device.read
OSError: read error
>>>


Again, hope this helps

Hulker
 
Posts: 13
Joined: Thu Jul 20, 2017 9:30 am

Re: MCP2221 read error

by Hulker on Wed Jan 22, 2020 5:07 pm

Code in read-bme680-i2c.py is:-

Code: Select all | TOGGLE FULL SIZE
import time
import board
from busio import I2C
import adafruit_bme680
 
# Create library object using our Bus I2C port
i2c = I2C(board.SCL, board.SDA)
bme680 = adafruit_bme680.Adafruit_BME680_I2C(i2c, address=0x76, debug=False)
 
# change this to match the location's pressure (hPa) at sea level
bme680.sea_level_pressure = 1013.25
 
while True:
    print("\nTemperature: %0.1f C" % bme680.temperature)
    print("Gas: %d ohm" % bme680.gas)
    print("Humidity: %0.1f %%" % bme680.humidity)
    print("Pressure: %0.3f hPa" % bme680.pressure)
    print("Altitude = %0.2f meters" % bme680.altitude)
 
    time.sleep(1)

Hulker
 
Posts: 13
Joined: Thu Jul 20, 2017 9:30 am

Re: MCP2221 read error

by adafruit2 on Wed Jan 22, 2020 5:23 pm

please just run 'python read-bme680-i2c.py'
something is weird with your setup because you're able to connect to the board in the repl but not in the script - are you using a pyenv or something?

adafruit2
Site Admin
 
Posts: 19043
Joined: Fri Mar 11, 2005 7:36 pm

Re: MCP2221 read error

by Hulker on Wed Jan 22, 2020 5:28 pm

Code: Select all | TOGGLE FULL SIZE
G:\IoTLab>python read-bme680-i2c.py
Traceback (most recent call last):
  File "read-bme680-i2c.py", line 7, in <module>
    i2c = I2C(board.SCL, board.SDA)
  File "C:\Python37\lib\site-packages\busio.py", line 18, in __init__
    self.init(scl, sda, frequency)
  File "C:\Python37\lib\site-packages\busio.py", line 22, in init
    if detector.board.ftdi_ft232h:
  File "C:\Python37\lib\site-packages\adafruit_platformdetect\board.py", line 304, in ftdi_ft232h
    return self.id == boards.FTDI_FT232H
  File "C:\Python37\lib\site-packages\adafruit_platformdetect\board.py", line 27, in id
    chip_id = self.detector.chip.id
  File "C:\Python37\lib\site-packages\adafruit_platformdetect\chip.py", line 39, in id
    raise RuntimeError('BLINKA_MCP2221 environment variable ' + \
RuntimeError: BLINKA_MCP2221 environment variable set, but no MCP2221 device found


Not using a virtual environment, all the python modules are installed into the main python installation directory.

Hulker
 
Posts: 13
Joined: Thu Jul 20, 2017 9:30 am

Please be positive and constructive with your questions and comments.