Adafruit Industries, Essential service and business: NYC – Executive Order 202.6 - Read more. Accepting essential orders - here's how.
0

MCP2221 read error
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Re: MCP2221 read error

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

you could try uninstalling-reinstalling or starting a new pyenv, there's something unusual about your setup...but we're not sure what and we cant reproduce it.

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

Re: MCP2221 read error

by jklem on Sun Jan 26, 2020 2:23 am

I have a very similar problem. Following your setup instructions, everything works up to this point:

Code: Select all | TOGGLE FULL SIZE
>>> led = digitalio.DigitalInOut(board.G0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\John\AppData\Local\Programs\Python\Python38-32\lib\site-packages\digitalio.py", line 85, in __init__
    self.direction = Direction.INPUT
  File "C:\Users\John\AppData\Local\Programs\Python\Python38-32\lib\site-packages\digitalio.py", line 111, in direction
    self._pin.init(mode=Pin.IN)
  File "C:\Users\John\AppData\Local\Programs\Python\Python38-32\lib\site-packages\adafruit_blinka\microcontroller\mcp2221\pin.py", line 24, in init
    mcp2221.gp_set_mode(self.id, mcp2221.GP_GPIO)
  File "C:\Users\John\AppData\Local\Programs\Python\Python38-32\lib\site-packages\adafruit_blinka\microcontroller\mcp2221\mcp2221.py", line 66, in gp_set_mode
    current = self._hid_xfer(b'\x61')
  File "C:\Users\John\AppData\Local\Programs\Python\Python38-32\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 updated adafruit-blinka and adafruit-platformdetect. BLINKA_MCP2221 is properly set; no other BLINKA environment variables. Not using a virtual environment. Win 10 Pro. hid.enumerate() shows the board. dir(board) works. Fresh installation of hidapi. device.open(0x04d8, 0x00dd) works.

Running a simple script or executing line-by-line in the REPL produces different results. Simple script:
Code: Select all | TOGGLE FULL SIZE
import board
import digitalio
led = digitalio.DigitalInOut(board.G0)
led.direction = digitalio.Direction.OUTPUT
led.value = True


Result from the REPL is similar to above error (read error). Running script from the command line produces
Code: Select all | TOGGLE FULL SIZE
  File "C:\Users\John\Documents\ham radio\GPIO project\mcpledtest.py", line 2, in <module>
    import digitalio
  File "C:\Users\John\AppData\Local\Programs\Python\Python38-32\lib\site-packages\digitalio.py", line 14, in <module>
    if detector.chip.BCM2XXX:
  File "C:\Users\John\AppData\Local\Programs\Python\Python38-32\lib\site-packages\adafruit_platformdetect\chip.py", line 138, in __getattr__
    if self.id == attr:
  File "C:\Users\John\AppData\Local\Programs\Python\Python38-32\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

jklem
 
Posts: 12
Joined: Sun Dec 08, 2019 10:20 pm

Re: MCP2221 read error

by adafruit2 on Sun Jan 26, 2020 12:28 pm

i find this deeply mystifying...
@carter do ya wanna try investigating next week?

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

Re: MCP2221 read error

by adafruit_support_carter on Mon Jan 27, 2020 12:20 pm

This is a weird issue and doesn't help that we can't reproduce it.

For those having connect issue - can you post a screen shot of what the MCP2221 is showing up as in Device Manager.

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

Re: MCP2221 read error

by Hulker on Mon Jan 27, 2020 3:27 pm

Hi,

this is my device manager after plugging in MCP2221A

device_manager.png
device_manager.png (85.99 KiB) Viewed 93 times

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

Re: MCP2221 read error

by adafruit_support_carter on Mon Jan 27, 2020 3:39 pm

@Hulker, thanks. Can you also expand the "Human Interface Devices" branch.

More info for all - The MCP2221 will enumerate as two separate devices: (1) A USB Serial Device and (2) A Human Interface Device. The first is how you would use the serial function. The second is for everything else: GPIO, I2C, etc.

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

Re: MCP2221 read error

by jklem on Mon Jan 27, 2020 8:26 pm

I see both "USB Input Device" (under the HID branch) and USB Serial Device COM18 (under Ports branch), both with PID 0x04d8 VID 0x00dd.

Capture.PNG
Capture.PNG (21.92 KiB) Viewed 85 times

jklem
 
Posts: 12
Joined: Sun Dec 08, 2019 10:20 pm

Re: MCP2221 read error

by adafruit_support_carter on Tue Jan 28, 2020 11:49 am

Thanks for the device manager info.

Can everyone also sound off on the hardware specifics for the USB path they are using. What type of USB port on the computer? What type of USB cable? Any adapters or hubs that are also being used? etc.

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

Re: MCP2221 read error

by jklem on Tue Jan 28, 2020 11:31 pm

I'm using a USB 2.0 A port on my tower, and red 1-meter A-to-C USB 2.0 cable from another reputable online provider of open-source electronics. It is the only A-to-C cable I have, at least for now. I don't have any hubs aside from whatever might be inside my Optiplex 790.

jklem
 
Posts: 12
Joined: Sun Dec 08, 2019 10:20 pm

Re: MCP2221 read error

by hermaml on Wed Jan 29, 2020 2:25 pm

I have a similar error when I try to use digitalio.DigitalInOut(board.G0).
Test 1: Using 5.0V on MCP2221, with external hub switch USB port A on PC ... Some times PASS
Test 2: Using 3.3V on MCP2221, with external hub switch USB port A on PC .... FAIL
Test 3: Using 5.0V on MCP2221 directly into another USB port B on PC ............. FAIL
Test 4: Using 3.3V on MCP2221 directly into another USB port Bon PC ............. FAIL

Note 1: Looks like my system has a dependency on the 5.0V config on the MCP2221 and the PC USB port. I also found that using a longer USB cable can make things more flaky.
Note 2: Using a different MCP2221 board showed similar results on the external hub, sometime both the 5.0V and 3.3V configurations would work.
Note 3: I also have issues trying to get ports to become inputs, Port G3 works, but G0:G2 wont switch using (PinG1.direction = digitalio.Direction.INPUT)
Note 4: All of this looks like a communication issues between my PC and the MCP2221 , can we slow down the USB interface as a test?
Thanks
==============================================
Debug Test 1:
Given: Jumper on MCP2221 set to 5.0V,
Using a Sabrent USB 4 port Hub HB-UM43 to PC USB port on PC
>>> import board
>>> import digitalio
>>> led = digitalio.DigitalInOut(board.G0)
>>>
Note: My py script also works sometimes, if I run the script several times it will start working
==============================================
Debug Test 2:
Given: Jumper on MCP2221 set to 3.3V,
Using a Sabrent USB 4 port Hub HB-UM43 to PC USB port on PC

>>> import board
>>> import digitalio
>>> led = digitalio.DigitalInOut(board.G0)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\herma\AppData\Local\Programs\Python\Python38\lib\site-packages\digitalio.py", line 85, in __init__
self.direction = Direction.INPUT
File "C:\Users\herma\AppData\Local\Programs\Python\Python38\lib\site-packages\digitalio.py", line 111, in direction
self._pin.init(mode=Pin.IN)
File "C:\Users\herma\AppData\Local\Programs\Python\Python38\lib\site-packages\adafruit_blinka\microcontroller\mcp2221\pin.py", line 24, in init
mcp2221.gp_set_mode(self.id, mcp2221.GP_GPIO)
File "C:\Users\herma\AppData\Local\Programs\Python\Python38\lib\site-packages\adafruit_blinka\microcontroller\mcp2221\mcp2221.py", line 66, in gp_set_mode
current = self._hid_xfer(b'\x61')
File "C:\Users\herma\AppData\Local\Programs\Python\Python38\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
==============================================
Debug Test 3:
Given: Jumper on MCP2221 set to 5.0V,
Directly connect to PC USB port on PC
>>> import board
>>> import digitalio
>>> led = digitalio.DigitalInOut(board.G0)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\herma\AppData\Local\Programs\Python\Python38\lib\site-packages\digitalio.py", line 85, in __init__
self.direction = Direction.INPUT
File "C:\Users\herma\AppData\Local\Programs\Python\Python38\lib\site-packages\digitalio.py", line 111, in direction
self._pin.init(mode=Pin.IN)
File "C:\Users\herma\AppData\Local\Programs\Python\Python38\lib\site-packages\adafruit_blinka\microcontroller\mcp2221\pin.py", line 24, in init
mcp2221.gp_set_mode(self.id, mcp2221.GP_GPIO)
File "C:\Users\herma\AppData\Local\Programs\Python\Python38\lib\site-packages\adafruit_blinka\microcontroller\mcp2221\mcp2221.py", line 66, in gp_set_mode
current = self._hid_xfer(b'\x61')
File "C:\Users\herma\AppData\Local\Programs\Python\Python38\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
>>>
==============================================
Debug Test 4:
Given: Jumper on MCP2221 set to 3.3V,
Directly connect to PC USB port on PC
>>> import board
>>> import digitalio
>>> led = digitalio.DigitalInOut(board.G0)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\herma\AppData\Local\Programs\Python\Python38\lib\site-packages\digitalio.py", line 85, in __init__
self.direction = Direction.INPUT
File "C:\Users\herma\AppData\Local\Programs\Python\Python38\lib\site-packages\digitalio.py", line 111, in direction
self._pin.init(mode=Pin.IN)
File "C:\Users\herma\AppData\Local\Programs\Python\Python38\lib\site-packages\adafruit_blinka\microcontroller\mcp2221\pin.py", line 24, in init
mcp2221.gp_set_mode(self.id, mcp2221.GP_GPIO)
File "C:\Users\herma\AppData\Local\Programs\Python\Python38\lib\site-packages\adafruit_blinka\microcontroller\mcp2221\mcp2221.py", line 66, in gp_set_mode
current = self._hid_xfer(b'\x61')
File "C:\Users\herma\AppData\Local\Programs\Python\Python38\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
>>>

hermaml
 
Posts: 8
Joined: Fri Jan 24, 2020 11:15 am

Re: MCP2221 read error

by jklem on Sat Feb 01, 2020 10:20 pm

For whatever it's worth, I tried this on a second computer with the same results (failure).

If Adafruit is still unable to reproduce this problem, I'd be happy to return my MCP2221A and a USB cable to allow testing there with peripheral hardware that consistently fails.

jklem
 
Posts: 12
Joined: Sun Dec 08, 2019 10:20 pm

Re: MCP2221 read error

by adafruit2 on Sat Feb 01, 2020 11:20 pm

carter's managed to reproduce the issue and will have a fix soon! hold tight :)

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

Re: MCP2221 read error

by adafruit_support_carter on Sun Feb 02, 2020 11:40 pm

OK all, there's a nominal fix added to the 3.8.0 release:
https://github.com/adafruit/Adafruit_Bl ... /tag/3.8.0

To use it, first update to that version of the library. Then, set an additional environment variable BLINKA_MCP2221_HID_DELAY to a time in seconds. This is a simple blocking delay that has been added to the underlying HID transfer. Start with a value of about 0.005 and see what happens
Code: Select all | TOGGLE FULL SIZE
set BLINKA_MCP2221_HID_DELAY=0.005

If this environment variable is not set, the default value is 0 (no delay). You can lower/raise the value to try fine tuning it. In particular, if you still get the OSError: read error, try raising it.

Please try this new version and fix and report back with what happens.

MORE INFO
On the machine I was able to recreate this issue on, the port was USB 3.0. I was able to get things to work by using a USB 2.0 hub and attaching the MCP2221 through that. No other changes. It seems like others tried that but without success. So not sure why that wasn't a fix for all.

The above delay will potentially break some other drivers. For example, the MLX90640 was not happy with the added delay. Reading the image sensor data on that requires multiple HID transfers. Everything that only uses a single HID transfer seemed fine, which is hopefully most of the sensor breakouts being used.

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

Re: MCP2221 read error

by jklem on Mon Feb 03, 2020 1:33 am

Well, this works, sort of. I need a delay of somewhere between 0.1 s (never works) and 0.15 s (seems to always work) on the one computer I've tried so far. I've only tried toggling a GPIO pin, no i2c yet.

I am hoping for something a bit faster, eventually. Thanks for getting us this far.

jklem
 
Posts: 12
Joined: Sun Dec 08, 2019 10:20 pm

Re: MCP2221 read error

by adafruit_support_carter on Tue Feb 04, 2020 7:47 pm

OK, yet another attempt. Try the 3.9.0 release:
https://github.com/adafruit/Adafruit_Bl ... /tag/3.9.0

Try first without any environment variables set. If you hit the issue again, try setting a value for the new environment variable BLINKA_MCP2221_RESET_DELAY. The default is 0.1, which made things work on the test machine. But try cranking that up, maybe even to a full second or more:
Code: Select all | TOGGLE FULL SIZE
set BLINKA_MCP2221_RESET_DELAY=1

and see if that helps.

With the above, I was able to get things to work without needing the delay from the previous release. You can either leave it undefined, in which case it will default to 0, or you can force it back to 0 with:
Code: Select all | TOGGLE FULL SIZE
set BLINKA_MCP2221_HID_DELAY=0

or
Code: Select all | TOGGLE FULL SIZE
set BLINKA_MCP2221_HID_DELAY=

to undefine it and revert to default.

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

Please be positive and constructive with your questions and comments.