Hi all
I am making a ESP8266 sumobot is sorts with a 4 channel IR sensor and a motor shield
http://www.energiazero.org/arduino_sens ... sensor.pdf
The plan is to create seperate files for the hbridge module (motors.py), the IR sensors (ir.py) and have a main file to create the drive program.
So I start with:
import motors
Import ir
The the body code which is a few if and elifs in a drive function.
In the webrepl, import the main file and call the drive() function.
Problem is, it says the ir module hasn't been imported. Only way to make it work is to manually import ir and motors before the main file in the webrepl.
Another way is to redownload all the files in uPyCraft which seems to so the same thing.
dir() shows all the files are in the same location?
I've tried importing main, ir and motors in boot.py
I will grab the code tomorrow and post it.
I've tried everything I can think of, it's going against everything read about how it should work?
It imports time or machine just fine..
Import not importing?
Import not importing?
Last edited by Murray on Tue Nov 30, 2021 9:59 pm, edited 1 time in total.
Re: Import not importing?
ir.py :
motors.py :
main.py :
Code: Select all
from machine import Pin
rf = Pin(14, Pin.IN)
lf = Pin(12, Pin.IN)
rt = Pin(13, Pin.IN)
lt = Pin(15, Pin.IN)
Code: Select all
import time
from machine import Pin
pwm1 = Pin(5, Pin.OUT) # D1
pwm2 = Pin(4, Pin.OUT) # D2
dir1 = Pin(0, Pin.OUT) # D3
dir2 = Pin(2, Pin.OUT) # D4
def rev ():
pwm1(1)
pwm2(1)
dir1(1)
dir2(1)
def fwd ():
pwm1(1)
pwm2(1)
dir1(0)
dir2(0)
def stop ():
pwm1(0)
pwm2(0)
dir1(0)
dir2(0)
def left():
pwm1(1)
dir1(1)
dir2(0)
def right():
pwm2(1)
dir1(0)
dir2(1)
def turn():
pwm2(1)
dir1(0)
dir2(1)
time.sleep(.5)
main.py :
Code: Select all
import irs
import motors
def drive():
try:
while True:
if rf.value() == False and lf.value() == False:
motors.fwd()
elif rf.value() == True and lf.value() == False:
motors.turn()
elif rf.value() == False and lf.value() == True:
motors.turn()
except KeyboardInterrupt:
motors.stop()
print('interrupted!')
Re: Import not importing?
Your import statement says "import irs" but the file is named ir.py not irs.py
Re: Import not importing?
Sorry, my description is different than the file naming.
The real version calls the correct file name
The real version calls the correct file name
Re: Import not importing?
Figured it out.
The function is called the same as the file and micropython got confused
The function is called the same as the file and micropython got confused
- Wind-stormger
- Posts: 17
- Joined: Fri Nov 05, 2021 6:59 am
Re: Import not importing?
Code: Select all
Interesting