bluebit --- blue:bit驱动

blue:bit 模块提供bluebit套件的掌控板库。

../../../../../_images/wiki_labplus_cn_3477ac8b17.png

NTC模块

class bluebit.Thermistor(pin, series_resistor=10000.0, nominal_resistance=10000.0, nominal_temperature=25.0, b_coefficient=3935.0, high_side=True)

NTC 模块。也适用于其他的热敏电阻。

参数:
  • pin -- 掌控板引脚号,如使用P0,pin=0.

  • series_resistor -- 与热敏电阻连接的串联电阻器的值。默认是10K电阻。

  • nominal_resistance -- 在标称温度下热敏电阻的阻值。

  • nominal_temperature -- 在标称电阻值下热敏电阻的温度值(以摄氏度为单位)。默认使用25.0摄氏度。

  • b_coefficient -- 热敏电阻的温度系数。

  • high_side -- 表示热敏电阻是连接在电阻分压器的高侧还是低侧。默认high_side为True。

getTemper()

获取温度,读取异常则返回None

返回:

温度,单位摄氏度

bluebit.NTC

Thermistor 的别名

LM35模块

class bluebit.LM35(pin)

LM35 模块

参数:

pin -- 掌控板引脚号,如使用P0,pin=0.

getTemper()

获取温度

返回:

温度,单位摄氏度

四按键模块

class bluebit.joyButton(pin)

四按键模块

参数:

pin -- 掌控板引脚号,如使用P0,pin=0.

getVal()

获取按键

返回:

返回按键,值可以是'A','B','C','D',无按键按下'None'.

温湿度模块

class bluebit.SHT20(i2c=machine.I2C)

温湿度模块SHT20控制类

参数:

i2c -- I2C实例对象,默认i2c=i2c.

temperature()

获取温度

返回:

温度,单位摄氏度

humidity()

获取湿度

返回:

湿度,单位%

颜色模块

class bluebit.Color(i2c=machine.I2C)

颜色模块控制类

参数:

i2c -- I2C实例对象,默认i2c=i2c.

getRGB()

获取RGB值

返回:

返回RGB三元组,(r,g,b)

getHSV()

获取HSV值

返回:

返回HSV三元组,(h,s,v)

数字光线模块

class bluebit.AmbientLight(i2c=machine.I2C)

数字光线模块控制类

参数:

i2c -- I2C实例对象,默认i2c=i2c.

getLight()

获取光线值

返回:

返回光线值,单位lux

超声波模块

class bluebit.Ultrasonic(i2c=machine.I2C)

超声波模块控制类

参数:

i2c -- I2C实例对象,默认i2c=i2c.

distance()

获取超声波测距

返回:

返回测距,单位cm

4段数码管模块

class bluebit.SEGdisplay(i2c=machine.I2C)

4段数码管模块tm1650控制类

参数:

i2c -- I2C实例对象,默认i2c=i2c.

numbers(x)

数字显示-999~9999

参数:

x (int) -- 数字,范围-999~9999

Clear()

数码管清屏

8x8点阵模块

class bluebit.Matrix(i2c=i2c)

8x8点阵模块控制类

  • i2c : I2C实例对象,默认i2c=i2c.

设置像素点闪烁率

  • rate : 闪烁间隔时间,单位秒.默认None,常亮.

Matrix.brightness(brightness)

设置像素点亮度

  • brightness : 亮度级别,范围0~15.

Matrix.fill(color)

填充所有

  • color : 1亮;0灭

Matrix.bitmap(bitmap)

显示位图

  • bitmap : 8x8点阵数据

Matrix.show()

显示生效

除上述函数方法外,还继承 FrameBuffer 类 ,有关其他方法,如显示字符,绘制函数。详情可查阅 micropython framebuf模块 FrameBuffer 类.

LCD1602模块

class bluebit.LCD1602(i2c=machine.I2C)

LCD1602模块控制类

参数:

i2c -- I2C实例对象,默认i2c=i2c.

LEFT_TO_RIGHT = 0

