micropython编程爱好网

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 11573|回复: 8

OpenMV Cam快速参考

[复制链接]

24

主题

24

帖子

2318

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
2318
发表于 2021-9-23 09:17:40 | 显示全部楼层 |阅读模式
OpenMV Cam快速参考通用硬件控制

See pyb.

  1. import pyb

  2. pyb.repl_uart(pyb.UART(3, 9600, timeout_char=1000)) # duplicate REPL on UART(3) 在UART(3)上重置REPL
  3. pyb.wfi() # pause CPU, waiting for interrupt 暂停cpu,等待中断
  4. pyb.stop() # stop CPU, waiting for external interrupt 停止cpu,等待外部中断
复制代码



延时和时间

Use the time module:

  1. import utime

  2. time.sleep(1)           # sleep for 1 second 延时1s
  3. time.sleep_ms(500)      # sleep for 500 milliseconds 延时500ms
  4. time.sleep_us(10)       # sleep for 10 microseconds 延时10us
  5. start = time.ticks_ms() # get value of millisecond counter  获取毫秒计数器的值
  6. delta = time.ticks_diff(time.ticks_ms(), start) # compute time difference 计算时间差
复制代码



LED 发光二极管

See pyb.LED.

  1. from pyb import LED

  2. led = LED(1) # 红色 led
  3. led.toggle()
  4. led.on()
  5. led.off()
复制代码

LED Pinout:

  • LED(1) -> 红色 RGB LED Segment
  • LED(2) -> 绿色 RGB LED Segment
  • LED(3) -> 蓝色 RGB LED Segment
  • LED(4) -> 红外 LEDs

引脚和GPIO

See pyb.Pin.

  1. from pyb import Pin

  2. p_out = Pin('P7', Pin.OUT_PP)
  3. p_out.high()
  4. p_out.low()

  5. p_in = Pin('P8', Pin.IN, Pin.PULL_UP)
  6. p_in.value() # get value, 0 or 1
复制代码

GPIO引脚分配:

  • Pin(‘P0’) -> P0 (PB15)
  • Pin(‘P1’) -> P1 (PB14)
  • Pin(‘P2’) -> P2 (PB13)
  • Pin(‘P3’) -> P3 (PB12)
  • Pin(‘P4’) -> P4 (PB10)
  • Pin(‘P5’) -> P5 (PB11)
  • Pin(‘P6’) -> P6 (PA5)
  • Pin(‘P7’) -> P7 (PD12)
  • Pin(‘P8’) -> P8 (PD13)
  • Pin(‘P9’) -> P9 (PD14) (只在OpenMV Cam M7/H7)

所有引脚适配范围为5V,其输出为3V(在ADC或DAC模式下,P6的适配范围并不是5V)。

所有引脚最高输入或者输出25mA(所有引脚加起来最高120mA)。


舵机控制

pyb.Servo.

  1. from pyb import Servo

  2. s1 = Servo(1) # servo on position 1 (P7) 位置1的servo(P7)
  3. s1.angle(45) # move to 45 degrees 移动到45度
  4. s1.angle(-60, 1500) # move to -60 degrees in 1500ms 在1500ms内移动到-60度
  5. s1.speed(50) # for continuous rotation servos 连续旋转舵机
复制代码


Servo Pinout:

  • Servo(1) -> P7 (PD12)
  • Servo(2) -> P8 (PD13)
  • Servo(3) -> P9 (PD14) (OpenMV Cam M7/H7 Only)

外部中断

See pyb.ExtInt.

  1. from pyb import Pin, ExtInt

  2. callback = lambda e: print("intr")
  3. ext = ExtInt(Pin('P7'), ExtInt.IRQ_RISING, Pin.PULL_NONE, callback)
复制代码

