Skip to content

Commit 776a108

Browse files
committed
【添加】w601 硬件控制模块示例
1 parent 7b8b7fb commit 776a108

File tree

8 files changed

+155
-0
lines changed

8 files changed

+155
-0
lines changed

examples/w601_iot_board/adc.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Copyright (c) 2006-2019, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: MIT License
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2019-06-13 SummerGift first version
9+
*/
10+
11+
from machine import ADC # 从 machine 导入 ADC 类
12+
13+
adc = ADC(2, 5) # 创建 ADC 对象,当前使用编号为 2 的 ADC 设备的 5 通道
14+
adc.read() # 获取 ADC 对象采样值
15+
adc.deinit() # 关闭 ADC 对象
16+
adc.init(5) # 开启并重新配置 ADC 对象

examples/w601_iot_board/i2c.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright (c) 2006-2019, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: MIT License
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2019-06-13 SummerGift first version
9+
*/
10+
11+
from machine import Pin, I2C
12+
13+
clk = Pin(("clk", 43), Pin.OUT_OD) # Select the 43 pin device as the clock
14+
sda = Pin(("sda", 44), Pin.OUT_OD) # Select the 44 pin device as the data line
15+
i2c = I2C(-1, clk, sda, freq=100000) # create I2C peripheral at frequency of 100kHz
16+
i2c.scan() # scan for slaves, returning a list of 7-bit addresses
17+
i2c.writeto(0x51, b'123') # write 3 bytes to slave with 7-bit address 42
18+
i2c.readfrom(0x51, 4) # read 4 bytes from slave with 7-bit address 42
19+
i2c.readfrom_mem(0x51, 0x02, 1) # read 1 bytes from memory of slave 0x51(7-bit)
20+
i2c.writeto_mem(0x51, 2, b'\x10') # write 1 byte to memory of slave 42

examples/w601_iot_board/lcd.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright (c) 2006-2019, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: MIT License
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2019-06-13 SummerGift first version
9+
*/
10+
11+
from machine import LCD # 从 machine 导入 LCD 类
12+
13+
lcd = LCD() # 创建一个 lcd 对象
14+
lcd.light(False) # 关闭背光
15+
lcd.light(True) # 打开背光
16+
lcd.fill(lcd.BLACK) # 将整个 LCD 填充为黑色
17+
lcd.fill(lcd.RED) # 将整个 LCD 填充为红色
18+
lcd.fill(lcd.GRAY) # 将整个 LCD 填充为灰色
19+
lcd.fill(lcd.WHITE) # 将整个 LCD 填充为白色
20+
lcd.pixel(50, 50, lcd.BLUE) # 将(50,50)位置的像素填充为蓝色
21+
lcd.text("hello RT-Thread", 0, 0, 16) # 在(0, 0) 位置以 16 字号打印字符串
22+
lcd.text("hello RT-Thread", 0, 16, 24) # 在(0, 16)位置以 24 字号打印字符串
23+
lcd.text("hello RT-Thread", 0, 48, 32) # 在(0, 48)位置以 32 字号打印字符串
24+
lcd.line(0, 50, 239, 50) # 以起点(0,50),终点(239,50)画一条线
25+
lcd.line(0, 50, 239, 50) # 以起点(0,50),终点(239,50)画一条线
26+
lcd.rectangle(100, 100, 200, 200) # 以左上角为(100,100),右下角(200,200)画矩形
27+
lcd.circle(150, 150, 80) # 以圆心位置(150,150),半径为 80 画圆

examples/w601_iot_board/pin.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Copyright (c) 2006-2019, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: MIT License
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2019-06-13 SummerGift first version
9+
*/
10+
11+
from machine import Pin
12+
13+
p_out = Pin(("X1", 33), Pin.OUT_PP)
14+
p_out.value(1) # set io high
15+
p_out.value(0) # set io low
16+
17+
p_in = Pin(("X2", 32), Pin.IN, Pin.PULL_UP)
18+
p_in.value() # get value, 0 or 1

examples/w601_iot_board/pwm.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright (c) 2006-2019, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: MIT License
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2019-06-13 SummerGift first version
9+
*/
10+
11+
from machine import PWM # 从 machine 导入 PWM 类
12+
13+
pwm = PWM(1, 4, 1000, 100) # 创建 PWM 对象,当前使用编号为 1 的 PWM 设备的 4 通道,初始化的频率为 1000Hz,占空比数值为 100(占空比为 100/255 = 39.22%)
14+
pwm.freq(2000) # 设置 PWM 对象频率
15+
pwm.freq() # 获取 PWM 对象频率
16+
pwm.duty(200) # 设置 PWM 对象占空比数值
17+
pwm.duty() # 获取 PWM 对象占空比数值
18+
pwm.deinit() # 关闭 PWM 对象
19+
pwm.init(4, 1000, 100) # 开启并重新配置 PWM 对象

examples/w601_iot_board/rtc.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* Copyright (c) 2006-2019, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: MIT License
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2019-06-13 SummerGift first version
9+
*/
10+
11+
from machine import RTC
12+
13+
rtc = RTC() # 创建 RTC 设备对象
14+
rtc.init((2019,6,5,2,10,22,30,0)) # 设置初始化时间
15+
rtc.now() # 获取当前时间
16+
rtc.deinit() # 重置时间到2015年1月1日
17+
rtc.now() # 获取当前时间

examples/w601_iot_board/spi.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright (c) 2006-2019, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: MIT License
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2019-06-13 SummerGift first version
9+
*/
10+
11+
from machine import Pin, SPI
12+
13+
clk = Pin(("clk", 43), Pin.OUT_PP)
14+
mosi = Pin(("mosi", 44), Pin.OUT_PP)
15+
miso = Pin(("miso", 45), Pin.IN)
16+
spi = SPI(-1, 500000, polarity = 0, phase = 0, bits = 8, firstbit = 0, sck = clk, mosi = mosi, miso = miso)
17+
print(spi)
18+
spi.write("hello rt-thread!")
19+
spi.read(10)

examples/w601_iot_board/uart.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright (c) 2006-2019, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: MIT License
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2019-06-13 SummerGift first version
9+
*/
10+
11+
from machine import UART
12+
13+
uart = UART(1, 9600) # init with given baudrate
14+
uart.init(9600, bits=8, parity=None, stop=1) # init with given parameters
15+
uart.read(10) # read 10 characters, returns a bytes object
16+
uart.read() # read all available characters
17+
uart.readline() # read a line
18+
uart.readinto(buf) # read and store into the given buffer
19+
uart.write('abc') # write the 3 characters

0 commit comments

Comments
 (0)