Skip to content

Commit 4238d64

Browse files
committed
add pyBLE-NRF52840
add SAMPLES
1 parent 3ae065b commit 4238d64

138 files changed

Lines changed: 901 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'''
2+
实验名称:点亮LED蓝灯
3+
版本:v1.0
4+
日期:2020.4
5+
作者:01Studio
6+
'''
7+
#导入相关模块
8+
9+
import board
10+
from digitalio import DigitalInOut, Direction, Pull
11+
12+
#构建LED对象和初始化
13+
led = DigitalInOut(board.BLUE_LED) #定义引脚编号
14+
led.direction = Direction.OUTPUT #IO为输出
15+
16+
led.value = True #输出高电平,点亮LED
17+
18+
#阻塞IO,让程序保持运行
19+
while True:
20+
pass
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
'''
2+
实验名称:按键(GPIO)
3+
版本:v1.0
4+
日期:2020.4
5+
作者:01Studio
6+
'''
7+
8+
#导入相关模块
9+
import board
10+
from digitalio import DigitalInOut, Direction, Pull
11+
12+
#构建LED对象和初始化
13+
led = DigitalInOut(board.BLUE_LED) #定义引脚编号
14+
led.direction = Direction.OUTPUT #IO为输出
15+
16+
#构建按键对象和初始化
17+
switch = DigitalInOut(board.SWITCH) #定义引脚编号
18+
switch.direction = Direction.INPUT #IO为输入
19+
switch.pull = Pull.UP #打开上拉电阻
20+
21+
while True:
22+
23+
if switch.value == 0: #按键被按下
24+
led.value = True #点亮LED
25+
26+
else:
27+
led.value = False #关闭LED
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'''
2+
实验名称:ADC
3+
版本:v1.0
4+
日期:2020.4
5+
说明:0-3.3V电压测量
6+
www.01studio.org
7+
'''
8+
9+
#导入相关库
10+
import time
11+
import board
12+
from analogio import AnalogIn
13+
14+
adc = AnalogIn(board.A5) #输入IO
15+
16+
while True:
17+
#输出电压,保留2位小数。精度16bit
18+
print(round(adc.value*3.3/65535,2))
19+
time.sleep(0.1) #测量周期100ms
20+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
'''
2+
实验名称:PWM
3+
版本:v1.0
4+
日期:2020.4
5+
作者:01Studio
6+
说明:输出PWM控制蜂鸣器发出不同频率声音
7+
'''
8+
9+
#导入相关模块
10+
import board
11+
from pulseio import PWMOut
12+
import time
13+
14+
#PWM构建,蜂鸣器引脚A4. frequency值必须大于3,否则报错
15+
PWM = PWMOut(board.A4, duty_cycle=32768,frequency=200,variable_frequency=True)
16+
17+
#循环发出不同频率响声。
18+
while True:
19+
20+
PWM.frequency = 200
21+
time.sleep(1)
22+
23+
PWM.frequency = 400
24+
time.sleep(1)
25+
26+
PWM.frequency = 600
27+
time.sleep(1)
28+
29+
PWM.frequency = 800
30+
time.sleep(1)
31+
32+
PWM.frequency = 1000
33+
time.sleep(1)
Binary file not shown.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
'''
2+
实验名称:I2C总线(OLED显示屏)
3+
版本:v1.0
4+
日期:2020.4
5+
作者:01Studio
6+
实验内容:学习使用MicroPython的I2C总线通讯编程和OLED显示屏的使用。
7+
'''
8+
9+
#导入相关模块
10+
import time,board,busio
11+
from digitalio import DigitalInOut
12+
import adafruit_ssd1306
13+
14+
15+
#构建I2C对象
16+
i2c = busio.I2C(board.SCK, board.MOSI)
17+
18+
#构建oled对象,01Studio配套的OLED地址为0x3C
19+
display = adafruit_ssd1306.SSD1306_I2C(128, 64, i2c, addr=0x3C)
20+
21+
#清屏
22+
display.fill(0)
23+
display.show()
24+
25+
#画点(x,y,color)
26+
display.pixel(5, 5, 1)
27+
28+
#画线(x, y, width, color)
29+
display.hline(5,10,20,1)
30+
31+
#画矩形(x, y, width, height, color, *, fill=False)
32+
display.rect(5, 15, 20, 10, 1)
33+
34+
#画圆
35+
display.circle(50, 15, 10, 1)
36+
37+
#字符
38+
display.text("Hello 01Studio!", 5, 40, 1,font_name='font5x8.bin')
39+
40+
#显示
41+
display.show()
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
'''
2+
实验名称:UART(串口通讯)
3+
版本:v1.0
4+
日期:2020.4
5+
作者:01Studio
6+
'''
7+
8+
#导入相关模块
9+
import board
10+
import busio
11+
12+
#串口初始化
13+
uart = busio.UART(board.TX, board.RX, baudrate=9600)
14+
15+
#发送数据,要求字节数组
16+
uart.write(b'Hello 01Studio!')
17+
18+
while True:
19+
20+
data = uart.read(64) #最多接收64个字节
21+
22+
if len(data) != 0: #有数据
23+
print(data) #REPL打印
24+
uart.write(data) #数据回发
Binary file not shown.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
'''
2+
实验名称:温度传感器DS18B20
3+
版本:v1.0
4+
日期:2020.4
5+
作者:01Studio
6+
实验内容:采集温度数据并在oled上显示。
7+
'''
8+
9+
#导入相关模块
10+
import time,board,busio
11+
from digitalio import DigitalInOut
12+
import adafruit_ssd1306
13+
14+
#DS18X20库模块
15+
from adafruit_onewire.bus import OneWireBus
16+
from adafruit_ds18x20 import DS18X20
17+
18+
19+
#构建I2C对象
20+
i2c = busio.I2C(board.SCK, board.MOSI)
21+
22+
#构建oled对象,01Studio配套的OLED地址为0x3C
23+
display = adafruit_ssd1306.SSD1306_I2C(128, 64, i2c, addr=0x3C)
24+
25+
#清屏
26+
display.fill(0)
27+
display.show()
28+
29+
# 初始化单总线对象,引脚为D5.
30+
ow = OneWireBus(board.D5)
31+
32+
# 搜索传感器,返回第1个
33+
ds = DS18X20(ow, ow.scan()[0])
34+
35+
while True:
36+
37+
temp=round(ds.temperature,2) #保留2位小数
38+
39+
display.fill(0) #清屏
40+
display.text('01Studio', 0,0, 1,font_name='font5x8.bin')
41+
display.text('Temp Test', 0,20, 1,font_name='font5x8.bin')
42+
display.text(str(temp)+' C', 0,40, 1,font_name='font5x8.bin')
43+
display.show()
44+
45+
print(str(temp)+' C')
46+
47+
time.sleep(1)
Binary file not shown.

0 commit comments

Comments
 (0)