does MPU6050_DMP module work on Puck?

Posted on
  • I'm able to use the MPU6050 module correctly on my Puck

    I2C1.setup({scl:D2, sda:D1, bitrate:100000});
    const MPU = require("MPU6050").connect(I2C1);

    But if I then add the MPU6050_DMP,
    var DMP = require("MPU6050_DMP").create(MPU,3);

    New interpreter error: LOW_MEMORY,MEMORY
    Uncaught Error: Function "initialize" not found!
    at line 1 col 33
    in function "b" called from line 1 col 10
    new b(a,d)
    in function "create" called from line 1 col 46
    var DMP = require("MPU6050_DMP").create(MPU,3);
    Uncaught SyntaxError: Got '?' expected EOF
    at line 1 col 1

    Does anyone know if the MPU6050_DMP works on Puck? Am I just running out of memory? Is there a workaround to get this module loaded onto Puck? Thanks

  • Are you already have "Save on send" checked in the Espruino Web IDE Communication Settings?

    In addition, add the onInit() method and put the connect in there.

    This helped me - in my case - over some memory issues.

  • MPU6050_DMP is a large module even min version is about 11KB. Not sure if this will work on a Puck.

  • It's possible it is a bit tight, but to give it a fighting chance try:

    • Enable Modules uploaded as functions in communications settings
    • Set 'Save on Send' to To Flash (execute code at boot)

    That way you end up with the code executed from flash memory, which should help with RAM usage.

  • Thanks @Gordon, with those settings MPU6050_DMP now works on my Puck

  • Unfortunately, I must have caused a problem with my flash, and I need help returning to a stable state. After a hard 10 second reset, I can connect my puck in the IDE, then with the same connection settings as above, I send the following code to my Puck:

    I2C1.setup({scl:D2, sda:D1, bitrate:100000});
    const MPU = require("MPU6050").connect(I2C1);
    var DMP = require("MPU6050_DMP").create(MPU,3);
    function getData() {
      var data = DMP.getData();
      if(data !== undefined) console.log(data);
    setInterval(getData, 1000);

    This code worked yesterday, but now I'm seeing an error:

    Uncaught InternalError: Timeout on jshFlashWrite
    at line 1 col 1078
    New interpreter error: FIFO_FULL

    Then I get a red bar
    Prompt not detected - upload failed. Trying to recover...

    and nothing else.. any advice?

  • Mostlikely, your modules has some initialization that has to happen... and you try not to save active things (intervals, timeouts, watches, etc, even though @Gordon did a great job to restore them as good as possible). I'm also a bit puzzled about your use of const and var for the very same thing...

    Place 'all active stuff' into a onInit() function - ESPECIALLY with Save on send setting and to avoid (heavy) things getting off on upload (starting heavy things on upload and writing to console in upload - level 0 / directly executed code messes even with the upload to not complete it or preventing Espruino to detect completion of upload. --- I expect this to solve the issues):

    I2C1.setup({scl:D2, sda:D1, bitrate:100000});
    var MPU, DMOP, iId;
    function getData() {
      var data = DMP.getData();
      if(data !== undefined) console.log(data);
    onInit() {
      MPU = require("MPU6050").connect(I2C1);
      DMP = require("MPU6050_DMP").create(MPU,3);
      iId = setInterval(getData, 1000);

    You may also be fine with:

    I2C1.setup({scl:D2, sda:D1, bitrate:100000});
    var mpu, mpuM = require("MPU6050")
      , dmp, dmpM = require("MPU6050_DMP")
      , iId;
    function getData() {
      var data = dmp.getData();
      if(data !== undefined) console.log(data);
    onInit() {
      mpu = mpuM.connect(I2C1);
      dmp = dmpM.create(mpu,3);
      iId = setInterval(getData, 1000);
  • Don’t miss to call onInit() or save() 😉

  • I don't know the data coming from DMPU... could you post a console output?

  • I'm struggling to get my Puck back to a stable state. If I just send the following:

    I2C1.setup({scl:D2, sda:D1, bitrate:100000});
    const MPU = require("MPU6050").connect(I2C1);

    The ide shows " Prompt not detected - upload failed. Trying to recover..." and then never seems to recover.

    I think I need a way to clear out or factory reset the flash memory. I've tried running reset() followed by save(), but that doesn't fix it.

    Also the web ide won't connect to my Puck unless I do a hard reset first.

  • Try reset(true)

  • The upload process is time sensitive: the IDE sends stuff to the Espruino board, Espruino board interprets it and responds back for the next junk. Espruino is a totally different architecture than you may be used to from other microcontroller setups, such as Arduino, to name an example. Even though some time has passed since the conversation about simple explanation how to save code that Espruino run on start? and Espruino got much more powerful, robust and resilient, the architecture has not changed.

  • I'd like to be a bit more specific about the general type of upload vs. the various kinds of uploads in Espruino context.

    The general type of upload is to move bytes from a source environment storage to a destination environment storage. On both source and destination sides, a simple read and write tooling is in place that just reads the bytes and puts them on the line or gets them from the line and just writes them - without any serious transformation - like a file transfer. If the 'file transfer' has some smartness, it knows about the data type and may do some formal conversion, such as a character set conversion, endian conversion, etc.

    Any conversion though is the begin of heating the water and because it is gradually, it will boil the frog - what ever that 'boiling the frog' means and manifests itself in... for example with: New Interpreter Interruption / Stack Overflow / Out Of Memory / Fifo Full / ... because of: see next paragraph.

    In Espruino, neither side's tooling - source-reading-sending nor destination-receiving-storing - is simple.

    On source side it is parsing code in nested, recursive manner to find all - not Espruino firmware built-in, involved modules and upload them to and store them either as source code or function in the Modules cache or flash EEPROM before uploading the actual root / level 0 code / IDE editor pane code - the code that is stored in the projects folder. The parsing is recursive because not only the 'project' / level-0 / project code can contain require(), but also modules can contain it.

    On destination side the code goes thru the interpreter which does some parsing and processing as well - depending wether it is project and module code, and when latter wether to store it as straight source code or as function. If that processing gets too heavy, the upload process may fail. While all code code arriving on the Espruino interpreter side, some is 'just' definition code, like a function(){ ...} which is 'just' rudimentarily processed before being stored, other is heavily processed and may even get the application aprocess started, such as variable declarations, value assignments, and function calls in level-0 / directly executed code.

    When having heavy active code in the upload and lots of code to upload, timers that are early on created by setTimeout() or setInterval() - and console.log() - may already be firing even before all code upload has completed. Too early firing may collide with upload communication content and timing, like application output to console interferes with upload because for both the same console connection and REPL is used, and timing wise, cpu resource is divided between performing upload task and and executing application code.

  • Can you try running require("Storage").eraseAll() on the left-hand side as well. That'll clear out flash storage completely (reset(true) only clears out saved JS)

  • Thanks @Gordon that fixed it. It may have also been a loose connection on the mpu... Also thanks @allObjects I see that by loading the modules in onInit(), and other practices, my code is running much more reliably.

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

does MPU6050_DMP module work on Puck?

Posted by Avatar for barrier @barrier