bluebit — blue:bit driver

blue:bit The module provides the mPython Board library of bluebit kit.

http://wiki.labplus.cn/images/0/07/Bluebit套件1.png

NTC Temperature module

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

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

Parameters:
  • pin – 掌控板引脚号,如使用P0,pin=0.
  • series_resistor – 与热敏电阻连接的串联电阻器的值。默认是10K电阻。
  • nominal_resistance – 在标称温度下热敏电阻的阻值。
  • nominal_temperature – 在标称电阻值下热敏电阻的温度值(以摄氏度为单位)。默认使用25.0摄氏度。
  • b_coefficient – 热敏电阻的温度系数。
  • high_side – 表示热敏电阻是连接在电阻分压器的高侧还是低侧。默认high_side为True。
getTemper()[source]

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

Returns:温度,单位摄氏度
bluebit.NTC

alias of bluebit.Thermistor

LM35 Temperature module

class bluebit.LM35(pin)[source]

LM35 模块

Parameters:pin – 掌控板引脚号,如使用P0,pin=0.
getTemper()[source]

获取温度

Returns:温度,单位摄氏度

Joy Button module

class bluebit.joyButton(pin)[source]

四按键模块

Parameters:pin – 掌控板引脚号,如使用P0,pin=0.
getVal()[source]

获取按键

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

Temperature-Humidity module

class bluebit.SHT20(i2c=<sphinx.ext.autodoc.importer._MockObject object>)[source]

温湿度模块SHT20控制类

Parameters:i2c – I2C实例对象,默认i2c=i2c.
temperature()[source]

获取温度

Returns:温度,单位摄氏度
humidity()[source]

获取湿度

Returns:湿度,单位%

Color module

class bluebit.Color(i2c=<sphinx.ext.autodoc.importer._MockObject object>)[source]

颜色模块控制类

Parameters:i2c – I2C实例对象,默认i2c=i2c.
getRGB()[source]

获取RGB值

Returns:返回RGB三元组,(r,g,b)
getHSV()[source]

获取HSV值

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

Light module

class bluebit.AmbientLight(i2c=<sphinx.ext.autodoc.importer._MockObject object>)[source]

数字光线模块控制类

Parameters:i2c – I2C实例对象,默认i2c=i2c.
getLight()[source]

获取光线值

Returns:返回光线值,单位lux

Ultrasonic module

class bluebit.Ultrasonic(i2c=<sphinx.ext.autodoc.importer._MockObject object>)[source]

超声波模块控制类

Parameters:i2c – I2C实例对象,默认i2c=i2c.
distance()[source]

获取超声波测距

Returns:返回测距,单位cm

4*7 SEG Display module

class bluebit.SEGdisplay(i2c=<sphinx.ext.autodoc.importer._MockObject object>)[source]

4段数码管模块tm1650控制类

Parameters:i2c – I2C实例对象,默认i2c=i2c.
numbers(x)[source]

数字显示-999~9999

Parameters:x (int) – 数字,范围-999~9999
Clear()[source]

数码管清屏

8x8 Matrix module

class bluebit.Matrix(i2c=i2c)[source]

8x8 matrix module control class

  • i2c : I2C instance object, default i2c=i2c.

Set pixel flicker rate

  • rate : Flashing interval time, in seconds. Default is None, always on.
Matrix.brightness(brightness)

Set pixel brightness

  • brightness : Brightness level, range 0~15.
Matrix.fill(color)

Fill all

  • color : 1 ON ; 0 OFF
Matrix.bitmap(bitmap)

Display bitmap

  • bitmap : 8x8 matrix data
Matrix.show()

Display show

In addition to the above function methods, it also inherits the FrameBuffer class, and other methods, such as displaying characters and drawing functions. For details, please refer to the FrameBuffer class of the micropython framebuf module.

LCD1602 module

class bluebit.LCD1602(i2c=<sphinx.ext.autodoc.importer._MockObject object>)[source]

LCD1602模块控制类

Parameters:i2c – I2C实例对象,默认i2c=i2c.
LEFT_TO_RIGHT

文本方向常量-从左到右

RIGHT_TO_LEFT

文本方向常量-从右到左

Init()[source]

1602初始化函数

Print(str)[source]

打印字符串

Parameters:str (str) – 显示字符串,只支持英文.
Clear()[source]

清屏

setCursor(col, row)[source]

设置光标位置

Parameters:
  • col – 列,1~16
  • row – 行,1~2
Cursor(show)[source]

光标显示使能

Parameters:show (bool) – True or False

光标闪烁使能

Parameters:blink (bool) – True or False
display(enable)[source]

显示使能

Parameters:enable (bool) – True or False
move_left()[source]

左滚动显示

move_right()[source]

右滚动显示

text_direction

文本方向

createChar(location, charmap=[])[source]

制作用户自定义 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

Parameters:
  • location – integer in range(8) to store the created character
  • pattern (~bytes) – len(8) describes created character
Home()[source]

光标返回屏幕原点

MIDI module

class bluebit.MIDI(tx)[source]

MIDI模块控制类

Parameters:i2c – I2C实例对象,默认i2c=i2c.
volume

设置或返回音量

instrument

设置或返回音色

note(note, on_off)[source]

播放音符

Parameters:
  • note – MIDI音符编码
  • on_off – 音符播放或停止

MP3 module

class bluebit.MP3(tx)[source]

MP3模块控制类

