esp32-micropython


本來之前買和另一貼子的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')

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM