Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MicroPython consumes too much memory and causes memory allocation error on V1 micro:bits #784

Open
JackAtKitronik opened this issue Nov 4, 2022 · 5 comments

Comments

@JackAtKitronik
Copy link

Describe the bug
Using the micro:bit Python Editor, we were trying to add servo and LED functionality to the Kitronik MOVE Motor MicroPython library. Upon adding the servo code (about 20 lines of code) the code is now too big and when put on the V1 micro:bit it causes a memory allocation error saying memeory allocation failed, allocating 398 bytes.

To Reproduce
Steps to reproduce the behavior:

  1. Open https://python.microbit.org/v/3/project
  2. Save KitronikMOVEMotor.py
  3. Add the code at MOVEMotor.py to main.py
  4. Download the code onto a V1 micro:bit
  5. The error memory error, memeory allocation failed, allocating 398 bytes appears

Expected behavior
Following the same steps on as above but the program works on a V1 micro:bit.
On a V2 micro:bit then the code works as expected.

micro:bit version
V1 micro:bit

@dpgeorge
Copy link
Member

dpgeorge commented Nov 7, 2022

I don't think there's much that can be done about this, the micro:bit V1 just doesn't have enough memory.

If you really need to get it working on a V1, it might be possible to optimise the code so that it does fit. But in general that's not possible to do, and the way to resolve it is either:

  1. have simpler programs
  2. use a micro:bit V2

@microbit-carlos
Copy link
Collaborator

@JackAtKitronik was this the issue where the code worked fine in a single file but it was running out of memory (in this case by ~400 bytes) when using a module?

@dpgeorge if that's the case, would that be expected? that separating the code into a module could consume that much extra memory?

@rhubarbdog
Copy link
Contributor

I got this working and used it with a move:mini https://github.com/rhubarbdog/microbit-servo

@dpgeorge
Copy link
Member

dpgeorge commented Nov 7, 2022

if that's the case, would that be expected? that separating the code into a module could consume that much extra memory?

Yes that's expected, simply because you now have two .py files: the main one which imports the second one. And some memory is already used by the first at the point where the second is imported and compiled.

This case would definitely benefit from being able to import .mpy files.

@JackAtKitronik
Copy link
Author

@JackAtKitronik was this the issue where the code worked fine in a single file but it was running out of memory (in this case by ~400 bytes) when using a module?

@microbit-carlos almost. Putting it into a single file did make it smaller but not small enough to work.

I got this working and used it with a move:mini https://github.com/rhubarbdog/microbit-servo

@rhubarbdog great I'll have a look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants