Minicom All In One
minicom bugs / minicom errors
Minicom 2.8
# 0000000000001 ❌
$ minicom -b 115200 -o -D /dev/tty.usbmodem0000000000001
# tty ❌
$ minicom -b 115200 -o -D /dev/tty.usbmodem14601
# cu ✅
$ minicom -b 115200 -o -D /dev/cu.usbmodem14601
MicroPython REPL
✅
MicroPython
v1.19.1
-994-ga4672149b on 2023-03-29;Raspberry Pi Pico
withRP2040
>>> pin25 = machine.Pin(25)
>>> print("pin25 =", type(pin25))
>>> pin25 = <class 'Pin'>
>>> import time
>>> from time import sleep
>>>
>>> GPIO_PIN = 25
>>> led = machine.Pin(GPIO_PIN, machine.Pin.OUT)
>>>
>>> led.value(1)
>>> time.sleep(1)
>>> led.value(0)
>>>
>>> led.high()
>>> time.sleep(1)
>>> led.low()
>>>
MPY: soft reboot
MicroPython v1.19.1-994-ga4672149b on 2023-03-29; Raspberry Pi Pico with RP2040
Type "help()" for more information.
>>> help()
Welcome to MicroPython!
For online help please visit https://micropython.org/help/.
For access to the hardware use the 'machine' module. RP2 specific commands
are in the 'rp2' module.
Quick overview of some objects:
machine.Pin(pin) -- get a pin, eg machine.Pin(0)
machine.Pin(pin, m, [p]) -- get a pin and configure it for IO mode m, pull mode p
methods: init(..), value([v]), high(), low(), irq(handler)
machine.ADC(pin) -- make an analog object from a pin
methods: read_u16()
machine.PWM(pin) -- make a PWM object from a pin
methods: deinit(), freq([f]), duty_u16([d]), duty_ns([d])
machine.I2C(id) -- create an I2C object (id=0,1)
methods: readfrom(addr, buf, stop=True), writeto(addr, buf, stop=True)
readfrom_mem(addr, memaddr, arg), writeto_mem(addr, memaddr, arg)
machine.SPI(id, baudrate=1000000) -- create an SPI object (id=0,1)
methods: read(nbytes, write=0x00), write(buf), write_readinto(wr_buf, rd_buf)
machine.Timer(freq, callback) -- create a software timer object
eg: machine.Timer(freq=1, callback=lambda t:print(t))
Pins are numbered 0-29, and 26-29 have ADC capabilities
Pin IO modes are: Pin.IN, Pin.OUT, Pin.ALT
Pin pull modes are: Pin.PULL_UP, Pin.PULL_DOWN
Useful control commands:
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')
>>>
Meta-Z for help | 115200 8N1 | NOR | Minicom 2.8 | VT102 | Offline | cu.usbmodem14601
machine
Pin
# machine.Pin(pin)
# -- get a pin, eg machine.Pin(0)
# machine.Pin(pin, m, [p])
# -- get a pin and configure it for IO mode m, pull mode p
methods: init(..), value([v]), high(), low(), irq(handler)
# machine.Pin(pin, m, [p])
led = machine.Pin(25, machine.Pin.OUT)
# value([v])
led.value(1)
led.value(0)
# high(), low()
led.high()
led.low()
# init(..) ???
led.init()
# irq(handler) ???
def handler():
print("function")
led.irq(handler)
ADC
PWM
I2C
minicom 无法退出 bug ❌
按 Ctrl + A
可以切换到 >
模式;但是再依次按 Z 键,X 键 也无法退出 ❓ 不好使 ❌
按 Ctrl + A
连续按两次也不好使 ❌
按 Ctrl + B
可以切换到 >>>
MicroPython 的 REPL 模式;
>>> help()
可以正常使用 ✅
macOS 配置 Python 环境变量
Python 3
$ which python
# python not found
$ python --version
# zsh: command not found: python
$ which python3
# /usr/bin/python3
$ python3 --version
# Python 3.9.6
Raspberry Pi 3 B
$ ssh [email protected]
[email protected]'s password:
Linux raspberrypi 4.19.118-v7+ #1311 SMP Mon Apr 27 14:21:24 BST 2020 armv7l
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Wed Mar 29 00:18:23 2023 from 192.168.18.195
SSH is enabled and the default password for the 'pi' user has not been changed.
This is a security risk - please login as the 'pi' user and type 'passwd' to set a new password.
$ python --version
Python 2.7.16
$ which python
/usr/bin/python
$ python3 --version
Python 3.7.3
$ which python3
/usr/bin/python3
$ vim test.py
$ python ./test.py 10
$ python3 ./test.py 10
# #!/usr/bin/env python3 ✅
# #!/usr/bin/python3
# # coding: utf8 ✅
gpio.py
#!/usr/bin/env python3
# coding: utf8
import RPi.GPIO as GPIO
import time
import sys
arg1 = sys.argv[1]
print("arg1 =", arg1);
# 指定 BCM 模式下的GPIO 针脚编号
PIN = 12
# BCM 模式
GPIO.setmode(GPIO.BCM)
# 指定 GPIO 针脚为一个电流输出针脚
GPIO.setup(PIN, GPIO.OUT)
# 输出低电平
GPIO.output(PIN, GPIO.LOW)
# index
i = 0
# max
# n = 7
# 类型转换,str => int
n = int(arg1)
print("n =", n)
print('开始闪烁⏳')
while (i < n):
print("i =", i)
# 高电平,LED 点亮
GPIO.output(PIN, GPIO.HIGH)
# 休眠 1 秒,防止 LED 长时间点亮烧坏了
time.sleep(1.0)
# 低电平,LED 熄灭
GPIO.output(PIN, GPIO.LOW)
# 休眠 1 秒
time.sleep(1.0)
i = i + 1
# 输出低电平,LED 关闭
# GPIO.output(PIN, GPIO.LOW)
# 清除,释放内存
GPIO.cleanup()
print('结束闪烁
标签:sudo,Pin,--,Minicom,apt,machine,GPIO
From: https://www.cnblogs.com/xgqfrms/p/17275859.html