Parameters:i2c – I2C实例对象,默认i2c=i2c.
play_song(num)[source]

播放歌曲

Parameters:num (int) – 歌曲编号,类型为数字
play()[source]

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

playDir(dir, songNo)[source]

播放指定文件夹指定歌曲

Parameters:
  • dir (int) – 文件夹编号,类型数字
  • songNo (int) – 歌曲编号,类型为数字
playNext()[source]

播下一首

playPrev()[source]

播上一首

pause()[source]

暂停播放

stop()[source]

停止播放

volumeInc()[source]

增加音量

volumeDec()[source]

减小音量

loop(songNo)[source]

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

Parameters:songNo (int) – 歌曲编号,类型为数字
loopDir(dir)[source]

指定目录内循环播放

Parameters:dir (int) – 文件夹编号,类型数字
singleLoop(onOff)[source]

单曲循环开关

Parameters:onOff (int) – 0:不循环 1:循环
volume

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

resetDevice()[source]

复位MP3

OLED module

class bluebit.OLEDBit(rx, tx)[source]

bluebit OLED模块类

Parameters:rx,tx – 接收,发送引脚
font_5x7

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

font_song16

字体常量-16*16宋体

font_song24

字体常量-24*24宋体

font_consol32

字体常量-32*32宋体

Print(str, x, y, font=<sphinx.ext.autodoc.importer._MockObject object>)[source]

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

Parameters:
  • str (str) – 中英文字符串
  • x y (int) – 显示坐标
  • font – 字体类型, font_5x7 , font_song24 , font_consol32 ;
clear(x0=0, y0=0, x1=127, y1=63)[source]

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

Parameters:
  • x0 y0 (int) – 抹去区域左上坐标
  • x1 y1 (int) – 抹去区域右下坐标
show()[source]

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

Bitmap(x, y, bitmap, w, h, c)[source]

显示图案

Parameters:
  • x y (int) – 起点坐标
  • bitmap – 图案1bit数据
  • w,h – 图案宽高
  • c – 颜色,1 or 0

IR Receive module

class bluebit.IRRecv(rx, uart_id=1)[source]

红外接收模块

Parameters:
  • rx – 接收引脚设置
  • uart_id – 串口号:1、2
recv()[source]

接收数据

Return int:返回红外值,类型整形

IR Emission module

class bluebit.IRTrans(tx, uart_id=2)[source]

红外发射模块

Parameters:
  • tx – 发送引脚设置
  • uart_id – 串口号:1、2
transmit(byte)[source]

发送数据

Parameters:byte (byte) – 发送数据,单字节

Science Exploration

Applicable modules are Voltage Meter, Current Meter, Magnetic Sensor, TDS Meter, PH Sensor, Photogate Timer, Pressure Sensor, Force Sensor.

class bluebit.DelveBit(address, i2c=<sphinx.ext.autodoc.importer._MockObject object>)[source]

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

Parameters:
  • address – 模块的I2C地址,可再模块拨动选择不同的地址避免冲突。
  • i2c – I2C实例对象,默认i2c=i2c
common_measure()[source]

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

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

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

Return int:返回正脉宽时间,单位秒

Motor Encoder module

class bluebit.EncoderMotor(address, i2c=<sphinx.ext.autodoc.importer._MockObject object>)[source]

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

Parameters:
  • address – 模块的I2C地址,可再模块拨动选择不同的地址避免冲突。
  • i2c – I2C实例对象,默认i2c=i2c
PWM_MODE = b'\x05'

pwm模式

CRUISE_MODE = b'\n'

巡航模式

POSITION_MODE = b'\x0f'

定位模式

motor_stop()[source]

停止编码电机转动

set_pwm(speed1, speed2)[source]

pwm模式

Parameters:
  • speed1 – 设置M1通道编码电机速度,范围-1023~1023
  • speed2 – 设置M2通道编码电机速度,范围-1023~1023
set_cruise(speed1, speed2)[source]

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

Parameters:
  • speed1 – 设置M1通道编码电机速度,范围-1023~1023
  • speed2 – 设置M2通道编码电机速度,范围-1023~1023
set_position(turn1, turn2)[source]

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

Parameters:
  • turn1 – 设置M1通道编码电机定位,-1023~1023
  • turn2 – 设置M2通道编码电机定位,-1023~1023

RFID module

class bluebit.Scan_Rfid[source]

扫描Rfid卡类.

rfid

Used by autodoc_mock_imports.

classmethod scanning(i2c=<sphinx.ext.autodoc.importer._MockObject object>)[source]

扫描RFID卡,返回Rfid对象

Parameters:i2c (obj) – I2C实例对象
Returns:返回Rfid对象
class bluebit.Rfid(i2c, serial_number)[source]

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

Parameters:
  • i2c – I2C实例对象
  • serial_number – RFID卡序列号
rfid

Used by autodoc_mock_imports.

serial_number()[source]

获取序列号

auth(block_number=1)[source]
read_block(block_number=1)[source]

读取块数据,长度16字节

Parameters:block_number – 块编号
write_block(buf, block_number=1)[source]

写块数据,长度16字节

Parameters:
  • buf (bytes) – 块编号
  • block_number (int) – 块编号
set_purse(block_number=1)[source]

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

Parameters:block_number (int) – 块编号
get_balance()[source]

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

Returns:返回余额
increment(value)[source]

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

Parameters:value (int) – 充值
decrement(value)[source]

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

Parameters:value (int) – 扣费