kaluma-project / kaluma

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

Issue with I2C -- not sure what I'm doing wrong #580

Closed alexander-daniel closed 1 year ago

alexander-daniel commented 1 year ago

I've got:

const { I2C } = require("i2c");

const i2c = new I2C(0);

i2c.write(new Uint8Array(0x01, 0x02) , 0x48);

IMG_5865

I get an Error: Operation Not Permitted message from Kaluma Shell.

I paired this example down as much as I could. I've gotten other i2c devices working, so maybe it's this one?

Originally posted by @alexander-daniel in https://github.com/kaluma-project/kaluma/discussions/518#discussioncomment-5983809

communix commented 1 year ago

@alexander-daniel I quickly check the code and found that Kaluma return Error: Operation Not Permitted if there's no response from the I2C slave. If you can check the I2C signal through scope or logic analyzer, you can check it and share it.

I think you use PN532 board and it seems to use 5V input and 5V I2C interface. please check the actual board specification. https://electropeak.com/learn/interfacing-pn532-nfc-rfid-reader-writer-module-i2c-spi-with-arduino/

If PN532 board need 5V input and 5V I2C interface, I2C communication may failed with Pico board because Pico board support 3.3V I2C interface.

alexander-daniel commented 1 year ago

Ah, that would make sense. These chips sometimes don't come with the clearest of documentation. There was a line about some level shifting, but it seems what you're saying makes sense! Thank you for tracing the error down to that, I needed this sanity check after trying to debug this :P

Thank you!