Module not working?

Posted on
  • I got an MPU6050, and I connected the wires based on what the doc for the module says. When I run my code, it seems like Espruino freezes (the command line in the IDE becomes unresponsive).

    Maybe I didn't connect the wires properly? I am using wires but no solder (see photo, the module is on bottom, the pins are fastened with the wires but not soldered). Maybe it really needs solder?

    Or if that should be good enough for prototyping, maybe there's something wrong in code or with the module? Here's my code:

    I2C1.setup({scl:B6,sda:B7});
    
    var MPU6050 = require("MPU6050");
    console.log(MPU6050);
    
    var mpu = MPU6050.connect(I2C1);
    
    setInterval(() => {
      console.log(
        '\nAcceleration:', mpu.getAcceleration(), // returns an [x,y,z] array with raw accl. data
        '\nGravity:', mpu.getGravity(),  // returns acceleration array in G's
        '\nRotation:', mpu.getRotation(), // returns an [x,y,z] array with raw gyro data
        '\nDegress per second:', mpu.getDegreesPerSecond() // returns gyro array in degrees/s
      );
    }, 1000);
    

    What are some steps I can take to diagnose the problem?


    1 Attachment

    • IMG_20170517_224505.jpg
  • No experience with the MPU6050 module here.
    Here are some I2C suggestions to try:

    Pullup resistors on the scl and sda lines are one thing to check.
    Does your MPU6050 breakout board provide these?
    Are the jumpers on the breakout board used to engage the pullup resistors?

    var MPU6050 = require("MPU6050");
    You might try
    var MM= require("MPU6050"); (and subsequent references to MPU6050 in your code)
    as the MPU6050 may already used by the module.

     I2C3.setup({ scl :A8, sda: B4} );
    //console.log(I2C3);
     var xgAddress= 0x6B;// Would be 0x1C if SDO_M is LOW
     var mAddress= 0x1e;// Would be 0x6A if SDO_AG is LOW 
     W=require("LSM9DS1").connect(I2C3,xgAddr­ess,mAddress);
    // W=new LSM9DS1(I2C3,xgAddress,mAddress);
     W.run();//Get it started
    

    For PICO
    //I2C1 sda=B7 scl=B6
    //I2C1 sda=B9 scl=B8 shim pins
    //I2C3 sda=B4 scl=A8
    //I2C2 sda=B3 scl=B10

  • ...since it is a @Gordon/node.js-classical-module-setup, global MPU6050 ('constructor') function is not exposed... in other words, your code is ok to use MPU6050 for the module (singleton) object returned by require(). The module object returned knows only .connect() - a function that then indeed invokes encapsulated/hidden MPU6050(...){...} with new and returns an "MPU6050" instance.

    I do not know the inner workings/details of the driver and the MPU650's behavior, but I would put the .connect(...) and setInterval(...) into an onInit() {...} function to have it also working when saved, disconnected and re-powered, because the - as said - the .connect...() creates the instance and calls initializations within the MPU6050 which for sure will not be saved within Espruino.

    Not soldered pins is not a good idea... (there are special pins that need no soldering but they are hard to use and often break the (thinner) breakout boards...).

    I may understand why you do not want to solder pins the standard way... Depending on how the pins are held in their plastic, you may just solder them in 'the other way round' without pushing them all the way in the the plastic touches the board. After solidly soldering them in, you can remove the plastic by preying gently multiple times on multiple locations. If you are then done with prototyping and you want to solder wires directly (or other final connections), you can take off pin by pin easily.

  • MPU6050 Try this code
    function start(){
    I2C1.setup({scl:B6,sda:B7});
    var mpu = require("MPU6050").connect(I2C1);
    
    setInterval(() => {
      console.log(
        '\nAcceleration:', mpu.getAcceleration(), // returns an [x,y,z] array with raw accl. data
        '\nGravity:', mpu.getGravity(),  // returns acceleration array in G's
        '\nRotation:', mpu.getRotation(), // returns an [x,y,z] array with raw gyro data
        '\nDegress per second:', mpu.getDegreesPerSecond() // returns gyro array in degrees/s
      );
    }, 1000);
    
    }//end start
    
    //Wait for program to load
    setTimeout(function () {
     start();
    }, 1000);
    

    Without an MPU6050 connected to the PICO I get the following:

    1v92 Copyright 2016 G.Williams
    >
    =undefined
    Uncaught InternalError: Timeout on I2C Write Transmit Mode 2
     at line 1 col 29
    this.i2c.writeTo(this.addr,a);return this.i2c.readFrom(this....
                                ^
    in function "readBytes" called from line 1 col 25
    var g=this.readBytes(a,1)[0],h=(1<<b)-1<<c-b­+1,g=g&~h|d<<c-b...
                            ^
    in function "writeBits" called from line 2 col 41
    d.PWR1_CLKSEL_BIT,d.PWR1_CLKSEL_LENGTH,a­)
                                            ^
    in function "setClockSource" called from line 1 col 38
    ...ockSource(d.CLOCK_PLL_XGYRO);this.set­FullScaleAccelRange(d.A...
                                  ^
    in function "initialize" called from line 1 col 103
    ...AD0_HIGH:c;this.initialize()
                                  ^
    in function "b" called from line 1 col 10
    new b(a,c)
             ^
    in function "connect" called from line 3 col 42
    var mpu = require("MPU6050").connect(I2C1);
                                             ^
    in function "start" called from line 1 col 7
    start();
          ^
    in fun
    

    Please try it with your chip connected.
    As for the connections, I use similar prototype connections for testing. For long term reliability soldered connections are the best. Loose connections cause headaches.

  • Also, just checking, but do you have up to date firmware? Some older versions had some bugs in the ES6 function implementation that could have caused a crash for arrow functions.

    Generally Espruino should never crash such that Ctrl-C won't break out of whatever is running.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Module not working?

Posted by Avatar for trusktr @trusktr

Actions