z3ugma
01/01/2025, 11:27 PMWire library, I get exactly what I expect. Here's the code comparison between the two of them.
See the attachment for the box highlighted in Red - that's the Toit script causing the chip to misbehave.
With toit, I always get exactly whatever the first value I read from the chip. With Arduino I can read different registers without issue.
I am starting to suspect it may come down to the default state of GPIO pins, one system having it high and the other having it low, or something.
I have a logic analyzer, an ESP32 dev kit WROOM-32D
https://cdn.discordapp.com/attachments/1324156979479838791/1324156981329788979/image.png?ex=677720c9&is=6775cf49&hm=a7be63e7e325383fd8c54919d587a3a90527a9df3957fadcd14d2c48cf3a5d15&z3ugma
01/01/2025, 11:27 PMimport gpio
import i2c
bus := i2c.Bus
--sda=gpio.Pin 16
--scl=gpio.Pin 26
--frequency=80_000
device := bus.device 0x57
a0 := gpio.Pin 14 --output
motion := gpio.Pin 27 --input
// clock := gpio.Pin 26 --output
// iodev := gpio.Pin 16 --output
shutdown := gpio.Pin 17 --output
nrst := gpio.Pin 22 --output
vddio := gpio.Pin 21 --output
//For TWI:
// 1. Apply power. Refer timing diagram on power up
// sequence below.
// 2. Set SHTDWN and IO_SELECT pin low.
// 3. Set A0 and A1 according to the desired TWI slave
// address (from TWI slave address table in datasheet).
// 4. Drive NRST pin low then high. TWI slave address will
// only be valid and according to the address set in step
// 3 after a NRST toggle is applied.
// 5. Read Product ID (PID) to ensure sensor is powered up
// and communicating properly with host.
// 6. Write 0xE4 to address 0x60
// 7. Write 0xC9 to address 0x61
main:
shutdown.set 0
a0.set 1
vddio.set 1
// Drive NRST low, then high
nrst.set 0 // Do this last to turn on the chip?
sleep --ms=80
nrst.set 1
sleep --ms=10
// 6. Write 0xE4 to address 0x60
// 7. Write 0xC9 to address 0x61
// Read Product ID (PID) to ensure sensor is powered up
// and communicating properly with host.
device.write-reg 0x60 #[0xE4]
device.write-reg 0x61 #[0xC9]
value2 := device.read-reg 0 1
print value2
sleep --ms=50
value := device.read-reg 0x3f 1
print value
sleep --ms=10
sleep --ms=2000
print "Done"
device.closefloitsch
01/01/2025, 11:29 PMz3ugma
01/01/2025, 11:29 PMz3ugma
01/01/2025, 11:31 PMz3ugma
01/01/2025, 11:31 PMfloitsch
01/01/2025, 11:32 PMz3ugma
01/01/2025, 11:34 PMfloitsch
01/01/2025, 11:34 PMfloitsch
01/01/2025, 11:35 PMfloitsch
01/02/2025, 3:06 PMz3ugma
01/02/2025, 4:21 PMz3ugma
01/02/2025, 4:21 PMfloitsch
01/02/2025, 4:22 PMfloitsch
01/02/2025, 4:22 PMz3ugma
01/02/2025, 4:22 PMfloitsch
01/02/2025, 4:23 PMfloitsch
01/02/2025, 4:23 PMz3ugma
01/02/2025, 4:23 PMVDDIO IO supply voltage or the VDDA analog supply voltagefloitsch
01/02/2025, 4:24 PMfloitsch
01/02/2025, 4:25 PMfloitsch
01/02/2025, 4:27 PMz3ugma
01/02/2025, 4:28 PMz3ugma
01/02/2025, 4:28 PMfloitsch
01/02/2025, 4:29 PMz3ugma
01/02/2025, 4:29 PMfloitsch
01/02/2025, 4:29 PM--output) they are floating.z3ugma
01/02/2025, 4:29 PMz3ugma
01/02/2025, 4:30 PMfloitsch
01/02/2025, 4:30 PM--value=... to set the start value.floitsch
01/02/2025, 4:31 PMa0 is probably the most likely candidate.floitsch
01/02/2025, 4:31 PMfloitsch
01/02/2025, 4:32 PMfloitsch
01/02/2025, 4:32 PMvddio.set 1)floitsch
01/02/2025, 4:33 PMfloitsch
01/02/2025, 4:33 PM