wtf main.py and boot.py empty?!

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
NikolaiE
Posts: 10
Joined: Sat Nov 10, 2018 1:23 pm

wtf main.py and boot.py empty?!

Post by NikolaiE » Sat Nov 10, 2018 3:41 pm

I managed it now to write data to the sd-card, but when i remove it: boot.py and main.py are empty?

Then I wrote scripts in there again and repeated procedure, they becam empty again.

Can i manage it to use boot.py and main.py from the sd-card?

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: wtf main.py and boot.py empty?!

Post by Roberthh » Sat Nov 10, 2018 3:50 pm

Sure. If main.py and boot.py are on the sd card, they will be used. What you see may be a problem of the sd-card being attached as a PC drive. Then data may look as if being on the sd card, but is still is in the cache. Take care that you eject that drive always. On linux, use the sync command to force cached data to be written.

NikolaiE
Posts: 10
Joined: Sat Nov 10, 2018 1:23 pm

Re: wtf main.py and boot.py empty?!

Post by NikolaiE » Sat Nov 10, 2018 7:26 pm

Thanks.

Is there any overview of boot process or enabled devices while starting up?

NikolaiE
Posts: 10
Joined: Sat Nov 10, 2018 1:23 pm

Re: wtf main.py and boot.py empty?!

Post by NikolaiE » Sat Nov 10, 2018 7:43 pm

my main.py:

this works:
pyb.delay(2000)

f = open("/sd/schrott.txt", "a")

f.write(str(pyb.millis()) + "\n")
f.flush()
f.close()

f = open("/sd/schrott.txt", "r")
f.read()

uos.sync()


pyb.LED(3).on() # indicate we are waiting for switch press


pyb.LED(4).on() # indicate that we are selecting the mode

and this works not (no delay):


f = open("/sd/schrott.txt", "a")

f.write(str(pyb.millis()) + "\n")
f.flush()
f.close()

f = open("/sd/schrott.txt", "r")
f.read()

uos.sync()


pyb.LED(3).on() # indicate we are waiting for switch press


pyb.LED(4).on() # indicate that we are selecting the mode


So your system needs still some time after booting to have working filesystem.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: wtf main.py and boot.py empty?!

Post by Roberthh » Sat Nov 10, 2018 7:54 pm

This is not plausible, since main.py is also executed form sd. To be sure, that there is no interference with the PC file manager, change boot.py like below, disabling the device as storage device. It will then not mount any more at your Pc as drive. This is inconvenient, but saves you from a lot of trouble.

Code: Select all

import pyb
#pyb.main('main.py') # main script to run after this one
#pyb.usb_mode('CDC+MSC') # act as a serial and a storage device
pyb.usb_mode('CDC+HID') # act as a serial device and a mouse
#pyb.usb_mode('CDC') # act as a serial device and a mouse

NikolaiE
Posts: 10
Joined: Sat Nov 10, 2018 1:23 pm

Re: wtf main.py and boot.py empty?!

Post by NikolaiE » Sat Nov 10, 2018 8:29 pm

I'm doing some analyzation:

my boot.py:


import machine
import pyb
q = pyb.micros()
p = pyb.micros()

pyb.LED(3).on() # indicate we are waiting for switch press
k = pyb.micros()

pyb.LED(4).on() # indicate that we are selecting the mode

pyb.usb_mode('VCP+MSC')
pyb.main('main.py') # if switch was pressed, run this

pyb.LED(4).off() # indicate that we finished selecting the mode

pyb.LED(3).off()

and as you know:
q-p is 10us
and k-p is 36us

So i assume, the reason for something normally taking ~50ns is taking 10us, is the time for interpretation of python code.
So My suggestion is a completely new language for writing bytecode :P

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: wtf main.py and boot.py empty?!

Post by Roberthh » Sat Nov 10, 2018 8:43 pm

Whatever you like ....

NikolaiE
Posts: 10
Joined: Sat Nov 10, 2018 1:23 pm

Re: wtf main.py and boot.py empty?!

Post by NikolaiE » Sat Nov 10, 2018 8:55 pm

when i push the rst button electricity becomes visible ...

NikolaiE
Posts: 10
Joined: Sat Nov 10, 2018 1:23 pm

Re: wtf main.py and boot.py empty?!

Post by NikolaiE » Sat Nov 10, 2018 9:34 pm

if you can manage it to directly interprete c-code this has great value.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: wtf main.py and boot.py empty?!

Post by Roberthh » Sun Nov 11, 2018 7:07 am

I remember to have tried a C-Code interpreters in the past. It combined the disadvantage of compiled code and interpreted code.
No. You cannot easily compare compiled C code and Python Code and blame Python for being slow without blaming compiled c code to be unsafe. Python provides a lot of convenience in data structures and safety in execution, and that does not come for free. If you have specific section of your code with a need for speed, MicroPython allows you to get that with the different code emitters, from native code, viper emitters and assembly code. @pythoncoder has written an excellent documentation about that. You'll find it in the docs: http://docs.micropython.org/en/latest/r ... ython.html

Post Reply