本来之前买和另一贴子的esp8266一起买了一块esp32.
现在开发esp的大概有乐鑫的ide以及基于乐鑫定制的、arduino、nodemcu、还有就是现在要讲的micropython.
乐鑫的主要跑ucos,arduino版本顾名思义,nodemcu用lua脚本语言,micropython用定制的python。
每一种都或多或少接触过,偶然的时候在NDIY论坛看到F4跑micropython,用python语言干单片机的活,然后就百度了下。
感觉如果拿来做轻量开发十分方便,比arduino还方便。恰好身边也有人在学python,学好了还可以介绍给他们。
http://www.eeboard.com/evaluation/pyboard/
这个帖子写的是pyboard评测,从中可以看出micropython的特点。
官方自己下的定义:
MicroPython - a lean and efficient Python implementation for microcontrollers and constrained systems
https://micropython.org
以下是安装步骤:
先安装esptool.py
pip install esptool.py
没装pip先sudo apt装好pip
然后不知道为什么我默认安装到/home/xxx/.local/bin/这个目录里面了,百度过来都是直接pip好了就能用,然后我locate esptool找到了脚本的位置,
然后在.bashrc里面alias esptool="/home/xxx/.local/bin/esptool.py"然后source一下就行了.
先按照官网说的:
Firmware for ESP32 boards The following files are daily firmware for ESP32-based boards, with separate firmware for boards with and without external SPIRAM. Non-SPIRAM firmware will work on any board, whereas SPIRAM enabled firmware will only work on boards with 4MiB of external pSRAM. Program your board using the esptool.py program, and put the firmware starting at address 0x1000. For example: esptool.py --chip esp32 --port /dev/ttyUSB1 write_flash -z 0x1000 esp32-20180511-v1.9.4.bin. If you are putting MicroPython on for the first time then you should first erase the entire flash using esptool.py --chip esp32 erase_flash.
清除flash
katachi@katachi-Inspiron-7559:~/eclipse-workspace/micropython$ esptool --chip esp32 --port /dev/ttyUSB0 erase_flash esptool.py v2.5.0 Serial port /dev/ttyUSB0 Connecting........__ Chip is ESP32D0WDQ6 (revision 1) Features: WiFi, BT, Dual Core MAC: 30:ae:a4:3a:1b:9c Uploading stub... Running stub... Stub running... Erasing flash (this may take a while)... Chip erase completed successfully in 3.6s Hard resetting via RTS pin... katachi@katachi-Inspiron-7559:~/eclipse-workspace/micropython$
然后刷进去:
katachi@katachi-Inspiron-7559:~/eclipse-workspace/micropython$ esptool --chip esp32 --port /dev/ttyUSB0 write_flash -z 0x1000 esp32spiram-20180908-v1.9.4-498-g5cd2c7f2e.bin esptool.py v2.5.0 Serial port /dev/ttyUSB0 Connecting.... Chip is ESP32D0WDQ6 (revision 1) Features: WiFi, BT, Dual Core MAC: 30:ae:a4:3a:1b:9c Uploading stub... Running stub... Stub running... Configuring flash size... Auto-detected Flash size: 4MB Compressed 1115728 bytes to 687324... Wrote 1115728 bytes (687324 compressed) at 0x00001000 in 60.7 seconds (effective 147.1 kbit/s)... Hash of data verified. Leaving... Hard resetting via RTS pin...
刷的是带ram的,但是rst后报错,然后刷了不带ram的就启动了,用串口连接,是一个叫REPL(read evaluate print loop)的交互bash,
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT) flash read err, 1000 ets_main.c 371 ets Jun 8 2016 00:22:57 rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT) configsip: 0, SPIWP:0xee clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00 mode:DIO, clock div:2 load:0x3fff0018,len:4 load:0x3fff001c,len:4732 load:0x40078000,len:7496 load:0x40080400,len:5512 entry 0x4008114c I (389) cpu_start: Pro cpu up. I (389) cpu_start: Single core mode I (389) heap_init: Initializing. RAM available for dynamic allocation: I (392) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM I (398) heap_init: At 3FFC4F48 len 0001B0B8 (108 KiB): DRAM I (405) heap_init: At 3FFE0440 len 00003BC0 (14 KiB): D/IRAM I (411) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM I (417) heap_init: At 40091448 len 0000EBB8 (58 KiB): IRAM I (424) cpu_start: Pro cpu start user code I (218) cpu_start: Starting scheduler on PRO CPU. OSError: [Errno 2] ENOENT MicroPython v1.9.4-498-g5cd2c7f2e on 2018-09-08; ESP32 module with ESP32 Type "help()" for more information. >>>
help一下
Welcome to MicroPython on the ESP32! For generic online docs please visit http://docs.micropython.org/ For access to the hardware use the 'machine' module: import machine pin12 = machine.Pin(12, machine.Pin.OUT) pin12.value(1) pin13 = machine.Pin(13, machine.Pin.IN, machine.Pin.PULL_UP) print(pin13.value()) i2c = machine.I2C(scl=machine.Pin(21), sda=machine.Pin(22)) i2c.scan() i2c.writeto(addr, b'1234') i2c.readfrom(addr, 4) Basic WiFi configuration: import network sta_if = network.WLAN(network.STA_IF); sta_if.active(True) sta_if.scan() # Scan for available access points sta_if.connect("<AP_name>", "<password>") # Connect to an AP sta_if.isconnected() # Check for successful connection Control commands: CTRL-A -- on a blank line, enter raw REPL mode CTRL-B -- on a blank line, enter normal REPL mode CTRL-C -- interrupt a running program CTRL-D -- on a blank line, do a soft reset of the board CTRL-E -- on a blank line, enter paste mode For further help on a specific object, type help(obj) For a list of available modules, type help('modules')