Skip to content

Instantly share code, notes, and snippets.

@ritiek
Last active September 27, 2022 22:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ritiek/501b9079353c8f87c303580fcc2687c2 to your computer and use it in GitHub Desktop.
Save ritiek/501b9079353c8f87c303580fcc2687c2 to your computer and use it in GitHub Desktop.
Setting up MicroPython on ESP32
import network
sta_if = network.WLAN(network.STA_IF)
sta_if.active(True)
sta_if.connect("ssid", "pass")
sta_if.isconnected()
sta_if.ifconfig()
import urequests
response = urequests.get("http://ipinfo.io")
ip_info = response.json()
print(f"{ip_info['ip']}, you're from {ip_info['city']}, {ip_info['region']}, {ip_info['country']}, {ip_info['timezone']}.")
# Download MicroPython for ESP32: https://micropython.org/download/esp32/
# sudo pacman -Syu screen esptool
# pamac install adafruit-ampy
# Erase
esptool.py --chip esp32 --port /dev/ttyUSB0 erase_flash
# Flash
esptool.py --chip esp32 --port /dev/ttyUSB0 --baud 460800 write_flash -z 0x1000 ~/Downloads/esp32-20220618-v1.19.1.bin
# TTY
screen /dev/ttyUSB0 115200
# ctrl+a e - paste mode
# ctrl+a d - exit paste mode / soft reboot
# ctrl+a k - kill screen
echo """print('hello, let\'s blink the blue onboard led 3 times')
from machine import Pin
import time
for x in range(6):
led_state = not (x % 2)
print(f'led_state: {int(led_state)}')
Pin(2, Pin.OUT).value(led_state)
time.sleep(1)""" > esp32_test.py
# Run program, capture stdout, display stdout at termination
ampy --port /dev/ttyUSB0 run test.py
# Run program
ampy --port /dev/ttyUSB0 run --no-output test.py
# Stream stdout
screen /dev/tty/USB0 115200
# Upload program to run on boot (soft reboot / reboot)
ampy --port /dev/ttyUSB0 put esp32_test.py /main.py
# Download program
ampy --port /dev/ttyUSB0 get /main.py
# Replace "get" with one of: ls mkdir rm rmdir, for unix-like commands
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment