▌01 byBoard Mini
In Taobao to buy the "Python microcontroller programming from scratch" , which refers to the pyBoard Mini application core board. The PyBoard purchased today has arrived. Conduct preliminary experimental tests on it.
1. pyBoard basic information
(1) Pin definition
▲ PyBoard Mini的外管脚
▲ 外观与个管脚定义
(2) Learning materials
Through communicating with Taobao e-commerce owners, obtain download links of relevant learning materials:
Information link : https://pan.baidu.com/s/11ZXjkUjAL-W2hd0thnzZ9w
Extraction code : 1234
After downloading, store it in:
D:\zhuoqing\DesignCenter\MicroPython\PyBoard\MicroPython development kit (based on pyboard STM32F05 platform) supporting information_2021-2-5
These include the following directories:
- 01-Development tools
- 02-Sample program
- 03-Related firmware
- 04-Schematic & Function Diagram
- 05-Chip Manual
- 06-Product Picture
- "MicroPython from 0 to 1" is based on pyBoard (STM32F405 platform)_v1.0.pdf
- Supporting information introduction.txt
2. Connect PyBoard to PC
(1) Install the USB serial port driver
Use the Mini USB cable purchased in the device to connect the P Board to the USB of the PC (Windows 7), and the following virtual serial port with no driver installed will appear at the beginning:
PyBoard Virtual Comm Port In FS Mode
At the same time, a disk named PYBFLASH will appear.
According to the solution provided by pyboard virtual comm port in fs mode , directly use the right mouse button to select the USB device to update the driver software, browse the computer to find the driver software , and select PYBFLASH to complete the installation of the USB device.
▲ 安装完之后出现的 PyBoard USB Comm Port
The following files exist in PYBFLASH when PyBoard is loaded into the USB port of the PC:
- boot.py
- dht.py
- ds18x20.py
- main.py
- onewire.py
- pybcdc.inf
- README.txt
- ssd1306.py
Save it temporarily at:
D:\zhuoqing\DesignCenter\MicroPython\PyBoard\PYBFLASH
(2) Connect with Thonny
The installation software development environment Thonny PI Pico description, download and install Thonny IDE.
Select the Options dialog box in Tools in Thonny, select "MicroPython (Generic)" in Interpreter, and then select PyBoard USB Comm Port (COM10) in Port.
Among them, COM10 needs to be determined according to the actual port number of the USB serial port corresponding to PyBoard in the computer.
▲ Thonny 的Options 对话框
Enter the following simple test statement in Thonny's Shells:
>>> from pyb import LED
>>> led = LED(1)
>>> led.toggle()
▲ Thonny Shells输入简单语句
Observe that the LED on the PyBoard is lit:
▲ LED被点亮
The following code lights up all four onboard LEDs:
from pyb import LED
led = [LED(x+1) for x in range(4)]
for l in led:
l.toggle()
▲ 四个板载LED都被点亮
from pyb import LED,delay
led = [LED(x+1) for x in range(4)]
print("LEDs flash")
while True:
for l in led:
l.toggle()
delay(250)
▲ PyBoard LEDs Flash
3. Preliminary study materials
"MicroPython from 0 to 1" is based on pyBoard (STM32F405 platform)_v1.0.pdf
4. Restore PyBoard factory settings
When an abnormality occurs in the pyboard, the startup sequence can be modified or the factory settings can be restored in the following ways. The method is as follows:
Press and hold the USER button on pyBoard, press and hold the button again, and press the RST button again, the LED lights will continue to flash alternately, when the flashing reaches the mode you want, release it when the flashing reaches the mode you want , Release the user button, the LED light will flash quickly, the board will flash quickly, the board will flash quickly, and the board will restart.
Mode 1: Only the green light, normal mode: first start boot.py
then main.py
.
Mode 2: Only the orange light is on, safe mode, safe mode: do not run any scripts at startup. (Valid only once)
Mode 3: The green light and orange light up at the same time, and the file system is reset: the file system is restored to the factory state, and then: the file system is restored to the factory state, and then starts in safe mode.
Note: When the edited program is stored in main.py in PYBFLASH, main.py will be run after the system board is powered on next time.
▌ 02 basic experiments
1. LED test
The relevant function of the LED object encapsulated in pyb is:
▲ LED 对象的相关函数
▲ 延迟相关的函数
(1) Water lamp
from pyb import LED,delay
led = [LED(x+1) for x in range(4)]
print("LEDs flash")
count = 0
while True:
for l in led:
l.on()
delay(100)
l.off()
delay(100)
▲ 板载LED实现流水灯
2. Button
▲ 按键相关的函数
from pyb import LED,delay,Switch
def func1():
LED(4).toggle()
sw = Switch()
sw.callback(func1)
▲ 使用按键切换LED(4)的状态
3.GPIO
▲ GPIO相关对象的函数
The following code is to control the state of the onboard LED (4) through the USR onboard buttons.
from pyb import LED,delay,Switch,Pin
p_out = Pin('B4', Pin.OUT_PP)
p_in = Pin('X17', Pin.IN, Pin.PULL_UP)
while True:
if p_in.value() == 0:
p_out.high()
else:
p_out.low()
Demonstration effect:
▲ 使用板载的USR按键控制LED(4)
4. External interruption
▲ 外部IO中断对应的函数
from pyb import LED,delay,Switch,Pin,ExtInt
callback = lambda e: LED(4).toggle()
ext = ExtInt(Pin('Y1'), ExtInt.IRQ_FALLING, Pin.PULL_UP, callback)
▲ 使用外部中断来切换LED(4)
5. Real-time clock
▲ 始终相关的函数
from pyb import LED,RTC,Pin
rtc = RTC()
if rtc.datetime()[0] != 2019:
rtc.datetime((2019,4,1,1,0,0,0,0))
while True:
print(rtc.datetime())
pyb.delay(500)
▲ 实时时钟输出的字符
6.ADC
▲ ADC 对象相关的函数
(1) Basic ADC reading
from pyb import LED,RTC,Pin,ADC
adc = ADC('X1')
while True:
print(adc.read())
pyb.delay(250)
▲ 通过电位器改变X1端口的电压
(2) Change LED brightness
from pyb import LED,RTC,Pin,ADC
adc = ADC('X1')
while True:
adv = adc.read()
intensity = int(adv / 16)
for i in range(4):
LED(i+1).intensity(intensity)
pyb.delay(25)
▲ 通过ADC设置LED的亮度
7.DAC
Note that according to the data sheet of STM32F411CEU4, it does not have a DAC output. According to the introduction in the experimental reference book, it has 2 DACs, X5 and X6. X6 is connected to the passive buzzer on the board, so X6 can only be used.
▲ DAC 对象的相关函数
Executing the program, you will find that there is no DAC module in it.
from pyb import LED,RTC,Pin,ADC,DAC
dac = DAC(1, bits=12)
dac.write(0x400)
print('DAC output 0x400')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: can't import name DAC
In the same Taobao seller, it provides a DAC converter in the PyBoard-STM32F405 development board .
8.UART
▲ F411模块只有两个UART端口
▲ UART对象
from pyb import LED,UART
uart = UART(1, 115200)
print("Test UART.")
while True:
uart.write(b'\x55')
pyb.delay(10)
▲ X9上的信号波形
▌Conclusion
This article conducts a preliminary test on the newly purchased pyBoard Mini to verify some of its functions.
This section does not have a DAC, which is a certain limitation in the subsequent signal processing process.
■ Related literature links: