• Micropython TurnipBit LCD5110显示英文词句


    相信大家对Microbit这款开发板都是很熟悉的了,之前发过一些Micropython开发板做的小实验,大多数都用的TPYboard这款开发板。今天我们这个实验将使用一款全新的开发板Turnipbit,使用和Turnipbit异曲同工,更加适合青少年使用,更加方便简介。
    准备工作
     
        TurnipBit开发套件(板子+扩展板) 1套
         Nokia LCD5110(PCD8544)显示屏 1块
         面包板 1个
         杜邦线 若干
         可接入互联网的电脑 1台(需要进入TurnipBit的在线编程器)
         地址:http://turnipbit.com/PythonEditor/editor.html
     
    实验步骤
         
    1、参考的TPYBoard v102控制5110的实验和代码,进行相应的修改。链接如下:
         http://docs.tpyboard.com/zh/latest/tpyboard/tutorial/v10x/script/
     
    2、将TurnipBit开发板与扩展板对接起来,连接实物图如下:
         扩展板的作用就是将TurnipBit开发板上所有的引脚进行了引出,同时还进行了分类,增加了3.3V、5V和GND的引脚,方便大家开发使用。
     
    3、接下来将lcd5110显示屏与扩展板进行相应的连接。接线图如下:
      
    LCD5110显示屏
      
    TurnipBit扩展板
    RST
    P0
    CE
    P1
    DC
    P5
    DIN
    P14
    CLK
    P13
    VCC
    3.3V
    BL
    3.3V(常亮,也可接入其他引脚通过高低电平控制亮灭)
    GND
    GND
     
    4、点击连接:http://turnipbit.com/PythonEditor/editor.html进入TurnipBit的在线编程器。录入一下代码:
      
     
     
    #***********************
    # - File Name:turnipbit_lcd5110.py
    # - Author:山东萝卜电子科技有限公司
    # - Date:2018年03月04日
    # - Description:RST=>pin0,CE=>pin1,DC=>pin5,DIN=>pin14,CLK=>pin13
    #*************************

    from microbit import *

    #ASCII 5x8
    font = bytearray(b'x00x00x00x00x00x00x00x5fx00x00x00x07x00x07x00x14x7fx14x7fx14x24x2ax7fx2ax12x23x13x08x64x62x36x49x55x22x50x00x05x03x00x00x00x1cx22x41x00x00x41x22x1cx00x14x08x3ex08x14x08x08x3ex08x08x00x50x30x00x00x08x08x08x08x08x00x60x60x00x00x20x10x08x04x02x3ex51x49x45x3ex00x42x7fx40x00x42x61x51x49x46x21x41x45x4bx31x18x14x12x7fx10x27x45x45x45x39x3cx4ax49x49x30x01x71x09x05x03x36x49x49x49x36x06x49x49x29x1ex00x36x36x00x00x00x56x36x00x00x08x14x22x41x00x14x14x14x14x14x00x41x22x14x08x02x01x51x09x06x32x49x79x41x3ex7ex11x11x11x7ex7fx49x49x49x36x3ex41x41x41x22x7fx41x41x22x1cx7fx49x49x49x41x7fx09x09x09x01x3ex41x49x49x7ax7fx08x08x08x7fx00x41x7fx41x00x20x40x41x3fx01x7fx08x14x22x41x7fx40x40x40x40x7fx02x0cx02x7fx7fx04x08x10x7fx3ex41x41x41x3ex7fx09x09x09x06x3ex41x51x21x5ex7fx09x19x29x46x46x49x49x49x31x01x01x7fx01x01x3fx40x40x40x3fx1fx20x40x20x1fx3fx40x38x40x3fx63x14x08x14x63x07x08x70x08x07x61x51x49x45x43x00x7fx41x41x00x02x04x08x10x20x00x41x41x7fx00x04x02x01x02x04x40x40x40x40x40x00x01x02x04x00x20x54x54x54x78x7fx48x44x44x38x38x44x44x44x20x38x44x44x48x7fx38x54x54x54x18x08x7ex09x01x02x0cx52x52x52x3ex7fx08x04x04x78x00x44x7dx40x00x20x40x44x3dx00x7fx10x28x44x00x00x41x7fx40x00x7cx04x18x04x78x7cx08x04x04x78x38x44x44x44x38x7cx14x14x14x08x08x14x14x18x7cx7cx08x04x04x08x48x54x54x54x20x04x3fx44x40x20x3cx40x40x20x7cx1cx20x40x20x1cx3cx40x30x40x3cx44x28x10x28x44x0cx50x50x50x3cx44x64x54x4cx44x00x08x36x41x00x00x00x7fx00x00x00x41x36x08x00x10x08x08x10x08x00x00x00x00x00')

    #reset
    def reset():
    pin0.write_digital(0) # RST on
    sleep(0.01)
    pin0.write_digital(1) # RST off

    def lcd_write(dc,data):
    pin5.write_digital(dc)#DC=0 select CMD DC=1 select DATA 
    pin1.write_digital(0) #CE=0 open
    spi.write(data)
    pin1.write_digital(1) #CE=1 close

    def lcd_init():
    reset()
    #初始化配置
    data=bytearray(b'x21xC8x06x13x0Cx20x0C')
    lcd_write(0,data)
    #清屏
    data = bytearray(504)
    lcd_write(1,data)

    #X 0-83
    #Y 0-5
    #光标位置 指定位置显示字符
    def lcd_postion(x,y):
    val_x = bytearray()
    val_x.append (0x80 + x)
    lcd_write(0,val_x)
    val_y = bytearray()
    val_y.append (0x40 + y)
    lcd_write(0,val_y)

    def lcd_print_string(message,x,y):
    lcd_postion(x,y)
    data = bytearray()
    for letter in message:
    i = (ord(letter) - 32)*5
    for b in range (0,5):
    data.append(font[i+b])
    data.append(0x00)
    lcd_write(1, data)

    spi.init(baudrate = 328125, sclk = pin13, mosi = pin14)
    lcd_init()
    lcd_print_string('I am TurnipBit',0,2)


      
     
    5、将TurnipBit通过USB数据线接入电脑,电脑正常显示出[TURNIPBIT]可移动存储设备。点击页面最底部的[下载hex]按钮,目录选择[TURNIPBIT]磁盘,将代码下载到TurnipBit中。
     
    6、等待下载完毕,TurnipBit会自动运行程序。实物效果图:
  • 相关阅读:
    Jenkin+TestNG进行自动化测试执行
    Jenkins配置
    一个简单的appium脚本
    白话以太网7层协议
    网络七层协议的形象说明
    RBAC权限管理
    五步搞定Android开发环境部署——非常详细的Android开发环境搭建教程
    extjs Combobox动态加载数据问题,mode:local 还是remote
    高效率去掉js数组中重复项
    win7(32/64)+apache2.4+php5.5+mysql5.6 环境搭建配置
  • 原文地址:https://www.cnblogs.com/xxosu/p/8510365.html
Copyright © 2020-2023  润新知