repl on the BBC:Microbit

Questions and discussion about running MicroPython on a micro:bit board.
Target audience: MicroPython users with a micro:bit.
Jim.S
Posts: 47
Joined: Fri Dec 18, 2015 7:36 pm

Re: repl on the BBC:Microbit

Post by Jim.S » Sat Aug 13, 2016 6:46 am

My microbit doent have a battery pack at present, I wonder if I connected a battery to it it would retain python scripts in memory between connections of the usb? I shall dig out some crokodil clips......

Jim.S
Posts: 47
Joined: Fri Dec 18, 2015 7:36 pm

Re: repl on the BBC:Microbit

Post by Jim.S » Sat Aug 13, 2016 4:09 pm

I tried it with a 3V battery connected during the removal and reconnection of the USB but this made no difference, main.py still vanished.

Seems to mean that the only way to program the microbit is to flash the script using uflash (or mu)

User avatar
deshipu
Posts: 1220
Joined: Thu May 28, 2015 5:54 pm

Re: repl on the BBC:Microbit

Post by deshipu » Sat Aug 13, 2016 9:58 pm

Can you describe in detail how you are uploading the main.py to the micro:bit and how you are checking that it is there?

Jim.S
Posts: 47
Joined: Fri Dec 18, 2015 7:36 pm

Re: repl on the BBC:Microbit

Post by Jim.S » Sun Aug 14, 2016 11:45 am

This is what I have just done

$ cp main.py /media/MICROBIT/
$ sudo sync
$ ls /media/MICROBIT/
AUTO_RST.CFG DETAILS.TXT main.py MICROBIT.HTM
$ sudo umount /media/MICROBIT

I then manually unplug and replug the USB cable

$ ls /media/MICROBIT/
AUTO_RST.CFG DETAILS.TXT MICROBIT.HTM

main.py has vanished.

I can flash main.py to the board using
$ uflash main.py
... and it keeps the script running after many hard and soft resets.

The system configuration is as follows:
* My linux is Mint 17.3,
* I have the latest Microbit firmware 0234,
The following is from the REPL prompt after a Ctrl-C
* MicroPython v1.7-9-gbe020eb on 2016-04-18; micro:bit with nRF51822

At the moment I'm not too bothered. I can program it using uflash, I will find the time to install mu. Its behaviour is different from the pyboard

User avatar
deshipu
Posts: 1220
Joined: Thu May 28, 2015 5:54 pm

Re: repl on the BBC:Microbit

Post by deshipu » Sun Aug 14, 2016 4:42 pm

I see the source of your confusion now!

You can't just copy files onto the fake mass storage device that micro:bit appears as -- this is only for flashing the hex files. Basically, anything you copy there will be flashed as firmware. It's not a real disk, it's just a hack to make it easy to flash firmware.

In order to create files on micro:bit's internal filesystem, you either have to run a python program that would create the files there and fill them with content, or use Mu to upload the files.

Jim.S
Posts: 47
Joined: Fri Dec 18, 2015 7:36 pm

Re: repl on the BBC:Microbit

Post by Jim.S » Sun Aug 14, 2016 5:25 pm

Ah, thanks, I understand now... But this opens up more questions
When I run the code

Code: Select all

from microbit import *
with open('file.txt', 'w') as f:
    f.write('this is a test')
The file is written to the Microbit's local-persistant-file-system but can I access that file or copy it to the host computer over the USB connection?

User avatar
deshipu
Posts: 1220
Joined: Thu May 28, 2015 5:54 pm

Re: repl on the BBC:Microbit

Post by deshipu » Sun Aug 14, 2016 6:06 pm

You can, using the Mu's "files" dialog.

rhubarbdog
Posts: 19
Joined: Tue Nov 07, 2017 11:45 pm

Re: repl on the BBC:Microbit

Post by rhubarbdog » Sun Nov 12, 2017 1:29 am

to use REPL under linux you need to be in group dialout, in a terminal type

Code: Select all

sudo usermod -a -Gdialout user-name
You will need to log out and bak in for the groups to take effect

rhubarbdog
Posts: 19
Joined: Tue Nov 07, 2017 11:45 pm

Re: repl on the BBC:Microbit

Post by rhubarbdog » Mon Nov 13, 2017 9:34 pm

To place persistent files onto a micro:bit you have at least these two options

1)

Code: Select all

 microfs put filename 
2) use the Mu ide

I guess your using linux if your doing

Code: Select all

cp my-data /media/xxx/MICROBIT 
which will never work. The microbit appearing as though it's a usb drive is a hack to allow drag and drop flashing.

If your using ubuntu/debian linux you may want to read https://ubuntuforums.org/showthread.php?t=2377314

Post Reply