• Continuing from https://github.com/espruino/EspruinoDocs­/issues/367#issuecomment-306120068,

    I tried the "falling" edge suggestion, but the behavior seems the same, the HTTP server never responds, and I never see the ------ dmpYawPitchRoll output in Espruino console.

    Here's the code I'm trying:

    function getMPU() {
        I2C1.setup({scl:B6,sda:B7, bitrate: 100000});
        var MPU6050 = require("MPU6050");
        var mpu = MPU6050.connect(I2C1);
        return mpu
    function connectToWifi(wifiName, options) {
        var resolve, reject
        var promise = new Promise(function(res, rej) {resolve = res; reject = rej})
        var wifi = require("EspruinoWiFi");
        wifi.connect(wifiName, options, function(err) {
            if (err) reject(err);
        return promise
    connectToWifi("wifi", { password : "password" })
    .then(function() {
        const mpu = getMPU();
        const dmp = require('MPU6050_DMP').create(mpu, 3);
        const http = require("http");
        let dmpYawPitchRoll = null
        // This loop locks up the espruino: https://github.com/espruino/EspruinoDocs­/issues/367
        function dmpLoop() {
            const dmpData = dmp.getData()
            if (dmpData !== undefined) {
                    dmpYawPitchRoll = dmp.getYawPitchRoll(dmpData)
        setWatch(dmpLoop, B5, { repeat:true, edge:'falling' });
        http.createServer(function (req, res) {
            let result = {
                acceleration: mpu.getAcceleration(), // returns an [x,y,z] array with raw accl. data
                gravity: mpu.getGravity(),  // returns acceleration array in G's
                rotation: mpu.getRotation(), // returns an [x,y,z] array with raw gyro data
                degreesPerSecond: mpu.getDegreesPerSecond(), // returns gyro array in degrees/s
            result = JSON.stringify(result)
            // This never fires, HTTP response is never sent to computer
            console.log(' ------ dmpYawPitchRoll:', dmpYawPitchRoll)
        const wifi = require("EspruinoWiFi");
        wifi.getIP(function(err, info) {
            if (err) throw err
            console.log('IP:', info.ip)
    function onInit() {
        console.log('Espruino started!');

    Making an HTTP request from the computer to Espruino doesn't work. If you uncomment the console.log calls, the setWatch loop is working, and I will see that output repeatedly in console.

  • Ok, thanks for giving that a go. It's difficult to track down without having an MPU6050 here (it's a contributed module).

    If you uncomment the console.log, how quickly is it being called?

    It'd be interesting if you could compare getTime before and after the call in dmpLoop, to see if the function call is actually taking the majority of the time or not.

    If you're able to change the module yourself, I think the while loop in this line: https://github.com/espruino/EspruinoDocs­/blob/master/devices/MPU6050_DMP.js#L121­

    should be removed, and the check moved into the if statement above.

    My hunch is that the interrupt line is maybe getting pulled low for reasons other than the FIFO having data, and that's causing it to enter the getData function and then get stuck polling for more data.

  • Just quickly:

    • Are you sure B5 is connected correctly to the IRQ pin? If it was floating it could cause all kinds of issues.
    • Are there I2C pullup resistors somewhere in the circuit? I think it's unlikely but if there were a bad I2c connection it could really slow things down and stall the idle loop
  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview

`setWatch` interrupt loop for MPU6050 seems to block async processes on Espruino.

Posted by Avatar for trusktr @trusktr