Ey Ya All, I am testing micropython in a microcontroller, here are some things I am using
$ pip install esptool
$ esptool.py --chip esp32c3 --port /dev/tty.usbmodem144301 erase_flash
$ esptool.py --chip esp32c3 --port /dev/tty.usbmodem144301 --baud 460800 write_flash -z 0x0 /tmp/ESP32_GENERIC_C3-20241129-v1.24.1.bin
$ $tio /dev/tty.usbmodem144301 -t
Create the next boot.py:
import network
import time
def connect_to_wifi(ssid, password):
wlan = network.WLAN(network.STA_IF) # Station mode
wlan.active(True)
if not wlan.isconnected():
print("Connecting to WiFi...")
wlan.connect(ssid, password)
for _ in range(10): # Retry for ~10 seconds
if wlan.isconnected():
break
time.sleep(1)
if wlan.isconnected():
print("Connected to WiFi!")
print("IP Address:", wlan.ifconfig()[0])
else:
print("Failed to connect to WiFi")
wlan.active(False)
return wlan
# Replace with your WiFi credentials
SSID = "YourWiFiSSID"
PASSWORD = "YourWiFiPassword"
wlan = connect_to_wifi(SSID, PASSWORD)
Then:
pip install adafruit-ampy
ampy --port /dev/tty.usbmodem144301 put boot.py
Check that the file is there with:
with open('boot.py', 'r') as f:
print(f.read())
And you can check the ip with:
import network
wlan = network.WLAN(network.STA_IF)
if wlan.isconnected():
print("Connected to WiFi:", wlan.config('essid'))
print("IP Address:", wlan.ifconfig()[0])
else:
print("Not connected to WiFi")
Then enable webREPL with, and follow the instructions:
import webrepl_setup
The you can connect to the webREPL by going to the next link:
http://ESPIP:8266/
In my case is in:
http://192.168.1.102:8266/
With the password “clubmate”
Neopixel example
from machine import Pin
from neopixel import NeoPixel
pin = Pin(3, Pin.OUT) # set GPIO0 to output to drive NeoPixels
np = NeoPixel(pin, 60, bpp=4) # create NeoPixel driver on GPIO0 for 8 pixels
np[1] = (255, 0, 0, 0) # set the first pixel to white
np.write() # write data to all pixels
np.fill((100, 0, 0, 0))
np.write()
Install Thonny IDE
I tried VS Code, and doesnt work, is too difficult, so that is why I am moving to Thonny.
Just install it, and then go to:
- Tools > Options > Interpreter
- Configure WebREPL interpreter