文本方向常量-从左到右

RIGHT_TO_LEFT = 1

文本方向常量-从右到左

Init()

1602初始化函数

Print(str)

打印字符串

参数:

str (str) -- 显示字符串,只支持英文.

Clear()

清屏

setCursor(col, row)

设置光标位置

参数:
  • col -- 列,1~16

  • row -- 行,1~2

Cursor(show)

光标显示使能

参数:

show (bool) -- True or False

光标闪烁使能

参数:

blink (bool) -- True or False

display(enable)

显示使能

参数:

enable (bool) -- True or False

move_left()

左滚动显示

move_right()

右滚动显示

property text_direction

文本方向

createChar(location, charmap=[])

制作用户自定义 Fill one of the first 8 CGRAM locations with custom characters. The location parameter should be between 0 and 7 and pattern should provide an array of 8 bytes containing the pattern. E.g. you can easily design your custom character at http://www.quinapalus.com/hd44780udg.html To show your custom character use

参数:
  • location -- integer in range(8) to store the created character

  • pattern (~bytes) -- len(8) describes created character

Home()

光标返回屏幕原点

MIDI模块

class bluebit.MIDI(tx)

MIDI模块控制类

参数:

i2c -- I2C实例对象,默认i2c=i2c.

property volume

设置或返回音量

property instrument

设置或返回音色

note(note, on_off)

播放音符

参数:
  • note -- MIDI音符编码

  • on_off -- 音符播放或停止

MP3模块

class bluebit.MP3(tx=-1, rx=-1, uart_num=1)

MP3模块控制类

参数:

i2c -- I2C实例对象,默认i2c=i2c.

play_song(num)

播放歌曲

参数:

num (int) -- 歌曲编号,类型为数字

play()

播放,用于暂停后的重新播放

playDir(dir, songNo)

播放指定文件夹指定歌曲

参数:
  • dir (int) -- 文件夹编号,类型数字

  • songNo (int) -- 歌曲编号,类型为数字

playNext()

播下一首

playPrev()

播上一首

pause()

暂停播放

stop()

停止播放

volumeInc()

增加音量

volumeDec()

减小音量

loop(songNo)

目录内指定序号歌曲循环播放

参数:

songNo (int) -- 歌曲编号,类型为数字

loopDir(dir)

指定目录内循环播放

参数:

dir (int) -- 文件夹编号,类型数字

singleLoop(onOff)

单曲循环开关

参数:

onOff (int) -- 0:不循环 1:循环

property volume

设置或返回音量设置,范围0~30

resetDevice()

复位MP3

OLED模块

class bluebit.OLEDBit(*args: Any, **kwargs: Any)

bluebit OLED模块类

参数:

rx,tx -- 接收,发送引脚

font_5x7 = 0

字体常量-5*7英文字体

font_song16 = 1

字体常量-16*16宋体

font_song24 = 2

字体常量-24*24宋体

font_consol32 = 3

字体常量-32*32宋体

Print(str, x, y, font=micropython.const)

显示中英文字符串,支持字体 '0' =Font5x7, '1' = 宋体16x16, '2' = 宋体24x24, '3' = Consolas32x32

参数:
  • str (str) -- 中英文字符串

  • y (int x) -- 显示坐标

  • font -- 字体类型, font_5x7 , font_song24 , font_consol32 ;

clear(x0=0, y0=0, x1=127, y1=63)

清除,默认全屏清除,也可以局部清除

参数:
  • y0 (int x0) -- 抹去区域左上坐标

  • y1 (int x1) -- 抹去区域右下坐标

show()

显示生效,当使用framebuf类方法后使用show()刷新屏幕.

Bitmap(x, y, bitmap, w, h, c)

显示图案

参数:
  • y (int x) -- 起点坐标

  • bitmap -- 图案1bit数据

  • w,h -- 图案宽高

  • c -- 颜色,1 or 0

红外接收模块

class bluebit.IRRecv(rx, uart_id=1)

红外接收模块

参数:
  • rx -- 接收引脚设置

  • uart_id -- 串口号:1、2

