-
• #2
Can you confirm which version of espruino you're using on which board?
What is the value of the pull-up resistors you have connected to the two i2c lines? -
• #3
The pull-ups for SDA and SCL have 2.2k.
I tried with two different pico boards (1v84) - same result. Next I will check the original board. -
• #4
Ooh, it works with the original Espruino board:
I2C1.setup( { scl: B6, sda: B7 } ); function start() { I2C1.writeTo( { address: 0x5a, stop: false }, 0x06 ); var d = I2C1.readFrom( 0x5a, 3 ); var temp = ((d[1] << 8) + d[0]) * 0.02 - 273.15; // formula from datasheet console.log( "Temperature = " + temp + "°C" ); } setTimeout( start, 250 ); // Sensor available 1/4 sec after POR
Are the boards different related to the power supply or the i2c setup?
-
• #5
Wow, that looks like a very cool sensor!
That's odd - the boards should be the same. You're using up to date firmware on both? The default I2C clock speed is 50000 (but it could be different on earlier firmwares) - it could be something that trips up the module.
One thing that will get you is that on the Pico, B6 and B7 are used for the Serial console when USB isn't connected - so on initialisation they are set up as a Serial port. I guess they might end up getting pulled low at times and that could confuse the module?
Maybe try something else - B4 and A8 on I2C3, and see if you have any more luck?
-
• #6
Yay, it works with
I2C3.setup( { scl: A8, sda: B4 } );
on the pico. Thank you!!I've checked the other I2C-pins too:
I2C1.setup( { scl: B6, sda: B7 } ); // not working
2.I2C1.setup( { scl: B8, sda: B9 } ); // not working
3.I2C2.setup( { scl: B10, sda: B3 } ); // working
4.I2C3.setup( { scl: A8, sda: B4 } ); // working
But USB is always connected. Is there really no difference between I2C1 and the I2C2 or I2C3?
-
• #7
Strange... but it does work intermittently? There are minor differences in the hardware, but Espruino tries quite hard to avoid them. I've definitely used I2C1 - in fact just earlier this week with a display - and it worked fine.
Currently I'm developing an Espruino module for MLX90614 - an infra red thermometer I2C sensor.
https://learn.adafruit.com/using-melexis-mlx90614-non-contact-sensors/overview
It's nearly complete but I have strange problems with the initialisation. I figured out that the sensor always works when the power supply will be switched on after I2C1.setup(..)-call. So I have connected Vin of the sensor with B3 to simulate switching on/off programmatically.
The following code works without any problems:
But now strange things happen. The following code works only one or two times after connecting the USB cable and then never again.
Instead of
Temperature = 22.37°C
an exception is thrown:I have no ideas anymore how to find the cause. I don't have a memory oscilloscope and can't say what happens during "I2C1.setup(..)".
Does anybody have an idea how I could continue...?