1

I'm coding some example in micropython for the BBC Micro::bit. I'm using the Mu editor, which checks the code and flashes it to the board.

The thing is, I can't find a way to import my own scripts from the main one. Despite the code check ends succesfully (and works on my computer), once flashed, the board will complain about the imported module not existing. It's like only the main script is making it into the board. Furthermore, if I paste all my code into one script, Mu will complain about the script being too long (about 300 lines). What am I doing wrong here? Why is there a max script length?

dvilela
  • 1,200
  • 12
  • 29

1 Answers1

2

The reason there is a maximum script length is because of the limited about of memory inside the micro:bit. It is a very capable "little computer", but it has a few limitation, memory being one of the more prominent ones.

When you click on the Flash button on Mu it only copies over the current script. You could use the new storage functionality from MicroPython (link to documentation explaining the feature), which will need the latest version of Mu (http://codewith.mu). You have to keep in mind that flashing a new script will always remove whatever is stored, so you would have to first flash your main script, and then add the other file by clicking on the "files" button on Mu. There you can drag and drop any script from your local Mu folder into the micro:bit.

The absolute simplest way to do what you want would be to combine everything into a single file, as you have tried before. If it doesn't fit you could try reducing the size of the script, for instance by reducing your comments or somehow reducing the amount of code.

carlosperate
  • 594
  • 4
  • 11
  • Totally working .Thank you so much! I guessed the file limit was due to the ammount of memory available, but...limiting the line count? It seems weird to me. – dvilela Oct 27 '16 at 18:03
  • 1
    Is not so much as limiting the line count, but the amount of code that fits in the microbit flash. Every time you flash using Mu it takes the MicroPython interpreter and attaches your script into a single hex file, which is copied to the microbit. At the moment there is only 8Kb for your Python script, encoded in UTF-8. So, best case scenario you have space for 8192 characters in your script, independent of the number of lines. Useful tip: There is 30Kbs available in the file system inside the microbit, so you could include larger files that way (main.py will always execute on reset). – carlosperate Oct 27 '16 at 23:10