I2C communication not working
I have a M5stack I2C joystick connected to side i2C port of the UNIHIKER. I use the following code to initialize the board:
Then I initialize the I2C port. When I do a scan, I see the address after a few tries (which is very slow):
But then, I can not read any values from the i2C sensor:
When I re-initialize the board, I always get an error and only after like 10 retires, the board is initialized correctly. It fails in one of the steps collecting information of the Firmata board, or at opening the serial port:
or this error:
Is there any work around or trick to get i2C working in a stable way?
1. Issue with i3c scanning: It's indeed true that i2c often needs to be scanned multiple times before it can be detected. We will consider ways to optimize this in the future.
2. Issues with obtaining data from the Joystick Unit: There could be two possible reasons. First, the reading method for the joystick might be incorrect. In pinpong, there are multiple reading functions in i2c (readfrom(i2c_addr, read_byte), readfrom_mem(i2c_addr, reg, read_byte), readfrom_mem_restart_transmission(i2c_addr, reg, read_byte)) that you can try. Second, after examining the joystick's Arduino library (https://github.com/esikora/M5StickC_Gamepad/blob/master/include/M5StickC_GamepadIO.h), it was found that its i2c baud rate is 400k, while pinpong's i2c is 100k. Therefore, it could be that the i2c communication baud rates are mismatched. You could try using a 100k baud rate on Arduino to see if you can read the data.
3.Error in pinpong begin in Jupyter: The guess is that the function Board().begin() has been run multiple times in Jupyter. Beca.use Jupyter maintains the state after each code execution, which means it will keep occupying the serial port, running begin again will result in an error. You should ensure that begin is only run once. Additionally, if this error occurs, you can click the reset kernel button on the Jupyter webpage to reset, and then run begin again.
Tonny12138The I2C M5Stack joystick is this model: https://shop.m5stack.com/products/joystick-unit?variant=16804781981786
Ste7an