dModule is not defined (LIS2DH12)

I am trying to access accelerometer with Espruino, but when I import module Ruuvitag var Ruuvitag = require("Ruuvitag"); this error occurs:

>Uncaught ReferenceError: "dModules" is not defined
  at line 1 col 10
  1dModules.addCached("LIS2DH12","function f(c,a,d){this.r=c;t...

Ruuvitag is flashed to the latest firmware.

Hello,

Can you give your Espruino console log? You can find it in settings, gear icon in top-right corner

Sure.

Sent
loadModule(Ruuvitag)

 - Ruuvitag requires ["LIS2DH12","BME280"]
    Queueing LIS2DH12
loadModule(LIS2DH12)
   Queueing BME280
loadModule(BME280)
 - LIS2DH12 requires []
- BME280 requires []
  Found a prompt... great!

Sending…
—> “\u0010reset();\n\u0010Modules.addCached("BME280","function f(a,b,c){this.read=b;this.write=c;this.write(242,1);this.write(244,39);this.write(245,160);this.readCoefficients()}function d(a,b){var c=(a[b+1]<<8)+a[b];c&32768&&(c-=65536);return c}f.prototype.setPower=function(a){this.read(244,1)};f.prototype.readCoefficients=function(){var a=new Uint8Array(32);a.set(this.read(136,24),0);a.set(this.read(161,1),24);a.set(this.read(225,7),25);this.dT=[,a[1]<<8|a[0],d(a,2),d(a,4)];this.dP=[,a[7]<<8|a[6],d(a,8),d(a,10),d(a,12),d(a,14),d(a,16),\nd(a,18),d(a,20),d(a,22)];this.dH=[,a[24],d(a,25),a[27],a[28]<<4|15&a[29],a[30]<<4|a[29]>>4&15,a[31]]};f.prototype.readRawData=function(){var a=this.read(247,8);this.pres_raw=a[0]<<12|a[1]<<4|a[2]>>4;this.temp_raw=a[3]<<12|a[4]<<4|a[5]>>4;this.hum_raw=a[6]<<8|a[7]};f.prototype.calibration_T=function(a){var b,c=this.dT;b=(a/16384-c[1]/1024)c[2];a=(a/131072-c[1]/8192)(a/131072-c[1]/8192)c[3];this.t_fine=b+a;return(b+a)/5120100};f.prototype.calibration_P=function(a){var b,c,e=this.dP;b=this.t_fine/\n2-64E3;c=bbe[6]/32768;c+=be[5]2;c=c/4+65536e[4];b=(e[3]bb/524288+e[2]b)/524288;b=(1+b/32768)e[1];if(0===b)return 0;a=6250(1048576-a-c/4096)/b;b=e[9]aa/2147483648;c=ae[8]/32768;return a+=(b+c+e[7])/16};f.prototype.calibration_H=function(a){var b,c=this.dH;b=this.t_fine-76800;b=((a<<14)-(c[4]<<20)-c[5]b+16384>>15)((((bc[6]>>10)((bc[3]>>11)+32768)>>10)+2097152)c[2]+8192>>14);b-=((b>>15)(b>>15)>>7)*c[1]>>4;b=Math.clip(b,0,419430400);return b>>12};f.prototype.getData=function(a){this.readRawData();\nreturn{temp:this.calibration_T(this.temp_raw)/100,pressure:this.calibration_P(this.pres_raw)/100,humidity:this.calibration_H(this.hum_raw)/1024}};exports.connect=function(a,b){return new f(b,function(b,e){a.writeTo(118,b);return a.readFrom(118,e)},function(b,e){a.writeTo(118,[b,e])})};exports.connectSPI=function(a,b,c){return new f(c,function(c,d){new Uint8Array(d+1);return a.send([c|128,new Uint8Array(d)],b).slice(1)},function(c,d){a.write(c&127,d,b)})}");\n\u0010\u001b[-1dModules.addCached("LIS2DH12","function f(c,a,d){this.r=c;this.w=a;this.options=d||{};this.callback=this.options.callback;if(this.r(b.WHO_AM_I,1)[0]!=b.I_AM_MASK)throw\"LIS2DH12 WHO_AM_I check failed\";this.g_scale=b.SCALE2G;this.mode=\"powerdown\";this.interval=void 0}var b={WHO_AM_I:15,CTRL_REG1:32,CTRL_REG2:33,CTRL_REG3:34,CTRL_REG4:35,STATUS_REG:39,OUT_X_L:40,I_AM_MASK:51,ODR_MASK_1HZ:16,ODR_MASK_10HZ:32,ODR_MASK_25HZ:48,ODR_MASK_50HZ:64,ODR_MASK_100HZ:80,ODR_MASK_200HZ:96,ODR_MASK_400HZ:112,ODR_MASK_1620HZ:128,ODR_MASK_HIGH_RES:144,\nLPEN_MASK:8,XYZ_EN_MASK:7,HR_MASK:8,SCALE2G:0,SCALE4G:1,SCALE8G:2,SCALE16G:3};f.prototype.setPowerMode=function(c){var a=b.XYZ_EN_MASK,d=this.g_scale<<4,e=0;switch(c){case \"normal\":a|=b.ODR_MASK_100HZ;this.g_mgpb=4<<this.g_scale;e=10;break;case \"low\":a|=b.ODR_MASK_1HZ;this.g_mgpb=4<<this.g_scale;e=1E3;break;case \"fast\":a|=b.ODR_MASK_1620HZ|b.LPEN_MASK;this.g_mgpb=16<<this.g_scale;e=1;break;case \"highres\":a|=b.ODR_MASK_HIGH_RES;d|=b.HR_MASK;this.g_mgpb=1<<this.g_scale;e=1;break;case \"powerdown\":e=\na=0;break;default:throw\"Unknown power mode \"+JSON.stringify(c);}this.w(b.CTRL_REG1,a);this.w(b.CTRL_REG4,d);this.mode=c;this.interval&&clearInterval(this.interval);this.interval=void 0;e&&this.callback&&(this.interval=setInterval(function(a){a.callback(a.getXYZ())},e,this))};f.prototype.getXYZ=function(){var c=new DataView((new Uint8Array(this.r(b.STATUS_REG,7))).buffer),a=1/(16<<this.g_scale)*1E3/1024;return{x:c.getInt16(1,!0)*a,y:c.getInt16(3,!0)*a,z:c.getInt16(5,!0)*a,\"new\":0!=(c.getUint8(0)&8)}};\nf.prototype.readXYZ=function(c){var a=\"powerdown\"==this.mode,b=this.callback;this.callback=function(e){a&&this.setPowerMode(\"powerdown\");this.callback=b;c(e)};a&&this.setPowerMode(\"normal\")};exports.connectSPI=function(c,a,b){if(\"function\"==typeof b)throw Error(\"Use require(LIS2DH12).connectSPI(…, {callback:function() { … }} instead\");return new f(function(b,d){return c.send([b|192,new Uint8Array(d)],a).slice(1)},function(b,d){return c.write(b,d,a)},b)};exports.connectI2C=function(b,a){var c=\na&&a.addr||25;return new f(function(a,d){b.writeTo(c,a|128);return b.readFrom(c,d)},function(a,d){b.writeTo(c,a,d)},a)}");\n\u0010\u001b[0dModules.addCached("Ruuvitag","function d(){a||(a=!0,b.setup({mosi:D25,miso:D28,sck:D29}),exports.accel=require(\"LIS2DH12\").connectSPI(b,D8),exports.env=require(\"BME280\").connectSPI(b,D3),exports.env.setPower(0))}var a=!1,b=new SPI;E.on(\"init\",function(){a=!1;exports.accel=void 0;exports.env=void 0});exports.setEnvOn=function(c){d();exports.env.setPower(c)};exports.setAccelOn=function(c,a){d();exports.accel.setPowerMode(c?\"low\":\"powerdown\");exports.accel.callback=a};exports.getEnvData=function(a){return exports.env.getData()};\nexports.getAccelData=function(a){return exports.accel.getXYZ()}");\n\u0010\u001b[16dvar Ruuvitag = require("Ruuvitag");\n\n”
Splitting for reset(), delay 250
Splitting for Modules.addCached, delay 250
Splitting for Modules.addCached, delay 250
Splitting for Modules.addCached, delay 250
Sent

Edit:
I tried this with another Ruuvitag, same problem

I’m wondering if the delay in Modules.addCached would be a reason for the error. Can you try adding a second or two before calling the accelerometer?

var Ruuvitag = require(“Ruuvitag”);
Ruuvitag.setEnvOn(true);
Ruuvitag.setAccelOn(true);
var on = false;
setInterval(function() {
on = !on;
LED1.write(on);
console.log(Ruuvitag.getEnvData());
// prints { “temp”: 23.70573815741, “pressure”: 1017.27733597036, “humidity”: 42.0771484375 }
console.log(Ruuvitag.getAccelData());
}, 1500);

for example uses setInterval to give 1.5 seconds before sensors are used

Same thing happens…

image

I’m getting the exact same error on previously good tag and program, so I’d assume something has broken in Espruino IDE. I’ll see if there would be a way to run a previous version of the IDE

I tried the code on previous version of the IDE, same error occured. I posted a question about this on Espruino forums, we’ll see if they would have a fix.

Great thank you, I really appreciate your help.

I tried playing around with a ruuvi tag and espruino for the first time today, and I think I’m getting this issue too.