kaluma-project / kaluma

A tiny JavaScript runtime for RP2040 (Raspberry Pi Pico)
https://kalumajs.org
Apache License 2.0
648 stars 38 forks source link

How to use SPI like in MicroPython ? #556

Closed AhmedM-Dev closed 1 year ago

AhmedM-Dev commented 1 year ago

I am trying to clone the MicroPython NRF24L01 (https://github.com/iottrends/NRF24l01_MicroPython/blob/main/nrf24l01.py) driver using KalumaJS.

My issue is that I could not replicate the exact behavior of spi.readinto using KalumaJS SPI interface.

Can someone guide me how to do it ?

communix commented 1 year ago

@AhmedM-Dev I checked the MicroPython spi.readinto function and I think it can be implemented by the spi.transfer() function of Kaluma.

image

Both function read and write the data through SPI. Here's the difference.

In this example, the self.buf = bytearray(1), that means it's one byte buffer, so spi.readinfo send and receive only one byte. Here's the code for Kaluma

Thanks.

AhmedM-Dev commented 1 year ago

@communix Thank you so much for your well explained reply. I will try to implement the nRF24L01 driver based on the MicroPython driver using your suggestion and send you feedback as soon as possible.

Thanks.