larsks/py-mpu6050

module has no method MPU

javirs85 opened this issue · 11 comments

Hi, When I try to run the module I get this error message. "'module' has no method MPU". When trying to call the "mpu = mpu6050.MPU()" (main.py line 11)

I tried creating my own file with a class and calling it from the main and I got the same kind of error. I Checked in the internet and it looks like in micropython you have to do something weird to be able to import and use modules but .. the problem does not look like it is when importing the module (import myFile.ph works ) but doing myFile.myClass() does produce this error (module has no method)

Im an experienced coded.. in C# XD i've done some codes in micropythong but never actually created a class in a different file. . . Am I doing something wrong ?

Can you detail the exact steps that lead to the error? In particular:

  • On what platform are you running Micropython (esp8266? pyboard? something else?)
  • How are you installing your files onto the board?
  • Exactly how are you executing the files?

Sorry yesterday I had no time to start the computer.

Im using a NodeMCU board (old ones, ESP8266, CH40 usb driver) I can run blink examples and those, REPL works nice.
I'm using uPyCraft environment for uploading and running files there. (https://legacy.gitbook.com/book/dfrobot/upycraft/details)

I open a question related on stack overflow : https://stackoverflow.com/questions/49769223/create-class-in-a-different-file-in-micropython

What software would you recommend for uploading / running the files ?

What software would you recommend for uploading / running the files ?

I just use ampy for uploading the files.

I don't use anything for "running the files". I either do that manually from the REPL, or I configure a main.py to do it automatically when the board boots.

I tried ampy. To be honest when doing ampy -p com5 ls I do not see the files.. so .. there might be something bad in uPyCraf and I stop using it right now.

In the other hand.. I uploaded every file using ampy, started the repl, ran import os os.listdir() and the files are there right now.

I run again:

>>> import mpu6050 
>>> mpu = mpu6050.MPU()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'MPU'

:(

can it be that he is missing something in the brackets?? The definition on it says: class MPU(object): what should this "object" be?

hi larsks, I tried a different method .. I created a class that I was able to load and, one by one, added your methods to this class...
Everything was going nice but I got some memory complains when loading the contants.py. I decided to create my own constantsMINI.py where I copied only the ones I needed .. and it worked XD

I´m now adding the last method (calibrate) and no mather what I do I get this:

>>> import mpu6050
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
MemoryError:

No details on the particular error.

If I remove part of the code it loads properly. If I left the code there and remove ANOTHER part of the code.. it loads..

Can it be that my nodeMCU has not enough memory to load the codes?? can it be?

I tried checking how much RAM I have ...

>>> import gc
>>> gc.mem_free()
28720
>>> import mpu6050
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
MemoryError: memory allocation failed, allocating 413 bytes
>>> gc.mem_free()
27200
>>>

any clue?

I checked using diag and the nodemcu board I use has 4MB of RAM. That shouldn't be the problem ..

can it be due to the connections I don't have? I don't think so since it crashes before I run any code but ... I have the I2C on a diferent port and I don't have the LED and I dont use any cable in the IRQ port .. can this affect ?

BTW, I DO NEED to use pull up resistors for I2C, even when I set the Pin as Pin(4, Pin.IN, Pin.PULL_UP) is that common behavior?

I have exactly the same error:

>>> import mpu6050
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
MemoryError: memory allocation failed, allocating %u bytes

Not sure if this is relevant:
MicroPython v1.9.3-8-g63826ac5c on 2017-11-01; ESP module with ESP8266

I have the same error by testing BME280 (((
Simple test worked well, but after adding WiFi - "object has no attribute"

It looks like folks are running into the memory limits of the ESP8266, which are indeed very small. You can reduce the space required byt his module (and others) by "baking" it into the micropython image:

  • Places the modules into the modules/ subdirectory of ports/esp8266.
  • Build a new image
  • Burn it to your esp8266. Make sure you erase flash first in order to clear out anything on the filesystem that doesn't need to be there.

This will often free up a few precious KB.