main.py don't start after poweron

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
lukesky333
Posts: 42
Joined: Fri Sep 02, 2016 4:07 pm
Location: Austria

main.py don't start after poweron

Post by lukesky333 » Mon Sep 05, 2016 8:26 am

Hello!!!

I'm new here and I've already my first problem. I tried a lot of code snippets and everything is working like expected.

Now I tried create a main.py file, that should start after poweron of the board. ...but it is not working.

Could anybody give me a hint how to do that?

I'm using the development board "Witty Cloud" with the ESP-12F.

Thanks a lot...

User avatar
platforma
Posts: 258
Joined: Thu May 28, 2015 5:08 pm
Location: Japan

Re: main.py don't start after poweron

Post by platforma » Mon Sep 05, 2016 8:32 am

How did you "create" the file? Perhaps you can walk us through what you have done so far and what output you get, that makes you think it's not working?

lukesky333
Posts: 42
Joined: Fri Sep 02, 2016 4:07 pm
Location: Austria

Re: main.py don't start after poweron

Post by lukesky333 » Mon Sep 05, 2016 8:51 am

Yes, of course...

At first I installed the firmware esp8266-20160901-v1.8.3-81-g9c04ef2.bin and then I create a new boot.py and main.py file with Vi.

here the content of "boot.py":

Code: Select all

import webrepl
print("boot.py loaded...")
webrepl.start()
content of "main.py":

Code: Select all

import esp
import machine
import time

def toggle(p):
   p.value(not p.value())

def main():
    pin = machine.Pin(2, machine.Pin.OUT)

    for i in range(10):
        toggle(pin)
        time.sleep_ms(500)
       
if __name__ == 'main':
    print("main entered")
    esp.osdebug(0)
    main()
Now I flashed the latest firmware esp8266-20160905-v1.8.3-112-gb4df3e7.bin but main.py is still not running...
What could be the reason for that?

EDIT: It seems that main.py is loaded but main() not executed... Why?
Last edited by lukesky333 on Mon Sep 05, 2016 9:36 am, edited 1 time in total.

User avatar
pythoncoder
Posts: 4351
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: main.py don't start after poweron

Post by pythoncoder » Mon Sep 05, 2016 9:35 am

I think one of the things @platforma was after was how you transferred the two files to the ESP8266. However if it's now working then you've evidently done this successfully :)
Peter Hinch

lukesky333
Posts: 42
Joined: Fri Sep 02, 2016 4:07 pm
Location: Austria

Re: main.py don't start after poweron

Post by lukesky333 » Mon Sep 05, 2016 9:38 am

For file transfer I'm using mpfshell.

The problem is, that main.py is loaded but main() not executed... Any idea why???

EDIT: OK, sorry for that stupid question/problem.
wrong:

Code: Select all

if __name__ == 'main':
correct:

Code: Select all

if __name__ == '__main__':

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

Re: main.py don't start after poweron

Post by Roberthh » Mon Sep 05, 2016 9:51 am

Just to ask a few simple questions:

Do you see the message printed "main entered", e.g. after reboot with Ctrl-D?
How do you tell that main() is not executed. Did you try a print statement inside main(), just to sort our any connection issue with the LED?

lukesky333
Posts: 42
Joined: Fri Sep 02, 2016 4:07 pm
Location: Austria

Re: main.py don't start after poweron

Post by lukesky333 » Mon Sep 05, 2016 9:56 am

Roberthh wrote:Do you see the message printed "main entered", e.g. after reboot with Ctrl-D?
Yes, I see... After fixing the code everything is working like expected. ;-)
Roberthh wrote:How do you tell that main() is not executed. Did you try a print statement inside main(), just to sort our any connection issue with the LED?
Not yet, but the code is working now.

Thanks a lot for the help!!!

User avatar
platforma
Posts: 258
Joined: Thu May 28, 2015 5:08 pm
Location: Japan

Re: main.py don't start after poweron

Post by platforma » Mon Sep 05, 2016 11:23 am

Easy mistake to get caught out on, glad you got it working!

poduris
Posts: 5
Joined: Wed Oct 05, 2016 1:59 pm

Re: main.py don't start after poweron

Post by poduris » Wed Oct 05, 2016 5:26 pm

Hi,
I'm new to ESP & Micropython, I wanted to run micropython code by including it in firmware .....I get following error on powering on NodeMCU.
"could not open file 'main.py' for reading"

I did following

1) Built esp sdk toolchain using documentaion available at
https://learn.adafruit.com/building-and ... d-firmware
2) Created main.py with following code at "/home/vagrant/micropython/esp8266/scripts" on ubuntu VM
3) compiled firmware & copied it to /vagrant folder
4) Flashed the firmware on NodeMCU using esptool.py

I'm not able to find out what went wrong....

import machine
pin = machine.Pin(5, machine.Pin.OUT)

import time

for i in range(100):
pin.value(1)
time.sleep(0.25)
pin.value(0)
time.sleep(0.25)

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

Re: main.py don't start after poweron

Post by Roberthh » Wed Oct 05, 2016 7:49 pm

Two questions:
a) How much flash has your device? For a file system, at least 1 MByte is required. You can tell by exectuing

Code: Select all

 import port_diag
from the command line
b) Try to erase the flash before loading micropython. Issue

Code: Select all

esptool.py erase_flash

Post Reply