recv()

接收数据

Return int:

返回红外值,类型整形

红外发射模块

class bluebit.IRTrans(tx, uart_id=2)

红外发射模块

参数:
  • tx -- 发送引脚设置

  • uart_id -- 串口号:1、2

transmit(byte)

发送数据

参数:

byte (byte) -- 发送数据,单字节

实验探究类

适用的模块有电压、电流、磁场、电导率、PH、光电门、气压、力传感器。

class bluebit.DelveBit(address, i2c=machine.I2C)

实验探究类的blue:bit,适用的模块有电压、电流、磁场、电导率、PH、光电门、气压、力传感器

参数:
  • address -- 模块的I2C地址,可再模块拨动选择不同的地址避免冲突。

  • i2c -- I2C实例对象,默认i2c=i2c

common_measure()

获取实验探究类传感器测量值的通用函数

Return int:

返回传感器测量值,单位:电压(V)、电流(A)、磁场(mT)、电导率(uS/cm)、PH(pH)、光电门(s)、气压(kPa)、力传感器(N)

photo_gate()

Photogate Timer 是用来记录刚触发时刻和触发结束时刻的时间。计算信号的正脉宽时间,当输入信号由低变高为触发开始点,由高变低位触发触发结束点,计算之间的时间差。

Return int:

返回正脉宽时间,单位秒

编码电机模块

class bluebit.EncoderMotor(address, i2c=machine.I2C)

blue:bit编码电机驱动,提供pwm、cruise、position 三种驱动方式。

参数:
  • address -- 模块的I2C地址,可再模块拨动选择不同的地址避免冲突。

  • i2c -- I2C实例对象,默认i2c=i2c

PWM_MODE = b'\x05'

pwm模式

CRUISE_MODE = b'\n'

巡航模式

POSITION_MODE = b'\x0f'

定位模式

motor_stop()

停止编码电机转动

set_pwm(speed1, speed2)

pwm模式

参数:
  • speed1 -- 设置M1通道编码电机速度,范围-1023~1023

  • speed2 -- 设置M2通道编码电机速度,范围-1023~1023

set_cruise(speed1, speed2)

Cruise巡航模式,设定速度后,当编码电机受阻时,会根据反馈,自动调整扭力,稳定在恒定的速度。

参数:
  • speed1 -- 设置M1通道编码电机速度,范围-1023~1023

  • speed2 -- 设置M2通道编码电机速度,范围-1023~1023

set_position(turn1, turn2)

定位模式,可设置编码编码电机定点位置,范围-1023~1023。

参数:
  • turn1 -- 设置M1通道编码电机定位,-1023~1023

  • turn2 -- 设置M2通道编码电机定位,-1023~1023

RFID模块

class bluebit.Scan_Rfid

扫描Rfid卡类.

classmethod scanning(i2c=machine.I2C)

扫描RFID卡,返回Rfid对象

参数:

i2c (obj) -- I2C实例对象

返回:

返回Rfid对象

class bluebit.Rfid(i2c, serial_number)

Rfid类,提供读写block和电子钱包操作。

参数:
  • i2c -- I2C实例对象

  • serial_number -- RFID卡序列号

serial_number()

获取序列号

auth(block_number=1)
read_block(block_number=1)

读取块数据,长度16字节

参数:

block_number -- 块编号

write_block(buf, block_number=1)

写块数据,长度16字节

参数:
  • buf (bytes) -- 块编号

  • block_number (int) -- 块编号

set_purse(block_number=1)

设置电子钱包,默认使用block 1。

参数:

block_number (int) -- 块编号

get_balance()

获取电子钱包余额。使用该函数前,必须对数据块进行 set_purse() 设置。

返回:

返回余额

increment(value)

给电子钱包充值。使用该函数前,必须对数据块进行 set_purse() 设置。

参数:

value (int) -- 充值

decrement(value)

给电子钱包扣费。使用该函数前,必须对数据块进行 set_purse() 设置。

参数:

value (int) -- 扣费