Script main.py (or boot.py) doesn't properly start when module reset #11411
Replies: 2 comments
-
In line 4 you imported SoftI2C instead of I2C. Therefor I2C is not found. |
Beta Was this translation helpful? Give feedback.
-
Hi robert-hh! Great advice, you are right, when corrected as suggested working fine. ................. Probably, author tried code for ESP32 only and forgot about importing I2C when ESP8266 run. I was misled when loading i2c_lcd.py first before main.py caused proper function of code. Thanks again and have a good day! eljots |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, as this is my first post here I'd like to welcome and wish all you the best.
Again, as I'm just starting with ESP and uPython my problem probably is obvious but so far have not found solution :-(
I try to start my python script at boot (or reset) using boot.py or main.py but receive such message when load manually eg. main.py:
download ok
exec(open('main.py').read(),globals())
Traceback (most recent call last):
File "", line 1, in
File "", line 11, in
NameError: name 'I2C' isn't defined
My boot.py (or main.py - I've tried both) is as follow:
import machine
import sys
import ds1302
from machine import Pin, SoftI2C
from lcd_api import LcdApi
from i2c_lcd import I2cLcd
from time import sleep
I2C_ADDR = 0x27
totalRows = 2
totalColumns = 16
i2c = I2C(scl=Pin(5), sda=Pin(4), freq=500000) #initializing the I2C method for ESP8266
lcd = I2cLcd(i2c, I2C_ADDR, totalRows, totalColumns)
............
............
Files lcd_api.py and i2c_lcd.py which mange I2C LCD module are present on ESP8266.
Using uPyCraft v.1 to load (and run) scripts on ESP8266.
Interesting, when manually, prior to the main.py script with mentioned code, first load lcd_api.py and i2c_lcd.py files, then everything working fine. When module is restarted with reset switch then nothing on the screen.
Any ideas?
eljots
Beta Was this translation helpful? Give feedback.
All reactions