Can main.py and REPL share any variables?

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
User avatar
liudr
Posts: 134
Joined: Tue Oct 17, 2017 5:18 am

Can main.py and REPL share any variables?

Post by liudr » Mon Aug 06, 2018 7:54 pm

This may be a very simple question to those experienced:

I have in my main.py import logger_setup.py that does all the initialization:

main.py

Code: Select all

from logger_setup import *
logger_setup.py

Code: Select all

import machine
import uos
import utime
import network
pin27=machine.Pin(27, machine.Pin.OUT) # Power pin for SDI-12 sensors
pin27.value(1) # Turn on power to SDI-12 sensors
uart1=machine.UART(1,baudrate=9600, tx=32,rx=33) # Xbee socket
uart2=machine.UART(2,baudrate=9600, tx=12, rx=13) # SDI-12 translator
uos.sdconfig(uos.SDMODE_SPI, clk=5, mosi=18, miso=19, cs=14)
uos.mountsd(True)
pin21=machine.Pin(21, machine.Pin.IN, machine.Pin.PULL_UP) # Mode button. Pushed in (0) = Wi-Fi station, Popped out (1) = Wi-Fi access point
utime.sleep(0.1)
if pin21.value()==1:
    ap = network.WLAN(network.AP_IF)
    ap.active(True)
    ap.config(essid='AAA') # Causes unknown error 0x0005 if executed before ap.active(True). 
    ap.config(authmode=3, password='AAA') # Causes unknown error 0x0005 if executed before ap.active(True).
	ap.ifconfig()

else:
    sta = network.WLAN(network.STA_IF)
    sta.active(True)
    sta.connect("AAA","AAA")
	sta.ifconfig()

network.ftp.start(user="AAA", password="AAA", buffsize=1024, timeout=300)
network.telnet.start(user="AAA", password="AAA", timeout=300)
Once REPL starts, I couldn't find any variables set up in the process, such as the uarts and pins. What I wish to do is that once this script is executed, I'd like to access pin27, uart1, uart2, etc. in REPL. Can this be done?

User avatar
liudr
Posts: 134
Joined: Tue Oct 17, 2017 5:18 am

Re: Can main.py and REPL share any variables?

Post by liudr » Mon Aug 06, 2018 8:27 pm

It's odd. I wasn't able to access variables I defined in main.py in REPL before but now I can. Maybe it's because I ran into some syntax errors in main.py

Hope that was the reason.

Post Reply