My code in esp8266/scrips/main.py is not working..

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
Vasili
Posts: 2
Joined: Fri Mar 18, 2016 5:29 pm

My code in esp8266/scrips/main.py is not working..

Post by Vasili » Fri Mar 18, 2016 5:37 pm

Hi guys,
I have added simpe lines of code from tutorial but it's not working on boot.
Can somebody explain me why ?

Here is the code:
[code]
import pyb
import time

pin = pyb.Pin(2, pyb.Pin.OUT)
for i in range(4):
pin.value(0)
time.sleep(1)
pin.value(1)
time.sleep(1)
[/code]

However this works in python shell.

Thanks !

wendlers
Posts: 47
Joined: Wed Mar 16, 2016 10:07 pm

Re: My code in esp8266/scrips/main.py is not working..

Post by wendlers » Sun Mar 20, 2016 3:06 pm

Vasili wrote:Hi guys,
I have added simpe lines of code from tutorial but it's not working on boot.
Can somebody explain me why ?

Here is the code:
<

import pyb
import time

pin = pyb.Pin(2, pyb.Pin.OUT)
for i in range(4):
pin.value(0)
time.sleep(1)
pin.value(1)
time.sleep(1)


However this works in python shell.

Thanks !
Hi Vasili,

on boot, the script "boot.py" is executed (this changed a while ago, and in the "scripts" directory, there is still only "main.py"). Thus, try the following:

add "boot.py" to the "scripts" directory with this in it:

Code: Select all

import main
now compile+flash:

Code: Select all

make clean
make
make PORT=/dev/ttyUSB0 deploy
This should then run your "main" script.

Vasili
Posts: 2
Joined: Fri Mar 18, 2016 5:29 pm

Re: My code in esp8266/scrips/main.py is not working..

Post by Vasili » Mon Mar 21, 2016 9:49 am

Thanks ! boot.py worked !

MikaelNissen
Posts: 4
Joined: Sat Apr 23, 2016 1:19 am

Re: My code in esp8266/scrips/main.py is not working..

Post by MikaelNissen » Sat Apr 23, 2016 3:37 pm

I have some sort of the same problem, but can't solve it with boot.py file in esp8266/scripts folder.

Get this massage at startup of eps8266 module:

��could not open file 'boot.py' for reading
could not open file 'main.py' for reading

#4 ets_task(401002a8, 3, 3fff4658, 4)
MicroPython v1.7-150-g0d10e53 on 2016-04-23; ESP module with ESP8266
Type "help()" for more information.


I have placed a boot.py file with "import main" and a main.py in the scripts folder before building.

wendlers
Posts: 47
Joined: Wed Mar 16, 2016 10:07 pm

Re: My code in esp8266/scrips/main.py is not working..

Post by wendlers » Sat Apr 23, 2016 7:10 pm

MikaelNissen wrote:I have some sort of the same problem, but can't solve it with boot.py file in esp8266/scripts folder.

Get this massage at startup of eps8266 module:

could not open file 'boot.py' for reading
could not open file 'main.py' for reading

...

I have placed a boot.py file with "import main" and a main.py in the scripts folder before building.
Hi Mikael,

the boot sequence on the ESP changed lately. See this commit:

https://github.com/micropython/micropyt ... 8254a35b79

From the commit:
Upon start-up, _boot module is executed from frozen files to do early
initialization, e.g. create and mount the flash filesystem. Then
"boot.py" is executed if it exists in the filesystem. Finally, "main.py"
is executed if exists to allow start-on-boot user applications.

This allows a user to make a custom boot file or startup application
without recompiling the firmware, while letting to do early initialization
in Python code.
So to sum it up and come back to your problem:

1) You don't need to "import main.py" in you "boot.py" any more. The "main.py" and "boot.py" are started both by MP if present
2) Both, "main.py" and "boot.py" are expected to be in the flash-file-system, NOT in frozen (means not in "scripts" when compiling)

At the moment, there is no official support for uploading files to the flash FS (but it is on the way I think). To make life a little easier, I use a script I wrote. If you like to have a look at it, it could be found here:

https://github.com/wendlers/mpfshell

Regards,
Stefan

MikaelNissen
Posts: 4
Joined: Sat Apr 23, 2016 1:19 am

Re: My code in esp8266/scrips/main.py is not working..

Post by MikaelNissen » Mon Apr 25, 2016 8:15 pm

Thanks Stefan for the reply.

The mpfshell is very usefull to upload the files.

Regards

Mikael

User avatar
patvdleer
Posts: 46
Joined: Mon Jun 13, 2016 11:52 am
Location: Maastricht, NL, Europe
Contact:

Re: My code in esp8266/scrips/main.py is not working..

Post by patvdleer » Mon Jun 13, 2016 11:56 am

Is there any update on this? I have a similar issue with main.py.

Code: Select all

#��${$�$ܟ|��{oc��d�s��pp�c䌜���c�lclsdǃr$���#$�#;|�c�㓛ǜ�l��n�og�l$���d��$����d$`�g����c��#���cl�c�l{$s�'����cp��������bd�cd�|b�b��o���b8cĜ�����#l�#d�|#d`�d��|��{r'c��d�p{�#�c서��Ǐ<�cllcl��do�$`Ãl'�p;l�l��|���could not open file 'main.py' for reading

#5 ets_task(40100350, 3, 3fff6350, 4)
MicroPython v1.8.1-37-g236838a on 2016-06-13; ESP module with ESP8266
Type "help()" for more information.
>>> scandone
state: 0 -> 2 (b0)
state: 2 -> 3 (0)
state: 3 -> 5 (10)
add 0
aid 3
cnt 

connected with 0x43.2, channel 1
dhcp client start...
ip:192.168.178.12,mask:255.255.255.0,gw:192.168.178.1

>>> import main
WebREPL daemon started on ws://192.168.4.1:8266
WebREPL daemon started on ws://192.168.178.12:8266
Started webrepl in normal mode
>>> 
My main.py files contains nothing more than:

Code: Select all

import webrepl
webrepl.start()

This only happens when I compile it with the image, not when I transfer the files via mpfshell.

Post Reply