GPIO Pinout:

  • Pin(‘P0’) -> P0 (PB15)
  • Pin(‘P1’) -> P1 (PB14)
  • Pin(‘P2’) -> P2 (PB13)
  • Pin(‘P3’) -> P3 (PB12)
  • Pin(‘P4’) -> P4 (PB10)
  • Pin(‘P5’) -> P5 (PB11)
  • Pin(‘P6’) -> P6 (PA5)
  • Pin(‘P7’) -> P7 (PD12)
  • Pin(‘P8’) -> P8 (PD13)
  • Pin(‘P9’) -> P9 (PD14) (只在OpenMV Cam M7/H7)

定时器

See pyb.Timer.

  1. from pyb import Timer

  2. tim = Timer(4, freq=1000)
  3. tim.counter() # get counter value 获取计时器值
  4. tim.freq(0.5) # 0.5 Hz
  5. tim.callback(lambda t: pyb.LED(1).toggle())
复制代码

定时器引脚分配:

  • Timer 1 Channel 3 Negative -> P0 (PB15)
  • Timer 1 Channel 2 Negative -> P1 (PB14)
  • Timer 1 Channel 1 Negative -> P2 (PB13)
  • Timer 2 Channel 3 Positive -> P4 (PB10)
  • Timer 2 Channel 4 Positive -> P5 (PB11)
  • Timer 2 Channel 1 Positive -> P6 (PA5)
  • Timer 4 Channel 1 Negative -> P7 (PD12)
  • Timer 4 Channel 2 Negative -> P8 (PD13)
  • Timer 4 Channel 3 Positive -> P9 (PD14) (OpenMV Cam M7/H7 Only)

PWM脉宽调制

See pyb.Pin and pyb.Timer.

  1. from pyb import Pin, Timer

  2. p = Pin('P7') # P7 has TIM4, CH1
  3. tim = Timer(4, freq=1000)
  4. ch = tim.channel(1, Timer.PWM, pin=p)
  5. ch.pulse_width_percent(50)
复制代码

定时器引脚分配:

  • Timer 1 Channel 3 Negative -> P0 (PB15)
  • Timer 1 Channel 2 Negative -> P1 (PB14)
  • Timer 1 Channel 1 Negative -> P2 (PB13)
  • Timer 2 Channel 3 Positive -> P4 (PB10)
  • Timer 2 Channel 4 Positive -> P5 (PB11)
  • Timer 2 Channel 1 Positive -> P6 (PA5)
  • Timer 4 Channel 1 Negative -> P7 (PD12)
  • Timer 4 Channel 2 Negative -> P8 (PD13)
  • Timer 4 Channel 3 Positive -> P9 (PD14) (OpenMV Cam M7/H7 Only)

ADC (模数转换)

pyb.Pinpyb.ADC.

  1. from pyb import Pin, ADC

  2. adc = ADC(Pin('P6'))
  3. adc.read() # read value, 0-4095 读取值,0-4095
复制代码


ADC 引脚分配:

  • ADC(Pin(‘P6’)) -> P6 (PA5)

ADC模式下,P6的适配范围为3.3V,而不是5V!


DAC (数模转换)

pyb.Pin and pyb.DAC.

  1. from pyb import Pin, DAC

  2. dac = DAC('P6')
  3. dac.write(120) # 输出介于0-255
复制代码

DAC 引脚分配:

  • DAC(Pin(‘P6’)) -> P6 (PA5)

DAC模式下,P6的适配范围为3.3V,而不是5V!


UART (串行总线)

See pyb.UART.

  1. from pyb import UART

  2. uart = UART(3, 9600, timeout_char=1000)
  3. uart.write('hello')
  4. uart.read(5) # read up to 5 bytes 读取5个字节
复制代码

UART Pinout:

  • UART 3 RX -> P5 (PB11)
  • UART 3 TX -> P4 (PB10)
  • UART 1 RX -> P0 (PB15) (只在OpenMV Cam M7/H7)
  • UART 1 TX -> P1 (PB14) (只在OpenMV Cam M7/H7)

SPI总线

pyb.SPI.

  1. from pyb import SPI

  2. spi = SPI(2, SPI.MASTER, baudrate=1000000, polarity=1, phase=0)
  3. spi.send('hello')
  4. spi.recv(5) # receive 5 bytes on the bus 在总线上接收5个字节
  5. spi.send_recv('hello') # send a receive 5 bytes 发送5个字节
