*micropython https://docs.micropython.org/en/latest/esp8266/esp8266/tutorial/intro.html /dev/ttyUSB0, Baud Rate: 115200 Vorteile: + no compiling, no waiting, interactive Nachteile: - kann noch kein Over-The-Air ? - weniger libs verfügbar als bei arduino(C/C++) webrepl, mpfshell http://micropython.org/webrepl/ https://github.com/adafruit/ampy nicht vergessen: import webrepl webrepl.start() ... kann man in boot.py schreiben ? ampy -p /dev/ttyUSB0 COMMAND *Commands: * get Retrieve a file from the board. * ls List contents of a directory on the board. * put Put a file on the board. * rm Remove a file from the board. * run Run a script and print its output. optional: esptool.py -p /dev/ttyUSB0 erase_flash ESP8266: esptool.py -p /dev/ttyUSB0 write_flash --flash_mode=dio --flash_size=detect 0 esp8266-20170108-v1.8.7.bin ESP32: esptool --chip esp32 --port /dev/ttyUSB0 --baud 460800 write_flash -z 0x1000 esp32-20190509-v1.10-336-gc0a1de3c2.bin import webrepl_setup [22:55:28:580] >>> import network [22:55:40:345] >>> sta_if = network.WLAN(network.STA_IF) [22:56:06:468] I (417640) wifi: wifi driver task: 3ffe2d70, prio:23, stack:3584, core=0 [22:56:06:477] I (423686) wifi: wifi firmware version: 38e2484 [22:56:06:480] I (423686) wifi: config NVS flash: enabled [22:56:06:484] I (423686) wifi: config nano formating: disabled [22:56:06:488] <0x1b>[0;32mI (423686) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE<0x1b>[0m [22:56:06:501] <0x1b>[0;32mI (423696) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE<0x1b>[0m [22:56:06:519] I (423736) wifi: Init dynamic tx buffer num: 32 [22:56:06:528] I (423736) wifi: Init data frame dynamic rx buffer num: 32 [22:56:06:530] I (423736) wifi: Init management frame dynamic rx buffer num: 32 [22:56:06:535] I (423736) wifi: Init static rx buffer size: 1600 [22:56:06:540] I (423746) wifi: Init static rx buffer num: 10 [22:56:06:545] I (423746) wifi: Init dynamic rx buffer num: 32 [22:56:06:549] >>> ap_if = network.WLAN(network.AP_IF) [22:56:24:586] >>> sta_if.active() [22:56:34:191] False [22:56:34:202] >>> ap_if.ifconfig() [22:56:49:105] ('192.168.4.1', '255.255.255.0', '192.168.4.1', '0.0.0.0') [22:56:49:110] >>> sta_if.active(True) [22:57:12:478] <0x1b>[0;33mW (489686) phy_init: failed to load RF calibration data (0x1102), falling back to full calibration<0x1b>[0m [22:57:12:619] <0x1b>[0;32mI (489836) phy: phy_version: 4007, 9c6b43b, Jan 11 2019, 16:45:07, 0, 2<0x1b>[0m [22:57:12:636] I (489846) wifi: mode : sta (24:0a:c4:31:96:7c) [22:57:12:636] True [22:57:12:636] >>> <0x1b>[0;32mI (489846) wifi: STA_START<0x1b>[0m [22:57:44:035] sta_if.connect('SSID', 'PassWord') [22:57:44:048] >>> I (522346) wifi: new:<9,0>, old:<1,0>, ap:<255,255>, sta:<9,0>, prof:1 [22:57:45:697] I (522916) wifi: state: init -> auth (b0) [22:57:45:710] I (522926) wifi: state: auth -> assoc (0) [22:57:45:725] I (522936) wifi: state: assoc -> run (10) [22:57:45:738] I (522956) wifi: connected with c3RE, channel 9, bssid = f2:9f:c2:2a:a6:15 [22:57:45:746] I (522956) wifi: pm start, type: 1 [22:57:45:755] [22:57:45:755] <0x1b>[0;32mI (522956) network: CONNECTED<0x1b>[0m [22:57:47:589] <0x1b>[0;32mI (524806) event: sta ip: 10.2.3.155, mask: 255.255.254.0, gw: 10.2.3.254<0x1b>[0m [22:57:47:596] <0x1b>[0;32mI (524806) network: GOT_IP<0x1b>[0m >>> help() [23:19:19:428] Welcome to MicroPython on the ESP32! [23:19:19:431] [23:19:19:436] For generic online docs please visit http://docs.micropython.org/ [23:19:19:437] [23:19:19:441] For access to the hardware use the 'machine' module: [23:19:19:442] [23:19:19:442] import machine [23:19:19:446] pin12 = machine.Pin(12, machine.Pin.OUT) [23:19:19:450] pin12.value(1) [23:19:19:450] pin13 = machine.Pin(13, machine.Pin.IN, machine.Pin.PULL_UP) [23:19:19:454] print(pin13.value()) [23:19:19:458] i2c = machine.I2C(scl=machine.Pin(21), sda=machine.Pin(22)) [23:19:19:462] i2c.scan() [23:19:19:462] i2c.writeto(addr, b'1234') [23:19:19:466] i2c.readfrom(addr, 4) [23:19:19:466] [23:19:19:466] Basic WiFi configuration: [23:19:19:471] [23:19:19:471] import network [23:19:19:471] sta_if = network.WLAN(network.STA_IF); sta_if.active(True) [23:19:19:476] sta_if.scan() # Scan for available access points [23:19:19:482] sta_if.connect("<AP_name>", "<password>") # Connect to an AP [23:19:19:488] sta_if.isconnected() # Check for successful connection [23:19:19:495] [23:19:19:495] Control commands: [23:19:19:500] CTRL-A -- on a blank line, enter raw REPL mode [23:19:19:503] CTRL-B -- on a blank line, enter normal REPL mode [23:19:19:507] CTRL-C -- interrupt a running program [23:19:19:511] CTRL-D -- on a blank line, do a soft reset of the board [23:19:19:516] CTRL-E -- on a blank line, enter paste mode [23:19:19:521] [23:19:19:521] For further help on a specific object, type help(obj) [23:19:19:531] For a list of available modules, type help('modules') passw: admin Falls im AP Mode: WPA-key: micropythoN #digital out: import machine blue_led = machine.Pin(2, machine.Pin.OUT) adc = machine.ADC(0) adc.read() D3 = machine.Pin(0, machine.Pin.OUT) D3.high() D3.low() import os os.remove('main.py') def do_connect(): import network sta_if = network.WLAN(network.STA_IF) if not sta_if.isconnected(): print('connecting to network...') sta_if.active(True) sta_if.connect('<essid>', '<password>') while not sta_if.isconnected(): pass print('network config:', sta_if.ifconfig()) boot.py: # This is script that run when device boot up or wake from sleep. import network sta_if = network.WLAN(network.STA_IF); sta_if.active(True) sta_if.connect("c3RE", "ClubMate") sta_if.isconnected() WS2812 ======= http://docs.micropython.org/en/v1.8.2/esp8266/esp8266/tutorial/neopixel.html main.py: import machine, neopixel, time print("Hello, world!") # Pin D4, 5 Stück LEDs np = neopixel.NeoPixel(machine.Pin(4), 5) for y in range(3): print(y) for x in range(5): np[x] = (100, 100, 0) np.write() time.sleep_ms(200) for x in range(5): np[x] = (0, 0, 20) np.write() time.sleep_ms(200) i2c und OLED SSD1306 mit ESP32: Diese Datei mit webrepl oder ampy hochladen: https://raw.githubusercontent.com/micropython/micropython/master/drivers/display/ssd1306.py >>> from machine import Pin, I2C >>> i2c = I2C(scl=Pin(4), sda=Pin(5), freq=100000) >>> print (i2c.scan()) [60] # dec 60 = hex 3c, 3c ist id ID von dem OLED-Display # print (hex(i2c.scan()[0])) # das erste i2c Gerät als Hex Adresse >>> import ssd1306 >>> oled = ssd1306.SSD1306_I2C(128,64, i2c, 0x3c) >>> oled.text("Hello c3RE", 10,10) >>> oled.show() manche Boards haben SDA und SCL vertauscht: "The OLED display uses pins 4 (SDA) and 5 (SCL) to communicate on the I2C bus with the ESP32." Quelle: https://diyprojects.io/unpacking-wemos-esp32-lolin-clone-0-96-ssd1306-monochrome-oled-display/ https://diyprojects.io/oled-display-ssd1306-micropython-example-digital-barometer-bme280-i2c/ machine.freq(240000000) #240Mhz print (( esp32.raw_temperature() - 32) * 5.0/9.0) 47.22222 machine.freq(20000000) #20Mhz print (( esp32.raw_temperature() - 32) * 5.0/9.0, "deg C") 46.66667 deg C Visual Studio Code mit pymakr ____________________________ All Commands: Global Settings ~/.config/Code/User/pymakr.json: { "address": "/dev/ttyUSB0", "username": "micro", "password": "admin", "sync_folder": "", "open_on_start": true, "safe_boot_on_upload": false, "py_ignore": [], "fast_upload": false, "sync_file_types": "py,txt,log,json,xml,html,js,css,mpy", "ctrl_c_on_connect": false, "sync_all_file_types": false, "auto_connect": false, "autoconnect_comport_manufacturers": [ "Pycom", "Pycom Ltd.", "FTDI", "Microsoft", "Microchip Technology, Inc.", "Cygnal Integrated Products, Inc. CP210x UART Bridge / myAVR mySmartUSB light" ] }
{}