Can't import original modules (pyb, time, Pin, etc)

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.
Post Reply
Trönfstar
Posts: 16
Joined: Fri Jun 09, 2017 5:16 am

Can't import original modules (pyb, time, Pin, etc)

Post by Trönfstar » Fri Jun 09, 2017 5:42 am

Hi everybody!

This is my very first post, and let me apologise for my weak english capabilities.

Last day, I've tried to import my module to the main script. Of course I couldn't.
I've decided to find the relevant topic here, and I got what I want, but then something really weird happened:

I checked the sys.path, but not modified it, then I reset the pyboard (and exeptionally it was a hard reset).
When connected again to my computer, I started to rewrite my main script importing the pyb modul and from pyb the Pin and the ExtInt.

When I was trying to run the main.py I got Syntax error for the first two lines (containing the import arguments)... and since than I always get a syntax error if I try to import a base module.

The really strange is to me that if I type it directly to the REPL it works fine. Pls help me, "I sit on needles"! :lol:
Last edited by Trönfstar on Fri Jun 09, 2017 1:45 pm, edited 1 time in total.

Trönfstar
Posts: 16
Joined: Fri Jun 09, 2017 5:16 am

Re: Can't import original modules (pyb, time, Pin, etc)

Post by Trönfstar » Fri Jun 09, 2017 1:28 pm

I forgot to notice, that afterall I made a factory reset using the buttons on the board, but nothing changed. :?

Trönfstar
Posts: 16
Joined: Fri Jun 09, 2017 5:16 am

Re: Can't import original modules (pyb, time, Pin, etc)

Post by Trönfstar » Fri Jun 09, 2017 8:09 pm

Just arrived from work. Long time without power supply solved my issue. :D

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

Re: Can't import original modules (pyb, time, Pin, etc)

Post by pythoncoder » Sat Jun 10, 2017 5:32 am

This has me baffled.

As a general point it's best to put your code in a file other than main.py. Then, at the REPL, you can issue

Code: Select all

import myfile
to debug it.

Once you have it working, edit main.py to issue

Code: Select all

import myfile
myfile.main()  # Or whatever is needed to run it
Peter Hinch
Index to my micropython libraries.

Trönfstar
Posts: 16
Joined: Fri Jun 09, 2017 5:16 am

Re: Can't import original modules (pyb, time, Pin, etc)

Post by Trönfstar » Mon Jun 12, 2017 12:43 pm

Thanks the tip! I'll put it to the proof. ;)

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

Re: Can't import original modules (pyb, time, Pin, etc)

Post by deshipu » Tue Jun 13, 2017 8:01 pm

Also, please show us the code that doesn't work. Maybe it really has syntax errors in it.

Trönfstar
Posts: 16
Joined: Fri Jun 09, 2017 5:16 am

Re: Can't import original modules (pyb, time, Pin, etc)

Post by Trönfstar » Fri Jun 16, 2017 8:29 am

Since then it works fine. Actually it was a simple control of the integrated leds. What should I do to share my script in the future?
( I mean the frames around the posted codes) :oops: Both of you are very helpful. I appreciate that, thank you! ;)

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

Re: Can't import original modules (pyb, time, Pin, etc)

Post by pythoncoder » Fri Jun 16, 2017 9:58 am

Because of spam, the forum disallows formatting such as code blocks until you've made a certain number of posts.
Peter Hinch
Index to my micropython libraries.

Trönfstar
Posts: 16
Joined: Fri Jun 09, 2017 5:16 am

Re: Can't import original modules (pyb, time, Pin, etc)

Post by Trönfstar » Fri Jun 16, 2017 10:06 am

Thanks the explanation!

Post Reply