复制代码


SPI 引脚分配:

  • SPI 2 MOSI (Master-Out-Slave-In) -> P0 (PB15)
  • SPI 2 MISO (Master-In-Slave-Out) -> P1 (PB14)
  • SPI 2 SCLK (Serial Clock) -> P2 (PB13)
  • SPI 2 SS (Serial Select) -> P3 (PB12)

I2C总线

See pyb.I2C.

  1. from pyb import I2C

  2. i2c = I2C(2, I2C.MASTER, baudrate=100000)
  3. i2c.scan() # returns list of slave addresses 返回一个从属设备地址的列表
  4. i2c.send('hello', 0x42) # send 5 bytes to slave with address 0x42 使用0x42地址向从属设备发送5个字节
  5. i2c.recv(5, 0x42) # receive 5 bytes from slave 从从属设备上接收5个字节
  6. i2c.mem_read(2, 0x42, 0x10) # read 2 bytes from slave 0x42, slave memory 0x10 从地址为0x42从属设备上接收2个字节,从属存储器为0x10
  7. i2c.mem_write('xy', 0x42, 0x10) # write 2 bytes to slave 0x42, slave memory 0x10 向地址为0x42的从属设备写入2个字节,从属存储器为0x10
复制代码

I2C 引脚分配:

  • I2C 2 SCL (Serial Clock) -> P4 (PB10)
  • I2C 2 SDA (Serial Data) -> P5 (PB11)
  • I2C 4 SCL (Serial Clock) -> P7 (PD13) (OpenMV Cam M7/H7 Only)
  • I2C 4 SDA (Serial Data) -> P8 (PD12) (OpenMV Cam M7/H7 Only)

回复

使用道具 举报

0

主题

11

帖子

46

积分

新手上路

Rank: 1

积分
46
发表于 2021-9-23 23:15:52 | 显示全部楼层

-

Casual concurrence
回复

使用道具 举报

0

主题

28

帖子

84

积分

注册会员

Rank: 2

积分
84
发表于 2021-11-4 14:07:18 | 显示全部楼层

-

I shall afford will disagree
回复

使用道具 举报

0

主题

8

帖子

40

积分

新手上路

Rank: 1

积分
40
发表于 2021-12-3 17:20:15 | 显示全部楼层

-

In my opinion you are mistaken. I suggest it to discuss. Write to me in PM, we will communicate.
Create
回复

使用道具 举报

0

主题

98

帖子

510

积分

高级会员

Rank: 4

积分
510
发表于 2022-4-4 14:26:38 | 显示全部楼层

-

Be assured.
http://defloration.gq/
回复

使用道具 举报

0

主题

98

帖子

510

积分

高级会员

Rank: 4

积分
510
发表于 2022-4-25 23:09:11 | 显示全部楼层

-

very good idea
http://defloration.gq/
回复

使用道具 举报

0

主题

10

帖子

170

积分

注册会员

Rank: 2

积分
170
发表于 2022-5-19 00:10:41 | 显示全部楼层

-

Excellent idea
http://defloration.gq/
回复

使用道具 举报

0

主题

10

帖子

170

积分

注册会员

Rank: 2

积分
170
发表于 2022-6-12 04:51:30 | 显示全部楼层

-

Now all is clear, thanks for the help in this question.
http://defloration.gq/
回复

使用道具 举报

0

主题

1

帖子

6

积分

新手上路

Rank: 1

积分
6
发表于 2023-7-8 04:43:26 | 显示全部楼层

-

In my opinion you are not right. I am assured. Let's discuss. Write to me in PM, we will communicate.
[url=https://restavratsiyavann.com/dyurtyuli/]修复浴缸[/url]
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|micropython编程爱好网 ( 粤ICP备14010847号-3 ) microPython技术交流 microPython技术交流2

粤公网安备 44030702001224号

GMT+8, 2024-4-20 14:02 , Processed in 0.202800 second(s), 19 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表