“端口扩展”的版本间的差异
来自Labplus盛思维基百科
Tangliufeng(讨论 | 贡献) (→MicroPython示例) |
Tangliufeng(讨论 | 贡献) (→使用教程) |
||
第21行: | 第21行: | ||
== 使用教程 == | == 使用教程 == | ||
+ | <pre style="color:blue"> | ||
+ | |||
+ | <pre/> | ||
=== 连接示意图 === | === 连接示意图 === | ||
=== Arduino示例 === | === Arduino示例 === | ||
第26行: | 第29行: | ||
<pre style="color:blue"> | <pre style="color:blue"> | ||
from microbit import * | from microbit import * | ||
+ | |||
+ | def readExtendedPort(pin): #读端口拓展引脚 | ||
+ | reg=bytearray([0x00])] | ||
+ | i2c.write(0x20, reg) | ||
+ | dat=i2c.read(0x20, 4) | ||
+ | return dat[0] & (2**pin) | ||
display.off() | display.off() | ||
第32行: | 第41行: | ||
while True: | while True: | ||
+ | print(readExtendedPort(1)) #读端口1引脚 | ||
cfg = bytearray([0x01, 0x00]) | cfg = bytearray([0x01, 0x00]) | ||
i2c.write(0x20,cfg) #配置输出引脚寄存器0x01,8个IO引脚设为输出低电平 | i2c.write(0x20,cfg) #配置输出引脚寄存器0x01,8个IO引脚设为输出低电平 | ||
第38行: | 第48行: | ||
i2c.write(0x20,cfg) | i2c.write(0x20,cfg) | ||
sleep(1000) | sleep(1000) | ||
+ | |||
</pre> | </pre> | ||
=== 图形化示例 === | === 图形化示例 === |
2017年12月20日 (三) 15:38的版本
概述
当主控的引脚不够用时,可用该模块通过I2C接口拓展I/O口,最大支持8个I/O引脚拓展。
技术参数
- 工作电压:3.3V~5V
- I2C数字信号通讯
- 最大支持8个I/O端口拓展
- 模块尺寸:24x46x7.5mm
引脚定义
VCC | 电源 |
SDA | I2C数据 |
SCL | I2C时钟 |
GND | 地 |
使用教程
<pre/> === 连接示意图 === === Arduino示例 === === MicroPython示例 === <pre style="color:blue"> from microbit import * def readExtendedPort(pin): #读端口拓展引脚 reg=bytearray([0x00])] i2c.write(0x20, reg) dat=i2c.read(0x20, 4) return dat[0] & (2**pin) display.off() cfg=bytearray([0x03, 0x00]) i2c.write(0x20,cfg) #配置引脚的配置寄存器0x03,8个IO引脚设为输出模式,从机地址为0x20 while True: print(readExtendedPort(1)) #读端口1引脚 cfg = bytearray([0x01, 0x00]) i2c.write(0x20,cfg) #配置输出引脚寄存器0x01,8个IO引脚设为输出低电平 sleep(1000) cfg = bytearray([0x01, 0xFF]) #配置输出引脚寄存器0x01,8个IO引脚设为输出低电平 i2c.write(0x20,cfg) sleep(1000)