-
@allObjects haha! That was my thought too. I can read temp and pressure accurately if I leave out altitude, and that is what I really need. When I get a chance I will dig a bit more into the module (https://github.com/espruino/EspruinoDocs/blob/master/devices/MPL3115A2.js).
Thanks for all the help. If anyone has any other ideas that would be great.
-
-
Am I to understand then, that only accurate data is obtained when L14-L17 are commented out?
That is correct.I made the interval 10s and added as much as a 2s timeout between the different reading with the same results.
I am not using any pull-ups on the i2c connection.
Everything is grounded.I tried reordering the functions and got some different results. I found that it doesn't matter where the temp reading is, but it can't read altitude and pressure (no matter which callback is first), or one of them will come up with crazy numbers. Also, the first reading is always off.
I am under the impression that the sensor uses the pressure and temp to estimate the altitude.
-
I am using a MDBT42Q breakout. It is on a breadboard. The MDBT42Q and the MPL3115A2 are powered with 5v. The screen does work. I was getting the same readings when it wasn't in the mix. The MPL3115A2 is from Adafruit.
I have refactored my code to this (with the same result):
var i2c = new I2C(); I2C1.setup({scl: D20, sda: D22}); i2c.setup({sda:D30,scl:D29}); var mpl = require("MPL3115A2").connect(i2c); var lcd = require("HD44780").connectI2C(I2C1, 0x3F); lcd.setCursor(0, 0); lcd.print("Starting..."); const onInit = ()=> { setInterval(() => { mpl.getPressure(function(x) { console.log("Pressure "+x+" pa"); mpl.getAltitude(function(x) { console.log("Altitude "+x+" m"); mpl.getTemperature(function(x) { console.log("Temperature "+x+" C"); }); }); }); }, 5000); }; setTimeout(onInit, 3000);
Per @allObjects I changed it so that I was only reading pressure. When I do that, the readings are 100066, and that is really close to the Arduino.
-
I am delaying the code. Here is what I have. There is also a display hooked up.
var i2c = new I2C(); I2C1.setup({scl: D20, sda: D22}); i2c.setup({sda:D30,scl:D29}); var mpl = require("MPL3115A2").connect(i2c); var lcd = require("HD44780").connectI2C(I2C1, 0x3F); lcd.setCursor(0, 0); lcd.print("Starting..."); setTimeout(() => { setInterval(() => { mpl.getPressure(function(x) { console.log("Pressure "+x+" pa"); mpl.getAltitude(function(x) { console.log("Altitude "+x+" m"); mpl.getTemperature(function(x) { console.log("Temperature "+x+" C"); }); }); }); }, 5000); }, 1000);
-
I am getting some odd reading from this sensor using the Espruino module (https://www.espruino.com/MPL3115A2).
When I run the example code, I get these reading:
Pressure 442.25 pa Altitude 110.125 m Temperature 17.6875 C
If I run the sam sensor hooked to an Arduino board, I get these readings:
100158.25 P 97.50 M 15.69 C
The Arduino readings seem to be correct.
Any ideas?
-
Right. What I meant was that I thought I tried 0x3F for the address using hardware I2C (without var i2c = new I2C();).
I realized the var names were different when using i2c = new I2C(); and changed them. This resulted in no errors, but the screen did not work. This of course was because the address was wrong.
-
-
Thank you so much for the responses! I am just now back at a computer to post this.
I just realized that these are 5v. I have two of the same screens and backpacks.I have checked the connection many time, and I just tried flipping the pins.
Here is my code.
var i2c = new I2C(); I2C1.setup({scl:D28, sda:D29}); var lcd = require("HD44780").connectI2C(I2C1); lcd.print("Hello World!");
I have tried with and without "var i2c = new I2C();"
When I run:
getPinMode(pin)
I get "input_pullup" for both pins. That doesn't seem right -
I feel like I am really missing something here. I have a 1602 display with an ic2 backpack. I am connecting it to a MDBT42Q Breakout, and using this doc: http://www.espruino.com/HD44780
I have tried different pins. I have also added pull up resistors from vcc (5v) to scl and sda
Here is the error I get. ...
>Uncaught InternalError: I2C Write Error 33281 at line 2 col 13 g|4,g|4,g,g]) ^ in function "a" called from line 1 col 7 a(51,1);a(50,1);a(40,1);a(12,1);a(6,1);a(1,1);return{write:a... ^ in function "h" called from line 2 col 15 g|4,g|4,g,g])}) ^ in function "connectI2C" called from line 2 col 45 var lcd = require("HD44780").connectI2C(I2C1); ^ Uncaught Error: Cannot read property 'print' of undefined at line 3 col 4 lcd.print("Hello World!"); ^
-
-
Oh and thank you @MaBe You have helped me with every question I have posted!
-
-
-
I have been working on this project on and off over the past year, and I finally got it finished! I am supper proud of the way it all turned out! I know I could have made the code a lot better if I used an official board that had better analog support.
Thanks to everyone that has helped me on the forms. This is my first project with Espruino.
You can check out the video for the project here:
https://youtu.be/w2Xx-gGuJ1A
Here are some pics:
-
-
-
When I try to change a pin's mode inside a setInterval after a number of loops Espruino hangs.
For example:var count = 0; const onInit = () => { var loop = setInterval(() => { if (count === 1000) { digitalWrite(1, 0); } console.log('foo', count); count = count + 1; }, 5); setTimeout(function() { clearInterval(loop); console.log("foobar"); }, 10000); }; setTimeout(onInit, 1000);
It will turn the pin off and log
foo 999
. It will never logfoobar
.The odd thing is that I can create a blink loop with setInterval like this:
var state = 0; const onInit = () => { var loop = setInterval(() => { digitalWrite(1, state); console.log('foo', state); state = !state; }, 500); }; setTimeout(onInit, 1000);
Any help would be great!
-
-
Yes it is working now. After I used this...
esptool.py --port /dev/tty.SLAB_USBtoUART --baud 115200 write_flash --flash_freq 80m --flash_mode qio --flash_size 4MB-c1 0x0000 boot_v1.6.bin 0x1000 espruino_esp8266_user1.bin 0x3FC000 esp_init_data_default.bin 0x3FE000 blank.bin
...it started working.
One difference is that I had to change the baud from 460800 to 115200.
Thank you so much for your help. I'm still not sure how this fixed the
wifi.save()
issue. -
-
-
So I should have been running this...
esptool.py --port /dev/tty.SLAB_USBtoUART --baud 115200 write_flash --flash_freq 80m --flash_mode qio --flash_size 32m 0x0000 "boot_v1.6.bin" 0x1000 espruino_esp8266_user1.bin 0x3FC000 esp_init_data_default.bin 0x3FE000 blank.bin
This got the board working again.
It still goes nuts and I have to re-flash when I runwifi.save()
and reboot.
I am not sure if this is a good idea or not, but I just removed thewifi.save()
and moved the wifi connect to the onInit function and it works on reboot. Is there something wrong with doing this?Thanks for all of your help by the way!
-
That looks sweet! I'll look into i. Thanks