Closed edgarbjorntvedt closed 4 years ago
Debugged the i2c communication and found the error in my own code. The difference between the apis is that the Espruino api is an async api. The Arduino api is synchronous. So here is the updated working code for Espruino:
var i2c = new I2C();
i2c.setup({sda:NodeMCU.D2, scl:NodeMCU.D1});
digitalWrite(new Pin(NodeMCU.D3), 0);
var ads = new ADS1X15(i2c);
ads.setGain(6144); // +/- 0.256mV
var v1, v2,v3,v4;
console.log('Espruino version');
setInterval(function() {
ads.getADC(0, function(val) {
v1 = val;
ads.getADC(1, function(val) {
v2 = val;
ads.getADC(2, function(val) {
v3 = val;
ads.getADC(3, function(val) {
v4 = val;
console.log(v1, v2,v3,v4);
});
});
});
});
}, 500);
Nice - thanks for the update and closing the issue :)
channel 0 and 3 is working as expected, but channel 1 is mirroring channel 0 and channel 2 is mirroring channel 3
To verify that it is a software issue in Espruino/ADS1x15.js, I have created an identical version of the code in Arduino, which is working as expected and according how I moved the analog potentiometers. Therefore the Arduino version can be considered a good reference.
Im using NodeMCU/ESP8266, with ADS1115. My hardware setup is almost following the schema in the image, except that ADDR is connected to D3 on NodeMCU which I have set to LOW in code. I've also connected 4 potentiometers to the 4 channels:
When running the two tests, I tried to move the potentiometers identical. One test run for Arduino version and one for Espruino version. The outputs is showing the error described above.
Please let me know if I've missing something in my test setup.