-
• #2
My goal is to use this module with a Jolt.js I just got. I have the Jolt attached to a little robot chassis. The issue with the small robot is that I don't know if it is going a a straight line or not, so I want to incorporate an MPU to track the "yaw" of the chassis as it drives along and eventually correct itself.
If anyone reading this knows of a better MPU or has suggestions please drop a comment. -
• #3
Sorry, I've just looked into this and it seems the MPU6050 module used default arguments, which Espruino has never supported - so I'm kind of amazed this worked at all (I assume earlier versions of Espruino just ignored them rather than erroring).
I've just fixed it, so if you try re-uploading now I believe it should all work ok
-
• #4
Thank you for your quick response, I took a look at the module and it didn't occur to me that the default parameters would be an issue.
I'm still having some issues with this module but I think it is mostly how I'm starting the I2c Communications when Loading this code to RAM.
It sometimes works and starts up right way but a lot of the time it fails to start. I get this:
____ _ | __|___ ___ ___ _ _|_|___ ___ | __|_ -| . | _| | | | | . | |____|___| _|_| |___|_|_|_|___| |_| espruino.com 2v25 (c) 2024 G.Williams > Uncaught InternalError: Timeout on I2C Write BUSY 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],f=(1<<d)-1<<b-d+1;g=g&~f|e<<b-d... ^ in function "writeBits" called from line 1 col 25 this.writeBits(107,2,3,a) ^ in function "setClockSource" called from line 1 col 22 this.setClockSource(1);this.setFullScaleAccelRange(0);this.s... ^ in function "initialize" called from line 1 col 74 ...===b?105:b;this.initialize() ^ in function "c" called from line 1 col 10 new c(a,b) ^ in function "connect" called from line 23 col 44 const MPU = require("MPU6050").connect(I2C1); ^ Resetting MPU6050... Uncaught Error: Can't read property 'reset' of undefined at line 1 col 45 ...tting MPU6050...");this.mpu.reset();setTimeout(k,30,this) ^ in function "initialize" called from line 1 col 44 this.mpu=a;this.fifoRate=b;this.initialize() ^ in function "c" called from line 1 col 10 new c(a,b) ^ in function "create" called from line 25 col 49 const DMP = require("MPU6050_DMP").create(MPU, 1);
I will play with it more to find the source of the issue. I will play with putting the code in flash and setting up the I2c using onInit().
I remember getting I2C devices to initialize is tricky and this may be an issue with how I'm doing things
Thanks again !
-
• #5
If it's unreliable it could be an issue with pullups on the I2C pins. As I recall sometimes hardware I2C can't use the pullups internal to the chip, so if your MPU6050 board doesn't have pullups on it, it might have problems.
You could try software I2C:
var i2c = new I2C(); i2c.setup({scl:B6, sda:B7, bitrate:100000}); const MPU = require("MPU6050").connect(i2c);
As I believe that can always use pullups, but you could also try adding ~10k-47k pullup resistors to the I2C lines and see if that helps?
-
• #6
I realized the the error Uncaught InternalError: Timeout on I2C Write BUSY was because of bad header pins! I somehow got a batch of headers that didn't have any beveling on them, this caused damage to my solderless breadboard and contrsibuted to a poor connection. I always use high quality solderless breadboards to reduce issues but I never anticipated bad header pins!
I think how the module initiates the MPU isn't perfect but it does work well enough for my purposes. If I have time , I might go though the module and modify it for myself. I want to see if I can make initialization more consistent and I want to eliminate verbose warning and error messages. My end goal it to interface my "robot" with an app on my phone(written with droidscript) . I like being able to interface directly using the console over BLE (jolt), it is very powerful and is one of the best features of the espruino environment. I don't want to filter all these warning messages from the module. The "puck" addon in Droidscript works flawlessly for interfacing with the espruino console over BLE and I have been using that for a bunch of little things. I like that I can program any BLE Espruino with my phone. I wrote a droidscript app with a dropdown menu of programs that I can upload at-will to espruino and it is very handy!
When I get home from work I will try to use the soft I2c connection to see if it helps with MPU initialization, thanks for the suggestion! I forgot that I can do that.
Keep up the good work with Espruino, It is by far my favorite platform for tinkering.
-
• #7
Thanks - I'm really glad it's working well for you!
I want to see if I can make initialization more consistent and I want to eliminate verbose warning and error messages.
If you do this, please could you contribute back? As you say it's not very useful having a bunch of log messages in your code when you're not actively developing
-
• #8
If I make any real progress I will do so.
I'm not sure what the issue is with this module(MPU 6050), but it only works when using the web IDE using Minification; specifically "Closure(online) - Simple Optimizations" , It fails when using Esprima (offline) or any other minification.
I'm currently trying to use this module on a Pico that was just updated to the latest firmware (2v25)
I have a working mpu6050 and I can get it to function under these very strict circumstances, but it feels like a kludge.
I'm just wondering why it would only work under such specific circumstances, is there anything that could be done to make the module more reliable?
This is not a huge concern but I'm wondering if there are some obvious reasons this module would behave this way.
I get this error :
Uncaught SyntaxError: Got '!' expected ','
at line 1 col 2110
...yBank=function(a,bundefined!1,dundefined!1){a&=31,d&&(a|=32)...