DEV Community

codemee
codemee

Posted on

2 3

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

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (5)

Some comments may only be visible to logged-in visitors. Sign in to view all comments.

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay