5.16 综合案例2.0-久坐提醒系统(2.2版本接口有更新)

最新案例教程点击下方链接跳转,CSDN已停止更新

点击跳转HaaS506官方最新案例







简介

长期久坐会损害身体健康,本案例就是为了提醒人们不要坐太久而设计的一个提醒系统。当你长时间在工位上坐着,他会通过钉钉提醒你,让你每隔一段时间活动一下筋骨。
久坐提醒设备是通过人体红外检测周围区域是否有人移动,当累计检测时长超过设定值,将会在钉钉群发来提醒,每次回到座位会重新开始计时。默认30分钟。

准备

本案例需要的硬件

器材数量
HaaS506开发板1
人体红外传感器1
OLED显示屏128*641
SIM卡1
杜邦线若干

人体红外传感器

用来检测人体辐射,检测会有稍微的滞后性.使用时需要调整传感器到合适状态

  • 1、调节距离电位器顺时针旋转,感应距离增大(约 7 米),反之,感应距离减小(约 3 米)。
  • 2、调节延时电位器顺时针旋转,感应延时加长(约300S),反之,感应延时减短(约 0.5S)。
  • 3、工作模式选择:
    L不可重复,H可重复。跳帽选择H。
    • L 不可重复触发方式:即感应输出高电平后,延时时间一结束,输出将自动从高电平变为低电平。
    • H 重复触发方式: 即感应输出高电平后,在延时时间段内,如果有人体在其感应范围内活动,其输出将一直保持高电平,直到人离开后才延时将高电平变为低电平(感应模块检测到人体的每一次活动后会自动顺延一个延时时间段,并且以最后一次活动的时间为延时时间的起始点)。
      在这里插入图片描述

硬件连接图

在这里插入图片描述

代码流程

1、连接阿里云平台。
2、传感器检测人体活动,计算人体久坐时间,当时间超过设定值,将信号上传阿里云平台。
3、设置云端与钉钉机器人,当满足条件时发出提醒。

功能实现

1、物联网平台开发

第一次使用物联网平台的读者,需要开通实例后使用物联网平台功能。也可以使用免费的公共实例进行开发,在阿里云物联网平台中,左上角选择‘华东2-上海’,点击‘公共实例’,即可开通。

1、平台产品创建可参考haas506 2.0开发教程-aliyunIoT
2、创建产品属性(添加物模型)
选择产品功能定义编辑草稿
在这里插入图片描述

  • 添加自定义功能
  • 设置标识符数据类型读写类型参数,标识符(light)要与代码保持一致。点击确定
  • 发布上线,点击确定

在这里插入图片描述

2、设备端开发

  • 第一次使用开发板的读者可以按照haas5062.0开发教程-导学篇搭建开发环境。
  • 搭建完后复制以下代码到Visual Studio Code,复制产品证书到代码相应位置。
    在这里插入图片描述
  • 2.2版本获取IMEI号接口有更新,需要更改以下内容(Ctrl+F 查找modem)
# 获取设备的IMEI 作为deviceName 进行动态注册
deviceName = modem.info.getDevImei()
...

代码包括5个文件
在这里插入图片描述

main.py

# coding=utf-8
from driver import GPIO
import utime as time
import sntp
from ssd1306 import SSD1306_128_64
from driver import TIMER
import aliyun

#传感器使能
hc=GPIO()
hc.open('hc')
interval_time = 30 #初始化提示时长min

#上传状态数据
interval_data = {}
def upload_interval():
    global interval_data,warns
    interval_data["warning"]= warns
    aliyun.up_data(interval_data)


#记录坐下的时长
turn = 0
def every_second():
    global duration_time,begin_time,interval_time,turn,warns,time_d,oled_stage,asd
    asd =  hc.read()
    if asd==1:
        if turn == 0:
            oled_stage = 2
            now_time=time.time()          #获取当前时间
            duration_time = (now_time - begin_time )/60
            print(round(duration_time,2))
            if int(duration_time) >= interval_time:
                warns= 1
                upload_interval()
                print('time out ---')
                oled_stage = 3
                #到时间后检测是否离开座位,如果没有离开,每隔5分钟会提醒一次
                while hc.read()==1:
                    time.sleep_ms(1000)
                    now_time=time.time() 
                    duration_time = now_time - begin_time
                    if duration_time%300 == 0 :
                        upload_interval()
    
                time_d =  [0x33, 0x30, 0x3a, 0x30, 0x30]  #倒计时时长
                begin_time = time.time()      #获取当前时间
        else:
            begin_time = time.time()      #获取当前时间
            time_d = [0x33, 0x30, 0x3a, 0x30, 0x30]  #倒计时时长
            turn = 0
            warns = 0
    else:
        turn +=1
        warns = 0
        oled_stage = 1
        # print('leave the seat')


#oled显示倒计时时间
disp=SSD1306_128_64()
disp.begin()  # 初始化   
disp.clear()  # 清屏 
time_d = [0x33, 0x30, 0x3a, 0x30, 0x30]  #倒计时时长
# 番茄时钟 OLED显示,每一秒刷一次
oled_stage = 0    #传感器当前状态   0开机;  1无人;  2有人倒计时;  3时间到
stage_turn = 0
def down_time(args):
    global downtime_end,time_d,oled_stage,stage_turn,asd
    disp.oled_showstr(110,0,str(asd),2)
    if oled_stage == 1:
        disp.oled_showstr(0,3,"leave the seat",2)
    elif oled_stage == 2:
        if time_d[4] > 0x30:
            time_d[4] = time_d[4] - 1
        else:
            time_d[4] = 0x39
            if time_d[3] > 0x30:
                time_d[3] = time_d[3] - 1
            else:
                time_d[3] = 0x35
                if time_d[1] > 0x30:
                    time_d[1] = time_d[1] - 1
                else:
                    time_d[1] = 0x39
                    if time_d[0] > 0x30:
                        time_d[0] = time_d[0] - 1
                    else:
                        downtime_end = 1
                        time_d[0] = 0x30
                        time_d[1] = 0x30
                        time_d[3] = 0x30
                        time_d[4] = 0x30
    
        disp.oled_showmun(70,3,time_d,2)
        disp.oled_showstr(0,3,"remain:",2)
    elif oled_stage == 3:
        disp.oled_showstr(0,3,"Time out",2)
    else:
        pass

    #每次状态改变清空屏幕
    if stage_turn != oled_stage:
        disp.oled_showstr(0,3,'                          ',2)   #清除屏幕显示文字
        print('stage change---------------------')
        stage_turn = oled_stage

timer = TIMER(0)
timer.open(period=1000, mode=TIMER.PERIODIC, callback=down_time)

if __name__ == '__main__':
    timer.stop()
    aliyun.connect()  # 连接网络
    while aliyun.get_connect_state() == False:
        time.sleep_ms(10)
    warns = 0  # 上传提醒
    upload_interval()
    sntp.settime()         #sntp 校时
    begin_time=time.time()          #获取当前时间
    timer.start()
    while True:	
        every_second()
        time.sleep_ms(500)
  

aliyun.py

# coding=utf-8
import network
import ujson
import utime as time
import modem
from  aliyunIoT import Device
import kv




#更改产品信息
###############################
productKey = "your productKey "
productSecret = "your productSecret "
###############################
global deviceName,g_connect_status,device_dyn_resigter_succed,netw
g_connect_status = False
netw = None
device = None
deviceSecret = None
device_dyn_resigter_succed = False

#初始化物联网平台Device类,获取device实例
device = Device()



connect_state = False
def get_connect_state():
    global connect_state
    return connect_state

def get_warns():
    global warns
    return warns

#当iot设备连接到物联网平台的时候触发'connect' 事件
def on_connect(data):
    global module_name,default_ver,productKey,deviceName,deviceSecret,on_trigger,on_download,on_verify,on_upgrade,connect_state
    print('***** connect lp succeed****')
    data_handle = {}
    data_handle['device_handle'] = device.getDeviceHandle()
    connect_state = True

#当iot云端下发属性设置时,触发'props'事件
warns_data = {}
def on_props(request):
    global warns
    print('clound req data is {}'.format(request))
    # # #获取消息中的params数据
    params=request['params']
    # #去除字符串的'',得到字典数据
    params=eval(params)
    if 'warning' in params:
        warns=params['warning']
        warns_data['warning'] = warns
        up_data(warns_data)


#当连接断开时,触发'disconnect'事件
def on_disconnect():
    print('linkkit is disconnected')


#当iot云端调用设备service时,触发'service'事件
def on_service(id,request):
    print('clound req id  is {} , req is {}'.format(id,request))
#当设备跟iot平台通信过程中遇到错误时,触发'error'事件
def on_error(err):
    print('err msg is {} '.format(err))

#网络连接的回调函数
def on_4g_cb(args):
    global g_connect_status
    pdp = args[0]
    netwk_sta = args[1]
    if netwk_sta == 1:
        g_connect_status = True

    else:
        g_connect_status = False


#网络连接
def connect_network():
    global netw,on_4g_cb,g_connect_status
    #NetWorkClient该类是一个单例类,实现网络管理相关的功能,包括初始化,联网,状态信息等.
    netw = network.NetWorkClient()
    g_register_network = False
    if netw._stagecode is not None and netw._stagecode == 3 and netw._subcode == 1:
        g_register_network = True
    else:
        g_register_network = False
    if g_register_network:
    #注册网络连接的回调函数on(self,id,func);  1代表连接,func 回调函数  ;return 0 成功
        netw.on(1,on_4g_cb)
        netw.connect(None)
    else:
        print('网络注册失败')
    while True:
        if g_connect_status:
            print('网络连接成功')
            break
        time.sleep_ms(20)


#动态注册回调函数
def on_dynreg_cb(data):
    global deviceSecret,device_dyn_resigter_succed
    deviceSecret = data
    device_dyn_resigter_succed = True

# 连接物联网平台
def dyn_register_device(productKey,productSecret,deviceName):
    global on_dynreg_cb,device,deviceSecret,device_dyn_resigter_succed

    key = '_amp_customer_devicesecret'
    deviceSecretdict = kv.get(key)
    print("deviceSecretdict:",deviceSecretdict)
    if isinstance(deviceSecretdict,str):    
        deviceSecret = deviceSecretdict 

    if deviceSecretdict is None or deviceSecret is None:
        key_info = {
            'productKey': productKey  ,
            'productSecret': productSecret ,
            'deviceName': deviceName
            }
        # 动态注册一个设备,获取设备的deviceSecret
        #下面的if防止多次注册,当前若是注册过一次了,重启设备再次注册就会卡住,
        if not device_dyn_resigter_succed:
            device.register(key_info,on_dynreg_cb)  

def connect():
    global deviceName,g_connect_status,device_dyn_resigter_succed
    deviceName = None
     # 获取设备的IMEI 作为deviceName 进行动态注册
    deviceName = modem.info.getDevImei()
    # 连接网络
    connect_network()
    if deviceName is not None and len(deviceName) > 0 :
        #动态注册一个设备
        dyn_register_device(productKey,productSecret,deviceName)
    else:
        print("获取设备IMEI失败,无法进行动态注册")
    while deviceSecret is None:
        time.sleep(0.2)
    print('动态注册成功:' + deviceSecret)
    key_info = {
        'region' : 'cn-shanghai' ,
        'productKey': productKey ,
        'deviceName': deviceName ,
        'deviceSecret': deviceSecret ,
        'keepaliveSec': 60,
        }
    #打印设备信息
    print(key_info)
    #device.ON_CONNECT 是事件,on_connect是事件处理函数/回调函数
    device.on(device.ON_CONNECT,on_connect)
    device.on(device.ON_DISCONNECT,on_disconnect)
    device.on(device.ON_PROPS,on_props)
    device.on(device.ON_SERVICE,on_service)
    device.on(device.ON_ERROR,on_error)
    device.connect(key_info)



def up_data(d):           
    d_str = ujson.dumps(d)
    data={
        'params':d_str
        }
    device.postProps(data)

ssd1306.py


import utime as time
import codetab

# Constants
SSD1306_I2C_ADDRESS = 0x3C    # 011110+SA0+RW - 0x3C or 0x3D
SSD1306_SETCONTRAST = 0x81
SSD1306_DISPLAYALLON_RESUME = 0xA4
SSD1306_DISPLAYALLON = 0xA5
SSD1306_NORMALDISPLAY = 0xA6
SSD1306_INVERTDISPLAY = 0xA7
SSD1306_DISPLAYOFF = 0xAE
SSD1306_DISPLAYON = 0xAF
SSD1306_SETDISPLAYOFFSET = 0xD3
SSD1306_SETCOMPINS = 0xDA
SSD1306_SETVCOMDETECT = 0xDB
SSD1306_SETDISPLAYCLOCKDIV = 0xD5
SSD1306_SETPRECHARGE = 0xD9
SSD1306_SETMULTIPLEX = 0xA8
SSD1306_SETLOWCOLUMN = 0x00
SSD1306_SETHIGHCOLUMN = 0x10
SSD1306_SETSTARTLINE = 0x40
SSD1306_MEMORYMODE = 0x20
SSD1306_COLUMNADDR = 0x21
SSD1306_PAGEADDR = 0x22
SSD1306_COMSCANINC = 0xC0
SSD1306_COMSCANDEC = 0xC8
SSD1306_SEGREMAP = 0xA0
SSD1306_CHARGEPUMP = 0x8D
SSD1306_EXTERNALVCC = 0x1
SSD1306_SWITCHCAPVCC = 0x2

# Scrolling constants
SSD1306_ACTIVATE_SCROLL = 0x2F
SSD1306_DEACTIVATE_SCROLL = 0x2E
SSD1306_SET_VERTICAL_SCROLL_AREA = 0xA3
SSD1306_RIGHT_HORIZONTAL_SCROLL = 0x26
SSD1306_LEFT_HORIZONTAL_SCROLL = 0x27
SSD1306_VERTICAL_AND_RIGHT_HORIZONTAL_SCROLL = 0x29
SSD1306_VERTICAL_AND_LEFT_HORIZONTAL_SCROLL = 0x2A


class SSD1306Base(object):
    def __init__(self, width, height):
        self.width = width
        self.height = height
        self._pages = height//8
        self._buffer = [0]*(width*self._pages)
        # Handle hardware I2C
        from driver import I2C
        self._i2c=I2C()
        self._i2c.open('OLED')


    def _initialize(self):
        raise NotImplementedError

    def writeCmd(self, command):
        """Send command byte to display."""
        # I2C write.
        control = 0x00   # Co = 0, DC = 0
        # writeBuf=bytearray(2)
        # writeBuf[0]=control
        # writeBuf[1]=command
        # self._i2c.write(writeBuf)

        writeBuf=bytearray(1)
        writeBuf[0]=command
        self._i2c.memWrite(writeBuf,control,8)


    def writeDat(self, data):
        """Send byte of data to display."""
        # I2C write.
        control = 0x40   # Co = 0, DC = 0
        # writeBuf=bytearray(2)
        # writeBuf[0]=control
        # writeBuf[1]=data
        # self._i2c.write(writeBuf)

        writeBuf=bytearray(1)
        writeBuf[0]=data
        self._i2c.memWrite(writeBuf,control,8)

    def begin(self, vccstate=SSD1306_SWITCHCAPVCC):
        """Initialize display."""
        # Save vcc state.
        self._vccstate = vccstate
        # Reset and initialize display.
        # self.reset()
        self._initialize()
        # Turn on the display.
        self.writeCmd(SSD1306_DISPLAYON)

# --------------------------------------------------------------
#  Prototype      : oled_fill(fill_data)
#  Parameters     : fill_data,范围0x00-0xff
#  Description    : 全屏填充,例如 0x00-全黑,0xff全亮
# --------------------------------------------------------------
    def oled_fill(self,fill_data):
        for i in range(8):
            #page0-page1
            self.writeCmd(0xb0+i)
            # low colum start address
            self.writeCmd(0x00)
            #high colum start address
            self.writeCmd(0x10)
        for i in range(128*64):
            self.writeDat(fill_data)  
      
# --------------------------------------------------------------
#  Prototype      : clear()
#  Parameters     : none
#  Description    : 全黑
# --------------------------------------------------------------
    def clear(self):
        self.oled_fill(0x00)



# --------------------------------------------------------------
#  Prototype      : oled_setPos(x,y)
#  Parameters     : x,y -- 起始点坐标(x:0~127, y:0~7)
#  Description    : 设置起始坐标
# --------------------------------------------------------------
    def oled_setPos(self,x,y):
        self.writeCmd(0xb0+y)
        self.writeCmd(((x&0xf0)>>4)|0x10)
        self.writeCmd((x&0x0f)|0x01)

# --------------------------------------------------------------
#  Prototype      : oled_showCN(x,y,n)
#  Parameters     : x,y -- 起始点坐标(x:0~127, y:0~7); N:汉字在codetab.h中的索引
#  Description    : 显示codetab.py中的汉字,16*16点阵
# --------------------------------------------------------------
    def oled_showCN(self,x,y,n):
        self.oled_setPos(x,y)
        adder=32*n
        for i in range(16):
            self.writeDat(codetab.F1[adder])
            adder+=1
        self.oled_setPos(x,y+1)
        for i in range(16):
            self.writeDat(codetab.F1[adder])
            adder+=1

# --------------------------------------------------------------
#  Prototype      : oled_showStr(x,y,ch,TextSize)
#  Parameters     : x,y -- 起始点坐标(x:0~127, y:0~7); ch[] -- 要显示的字符串; TextSize -- 字符大小(1:6*8 ; 2:8*16)
#  Description    : 显示codetab.py中的ASCII字符,有6*8和8*16可选择
# --------------------------------------------------------------    

    def oled_showmun(self,x,y,ch,TextSize):
        c=0
        j=0
        if TextSize==1:
            while ch[j]!='\0':
                #ord()将字符转换成十进制,如'a'->97
                c=ch[j]-32
                if x>126:
                    x=0
                    y+=1
                self.oled_setPos(x,y)
                for i in range(6):
                    self.writeDat(codetab.F6x8[c][i]) 
                x+=6
                j+=1
                #防止index out of range 
                if j==len(ch):
                    break
        if TextSize==2:
             while ch[j]!='\0':
                #ord()将字符转换成十进制
                c=ch[j]-32
                if x>120:
                    x=0
                    y+=1
                self.oled_setPos(x,y)
                for i in range(8):
                    self.writeDat(codetab.F8X16[c*16+i]) 
                self.oled_setPos(x,y+1)
                for i in range(8):
                    self.writeDat(codetab.F8X16[c*16+i+8])    
                x+=8
                j+=1    
                #防止index out of range                                    
                if j==len(ch):
                    break


    def oled_showstr(self,x,y,ch,TextSize):
        c2=0
        j=0
        if TextSize==1:
            while ch[j]!='\0':
                #ord()将字符转换成十进制,如'a'->97
                c2=ord(ch[j])-32
                if x>126:
                    x=0
                    y+=1
                self.oled_setPos(x,y)
                for i in range(6):
                    self.writeDat(codetab.F6x8[c2][i]) 
                x+=6
                j+=1
                #防止index out of range 
                if j==len(ch):
                    break
        if TextSize==2:
             while ch[j]!='\0':
                #ord()将字符转换成十进制,如'a'->97
                c2=ord(ch[j])-32
                if x>120:
                    x=0
                    y+=1
                self.oled_setPos(x,y)
                for i in range(8):
                    self.writeDat(codetab.F8X16[c2*16+i]) 
                self.oled_setPos(x,y+1)
                for i in range(8):
                    self.writeDat(codetab.F8X16[c2*16+i+8])    
                x+=8
                j+=1    
                #防止index out of range                                    
                if j==len(ch):
                    break
# # --------------------------------------------------------------
# Prototype      : oled_showPicture(x0,y0,x1,y1,BMP)
# Parameters     : x0,y0 -- 起始点坐标(x0:0~127, y0:0~7); x1,y1 -- 起点对角线(结束点)的坐标(x1:1~128,y1:128)
# Description    : 显示BMP位图
# --------------------------------------------------------------
    def oled_showPicture(self,x0,y0,x1,y1,BMP):
        i=0
        if y1%8==0:
            y=y1/8
        else:
            y=y1/8+1
        for y in range(y0,y1):
            self.oled_setPos(x0,y)   
            for x in range(x0,x1):
                self.writeDat(BMP[i])  
                i+=1    
            if i==len(BMP) :
                break

# --------------------------------------------------------------
# Prototype      : set_contrast(contrast)
# Parameters     : coontrast,取值范围为0-255
# Description    : 对比度/亮度调节
# --------------------------------------------------------------    
    def set_contrast(self, contrast):
        if contrast < 0 or contrast > 255:
            raise ValueError('Contrast must be a value from 0 to 255 (inclusive).')
        self.writeCmd(SSD1306_SETCONTRAST)
        self.writeCmd(contrast)


class SSD1306_128_64(SSD1306Base):
    def __init__(self):
        super(SSD1306_128_64, self).__init__(128, 64)

    def _initialize(self):
        # 128x64 pixel specific initialization.
        self.writeCmd(SSD1306_DISPLAYOFF)                    # 0xAE
        self.writeCmd(SSD1306_SETDISPLAYCLOCKDIV)            # 0xD5
        self.writeCmd(0x80)                                  # the suggested ratio 0x80
        self.writeCmd(SSD1306_SETMULTIPLEX)                  # 0xA8
        self.writeCmd(0x3F)
        self.writeCmd(SSD1306_SETDISPLAYOFFSET)              # 0xD3
        self.writeCmd(0x0)                                   # no offset
        self.writeCmd(SSD1306_SETSTARTLINE | 0x0)            # line #0
        self.writeCmd(SSD1306_CHARGEPUMP)                    # 0x8D
        if self._vccstate == SSD1306_EXTERNALVCC:
            self.writeCmd(0x10)
        else:
            self.writeCmd(0x14)
        self.writeCmd(SSD1306_MEMORYMODE)                    # 0x20
        self.writeCmd(0x00)                                  # 0x0 act like ks0108
        self.writeCmd(SSD1306_SEGREMAP | 0x1)
        self.writeCmd(SSD1306_COMSCANDEC)
        self.writeCmd(SSD1306_SETCOMPINS)                    # 0xDA
        self.writeCmd(0x12)
        self.writeCmd(SSD1306_SETCONTRAST)                   # 0x81
        if self._vccstate == SSD1306_EXTERNALVCC:
            self.writeCmd(0x9F)
        else:
            self.writeCmd(0xCF)
        self.writeCmd(SSD1306_SETPRECHARGE)                  # 0xd9
        if self._vccstate == SSD1306_EXTERNALVCC:
            self.writeCmd(0x22)
        else:
            self.writeCmd(0xF1)
        self.writeCmd(SSD1306_SETVCOMDETECT)                 # 0xDB
        self.writeCmd(0x40)
        self.writeCmd(SSD1306_DISPLAYALLON_RESUME)           # 0xA4
        self.writeCmd(SSD1306_NORMALDISPLAY)                 # 0xA6


class SSD1306_128_32(SSD1306Base):
    def __init__(self):
        super(SSD1306_128_32, self).__init__(128, 32)

    def _initialize(self):
        self.writeCmd(SSD1306_DISPLAYOFF)                    # 0xAE
        self.writeCmd(SSD1306_SETDISPLAYCLOCKDIV)            # 0xD5
        self.writeCmd(0x80)                                  # the suggested ratio 0x80
        self.writeCmd(SSD1306_SETMULTIPLEX)                  # 0xA8
        self.writeCmd(0x1F)
        self.writeCmd(SSD1306_SETDISPLAYOFFSET)              # 0xD3
        self.writeCmd(0x0)                                   # no offset
        self.writeCmd(SSD1306_SETSTARTLINE | 0x0)            # line #0
        self.writeCmd(SSD1306_CHARGEPUMP)                    # 0x8D
        if self._vccstate == SSD1306_EXTERNALVCC:
            self.writeCmd(0x10)
        else:
            self.writeCmd(0x14)
        self.writeCmd(SSD1306_MEMORYMODE)                    # 0x20
        self.writeCmd(0x00)                                  # 0x0 act like ks0108
        self.writeCmd(SSD1306_SEGREMAP | 0x1)
        self.writeCmd(SSD1306_COMSCANDEC)
        self.writeCmd(SSD1306_SETCOMPINS)                    # 0xDA
        self.writeCmd(0x02)
        self.writeCmd(SSD1306_SETCONTRAST)                   # 0x81
        self.writeCmd(0x8F)
        self.writeCmd(SSD1306_SETPRECHARGE)                  # 0xd9
        if self._vccstate == SSD1306_EXTERNALVCC:
            self.writeCmd(0x22)
        else:
            self.writeCmd(0xF1)
        self.writeCmd(SSD1306_SETVCOMDETECT)                 # 0xDB
        self.writeCmd(0x40)
        self.writeCmd(SSD1306_DISPLAYALLON_RESUME)           # 0xA4
        self.writeCmd(SSD1306_NORMALDISPLAY)                 # 0xA6


class SSD1306_96_16(SSD1306Base):
    def __init__(self):
        super(SSD1306_96_16, self).__init__(96, 16)

    def _initialize(self):
        self.writeCmd(SSD1306_DISPLAYOFF)                    # 0xAE
        self.writeCmd(SSD1306_SETDISPLAYCLOCKDIV)            # 0xD5
        self.writeCmd(0x60)                                  # the suggested ratio 0x60
        self.writeCmd(SSD1306_SETMULTIPLEX)                  # 0xA8
        self.writeCmd(0x0F)
        self.writeCmd(SSD1306_SETDISPLAYOFFSET)              # 0xD3
        self.writeCmd(0x0)                                   # no offset
        self.writeCmd(SSD1306_SETSTARTLINE | 0x0)            # line #0
        self.writeCmd(SSD1306_CHARGEPUMP)                    # 0x8D
        if self._vccstate == SSD1306_EXTERNALVCC:
            self.writeCmd(0x10)
        else:
            self.writeCmd(0x14)
        self.writeCmd(SSD1306_MEMORYMODE)                    # 0x20
        self.writeCmd(0x00)                                  # 0x0 act like ks0108
        self.writeCmd(SSD1306_SEGREMAP | 0x1)
        self.writeCmd(SSD1306_COMSCANDEC)
        self.writeCmd(SSD1306_SETCOMPINS)                    # 0xDA
        self.writeCmd(0x02)
        self.writeCmd(SSD1306_SETCONTRAST)                   # 0x81
        self.writeCmd(0x8F)
        self.writeCmd(SSD1306_SETPRECHARGE)                  # 0xd9
        if self._vccstate == SSD1306_EXTERNALVCC:
            self.writeCmd(0x22)
        else:
            self.writeCmd(0xF1)
        self.writeCmd(SSD1306_SETVCOMDETECT)                 # 0xDB
        self.writeCmd(0x40)
        self.writeCmd(SSD1306_DISPLAYALLON_RESUME)           # 0xA4
        self.writeCmd(SSD1306_NORMALDISPLAY)                 # 0xA6


codetab.py


# 每个字符是8x16(宽x高) 点阵,
F2=[
	0x10,0xF0,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,    #*"h",0*#

	0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x19,0x24,0x24,0x12,0x3F,0x20,0x00,    #*"a",1*#

	0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x19,0x24,0x24,0x12,0x3F,0x20,0x00,     #*"a",2*#

	0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x33,0x24,0x24,0x24,0x24,0x19,0x00,     #*"s",3*#

	0x00,0xF8,0x88,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x20,0x20,0x20,0x11,0x0E,0x00,     #*"5",4*#

	0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,     #*"0",5*#

	0x00,0xE0,0x10,0x88,0x88,0x90,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x20,0x1F,0x00,     #*"6",6*#

]

#字符串 6x8点阵
F6x8=[
    [0x00, 0x00, 0x00, 0x00, 0x00, 0x00],# sp
	[0x00, 0x00, 0x00, 0x2f, 0x00, 0x00],# !
	[0x00, 0x00, 0x07, 0x00, 0x07, 0x00],# "
	[0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14],# #
	[0x00, 0x24, 0x2a, 0x7f, 0x2a, 0x12],# $
	[0x00, 0x62, 0x64, 0x08, 0x13, 0x23],# %
	[0x00, 0x36, 0x49, 0x55, 0x22, 0x50],# &
	[0x00, 0x00, 0x05, 0x03, 0x00, 0x00],# '
	[0x00, 0x00, 0x1c, 0x22, 0x41, 0x00],# (
	[0x00, 0x00, 0x41, 0x22, 0x1c, 0x00],# )
	[0x00, 0x14, 0x08, 0x3E, 0x08, 0x14],# *
	[0x00, 0x08, 0x08, 0x3E, 0x08, 0x08],# +
	[0x00, 0x00, 0x00, 0xA0, 0x60, 0x00],# ,
	[0x00, 0x08, 0x08, 0x08, 0x08, 0x08],# -
	[0x00, 0x00, 0x60, 0x60, 0x00, 0x00],# .
	[0x00, 0x20, 0x10, 0x08, 0x04, 0x02],# #
	[0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E],# 0
	[0x00, 0x00, 0x42, 0x7F, 0x40, 0x00],# 1
	[0x00, 0x42, 0x61, 0x51, 0x49, 0x46],# 2
	[0x00, 0x21, 0x41, 0x45, 0x4B, 0x31],# 3
	[0x00, 0x18, 0x14, 0x12, 0x7F, 0x10],# 4
	[0x00, 0x27, 0x45, 0x45, 0x45, 0x39],# 5
	[0x00, 0x3C, 0x4A, 0x49, 0x49, 0x30],# 6
	[0x00, 0x01, 0x71, 0x09, 0x05, 0x03],# 7
	[0x00, 0x36, 0x49, 0x49, 0x49, 0x36],# 8
	[0x00, 0x06, 0x49, 0x49, 0x29, 0x1E],# 9
	[0x00, 0x00, 0x36, 0x36, 0x00, 0x00],# :
	[0x00, 0x00, 0x56, 0x36, 0x00, 0x00],# ;
	[0x00, 0x08, 0x14, 0x22, 0x41, 0x00],# <
	[0x00, 0x14, 0x14, 0x14, 0x14, 0x14],# =
	[0x00, 0x00, 0x41, 0x22, 0x14, 0x08],# >
	[0x00, 0x02, 0x01, 0x51, 0x09, 0x06],# ?
	[0x00, 0x32, 0x49, 0x59, 0x51, 0x3E],# @
	[0x00, 0x7C, 0x12, 0x11, 0x12, 0x7C],# A
	[0x00, 0x7F, 0x49, 0x49, 0x49, 0x36],# B
	[0x00, 0x3E, 0x41, 0x41, 0x41, 0x22],# C
	[0x00, 0x7F, 0x41, 0x41, 0x22, 0x1C],# D
	[0x00, 0x7F, 0x49, 0x49, 0x49, 0x41],# E
	[0x00, 0x7F, 0x09, 0x09, 0x09, 0x01],# F
	[0x00, 0x3E, 0x41, 0x49, 0x49, 0x7A],# G
	[0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F],# H
	[0x00, 0x00, 0x41, 0x7F, 0x41, 0x00],# I
	[0x00, 0x20, 0x40, 0x41, 0x3F, 0x01],# J
	[0x00, 0x7F, 0x08, 0x14, 0x22, 0x41],# K
	[0x00, 0x7F, 0x40, 0x40, 0x40, 0x40],# L
	[0x00, 0x7F, 0x02, 0x0C, 0x02, 0x7F],# M
	[0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F],# N
	[0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E],# O
	[0x00, 0x7F, 0x09, 0x09, 0x09, 0x06],# P
	[0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E],# Q
	[0x00, 0x7F, 0x09, 0x19, 0x29, 0x46],# R
	[0x00, 0x46, 0x49, 0x49, 0x49, 0x31],# S
	[0x00, 0x01, 0x01, 0x7F, 0x01, 0x01],# T
	[0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F],# U
	[0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F],# V
	[0x00, 0x3F, 0x40, 0x38, 0x40, 0x3F],# W
	[0x00, 0x63, 0x14, 0x08, 0x14, 0x63],# X
	[0x00, 0x07, 0x08, 0x70, 0x08, 0x07],# Y
	[0x00, 0x61, 0x51, 0x49, 0x45, 0x43],# Z
	[0x00, 0x00, 0x7F, 0x41, 0x41, 0x00],# [
	[0x00, 0x55, 0x2A, 0x55, 0x2A, 0x55],# 55
	[0x00, 0x00, 0x41, 0x41, 0x7F, 0x00],# ]
	[0x00, 0x04, 0x02, 0x01, 0x02, 0x04],# ^
	[0x00, 0x40, 0x40, 0x40, 0x40, 0x40],# _
	[0x00, 0x00, 0x01, 0x02, 0x04, 0x00],# '
	[0x00, 0x20, 0x54, 0x54, 0x54, 0x78],# a
	[0x00, 0x7F, 0x48, 0x44, 0x44, 0x38],# b
	[0x00, 0x38, 0x44, 0x44, 0x44, 0x20],# c
	[0x00, 0x38, 0x44, 0x44, 0x48, 0x7F],# d
	[0x00, 0x38, 0x54, 0x54, 0x54, 0x18],# e
	[0x00, 0x08, 0x7E, 0x09, 0x01, 0x02],# f
	[0x00, 0x18, 0xA4, 0xA4, 0xA4, 0x7C],# g
	[0x00, 0x7F, 0x08, 0x04, 0x04, 0x78],# h
	[0x00, 0x00, 0x44, 0x7D, 0x40, 0x00],# i
	[0x00, 0x40, 0x80, 0x84, 0x7D, 0x00],# j
	[0x00, 0x7F, 0x10, 0x28, 0x44, 0x00],# k
	[0x00, 0x00, 0x41, 0x7F, 0x40, 0x00],# l
	[0x00, 0x7C, 0x04, 0x18, 0x04, 0x78],# m
	[0x00, 0x7C, 0x08, 0x04, 0x04, 0x78],# n
	[0x00, 0x38, 0x44, 0x44, 0x44, 0x38],# o
	[0x00, 0xFC, 0x24, 0x24, 0x24, 0x18],# p
	[0x00, 0x18, 0x24, 0x24, 0x18, 0xFC],# q
	[0x00, 0x7C, 0x08, 0x04, 0x04, 0x08],# r
	[0x00, 0x48, 0x54, 0x54, 0x54, 0x20],# s
	[0x00, 0x04, 0x3F, 0x44, 0x40, 0x20],# t
	[0x00, 0x3C, 0x40, 0x40, 0x20, 0x7C],# u
	[0x00, 0x1C, 0x20, 0x40, 0x20, 0x1C],# v
	[0x00, 0x3C, 0x40, 0x30, 0x40, 0x3C],# w
	[0x00, 0x44, 0x28, 0x10, 0x28, 0x44],# x
	[0x00, 0x1C, 0xA0, 0xA0, 0xA0, 0x7C],# y
	[0x00, 0x44, 0x64, 0x54, 0x4C, 0x44],# z
	[0x14, 0x14, 0x14, 0x14, 0x14, 0x14]# horiz lines
]


#字符串 8x16点阵
F8X16=[
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,# 0
  0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x33,0x30,0x00,0x00,0x00,#! 1
  0x00,0x10,0x0C,0x06,0x10,0x0C,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#" 2
  0x40,0xC0,0x78,0x40,0xC0,0x78,0x40,0x00,0x04,0x3F,0x04,0x04,0x3F,0x04,0x04,0x00,## 3
  0x00,0x70,0x88,0xFC,0x08,0x30,0x00,0x00,0x00,0x18,0x20,0xFF,0x21,0x1E,0x00,0x00,#$ 4
  0xF0,0x08,0xF0,0x00,0xE0,0x18,0x00,0x00,0x00,0x21,0x1C,0x03,0x1E,0x21,0x1E,0x00,#% 5
  0x00,0xF0,0x08,0x88,0x70,0x00,0x00,0x00,0x1E,0x21,0x23,0x24,0x19,0x27,0x21,0x10,#& 6
  0x10,0x16,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#' 7
  0x00,0x00,0x00,0xE0,0x18,0x04,0x02,0x00,0x00,0x00,0x00,0x07,0x18,0x20,0x40,0x00,#( 8
  0x00,0x02,0x04,0x18,0xE0,0x00,0x00,0x00,0x00,0x40,0x20,0x18,0x07,0x00,0x00,0x00,#) 9
  0x40,0x40,0x80,0xF0,0x80,0x40,0x40,0x00,0x02,0x02,0x01,0x0F,0x01,0x02,0x02,0x00,#* 10
  0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x1F,0x01,0x01,0x01,0x00,#+ 11
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xB0,0x70,0x00,0x00,0x00,0x00,0x00,#, 12
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,#- 13
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,#. 14
  0x00,0x00,0x00,0x00,0x80,0x60,0x18,0x04,0x00,0x60,0x18,0x06,0x01,0x00,0x00,0x00,## 15
  0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,#0 16
  0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,#1 17
  0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,#2 18
  0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,#3 19
  0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,#4 20
  0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,#5 21
  0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,#6 22
  0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,#7 23
  0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,#8 24
  0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,#9 25
  0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,#: 26
  0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x60,0x00,0x00,0x00,0x00,#; 27
  0x00,0x00,0x80,0x40,0x20,0x10,0x08,0x00,0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x00,#< 28
  0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x00,#= 29
  0x00,0x08,0x10,0x20,0x40,0x80,0x00,0x00,0x00,0x20,0x10,0x08,0x04,0x02,0x01,0x00,#> 30
  0x00,0x70,0x48,0x08,0x08,0x08,0xF0,0x00,0x00,0x00,0x00,0x30,0x36,0x01,0x00,0x00,#? 31
  0xC0,0x30,0xC8,0x28,0xE8,0x10,0xE0,0x00,0x07,0x18,0x27,0x24,0x23,0x14,0x0B,0x00,#@ 32
  0x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00,0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20,#A 33
  0x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x11,0x0E,0x00,#B 34
  0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00,#C 35
  0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00,#D 36
  0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00,#E 37
  0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x00,0x03,0x00,0x00,0x00,#F 38
  0xC0,0x30,0x08,0x08,0x08,0x38,0x00,0x00,0x07,0x18,0x20,0x20,0x22,0x1E,0x02,0x00,#G 39
  0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x20,0x3F,0x21,0x01,0x01,0x21,0x3F,0x20,#H 40
  0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,#I 41
  0x00,0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,0x00,#J 42
  0x08,0xF8,0x88,0xC0,0x28,0x18,0x08,0x00,0x20,0x3F,0x20,0x01,0x26,0x38,0x20,0x00,#K 43
  0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00,#L 44
  0x08,0xF8,0xF8,0x00,0xF8,0xF8,0x08,0x00,0x20,0x3F,0x00,0x3F,0x00,0x3F,0x20,0x00,#M 45
  0x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08,0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00,#N 46
  0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00,#O 47
  0x08,0xF8,0x08,0x08,0x08,0x08,0xF0,0x00,0x20,0x3F,0x21,0x01,0x01,0x01,0x00,0x00,#P 48
  0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x18,0x24,0x24,0x38,0x50,0x4F,0x00,#Q 49
  0x08,0xF8,0x88,0x88,0x88,0x88,0x70,0x00,0x20,0x3F,0x20,0x00,0x03,0x0C,0x30,0x20,#R 50
  0x00,0x70,0x88,0x08,0x08,0x08,0x38,0x00,0x00,0x38,0x20,0x21,0x21,0x22,0x1C,0x00,#S 51
  0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,#T 52
  0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,#U 53
  0x08,0x78,0x88,0x00,0x00,0xC8,0x38,0x08,0x00,0x00,0x07,0x38,0x0E,0x01,0x00,0x00,#V 54
  0xF8,0x08,0x00,0xF8,0x00,0x08,0xF8,0x00,0x03,0x3C,0x07,0x00,0x07,0x3C,0x03,0x00,#W 55
  0x08,0x18,0x68,0x80,0x80,0x68,0x18,0x08,0x20,0x30,0x2C,0x03,0x03,0x2C,0x30,0x20,#X 56
  0x08,0x38,0xC8,0x00,0xC8,0x38,0x08,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,#Y 57
  0x10,0x08,0x08,0x08,0xC8,0x38,0x08,0x00,0x20,0x38,0x26,0x21,0x20,0x20,0x18,0x00,#Z 58
  0x00,0x00,0x00,0xFE,0x02,0x02,0x02,0x00,0x00,0x00,0x00,0x7F,0x40,0x40,0x40,0x00,#[ 59
  0x00,0x0C,0x30,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x06,0x38,0xC0,0x00,#\ 60
  0x00,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,0x00,0x40,0x40,0x40,0x7F,0x00,0x00,0x00,#] 61
  0x00,0x00,0x04,0x02,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#^ 62
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,#_ 63
  0x00,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#` 64
  0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x19,0x24,0x22,0x22,0x22,0x3F,0x20,#a 65
  0x08,0xF8,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x3F,0x11,0x20,0x20,0x11,0x0E,0x00,#b 66
  0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x0E,0x11,0x20,0x20,0x20,0x11,0x00,#c 67
  0x00,0x00,0x00,0x80,0x80,0x88,0xF8,0x00,0x00,0x0E,0x11,0x20,0x20,0x10,0x3F,0x20,#d 68
  0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x22,0x22,0x22,0x22,0x13,0x00,#e 69
  0x00,0x80,0x80,0xF0,0x88,0x88,0x88,0x18,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,#f 70
  0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x6B,0x94,0x94,0x94,0x93,0x60,0x00,#g 71
  0x08,0xF8,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,#h 72
  0x00,0x80,0x98,0x98,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,#i 73
  0x00,0x00,0x00,0x80,0x98,0x98,0x00,0x00,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,#j 74
  0x08,0xF8,0x00,0x00,0x80,0x80,0x80,0x00,0x20,0x3F,0x24,0x02,0x2D,0x30,0x20,0x00,#k 75
  0x00,0x08,0x08,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,#l 76
  0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F,#m 77
  0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,#n 78
  0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,#o 79
  0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x00,0x80,0xFF,0xA1,0x20,0x20,0x11,0x0E,0x00,#p 80
  0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x0E,0x11,0x20,0x20,0xA0,0xFF,0x80,#q 81
  0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x20,0x20,0x3F,0x21,0x20,0x00,0x01,0x00,#r 82
  0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x33,0x24,0x24,0x24,0x24,0x19,0x00,#s 83
  0x00,0x80,0x80,0xE0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x1F,0x20,0x20,0x00,0x00,#t 84
  0x80,0x80,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20,#u 85
  0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x00,0x01,0x0E,0x30,0x08,0x06,0x01,0x00,#v 86
  0x80,0x80,0x00,0x80,0x00,0x80,0x80,0x80,0x0F,0x30,0x0C,0x03,0x0C,0x30,0x0F,0x00,#w 87
  0x00,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x31,0x2E,0x0E,0x31,0x20,0x00,#x 88
  0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x80,0x81,0x8E,0x70,0x18,0x06,0x01,0x00,#y 89
  0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x21,0x30,0x2C,0x22,0x21,0x30,0x00,#z 90
  0x00,0x00,0x00,0x00,0x80,0x7C,0x02,0x02,0x00,0x00,0x00,0x00,0x00,0x3F,0x40,0x40,# 91
  0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,#| 92
  0x00,0x02,0x02,0x7C,0x80,0x00,0x00,0x00,0x00,0x40,0x40,0x3F,0x00,0x00,0x00,0x00,# 93
  0x00,0x06,0x01,0x01,0x02,0x02,0x04,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#~ 94
]

BMP1=[
    0x00,0x03,0x05,0x09,0x11,0xFF,0x11,0x89,0x05,0xC3,0x00,0xE0,0x00,0xF0,0x00,0xF8,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x44,0x28,0xFF,0x11,0xAA,0x44,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x83,0x01,0x38,0x44,0x82,0x92,
	0x92,0x74,0x01,0x83,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7C,0x44,0xC7,0x01,0x7D,
	0x7D,0x7D,0x7D,0x01,0x7D,0x7D,0x7D,0x7D,0x01,0x7D,0x7D,0x7D,0x7D,0x01,0xFF,0x00,
	0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00,
	0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,
	0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x40,0x40,0x40,0x40,0x00,0x00,
	0x6D,0x6D,0x6D,0x6D,0x6D,0x00,0x00,0x60,0x60,0x60,0x60,0x60,0x00,0x00,0x40,0x40,
	0x40,0x40,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xDB,0xDB,0xDB,0xDB,0xDB,0x00,0x00,
	0xDB,0xDB,0xDB,0xDB,0xDB,0x00,0x00,0xDB,0xDB,0xDB,0xDB,0xDB,0x00,0x00,0xDB,0xDB,
	0xDB,0xDB,0xDB,0x00,0x00,0xDA,0xDA,0xDA,0xDA,0xDA,0x00,0x00,0xD8,0xD8,0xD8,0xD8,
	0xD8,0x00,0x00,0xC0,0xC0,0xC0,0xC0,0xC0,0x00,0x00,0xC0,0xC0,0xC0,0xC0,0xC0,0x00,
	0x00,0xC0,0xC0,0xC0,0xC0,0xC0,0x00,0x00,0xC0,0xC0,0xC0,0xC0,0xC0,0x00,0x00,0x80,
	0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x06,0x06,0x06,0x06,0x00,0x00,
	0x06,0x06,0x06,0x06,0x06,0x00,0x00,0x06,0x06,0x06,0x06,0x06,0x00,0x00,0x06,0x06,
	0x06,0x06,0x06,0x00,0x00,0x06,0x06,0x06,0xE6,0x66,0x20,0x00,0x06,0x06,0x86,0x06,
	0x06,0x00,0x00,0x06,0x06,0x06,0x06,0x86,0x00,0x00,0x06,0x06,0x06,0x06,0x06,0x00,
	0x00,0x86,0x86,0x86,0x86,0x86,0x80,0x80,0x86,0x86,0x06,0x86,0x86,0xC0,0xC0,0x86,
	0x86,0x86,0x06,0x06,0xD0,0x30,0x76,0x06,0x06,0x06,0x06,0x00,0x00,0x06,0x06,0x06,
	0x06,0x06,0x00,0x00,0x06,0x06,0x06,0x06,0x06,0x00,0x00,0x06,0x06,0x06,0x06,0x06,
	0x00,0x00,0x06,0x06,0x06,0x06,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x1C,0x00,0xFE,0x00,0x01,
	0x02,0x00,0xC4,0x18,0x20,0x02,0x9E,0x63,0xB2,0x0E,0x00,0xFF,0x81,0x81,0xFF,0x00,
	0x00,0x80,0x40,0x30,0x0F,0x00,0x00,0x00,0x00,0xFF,0x00,0x23,0xEA,0xAA,0xBF,0xAA,
	0xEA,0x03,0x3F,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0E,0x0C,0x08,0x00,0x00,0x01,0x01,0x01,
	0x01,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x81,0x80,0x80,0x81,0x80,
	0x81,0x80,0x80,0x80,0x80,0x01,0x01,0x01,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,
	0x01,0x00,0x01,0x01,0x09,0x0C,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,
	0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0x00,
	0x00,0x1E,0x21,0x40,0x40,0x50,0x21,0x5E,0x00,0x1E,0x21,0x40,0x40,0x50,0x21,0x5E,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xC1,0xC1,0xFF,
	0xFF,0xC1,0xC1,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0x80,0xFC,0xF3,0xEF,0xF3,0xFC,
	0x80,0xFF,0x80,0xEE,0xEE,0xEE,0xF5,0xFB,0xFF,0x9C,0xBE,0xB6,0xB6,0x88,0xFF,0x00
    ]

#像素:64*64
#列表大小:32*16
BMP2=[
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,
	0x60,0x38,0x08,0x0C,0x06,0xC2,0xE2,0x33,0x11,0xF9,0x11,0x33,0x73,0xE2,0x06,0x04,
	0x0C,0x18,0x30,0xE0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xF7,
	0x00,0x00,0x00,0x00,0x00,0xC3,0x87,0x06,0x0C,0xFF,0x0C,0x18,0x18,0xF0,0xE0,0x00,
	0x00,0x00,0x00,0x81,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
	0x07,0x0C,0x18,0x30,0x30,0x61,0x63,0x46,0x46,0x5F,0x46,0x46,0x43,0x63,0x20,0x30,
	0x18,0x0C,0x06,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x80,0xE0,0xE0,0xF0,0xE0,0xE0,0xC0,0x60,0x70,0x30,0x38,0x18,0x18,0x0C,
	0x0C,0x0C,0x66,0x66,0x66,0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x36,
	0x66,0x66,0x0C,0x0C,0x0C,0x18,0x18,0x30,0x30,0x60,0xE0,0xE0,0x70,0x38,0x18,0x0C,
	0xFC,0xFC,0x1C,0x04,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0xC7,0xFF,0x79,0x1B,0x03,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0xC3,0xC3,0xC7,0x06,0x0C,0x18,0x70,0xE0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0xFF,0xFF,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x03,0x03,0x03,0x83,0xFF,0x7F,0x00,0x00,
	0x00,0x00,0x00,0x03,0x07,0xFE,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0xC0,
	0xC0,0xC0,0x60,0x60,0x30,0x30,0x18,0x1C,0x0E,0x06,0x03,0x03,0x01,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x3F,0x78,0xE0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,
	0xFE,0xFE,0x06,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,
	0x1C,0x38,0xF0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xDC,0xFF,0xC3,0x01,0x01,0x01,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
]

#32-32.bmp
BMP3=[
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF8,0x0E,0x02,0x9B,0xBD,0xFF,0x65,0xED,0xCB,
	0x06,0x9C,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0xC0,0xC0,0xC0,0xC0,0xC0,0x60,0x61,0x23,0xF6,0xFD,0x7F,0x7F,0x7B,0x7D,0xF4,
	0xF6,0x23,0x60,0x60,0xC0,0xC0,0x60,0x60,0xE0,0x60,0x20,0x00,0x00,0x00,0x00,0x00,
	0x20,0xFF,0x8F,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x19,0x1B,0x06,0x0C,0x18,0x90,0xF0,0x20,
	0x00,0x01,0x1F,0x7E,0xE0,0x80,0x80,0xA0,0xF0,0x30,0x20,0x20,0x20,0x20,0x20,0x20,
	0x60,0xC0,0x80,0x80,0xF0,0xF0,0x18,0x18,0x08,0x0C,0x04,0x06,0x03,0x01,0x01,0x00,
]

board.json

{
  "name": "haas506",
  "version": "2.0.0",
  "io": {
    "OLED": {
      "type": "I2C",
      "port": 1,
      "addrWidth": 7,
      "freq": 400000,
      "mode": "master",
      "devAddr": 60
    },     
    "hc":{
      "type":"GPIO",
      "port": 17,
      "dir": "input",
      "pull":"pullup"
    }
  },
  "debugLevel": "ERROR",
  "repl": "enable",
  "replPort": 0
}



3、调试

程序运行后屏幕上显传感器状态和倒计时时间,显示成功说明硬件配置没问题
在这里插入图片描述

4、钉钉消息提醒

4.1添加钉钉机器人

在钉钉创建一个群组并进入群设置→智能助手→添加机器人→自定义。
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
注意:自定义关键词要与平台物模型一致
在这里插入图片描述
复制webhook地址,后面需要用到。
在这里插入图片描述

4.2、IoT Studio设置

进入IoT Studio产品页,开通服务后
项目管理→新建项目
在这里插入图片描述
在这里插入图片描述
添加关联产品、设备
在这里插入图片描述
在这里插入图片描述
返回主页,新建空白业务逻辑。
在这里插入图片描述
将节点拖入操作区
在这里插入图片描述

节点用线连接。
在这里插入图片描述

配置设备触发节点
选择调试设备
在这里插入图片描述
配置条件判断

在这里插入图片描述

配置钉钉机器人节点,复制钉钉webhook网址。
在这里插入图片描述

依次点击保存、部署
在这里插入图片描述

4.3 在线调试

云平台在线调试发送数据1
在这里插入图片描述

钉钉群收到消息
在这里插入图片描述
在这里插入图片描述

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值