Connecting to wifi upon boot
Hi, I'm a little confused as what is happening here.
If I run the following
main.pyon my WiPy using Thonny interactively "run current script" the script works as expected. i.e. it prints the defined output to the LCD display, connects to the Wifi network then displays the output for
Hello World! ('192.168.1.34, '255.255.255.0', '192.168.1.1', '18.104.22.168') Running test_main
However, if then directly boot the WiPy using the same
main.pyit doesn't seem to connect to the wifi network and the display just shows:
('0.0.0.0', '0.0.0.0', '0.0.0.0', '22.214.171.124')
# main.py -- put your code here! """Implements a HD44780 character LCD connected via ESP32 GPIO pins.""" from machine import Pin from esp32_gpio_lcd import GpioLcd from utime import sleep_ms, ticks_ms from network import WLAN wlan = WLAN(mode=WLAN.STA) wlan.antenna(WLAN.EXT_ANT) # Wiring used for this example: # # 1 - Vss (aka Ground) - Connect to one of the ground pins on you pyboard. # 2 - VDD - I connected to VIN which is 5 volts when your pyboard is powered via USB # 3 - VE (Contrast voltage) - I'll discuss this below # 4 - RS (Register Select) connect to G4 (as per call to GpioLcd) # 5 - RW (Read/Write) - connect to ground # 6 - EN (Enable) connect to G11 (as per call to GpioLcd) # 7 - D0 - leave unconnected # 8 - D1 - leave unconnected # 9 - D2 - leave unconnected # 10 - D3 - leave unconnected # 11 - D4 - connect to G5 (as per call to GpioLcd) # 12 - D5 - connect to G18 (as per call to GpioLcd) # 13 - D6 - connect to G21 (as per call to GpioLcd) # 14 - D7 - connect to G22 (as per call to GpioLcd) # 15 - A (BackLight Anode) - Connect to VIN # 16 - K (Backlight Cathode) - Connect to Ground # # On 14-pin LCDs, there is no backlight, so pins 15 & 16 don't exist. # # The Contrast line (pin 3) typically connects to the center tap of a # 10K potentiometer, and the other 2 legs of the 10K potentiometer are # connected to pins 1 and 2 (Ground and VDD) # # The wiring diagram on the following page shows a typical "base" wiring: # http://www.instructables.com/id/How-to-drive-a-character-LCD-displays-using-DIP-sw/step2/HD44780-pinout/ # Add to that the EN, RS, and D4-D7 lines. def test_main(): wlan.connect(ssid='School_2.4GHz', auth=(WLAN.WPA2, '1234')) print(wlan.ifconfig()) """Test function for verifying basic functionality.""" print("Running test_main") lcd = GpioLcd(rs_pin=Pin("P4"), enable_pin=Pin("P5"), d4_pin=Pin("P6"), d5_pin=Pin("P7"), d6_pin=Pin("P8"), d7_pin=Pin("P9"), num_lines=4, num_columns=20) lcd.putstr("It Works!\nSecond Line\nThird Line\nFourth Line\nFourth Line") sleep_ms(3000) lcd.clear() count = 0 while True: lcd.move_to(0, 0) lcd.putstr("%7d" % (ticks_ms() // 1000)) lcd.move_to(0, 1) lcd.putstr(str(wlan.ifconfig())) sleep_ms(1000) count += 1 def main(): print("Hello World!") test_main() if __name__ == "__main__": main()
robert-hh last edited by
@cbourne Wifi connection is not always immediate. It may take a few seconds after the wlan.connect() statement until the connection is settled and the dhcp server submitted an IP address. So better code a loop after the connect statements, which checks with wlan.isconnected(), whther the connection is established. Add a short sleep into the loop, like sleep_ms(100).
OK, so this seems to have resolved itself after updating to latest firmware.
Hi my boot.py file is empty at the moment. Not sure if Pybytes is enabled. How do I check that ?