IOError with Qwiic Keypad and Python

I’ve been trying to get the Qwiic Keypad (COM-15290) Example 1 to run on a Pi Zero W with python. I connect the keypad using the Qwiic Hat for the Pi. When I start the program it generates non-numeric characters for a while, even when I don’t touch the keypad, then crashes. If I try to key in a number there is a delay before the number is displayed, often with non-numeric characters interspersed, and again a crash.

Here are two example runs:

~/myScripts/keypad $ python qwiic_keypad_ex1.py

SparkFun qwiic Keypad Example 1

Initialized. Firmware Version: v 127.127

Press a button: * to do a space. # to go to next line.

?Traceback (most recent call last):

File “qwiic_keypad_ex1.py”, line 91, in

runExample()

File “qwiic_keypad_ex1.py”, line 66, in runExample

myKeypad.update_fifo()

File “/usr/local/lib/python2.7/dist-packages/qwiic_keypad.py”, line 229, in update_fifo

self._i2c.writeByte(self.address, KEYPAD_UPDATE_FIFO, 0x01)

File “/usr/local/lib/python2.7/dist-packages/qwiic_i2c/linux_i2c.py”, line 180, in writeByte

return self.i2cbus.write_byte_data(address, commandCode, value)

IOError: [Errno 121] Remote I/O error

~/myScripts/keypad $ python qwiic_keypad_ex1.py

SparkFun qwiic Keypad Example 1

Initialized. Firmware Version: v 1.0

Press a button: * to do a space. # to go to next line.

23??456??78??9 123Traceback (most recent call last):

File “qwiic_keypad_ex1.py”, line 91, in

runExample()

File “qwiic_keypad_ex1.py”, line 66, in runExample

myKeypad.update_fifo()

File “/usr/local/lib/python2.7/dist-packages/qwiic_keypad.py”, line 229, in update_fifo

self._i2c.writeByte(self.address, KEYPAD_UPDATE_FIFO, 0x01)

File “/usr/local/lib/python2.7/dist-packages/qwiic_i2c/linux_i2c.py”, line 180, in writeByte

return self.i2cbus.write_byte_data(address, commandCode, value)

IOError: [Errno 121] Remote I/O error

The keypad works fine on an Arduino ; there are no extra characters. I’ve tried it on two Pi Zero Ws, and both showed this problem. However, I don’t have any problems running the Qwiic joystick example on the Pi Zero W.

Any suggestions?

Hi robothacker,

Sorry for the delay here. Assuming you have not tried already and to see if it is a problem with the specific example or something wrong with the Python module, try the other examples ([Example 2 and [Example 3) and see if you get the same error. That will help us nail down where the error is coming from.](Qwiic_Keypad_Py/examples/qwiic_keypad_ex3.py at main · sparkfun/Qwiic_Keypad_Py · GitHub)](Qwiic_Keypad_Py/examples/qwiic_keypad_ex2.py at main · sparkfun/Qwiic_Keypad_Py · GitHub)

The “IOError: [Errno 121] Remote I/O error” error occurs when the I2C bus can’t reach the device at the specified I2C address, which can happen from time to time. When this occurs, an exception error is thrown and it causes the code to exit. You can add a “try” and “except” in the example to prevent that from happening. The code below will just print out the error message instead of terminating the script.

try:
	# necessary for keypad to pull button from stack to readable register
	myKeypad.update_fifo()
	button = myKeypad.get_button()
except Exception as e:
	print(e)

I see the same issue you are seeing with the non-numeric character response. I’ll have to scope it with a logic analyzer next week to dig into that more.

I’ve narrowed down this issue to a communication issue on the I2C bus (missing a stop/start bit between the write and read actions). After scoping the issue with a logic analyzer between a Raspberry Pi and RedBoard Qwiic, it seems that the issue might be with the I2C driver on the Raspberry Pi and could be similar to the reported clock stretching issues.

I was able to get it working by lowering the baudrate of the I2C bus to 50kHz. (*A similar method is used in our [Qwiic kit for the Raspberry Pi to address clock stretching.[/i])
Run the following command in the terminal:
* *sudo nano /boot/config.txt* *
If you don’t have nano installed run:
* *sudo apt-get install nano* *
Once you have the config.txt file up, scroll down with the arrow keys to:
* *dtparam=i2c_arm=on #dtparam=i2s=on #dtparam=spi=on* *
To change the baudrate, add (don’t use spaces):
* *dtparam=i2c_arm_baudrate=50000* *
To save the changes press:

  • - “Ctrl+x”

  • - “y”

  • - “Enter”

  • ](Qwiic Kit for Raspberry Pi Hookup Guide - SparkFun Learn)