DEV Community 👩‍💻👨‍💻

codemee
codemee

Posted on

MaixDuino 上使用 MaixPy 讀取類比輸入

MaixDuino 是透過 ESP32 讀取 ADC, 可參考官方的範例檔。不過目前測試似乎有問題, 都會得到以下錯誤:

[MaixPy]: esp32 read adc failed!
Enter fullscreen mode Exit fullscreen mode

根據論壇的說明, 這似乎是 ESP32 上的韌體有問題, 以後再測試看看。

如果使用特定版本的 MaixPy 及 ESP32 韌體, 就可正常運作。請使用 kflash 工具燒錄下載後解開的 mainxpy.bin:

接著再使用 flash_download_tools 將下載解開的 NINA_W102-1.3.1.bin 燒錄到 MaixDuino 上的 ESP32:

請記得 ESP32 是另一個序列埠。完成後, 就可以使用以下程式測試 ADC (MaixDuino 上的 K210 晶片和 ESP32 之間使用 SPI 傳輸資料, 相關接腳可參考電路圖):

import network
import utime
from Maix import GPIO
from fpioa_manager import *

#iomap at MaixDuino
fm.register(25,fm.fpioa.GPIOHS10)#cs
fm.register(8,fm.fpioa.GPIOHS11)#rst
fm.register(9,fm.fpioa.GPIOHS12)#rdy
fm.register(28,fm.fpioa.GPIOHS13)#mosi
fm.register(26,fm.fpioa.GPIOHS14)#miso
fm.register(27,fm.fpioa.GPIOHS15)#sclk

nic = network.ESP32_SPI(cs=fm.fpioa.GPIOHS10,rst=fm.fpioa.GPIOHS11,rdy=fm.fpioa.GPIOHS12,
mosi=fm.fpioa.GPIOHS13,miso=fm.fpioa.GPIOHS14,sclk=fm.fpioa.GPIOHS15)

adc = nic.adc()
print(adc)
Enter fullscreen mode Exit fullscreen mode

adc() 會以 tuple 形式傳回 6 個 ADC 接腳的值:

>>> %Run -c $EDITOR_CONTENT
ESP32_SPI init over
(839, 1169, 192, 16, 0, 0)
Enter fullscreen mode Exit fullscreen mode

Top comments (5)

Collapse
strtest1 profile image
Strtest1

Hello,

I tried this but I am not able to flash my ESP32 chip on the maixduino. I get the message "5-chip efuse check fail". Maybe you can give me some more instructions on how you did it? Or do you have an idea why it is not working on my end?

Thank you in advance!

Collapse
codemee profile image
codemee Author

I've try this again and it's OK. Did you use the MaixPy firmware come with the downloaded file?

Collapse
strtest1 profile image
Strtest1

I started by flashing the K210 chip with the kflash_gui.exe like it is told in the sipeed docs. As firmware I used "maixpy_v0.5.1_103gf9bb0bb.bin". I just saw that there are newer version out now. I tried them as well (the newest from 16.12.2020) but it still does not work.
Maybe you could give me a little bit more detail on how you did it and what firmware your board is on?

Thank you in advance!

Thread Thread
codemee profile image
codemee Author

You should use the MaixPy firmware in this link as shown in my post, it had customized code for ADC. The official release MaixPy firmware doesn't do ADC right.

Thread Thread
strtest1 profile image
Strtest1 • Edited on

Sadly this does not resolve the issue. I still get the same error code when I try to burn the ESP32 with the flash_download_tool v3.8.5 (I couldn't find the Version 3.6.8 you used online to check if that might be a problem). Do I need additional drivers besides the COM driver I use for communicating with the K210?

Thank you in advance!

🌚 Life is too short to browse without dark mode