Skip to content

OSError: [Errno 22] Invalid argument - on Buster #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
briankaemingk opened this issue Apr 7, 2021 · 8 comments · Fixed by #19
Closed

OSError: [Errno 22] Invalid argument - on Buster #18

briankaemingk opened this issue Apr 7, 2021 · 8 comments · Fixed by #19
Assignees

Comments

@briankaemingk
Copy link

Hello!

I have set up the STMPE610 on a pi zero WH running the latest version or Raspbian (buster release 10). I have installed the latest pip dependencies (Adafruit CircuitPython, Bus Device, Register). I have enabled SPI in the boot config.

Running the simpletest with sudo python3 connected to a beautiful, new Adafruit touchscreen overlay gives me the following error:

(env) pi@raspberrypi:~/Adafruit_CircuitPython_STMPE610 $ sudo python3 examples/stmpe610_simpletest.py 
Traceback (most recent call last):
  File "examples/stmpe610_simpletest.py", line 12, in <module>
    st = Adafruit_STMPE610_SPI(spi, cs)
  File "/usr/local/lib/python3.7/dist-packages/adafruit_stmpe610.py", line 278, in __init__
    version = self.get_version
  File "/usr/local/lib/python3.7/dist-packages/adafruit_stmpe610.py", line 193, in get_version
    v_1 = self._read_byte(0)
  File "/usr/local/lib/python3.7/dist-packages/adafruit_stmpe610.py", line 164, in _read_byte
    return self._read_register(register, 1)[0]
  File "/usr/local/lib/python3.7/dist-packages/adafruit_stmpe610.py", line 291, in _read_register
    spi.write(bytearray([register]))
  File "/usr/local/lib/python3.7/dist-packages/busio.py", line 325, in write
    return self._spi.write(buf, start, end)
  File "/usr/local/lib/python3.7/dist-packages/adafruit_blinka/microcontroller/generic_linux/spi.py", line 81, in write
    self._spi.mode = self.mode
  File "/usr/local/lib/python3.7/dist-packages/Adafruit_PureIO/spi.py", line 355, in mode
    self._ioctl(SPI._IOC_WR_MODE, mode)
  File "/usr/local/lib/python3.7/dist-packages/Adafruit_PureIO/spi.py", line 224, in _ioctl
    ioctl(self.handle, ioctl_bytes, arg)
OSError: [Errno 22] Invalid argument

Things I have tried:

  • Verified wires/connections/soldering
  • Restarted the pi
  • Successfully ran the blinka test

Can't wait to get my touchscreen to make my day and get my project rolling!! Any other ideas for troubleshooting this error? Happy to provide more info. Much appreciated.

@ladyada
Copy link
Member

ladyada commented Apr 7, 2021

if you have the kernel overlay you cannot connect to it over SPI 'user space' - you can only do one or the other.

@briankaemingk
Copy link
Author

Thanks for the quick response, @ladyada. Trying to interpret and get to a next step... Not sure if I have the kernel overlay, just installed Buster as directed.. Should I try this all as root or...?

@ladyada
Copy link
Member

ladyada commented Apr 7, 2021

oh you just mean overlay, not kernel overlay. not sure what it is then, we'll leave this open for now!

@briankaemingk
Copy link
Author

ah, yes, the touch overlay is what i mean, which i have used in the past to great success with this microcontroller. the example "make my day" script works like a charm, but now, alas, no dice. not sure what, if anything, changed. also, not really sure how to debug it....

any logs i can provide? any tips from users is much appreciated.

@briankaemingk
Copy link
Author

thanks for assigning this/helping me out, @ladyada and @makermelissa . i did a little more debugging.. this particular error is caused after the first get version/initialization step fails.

in other words, it tries to find the stmpe610 version first on this line. That version check fails (the version returned is 0x0).

next, it executes the following code to switch the polarity, related to this issue

            # if it fails try SPI MODE 1  -- that is what Arduino does
            self._spi = spidev.SPIDevice(spi, cs, baudrate=baudrate, polarity=0, phase=1)

it then tries to find the stmpe610 version on this line. that is when i get the below error:

Traceback (most recent call last):
  File "examples/stmpe610_simpletest.py", line 12, in <module>
    st = Adafruit_STMPE610_SPI(spi, cs)
  File "/usr/local/lib/python3.7/dist-packages/adafruit_stmpe610.py", line 278, in __init__
    version = self.get_version
  File "/usr/local/lib/python3.7/dist-packages/adafruit_stmpe610.py", line 193, in get_version
    v_1 = self._read_byte(0)
  File "/usr/local/lib/python3.7/dist-packages/adafruit_stmpe610.py", line 164, in _read_byte
    return self._read_register(register, 1)[0]
  File "/usr/local/lib/python3.7/dist-packages/adafruit_stmpe610.py", line 291, in _read_register
    spi.write(bytearray([register]))
  File "/usr/local/lib/python3.7/dist-packages/busio.py", line 325, in write
    return self._spi.write(buf, start, end)
  File "/usr/local/lib/python3.7/dist-packages/adafruit_blinka/microcontroller/generic_linux/spi.py", line 81, in write
    self._spi.mode = self.mode
  File "/usr/local/lib/python3.7/dist-packages/Adafruit_PureIO/spi.py", line 355, in mode
    self._ioctl(SPI._IOC_WR_MODE, mode)
  File "/usr/local/lib/python3.7/dist-packages/Adafruit_PureIO/spi.py", line 224, in _ioctl
    ioctl(self.handle, ioctl_bytes, arg)
OSError: [Errno 22] Invalid argument

@briankaemingk
Copy link
Author

briankaemingk commented Apr 8, 2021

Hi everyone,

Just another quick update here. We just got the chip working by pulling "up" the MODE pin on the breakout board (aka setting it to 1). We did this physically on the board by connecting the MODE pin to an open 3.3v pin on the raspberry pi and cycling power to the controller. There is also probably a way to do it via python, which we will try next.

So, it seems like our board was in I2C mode, which initially cause it to fail the version check and not find the board. Then it switched the polarity to try to initialize with...

# if it fails try SPI MODE 1  -- that is what Arduino does
            self._spi = spidev.SPIDevice(spi, cs, baudrate=baudrate, polarity=0, phase=1)

After it ran that, for some reason it couldn't read the output it got back about the version, and it errored out with the below. So maybe there is a way for a more descriptive error message or something, or a warning about setting the controller to SPI mode...? Hope that helps, let me know if you need anything more to help debug. Thanks for the great stuff, Adafruit!! Love playing with it.

  File "examples/stmpe610_simpletest.py", line 12, in <module>
    st = Adafruit_STMPE610_SPI(spi, cs)
  File "/usr/local/lib/python3.7/dist-packages/adafruit_stmpe610.py", line 278, in __init__
    version = self.get_version
  File "/usr/local/lib/python3.7/dist-packages/adafruit_stmpe610.py", line 193, in get_version
    v_1 = self._read_byte(0)
  File "/usr/local/lib/python3.7/dist-packages/adafruit_stmpe610.py", line 164, in _read_byte
    return self._read_register(register, 1)[0]
  File "/usr/local/lib/python3.7/dist-packages/adafruit_stmpe610.py", line 291, in _read_register
    spi.write(bytearray([register]))
  File "/usr/local/lib/python3.7/dist-packages/busio.py", line 325, in write
    return self._spi.write(buf, start, end)
  File "/usr/local/lib/python3.7/dist-packages/adafruit_blinka/microcontroller/generic_linux/spi.py", line 81, in write
    self._spi.mode = self.mode
  File "/usr/local/lib/python3.7/dist-packages/Adafruit_PureIO/spi.py", line 355, in mode
    self._ioctl(SPI._IOC_WR_MODE, mode)
  File "/usr/local/lib/python3.7/dist-packages/Adafruit_PureIO/spi.py", line 224, in _ioctl
    ioctl(self.handle, ioctl_bytes, arg)
OSError: [Errno 22] Invalid argument

@makermelissa
Copy link
Collaborator

I've been trying various strategies to try and reproduce this error without much luck. I also found it defaulted to I2C mode and tying the mode to 3.3v and then fully shutting down the pi and restarting got it working, though I suspect removing power from the breakout for a minute or so would have also worked due to capacitors.

I have tried reproducing the error with both a Raspberry Pi 4 and a Raspberry Pi Zero WH running the latest Raspberry Pi OS. I even tried forcing it to Mode 1 (which didn't work, but didn't produce the OSError). The only states I was able to get are working or I2C mode.

I like your suggestion about making the error message a bit better, so I think I will go with that for the fix.

@briankaemingk
Copy link
Author

Thanks for your efforts, @makermelissa. Hoping this will make things better for users down the road.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants