WouterSchols / SmartChessboard

A software project to connect any electronic DIY chessboard to chess.com
MIT License
14 stars 2 forks source link

Error #6

Open Dani18718 opened 1 year ago

Dani18718 commented 1 year ago

Hello again,

I implemented your hardware project nearly the same using the tutorial. I do not see the MCPs using i2cdetect, but using some test code they are displayed via the TCA Multiplexer at x20 and the following addresses. What I want to say is, that the wiring should not be the problem. I get the following error and hope that you can give me a hint what is going wrong. I am very grateful for any help.

python3 main.py

Traceback (most recent call last): File "/home/daniel/.local/lib/python3.9/site-packages/adafruit_bus_device/i2c_device.py", line 175, in __probe_for_device self.i2c.writeto(self.device_address, b"") File "/home/daniel/.local/lib/python3.9/site-packages/adafruit_tca9548a.py", line 80, in writeto return self.tca.i2c.writeto(address, buffer, **kwargs) File "/home/daniel/.local/lib/python3.9/site-packages/busio.py", line 203, in writeto return self._i2c.writeto(address, buffer, stop=stop) File "/home/daniel/.local/lib/python3.9/site-packages/adafruit_blinka/microcontroller/generic_linux/i2c.py", line 52, in writeto self._i2c_bus.write_bytes(address, buffer[start:end]) File "/usr/local/lib/python3.9/dist-packages/Adafruit_PureIO-1.1.11-py3.9.egg/Adafruit_PureIO/smbus.py", line 303, in write_bytes self._device.write(buf) OSError: [Errno 121] Remote I/O error

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/daniel/.local/lib/python3.9/site-packages/adafruit_bus_device/i2c_device.py", line 181, in __probe_for_device self.i2c.readfrom_into(self.device_address, result) File "/home/daniel/.local/lib/python3.9/site-packages/adafruit_tca9548a.py", line 74, in readfrom_into return self.tca.i2c.readfrom_into(address, buffer, **kwargs) File "/home/daniel/.local/lib/python3.9/site-packages/busio.py", line 193, in readfrom_into return self._i2c.readfrom_into(address, buffer, stop=stop) File "/home/daniel/.local/lib/python3.9/site-packages/adafruit_blinka/microcontroller/generic_linux/i2c.py", line 59, in readfrom_into readin = self._i2c_bus.read_bytes(address, end - start) File "/usr/local/lib/python3.9/dist-packages/Adafruit_PureIO-1.1.11-py3.9.egg/Adafruit_PureIO/smbus.py", line 170, in read_bytes return self._device.read(number) OSError: [Errno 121] Remote I/O error

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/daniel/SmartChessboard/src/main.py", line 47, in player = HardwareClient.HardwareClient(chess.WHITE) if successful_import else \ File "/home/daniel/SmartChessboard/src/Clients/HardwareClient.py", line 57, in init self._hwi: HardwareInterface = HardwareImplementation.HardwareImplementation() File "/home/daniel/SmartChessboard/src/Hardware/HardwareImplementation.py", line 37, in init mcp = [self._perform_safe(lambda i: MCP23017(tca[i], address=0x20))(i) for i in range(4)] File "/home/daniel/SmartChessboard/src/Hardware/HardwareImplementation.py", line 37, in mcp = [self._perform_safe(lambda i: MCP23017(tca[i], address=0x20))(i) for i in range(4)] File "/home/daniel/SmartChessboard/src/Hardware/SafeDecorator.py", line 35, in safe_wrapper return func(*args, **kwargs) File "/home/daniel/SmartChessboard/src/Hardware/HardwareImplementation.py", line 37, in mcp = [self._perform_safe(lambda i: MCP23017(tca[i], address=0x20))(i) for i in range(4)] File "/usr/local/lib/python3.9/dist-packages/adafruit_mcp230xx/mcp23017.py", line 69, in init super().init(i2c, address) File "/usr/local/lib/python3.9/dist-packages/adafruit_mcp230xx/mcp23xxx.py", line 39, in init self._device = i2c_device.I2CDevice(bus_device, address) File "/home/daniel/.local/lib/python3.9/site-packages/adafruit_bus_device/i2c_device.py", line 62, in init self.__probe_for_device() File "/home/daniel/.local/lib/python3.9/site-packages/adafruit_bus_device/i2c_device.py", line 184, in __probe_for_device raise ValueError("No I2C device at address: 0x%x" % self.device_address) ValueError: No I2C device at address: 0x20

WouterSchols commented 1 year ago

Ahhh you are even reusing my hardware implementation. I was expecting users to reimplement HardwareInterface.HardwareInterface. Since it is very difficult to get everything exactly the same on the same ports. Well anyway, it is a bit hard for me to diagnose your exact error given that I cannot see your hardware.

I have two takeaways for you. First the problem itself looks clear from the message "No I2C device at address: 0x20". From the stack trace we see that this originates when setting the buttons. In my code the buttons are on channel tca[5]. I suspect this is empty for you and this causes the error

However, takeaway is don't make too big of a step in one go. Trying to my hardware exactly sounds like the easiest but this will not help you in the long run. Make sure you test all the hardware in small steps. I would test every piece of hardware completely by itself. Once you can get it to work add it in the actual code. If you reimplement HardwareInterface.HardwareInterface yourself you will find and diagnose issues quickly. Just leave unfinished things turned off at first. You should not really need to change/reimplement any other code in my project.

Good luck and be sure to share the results

WouterSchols commented 1 year ago

I implemented your hardware project nearly the same using the tutorial. I do not see the MCPs using i2cdetect, but using some test code they are displayed via the TCA Multiplexer at x20 and the following addresses. What I want to say is, that the wiring should not be the problem. I get the following error and hope that you can give me a hint what is going wrong. I am very grateful for any help.

This statement worries me slightly. Just to be sure, do you understand what the multiplexer does? The multiplexer is a switch between i2c channels. Normally you have a 1 channel for i2c. i2cdetect scan this one channel. If you hook up everything to one channel then it will be too busy and things will break all the time. This is why we have the multiplexer, The multiplexer is a device you can talk to and which will forward your message to one of 8 other i2c channels. However you will need to send the message to the correct address and on the correct channel number. (You can have multiple devices at the same address as long as they are on different channels)

Dani18718 commented 1 year ago

Many thanks for the quick response. I adopted your hardware setup because you don't have to reinvent the wheel. In addition, the description of “chess-fortherapy” is also very good. But at the same time I have to correct myself when I said that I reused your whole setup because I haven't installed the buttons yet. If I understand you correctly, one of the reasons for the error is that the buttons cannot be found? Based on the error message, I would have thought that it was related to the MCPs. I've now experimented a bit with the code, but it turns out to be quite difficult and tedious if you only have moderate knowledge of Python. I'll stay tuned and get back to you. Thank you again

WouterSchols commented 1 year ago

The buttons themselves do not matter but the buttons are connected to an MCP. That needs to be there. I also have an MCP for a 9th row of LEDs. If you do not have that then you will need some changes there as well.

Medium python knowledge should be enough to implement the hardware but understanding my implementation can indeed be a bit tricky since I use some advanced tricks. I would advice reading this page carefully if you haven't yet https://wouterschols.github.io/SmartChessboard/_build/html/InterfaceImplementation.html.