UNIHIKERGeneral

How to resolve SPI error when using unihiker?

userHead LL 2024-01-18 04:40:09 753 Views3 Replies

How to resolve SPI error when using unihiker?
I'm experiencing several problems when trying to control the SPI with a unihiker board using pinpong library versions v0.5.1 or v0.5.2. Below are the issues I'm facing:


Question 1:
```
Traceback (most recent call last):
 File "/root/mindplus/cache/new-project-2024-1-17-19-51-22.mp/spi.py", line 2, in <module>
   from unihiker.board import Board, Pin, SPI
ModuleNotFoundError: No module named 'unihiker.board'
```

Question 2:
```
Traceback (most recent call last):
 File "/root/mindplus/cache/new-project-2024-1-17-19-51-22.mp/spi.py", line 8, in <module>
   spi0 = SPI(0, cs=Pin.P3)
 File "/usr/local/lib/python3.7/dist-packages/pinpong/board.py", line 665, in __init__
   self.board.spi[bus_num][device_num] = eval(self.board.res["spi"]["class"]+"(bus_num, device_num)")
 File "<string>", line 1, in <module>
TypeError: __init__() missing 1 required positional argument: 'cs'

```

 

Question 3:
```
Traceback (most recent call last):
 File "/root/mindplus/cache/new-project-2024-1-17-19-51-22.mp/spi.py", line 8, in <module>
   spi0 = SPI(1, cs=Pin.P3)
 File "/usr/local/lib/python3.7/dist-packages/pinpong/board.py", line 664, in __init__
   raise ValueError("spi does not support this device", spi_num, "List of supported spi devices",self.board.res["spi"]["busnum"])
ValueError: ('spi does not support this device', (1, 1), 'List of supported spi devices', [(0, 0)])

```
 

2024-01-18 04:44:51

Issue 1 is caused by a programming error, the correct code should be: ```from pinpong.board import Board, Pin, SPI```

Issues 2 and 3 are due to errors in the code within the pinpong library. The files "/usr/local/lib/python3.7/dist-packages/pinpong/extension/unihi.py" and "/usr/local/lib/python3.7/dist-packages/pinpong/board.py" need to be modified. After the modifications, it should appear as shown in the following figure:

userHeadPic LL
LL wrote:
2024-01-18 04:44:57
LL wrote:

 

"busnum" : [(0,0),(1,1)],

self.board.spi[bus_num][device_num] = eval(self.board.res["spi"]["class"]+"(board, device_num, cs)")

 

2024-01-18 23:23:50
2 Replies