├── TPYBoard-v10x-master ├── 01.模拟红绿灯教程 │ └── main.py ├── 02.DIY金属检测仪 │ └── main.py ├── 03.DIY声光控小夜灯 │ └── main.py ├── 04.心形8x8点阵 │ └── main.py ├── 05.DIY温度计 │ ├── ds18x20.py │ ├── main.py │ └── onewire_lib.py ├── 06.驱动LCD5110显示6x8字符 │ ├── font.py │ ├── main.py │ └── upcd8544.py ├── 07.PM2.5检测仪制作 │ ├── font.py │ ├── main.py │ └── upcd8544.py ├── 08.DIY超声波测距仪 │ ├── font.py │ ├── main.py │ └── upcd8544.py ├── 09.DIY电子时钟 │ ├── DS3231.py │ ├── font.py │ ├── main.py │ └── upcd8544.py ├── 10.控制LCD5110显示温度时间(中文版) │ ├── DS3231.py │ ├── chinese.py │ ├── font.py │ ├── main.py │ └── upcd8544.py ├── 11.学习使用OLED显示屏 │ ├── font.py │ ├── main.py │ └── ssd1306_lib.py ├── 12.控制LCD1602显示字符 │ ├── main.py │ ├── tpyb_gpio_lcd1602.py │ └── tpyb_lcd1602.py ├── 13.DIY智能温控小风扇 │ ├── ds18x20.py │ ├── main.py │ └── onewire_lib.py ├── 14.驱动舵机教程 │ ├── main_servo.py │ └── main_text.py ├── 15.红外防坠落小车 │ └── main.py ├── 16.红外寻迹无线小车 │ └── main.py ├── 17.无线蓝牙智能小车 │ └── main.py ├── 18.加速度无线小车 │ ├── 控制端 │ │ └── main.py │ └── 被控制端 │ │ └── main.py ├── 31.线程和锁 │ ├── main.py │ └── main_lock.py ├── 32.学习OLED显示中文 │ ├── font.py │ ├── main.py │ └── ssd1306_lib.py ├── 33.智能蓝牙+红外循迹小车 │ ├── README.txt │ ├── boot.py │ ├── main.py │ └── tpybcdc.inf ├── 34.驱动步进电机 │ └── main.py ├── 35.自动浇花系统 │ ├── README.txt │ ├── boot.py │ ├── ds18x20.py │ ├── main.py │ ├── onewire.py │ └── tpybcdc.inf ├── 36.照相机 │ ├── README.txt │ ├── boot.py │ ├── font.py │ ├── main.py │ ├── pybcdc.inf │ └── upcd8544.py ├── 37.结合ESP8266模块实现TCP通信 │ └── main.py ├── 38.结合ESP8266模块实现HTTP请求实例 │ ├── GET │ │ └── main.py │ └── POST │ │ └── main.py ├── 39.驱动DHT11模块获取温湿度 │ ├── dht11.py │ └── main.py ├── README.md └── image │ └── v102.png ├── TPYBoard-v20x-master ├── README.md ├── TPYBoard v201 典型实例 │ ├── 01.建立云加法器 │ │ └── main.py │ └── 02.温湿度数据上传 │ │ ├── dht11.py │ │ └── main.py ├── TPYBoard v202 典型实例 │ ├── 01.GPIO的使用 │ │ └── main.py │ ├── 02.Network连接网络 │ │ ├── 实验一 │ │ │ └── main.py │ │ └── 实验二 │ │ │ └── main.py │ ├── 03.定时器 │ │ └── main.py │ ├── 04.PWM控制舵机 │ │ ├── WIFI无线控制舵机 │ │ │ └── main.py │ │ └── main.py │ ├── 05.I2C操作DS3231模块 │ │ ├── ds3231.py │ │ └── main.py │ ├── 06.通过HTTP协议上传温湿度 │ │ └── main.py │ ├── 07.自制微信远程智能温湿度计 │ │ ├── boot.py │ │ └── main.py │ ├── 08.家庭气象站 │ │ ├── SensorData.php │ │ ├── SensorTest.php │ │ ├── v102 │ │ │ ├── README.txt │ │ │ ├── boot.py │ │ │ ├── dht11.py │ │ │ ├── font.py │ │ │ ├── main.py │ │ │ ├── tpybcdc.inf │ │ │ └── upcd8544.py │ │ └── v202 │ │ │ └── main.py │ ├── 09.MQTT协议接入OneNET平台 │ │ ├── boot.py │ │ ├── main.py │ │ ├── mqtt.py │ │ └── simple.py │ ├── 10.MQTT协议2:上传数据点到OneNET平台 │ │ ├── boot.py │ │ ├── main.py │ │ ├── mqtt.py │ │ └── simple.py │ └── 11.利用单片机快速实现家庭智能控制平台 │ │ ├── device.html │ │ ├── fail.html │ │ ├── info.txt │ │ ├── login.html │ │ └── main.py └── image │ ├── v201.jpg │ └── v202.png └── TPYBoard-v70x-master ├── 01.LCD5110显示环境信息 ├── README.md ├── SHT20.py ├── font.py ├── main.py └── upcd8544.py ├── 02.LCD5110显示当前经纬度 ├── README.md ├── font.py ├── main.py └── upcd8544.py ├── 03.GPRS功能测试 ├── font.py ├── main.py └── upcd8544.py ├── 04.短信功能 ├── 单条发送 │ ├── font.py │ ├── main.py │ └── upcd8544.py └── 短信群发机 │ ├── font.py │ ├── main.py │ └── upcd8544.py ├── 05.来电显示功能 ├── font.py ├── main.py └── upcd8544.py ├── README.md └── image └── v702.png /TPYBoard-v10x-master/01.模拟红绿灯教程/main.py: -------------------------------------------------------------------------------- 1 | import pyb 2 | from pyb import Pin 3 | 4 | r_LED=Pin('Y1',Pin.OUT_PP)#red 5 | y_LED=Pin('Y2',Pin.OUT_PP)#yellow 6 | g_LED=Pin('Y3',Pin.OUT_PP)#green 7 | 8 | #数码管a~g对应的开发板引脚X1~X7 9 | d_Pins=[Pin(i,Pin.OUT_PP) for i in ['X1','X2','X3','X4','X5','X6','X7']] 10 | 11 | number=[ 12 | [0,0,0,0,0,0,1],#0 13 | [1,1,1,1,0,0,1],#1 14 | [0,0,1,0,0,1,0],#2 15 | [0,0,0,0,1,1,0],#3 16 | [1,0,0,1,1,0,0],#4 17 | [0,1,0,0,1,0,0],#5 18 | [0,1,0,0,0,0,0],#6 19 | [0,0,0,1,1,1,1],#7 20 | [0,0,0,0,0,0,0],#8 21 | [0,0,0,0,1,0,0],#9 22 | ] 23 | 24 | def display(num): 25 | global number 26 | count=0 27 | for pin in d_Pins:#X1~X7分别设置电平值 动态显示num的值 28 | pin.value(number[num][count]) 29 | count+=1 30 | 31 | if __name__=='__main__': 32 | while True: 33 | #红灯亮10秒 34 | r_LED.value(1) 35 | for i in range(0,10): 36 | display(9-i) 37 | pyb.delay(1000)#1s 38 | r_LED.value(0) 39 | #黄灯亮3秒 40 | y_LED.value(1) 41 | for i in range(0,3): 42 | display(2-i) 43 | pyb.delay(1000)#1s 44 | y_LED.value(0) 45 | #绿灯亮10秒 46 | g_LED.value(1) 47 | for i in range(0,10): 48 | display(9-i) 49 | pyb.delay(1000)#1s 50 | g_LED.value(0) -------------------------------------------------------------------------------- /TPYBoard-v10x-master/02.DIY金属检测仪/main.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TPYBoard/developmentBoard/535a975480a6755394cedfe3708a05952d9b6539/TPYBoard-v10x-master/02.DIY金属检测仪/main.py -------------------------------------------------------------------------------- /TPYBoard-v10x-master/03.DIY声光控小夜灯/main.py: -------------------------------------------------------------------------------- 1 | # main.py -- put your code here! 2 | import pyb 3 | from pyb import Pin 4 | 5 | voice = Pin('Y1',Pin.IN) 6 | light = Pin('Y2',Pin.IN) 7 | led = pyb.Pin("X1",pyb.Pin.OUT_PP) 8 | print('start') 9 | print('guang',light.value()) 10 | while 1: 11 | if light.value()==1: 12 | if voice.value()==1: 13 | led.value(0) 14 | pyb.LED(2).off() 15 | pyb.LED(3).off() 16 | pyb.LED(4).on() 17 | else: 18 | pyb.LED(3).off() 19 | pyb.LED(4).off() 20 | led.value(1) 21 | pyb.LED(2).on() 22 | pyb.delay(5000) 23 | else: 24 | pyb.LED(3).on() 25 | pyb.LED(2).off() 26 | pyb.LED(4).off() 27 | led.value(0) 28 | -------------------------------------------------------------------------------- /TPYBoard-v10x-master/04.心形8x8点阵/main.py: -------------------------------------------------------------------------------- 1 | # main.py -- put your code here! 2 | import pyb 3 | from pyb import Pin 4 | x_row = [Pin(i, Pin.OUT_PP) for i in ['X1','X2','X3','X4','X5','X6','X7','X8']] 5 | y_col = [Pin(i, Pin.OUT_PP) for i in ['Y1','Y2','Y3','Y4','Y5','Y6','Y7','Y8']] 6 | tuxing = [ 7 | #大心 8 | ['11111111','10011001','00000000','00000000','10000001','11000011','11100111','11111111'], 9 | #小心 10 | ['11111111','11111111','10011001','10000001','11000011','11100111','11111111','11111111'] 11 | ] 12 | def displayLED(num): 13 | for i,j in enumerate(x_row): 14 | x_row[i-1].value(0) 15 | data = tuxing[num][i] 16 | for k,v in enumerate(data): 17 | y_col[k].value(int(v)) 18 | j.value(1) 19 | pyb.delay(1) 20 | 21 | while True: 22 | for i in range(2): 23 | for k in range(100): 24 | displayLED(i) -------------------------------------------------------------------------------- /TPYBoard-v10x-master/05.DIY温度计/ds18x20.py: -------------------------------------------------------------------------------- 1 | """ 2 | DS18x20 temperature sensor driver for MicroPython. 3 | 4 | This driver uses the OneWire driver to control DS18S20 and DS18B20 5 | temperature sensors. It supports multiple devices on the same 1-wire bus. 6 | 7 | The following example assumes the ground of your DS18x20 is connected to 8 | Y11, vcc is connected to Y9 and the data pin is connected to Y10. 9 | 10 | >>> from pyb import Pin 11 | >>> gnd = Pin('Y11', Pin.OUT_PP) 12 | >>> gnd.low() 13 | >>> vcc = Pin('Y9', Pin.OUT_PP) 14 | >>> vcc.high() 15 | 16 | >>> from ds18x20 import DS18X20 17 | >>> d = DS18X20(Pin('Y10')) 18 | 19 | Call read_temps to read all sensors: 20 | 21 | >>> result = d.read_temps() 22 | >>> print(result) 23 | [20.875, 20.8125] 24 | 25 | Call read_temp to read the temperature of a specific sensor: 26 | 27 | >>> result = d.read_temp(d.roms[0]) 28 | >>> print(result) 29 | 20.25 30 | 31 | If only one DS18x20 is attached to the bus, then you don't need to 32 | pass a ROM to read_temp: 33 | 34 | >>> result = d.read_temp() 35 | >>> print(result) 36 | 20.25 37 | 38 | """ 39 | 40 | from onewire_lib import OneWire 41 | 42 | class DS18X20(object): 43 | def __init__(self, pin): 44 | self.ow = OneWire(pin) 45 | # Scan the 1-wire devices, but only keep those which have the 46 | # correct # first byte in their rom for a DS18x20 device. 47 | self.roms = [rom for rom in self.ow.scan() if rom[0] == 0x10 or rom[0] == 0x28] 48 | 49 | def read_temp(self, rom=None): 50 | """ 51 | Read and return the temperature of one DS18x20 device. 52 | Pass the 8-byte bytes object with the ROM of the specific device you want to read. 53 | If only one DS18x20 device is attached to the bus you may omit the rom parameter. 54 | """ 55 | rom = rom or self.roms[0] 56 | ow = self.ow 57 | ow.reset() 58 | ow.select_rom(rom) 59 | ow.write_byte(0x44) # Convert Temp 60 | while True: 61 | if ow.read_bit(): 62 | break 63 | ow.reset() 64 | ow.select_rom(rom) 65 | ow.write_byte(0xbe) # Read scratch 66 | data = ow.read_bytes(9) 67 | return self.convert_temp(rom[0], data) 68 | 69 | def read_temps(self): 70 | """ 71 | Read and return the temperatures of all attached DS18x20 devices. 72 | """ 73 | temps = [] 74 | for rom in self.roms: 75 | temps.append(self.read_temp(rom)) 76 | return temps 77 | 78 | def convert_temp(self, rom0, data): 79 | """ 80 | Convert the raw temperature data into degrees celsius and return as a float. 81 | """ 82 | temp_lsb = data[0] 83 | temp_msb = data[1] 84 | if rom0 == 0x10: 85 | if temp_msb != 0: 86 | # convert negative number 87 | temp_read = temp_lsb >> 1 | 0x80 # truncate bit 0 by shifting, fill high bit with 1. 88 | temp_read = -((~temp_read + 1) & 0xff) # now convert from two's complement 89 | else: 90 | temp_read = temp_lsb >> 1 # truncate bit 0 by shifting 91 | count_remain = data[6] 92 | count_per_c = data[7] 93 | temp = temp_read - 0.25 + (count_per_c - count_remain) / count_per_c 94 | return temp 95 | elif rom0 == 0x28: 96 | return (temp_msb << 8 | temp_lsb) / 16 97 | else: 98 | assert False 99 | -------------------------------------------------------------------------------- /TPYBoard-v10x-master/05.DIY温度计/main.py: -------------------------------------------------------------------------------- 1 | import pyb 2 | from pyb import Pin 3 | from ds18x20 import DS18X20 4 | from pyb import Timer 5 | 6 | x_PIN = [Pin(i, Pin.OUT_PP) for i in ['X1','X2','X3','X4','X5','X6','X7','X8']] 7 | y_PIN = [Pin(i, Pin.OUT_PP) for i in ['Y1','Y2','Y3','Y4','Y5','Y6','Y7','Y8']] 8 | temp=['0000,0110,0110,0110,0110,0110,0110,0000','1101,1101,1101,1101,1101,1101,1101,1101', 9 | '0000,1110,1110,0000,0111,0111,0111,0000','0000,1110,1110,0000,1110,1110,1110,0000', 10 | '0101,0101,0101,0000,1101,1101,1101,1101','0000,0111,0111,0000,1110,1110,1110,0000', 11 | '0000,0111,0111,0000,0110,0110,0110,0000','0000,1110,1110,1110,1110,1110,1110,1110', 12 | '0000,0110,0110,0000,0110,0110,0110,0000','0000,0110,0110,0000,1110,1110,1110,0000'] 13 | tempValue=0 14 | def show(l_num,r_num): 15 | flag=0 16 | for x_ in range(0,8): 17 | for x_ in range(0,8): 18 | if x_!=flag: 19 | x_PIN[x_].value(0) 20 | left_ = temp[l_num] 21 | left_item=left_.split(',') 22 | right_ = temp[r_num] 23 | right_item=right_.split(',') 24 | li_l=left_item[flag] 25 | li_r=right_item[flag] 26 | y_PIN[0].value(int(li_l[:1])) 27 | y_PIN[1].value(int(li_l[1:2])) 28 | y_PIN[2].value(int(li_l[2:3])) 29 | y_PIN[3].value(int(li_l[3:4])) 30 | y_PIN[4].value(int(li_r[:1])) 31 | y_PIN[5].value(int(li_r[1:2])) 32 | y_PIN[6].value(int(li_r[2:3])) 33 | y_PIN[7].value(int(li_r[3:4])) 34 | x_PIN[flag].value(1) 35 | flag=flag+1 36 | pyb.delay(2) 37 | def display(time_,l_num,r_num): 38 | for x in range(0,time_): 39 | for y in range(0,110): 40 | show(l_num,r_num) 41 | if __name__=='__main__': 42 | #time_t=Timer(4,freq=5,callback=randSensor) 43 | DQ=DS18X20(Pin('Y10'))#DQ 44 | while 1: 45 | tempValue =int(DQ.read_temp()) 46 | print(tempValue) 47 | l_n=tempValue//10 48 | r_n=tempValue%10 49 | print(l_n,'-',r_n) 50 | display(1,l_n,r_n) 51 | for i in x_PIN: 52 | i.value(0) -------------------------------------------------------------------------------- /TPYBoard-v10x-master/06.驱动LCD5110显示6x8字符/font.py: -------------------------------------------------------------------------------- 1 | class FONT6_8: 2 | """docstring for FONT6_8""" 3 | FONTTYPE6_8 = [ 4 | [0x00, 0x00, 0x00, 0x00, 0x00, 0x00] # 20 5 | ,[0x00, 0x00, 0x00, 0x5f, 0x00, 0x00] # 21 ! 6 | ,[0x00, 0x00, 0x07, 0x00, 0x07, 0x00] # 22 " 7 | ,[0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14] # 23 # 8 | ,[0x00, 0x24, 0x2a, 0x7f, 0x2a, 0x12] # 24 $ 9 | ,[0x00, 0x23, 0x13, 0x08, 0x64, 0x62] # 25 % 10 | ,[0x00, 0x36, 0x49, 0x55, 0x22, 0x50] # 26 & 11 | ,[0x00, 0x00, 0x05, 0x03, 0x00, 0x00] # 27 ' 12 | ,[0x00, 0x00, 0x1c, 0x22, 0x41, 0x00] # 28 ( 13 | ,[0x00, 0x00, 0x41, 0x22, 0x1c, 0x00] # 29 ) 14 | ,[0x00, 0x14, 0x08, 0x3e, 0x08, 0x14] # 2a * 15 | ,[0x00, 0x08, 0x08, 0x3e, 0x08, 0x08] # 2b + 16 | ,[0x00, 0x00, 0x50, 0x30, 0x00, 0x00] # 2c , 17 | ,[0x00, 0x08, 0x08, 0x08, 0x08, 0x08] # 2d - 18 | ,[0x00, 0x00, 0x60, 0x60, 0x00, 0x00] # 2e . 19 | ,[0x00, 0x20, 0x10, 0x08, 0x04, 0x02] # 2f / 20 | ,[0x00, 0x3e, 0x51, 0x49, 0x45, 0x3e] # 30 0 21 | ,[0x00, 0x00, 0x42, 0x7f, 0x40, 0x00] # 31 1 22 | ,[0x00, 0x42, 0x61, 0x51, 0x49, 0x46] # 32 2 23 | ,[0x00, 0x21, 0x41, 0x45, 0x4b, 0x31] # 33 3 24 | ,[0x00, 0x18, 0x14, 0x12, 0x7f, 0x10] # 34 4 25 | ,[0x00, 0x27, 0x45, 0x45, 0x45, 0x39] # 35 5 26 | ,[0x00, 0x3c, 0x4a, 0x49, 0x49, 0x30] # 36 6 27 | ,[0x00, 0x01, 0x71, 0x09, 0x05, 0x03] # 37 7 28 | ,[0x00, 0x36, 0x49, 0x49, 0x49, 0x36] # 38 8 29 | ,[0x00, 0x06, 0x49, 0x49, 0x29, 0x1e] # 39 9 30 | ,[0x00, 0x00, 0x36, 0x36, 0x00, 0x00] # 3a : 31 | ,[0x00, 0x00, 0x56, 0x36, 0x00, 0x00] # 3b ; 32 | ,[0x00, 0x08, 0x14, 0x22, 0x41, 0x00] # 3c < 33 | ,[0x00, 0x14, 0x14, 0x14, 0x14, 0x14] # 3d = 34 | ,[0x00, 0x00, 0x41, 0x22, 0x14, 0x08] # 3e > 35 | ,[0x00, 0x02, 0x01, 0x51, 0x09, 0x06] # 3f ? 36 | ,[0x00, 0x32, 0x49, 0x79, 0x41, 0x3e] # 40 @ 37 | ,[0x00, 0x7e, 0x11, 0x11, 0x11, 0x7e] # 41 A 38 | ,[0x00, 0x7f, 0x49, 0x49, 0x49, 0x36] # 42 B 39 | ,[0x00, 0x3e, 0x41, 0x41, 0x41, 0x22] # 43 C 40 | ,[0x00, 0x7f, 0x41, 0x41, 0x22, 0x1c] # 44 D 41 | ,[0x00, 0x7f, 0x49, 0x49, 0x49, 0x41] # 45 E 42 | ,[0x00, 0x7f, 0x09, 0x09, 0x09, 0x01] # 46 F 43 | ,[0x00, 0x3e, 0x41, 0x49, 0x49, 0x7a] # 47 G 44 | ,[0x00, 0x7f, 0x08, 0x08, 0x08, 0x7f] # 48 H 45 | ,[0x00, 0x00, 0x41, 0x7f, 0x41, 0x00] # 49 I 46 | ,[0x00, 0x20, 0x40, 0x41, 0x3f, 0x01] # 4a J 47 | ,[0x00, 0x7f, 0x08, 0x14, 0x22, 0x41] # 4b K 48 | ,[0x00, 0x7f, 0x40, 0x40, 0x40, 0x40] # 4c L 49 | ,[0x00, 0x7f, 0x02, 0x0c, 0x02, 0x7f] # 4d M 50 | ,[0x00, 0x7f, 0x04, 0x08, 0x10, 0x7f] # 4e N 51 | ,[0x00, 0x3e, 0x41, 0x41, 0x41, 0x3e] # 4f O 52 | ,[0x00, 0x7f, 0x09, 0x09, 0x09, 0x06] # 50 P 53 | ,[0x00, 0x3e, 0x41, 0x51, 0x21, 0x5e] # 51 Q 54 | ,[0x00, 0x7f, 0x09, 0x19, 0x29, 0x46] # 52 R 55 | ,[0x00, 0x46, 0x49, 0x49, 0x49, 0x31] # 53 S 56 | ,[0x00, 0x01, 0x01, 0x7f, 0x01, 0x01] # 54 T 57 | ,[0x00, 0x3f, 0x40, 0x40, 0x40, 0x3f] # 55 U 58 | ,[0x00, 0x1f, 0x20, 0x40, 0x20, 0x1f] # 56 V 59 | ,[0x00, 0x3f, 0x40, 0x38, 0x40, 0x3f] # 57 W 60 | ,[0x00, 0x63, 0x14, 0x08, 0x14, 0x63] # 58 X 61 | ,[0x00, 0x07, 0x08, 0x70, 0x08, 0x07] # 59 Y 62 | ,[0x00, 0x61, 0x51, 0x49, 0x45, 0x43] # 5a Z 63 | ,[0x00, 0x00, 0x7f, 0x41, 0x41, 0x00] # 5b [ 64 | ,[0x00, 0x02, 0x04, 0x08, 0x10, 0x20] # 5c \ # 65 | ,[0x00, 0x00, 0x41, 0x41, 0x7f, 0x00] # 5d ] 66 | ,[0x00, 0x04, 0x02, 0x01, 0x02, 0x04] # 5e ^ 67 | ,[0x00, 0x40, 0x40, 0x40, 0x40, 0x40] # 5f _ 68 | ,[0x00, 0x00, 0x01, 0x02, 0x04, 0x00] # 60 ` 69 | ,[0x00, 0x20, 0x54, 0x54, 0x54, 0x78] # 61 a 70 | ,[0x00, 0x7f, 0x48, 0x44, 0x44, 0x38] # 62 b 71 | ,[0x00, 0x38, 0x44, 0x44, 0x44, 0x20] # 63 c 72 | ,[0x00, 0x38, 0x44, 0x44, 0x48, 0x7f] # 64 d 73 | ,[0x00, 0x38, 0x54, 0x54, 0x54, 0x18] # 65 e 74 | ,[0x00, 0x08, 0x7e, 0x09, 0x01, 0x02] # 66 f 75 | ,[0x00, 0x0c, 0x52, 0x52, 0x52, 0x3e] # 67 g 76 | ,[0x00, 0x7f, 0x08, 0x04, 0x04, 0x78] # 68 h 77 | ,[0x00, 0x00, 0x44, 0x7d, 0x40, 0x00] # 69 i 78 | ,[0x00, 0x20, 0x40, 0x44, 0x3d, 0x00] # 6a j 79 | ,[0x00, 0x7f, 0x10, 0x28, 0x44, 0x00] # 6b k 80 | ,[0x00, 0x00, 0x41, 0x7f, 0x40, 0x00] # 6c l 81 | ,[0x00, 0x7c, 0x04, 0x18, 0x04, 0x78] # 6d m 82 | ,[0x00, 0x7c, 0x08, 0x04, 0x04, 0x78] # 6e n 83 | ,[0x00, 0x38, 0x44, 0x44, 0x44, 0x38] # 6f o 84 | ,[0x00, 0x7c, 0x14, 0x14, 0x14, 0x08] # 70 p 85 | ,[0x00, 0x08, 0x14, 0x14, 0x18, 0x7c] # 71 q 86 | ,[0x00, 0x7c, 0x08, 0x04, 0x04, 0x08] # 72 r 87 | ,[0x00, 0x48, 0x54, 0x54, 0x54, 0x20] # 73 s 88 | ,[0x00, 0x04, 0x3f, 0x44, 0x40, 0x20] # 74 t 89 | ,[0x00, 0x3c, 0x40, 0x40, 0x20, 0x7c] # 75 u 90 | ,[0x00, 0x1c, 0x20, 0x40, 0x20, 0x1c] # 76 v 91 | ,[0x00, 0x3c, 0x40, 0x30, 0x40, 0x3c] # 77 w 92 | ,[0x00, 0x44, 0x28, 0x10, 0x28, 0x44] # 78 x 93 | ,[0x00, 0x0c, 0x50, 0x50, 0x50, 0x3c] # 79 y 94 | ,[0x00, 0x44, 0x64, 0x54, 0x4c, 0x44] # 7a z 95 | ,[0x00, 0x00, 0x08, 0x36, 0x41, 0x00] # 7b [ 96 | ,[0x00, 0x00, 0x00, 0x7f, 0x00, 0x00] # 7c | 97 | ,[0x00, 0x00, 0x41, 0x36, 0x08, 0x00] # 7d ] 98 | ,[0x00, 0x10, 0x08, 0x08, 0x10, 0x08] # 7e ~ 99 | ,[0x00, 0x78, 0x46, 0x41, 0x46, 0x78] # 7f (delete) 100 | ] 101 | 102 | def get_font6_8(self, data): 103 | return self.FONTTYPE6_8[bytearray(data)[0] - 0x20] 104 | 105 | -------------------------------------------------------------------------------- /TPYBoard-v10x-master/06.驱动LCD5110显示6x8字符/main.py: -------------------------------------------------------------------------------- 1 | #main.py 2 | import pyb 3 | import upcd8544 4 | from machine import SPI,Pin 5 | 6 | def main(): 7 | SPI = pyb.SPI(1) #DIN=>X8-MOSI/CLK=>X6-SCK 8 | #DIN =>SPI(1).MOSI 'X8' data flow (Master out, Slave in) 9 | #CLK =>SPI(1).SCK 'X6' SPI clock 10 | 11 | RST = pyb.Pin('Y10') 12 | CE = pyb.Pin('Y11') 13 | DC = pyb.Pin('Y9') 14 | LIGHT = pyb.Pin('Y12') 15 | lcd_5110 = upcd8544.PCD8544(SPI, RST, CE, DC, LIGHT) 16 | 17 | lcd_5110.lcd_write_string('Hello Python!',0,0) 18 | lcd_5110.lcd_write_string('Micropython',6,1) 19 | lcd_5110.lcd_write_string('TPYBoard',12,2) 20 | lcd_5110.lcd_write_string('v102',60,3) 21 | lcd_5110.lcd_write_string('This is a test of LCD5110',0,4) 22 | 23 | 24 | if __name__ == '__main__': 25 | main() 26 | -------------------------------------------------------------------------------- /TPYBoard-v10x-master/07.PM2.5检测仪制作/font.py: -------------------------------------------------------------------------------- 1 | class FONT6_8: 2 | """docstring for FONT6_8""" 3 | FONTTYPE6_8 = [ 4 | [0x00, 0x00, 0x00, 0x00, 0x00, 0x00] # 20 5 | ,[0x00, 0x00, 0x00, 0x5f, 0x00, 0x00] # 21 ! 6 | ,[0x00, 0x00, 0x07, 0x00, 0x07, 0x00] # 22 " 7 | ,[0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14] # 23 # 8 | ,[0x00, 0x24, 0x2a, 0x7f, 0x2a, 0x12] # 24 $ 9 | ,[0x00, 0x23, 0x13, 0x08, 0x64, 0x62] # 25 % 10 | ,[0x00, 0x36, 0x49, 0x55, 0x22, 0x50] # 26 & 11 | ,[0x00, 0x00, 0x05, 0x03, 0x00, 0x00] # 27 ' 12 | ,[0x00, 0x00, 0x1c, 0x22, 0x41, 0x00] # 28 ( 13 | ,[0x00, 0x00, 0x41, 0x22, 0x1c, 0x00] # 29 ) 14 | ,[0x00, 0x14, 0x08, 0x3e, 0x08, 0x14] # 2a * 15 | ,[0x00, 0x08, 0x08, 0x3e, 0x08, 0x08] # 2b + 16 | ,[0x00, 0x00, 0x50, 0x30, 0x00, 0x00] # 2c , 17 | ,[0x00, 0x08, 0x08, 0x08, 0x08, 0x08] # 2d - 18 | ,[0x00, 0x00, 0x60, 0x60, 0x00, 0x00] # 2e . 19 | ,[0x00, 0x20, 0x10, 0x08, 0x04, 0x02] # 2f / 20 | ,[0x00, 0x3e, 0x51, 0x49, 0x45, 0x3e] # 30 0 21 | ,[0x00, 0x00, 0x42, 0x7f, 0x40, 0x00] # 31 1 22 | ,[0x00, 0x42, 0x61, 0x51, 0x49, 0x46] # 32 2 23 | ,[0x00, 0x21, 0x41, 0x45, 0x4b, 0x31] # 33 3 24 | ,[0x00, 0x18, 0x14, 0x12, 0x7f, 0x10] # 34 4 25 | ,[0x00, 0x27, 0x45, 0x45, 0x45, 0x39] # 35 5 26 | ,[0x00, 0x3c, 0x4a, 0x49, 0x49, 0x30] # 36 6 27 | ,[0x00, 0x01, 0x71, 0x09, 0x05, 0x03] # 37 7 28 | ,[0x00, 0x36, 0x49, 0x49, 0x49, 0x36] # 38 8 29 | ,[0x00, 0x06, 0x49, 0x49, 0x29, 0x1e] # 39 9 30 | ,[0x00, 0x00, 0x36, 0x36, 0x00, 0x00] # 3a : 31 | ,[0x00, 0x00, 0x56, 0x36, 0x00, 0x00] # 3b ; 32 | ,[0x00, 0x08, 0x14, 0x22, 0x41, 0x00] # 3c < 33 | ,[0x00, 0x14, 0x14, 0x14, 0x14, 0x14] # 3d = 34 | ,[0x00, 0x00, 0x41, 0x22, 0x14, 0x08] # 3e > 35 | ,[0x00, 0x02, 0x01, 0x51, 0x09, 0x06] # 3f ? 36 | ,[0x00, 0x32, 0x49, 0x79, 0x41, 0x3e] # 40 @ 37 | ,[0x00, 0x7e, 0x11, 0x11, 0x11, 0x7e] # 41 A 38 | ,[0x00, 0x7f, 0x49, 0x49, 0x49, 0x36] # 42 B 39 | ,[0x00, 0x3e, 0x41, 0x41, 0x41, 0x22] # 43 C 40 | ,[0x00, 0x7f, 0x41, 0x41, 0x22, 0x1c] # 44 D 41 | ,[0x00, 0x7f, 0x49, 0x49, 0x49, 0x41] # 45 E 42 | ,[0x00, 0x7f, 0x09, 0x09, 0x09, 0x01] # 46 F 43 | ,[0x00, 0x3e, 0x41, 0x49, 0x49, 0x7a] # 47 G 44 | ,[0x00, 0x7f, 0x08, 0x08, 0x08, 0x7f] # 48 H 45 | ,[0x00, 0x00, 0x41, 0x7f, 0x41, 0x00] # 49 I 46 | ,[0x00, 0x20, 0x40, 0x41, 0x3f, 0x01] # 4a J 47 | ,[0x00, 0x7f, 0x08, 0x14, 0x22, 0x41] # 4b K 48 | ,[0x00, 0x7f, 0x40, 0x40, 0x40, 0x40] # 4c L 49 | ,[0x00, 0x7f, 0x02, 0x0c, 0x02, 0x7f] # 4d M 50 | ,[0x00, 0x7f, 0x04, 0x08, 0x10, 0x7f] # 4e N 51 | ,[0x00, 0x3e, 0x41, 0x41, 0x41, 0x3e] # 4f O 52 | ,[0x00, 0x7f, 0x09, 0x09, 0x09, 0x06] # 50 P 53 | ,[0x00, 0x3e, 0x41, 0x51, 0x21, 0x5e] # 51 Q 54 | ,[0x00, 0x7f, 0x09, 0x19, 0x29, 0x46] # 52 R 55 | ,[0x00, 0x46, 0x49, 0x49, 0x49, 0x31] # 53 S 56 | ,[0x00, 0x01, 0x01, 0x7f, 0x01, 0x01] # 54 T 57 | ,[0x00, 0x3f, 0x40, 0x40, 0x40, 0x3f] # 55 U 58 | ,[0x00, 0x1f, 0x20, 0x40, 0x20, 0x1f] # 56 V 59 | ,[0x00, 0x3f, 0x40, 0x38, 0x40, 0x3f] # 57 W 60 | ,[0x00, 0x63, 0x14, 0x08, 0x14, 0x63] # 58 X 61 | ,[0x00, 0x07, 0x08, 0x70, 0x08, 0x07] # 59 Y 62 | ,[0x00, 0x61, 0x51, 0x49, 0x45, 0x43] # 5a Z 63 | ,[0x00, 0x00, 0x7f, 0x41, 0x41, 0x00] # 5b [ 64 | ,[0x00, 0x02, 0x04, 0x08, 0x10, 0x20] # 5c \ # 65 | ,[0x00, 0x00, 0x41, 0x41, 0x7f, 0x00] # 5d ] 66 | ,[0x00, 0x04, 0x02, 0x01, 0x02, 0x04] # 5e ^ 67 | ,[0x00, 0x40, 0x40, 0x40, 0x40, 0x40] # 5f _ 68 | ,[0x00, 0x00, 0x01, 0x02, 0x04, 0x00] # 60 ` 69 | ,[0x00, 0x20, 0x54, 0x54, 0x54, 0x78] # 61 a 70 | ,[0x00, 0x7f, 0x48, 0x44, 0x44, 0x38] # 62 b 71 | ,[0x00, 0x38, 0x44, 0x44, 0x44, 0x20] # 63 c 72 | ,[0x00, 0x38, 0x44, 0x44, 0x48, 0x7f] # 64 d 73 | ,[0x00, 0x38, 0x54, 0x54, 0x54, 0x18] # 65 e 74 | ,[0x00, 0x08, 0x7e, 0x09, 0x01, 0x02] # 66 f 75 | ,[0x00, 0x0c, 0x52, 0x52, 0x52, 0x3e] # 67 g 76 | ,[0x00, 0x7f, 0x08, 0x04, 0x04, 0x78] # 68 h 77 | ,[0x00, 0x00, 0x44, 0x7d, 0x40, 0x00] # 69 i 78 | ,[0x00, 0x20, 0x40, 0x44, 0x3d, 0x00] # 6a j 79 | ,[0x00, 0x7f, 0x10, 0x28, 0x44, 0x00] # 6b k 80 | ,[0x00, 0x00, 0x41, 0x7f, 0x40, 0x00] # 6c l 81 | ,[0x00, 0x7c, 0x04, 0x18, 0x04, 0x78] # 6d m 82 | ,[0x00, 0x7c, 0x08, 0x04, 0x04, 0x78] # 6e n 83 | ,[0x00, 0x38, 0x44, 0x44, 0x44, 0x38] # 6f o 84 | ,[0x00, 0x7c, 0x14, 0x14, 0x14, 0x08] # 70 p 85 | ,[0x00, 0x08, 0x14, 0x14, 0x18, 0x7c] # 71 q 86 | ,[0x00, 0x7c, 0x08, 0x04, 0x04, 0x08] # 72 r 87 | ,[0x00, 0x48, 0x54, 0x54, 0x54, 0x20] # 73 s 88 | ,[0x00, 0x04, 0x3f, 0x44, 0x40, 0x20] # 74 t 89 | ,[0x00, 0x3c, 0x40, 0x40, 0x20, 0x7c] # 75 u 90 | ,[0x00, 0x1c, 0x20, 0x40, 0x20, 0x1c] # 76 v 91 | ,[0x00, 0x3c, 0x40, 0x30, 0x40, 0x3c] # 77 w 92 | ,[0x00, 0x44, 0x28, 0x10, 0x28, 0x44] # 78 x 93 | ,[0x00, 0x0c, 0x50, 0x50, 0x50, 0x3c] # 79 y 94 | ,[0x00, 0x44, 0x64, 0x54, 0x4c, 0x44] # 7a z 95 | ,[0x00, 0x00, 0x08, 0x36, 0x41, 0x00] # 7b [ 96 | ,[0x00, 0x00, 0x00, 0x7f, 0x00, 0x00] # 7c | 97 | ,[0x00, 0x00, 0x41, 0x36, 0x08, 0x00] # 7d ] 98 | ,[0x00, 0x10, 0x08, 0x08, 0x10, 0x08] # 7e ~ 99 | ,[0x00, 0x78, 0x46, 0x41, 0x46, 0x78] # 7f (delete) 100 | ] 101 | 102 | def get_font6_8(self, data): 103 | return self.FONTTYPE6_8[bytearray(data)[0] - 0x20] 104 | 105 | -------------------------------------------------------------------------------- /TPYBoard-v10x-master/07.PM2.5检测仪制作/main.py: -------------------------------------------------------------------------------- 1 | #main.py 2 | import pyb 3 | import upcd8544 4 | from machine import SPI,Pin 5 | from pyb import UART 6 | from ubinascii import hexlify 7 | from ubinascii import * 8 | 9 | 10 | leds = [pyb.LED(i) for i in range(1,5)] 11 | P,L,SHUCHU=0,0,0 12 | #A比例系数,在北方一般使用800-1000.南方空气好一些,一般使用600-800.这个还和你使用的传感器灵敏度有关的,需要自己测试再定下来 13 | A=800 14 | #G为固定系数,是为了把串口收到的数据转换成PM标准值 15 | G=1024/5 16 | SPI = pyb.SPI(1) #DIN=>X8-MOSI/CLK=>X6-SCK 17 | #DIN =>SPI(1).MOSI 'X8' data flow (Master out, Slave in) 18 | #CLK =>SPI(1).SCK 'X6' SPI clock 19 | RST = pyb.Pin('Y10') 20 | CE = pyb.Pin('Y11') 21 | DC = pyb.Pin('Y9') 22 | LIGHT = pyb.Pin('Y12') 23 | lcd_5110 = upcd8544.PCD8544(SPI, RST, CE, DC, LIGHT) 24 | u2 = UART(2, 2400) 25 | count_=0 26 | def ChangeLEDState(num_): 27 | global leds 28 | len_=len(leds) 29 | for i in range(0,len_): 30 | if i!=num_: 31 | leds[i].off() 32 | else: 33 | leds[i].on() 34 | while True: 35 | u2.init(2400, bits=8, parity=None, stop=1) 36 | pyb.delay(80) 37 | Quality='DATA NULL' 38 | if(u2.any()>0): 39 | u2.deinit() 40 | _dataRead=u2.read() 41 | #R代表截取数据的起始位 42 | R=_dataRead.find(b'\xaa') 43 | #R>-1代表存在起始位,长度大于起始位位置+2 44 | if R>-1 and len(_dataRead)>(R+2): 45 | P=_dataRead[R+1] 46 | L=_dataRead[R+2] 47 | #把串口收到的十六进制数据转换成十进制 48 | SHI=P*256+L 49 | SHUCHU=SHI/G*A 50 | if(SHUCHU<35): 51 | Quality = 'Excellente' 52 | print('环境质量:优','PM2.5=',SHUCHU) 53 | count_=1 54 | elif(35 35 | ,[0x00, 0x02, 0x01, 0x51, 0x09, 0x06] # 3f ? 36 | ,[0x00, 0x32, 0x49, 0x79, 0x41, 0x3e] # 40 @ 37 | ,[0x00, 0x7e, 0x11, 0x11, 0x11, 0x7e] # 41 A 38 | ,[0x00, 0x7f, 0x49, 0x49, 0x49, 0x36] # 42 B 39 | ,[0x00, 0x3e, 0x41, 0x41, 0x41, 0x22] # 43 C 40 | ,[0x00, 0x7f, 0x41, 0x41, 0x22, 0x1c] # 44 D 41 | ,[0x00, 0x7f, 0x49, 0x49, 0x49, 0x41] # 45 E 42 | ,[0x00, 0x7f, 0x09, 0x09, 0x09, 0x01] # 46 F 43 | ,[0x00, 0x3e, 0x41, 0x49, 0x49, 0x7a] # 47 G 44 | ,[0x00, 0x7f, 0x08, 0x08, 0x08, 0x7f] # 48 H 45 | ,[0x00, 0x00, 0x41, 0x7f, 0x41, 0x00] # 49 I 46 | ,[0x00, 0x20, 0x40, 0x41, 0x3f, 0x01] # 4a J 47 | ,[0x00, 0x7f, 0x08, 0x14, 0x22, 0x41] # 4b K 48 | ,[0x00, 0x7f, 0x40, 0x40, 0x40, 0x40] # 4c L 49 | ,[0x00, 0x7f, 0x02, 0x0c, 0x02, 0x7f] # 4d M 50 | ,[0x00, 0x7f, 0x04, 0x08, 0x10, 0x7f] # 4e N 51 | ,[0x00, 0x3e, 0x41, 0x41, 0x41, 0x3e] # 4f O 52 | ,[0x00, 0x7f, 0x09, 0x09, 0x09, 0x06] # 50 P 53 | ,[0x00, 0x3e, 0x41, 0x51, 0x21, 0x5e] # 51 Q 54 | ,[0x00, 0x7f, 0x09, 0x19, 0x29, 0x46] # 52 R 55 | ,[0x00, 0x46, 0x49, 0x49, 0x49, 0x31] # 53 S 56 | ,[0x00, 0x01, 0x01, 0x7f, 0x01, 0x01] # 54 T 57 | ,[0x00, 0x3f, 0x40, 0x40, 0x40, 0x3f] # 55 U 58 | ,[0x00, 0x1f, 0x20, 0x40, 0x20, 0x1f] # 56 V 59 | ,[0x00, 0x3f, 0x40, 0x38, 0x40, 0x3f] # 57 W 60 | ,[0x00, 0x63, 0x14, 0x08, 0x14, 0x63] # 58 X 61 | ,[0x00, 0x07, 0x08, 0x70, 0x08, 0x07] # 59 Y 62 | ,[0x00, 0x61, 0x51, 0x49, 0x45, 0x43] # 5a Z 63 | ,[0x00, 0x00, 0x7f, 0x41, 0x41, 0x00] # 5b [ 64 | ,[0x00, 0x02, 0x04, 0x08, 0x10, 0x20] # 5c \ # 65 | ,[0x00, 0x00, 0x41, 0x41, 0x7f, 0x00] # 5d ] 66 | ,[0x00, 0x04, 0x02, 0x01, 0x02, 0x04] # 5e ^ 67 | ,[0x00, 0x40, 0x40, 0x40, 0x40, 0x40] # 5f _ 68 | ,[0x00, 0x00, 0x01, 0x02, 0x04, 0x00] # 60 ` 69 | ,[0x00, 0x20, 0x54, 0x54, 0x54, 0x78] # 61 a 70 | ,[0x00, 0x7f, 0x48, 0x44, 0x44, 0x38] # 62 b 71 | ,[0x00, 0x38, 0x44, 0x44, 0x44, 0x20] # 63 c 72 | ,[0x00, 0x38, 0x44, 0x44, 0x48, 0x7f] # 64 d 73 | ,[0x00, 0x38, 0x54, 0x54, 0x54, 0x18] # 65 e 74 | ,[0x00, 0x08, 0x7e, 0x09, 0x01, 0x02] # 66 f 75 | ,[0x00, 0x0c, 0x52, 0x52, 0x52, 0x3e] # 67 g 76 | ,[0x00, 0x7f, 0x08, 0x04, 0x04, 0x78] # 68 h 77 | ,[0x00, 0x00, 0x44, 0x7d, 0x40, 0x00] # 69 i 78 | ,[0x00, 0x20, 0x40, 0x44, 0x3d, 0x00] # 6a j 79 | ,[0x00, 0x7f, 0x10, 0x28, 0x44, 0x00] # 6b k 80 | ,[0x00, 0x00, 0x41, 0x7f, 0x40, 0x00] # 6c l 81 | ,[0x00, 0x7c, 0x04, 0x18, 0x04, 0x78] # 6d m 82 | ,[0x00, 0x7c, 0x08, 0x04, 0x04, 0x78] # 6e n 83 | ,[0x00, 0x38, 0x44, 0x44, 0x44, 0x38] # 6f o 84 | ,[0x00, 0x7c, 0x14, 0x14, 0x14, 0x08] # 70 p 85 | ,[0x00, 0x08, 0x14, 0x14, 0x18, 0x7c] # 71 q 86 | ,[0x00, 0x7c, 0x08, 0x04, 0x04, 0x08] # 72 r 87 | ,[0x00, 0x48, 0x54, 0x54, 0x54, 0x20] # 73 s 88 | ,[0x00, 0x04, 0x3f, 0x44, 0x40, 0x20] # 74 t 89 | ,[0x00, 0x3c, 0x40, 0x40, 0x20, 0x7c] # 75 u 90 | ,[0x00, 0x1c, 0x20, 0x40, 0x20, 0x1c] # 76 v 91 | ,[0x00, 0x3c, 0x40, 0x30, 0x40, 0x3c] # 77 w 92 | ,[0x00, 0x44, 0x28, 0x10, 0x28, 0x44] # 78 x 93 | ,[0x00, 0x0c, 0x50, 0x50, 0x50, 0x3c] # 79 y 94 | ,[0x00, 0x44, 0x64, 0x54, 0x4c, 0x44] # 7a z 95 | ,[0x00, 0x00, 0x08, 0x36, 0x41, 0x00] # 7b [ 96 | ,[0x00, 0x00, 0x00, 0x7f, 0x00, 0x00] # 7c | 97 | ,[0x00, 0x00, 0x41, 0x36, 0x08, 0x00] # 7d ] 98 | ,[0x00, 0x10, 0x08, 0x08, 0x10, 0x08] # 7e ~ 99 | ,[0x00, 0x78, 0x46, 0x41, 0x46, 0x78] # 7f (delete) 100 | ] 101 | 102 | def get_font6_8(self, data): 103 | return self.FONTTYPE6_8[bytearray(data)[0] - 0x20] 104 | 105 | -------------------------------------------------------------------------------- /TPYBoard-v10x-master/08.DIY超声波测距仪/main.py: -------------------------------------------------------------------------------- 1 | import pyb 2 | from pyb import Pin 3 | from pyb import Timer 4 | import upcd8544 5 | from machine import SPI,Pin 6 | 7 | Trig = Pin('X2',Pin.OUT_PP) 8 | Echo = Pin('X1',Pin.IN) 9 | num=0 10 | flag=0 11 | run=1 12 | def start(t): 13 | global flag 14 | global num 15 | if(flag==0): 16 | num=0 17 | else: 18 | num=num+1 19 | def stop(t): 20 | global run 21 | if(run==0): 22 | run=1 23 | start1=Timer(1,freq=10000,callback=start) 24 | stop1=Timer(4,freq=2,callback=stop) 25 | while True: 26 | if(run==1): 27 | SPI = pyb.SPI(1) #DIN=>X8-MOSI/CLK=>X6-SCK 28 | #DIN =>SPI(1).MOSI 'X8' data flow (Master out, Slave in) 29 | #CLK =>SPI(1).SCK 'X6' SPI clock 30 | RST = pyb.Pin('Y10') 31 | CE = pyb.Pin('Y11') 32 | DC = pyb.Pin('Y9') 33 | LIGHT = pyb.Pin('Y12') 34 | lcd_5110 = upcd8544.PCD8544(SPI, RST, CE, DC, LIGHT) 35 | Trig.value(1) 36 | pyb.udelay(100) 37 | Trig.value(0) 38 | while(Echo.value()==0): 39 | Trig.value(1) 40 | pyb.udelay(100) 41 | Trig.value(0) 42 | flag=0 43 | if(Echo.value()==1): 44 | flag=1 45 | while(Echo.value()==1): 46 | flag=1 47 | if(num!=0): 48 | #print('num:',num) 49 | distance=num/10000*34299/2 50 | print('Distance:') 51 | print(distance,'cm') 52 | lcd_5110.lcd_write_string('Distance',0,0) 53 | lcd_5110.lcd_write_string(str(distance),6,1) 54 | lcd_5110.lcd_write_string('cm',55,1) 55 | flag=0 56 | run=0 -------------------------------------------------------------------------------- /TPYBoard-v10x-master/09.DIY电子时钟/DS3231.py: -------------------------------------------------------------------------------- 1 | import pyb 2 | from pyb import I2C 3 | 4 | DS3231_ADDR = const(0x68) 5 | DS3231_REG_SEC = const(0x00) 6 | DS3231_REG_MIN = const(0x01) 7 | DS3231_REG_HOUR = const(0x02) 8 | DS3231_REG_WEEKDAY= const(0x03) 9 | DS3231_REG_DAY = const(0x04) 10 | DS3231_REG_MONTH = const(0x05) 11 | DS3231_REG_YEAR = const(0x06) 12 | DS3231_REG_A1SEC = const(0x07) 13 | DS3231_REG_A1MIN = const(0x08) 14 | DS3231_REG_A1HOUR = const(0x09) 15 | DS3231_REG_A1DAY = const(0x0A) 16 | DS3231_REG_A2MIN = const(0x0B) 17 | DS3231_REG_A2HOUR = const(0x0C) 18 | DS3231_REG_A2DAY = const(0x0D) 19 | DS3231_REG_CTRL = const(0x0E) 20 | DS3231_REG_STA = const(0x0F) 21 | DS3231_REG_OFF = const(0x10) 22 | DS3231_REG_TEMP = const(0x11) 23 | 24 | class DS3231(object): 25 | def __init__(self, i2c_num): 26 | self.i2c = I2C(i2c_num, I2C.MASTER, baudrate = 100000) 27 | 28 | def DATE(self, dat=[]): 29 | if dat==[]: 30 | t = [] 31 | t.append(self.year()) 32 | t.append(self.month()) 33 | t.append(self.day()) 34 | return t 35 | else: 36 | self.year(dat[0]) 37 | self.month(dat[1]) 38 | self.day(dat[2]) 39 | 40 | def TIME(self, dat=[]): 41 | if dat==[]: 42 | t = [] 43 | t.append(self.hour()) 44 | t.append(self.min()) 45 | t.append(self.sec()) 46 | return t 47 | else: 48 | self.hour(dat[0]) 49 | self.min(dat[1]) 50 | self.sec(dat[2]) 51 | 52 | def DateTime(self, dat=[]): 53 | if dat==[]: 54 | return self.DATE() + self.TIME() 55 | else: 56 | self.year(dat[0]) 57 | self.month(dat[1]) 58 | self.day(dat[2]) 59 | self.hour(dat[3]) 60 | self.min(dat[4]) 61 | self.sec(dat[5]) 62 | 63 | def dec2hex(self, dat): 64 | return (int(dat/10)<<4) + (dat%10) 65 | 66 | def setREG(self, dat, reg): 67 | buf = bytearray(2) 68 | buf[0] = reg 69 | buf[1] = dat 70 | self.i2c.send(buf, DS3231_ADDR) 71 | 72 | def getREG_DEC(self, reg): 73 | self.i2c.send(reg, DS3231_ADDR) 74 | t = self.i2c.recv(1, DS3231_ADDR)[0] 75 | return (t>>4)*10 + (t%16) 76 | 77 | def sec(self, sec=''): 78 | if sec == '': 79 | return self.getREG_DEC(DS3231_REG_SEC) 80 | else: 81 | self.setREG(self.dec2hex(sec), DS3231_REG_SEC) 82 | 83 | def min(self, min=''): 84 | if min == '': 85 | return self.getREG_DEC(DS3231_REG_MIN) 86 | else: 87 | self.setREG(self.dec2hex(min), DS3231_REG_MIN) 88 | 89 | def hour(self, hour=''): 90 | if hour=='': 91 | return self.getREG_DEC(DS3231_REG_HOUR) 92 | else: 93 | self.setREG(self.dec2hex(hour), DS3231_REG_HOUR) 94 | 95 | def day(self, day=''): 96 | if day=='': 97 | return self.getREG_DEC(DS3231_REG_DAY) 98 | else: 99 | self.setREG(self.dec2hex(day), DS3231_REG_DAY) 100 | 101 | def month(self, month=''): 102 | if month=='': 103 | return self.getREG_DEC(DS3231_REG_MONTH) 104 | else: 105 | self.setREG(self.dec2hex(month), DS3231_REG_MONTH) 106 | 107 | def year(self, year=''): 108 | if year=='': 109 | return self.getREG_DEC(DS3231_REG_YEAR) 110 | else: 111 | self.setREG(self.dec2hex(year), DS3231_REG_YEAR) 112 | 113 | def TEMP(self): 114 | self.i2c.send(DS3231_REG_TEMP, DS3231_ADDR) 115 | t1 = self.i2c.recv(1, DS3231_ADDR)[0] 116 | self.i2c.send(DS3231_REG_TEMP+1, DS3231_ADDR) 117 | t2 = self.i2c.recv(1, DS3231_ADDR)[0] 118 | if t1>0x7F: 119 | return t1 - t2/256 -256 120 | else: 121 | return t1 + t2/256 122 | 123 | -------------------------------------------------------------------------------- /TPYBoard-v10x-master/09.DIY电子时钟/font.py: -------------------------------------------------------------------------------- 1 | class FONT6_8: 2 | """docstring for FONT6_8""" 3 | FONTTYPE6_8 = [ 4 | [0x00, 0x00, 0x00, 0x00, 0x00, 0x00] # 20 5 | ,[0x00, 0x00, 0x00, 0x5f, 0x00, 0x00] # 21 ! 6 | ,[0x00, 0x00, 0x07, 0x00, 0x07, 0x00] # 22 " 7 | ,[0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14] # 23 # 8 | ,[0x00, 0x24, 0x2a, 0x7f, 0x2a, 0x12] # 24 $ 9 | ,[0x00, 0x23, 0x13, 0x08, 0x64, 0x62] # 25 % 10 | ,[0x00, 0x36, 0x49, 0x55, 0x22, 0x50] # 26 & 11 | ,[0x00, 0x00, 0x05, 0x03, 0x00, 0x00] # 27 ' 12 | ,[0x00, 0x00, 0x1c, 0x22, 0x41, 0x00] # 28 ( 13 | ,[0x00, 0x00, 0x41, 0x22, 0x1c, 0x00] # 29 ) 14 | ,[0x00, 0x14, 0x08, 0x3e, 0x08, 0x14] # 2a * 15 | ,[0x00, 0x08, 0x08, 0x3e, 0x08, 0x08] # 2b + 16 | ,[0x00, 0x00, 0x50, 0x30, 0x00, 0x00] # 2c , 17 | ,[0x00, 0x08, 0x08, 0x08, 0x08, 0x08] # 2d - 18 | ,[0x00, 0x00, 0x60, 0x60, 0x00, 0x00] # 2e . 19 | ,[0x00, 0x20, 0x10, 0x08, 0x04, 0x02] # 2f / 20 | ,[0x00, 0x3e, 0x51, 0x49, 0x45, 0x3e] # 30 0 21 | ,[0x00, 0x00, 0x42, 0x7f, 0x40, 0x00] # 31 1 22 | ,[0x00, 0x42, 0x61, 0x51, 0x49, 0x46] # 32 2 23 | ,[0x00, 0x21, 0x41, 0x45, 0x4b, 0x31] # 33 3 24 | ,[0x00, 0x18, 0x14, 0x12, 0x7f, 0x10] # 34 4 25 | ,[0x00, 0x27, 0x45, 0x45, 0x45, 0x39] # 35 5 26 | ,[0x00, 0x3c, 0x4a, 0x49, 0x49, 0x30] # 36 6 27 | ,[0x00, 0x01, 0x71, 0x09, 0x05, 0x03] # 37 7 28 | ,[0x00, 0x36, 0x49, 0x49, 0x49, 0x36] # 38 8 29 | ,[0x00, 0x06, 0x49, 0x49, 0x29, 0x1e] # 39 9 30 | ,[0x00, 0x00, 0x36, 0x36, 0x00, 0x00] # 3a : 31 | ,[0x00, 0x00, 0x56, 0x36, 0x00, 0x00] # 3b ; 32 | ,[0x00, 0x08, 0x14, 0x22, 0x41, 0x00] # 3c < 33 | ,[0x00, 0x14, 0x14, 0x14, 0x14, 0x14] # 3d = 34 | ,[0x00, 0x00, 0x41, 0x22, 0x14, 0x08] # 3e > 35 | ,[0x00, 0x02, 0x01, 0x51, 0x09, 0x06] # 3f ? 36 | ,[0x00, 0x32, 0x49, 0x79, 0x41, 0x3e] # 40 @ 37 | ,[0x00, 0x7e, 0x11, 0x11, 0x11, 0x7e] # 41 A 38 | ,[0x00, 0x7f, 0x49, 0x49, 0x49, 0x36] # 42 B 39 | ,[0x00, 0x3e, 0x41, 0x41, 0x41, 0x22] # 43 C 40 | ,[0x00, 0x7f, 0x41, 0x41, 0x22, 0x1c] # 44 D 41 | ,[0x00, 0x7f, 0x49, 0x49, 0x49, 0x41] # 45 E 42 | ,[0x00, 0x7f, 0x09, 0x09, 0x09, 0x01] # 46 F 43 | ,[0x00, 0x3e, 0x41, 0x49, 0x49, 0x7a] # 47 G 44 | ,[0x00, 0x7f, 0x08, 0x08, 0x08, 0x7f] # 48 H 45 | ,[0x00, 0x00, 0x41, 0x7f, 0x41, 0x00] # 49 I 46 | ,[0x00, 0x20, 0x40, 0x41, 0x3f, 0x01] # 4a J 47 | ,[0x00, 0x7f, 0x08, 0x14, 0x22, 0x41] # 4b K 48 | ,[0x00, 0x7f, 0x40, 0x40, 0x40, 0x40] # 4c L 49 | ,[0x00, 0x7f, 0x02, 0x0c, 0x02, 0x7f] # 4d M 50 | ,[0x00, 0x7f, 0x04, 0x08, 0x10, 0x7f] # 4e N 51 | ,[0x00, 0x3e, 0x41, 0x41, 0x41, 0x3e] # 4f O 52 | ,[0x00, 0x7f, 0x09, 0x09, 0x09, 0x06] # 50 P 53 | ,[0x00, 0x3e, 0x41, 0x51, 0x21, 0x5e] # 51 Q 54 | ,[0x00, 0x7f, 0x09, 0x19, 0x29, 0x46] # 52 R 55 | ,[0x00, 0x46, 0x49, 0x49, 0x49, 0x31] # 53 S 56 | ,[0x00, 0x01, 0x01, 0x7f, 0x01, 0x01] # 54 T 57 | ,[0x00, 0x3f, 0x40, 0x40, 0x40, 0x3f] # 55 U 58 | ,[0x00, 0x1f, 0x20, 0x40, 0x20, 0x1f] # 56 V 59 | ,[0x00, 0x3f, 0x40, 0x38, 0x40, 0x3f] # 57 W 60 | ,[0x00, 0x63, 0x14, 0x08, 0x14, 0x63] # 58 X 61 | ,[0x00, 0x07, 0x08, 0x70, 0x08, 0x07] # 59 Y 62 | ,[0x00, 0x61, 0x51, 0x49, 0x45, 0x43] # 5a Z 63 | ,[0x00, 0x00, 0x7f, 0x41, 0x41, 0x00] # 5b [ 64 | ,[0x00, 0x02, 0x04, 0x08, 0x10, 0x20] # 5c \ # 65 | ,[0x00, 0x00, 0x41, 0x41, 0x7f, 0x00] # 5d ] 66 | ,[0x00, 0x04, 0x02, 0x01, 0x02, 0x04] # 5e ^ 67 | ,[0x00, 0x40, 0x40, 0x40, 0x40, 0x40] # 5f _ 68 | ,[0x00, 0x00, 0x01, 0x02, 0x04, 0x00] # 60 ` 69 | ,[0x00, 0x20, 0x54, 0x54, 0x54, 0x78] # 61 a 70 | ,[0x00, 0x7f, 0x48, 0x44, 0x44, 0x38] # 62 b 71 | ,[0x00, 0x38, 0x44, 0x44, 0x44, 0x20] # 63 c 72 | ,[0x00, 0x38, 0x44, 0x44, 0x48, 0x7f] # 64 d 73 | ,[0x00, 0x38, 0x54, 0x54, 0x54, 0x18] # 65 e 74 | ,[0x00, 0x08, 0x7e, 0x09, 0x01, 0x02] # 66 f 75 | ,[0x00, 0x0c, 0x52, 0x52, 0x52, 0x3e] # 67 g 76 | ,[0x00, 0x7f, 0x08, 0x04, 0x04, 0x78] # 68 h 77 | ,[0x00, 0x00, 0x44, 0x7d, 0x40, 0x00] # 69 i 78 | ,[0x00, 0x20, 0x40, 0x44, 0x3d, 0x00] # 6a j 79 | ,[0x00, 0x7f, 0x10, 0x28, 0x44, 0x00] # 6b k 80 | ,[0x00, 0x00, 0x41, 0x7f, 0x40, 0x00] # 6c l 81 | ,[0x00, 0x7c, 0x04, 0x18, 0x04, 0x78] # 6d m 82 | ,[0x00, 0x7c, 0x08, 0x04, 0x04, 0x78] # 6e n 83 | ,[0x00, 0x38, 0x44, 0x44, 0x44, 0x38] # 6f o 84 | ,[0x00, 0x7c, 0x14, 0x14, 0x14, 0x08] # 70 p 85 | ,[0x00, 0x08, 0x14, 0x14, 0x18, 0x7c] # 71 q 86 | ,[0x00, 0x7c, 0x08, 0x04, 0x04, 0x08] # 72 r 87 | ,[0x00, 0x48, 0x54, 0x54, 0x54, 0x20] # 73 s 88 | ,[0x00, 0x04, 0x3f, 0x44, 0x40, 0x20] # 74 t 89 | ,[0x00, 0x3c, 0x40, 0x40, 0x20, 0x7c] # 75 u 90 | ,[0x00, 0x1c, 0x20, 0x40, 0x20, 0x1c] # 76 v 91 | ,[0x00, 0x3c, 0x40, 0x30, 0x40, 0x3c] # 77 w 92 | ,[0x00, 0x44, 0x28, 0x10, 0x28, 0x44] # 78 x 93 | ,[0x00, 0x0c, 0x50, 0x50, 0x50, 0x3c] # 79 y 94 | ,[0x00, 0x44, 0x64, 0x54, 0x4c, 0x44] # 7a z 95 | ,[0x00, 0x00, 0x08, 0x36, 0x41, 0x00] # 7b [ 96 | ,[0x00, 0x00, 0x00, 0x7f, 0x00, 0x00] # 7c | 97 | ,[0x00, 0x00, 0x41, 0x36, 0x08, 0x00] # 7d ] 98 | ,[0x00, 0x10, 0x08, 0x08, 0x10, 0x08] # 7e ~ 99 | ,[0x00, 0x78, 0x46, 0x41, 0x46, 0x78] # 7f (delete) 100 | ] 101 | 102 | def get_font6_8(self, data): 103 | return self.FONTTYPE6_8[bytearray(data)[0] - 0x20] 104 | 105 | -------------------------------------------------------------------------------- /TPYBoard-v10x-master/09.DIY电子时钟/main.py: -------------------------------------------------------------------------------- 1 | # main.py -- put your code here! 2 | import pyb 3 | import upcd8544 4 | from machine import SPI,Pin 5 | from DS3231 import DS3231 6 | 7 | ds=DS3231(1) 8 | 9 | while True: 10 | ds.TEMP() 11 | ds.DATE() 12 | SPI = pyb.SPI(1) #DIN=>X8-MOSI/CLK=>X6-SCK 13 | #DIN =>SPI(1).MOSI 'X8' data flow (Master out, Slave in) 14 | #CLK =>SPI(1).SCK 'X6' SPI clock 15 | RST = pyb.Pin('X1') 16 | CE = pyb.Pin('X2') 17 | DC = pyb.Pin('X3') 18 | LIGHT = pyb.Pin('X4') 19 | lcd_5110 = upcd8544.PCD8544(SPI, RST, CE, DC, LIGHT) 20 | lcd_5110.lcd_write_string('Date',0,0) 21 | lcd_5110.lcd_write_string(str(ds.DATE()),0,1) 22 | lcd_5110.lcd_write_string('Time',0,2) 23 | lcd_5110.lcd_write_string(str(ds.TIME()),0,3) 24 | lcd_5110.lcd_write_string('Tem',0,4 ) 25 | lcd_5110.lcd_write_string(str(ds.TEMP()),0,5) 26 | pyb.delay(1000) 27 | -------------------------------------------------------------------------------- /TPYBoard-v10x-master/10.控制LCD5110显示温度时间(中文版)/DS3231.py: -------------------------------------------------------------------------------- 1 | import pyb 2 | from pyb import I2C 3 | DS3231_ADDR = const(0x68) 4 | DS3231_REG_SEC = const(0x00) 5 | DS3231_REG_MIN = const(0x01) 6 | DS3231_REG_HOUR = const(0x02) 7 | DS3231_REG_WEEKDAY= const(0x03) 8 | DS3231_REG_DAY = const(0x04) 9 | DS3231_REG_MONTH = const(0x05) 10 | DS3231_REG_YEAR = const(0x06) 11 | DS3231_REG_A1SEC = const(0x07) 12 | DS3231_REG_A1MIN = const(0x08) 13 | DS3231_REG_A1HOUR = const(0x09) 14 | DS3231_REG_A1DAY = const(0x0A) 15 | DS3231_REG_A2MIN = const(0x0B) 16 | DS3231_REG_A2HOUR = const(0x0C) 17 | DS3231_REG_A2DAY = const(0x0D) 18 | DS3231_REG_CTRL = const(0x0E) 19 | DS3231_REG_STA = const(0x0F) 20 | DS3231_REG_OFF = const(0x10) 21 | DS3231_REG_TEMP = const(0x11) 22 | 23 | class DS3231(object): 24 | def __init__(self, i2c_num): 25 | self.i2c = I2C(i2c_num, I2C.MASTER, baudrate = 100000) 26 | 27 | def DATE(self, dat=[]): 28 | if dat==[]: 29 | t = [] 30 | t.append(self.year()) 31 | t.append(self.month()) 32 | t.append(self.day()) 33 | return t 34 | else: 35 | self.year(dat[0]) 36 | self.month(dat[1]) 37 | self.day(dat[2]) 38 | 39 | def TIME(self, dat=[]): 40 | if dat==[]: 41 | t = [] 42 | t.append(self.hour()) 43 | t.append(self.min()) 44 | t.append(self.sec()) 45 | # t = "" 46 | # t+=self.hour()+":" 47 | # t+=self.min()+":" 48 | # t+=self.sec() 49 | return t 50 | else: 51 | self.hour(dat[0]) 52 | self.min(dat[1]) 53 | self.sec(dat[2]) 54 | 55 | def DateTime(self, dat=[]): 56 | if dat==[]: 57 | return self.DATE() + self.TIME() 58 | else: 59 | self.year(dat[0]) 60 | self.month(dat[1]) 61 | self.day(dat[2]) 62 | self.hour(dat[3]) 63 | self.min(dat[4]) 64 | self.sec(dat[5]) 65 | 66 | def dec2hex(self, dat): 67 | return (int(dat/10)<<4) + (dat%10) 68 | 69 | def setREG(self, dat, reg): 70 | buf = bytearray(2) 71 | buf[0] = reg 72 | buf[1] = dat 73 | self.i2c.send(buf, DS3231_ADDR) 74 | 75 | def getREG_DEC(self, reg): 76 | self.i2c.send(reg, DS3231_ADDR) 77 | t = self.i2c.recv(1, DS3231_ADDR)[0] 78 | return (t>>4)*10 + (t%16) 79 | 80 | def sec(self, sec=''): 81 | if sec == '': 82 | return self.getREG_DEC(DS3231_REG_SEC) 83 | else: 84 | self.setREG(self.dec2hex(sec), DS3231_REG_SEC) 85 | 86 | def min(self, min=''): 87 | if min == '': 88 | return self.getREG_DEC(DS3231_REG_MIN) 89 | else: 90 | self.setREG(self.dec2hex(min), DS3231_REG_MIN) 91 | 92 | def hour(self, hour=''): 93 | if hour=='': 94 | return self.getREG_DEC(DS3231_REG_HOUR) 95 | else: 96 | self.setREG(self.dec2hex(hour), DS3231_REG_HOUR) 97 | 98 | def day(self, day=''): 99 | if day=='': 100 | return self.getREG_DEC(DS3231_REG_DAY) 101 | else: 102 | self.setREG(self.dec2hex(day), DS3231_REG_DAY) 103 | 104 | def month(self, month=''): 105 | if month=='': 106 | return self.getREG_DEC(DS3231_REG_MONTH) 107 | else: 108 | self.setREG(self.dec2hex(month), DS3231_REG_MONTH) 109 | 110 | def year(self, year=''): 111 | if year=='': 112 | return self.getREG_DEC(DS3231_REG_YEAR) 113 | else: 114 | self.setREG(self.dec2hex(year), DS3231_REG_YEAR) 115 | 116 | def TEMP(self): 117 | self.i2c.send(DS3231_REG_TEMP, DS3231_ADDR) 118 | t1 = self.i2c.recv(1, DS3231_ADDR)[0] 119 | self.i2c.send(DS3231_REG_TEMP+1, DS3231_ADDR) 120 | t2 = self.i2c.recv(1, DS3231_ADDR)[0] 121 | if t1>0x7F: 122 | return t1 - t2/256 -256 123 | else: 124 | return t1 + t2/256 125 | 126 | 127 | -------------------------------------------------------------------------------- /TPYBoard-v10x-master/10.控制LCD5110显示温度时间(中文版)/chinese.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TPYBoard/developmentBoard/535a975480a6755394cedfe3708a05952d9b6539/TPYBoard-v10x-master/10.控制LCD5110显示温度时间(中文版)/chinese.py -------------------------------------------------------------------------------- /TPYBoard-v10x-master/10.控制LCD5110显示温度时间(中文版)/font.py: -------------------------------------------------------------------------------- 1 | class FONT6_8: 2 | """docstring for FONT6_8""" 3 | FONTTYPE6_8 = [ 4 | [0x00, 0x00, 0x00, 0x00, 0x00, 0x00] # 20 5 | ,[0x00, 0x00, 0x00, 0x5f, 0x00, 0x00] # 21 ! 6 | ,[0x00, 0x00, 0x07, 0x00, 0x07, 0x00] # 22 " 7 | ,[0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14] # 23 # 8 | ,[0x00, 0x24, 0x2a, 0x7f, 0x2a, 0x12] # 24 $ 9 | ,[0x00, 0x23, 0x13, 0x08, 0x64, 0x62] # 25 % 10 | ,[0x00, 0x36, 0x49, 0x55, 0x22, 0x50] # 26 & 11 | ,[0x00, 0x00, 0x05, 0x03, 0x00, 0x00] # 27 ' 12 | ,[0x00, 0x00, 0x1c, 0x22, 0x41, 0x00] # 28 ( 13 | ,[0x00, 0x00, 0x41, 0x22, 0x1c, 0x00] # 29 ) 14 | ,[0x00, 0x14, 0x08, 0x3e, 0x08, 0x14] # 2a * 15 | ,[0x00, 0x08, 0x08, 0x3e, 0x08, 0x08] # 2b + 16 | ,[0x00, 0x00, 0x50, 0x30, 0x00, 0x00] # 2c , 17 | ,[0x00, 0x08, 0x08, 0x08, 0x08, 0x08] # 2d - 18 | ,[0x00, 0x00, 0x60, 0x60, 0x00, 0x00] # 2e . 19 | ,[0x00, 0x20, 0x10, 0x08, 0x04, 0x02] # 2f / 20 | ,[0x00, 0x3e, 0x51, 0x49, 0x45, 0x3e] # 30 0 21 | ,[0x00, 0x00, 0x42, 0x7f, 0x40, 0x00] # 31 1 22 | ,[0x00, 0x42, 0x61, 0x51, 0x49, 0x46] # 32 2 23 | ,[0x00, 0x21, 0x41, 0x45, 0x4b, 0x31] # 33 3 24 | ,[0x00, 0x18, 0x14, 0x12, 0x7f, 0x10] # 34 4 25 | ,[0x00, 0x27, 0x45, 0x45, 0x45, 0x39] # 35 5 26 | ,[0x00, 0x3c, 0x4a, 0x49, 0x49, 0x30] # 36 6 27 | ,[0x00, 0x01, 0x71, 0x09, 0x05, 0x03] # 37 7 28 | ,[0x00, 0x36, 0x49, 0x49, 0x49, 0x36] # 38 8 29 | ,[0x00, 0x06, 0x49, 0x49, 0x29, 0x1e] # 39 9 30 | ,[0x00, 0x00, 0x36, 0x36, 0x00, 0x00] # 3a : 31 | ,[0x00, 0x00, 0x56, 0x36, 0x00, 0x00] # 3b ; 32 | ,[0x00, 0x08, 0x14, 0x22, 0x41, 0x00] # 3c < 33 | ,[0x00, 0x14, 0x14, 0x14, 0x14, 0x14] # 3d = 34 | ,[0x00, 0x00, 0x41, 0x22, 0x14, 0x08] # 3e > 35 | ,[0x00, 0x02, 0x01, 0x51, 0x09, 0x06] # 3f ? 36 | ,[0x00, 0x32, 0x49, 0x79, 0x41, 0x3e] # 40 @ 37 | ,[0x00, 0x7e, 0x11, 0x11, 0x11, 0x7e] # 41 A 38 | ,[0x00, 0x7f, 0x49, 0x49, 0x49, 0x36] # 42 B 39 | ,[0x00, 0x3e, 0x41, 0x41, 0x41, 0x22] # 43 C 40 | ,[0x00, 0x7f, 0x41, 0x41, 0x22, 0x1c] # 44 D 41 | ,[0x00, 0x7f, 0x49, 0x49, 0x49, 0x41] # 45 E 42 | ,[0x00, 0x7f, 0x09, 0x09, 0x09, 0x01] # 46 F 43 | ,[0x00, 0x3e, 0x41, 0x49, 0x49, 0x7a] # 47 G 44 | ,[0x00, 0x7f, 0x08, 0x08, 0x08, 0x7f] # 48 H 45 | ,[0x00, 0x00, 0x41, 0x7f, 0x41, 0x00] # 49 I 46 | ,[0x00, 0x20, 0x40, 0x41, 0x3f, 0x01] # 4a J 47 | ,[0x00, 0x7f, 0x08, 0x14, 0x22, 0x41] # 4b K 48 | ,[0x00, 0x7f, 0x40, 0x40, 0x40, 0x40] # 4c L 49 | ,[0x00, 0x7f, 0x02, 0x0c, 0x02, 0x7f] # 4d M 50 | ,[0x00, 0x7f, 0x04, 0x08, 0x10, 0x7f] # 4e N 51 | ,[0x00, 0x3e, 0x41, 0x41, 0x41, 0x3e] # 4f O 52 | ,[0x00, 0x7f, 0x09, 0x09, 0x09, 0x06] # 50 P 53 | ,[0x00, 0x3e, 0x41, 0x51, 0x21, 0x5e] # 51 Q 54 | ,[0x00, 0x7f, 0x09, 0x19, 0x29, 0x46] # 52 R 55 | ,[0x00, 0x46, 0x49, 0x49, 0x49, 0x31] # 53 S 56 | ,[0x00, 0x01, 0x01, 0x7f, 0x01, 0x01] # 54 T 57 | ,[0x00, 0x3f, 0x40, 0x40, 0x40, 0x3f] # 55 U 58 | ,[0x00, 0x1f, 0x20, 0x40, 0x20, 0x1f] # 56 V 59 | ,[0x00, 0x3f, 0x40, 0x38, 0x40, 0x3f] # 57 W 60 | ,[0x00, 0x63, 0x14, 0x08, 0x14, 0x63] # 58 X 61 | ,[0x00, 0x07, 0x08, 0x70, 0x08, 0x07] # 59 Y 62 | ,[0x00, 0x61, 0x51, 0x49, 0x45, 0x43] # 5a Z 63 | ,[0x00, 0x00, 0x7f, 0x41, 0x41, 0x00] # 5b [ 64 | ,[0x00, 0x02, 0x04, 0x08, 0x10, 0x20] # 5c \ 65 | ,[0x00, 0x00, 0x41, 0x41, 0x7f, 0x00] # 5d ] 66 | ,[0x00, 0x04, 0x02, 0x01, 0x02, 0x04] # 5e ^ 67 | ,[0x00, 0x40, 0x40, 0x40, 0x40, 0x40] # 5f _ 68 | ,[0x00, 0x00, 0x01, 0x02, 0x04, 0x00] # 60 ` 69 | ,[0x00, 0x20, 0x54, 0x54, 0x54, 0x78] # 61 a 70 | ,[0x00, 0x7f, 0x48, 0x44, 0x44, 0x38] # 62 b 71 | ,[0x00, 0x38, 0x44, 0x44, 0x44, 0x20] # 63 c 72 | ,[0x00, 0x38, 0x44, 0x44, 0x48, 0x7f] # 64 d 73 | ,[0x00, 0x38, 0x54, 0x54, 0x54, 0x18] # 65 e 74 | ,[0x00, 0x08, 0x7e, 0x09, 0x01, 0x02] # 66 f 75 | ,[0x00, 0x0c, 0x52, 0x52, 0x52, 0x3e] # 67 g 76 | ,[0x00, 0x7f, 0x08, 0x04, 0x04, 0x78] # 68 h 77 | ,[0x00, 0x00, 0x44, 0x7d, 0x40, 0x00] # 69 i 78 | ,[0x00, 0x20, 0x40, 0x44, 0x3d, 0x00] # 6a j 79 | ,[0x00, 0x7f, 0x10, 0x28, 0x44, 0x00] # 6b k 80 | ,[0x00, 0x00, 0x41, 0x7f, 0x40, 0x00] # 6c l 81 | ,[0x00, 0x7c, 0x04, 0x18, 0x04, 0x78] # 6d m 82 | ,[0x00, 0x7c, 0x08, 0x04, 0x04, 0x78] # 6e n 83 | ,[0x00, 0x38, 0x44, 0x44, 0x44, 0x38] # 6f o 84 | ,[0x00, 0x7c, 0x14, 0x14, 0x14, 0x08] # 70 p 85 | ,[0x00, 0x08, 0x14, 0x14, 0x18, 0x7c] # 71 q 86 | ,[0x00, 0x7c, 0x08, 0x04, 0x04, 0x08] # 72 r 87 | ,[0x00, 0x48, 0x54, 0x54, 0x54, 0x20] # 73 s 88 | ,[0x00, 0x04, 0x3f, 0x44, 0x40, 0x20] # 74 t 89 | ,[0x00, 0x3c, 0x40, 0x40, 0x20, 0x7c] # 75 u 90 | ,[0x00, 0x1c, 0x20, 0x40, 0x20, 0x1c] # 76 v 91 | ,[0x00, 0x3c, 0x40, 0x30, 0x40, 0x3c] # 77 w 92 | ,[0x00, 0x44, 0x28, 0x10, 0x28, 0x44] # 78 x 93 | ,[0x00, 0x0c, 0x50, 0x50, 0x50, 0x3c] # 79 y 94 | ,[0x00, 0x44, 0x64, 0x54, 0x4c, 0x44] # 7a z 95 | ,[0x00, 0x00, 0x08, 0x36, 0x41, 0x00] # 7b [ 96 | ,[0x00, 0x00, 0x00, 0x7f, 0x00, 0x00] # 7c | 97 | ,[0x00, 0x00, 0x41, 0x36, 0x08, 0x00] # 7d ] 98 | ,[0x00, 0x10, 0x08, 0x08, 0x10, 0x08] # 7e ~ 99 | ,[0x00, 0x78, 0x46, 0x41, 0x46, 0x78] # 7f (delete) 100 | ] 101 | 102 | 103 | def get_font6_8(self, data): 104 | return self.FONTTYPE6_8[bytearray(data)[0] - 0x20] 105 | 106 | -------------------------------------------------------------------------------- /TPYBoard-v10x-master/10.控制LCD5110显示温度时间(中文版)/main.py: -------------------------------------------------------------------------------- 1 | # main.py -- put your code here! 2 | import pyb 3 | import upcd8544 4 | from machine import SPI,Pin 5 | from DS3231 import DS3231 6 | 7 | ds=DS3231(1) #定义DS3231 8 | 9 | # 用于设定时间和日期 10 | def setDateTime(year,month,day,time,minutes,seconds): 11 | ds.DATE([year,month,day]) 12 | ds.TIME([time,minutes,seconds]) 13 | 14 | # 在LCD5110 显示时间或日期,separator 中间的分割符 15 | # x,y 在LCD5110 显示的位置 16 | def showTimeOrDate(why,x,y,separator=':'): 17 | # [HH,MM,SS] >> HH:MM:SS 18 | why = why.replace('[','') 19 | why = why.replace(']','') 20 | why = why.replace(',',separator) 21 | print(why) 22 | lcd_5110.lcd_write_string(why,x,y) 23 | 24 | 25 | def main(): 26 | lcd_5110.lcd_write_chinese('萝',14,0) 27 | lcd_5110.lcd_write_chinese('卜',30,0) 28 | lcd_5110.lcd_write_chinese('智',46,0) 29 | lcd_5110.lcd_write_chinese('能',62,0) 30 | lcd_5110.lcd_write_string('TEM:',14,2) 31 | lcd_5110.lcd_write_string(str(ds.TEMP()),44,2) 32 | lcd_5110.lcd_write_chinese("当",14,3) 33 | lcd_5110.lcd_write_chinese("前",30,3) 34 | lcd_5110.lcd_write_chinese("时",46,3) 35 | lcd_5110.lcd_write_chinese("间",62,3) 36 | showTimeOrDate(str(ds.TIME()),14,5) 37 | print(str(ds.TIME())) 38 | pyb.delay(1000) 39 | 40 | if __name__ == '__main__': 41 | #setDateTime(2016,12,27,13,17,00)#设置时间 42 | ds.DATE() 43 | SPI = pyb.SPI(1) #DIN=>X8-MOSI/CLK=>X6-SCK 44 | #DIN =>SPI(1).MOSI 'X8' data flow (Master out, Slave in) 45 | #CLK =>SPI(1).SCK 'X6' SPI clock 46 | RST = pyb.Pin('X1') 47 | CE = pyb.Pin('X2') 48 | DC = pyb.Pin('X3') 49 | LIGHT = pyb.Pin('X4') 50 | lcd_5110 = upcd8544.PCD8544(SPI, RST, CE, DC, LIGHT) 51 | while(1): 52 | main() 53 | -------------------------------------------------------------------------------- /TPYBoard-v10x-master/11.学习使用OLED显示屏/main.py: -------------------------------------------------------------------------------- 1 | import pyb 2 | from ssd1306_lib import SSD1306 3 | 4 | # SPI 5 | display = SSD1306(pinout={'dc': 'Y9', 6 | 'res': 'Y10'}, 7 | height=64, 8 | external_vcc=False) 9 | 10 | # I2C connected to Y9, Y10 (I2C bus 2) 11 | # display = SSD1306(pinout={'sda': 'Y10', 12 | # 'scl': 'Y9'}, 13 | # height=64, 14 | # external_vcc=False) 15 | 16 | led_red = pyb.LED(1) 17 | led_red.off() 18 | 19 | try: 20 | display.poweron() 21 | display.init_display() 22 | 23 | display.draw_text(1,1,'Welcome T TurnipSmart',size=1,space=1) 24 | display.draw_text(1,10,'Hello MicroPython!',size=1,space=1) 25 | 26 | # Write display buffer 27 | display.display() 28 | pyb.delay(10000) 29 | 30 | x = 0 31 | y = 0 32 | direction_x = True 33 | direction_y = True 34 | 35 | 36 | except Exception as ex: 37 | led_red.on() 38 | print('Unexpected error: {0}'.format(ex)) 39 | display.poweroff() -------------------------------------------------------------------------------- /TPYBoard-v10x-master/11.学习使用OLED显示屏/ssd1306_lib.py: -------------------------------------------------------------------------------- 1 | # The MIT License (MIT) 2 | # 3 | # Copyright (c) 2014 Kenneth Henderick 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in 13 | # all copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | # THE SOFTWARE. 22 | 23 | import pyb 24 | import font 25 | 26 | # Constants 27 | DISPLAYOFF = 0xAE 28 | SETCONTRAST = 0x81 29 | DISPLAYALLON_RESUME = 0xA4 30 | DISPLAYALLON = 0xA5 31 | NORMALDISPLAY = 0xA6 32 | INVERTDISPLAY = 0xA7 33 | DISPLAYON = 0xAF 34 | SETDISPLAYOFFSET = 0xD3 35 | SETCOMPINS = 0xDA 36 | SETVCOMDETECT = 0xDB 37 | SETDISPLAYCLOCKDIV = 0xD5 38 | SETPRECHARGE = 0xD9 39 | SETMULTIPLEX = 0xA8 40 | SETLOWCOLUMN = 0x00 41 | SETHIGHCOLUMN = 0x10 42 | SETSTARTLINE = 0x40 43 | MEMORYMODE = 0x20 44 | COLUMNADDR = 0x21 45 | PAGEADDR = 0x22 46 | COMSCANINC = 0xC0 47 | COMSCANDEC = 0xC8 48 | SEGREMAP = 0xA0 49 | CHARGEPUMP = 0x8D 50 | EXTERNALVCC = 0x10 51 | SWITCHCAPVCC = 0x20 52 | SETPAGEADDR = 0xB0 53 | SETCOLADDR_LOW = 0x00 54 | SETCOLADDR_HIGH = 0x10 55 | ACTIVATE_SCROLL = 0x2F 56 | DEACTIVATE_SCROLL = 0x2E 57 | SET_VERTICAL_SCROLL_AREA = 0xA3 58 | RIGHT_HORIZONTAL_SCROLL = 0x26 59 | LEFT_HORIZONTAL_SCROLL = 0x27 60 | VERTICAL_AND_RIGHT_HORIZONTAL_SCROLL = 0x29 61 | VERTICAL_AND_LEFT_HORIZONTAL_SCROLL = 0x2A 62 | 63 | # I2C devices are accessed through a Device ID. This is a 7-bit 64 | # value but is sometimes expressed left-shifted by 1 as an 8-bit value. 65 | # A pin on SSD1306 allows it to respond to ID 0x3C or 0x3D. The board 66 | # I bought from ebay used a 0-ohm resistor to select between "0x78" 67 | # (0x3c << 1) or "0x7a" (0x3d << 1). The default was set to "0x78" 68 | DEVID = 0x3c 69 | 70 | # I2C communication here is either 71 | # or <> <> <> <>... 72 | # These two values encode the Co (Continuation) bit as b7 and the 73 | # D/C# (Data/Command Selection) bit as b6. 74 | CTL_CMD = 0x80 75 | CTL_DAT = 0x40 76 | 77 | class SSD1306(object): 78 | 79 | def __init__(self, pinout, height=32, external_vcc=True, i2c_devid=DEVID): 80 | self.external_vcc = external_vcc 81 | self.height = 32 if height == 32 else 64 82 | self.pages = int(self.height / 8) 83 | self.columns = 128 84 | 85 | # Infer interface type from entries in pinout{} 86 | if 'dc' in pinout: 87 | # SPI 88 | rate = 16 * 1024 * 1024 89 | self.spi = pyb.SPI(1, pyb.SPI.MASTER, baudrate=rate, polarity=1, phase=0) # SCK: Y6: MOSI: Y8 90 | self.dc = pyb.Pin(pinout['dc'], pyb.Pin.OUT_PP, pyb.Pin.PULL_DOWN) 91 | self.res = pyb.Pin(pinout['res'], pyb.Pin.OUT_PP, pyb.Pin.PULL_DOWN) 92 | self.offset = 0 93 | else: 94 | # Infer bus number from pin 95 | if pinout['sda'] == 'X10': 96 | self.i2c = pyb.I2C(1) 97 | else: 98 | self.i2c = pyb.I2C(2) 99 | self.i2c.init(pyb.I2C.MASTER, baudrate=400000) # 400kHz 100 | self.devid = i2c_devid 101 | # used to reserve an extra byte in the image buffer AND as a way to 102 | # infer the interface type 103 | self.offset = 1 104 | # I2C command buffer 105 | self.cbuffer = bytearray(2) 106 | self.cbuffer[0] = CTL_CMD 107 | 108 | def clear(self): 109 | self.buffer = bytearray(self.offset + self.pages * self.columns) 110 | if self.offset == 1: 111 | self.buffer[0] = CTL_DAT 112 | 113 | def write_command(self, command_byte): 114 | if self.offset == 1: 115 | self.cbuffer[1] = command_byte 116 | self.i2c.send(self.cbuffer, addr=self.devid, timeout=5000) 117 | else: 118 | self.dc.low() 119 | self.spi.send(command_byte) 120 | 121 | def invert_display(self, invert): 122 | self.write_command(INVERTDISPLAY if invert else NORMALDISPLAY) 123 | 124 | def display(self): 125 | self.write_command(COLUMNADDR) 126 | self.write_command(0) 127 | self.write_command(self.columns - 1) 128 | self.write_command(PAGEADDR) 129 | self.write_command(0) 130 | self.write_command(self.pages - 1) 131 | if self.offset == 1: 132 | self.i2c.send(self.buffer, addr=self.devid, timeout=5000) 133 | else: 134 | self.dc.high() 135 | self.spi.send(self.buffer) 136 | 137 | def set_pixel(self, x, y, state): 138 | index = x + (int(y / 8) * self.columns) 139 | if state: 140 | self.buffer[self.offset + index] |= (1 << (y & 7)) 141 | else: 142 | self.buffer[self.offset + index] &= ~(1 << (y & 7)) 143 | 144 | def init_display(self): 145 | chargepump = 0x10 if self.external_vcc else 0x14 146 | precharge = 0x22 if self.external_vcc else 0xf1 147 | multiplex = 0x1f if self.height == 32 else 0x3f 148 | compins = 0x02 if self.height == 32 else 0x12 149 | contrast = 0xff # 0x8f if self.height == 32 else (0x9f if self.external_vcc else 0x9f) 150 | data = [DISPLAYOFF, 151 | SETDISPLAYCLOCKDIV, 0x80, 152 | SETMULTIPLEX, multiplex, 153 | SETDISPLAYOFFSET, 0x00, 154 | SETSTARTLINE | 0x00, 155 | CHARGEPUMP, chargepump, 156 | MEMORYMODE, 0x00, 157 | SEGREMAP | 0x10, 158 | COMSCANDEC, 159 | SETCOMPINS, compins, 160 | SETCONTRAST, contrast, 161 | SETPRECHARGE, precharge, 162 | SETVCOMDETECT, 0x40, 163 | DISPLAYALLON_RESUME, 164 | NORMALDISPLAY, 165 | DISPLAYON] 166 | for item in data: 167 | self.write_command(item) 168 | self.clear() 169 | self.display() 170 | 171 | def poweron(self): 172 | if self.offset == 1: 173 | pyb.delay(10) 174 | else: 175 | self.res.high() 176 | pyb.delay(1) 177 | self.res.low() 178 | pyb.delay(10) 179 | self.res.high() 180 | pyb.delay(10) 181 | 182 | def poweroff(self): 183 | self.write_command(DISPLAYOFF) 184 | 185 | def contrast(self, contrast): 186 | self.write_command(SETCONTRAST) 187 | self.write_command(contrast) 188 | 189 | def draw_text(self, x, y, string, size=1, space=1): 190 | def pixel_x(char_number, char_column, point_row): 191 | char_offset = x + char_number * size * font.cols + space * char_number 192 | pixel_offset = char_offset + char_column * size + point_row 193 | return self.columns - pixel_offset 194 | 195 | def pixel_y(char_row, point_column): 196 | char_offset = y + char_row * size 197 | return char_offset + point_column 198 | 199 | def pixel_mask(char, char_column, char_row): 200 | char_index_offset = ord(char) * font.cols 201 | return font.bytes[char_index_offset + char_column] >> char_row & 0x1 202 | 203 | pixels = ( 204 | (pixel_x(char_number, char_column, point_row), 205 | pixel_y(char_row, point_column), 206 | pixel_mask(char, char_column, char_row)) 207 | for char_number, char in enumerate(string) 208 | for char_column in range(font.cols) 209 | for char_row in range(font.rows) 210 | for point_column in range(size) 211 | for point_row in range(1, size + 1)) 212 | 213 | for pixel in pixels: 214 | self.set_pixel(*pixel) 215 | -------------------------------------------------------------------------------- /TPYBoard-v10x-master/12.控制LCD1602显示字符/main.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TPYBoard/developmentBoard/535a975480a6755394cedfe3708a05952d9b6539/TPYBoard-v10x-master/12.控制LCD1602显示字符/main.py -------------------------------------------------------------------------------- /TPYBoard-v10x-master/12.控制LCD1602显示字符/tpyb_gpio_lcd1602.py: -------------------------------------------------------------------------------- 1 | """Implements a character based lcd connected via PCF8574 on i2c.""" 2 | 3 | from tpyb_lcd1602 import TPYBoardLcd1602Api 4 | from pyb import Pin 5 | from pyb import delay, udelay 6 | 7 | 8 | class TPYBoardGpioLcd1602(TPYBoardLcd1602Api): 9 | """Implements a character based lcd connected via GPIO pins.""" 10 | 11 | def __init__(self, rs_pin, enable_pin, d0_pin=None, d1_pin=None, 12 | d2_pin=None, d3_pin=None, d4_pin=None, d5_pin=None, 13 | d6_pin=None, d7_pin=None, rw_pin=None, backlight_pin=None, 14 | num_lines=2, num_columns=16): 15 | """Constructs the TPYBoardGpioLcd1602 object. All of the arguments must pyb.Pin 16 | objects which ddescribe which pin the given line from the LCD is 17 | connected to. 18 | 19 | When used in 4-bit mode, only D4, D5, D6, and D7 are physically 20 | connected to the LCD panel. This function allows you call it like 21 | TPYBoardGpioLcd1602(rs, enable, D4, D5, D6, D7) and it will interpret that as 22 | if you had actually called: 23 | TPYBoardGpioLcd1602(rs, enable, d4=D4, d5=D5, d6=D6, d7=D7) 24 | 25 | The enable 8-bit mode, you need pass d0 thru d7. 26 | 27 | The rw pin isn't used by this library, but if you specify it, then 28 | it will be set low. 29 | """ 30 | self.rs_pin = rs_pin 31 | self.enable_pin = enable_pin 32 | self.rw_pin = rw_pin 33 | self.backlight_pin = backlight_pin 34 | self._4bit = True 35 | if d4_pin and d5_pin and d6_pin and d7_pin: 36 | self.d0_pin = d0_pin 37 | self.d1_pin = d1_pin 38 | self.d2_pin = d2_pin 39 | self.d3_pin = d3_pin 40 | self.d4_pin = d4_pin 41 | self.d5_pin = d5_pin 42 | self.d6_pin = d6_pin 43 | self.d7_pin = d7_pin 44 | if self.d0_pin and self.d1_pin and self.d2_pin and self.d3_pin: 45 | self._4bit = False 46 | else: 47 | # This is really 4-bit mode, and the 4 data pins were just 48 | # passed as the first 4 arguments, so we switch things around. 49 | self.d0_pin = None 50 | self.d1_pin = None 51 | self.d2_pin = None 52 | self.d3_pin = None 53 | self.d4_pin = d0_pin 54 | self.d5_pin = d1_pin 55 | self.d6_pin = d2_pin 56 | self.d7_pin = d3_pin 57 | self.rs_pin.init(Pin.OUT_PP) 58 | self.rs_pin.low() 59 | if self.rw_pin: 60 | self.rw_pin.init(Pin.OUT_PP) 61 | self.rw_pin.low() 62 | self.enable_pin.init(Pin.OUT_PP) 63 | self.enable_pin.low() 64 | self.d4_pin.init(Pin.OUT_PP) 65 | self.d5_pin.init(Pin.OUT_PP) 66 | self.d6_pin.init(Pin.OUT_PP) 67 | self.d7_pin.init(Pin.OUT_PP) 68 | self.d4_pin.low() 69 | self.d5_pin.low() 70 | self.d6_pin.low() 71 | self.d7_pin.low() 72 | if not self._4bit: 73 | self.d0_pin.init(Pin.OUT_PP) 74 | self.d1_pin.init(Pin.OUT_PP) 75 | self.d2_pin.init(Pin.OUT_PP) 76 | self.d3_pin.init(Pin.OUT_PP) 77 | self.d0_pin.low() 78 | self.d1_pin.low() 79 | self.d2_pin.low() 80 | self.d3_pin.low() 81 | if self.backlight_pin is not None: 82 | self.backlight_pin.init(Pin.OUT_PP) 83 | self.backlight_pin.low() 84 | 85 | # See about splitting this into begin 86 | 87 | delay(20) # Allow LCD time to powerup 88 | # Send reset 3 times 89 | self.hal_write_init_nibble(self.LCD_FUNCTION_RESET) 90 | delay(5) # need to delay at least 4.1 msec 91 | self.hal_write_init_nibble(self.LCD_FUNCTION_RESET) 92 | delay(1) 93 | self.hal_write_init_nibble(self.LCD_FUNCTION_RESET) 94 | delay(1) 95 | cmd = self.LCD_FUNCTION 96 | if not self._4bit: 97 | cmd |= self.LCD_FUNCTION_8BIT 98 | self.hal_write_init_nibble(cmd) 99 | delay(1) 100 | TPYBoardLcd1602Api.__init__(self, num_lines, num_columns) 101 | if num_lines > 1: 102 | cmd |= self.LCD_FUNCTION_2LINES 103 | self.hal_write_command(cmd) 104 | 105 | def hal_pulse_enable(self): 106 | """Pulse the enable line high, and then low again.""" 107 | self.enable_pin.low() 108 | udelay(1) 109 | self.enable_pin.high() 110 | udelay(1) # Enable pulse needs to be > 450 nsec 111 | self.enable_pin.low() 112 | udelay(100) # Commands need > 37us to settle 113 | 114 | def hal_write_init_nibble(self, nibble): 115 | """Writes an initialization nibble to the LCD. 116 | 117 | This particular function is only used during intiialization. 118 | """ 119 | self.hal_write_4bits(nibble >> 4) 120 | 121 | def hal_backlight_on(self): 122 | """Allows the hal layer to turn the backlight on.""" 123 | if self.backlight_pin: 124 | self.backlight_pin.high() 125 | 126 | def hal_backlight_off(self): 127 | """Allows the hal layer to turn the backlight off.""" 128 | if self.backlight_pin: 129 | self.backlight_pin.low() 130 | 131 | def hal_write_command(self, cmd): 132 | """Writes a command to the LCD. 133 | 134 | Data is latched on the falling edge of E. 135 | """ 136 | self.rs_pin.low() 137 | self.hal_write_8bits(cmd) 138 | if cmd <= 3: 139 | # The home and clear commands require a worst 140 | # case delay of 4.1 msec 141 | delay(5) 142 | 143 | def hal_write_data(self, data): 144 | """Write data to the LCD.""" 145 | self.rs_pin.high() 146 | self.hal_write_8bits(data) 147 | 148 | def hal_write_8bits(self, value): 149 | """Writes 8 bits of data to the LCD.""" 150 | if self.rw_pin: 151 | self.rw_pin.low() 152 | if self._4bit: 153 | self.hal_write_4bits(value >> 4) 154 | self.hal_write_4bits(value) 155 | else: 156 | self.d3_pin.value(value & 0x08) 157 | self.d2_pin.value(value & 0x04) 158 | self.d1_pin.value(value & 0x02) 159 | self.d0_pin.value(value & 0x01) 160 | self.hal_write_4bits(value >> 4) 161 | 162 | def hal_write_4bits(self, nibble): 163 | """Writes 4 bits of data to the LCD.""" 164 | self.d7_pin.value(nibble & 0x08) 165 | self.d6_pin.value(nibble & 0x04) 166 | self.d5_pin.value(nibble & 0x02) 167 | self.d4_pin.value(nibble & 0x01) 168 | self.hal_pulse_enable() 169 | -------------------------------------------------------------------------------- /TPYBoard-v10x-master/12.控制LCD1602显示字符/tpyb_lcd1602.py: -------------------------------------------------------------------------------- 1 | """Provides an API for talking to HD44780 style character LCDs.""" 2 | 3 | 4 | class TPYBoardLcd1602Api(object): 5 | """Implements the API for talking with n LCD. This class only knows what 6 | commands to send to the LCD, and not how t get them to the LCD. 7 | 8 | It is expected that a derived class will implement the hal_xxx functions. 9 | """ 10 | 11 | # The following constant names were lifted from the avrlib lcd.h 12 | # header file, however, I changed the definitions from bit numbers 13 | # to bit masks. 14 | # 15 | # HD44780 LCD controller command set 16 | 17 | LCD_CLR = 0x01 # DB0: clear display 18 | LCD_HOME = 0x02 # DB1: return to home position 19 | 20 | LCD_ENTRY_MODE = 0x04 # DB2: set entry mode 21 | LCD_ENTRY_INC = 0x02 # --DB1: increment 22 | LCD_ENTRY_SHIFT = 0x01 # --DB0: shift 23 | 24 | LCD_ON_CTRL = 0x08 # DB3: turn lcd/cursor on 25 | LCD_ON_DISPLAY = 0x04 # --DB2: turn display on 26 | LCD_ON_CURSOR = 0x02 # --DB1: turn cursor on 27 | LCD_ON_BLINK = 0x01 # --DB0: blinking cursor 28 | 29 | LCD_MOVE = 0x10 # DB4: move cursor/display 30 | LCD_MOVE_DISP = 0x08 # --DB3: move display (0-> move cursor) 31 | LCD_MOVE_RIGHT = 0x04 # --DB2: move right (0-> left) 32 | 33 | LCD_FUNCTION = 0x20 # DB5: function set 34 | LCD_FUNCTION_8BIT = 0x10 # --DB4: set 8BIT mode (0->4BIT mode) 35 | LCD_FUNCTION_2LINES = 0x08 # --DB3: two lines (0->one line) 36 | LCD_FUNCTION_10DOTS = 0x04 # --DB2: 5x10 font (0->5x7 font) 37 | LCD_FUNCTION_RESET = 0x30 # See "Initializing by Instruction" section 38 | 39 | LCD_CGRAM = 0x40 # DB6: set CG RAM address 40 | LCD_DDRAM = 0x80 # DB7: set DD RAM address 41 | 42 | LCD_RS_CMD = 0 43 | LCD_RS_DATA = 1 44 | 45 | LCD_RW_WRITE = 0 46 | LCD_RW_READ = 1 47 | 48 | def __init__(self, num_lines, num_columns): 49 | self.num_lines = num_lines 50 | if self.num_lines > 4: 51 | self.num_lines = 4 52 | self.num_columns = num_columns 53 | if self.num_columns > 40: 54 | self.num_columns = 40 55 | self.cursor_x = 0 56 | self.cursor_y = 0 57 | self.backlight = True 58 | self.display_off() 59 | self.backlight_on() 60 | self.clear() 61 | self.hal_write_command(self.LCD_ENTRY_MODE | self.LCD_ENTRY_INC) 62 | self.hide_cursor() 63 | self.display_on() 64 | 65 | def clear(self): 66 | """Clears the LCD display and moves the cursor to the top left 67 | corner. 68 | 69 | """ 70 | self.hal_write_command(self.LCD_CLR) 71 | self.hal_write_command(self.LCD_HOME) 72 | self.cursor_x = 0 73 | self.cursor_y = 0 74 | 75 | def show_cursor(self): 76 | """Causes the cursor to be made visible.""" 77 | self.hal_write_command(self.LCD_ON_CTRL | self.LCD_ON_DISPLAY | 78 | self.LCD_ON_CURSOR) 79 | 80 | def hide_cursor(self): 81 | """Causes the cursor to be hidden.""" 82 | self.hal_write_command(self.LCD_ON_CTRL | self.LCD_ON_DISPLAY) 83 | 84 | def blink_cursor_on(self): 85 | """Turns on the cursor, and makes it blink.""" 86 | self.hal_write_command(self.LCD_ON_CTRL | self.LCD_ON_DISPLAY | 87 | self.LCD_ON_CURSOR | self.LCD_ON_BLINK) 88 | 89 | def blink_cursor_off(self): 90 | """Turns on the cursor, and makes it no blink (i.e. be solid).""" 91 | self.hal_write_command(self.LCD_ON_CTRL | self.LCD_ON_DISPLAY | 92 | self.LCD_ON_CURSOR) 93 | 94 | def display_on(self): 95 | """Turns on (i.e. unblanks) the LCD.""" 96 | self.hal_write_command(self.LCD_ON_CTRL | self.LCD_ON_DISPLAY) 97 | 98 | def display_off(self): 99 | """Turns off (i.e. blanks) the LCD.""" 100 | self.hal_write_command(self.LCD_ON_CTRL) 101 | 102 | def backlight_on(self): 103 | """Turns the backlight on. 104 | 105 | This isn't really an LCD command, but some modules have backlight 106 | controls, so this allows the hal to pass through the command. 107 | """ 108 | self.backlight = True 109 | self.hal_backlight_on() 110 | 111 | def backlight_off(self): 112 | """Turns the backlight off. 113 | 114 | This isn't really an LCD command, but some modules have backlight 115 | controls, so this allows the hal to pass through the command. 116 | """ 117 | self.backlight = False 118 | self.hal_backlight_off() 119 | 120 | def move_to(self, cursor_x, cursor_y): 121 | """Moves the cursor position to the indicated position. The cursor 122 | position is zero based (i.e. cursor_x == 0 indicates first column). 123 | """ 124 | self.cursor_x = cursor_x 125 | self.cursor_y = cursor_y 126 | addr = cursor_x & 0x3f 127 | if cursor_y & 1: 128 | addr += 0x40 # Lines 1 & 3 add 0x40 129 | if cursor_y & 2: 130 | addr += 0x14 # Lines 2 & 3 add 0x14 131 | self.hal_write_command(self.LCD_DDRAM | addr) 132 | 133 | def lcd1602_write_char(self, char): 134 | """Writes the indicated charcter to the LCD at the current cursor 135 | position, and advances the cursor by one position. 136 | """ 137 | if self.cursor_x >= self.num_columns or char == '\n': 138 | self.cursor_x = 0 139 | self.cursor_y += 1 140 | if self.cursor_y >= self.num_lines: 141 | self.cursor_y = 0 142 | self.move_to(self.cursor_x, self.cursor_y) 143 | if char != '\n': 144 | self.hal_write_data(ord(char)) 145 | self.cursor_x += 1 146 | 147 | def lcd1602_write_string(self, string): 148 | """Write the indicated string to the LCD at the current cursor 149 | position and advances the cursor position appropriately. 150 | """ 151 | for char in string: 152 | self.lcd1602_write_char(char) 153 | 154 | def hal_backlight_on(self): 155 | """Allows the hal layer to turn the backlight on. 156 | 157 | If desired, a derived HAL class will implement this function. 158 | """ 159 | pass 160 | 161 | def hal_backlight_off(self): 162 | """Allows the hal layer to turn the backlight off. 163 | 164 | If desired, a derived HAL class will implement this function. 165 | """ 166 | 167 | pass 168 | 169 | def hal_write_command(self, cmd): 170 | """Write a command to the LCD. 171 | 172 | It is expected that a derived HAL class will implement this 173 | function. 174 | """ 175 | raise NotImplementedError 176 | 177 | def hal_write_data(self, data): 178 | """Write data to the LCD. 179 | 180 | It is expected that a derived HAL class will implement this 181 | function. 182 | """ 183 | raise NotImplementedError 184 | -------------------------------------------------------------------------------- /TPYBoard-v10x-master/13.DIY智能温控小风扇/ds18x20.py: -------------------------------------------------------------------------------- 1 | """ 2 | DS18x20 temperature sensor driver for MicroPython. 3 | 4 | This driver uses the OneWire driver to control DS18S20 and DS18B20 5 | temperature sensors. It supports multiple devices on the same 1-wire bus. 6 | 7 | The following example assumes the ground of your DS18x20 is connected to 8 | Y11, vcc is connected to Y9 and the data pin is connected to Y10. 9 | 10 | >>> from pyb import Pin 11 | >>> gnd = Pin('Y11', Pin.OUT_PP) 12 | >>> gnd.low() 13 | >>> vcc = Pin('Y9', Pin.OUT_PP) 14 | >>> vcc.high() 15 | 16 | >>> from ds18x20 import DS18X20 17 | >>> d = DS18X20(Pin('Y10')) 18 | 19 | Call read_temps to read all sensors: 20 | 21 | >>> result = d.read_temps() 22 | >>> print(result) 23 | [20.875, 20.8125] 24 | 25 | Call read_temp to read the temperature of a specific sensor: 26 | 27 | >>> result = d.read_temp(d.roms[0]) 28 | >>> print(result) 29 | 20.25 30 | 31 | If only one DS18x20 is attached to the bus, then you don't need to 32 | pass a ROM to read_temp: 33 | 34 | >>> result = d.read_temp() 35 | >>> print(result) 36 | 20.25 37 | 38 | """ 39 | 40 | from onewire_lib import OneWire 41 | 42 | class DS18X20(object): 43 | def __init__(self, pin): 44 | self.ow = OneWire(pin) 45 | # Scan the 1-wire devices, but only keep those which have the 46 | # correct # first byte in their rom for a DS18x20 device. 47 | self.roms = [rom for rom in self.ow.scan() if rom[0] == 0x10 or rom[0] == 0x28] 48 | 49 | def read_temp(self, rom=None): 50 | """ 51 | Read and return the temperature of one DS18x20 device. 52 | Pass the 8-byte bytes object with the ROM of the specific device you want to read. 53 | If only one DS18x20 device is attached to the bus you may omit the rom parameter. 54 | """ 55 | rom = rom or self.roms[0] 56 | ow = self.ow 57 | ow.reset() 58 | ow.select_rom(rom) 59 | ow.write_byte(0x44) # Convert Temp 60 | while True: 61 | if ow.read_bit(): 62 | break 63 | ow.reset() 64 | ow.select_rom(rom) 65 | ow.write_byte(0xbe) # Read scratch 66 | data = ow.read_bytes(9) 67 | return self.convert_temp(rom[0], data) 68 | 69 | def read_temps(self): 70 | """ 71 | Read and return the temperatures of all attached DS18x20 devices. 72 | """ 73 | temps = [] 74 | for rom in self.roms: 75 | temps.append(self.read_temp(rom)) 76 | return temps 77 | 78 | def convert_temp(self, rom0, data): 79 | """ 80 | Convert the raw temperature data into degrees celsius and return as a float. 81 | """ 82 | temp_lsb = data[0] 83 | temp_msb = data[1] 84 | if rom0 == 0x10: 85 | if temp_msb != 0: 86 | # convert negative number 87 | temp_read = temp_lsb >> 1 | 0x80 # truncate bit 0 by shifting, fill high bit with 1. 88 | temp_read = -((~temp_read + 1) & 0xff) # now convert from two's complement 89 | else: 90 | temp_read = temp_lsb >> 1 # truncate bit 0 by shifting 91 | count_remain = data[6] 92 | count_per_c = data[7] 93 | temp = temp_read - 0.25 + (count_per_c - count_remain) / count_per_c 94 | return temp 95 | elif rom0 == 0x28: 96 | return (temp_msb << 8 | temp_lsb) / 16 97 | else: 98 | assert False 99 | -------------------------------------------------------------------------------- /TPYBoard-v10x-master/13.DIY智能温控小风扇/main.py: -------------------------------------------------------------------------------- 1 | #main.py 2 | import pyb 3 | from pyb import Pin 4 | from ds18x20 import DS18X20 5 | 6 | Pin("Y9",Pin.OUT_PP).high()#VCC 7 | Pin("Y11",Pin.OUT_PP).low()#GND 8 | x1 = Pin('X1', Pin.OUT_PP) 9 | pyb.delay(100) 10 | DQ=DS18X20(Pin('Y10'))#DQ 11 | while 1: 12 | tem = DQ.read_temp() 13 | if tem > 18: 14 | x1.value(1) 15 | else: 16 | x1.value(0) -------------------------------------------------------------------------------- /TPYBoard-v10x-master/14.驱动舵机教程/main_servo.py: -------------------------------------------------------------------------------- 1 | from pyb import * 2 | 3 | accel = Accel() 4 | servo = Servo(1) 5 | while True: 6 | x = accel.x() 7 | servo.angle(-x*3,300) 8 | delay(200) -------------------------------------------------------------------------------- /TPYBoard-v10x-master/14.驱动舵机教程/main_text.py: -------------------------------------------------------------------------------- 1 | # main.py -- put your code here! 2 | from pyb import Servo 3 | while 1: 4 | s=Servo(1) 5 | s.angle(30,500) 6 | pyb.delay(1500) 7 | s.angle(-30,500) 8 | pyb.delay(1500) 9 | s.angle(60,500) 10 | pyb.delay(1500) 11 | s.angle(-60,500) 12 | pyb.delay(1500) 13 | s.angle(90,500) 14 | pyb.delay(1500) 15 | s.angle(-30,500) 16 | pyb.delay(1500) 17 | s.angle(135,500) 18 | pyb.delay(1500) 19 | -------------------------------------------------------------------------------- /TPYBoard-v10x-master/15.红外防坠落小车/main.py: -------------------------------------------------------------------------------- 1 | import pyb 2 | from pyb import UART 3 | from pyb import Pin 4 | 5 | M0 = Pin('X1', Pin.IN) 6 | M1 = Pin('X2', Pin.IN) 7 | M2 = Pin('X3', Pin.IN) 8 | M3 = Pin('X4', Pin.IN) 9 | N1 = Pin('Y1', Pin.OUT_PP) 10 | N2 = Pin('Y2', Pin.OUT_PP) 11 | N3 = Pin('Y3', Pin.OUT_PP) 12 | N4 = Pin('Y4', Pin.OUT_PP) 13 | 14 | print('while') 15 | while True: 16 | print('while') 17 | if(M2.value()|M1.value()|M3.value()|M0.value()==0): 18 | N1.low() 19 | N2.high() 20 | N4.high() 21 | N3.low() 22 | pyb.LED(2).on() 23 | pyb.LED(3).off() 24 | elif(M2.value()|M1.value()|M3.value()|M0.value()==1): 25 | N1.high() 26 | N2.low() 27 | N4.low() 28 | N3.high() 29 | pyb.delay(300) 30 | N1.low() 31 | N2.high() 32 | N3.high() 33 | N4.low() 34 | pyb.delay(200) 35 | pyb.LED(3).on() 36 | pyb.LED(2).off() -------------------------------------------------------------------------------- /TPYBoard-v10x-master/16.红外寻迹无线小车/main.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TPYBoard/developmentBoard/535a975480a6755394cedfe3708a05952d9b6539/TPYBoard-v10x-master/16.红外寻迹无线小车/main.py -------------------------------------------------------------------------------- /TPYBoard-v10x-master/17.无线蓝牙智能小车/main.py: -------------------------------------------------------------------------------- 1 | import pyb 2 | from pyb import UART 3 | from pyb import Pin 4 | 5 | M2 = Pin('X3', Pin.IN) 6 | M3 = Pin('X4', Pin.IN) 7 | N1 = Pin('Y1', Pin.OUT_PP) 8 | N2 = Pin('Y2', Pin.OUT_PP) 9 | N3 = Pin('Y3', Pin.OUT_PP) 10 | N4 = Pin('Y4', Pin.OUT_PP) 11 | 12 | u2 = UART(2, 9600,timeout = 100) 13 | 14 | while True: 15 | pyb.LED(2).on() 16 | pyb.LED(3).on() 17 | pyb.LED(4).on() 18 | _dataRead=u2.read() 19 | if _dataRead!=None: 20 | #停止 21 | if(_dataRead.find(b'\xa5Z\x04\xb1\xb5\xaa')>-1): 22 | print('stop') 23 | N1.low() 24 | N2.low() 25 | N3.low() 26 | N4.low() 27 | #向左 28 | elif(_dataRead.find( b'\xa5Z\x04\xb4\xb8\xaa')>-1): 29 | print('left') 30 | N1.low() 31 | N2.high() 32 | N3.high() 33 | N4.low() 34 | #向右 35 | elif(_dataRead.find( b'\xa5Z\x04\xb6\xba\xaa')>-1): 36 | print('right') 37 | N1.high() 38 | N2.low() 39 | N3.low() 40 | N4.high() 41 | #后退 42 | elif(_dataRead.find(b'\xa5Z\x04\xb5\xb9\xaa')>-1): 43 | print('back') 44 | N2.high() 45 | N1.low() 46 | N4.high() 47 | N3.low() 48 | #向前 49 | elif(_dataRead.find( b'\xa5Z\x04\xb2\xb6\xaa')>-1): 50 | print('go') 51 | N1.high() 52 | N2.low() 53 | N3.high() 54 | N4.low() 55 | -------------------------------------------------------------------------------- /TPYBoard-v10x-master/18.加速度无线小车/控制端/main.py: -------------------------------------------------------------------------------- 1 | import pyb 2 | xlights = (pyb.LED(2), pyb.LED(3)) 3 | ylights = (pyb.LED(1), pyb.LED(4)) 4 | from pyb import UART 5 | from pyb import Pin 6 | #from ubinascii import hexlify 7 | from ubinascii import * 8 | accel = pyb.Accel() 9 | u2 = UART(2,9600,timeout=100) 10 | i=0 11 | K=1 12 | 13 | #*******************************主程序********************************** 14 | print('while') 15 | while (K>0): 16 | _dataRead=u2.readall() 17 | if(1>0): 18 | x = accel.x() 19 | print("x=") 20 | print(x) 21 | if x > 10: 22 | xlights[0].on() 23 | xlights[1].off() 24 | u2.write('\x00\x05\x18YOU') 25 | print('\x00\x01\x18YOU') 26 | elif x < -10: 27 | xlights[1].on() 28 | xlights[0].off() 29 | u2.write('\x00\x05\x18ZUO') 30 | print('\x00\x01\x18ZUO') 31 | 32 | else: 33 | xlights[0].off() 34 | xlights[1].off() 35 | 36 | y = accel.y() 37 | print("y=") 38 | print(y) 39 | if y > 15: 40 | ylights[0].on() 41 | ylights[1].off() 42 | elif y < -15: 43 | ylights[1].on() 44 | ylights[0].off() 45 | u2.write('\x00\x05\x18QIAN') 46 | print('\x00\x01\x18QIAN') 47 | else: 48 | ylights[0].off() 49 | ylights[1].off() 50 | 51 | pyb.delay(10) -------------------------------------------------------------------------------- /TPYBoard-v10x-master/18.加速度无线小车/被控制端/main.py: -------------------------------------------------------------------------------- 1 | import pyb 2 | from pyb import UART 3 | from pyb import Pin 4 | from ubinascii import hexlify 5 | from ubinascii import * 6 | M1 = Pin('X1', Pin.OUT_PP) 7 | M3 = Pin('Y1', Pin.OUT_PP) 8 | u2 = UART(2, 9600,timeout = 100) 9 | i=0 10 | K=1 11 | #*******************************主程序********************************** 12 | print('while') 13 | while (K>0): 14 | M1.high() 15 | pyb.delay(3) 16 | M3.high() 17 | if(u2.any()>0): 18 | print('1234') 19 | M1.low() 20 | M3.low() 21 | pyb.delay(3) 22 | _dataRead=u2.readall() 23 | print('123',_dataRead) 24 | if(_dataRead.find(b'QIAN')>-1): 25 | M1.low() 26 | M3.low() 27 | print('QIAN') 28 | pyb.delay(250) 29 | elif(_dataRead.find(b'ZUO')>-1): 30 | M1.low() 31 | M3.high() 32 | print('ZUO') 33 | pyb.delay(250) 34 | elif(_dataRead.find(b'YOU')>-1): 35 | M1.high() 36 | M3.low() 37 | print('ZUO') 38 | pyb.delay(250) -------------------------------------------------------------------------------- /TPYBoard-v10x-master/31.线程和锁/main.py: -------------------------------------------------------------------------------- 1 | import _thread 2 | import time 3 | 4 | lock=_thread.allocate_lock() 5 | 6 | def myThread_A(): 7 | print('我是 thread A-') 8 | _thread.exit() 9 | 10 | 11 | def myThread_B(time_): 12 | time.sleep(time_) 13 | print('我是 thread B-') 14 | print('我是 thread B- Sleep 5s') 15 | time.sleep(5) 16 | print('我是 thread B-Wake up') 17 | _thread.exit() 18 | 19 | def myThread_C(time_): 20 | time.sleep(time_) 21 | print('我是 thread C-') 22 | _thread.exit() 23 | 24 | _thread.start_new_thread(myThread_A, ()) 25 | _thread.start_new_thread(myThread_B, (2,)) 26 | _thread.start_new_thread(myThread_C, (3,)) 27 | 28 | while True: 29 | pass -------------------------------------------------------------------------------- /TPYBoard-v10x-master/31.线程和锁/main_lock.py: -------------------------------------------------------------------------------- 1 | import _thread 2 | import time 3 | 4 | lock=_thread.allocate_lock() 5 | 6 | def myThread_A(): 7 | print('我是 thread A-') 8 | _thread.exit() 9 | 10 | 11 | def myThread_B(time_): 12 | time.sleep(time_) 13 | if lock.acquire():#锁住资源 14 | print('我是 thread B-') 15 | print('我是 thread B- Sleep 5s') 16 | time.sleep(5) 17 | print('我是 thread B-Wake up') 18 | lock.release()#打开锁 释放资源 19 | _thread.exit() 20 | 21 | def myThread_C(time_): 22 | time.sleep(time_) 23 | if lock.acquire():#B先抢到了资源 需等待B释放后才能占有 24 | print('我是 thread C-') 25 | lock.release() 26 | _thread.exit() 27 | 28 | _thread.start_new_thread(myThread_A, ()) 29 | _thread.start_new_thread(myThread_B, (2,)) 30 | _thread.start_new_thread(myThread_C, (3,)) 31 | 32 | while True: 33 | pass -------------------------------------------------------------------------------- /TPYBoard-v10x-master/32.学习OLED显示中文/main.py: -------------------------------------------------------------------------------- 1 | import pyb 2 | from ssd1306_lib import SSD1306 3 | import math 4 | import font 5 | from pyb import Timer 6 | 7 | display = SSD1306(pinout={'dc': 'Y9', 8 | 'res': 'Y10'}, 9 | height=64, 10 | external_vcc=False) 11 | 12 | led_red = pyb.LED(2) 13 | led_red.on() 14 | display.poweron() 15 | display.init_display() 16 | display.draw_text(8,8,'TPYBoard OLED Text',) 17 | display.draw_chinese('我爱你祖国',1,3) 18 | 19 | 20 | display.display() 21 | -------------------------------------------------------------------------------- /TPYBoard-v10x-master/33.智能蓝牙+红外循迹小车/README.txt: -------------------------------------------------------------------------------- 1 | This is a TPYboard 2 | 3 | You can get started right away by writing your Python code in 'main.py'. 4 | 5 | For a serial prompt: 6 | - Windows: you need to go to 'Device manager', right click on the unknown device, 7 | then update the driver software, using the 'tpybcdc.inf' file found on this drive. 8 | Then use a terminal program like Hyperterminal or putty. 9 | - Mac OS X: use the command: screen /dev/tty.usbmodem* 10 | - Linux: use the command: screen /dev/ttyACM0 11 | 12 | Please visit http://www.tpyboard.com/help/ for further help. 13 | 14 | Designed by TurnipSmart in Shandong! -------------------------------------------------------------------------------- /TPYBoard-v10x-master/33.智能蓝牙+红外循迹小车/boot.py: -------------------------------------------------------------------------------- 1 | # boot.py -- run on boot-up 2 | # can run arbitrary Python, but best to keep it minimal 3 | 4 | import machine 5 | import pyb 6 | #pyb.main('main.py') # main script to run after this one 7 | #pyb.usb_mode('CDC+MSC') # act as a serial and a storage device 8 | #pyb.usb_mode('CDC+HID') # act as a serial device and a mouse 9 | -------------------------------------------------------------------------------- /TPYBoard-v10x-master/33.智能蓝牙+红外循迹小车/main.py: -------------------------------------------------------------------------------- 1 | # main.py -- put your code here! 2 | import pyb 3 | from pyb import UART 4 | from pyb import Pin 5 | 6 | N1 = Pin('X1', Pin.OUT_PP) 7 | N2 = Pin('X2', Pin.OUT_PP) 8 | N3 = Pin('X3', Pin.OUT_PP) 9 | N4 = Pin('X4', Pin.OUT_PP) 10 | 11 | M1 = Pin('Y1', Pin.IN) 12 | M2 = Pin('Y2', Pin.IN) 13 | M3 = Pin('Y3', Pin.IN) 14 | M4 = Pin('Y4', Pin.IN) 15 | 16 | blue=UART(3,9600) 17 | mode='1'#1:表示蓝牙模式 2:循迹模式 18 | 19 | def Stop(): 20 | N1.low() 21 | N2.low() 22 | N3.low() 23 | N4.low() 24 | def Back(): 25 | N1.high() 26 | N2.low() 27 | N3.high() 28 | N4.low() 29 | def Go(): 30 | N1.low() 31 | N2.high() 32 | N3.low() 33 | N4.high() 34 | def Left(): 35 | N1.high() 36 | N2.low() 37 | N3.low() 38 | N4.high() 39 | def Right(): 40 | N1.low() 41 | N2.high() 42 | N3.high() 43 | N4.low() 44 | while True: 45 | if blue.any()>0: 46 | data=blue.read().decode() 47 | print(data) 48 | if data.find('0')>-1: 49 | #stop 50 | Stop() 51 | mode="1" 52 | print('stop') 53 | if data.find('1')>-1: 54 | Go() 55 | print('go') 56 | if data.find('2')>-1: 57 | Back() 58 | pyb.delay(500) 59 | Stop() 60 | if data.find('3')>-1: 61 | Left() 62 | pyb.delay(250) 63 | Stop() 64 | if data.find('4')>-1: 65 | Right() 66 | pyb.delay(250) 67 | Stop() 68 | if data.find('5')>-1: 69 | mode="1" 70 | Stop() 71 | if data.find('6')>-1: 72 | mode="2" 73 | else: 74 | if mode=="2": 75 | print('循迹模式') 76 | if(M1.value() and M2.value() and M3.value()): 77 | Stop() 78 | mode="1" 79 | if(M2.value() or M3.value()): 80 | pyb.LED(2).on() 81 | pyb.LED(3).off() 82 | pyb.LED(4).off() 83 | Go() 84 | if M1.value(): 85 | pyb.LED(3).on() 86 | pyb.LED(2).off() 87 | pyb.LED(4).off() 88 | Right() 89 | pyb.delay(10) 90 | if M4.value(): 91 | pyb.LED(4).on() 92 | pyb.LED(2).off() 93 | pyb.LED(3).off() 94 | Left() 95 | pyb.delay(10) -------------------------------------------------------------------------------- /TPYBoard-v10x-master/33.智能蓝牙+红外循迹小车/tpybcdc.inf: -------------------------------------------------------------------------------- 1 | key = USB_VID val = f055 2 | key = USB_PID_CDC_MSC val = 9800 3 | key = USB_PID_CDC_HID val = 9801 4 | key = USB_PID_CDC val = 9802 5 | ; Windows USB CDC ACM Setup File 6 | ; Based on INF files which were: 7 | ; Copyright (c) 2000 Microsoft Corporation 8 | ; Copyright (C) 2007 Microchip Technology Inc. 9 | ; Likely to be covered by the MLPL as found at: 10 | ; . 11 | 12 | [Version] 13 | Signature="$Windows NT$" 14 | Class=Ports 15 | ClassGuid={4D36E978-E325-11CE-BFC1-08002BE10318} 16 | Provider=%MFGNAME% 17 | LayoutFile=layout.inf 18 | DriverVer=03/11/2010,5.1.2600.3 19 | 20 | [Manufacturer] 21 | %MFGNAME%=DeviceList, NTamd64 22 | 23 | [DestinationDirs] 24 | DefaultDestDir=12 25 | 26 | ;--------------------------------------------------------------------- 27 | ; Windows 2000/XP/Server2003/Vista/Server2008/7 - 32bit Sections 28 | 29 | [DriverInstall.nt] 30 | include=mdmcpq.inf 31 | CopyFiles=DriverCopyFiles.nt 32 | AddReg=DriverInstall.nt.AddReg 33 | 34 | [DriverCopyFiles.nt] 35 | usbser.sys,,,0x20 36 | 37 | [DriverInstall.nt.AddReg] 38 | HKR,,DevLoader,,*ntkern 39 | HKR,,NTMPDriver,,usbser.sys 40 | HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider" 41 | 42 | [DriverInstall.nt.Services] 43 | AddService=usbser, 0x00000002, DriverService.nt 44 | 45 | [DriverService.nt] 46 | DisplayName=%SERVICE% 47 | ServiceType=1 48 | StartType=3 49 | ErrorControl=1 50 | ServiceBinary=%12%\usbser.sys 51 | 52 | ;--------------------------------------------------------------------- 53 | ; Windows XP/Server2003/Vista/Server2008/7 - 64bit Sections 54 | 55 | [DriverInstall.NTamd64] 56 | include=mdmcpq.inf 57 | CopyFiles=DriverCopyFiles.NTamd64 58 | AddReg=DriverInstall.NTamd64.AddReg 59 | 60 | [DriverCopyFiles.NTamd64] 61 | usbser.sys,,,0x20 62 | 63 | [DriverInstall.NTamd64.AddReg] 64 | HKR,,DevLoader,,*ntkern 65 | HKR,,NTMPDriver,,usbser.sys 66 | HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider" 67 | 68 | [DriverInstall.NTamd64.Services] 69 | AddService=usbser, 0x00000002, DriverService.NTamd64 70 | 71 | [DriverService.NTamd64] 72 | DisplayName=%SERVICE% 73 | ServiceType=1 74 | StartType=3 75 | ErrorControl=1 76 | ServiceBinary=%12%\usbser.sys 77 | 78 | ;--------------------------------------------------------------------- 79 | ; Vendor and Product ID Definitions 80 | 81 | [SourceDisksFiles] 82 | [SourceDisksNames] 83 | [DeviceList] 84 | %DESCRIPTION%=DriverInstall, USB\VID_f055&PID_9800&MI_00, USB\VID_f055&PID_9800&MI_01, USB\VID_f055&PID_9801&MI_00, USB\VID_f055&PID_9801&MI_01, USB\VID_f055&PID_9802 85 | 86 | [DeviceList.NTamd64] 87 | %DESCRIPTION%=DriverInstall, USB\VID_f055&PID_9800&MI_00, USB\VID_f055&PID_9800&MI_01, USB\VID_f055&PID_9801&MI_00, USB\VID_f055&PID_9801&MI_01, USB\VID_f055&PID_9802 88 | 89 | ;--------------------------------------------------------------------- 90 | ; String Definitions 91 | 92 | [Strings] 93 | MFGFILENAME="tpybcdc" 94 | MFGNAME="MicroPython" 95 | DESCRIPTION="TPYBoard USB Comm Port" 96 | SERVICE="USB Serial Driver" 97 | -------------------------------------------------------------------------------- /TPYBoard-v10x-master/34.驱动步进电机/main.py: -------------------------------------------------------------------------------- 1 | # main.py -- put your code here! 2 | import pyb 3 | from pyb import Pin 4 | 5 | Pin_All=[Pin(p,Pin.OUT_PP) for p in ['X1','X2','X3','X4']] 6 | 7 | #转速(ms) 数值越大转速越慢 最小值1.8ms 8 | speed=2 9 | 10 | STEPER_ROUND=512 #转动一圈(360度)的周期 11 | ANGLE_PER_ROUND=STEPER_ROUND/360 #转动1度的周期 12 | print('ANGLE_PER_ROUND:',ANGLE_PER_ROUND) 13 | 14 | def SteperWriteData(data): 15 | count=0 16 | for i in data: 17 | Pin_All[count].value(i) 18 | count+=1 19 | def SteperFrontTurn(): 20 | global speed 21 | 22 | SteperWriteData([1,1,0,0]) 23 | pyb.delay(speed) 24 | 25 | SteperWriteData([0,1,1,0]) 26 | pyb.delay(speed) 27 | 28 | SteperWriteData([0,0,1,1]) 29 | pyb.delay(speed) 30 | 31 | SteperWriteData([1,0,0,1]) 32 | pyb.delay(speed) 33 | 34 | def SteperBackTurn(): 35 | global speed 36 | 37 | SteperWriteData([1,1,0,0]) 38 | pyb.delay(speed) 39 | 40 | SteperWriteData([1,0,0,1]) 41 | pyb.delay(speed) 42 | 43 | SteperWriteData([0,0,1,1]) 44 | pyb.delay(speed) 45 | 46 | SteperWriteData([0,1,1,0]) 47 | pyb.delay(speed) 48 | 49 | 50 | def SteperStop(): 51 | SteperWriteData([0,0,0,0]) 52 | 53 | def SteperRun(angle): 54 | global ANGLE_PER_ROUND 55 | 56 | val=ANGLE_PER_ROUND*abs(angle) 57 | if(angle>0): 58 | for i in range(0,val): 59 | SteperFrontTurn() 60 | else: 61 | for i in range(0,val): 62 | SteperBackTurn() 63 | angle = 0 64 | SteperStop() 65 | 66 | if __name__=='__main__': 67 | SteperRun(180) 68 | SteperRun(-180) 69 | 70 | 71 | -------------------------------------------------------------------------------- /TPYBoard-v10x-master/35.自动浇花系统/README.txt: -------------------------------------------------------------------------------- 1 | This is a TPYboard 2 | 3 | You can get started right away by writing your Python code in 'main.py'. 4 | 5 | For a serial prompt: 6 | - Windows: you need to go to 'Device manager', right click on the unknown device, 7 | then update the driver software, using the 'tpybcdc.inf' file found on this drive. 8 | Then use a terminal program like Hyperterminal or putty. 9 | - Mac OS X: use the command: screen /dev/tty.usbmodem* 10 | - Linux: use the command: screen /dev/ttyACM0 11 | 12 | Please visit http://www.tpyboard.com/help/ for further help. 13 | 14 | Designed by TurnipSmart in Shandong! -------------------------------------------------------------------------------- /TPYBoard-v10x-master/35.自动浇花系统/boot.py: -------------------------------------------------------------------------------- 1 | # boot.py -- run on boot-up 2 | # can run arbitrary Python, but best to keep it minimal 3 | 4 | import machine 5 | import pyb 6 | #pyb.main('main.py') # main script to run after this one 7 | #pyb.usb_mode('CDC+MSC') # act as a serial and a storage device 8 | #pyb.usb_mode('CDC+HID') # act as a serial device and a mouse 9 | -------------------------------------------------------------------------------- /TPYBoard-v10x-master/35.自动浇花系统/ds18x20.py: -------------------------------------------------------------------------------- 1 | """ 2 | DS18x20 temperature sensor driver for MicroPython. 3 | This driver uses the OneWire driver to control DS18S20 and DS18B20 4 | temperature sensors. It supports multiple devices on the same 1-wire bus. 5 | The following example assumes the ground of your DS18x20 is connected to 6 | Y11, vcc is connected to Y9 and the data pin is connected to Y10. 7 | >>> from pyb import Pin 8 | >>> gnd = Pin('Y11', Pin.OUT_PP) 9 | >>> gnd.low() 10 | >>> vcc = Pin('Y9', Pin.OUT_PP) 11 | >>> vcc.high() 12 | >>> from ds18x20 import DS18X20 13 | >>> d = DS18X20(Pin('Y10')) 14 | Call read_temps to read all sensors: 15 | >>> result = d.read_temps() 16 | >>> print(result) 17 | [20.875, 20.8125] 18 | Call read_temp to read the temperature of a specific sensor: 19 | >>> result = d.read_temp(d.roms[0]) 20 | >>> print(result) 21 | 20.25 22 | If only one DS18x20 is attached to the bus, then you don't need to 23 | pass a ROM to read_temp: 24 | >>> result = d.read_temp() 25 | >>> print(result) 26 | 20.25 27 | """ 28 | 29 | from onewire import OneWire 30 | 31 | class DS18X20(object): 32 | def __init__(self, pin): 33 | self.ow = OneWire(pin) 34 | # Scan the 1-wire devices, but only keep those which have the 35 | # correct # first byte in their rom for a DS18x20 device. 36 | self.roms = [rom for rom in self.ow.scan() if rom[0] == 0x10 or rom[0] == 0x28] 37 | 38 | def read_temp(self, rom=None): 39 | """ 40 | Read and return the temperature of one DS18x20 device. 41 | Pass the 8-byte bytes object with the ROM of the specific device you want to read. 42 | If only one DS18x20 device is attached to the bus you may omit the rom parameter. 43 | """ 44 | rom = rom or self.roms[0] 45 | ow = self.ow 46 | ow.reset() 47 | ow.select_rom(rom) 48 | ow.write_byte(0x44) # Convert Temp 49 | while True: 50 | if ow.read_bit(): 51 | break 52 | ow.reset() 53 | ow.select_rom(rom) 54 | ow.write_byte(0xbe) # Read scratch 55 | data = ow.read_bytes(9) 56 | return self.convert_temp(rom[0], data) 57 | 58 | def read_temps(self): 59 | """ 60 | Read and return the temperatures of all attached DS18x20 devices. 61 | """ 62 | temps = [] 63 | for rom in self.roms: 64 | temps.append(self.read_temp(rom)) 65 | return temps 66 | 67 | def convert_temp(self, rom0, data): 68 | """ 69 | Convert the raw temperature data into degrees celsius and return as a float. 70 | """ 71 | temp_lsb = data[0] 72 | temp_msb = data[1] 73 | if rom0 == 0x10: 74 | if temp_msb != 0: 75 | # convert negative number 76 | temp_read = temp_lsb >> 1 | 0x80 # truncate bit 0 by shifting, fill high bit with 1. 77 | temp_read = -((~temp_read + 1) & 0xff) # now convert from two's complement 78 | else: 79 | temp_read = temp_lsb >> 1 # truncate bit 0 by shifting 80 | count_remain = data[6] 81 | count_per_c = data[7] 82 | temp = temp_read - 0.25 + (count_per_c - count_remain) / count_per_c 83 | return temp 84 | elif rom0 == 0x28: 85 | return (temp_msb << 8 | temp_lsb) / 16 86 | else: 87 | assert False -------------------------------------------------------------------------------- /TPYBoard-v10x-master/35.自动浇花系统/main.py: -------------------------------------------------------------------------------- 1 | from pyb import Pin, ADC 2 | from ds18x20 import DS18X20 3 | 4 | gl = ADC(Pin('Y12')) #300亮-1700暗 5 | sd = ADC(Pin('Y11')) #1800干-800湿 6 | wd = DS18X20(Pin('Y10')) 7 | ks = Pin('Y9', Pin.OUT_PP) 8 | jr = Pin('Y8', Pin.OUT_PP) 9 | 10 | while True: 11 | print('\t光照强度:',gl.read(),'\t土壤湿度:',sd.read(),'\t当前温度:',wd.read_temp()) 12 | pyb.delay(200) 13 | if gl.read()<=250 : #阳光充足 14 | if sd.read()>800 : #多浇水 15 | ks.value(1) 16 | else : 17 | ks.value(0) 18 | elif gl.read()>=1300 : #阳光不足 19 | if sd.read()>1200 : #少浇水 20 | ks.value(1) 21 | else : 22 | ks.value(0) 23 | else : #阳光一般 24 | if sd.read()>1000 : #正常浇水 25 | ks.value(1) 26 | else : 27 | ks.value(0) 28 | if wd.read_temp()<18 : #温度过低 29 | jr.value(1) 30 | else : 31 | jr.value(0) -------------------------------------------------------------------------------- /TPYBoard-v10x-master/35.自动浇花系统/tpybcdc.inf: -------------------------------------------------------------------------------- 1 | key = USB_VID val = f055 2 | key = USB_PID_CDC_MSC val = 9800 3 | key = USB_PID_CDC_HID val = 9801 4 | key = USB_PID_CDC val = 9802 5 | ; Windows USB CDC ACM Setup File 6 | ; Based on INF files which were: 7 | ; Copyright (c) 2000 Microsoft Corporation 8 | ; Copyright (C) 2007 Microchip Technology Inc. 9 | ; Likely to be covered by the MLPL as found at: 10 | ; . 11 | 12 | [Version] 13 | Signature="$Windows NT$" 14 | Class=Ports 15 | ClassGuid={4D36E978-E325-11CE-BFC1-08002BE10318} 16 | Provider=%MFGNAME% 17 | LayoutFile=layout.inf 18 | DriverVer=03/11/2010,5.1.2600.3 19 | 20 | [Manufacturer] 21 | %MFGNAME%=DeviceList, NTamd64 22 | 23 | [DestinationDirs] 24 | DefaultDestDir=12 25 | 26 | ;--------------------------------------------------------------------- 27 | ; Windows 2000/XP/Server2003/Vista/Server2008/7 - 32bit Sections 28 | 29 | [DriverInstall.nt] 30 | include=mdmcpq.inf 31 | CopyFiles=DriverCopyFiles.nt 32 | AddReg=DriverInstall.nt.AddReg 33 | 34 | [DriverCopyFiles.nt] 35 | usbser.sys,,,0x20 36 | 37 | [DriverInstall.nt.AddReg] 38 | HKR,,DevLoader,,*ntkern 39 | HKR,,NTMPDriver,,usbser.sys 40 | HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider" 41 | 42 | [DriverInstall.nt.Services] 43 | AddService=usbser, 0x00000002, DriverService.nt 44 | 45 | [DriverService.nt] 46 | DisplayName=%SERVICE% 47 | ServiceType=1 48 | StartType=3 49 | ErrorControl=1 50 | ServiceBinary=%12%\usbser.sys 51 | 52 | ;--------------------------------------------------------------------- 53 | ; Windows XP/Server2003/Vista/Server2008/7 - 64bit Sections 54 | 55 | [DriverInstall.NTamd64] 56 | include=mdmcpq.inf 57 | CopyFiles=DriverCopyFiles.NTamd64 58 | AddReg=DriverInstall.NTamd64.AddReg 59 | 60 | [DriverCopyFiles.NTamd64] 61 | usbser.sys,,,0x20 62 | 63 | [DriverInstall.NTamd64.AddReg] 64 | HKR,,DevLoader,,*ntkern 65 | HKR,,NTMPDriver,,usbser.sys 66 | HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider" 67 | 68 | [DriverInstall.NTamd64.Services] 69 | AddService=usbser, 0x00000002, DriverService.NTamd64 70 | 71 | [DriverService.NTamd64] 72 | DisplayName=%SERVICE% 73 | ServiceType=1 74 | StartType=3 75 | ErrorControl=1 76 | ServiceBinary=%12%\usbser.sys 77 | 78 | ;--------------------------------------------------------------------- 79 | ; Vendor and Product ID Definitions 80 | 81 | [SourceDisksFiles] 82 | [SourceDisksNames] 83 | [DeviceList] 84 | %DESCRIPTION%=DriverInstall, USB\VID_f055&PID_9800&MI_00, USB\VID_f055&PID_9800&MI_01, USB\VID_f055&PID_9801&MI_00, USB\VID_f055&PID_9801&MI_01, USB\VID_f055&PID_9802 85 | 86 | [DeviceList.NTamd64] 87 | %DESCRIPTION%=DriverInstall, USB\VID_f055&PID_9800&MI_00, USB\VID_f055&PID_9800&MI_01, USB\VID_f055&PID_9801&MI_00, USB\VID_f055&PID_9801&MI_01, USB\VID_f055&PID_9802 88 | 89 | ;--------------------------------------------------------------------- 90 | ; String Definitions 91 | 92 | [Strings] 93 | MFGFILENAME="tpybcdc" 94 | MFGNAME="MicroPython" 95 | DESCRIPTION="TPYBoard USB Comm Port" 96 | SERVICE="USB Serial Driver" 97 | -------------------------------------------------------------------------------- /TPYBoard-v10x-master/36.照相机/README.txt: -------------------------------------------------------------------------------- 1 | 实例的大概简介 2 | ----------------------- 3 | TPYBoard v102 通过串口与串口摄像头模块(PTC06)进行连接,通过按键控制模块进行拍照,并保存到TF卡中。 4 | 5 | 6 | 接线方式 7 | 8 | TPYBoard v102 摄像头模块 9 | --------------------------- 10 | VIN 5V 11 | GND GND 12 | X1(UART 4 TX) RX 13 | X2(UART 4 RX) TX 14 | 15 | TPYBoard v102 LCD5110显示屏 16 | --------------------------- 17 | Y12 RST 18 | Y11 CE 19 | Y10 DC 20 | Y9 LIGHT 21 | X8 DIN 22 | X6 CLK 23 | 3.3V VIN 24 | GND GND 25 | 26 | 按键引出 27 | ------------------ 28 | 将TPYBoard v102上面的两个板子按键RST、USR引出,好嵌入到相机纸盒的顶部。由于板子按键初始化默认为低电平。 29 | 所以接按键模块时,需要将正负极反过来接。 30 | 31 | TPYBoard v102 RST按键(黑色) 32 | -------------------------------- 33 | 3.3V GND 34 | GND VCC 35 | RST OUT 36 | 37 | 38 | TPYBoard v102 USR按键(黄色) 39 | --------------------------------- 40 | GND VCC 41 | 3.3V GND 42 | X17 OUT 43 | 44 | -------------------------------------------------------------------------------- /TPYBoard-v10x-master/36.照相机/boot.py: -------------------------------------------------------------------------------- 1 | # boot.py -- run on boot-up 2 | # can run arbitrary Python, but best to keep it minimal 3 | 4 | import machine 5 | import pyb 6 | pyb.main('main.py') # main script to run after this one 7 | #pyb.usb_mode('CDC+MSC') # act as a serial and a storage device 8 | #pyb.usb_mode('CDC+HID') # act as a serial device and a mouse 9 | -------------------------------------------------------------------------------- /TPYBoard-v10x-master/36.照相机/main.py: -------------------------------------------------------------------------------- 1 | import pyb 2 | from pyb import UART,Switch 3 | import upcd8544 4 | 5 | 6 | 7 | #-----command---------# 8 | initcmd=b'\x56\x00\x26\x00' #复位 9 | clearcmd=b'\x56\x00\x36\x01\x02' #清除缓存 10 | photocmd=b'\x56\x00\x36\x01\x00' #拍照 11 | lengthcmd=b'\x56\x00\x34\x01\x00' #获取图片长度 12 | readcmd=b'\x56\x00\x32\x0C\x00\x0A\x00\x00' #获取图片数据 13 | responseCmd=b'\x76\x00\x32\x00\x00'#返回的图片数据固定头和尾 14 | #---------------------------------# 15 | isFlag=0#标识是否初始化 16 | isPhoto=0#标识是否发送拍照命令 17 | num=0 18 | f_name='/sd/photo%s.jpeg' 19 | nBytes=2048#每次读取的字节数 20 | #---------------------------------# 21 | uart=UART(4,115200,timeout=100)#X1(UART 4 TX) X2(UART 4 RX) 22 | #-------十进制转16进制------------# 23 | def convert_Data(num): 24 | if num>255: 25 | num_h=hex(num) 26 | if len(num_h)<6: 27 | num_h_a=num_h[:3] 28 | num_h_b='0x'+num_h[3:] 29 | else: 30 | num_h_a=num_h[:4] 31 | num_h_b='0x'+num_h[4:] 32 | byte_num=bytes([int(num_h_a,16),int(num_h_b,16)]) 33 | else: 34 | byte_num=b'\x00'+bytes([num]) 35 | return byte_num 36 | def get_photo(add,readlen): 37 | global readcmd,responseCmd 38 | 39 | cmd=readcmd+add+b'\x00\x00'+readlen+b'\x00\xFF' 40 | uart.write(cmd) 41 | while uart.any()<=0: 42 | continue 43 | data=uart.read() 44 | #print('data:',data) 45 | #print('data[0:5]:',data[0:5]) 46 | #print('data[-5:]:',data[-5:]) 47 | if data[0:5]==responseCmd and data[-5:]==responseCmd: 48 | revdata=data[5:-5] 49 | print('revdata:',revdata) 50 | else: 51 | revdata=0 52 | return revdata 53 | def test(): 54 | global num,isPhoto 55 | pyb.delay(30) 56 | if(sw()): 57 | sw.callback(None) 58 | isPhoto=0 59 | num+=1 60 | pyb.LED(3).on() 61 | #清除缓存 62 | uart.write(clearcmd) 63 | #-------LCD5110 Init-----------# 64 | SPI = pyb.SPI(1) #DIN=>X8-MOSI/CLK=>X6-SCK 65 | RST = pyb.Pin('Y12') 66 | CE = pyb.Pin('Y11') 67 | DC = pyb.Pin('Y10') 68 | LIGHT = pyb.Pin('Y9') 69 | lcd_5110 = upcd8544.PCD8544(SPI, RST, CE, DC, LIGHT) 70 | lcd_5110.lcd_write_bmp() 71 | #------------------------------# 72 | print('wait......') 73 | pyb.delay(2800) 74 | print('init start.......') 75 | uart.write(initcmd) 76 | sw=Switch() 77 | sw.callback(test) 78 | while True: 79 | if uart.any()>0: 80 | data=uart.read() 81 | print('revdata:',data) 82 | if isFlag==0: 83 | #说明接收的是复位后的信息 84 | if data==b'Init end\r\n': 85 | #复位完毕 86 | print('init ok.......') 87 | pyb.delay(2000) 88 | isFlag=1 89 | pyb.LED(2).on() 90 | lcd_5110.lcd_write_bmp(0) 91 | else: 92 | if len(data)>=5: 93 | if data[0]==118:#0x76 94 | if data[2]==54:#0x36 95 | if isPhoto==0: 96 | #清除缓存返回 97 | print('-----clear buffer ok----') 98 | isPhoto=1 99 | uart.write(photocmd) 100 | lcd_5110.clear() 101 | lcd_5110.lcd_write_bmp(1) 102 | else: 103 | #拍照返回 104 | print('-----taking pictures ok----') 105 | uart.write(lengthcmd) 106 | if data[2]==52:#0x34 107 | print('photo length:',data[7],'-',data[8]) 108 | tlen=data[7]*256+data[8] 109 | t_c=tlen//nBytes 110 | t_y=tlen%nBytes 111 | add=0 112 | #256=[0x01,0x00] 512=[0x02,0x00] 113 | length=convert_Data(nBytes) 114 | name=f_name % str(num) 115 | print('filename:',name) 116 | f=open(name,'w') 117 | f.write('') 118 | f.close() 119 | offset=0 120 | for i in range(0,t_c): 121 | offset_a=i//4 122 | if offset 0: 22 | buf = ESP_UART.read().decode().replace('\r','').replace('\n','').replace(' ','') 23 | print(buf) 24 | if buf.find('busyp') > -1 or buf.find('ERROR') > -1: 25 | # AT指令执行失败 26 | # 结束程序排查原因 27 | break 28 | elif buf.find('ATOK') > -1: 29 | # 说明AT指令执行成功 30 | #if 'ATOK' in buf: 31 | # 成功进入AT指令模式 32 | # 设置WIFI模式 33 | sendToUart(CWMODE_CUR) 34 | elif buf.find(CWMODE_CUR) > -1: 35 | # 设置sta模式成功,连接AP 36 | sendToUart(CWJAP_CUR) 37 | LED(1).on() 38 | elif buf.find('WIFIGOTIP') > -1: 39 | # 连接AP成功 40 | # 连接TCP Server成功,发送数据 41 | pyb.delay(150) 42 | sendToUart(CIPSTART) 43 | LED(2).on() 44 | elif buf.find(CIPSTART) > -1: 45 | # 连接TCP Server成功,发送数据 46 | CIPSEND = CIPSEND % str(len(msg)) 47 | sendToUart(CIPSEND) 48 | LED(3).on() 49 | elif buf.find('>') > -1: 50 | # 发送数据 51 | sendToUart(msg) 52 | LED(4).on() 53 | -------------------------------------------------------------------------------- /TPYBoard-v10x-master/38.结合ESP8266模块实现HTTP请求实例/GET/main.py: -------------------------------------------------------------------------------- 1 | from pyb import UART 2 | from pyb import LED 3 | 4 | #等待ESP-01模块初始化,忽略启动时的内部信息 5 | pyb.delay(1000) 6 | 7 | ESP_UART = UART(4,115200,timeout=100) 8 | 9 | def sendToUart(msg): 10 | ESP_UART.write(msg+'\r\n') 11 | 12 | CWMODE_CUR = 'AT+CWMODE_CUR=1' 13 | CWJAP_CUR = 'AT+CWJAP_CUR="TurnipSmart","turnip2016"' 14 | CIPSTART = 'AT+CIPSTART="TCP","183.230.40.33",80' 15 | CIPSEND = 'AT+CIPSEND=%s' 16 | 17 | get = """GET /devices/5835707 HTTP/1.1 18 | api-key: xUrvOCDB=iRuS5noq9FsKrvoW=s= 19 | Host:api.heclouds.com\r\n\r\n 20 | """ 21 | if __name__ == '__main__': 22 | #退出透传 23 | ESP_UART.write('+++') 24 | pyb.delay(500) 25 | sendToUart('AT') 26 | isConn = 0 27 | while True: 28 | if ESP_UART.any() > 0: 29 | buf = ESP_UART.read().decode().replace('\r','').replace('\n','').replace(' ','') 30 | print(buf) 31 | pyb.delay(200) 32 | if buf.find('busyp') > -1 or buf.find('ERROR') > -1: 33 | # AT指令执行失败 34 | # 结束程序排查原因 35 | break 36 | elif buf.find('ATOK') > -1: 37 | # 说明AT指令执行成功 38 | #if 'ATOK' in buf: 39 | # 成功进入AT指令模式 40 | # 设置WIFI模式 41 | sendToUart(CWMODE_CUR) 42 | elif buf.find(CWMODE_CUR) > -1: 43 | # 设置sta模式成功,连接AP 44 | sendToUart(CWJAP_CUR) 45 | LED(1).on() 46 | elif buf.find(CWJAP_CUR) > -1: 47 | isConn = 1 48 | elif buf.find('OK') > -1 and isConn: 49 | # 连接AP成功 50 | # 连接TCP Server 51 | sendToUart(CIPSTART) 52 | LED(2).on() 53 | isConn = 0 54 | elif buf.find('WIFIGOTIP') > -1: 55 | # 连接AP成功 56 | # 连接TCP Server 57 | sendToUart(CIPSTART) 58 | LED(2).on() 59 | elif buf.find('CONNECTOK') > -1: 60 | # 连接TCP Server成功,发送数据 61 | LED(3).on() 62 | sendToUart('AT+CIPMODE=1')#透传 63 | elif buf.find('AT+CIPMODE=1') > -1: 64 | sendToUart('AT+CIPSEND')#启动传输 65 | elif buf.find('>') > -1: 66 | # 发送数据 67 | sendToUart(get) 68 | LED(4).on() 69 | elif buf.find('HTTP') > -1: 70 | #退出透传 71 | ESP_UART.write('+++') 72 | pyb.delay(500) 73 | break -------------------------------------------------------------------------------- /TPYBoard-v10x-master/38.结合ESP8266模块实现HTTP请求实例/POST/main.py: -------------------------------------------------------------------------------- 1 | from pyb import UART 2 | from pyb import LED 3 | 4 | #等待ESP-01模块初始化,忽略启动时的内部信息 5 | pyb.delay(1000) 6 | 7 | ESP_UART = UART(4,115200,timeout=100) 8 | 9 | def sendToUart(msg): 10 | ESP_UART.write(msg+'\r\n') 11 | 12 | CWMODE_CUR = 'AT+CWMODE_CUR=1' 13 | CWJAP_CUR = 'AT+CWJAP_CUR="TurnipSmart","turnip2016"' 14 | CIPSTART = 'AT+CIPSTART="TCP","183.230.40.33",80' 15 | CIPSEND = 'AT+CIPSEND=%s' 16 | 17 | get = """GET /devices/5835707 HTTP/1.1 18 | api-key: xUrvOCDB=iRuS5noq9FsKrvoW=s= 19 | Host:api.heclouds.com\r\n\r\n 20 | """ 21 | post = """POST /devices/5835707/datapoints HTTP/1.1 22 | api-key: xUrvOCDB=iRuS5noq9FsKrvoW=s= 23 | Host:api.heclouds.com 24 | Content-Length:60\r\n 25 | {"datastreams":[{"id":"switch","datapoints":[{"value":1}]}]} 26 | """ 27 | if __name__ == '__main__': 28 | #退出透传 29 | ESP_UART.write('+++') 30 | pyb.delay(500) 31 | sendToUart('AT') 32 | isConn = 0 33 | while True: 34 | if ESP_UART.any() > 0: 35 | buf = ESP_UART.read().decode().replace('\r','').replace('\n','').replace(' ','') 36 | print(buf) 37 | pyb.delay(200) 38 | if buf.find('busyp') > -1 or buf.find('ERROR') > -1: 39 | # AT指令执行失败 40 | # 结束程序排查原因 41 | break 42 | elif buf.find('ATOK') > -1: 43 | # 说明AT指令执行成功 44 | #if 'ATOK' in buf: 45 | # 成功进入AT指令模式 46 | # 设置WIFI模式 47 | sendToUart(CWMODE_CUR) 48 | elif buf.find(CWMODE_CUR) > -1: 49 | # 设置sta模式成功,连接AP 50 | sendToUart(CWJAP_CUR) 51 | LED(1).on() 52 | elif buf.find(CWJAP_CUR) > -1: 53 | isConn = 1 54 | elif buf.find('OK') > -1 and isConn: 55 | # 连接AP成功 56 | # 连接TCP Server 57 | sendToUart(CIPSTART) 58 | LED(2).on() 59 | isConn = 0 60 | elif buf.find('WIFIGOTIP') > -1: 61 | # 连接AP成功 62 | # 连接TCP Server 63 | sendToUart(CIPSTART) 64 | LED(2).on() 65 | elif buf.find('CONNECTOK') > -1: 66 | # 连接TCP Server成功,发送数据 67 | LED(3).on() 68 | sendToUart('AT+CIPMODE=1')#透传 69 | elif buf.find('AT+CIPMODE=1') > -1: 70 | sendToUart('AT+CIPSEND')#启动传输 71 | elif buf.find('>') > -1: 72 | # 发送数据 73 | sendToUart(post) 74 | LED(4).on() 75 | elif buf.find('HTTP') > -1: 76 | #退出透传 77 | ESP_UART.write('+++') 78 | pyb.delay(500) 79 | break -------------------------------------------------------------------------------- /TPYBoard-v10x-master/39.驱动DHT11模块获取温湿度/dht11.py: -------------------------------------------------------------------------------- 1 | import pyb 2 | from pyb import UART 3 | from pyb import Pin,delay,udelay 4 | import time 5 | class DHT11: 6 | def __init__(self,pin_name): 7 | time.sleep(1) 8 | self.N1 = Pin(pin_name, Pin.OUT_PP) 9 | self.PinName=pin_name 10 | pyb.delay(10) 11 | def read_data(self): 12 | self.__init__(self.PinName) 13 | data=[] 14 | j=0 15 | N1=self.N1 16 | N1.low() 17 | delay(20) 18 | N1.high() 19 | N1 = Pin(self.PinName, Pin.IN) 20 | udelay(30) 21 | if N1.value() != 0: 22 | return [0,0] 23 | while N1.value()==0: 24 | continue 25 | while N1.value()==1: 26 | continue 27 | while j<40: 28 | k=0 29 | while N1.value()==0: 30 | continue 31 | while N1.value()==1: 32 | k+=1 33 | if k>100:break 34 | if k<3: 35 | data.append(0) 36 | else: 37 | data.append(1) 38 | j=j+1 39 | print('Sensor is working') 40 | j=0 41 | humidity_bit=data[0:8] 42 | humidity_point_bit=data[8:16] 43 | temperature_bit=data[16:24] 44 | temperature_point_bit=data[24:32] 45 | check_bit=data[32:40] 46 | humidity=0 47 | humidity_point=0 48 | temperature=0 49 | temperature_point=0 50 | check=0 51 | for i in range(8): 52 | humidity+=humidity_bit[i]*2**(7-i) 53 | humidity_point+=humidity_point_bit[i]*2**(7-i) 54 | temperature+=temperature_bit[i]*2**(7-i) 55 | temperature_point+=temperature_point_bit[i]*2**(7-i) 56 | check+=check_bit[i]*2**(7-i) 57 | tmp=humidity+humidity_point+temperature+temperature_point 58 | if check==tmp: 59 | print('temperature is',temperature,'-wet is',humidity,'%') 60 | else: 61 | print('Error:',humidity,humidity_point,temperature,temperature_point,check) 62 | return [str(temperature),str(humidity)] -------------------------------------------------------------------------------- /TPYBoard-v10x-master/39.驱动DHT11模块获取温湿度/main.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TPYBoard/developmentBoard/535a975480a6755394cedfe3708a05952d9b6539/TPYBoard-v10x-master/39.驱动DHT11模块获取温湿度/main.py -------------------------------------------------------------------------------- /TPYBoard-v10x-master/README.md: -------------------------------------------------------------------------------- 1 |

The TPYBoard v10x Series

2 | 3 |

TPYBoard v102

4 | 5 | 6 | 7 | 8 | 9 | 典型实例文档资料:http://docs.tpyboard.com/ 10 | 11 | -------------------------------------------------------------------------------- /TPYBoard-v10x-master/image/v102.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TPYBoard/developmentBoard/535a975480a6755394cedfe3708a05952d9b6539/TPYBoard-v10x-master/image/v102.png -------------------------------------------------------------------------------- /TPYBoard-v20x-master/README.md: -------------------------------------------------------------------------------- 1 |

The TPYBoard v20x Series

2 | 3 |

TPYBoard v201

4 | 5 | 6 | 7 |

TPYBoard v202

8 | 9 | 10 | 11 | 12 | 典型实例文档资料:http://docs.tpyboard.com/ 13 | 14 | -------------------------------------------------------------------------------- /TPYBoard-v20x-master/TPYBoard v201 典型实例/01.建立云加法器/main.py: -------------------------------------------------------------------------------- 1 | import pyb 2 | from pyb import UART 3 | from pyb import Pin 4 | from ubinascii import hexlify 5 | from ubinascii import * 6 | 7 | ulan = UART(6, 9600,timeout = 100)#定义连接网口的串口 8 | K=1 9 | jia=0 10 | jie1=0 11 | he=0 12 | js=0#设置寄存变量 13 | #*******************************主程序********************************** 14 | print('while') 15 | while (K>0): 16 | _dataRead=ulan.readall()#读取客户端数据 17 | if _dataRead!=None:#判断客户端是否传来数据 18 | print(_dataRead) 19 | js=js+1#计数判断执行命令标志 20 | if(js==1): 21 | jia=_dataRead.decode('utf-8')#数据转换 22 | jia=int(jia)#数据转换 23 | print(jia) 24 | if(js==2): 25 | jia1=_dataRead.decode('utf-8') 26 | jia1=int(jia1) 27 | print(jia1) 28 | if(js==2): 29 | he=jia+jia1 30 | js=0 31 | ulan.write(str(jia)+'+'+str(jia1)+'='+str(he)+'\r\n')#计算结果返回给客户端 -------------------------------------------------------------------------------- /TPYBoard-v20x-master/TPYBoard v201 典型实例/02.温湿度数据上传/dht11.py: -------------------------------------------------------------------------------- 1 | import pyb 2 | from pyb import UART 3 | from pyb import Pin 4 | import time 5 | class DHT11: 6 | def __init__(self,pin_name): 7 | time.sleep(1) 8 | self.N1 = Pin(pin_name, Pin.OUT_PP) 9 | self.PinName=pin_name 10 | pyb.delay(10) 11 | def read_data(self): 12 | self.__init__(self.PinName) 13 | data=[] 14 | j=0 15 | N1=self.N1 16 | N1.low() 17 | time.sleep(0.03) 18 | N1.high() 19 | N1 = Pin(self.PinName, Pin.IN) 20 | while N1.value()==1: 21 | continue 22 | while N1.value()==0: 23 | continue 24 | while N1.value()==1: 25 | continue 26 | while j<40: 27 | k=0 28 | while N1.value()==0: 29 | continue 30 | while N1.value()==1: 31 | k+=1 32 | if k>100:break 33 | if k<3: 34 | data.append(0) 35 | else: 36 | data.append(1) 37 | j=j+1 38 | print('Sensor is working') 39 | j=0 40 | humidity_bit=data[0:8] 41 | humidity_point_bit=data[8:16] 42 | temperature_bit=data[16:24] 43 | temperature_point_bit=data[24:32] 44 | check_bit=data[32:40] 45 | humidity=0 46 | humidity_point=0 47 | temperature=0 48 | temperature_point=0 49 | check=0 50 | for i in range(8): 51 | humidity+=humidity_bit[i]*2**(7-i) 52 | humidity_point+=humidity_point_bit[i]*2**(7-i) 53 | temperature+=temperature_bit[i]*2**(7-i) 54 | temperature_point+=temperature_point_bit[i]*2**(7-i) 55 | check+=check_bit[i]*2**(7-i) 56 | tmp=humidity+humidity_point+temperature+temperature_point 57 | if check==tmp: 58 | print('temperature is',temperature,'-wet is',humidity,'%') 59 | else: 60 | print('Error:',humidity,humidity_point,temperature,temperature_point,check) 61 | return [str(temperature),str(humidity)] 62 | -------------------------------------------------------------------------------- /TPYBoard-v20x-master/TPYBoard v201 典型实例/02.温湿度数据上传/main.py: -------------------------------------------------------------------------------- 1 | import pyb 2 | from pyb import UART 3 | from pyb import Pin 4 | from ubinascii import hexlify 5 | from ubinascii import * 6 | from dht11 import DHT11#定义温湿度传感器的库 7 | 8 | ulan = UART(6, 115200 , timeout = 100)#定义串口,我的网口设置了115200的波特率 9 | K=1 10 | #*******************************主程序********************************** 11 | print('while') 12 | while (K>0): 13 | #init DHT11 14 | dht=DHT11('X8') 15 | data_=dht.read_data()#读取温湿度的值 16 | temp=str(data_[0])#温度 17 | hum=str(data_[1])#湿度 18 | print('temp:'+temp) 19 | print('hum:'+hum) 20 | ulan.write('temperature is:'+temp+'\r\n')#上传温度 21 | pyb.delay(2000)#做延时是为了让给模拟服务器一个反应时间 22 | ulan.write('wet is:'+hum+'%'+'\r\n')#上传湿度 23 | pyb.delay(12000) -------------------------------------------------------------------------------- /TPYBoard-v20x-master/TPYBoard v202 典型实例/01.GPIO的使用/main.py: -------------------------------------------------------------------------------- 1 | from machine import Pin 2 | import time 3 | 4 | p2 = Pin(2, Pin.OUT) # create output pin on GPIO2 5 | p2.value(1) # set pin to high 6 | 7 | while True: 8 | p2.low() # set pin to low 9 | p2.value() 10 | time.sleep(3) # sleep for 3 second 11 | p2.high() # set pin to high 12 | p2.value() 13 | time.sleep(3)# sleep for 3 second -------------------------------------------------------------------------------- /TPYBoard-v20x-master/TPYBoard v202 典型实例/02.Network连接网络/实验一/main.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TPYBoard/developmentBoard/535a975480a6755394cedfe3708a05952d9b6539/TPYBoard-v20x-master/TPYBoard v202 典型实例/02.Network连接网络/实验一/main.py -------------------------------------------------------------------------------- /TPYBoard-v20x-master/TPYBoard v202 典型实例/02.Network连接网络/实验二/main.py: -------------------------------------------------------------------------------- 1 | import network 2 | from machine import Pin 3 | import socket 4 | import urllib 5 | import time 6 | 7 | def led_state(): 8 | p2 = Pin(2, Pin.OUT) 9 | p2.value(0) 10 | time.sleep_ms(500) 11 | p2.value(1) 12 | time.sleep_ms(500) 13 | p2.value(0) 14 | time.sleep_ms(500) 15 | p2.value(1) 16 | 17 | def do_connect(): 18 | sta_if = network.WLAN(network.STA_IF) 19 | p2 = Pin(2, Pin.OUT) 20 | sta_if.active(False) 21 | if not sta_if.isconnected(): 22 | p2.low() 23 | print('connecting to network...') 24 | sta_if.active(True) 25 | sta_if.connect('TurnipSmart', 'turnip2016') 26 | while not sta_if.isconnected(): 27 | pass 28 | if sta_if.isconnected(): 29 | print('connect success') 30 | p2.high() 31 | print('network config:', sta_if.ifconfig()) 32 | 33 | def http_get(url): 34 | _, _, host, path = url.split('/', 3) 35 | addr = socket.getaddrinfo(host, 80)[0][-1] 36 | s = socket.socket() 37 | s.connect(addr) 38 | s.send(bytes('GET /%s HTTP/1.0\r\nHost: %s\r\n\r\n' % (path, host), 'utf8')) 39 | while True: 40 | data = s.recv(50) 41 | if data: 42 | recive=str(data, 'utf8') 43 | #print('recive:',recive) 44 | print(str(data, 'utf8'), end='') 45 | if(recive.find('begin')>-1): 46 | led_state() 47 | else: 48 | break 49 | s.close() 50 | do_connect() 51 | http_get('http://www.tpyboard.com/esp8266/test.php?val=A') -------------------------------------------------------------------------------- /TPYBoard-v20x-master/TPYBoard v202 典型实例/03.定时器/main.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TPYBoard/developmentBoard/535a975480a6755394cedfe3708a05952d9b6539/TPYBoard-v20x-master/TPYBoard v202 典型实例/03.定时器/main.py -------------------------------------------------------------------------------- /TPYBoard-v20x-master/TPYBoard v202 典型实例/04.PWM控制舵机/WIFI无线控制舵机/main.py: -------------------------------------------------------------------------------- 1 | import machine 2 | import time 3 | import network 4 | import usocket 5 | import usocket as socket 6 | 7 | 8 | def WorkMode_STA(essid,pwd): 9 | sta_mode=network.WLAN(network.STA_IF)#设定工作模式为STA模式 10 | sta_mode.active(True)#激活接口 11 | sta_mode.connect(essid,pwd)#essid:WIFI名称 pwd:WIFI密码 12 | #检测是否连接路由器成功 13 | while not sta_mode.isconnected(): 14 | pass 15 | print('IP:', sta_mode.ifconfig()[0])#打印IP地址 16 | #ifconfig() (ip, subnet, gateway, dns) 17 | return sta_mode.ifconfig()[0] 18 | def WorkMode_AP(essid,pwd): 19 | ap_mode=network.WLAN(network.AP_IF)#设定工作模式为AP模式 20 | ap_mode.active(True)#激活接口 21 | ap_mode.config(essid,pwd)#设置WIFI热点,essid:WIFI名称 pwd:WIFI密码 22 | print('IP:', ap_mode.ifconfig()[0])#打印IP地址 23 | return ap_mode.ifconfig()[0] 24 | def StartServer(ip_): 25 | s = socket.socket()#创建TCPSocket服务 26 | ai = socket.getaddrinfo(ip_,8989)#获取IP地址和端口 27 | addr = ai[0][-1] 28 | print('Server:',addr) 29 | s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) 30 | s.bind(addr)#绑定地址 31 | s.listen(5)#监听最大客户端数5个 32 | while True: 33 | res = s.accept()#接收请求 34 | client_s = res[0] 35 | client_addr = res[1] 36 | print('addr:',client_addr)#打印客户端地址 37 | req =client_s.recv(1024)#读取数据 38 | req=req.decode('utf-8')#字节数组转字符串 39 | print('reviceData:',req) 40 | try: 41 | val_=int(req) 42 | servo.duty(val_)#舵机角度的设定 43 | client_s.send('ok') 44 | client_s.close() 45 | except: 46 | client_s.send('no') 47 | client_s.close() 48 | if __name__ =="__main__": 49 | #设置PWM 引脚G5,频率50Hz 50 | servo = machine.PWM(machine.Pin(5), freq=50) 51 | myip=WorkMode_STA('essid','pwd') 52 | #myip=WorkMode_AP('TPYBoard v202','12345678') 53 | StartServer(myip) -------------------------------------------------------------------------------- /TPYBoard-v20x-master/TPYBoard v202 典型实例/04.PWM控制舵机/main.py: -------------------------------------------------------------------------------- 1 | import machine 2 | import time 3 | 4 | #设置PWM 引脚G5,频率50Hz 5 | servo = machine.PWM(machine.Pin(5), freq=50) 6 | 7 | servo.duty(40)#舵机角度的设定 8 | time.sleep(2)#延时2秒 9 | servo.duty(115) 10 | time.sleep(2) 11 | servo.duty(180) -------------------------------------------------------------------------------- /TPYBoard-v20x-master/TPYBoard v202 典型实例/05.I2C操作DS3231模块/ds3231.py: -------------------------------------------------------------------------------- 1 | import machine 2 | from machine import I2C,Pin 3 | 4 | DS3231_ADDR = const(0x68) 5 | DS3231_REG_SEC = b'\x00' 6 | DS3231_REG_MIN = b'\x01' 7 | DS3231_REG_HOUR = b'\x02' 8 | DS3231_REG_WEEKDAY= b'\x03' 9 | DS3231_REG_DAY = b'\x04' 10 | DS3231_REG_MONTH = b'\x05' 11 | DS3231_REG_YEAR = b'\x06' 12 | DS3231_REG_A1SEC = b'\x07' 13 | DS3231_REG_A1MIN = b'\x08' 14 | DS3231_REG_A1HOUR = b'\x09' 15 | DS3231_REG_A1DAY = 0x0A 16 | DS3231_REG_A2MIN = 0x0B 17 | DS3231_REG_A2HOUR = 0x0C 18 | DS3231_REG_A2DAY = 0x0D 19 | DS3231_REG_CTRL = 0x0E 20 | DS3231_REG_STA = 0x0F 21 | DS3231_REG_OFF = 0x10 22 | DS3231_REG_TEMP = b'\x11' 23 | 24 | class DS3231(object): 25 | def __init__(self): 26 | self.i2c =I2C(scl=Pin(14),sda=Pin(2),freq=100000) 27 | def DATE(self, dat=[]): 28 | if dat==[]: 29 | t = [] 30 | t.append(self.year()) 31 | t.append(self.month()) 32 | t.append(self.day()) 33 | return t 34 | else: 35 | self.year(dat[0]) 36 | self.month(dat[1]) 37 | self.day(dat[2]) 38 | 39 | def TIME(self, dat=[]): 40 | if dat==[]: 41 | t = [] 42 | t.append(self.hour()) 43 | t.append(self.min()) 44 | t.append(self.sec()) 45 | return t 46 | else: 47 | self.hour(dat[0]) 48 | self.min(dat[1]) 49 | self.sec(dat[2]) 50 | 51 | def DateTime(self, dat=[]): 52 | if dat==[]: 53 | return self.DATE() + self.TIME() 54 | else: 55 | self.year(dat[0]) 56 | self.month(dat[1]) 57 | self.day(dat[2]) 58 | self.hour(dat[3]) 59 | self.min(dat[4]) 60 | self.sec(dat[5]) 61 | 62 | def dec2hex(self, dat): 63 | return (int(dat/10)<<4) + (dat%10) 64 | 65 | def setREG(self, dat,reg): 66 | buf = bytearray(2) 67 | buf[0] = reg[0] 68 | buf[1] = dat 69 | self.i2c.writeto(DS3231_ADDR,buf) 70 | 71 | def getREG_DEC(self,reg): 72 | self.i2c.writeto(DS3231_ADDR,reg) 73 | t = self.i2c.readfrom(DS3231_ADDR,1)[0] 74 | return (t>>4)*10 + (t%16) 75 | 76 | def sec(self, sec=''): 77 | if sec == '': 78 | return self.getREG_DEC(DS3231_REG_SEC) 79 | else: 80 | self.setREG(self.dec2hex(sec), DS3231_REG_SEC) 81 | 82 | def min(self, min=''): 83 | if min == '': 84 | return self.getREG_DEC(DS3231_REG_MIN) 85 | else: 86 | self.setREG(self.dec2hex(min), DS3231_REG_MIN) 87 | 88 | def hour(self, hour=''): 89 | if hour=='': 90 | return self.getREG_DEC(DS3231_REG_HOUR) 91 | else: 92 | self.setREG(self.dec2hex(hour), DS3231_REG_HOUR) 93 | 94 | def day(self, day=''): 95 | if day=='': 96 | return self.getREG_DEC(DS3231_REG_DAY) 97 | else: 98 | self.setREG(self.dec2hex(day), DS3231_REG_DAY) 99 | 100 | def month(self, month=''): 101 | if month=='': 102 | return self.getREG_DEC(DS3231_REG_MONTH) 103 | else: 104 | self.setREG(self.dec2hex(month), DS3231_REG_MONTH) 105 | 106 | def year(self, year=''): 107 | if year=='': 108 | return self.getREG_DEC(DS3231_REG_YEAR) 109 | else: 110 | self.setREG(self.dec2hex(year), DS3231_REG_YEAR) 111 | 112 | def TEMP(self): 113 | self.i2c.writeto(DS3231_ADDR,DS3231_REG_TEMP) 114 | t1 = self.i2c.readfrom(DS3231_ADDR,1)[0] 115 | self.i2c.writeto(DS3231_ADDR,b'\x12') 116 | t2 = self.i2c.readfrom(DS3231_ADDR,1)[0] 117 | if t1>0x7F: 118 | return t1 - t2/256 -256 119 | else: 120 | return t1 + t2/256 121 | 122 | 123 | -------------------------------------------------------------------------------- /TPYBoard-v20x-master/TPYBoard v202 典型实例/05.I2C操作DS3231模块/main.py: -------------------------------------------------------------------------------- 1 | import machine 2 | import time 3 | from ds3231 import DS3231 4 | 5 | ds=DS3231() 6 | ds.DATE([17,9,1]) 7 | ds.TIME([10,10,10]) 8 | 9 | while True: 10 | print('Date:',ds.DATE()) 11 | print('Time:',ds.TIME()) 12 | print('TEMP:',ds.TEMP()) 13 | time.sleep(5) -------------------------------------------------------------------------------- /TPYBoard-v20x-master/TPYBoard v202 典型实例/06.通过HTTP协议上传温湿度/main.py: -------------------------------------------------------------------------------- 1 | import dht 2 | import machine 3 | import network 4 | from machine import Pin 5 | import socket 6 | import urllib 7 | import time#声明用到的类库,尤其是dht的类库 8 | 9 | d = dht.DHT11(machine.Pin(5))#声明用到类库中的函数,并设置参数 10 | led = Pin(2, Pin.OUT) 11 | count=0 12 | def http_get(url):#定义数据上传的函数 13 | _, _, host, path = url.split('/', 3)#分割传进来的参数 14 | addr = socket.getaddrinfo(host, 80)[0][-1]#把传进来的参数处理成符合格式的地址 15 | s = socket.socket() 16 | s.connect(addr)#链接地址 17 | s.send(bytes('GET /%s HTTP/1.0\r\nHost: %s\r\n\r\n' % (path, host), 'utf8'))#向链接的地址发送数据 18 | while True:#开始数据发送 19 | data = s.recv(50) 20 | if data:#数据未发送完成,继续发送 21 | recive=str(data, 'utf8').upper() 22 | #print(str(data, 'utf8'), end='') 23 | if(recive.find('YES')>-1): 24 | print('Send Data OK') 25 | else:#数据发送完成,退出while 26 | break 27 | s.close()#关闭数据连接 28 | def do_connect():#定义开发板连接无线网络的函数 29 | wlan = network.WLAN(network.STA_IF)#设置开发板的网#络模式 30 | wlan.active(True)#打开网络连接 31 | if not wlan.isconnected():#判断是否有网络连接 32 | print('connecting to network...') 33 | wlan.connect('无线名称', '密码')#设置想要连接的无线名称和密码 34 | while not wlan.isconnected():#等待连接上无线网络 35 | pass 36 | print('network config:', wlan.ifconfig()) 37 | 38 | do_connect()#调用一次开发板连接无线网络的函数 39 | while True:#开始整个代码的大循环 40 | d.measure()#调用DHT类库中测量数据的函数 41 | temp_=str(d.temperature())#读取measure()函数中的温度数据 42 | hum_=str(d.humidity())#读取measure()函数中的湿度数据 43 | count+=1#计数变量+1 44 | print('eg:',temp_,'-',hum_) 45 | http_get('http://www.tpyboard.com/esp8266/SensorTest.php?t='+temp_+'&h='+hum_+'') 46 | #调用数据上传函数,把最新测量得到的数据进行上传 47 | print('Count:',count) 48 | time.sleep(5) -------------------------------------------------------------------------------- /TPYBoard-v20x-master/TPYBoard v202 典型实例/07.自制微信远程智能温湿度计/boot.py: -------------------------------------------------------------------------------- 1 | import network 2 | import utime 3 | 4 | pdcn = network.WLAN(network.STA_IF) 5 | pdcn.active(True) 6 | pdcn.connect('wifi账号', 'wifi密码') 7 | utime.sleep(5) 8 | if pdcn.isconnected(): 9 | print("WiFi is connected %s."%pdcn.ifconfig()[0]) 10 | else: 11 | pdcn.active(False) 12 | utime.sleep(5) 13 | print("WiFi cannot connect.") -------------------------------------------------------------------------------- /TPYBoard-v20x-master/TPYBoard v202 典型实例/07.自制微信远程智能温湿度计/main.py: -------------------------------------------------------------------------------- 1 | import urequests 2 | import dht 3 | import machine 4 | from machine import Pin 5 | import time 6 | 7 | class AlarmSystem: 8 | def __init__(self): 9 | self.d = dht.DHT11(machine.Pin(5)) 10 | 11 | def dht11(self): 12 | try: 13 | self.d.measure() 14 | return 'Temp:'+str(self.d.temperature())+'°C---Hum:'+str(self.d.humidity())+'%' 15 | 16 | except: 17 | return '0' 18 | 19 | def push(self, result): 20 | title = "TPYBoardv202提示您:注意天气变化保持健康心情" 21 | content = 'text='+title+'&'+'desp='+result 22 | url="https://sc.ftqq.com/你的密钥.send?%s" % content 23 | r = urequests.get(url) 24 | r.close() 25 | 26 | p2=Pin(2,Pin.OUT) 27 | a = AlarmSystem() 28 | 29 | def SendData(): 30 | p2.value(not p2.value()) 31 | data_= a.dht11() 32 | if(data_!='0'): 33 | print(data_) 34 | a.push(data_) 35 | else: 36 | print('GET Data Fail') 37 | 38 | if __name__ == '__main__': 39 | 40 | while True: 41 | SendData() 42 | time.sleep(300) 43 | -------------------------------------------------------------------------------- /TPYBoard-v20x-master/TPYBoard v202 典型实例/08.家庭气象站/SensorData.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 温湿度传感器实验 6 | 25 | 26 | 27 | 28 |
29 |
30 |

TPYBoardV202_温湿度传感器实验

31 |
32 |
33 |
34 | 35 | 36 | -------------------------------------------------------------------------------- /TPYBoard-v20x-master/TPYBoard v202 典型实例/08.家庭气象站/SensorTest.php: -------------------------------------------------------------------------------- 1 | 1) 6 | { 7 | $data_=""; 8 | //获取温度 9 | if(isset($_GET["t"])) 10 | { 11 | $para=$_GET["t"]; 12 | $data_.="传感器数据:温度:".$para." ℃ - "; 13 | } 14 | //获取湿度 15 | if(isset($_GET["h"])) 16 | { 17 | $para=$_GET["h"]; 18 | $data_.="湿度:".$para." % "; 19 | $state_="Yes"; 20 | } 21 | } 22 | $myfile = fopen("sensor.txt", "w"); 23 | $txt = $time_."

".$data_; 24 | fwrite($myfile, $txt); 25 | fclose($myfile); 26 | echo $state_; 27 | ?> -------------------------------------------------------------------------------- /TPYBoard-v20x-master/TPYBoard v202 典型实例/08.家庭气象站/v102/README.txt: -------------------------------------------------------------------------------- 1 | This is a TPYboard 2 | 3 | You can get started right away by writing your Python code in 'main.py'. 4 | 5 | For a serial prompt: 6 | - Windows: you need to go to 'Device manager', right click on the unknown device, 7 | then update the driver software, using the 'tpybcdc.inf' file found on this drive. 8 | Then use a terminal program like Hyperterminal or putty. 9 | - Mac OS X: use the command: screen /dev/tty.usbmodem* 10 | - Linux: use the command: screen /dev/ttyACM0 11 | 12 | Please visit http://www.tpyboard.com/help/ for further help. 13 | 14 | Designed by TurnipSmart in Shandong! -------------------------------------------------------------------------------- /TPYBoard-v20x-master/TPYBoard v202 典型实例/08.家庭气象站/v102/boot.py: -------------------------------------------------------------------------------- 1 | # boot.py -- run on boot-up 2 | # can run arbitrary Python, but best to keep it minimal 3 | 4 | import machine 5 | import pyb 6 | #pyb.main('main.py') # main script to run after this one 7 | #pyb.usb_mode('CDC+MSC') # act as a serial and a storage device 8 | #pyb.usb_mode('CDC+HID') # act as a serial device and a mouse 9 | -------------------------------------------------------------------------------- /TPYBoard-v20x-master/TPYBoard v202 典型实例/08.家庭气象站/v102/dht11.py: -------------------------------------------------------------------------------- 1 | import pyb 2 | from pyb import UART 3 | from pyb import Pin,delay,udelay 4 | import time 5 | class DHT11: 6 | def __init__(self,pin_name): 7 | time.sleep(1) 8 | self.N1 = Pin(pin_name, Pin.OUT_PP) 9 | self.PinName=pin_name 10 | pyb.delay(10) 11 | def read_data(self): 12 | self.__init__(self.PinName) 13 | data=[] 14 | j=0 15 | N1=self.N1 16 | N1.low() 17 | delay(20) 18 | N1.high() 19 | N1 = Pin(self.PinName, Pin.IN) 20 | udelay(30) 21 | if N1.value() != 0: 22 | return [0,0] 23 | while N1.value()==0: 24 | continue 25 | while N1.value()==1: 26 | continue 27 | while j<40: 28 | k=0 29 | while N1.value()==0: 30 | continue 31 | while N1.value()==1: 32 | k+=1 33 | if k>100:break 34 | if k<3: 35 | data.append(0) 36 | else: 37 | data.append(1) 38 | j=j+1 39 | print('Sensor is working') 40 | j=0 41 | humidity_bit=data[0:8] 42 | humidity_point_bit=data[8:16] 43 | temperature_bit=data[16:24] 44 | temperature_point_bit=data[24:32] 45 | check_bit=data[32:40] 46 | humidity=0 47 | humidity_point=0 48 | temperature=0 49 | temperature_point=0 50 | check=0 51 | for i in range(8): 52 | humidity+=humidity_bit[i]*2**(7-i) 53 | humidity_point+=humidity_point_bit[i]*2**(7-i) 54 | temperature+=temperature_bit[i]*2**(7-i) 55 | temperature_point+=temperature_point_bit[i]*2**(7-i) 56 | check+=check_bit[i]*2**(7-i) 57 | tmp=humidity+humidity_point+temperature+temperature_point 58 | if check==tmp: 59 | print('temperature is',temperature,'-wet is',humidity,'%') 60 | else: 61 | print('Error:',humidity,humidity_point,temperature,temperature_point,check) 62 | return [temperature,humidity] -------------------------------------------------------------------------------- /TPYBoard-v20x-master/TPYBoard v202 典型实例/08.家庭气象站/v102/font.py: -------------------------------------------------------------------------------- 1 | class FONT6_8: 2 | """docstring for FONT6_8""" 3 | FONTTYPE6_8 = [ 4 | [0x00, 0x00, 0x00, 0x00, 0x00, 0x00] # 20 5 | ,[0x00, 0x00, 0x00, 0x5f, 0x00, 0x00] # 21 ! 6 | ,[0x00, 0x00, 0x07, 0x00, 0x07, 0x00] # 22 " 7 | ,[0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14] # 23 # 8 | ,[0x00, 0x24, 0x2a, 0x7f, 0x2a, 0x12] # 24 $ 9 | ,[0x00, 0x23, 0x13, 0x08, 0x64, 0x62] # 25 % 10 | ,[0x00, 0x36, 0x49, 0x55, 0x22, 0x50] # 26 & 11 | ,[0x00, 0x00, 0x05, 0x03, 0x00, 0x00] # 27 ' 12 | ,[0x00, 0x00, 0x1c, 0x22, 0x41, 0x00] # 28 ( 13 | ,[0x00, 0x00, 0x41, 0x22, 0x1c, 0x00] # 29 ) 14 | ,[0x00, 0x14, 0x08, 0x3e, 0x08, 0x14] # 2a * 15 | ,[0x00, 0x08, 0x08, 0x3e, 0x08, 0x08] # 2b + 16 | ,[0x00, 0x00, 0x50, 0x30, 0x00, 0x00] # 2c , 17 | ,[0x00, 0x08, 0x08, 0x08, 0x08, 0x08] # 2d - 18 | ,[0x00, 0x00, 0x60, 0x60, 0x00, 0x00] # 2e . 19 | ,[0x00, 0x20, 0x10, 0x08, 0x04, 0x02] # 2f / 20 | ,[0x00, 0x3e, 0x51, 0x49, 0x45, 0x3e] # 30 0 21 | ,[0x00, 0x00, 0x42, 0x7f, 0x40, 0x00] # 31 1 22 | ,[0x00, 0x42, 0x61, 0x51, 0x49, 0x46] # 32 2 23 | ,[0x00, 0x21, 0x41, 0x45, 0x4b, 0x31] # 33 3 24 | ,[0x00, 0x18, 0x14, 0x12, 0x7f, 0x10] # 34 4 25 | ,[0x00, 0x27, 0x45, 0x45, 0x45, 0x39] # 35 5 26 | ,[0x00, 0x3c, 0x4a, 0x49, 0x49, 0x30] # 36 6 27 | ,[0x00, 0x01, 0x71, 0x09, 0x05, 0x03] # 37 7 28 | ,[0x00, 0x36, 0x49, 0x49, 0x49, 0x36] # 38 8 29 | ,[0x00, 0x06, 0x49, 0x49, 0x29, 0x1e] # 39 9 30 | ,[0x00, 0x00, 0x36, 0x36, 0x00, 0x00] # 3a : 31 | ,[0x00, 0x00, 0x56, 0x36, 0x00, 0x00] # 3b ; 32 | ,[0x00, 0x08, 0x14, 0x22, 0x41, 0x00] # 3c < 33 | ,[0x00, 0x14, 0x14, 0x14, 0x14, 0x14] # 3d = 34 | ,[0x00, 0x00, 0x41, 0x22, 0x14, 0x08] # 3e > 35 | ,[0x00, 0x02, 0x01, 0x51, 0x09, 0x06] # 3f ? 36 | ,[0x00, 0x32, 0x49, 0x79, 0x41, 0x3e] # 40 @ 37 | ,[0x00, 0x7e, 0x11, 0x11, 0x11, 0x7e] # 41 A 38 | ,[0x00, 0x7f, 0x49, 0x49, 0x49, 0x36] # 42 B 39 | ,[0x00, 0x3e, 0x41, 0x41, 0x41, 0x22] # 43 C 40 | ,[0x00, 0x7f, 0x41, 0x41, 0x22, 0x1c] # 44 D 41 | ,[0x00, 0x7f, 0x49, 0x49, 0x49, 0x41] # 45 E 42 | ,[0x00, 0x7f, 0x09, 0x09, 0x09, 0x01] # 46 F 43 | ,[0x00, 0x3e, 0x41, 0x49, 0x49, 0x7a] # 47 G 44 | ,[0x00, 0x7f, 0x08, 0x08, 0x08, 0x7f] # 48 H 45 | ,[0x00, 0x00, 0x41, 0x7f, 0x41, 0x00] # 49 I 46 | ,[0x00, 0x20, 0x40, 0x41, 0x3f, 0x01] # 4a J 47 | ,[0x00, 0x7f, 0x08, 0x14, 0x22, 0x41] # 4b K 48 | ,[0x00, 0x7f, 0x40, 0x40, 0x40, 0x40] # 4c L 49 | ,[0x00, 0x7f, 0x02, 0x0c, 0x02, 0x7f] # 4d M 50 | ,[0x00, 0x7f, 0x04, 0x08, 0x10, 0x7f] # 4e N 51 | ,[0x00, 0x3e, 0x41, 0x41, 0x41, 0x3e] # 4f O 52 | ,[0x00, 0x7f, 0x09, 0x09, 0x09, 0x06] # 50 P 53 | ,[0x00, 0x3e, 0x41, 0x51, 0x21, 0x5e] # 51 Q 54 | ,[0x00, 0x7f, 0x09, 0x19, 0x29, 0x46] # 52 R 55 | ,[0x00, 0x46, 0x49, 0x49, 0x49, 0x31] # 53 S 56 | ,[0x00, 0x01, 0x01, 0x7f, 0x01, 0x01] # 54 T 57 | ,[0x00, 0x3f, 0x40, 0x40, 0x40, 0x3f] # 55 U 58 | ,[0x00, 0x1f, 0x20, 0x40, 0x20, 0x1f] # 56 V 59 | ,[0x00, 0x3f, 0x40, 0x38, 0x40, 0x3f] # 57 W 60 | ,[0x00, 0x63, 0x14, 0x08, 0x14, 0x63] # 58 X 61 | ,[0x00, 0x07, 0x08, 0x70, 0x08, 0x07] # 59 Y 62 | ,[0x00, 0x61, 0x51, 0x49, 0x45, 0x43] # 5a Z 63 | ,[0x00, 0x00, 0x7f, 0x41, 0x41, 0x00] # 5b [ 64 | ,[0x00, 0x02, 0x04, 0x08, 0x10, 0x20] # 5c \ # 65 | ,[0x00, 0x00, 0x41, 0x41, 0x7f, 0x00] # 5d ] 66 | ,[0x00, 0x04, 0x02, 0x01, 0x02, 0x04] # 5e ^ 67 | ,[0x00, 0x40, 0x40, 0x40, 0x40, 0x40] # 5f _ 68 | ,[0x00, 0x00, 0x01, 0x02, 0x04, 0x00] # 60 ` 69 | ,[0x00, 0x20, 0x54, 0x54, 0x54, 0x78] # 61 a 70 | ,[0x00, 0x7f, 0x48, 0x44, 0x44, 0x38] # 62 b 71 | ,[0x00, 0x38, 0x44, 0x44, 0x44, 0x20] # 63 c 72 | ,[0x00, 0x38, 0x44, 0x44, 0x48, 0x7f] # 64 d 73 | ,[0x00, 0x38, 0x54, 0x54, 0x54, 0x18] # 65 e 74 | ,[0x00, 0x08, 0x7e, 0x09, 0x01, 0x02] # 66 f 75 | ,[0x00, 0x0c, 0x52, 0x52, 0x52, 0x3e] # 67 g 76 | ,[0x00, 0x7f, 0x08, 0x04, 0x04, 0x78] # 68 h 77 | ,[0x00, 0x00, 0x44, 0x7d, 0x40, 0x00] # 69 i 78 | ,[0x00, 0x20, 0x40, 0x44, 0x3d, 0x00] # 6a j 79 | ,[0x00, 0x7f, 0x10, 0x28, 0x44, 0x00] # 6b k 80 | ,[0x00, 0x00, 0x41, 0x7f, 0x40, 0x00] # 6c l 81 | ,[0x00, 0x7c, 0x04, 0x18, 0x04, 0x78] # 6d m 82 | ,[0x00, 0x7c, 0x08, 0x04, 0x04, 0x78] # 6e n 83 | ,[0x00, 0x38, 0x44, 0x44, 0x44, 0x38] # 6f o 84 | ,[0x00, 0x7c, 0x14, 0x14, 0x14, 0x08] # 70 p 85 | ,[0x00, 0x08, 0x14, 0x14, 0x18, 0x7c] # 71 q 86 | ,[0x00, 0x7c, 0x08, 0x04, 0x04, 0x08] # 72 r 87 | ,[0x00, 0x48, 0x54, 0x54, 0x54, 0x20] # 73 s 88 | ,[0x00, 0x04, 0x3f, 0x44, 0x40, 0x20] # 74 t 89 | ,[0x00, 0x3c, 0x40, 0x40, 0x20, 0x7c] # 75 u 90 | ,[0x00, 0x1c, 0x20, 0x40, 0x20, 0x1c] # 76 v 91 | ,[0x00, 0x3c, 0x40, 0x30, 0x40, 0x3c] # 77 w 92 | ,[0x00, 0x44, 0x28, 0x10, 0x28, 0x44] # 78 x 93 | ,[0x00, 0x0c, 0x50, 0x50, 0x50, 0x3c] # 79 y 94 | ,[0x00, 0x44, 0x64, 0x54, 0x4c, 0x44] # 7a z 95 | ,[0x00, 0x00, 0x08, 0x36, 0x41, 0x00] # 7b [ 96 | ,[0x00, 0x00, 0x00, 0x7f, 0x00, 0x00] # 7c | 97 | ,[0x00, 0x00, 0x41, 0x36, 0x08, 0x00] # 7d ] 98 | ,[0x00, 0x10, 0x08, 0x08, 0x10, 0x08] # 7e ~ 99 | ,[0x00, 0x78, 0x46, 0x41, 0x46, 0x78] # 7f (delete) 100 | ] 101 | 102 | def get_font6_8(self, data): 103 | return self.FONTTYPE6_8[bytearray(data)[0] - 0x20] 104 | 105 | -------------------------------------------------------------------------------- /TPYBoard-v20x-master/TPYBoard v202 典型实例/08.家庭气象站/v102/main.py: -------------------------------------------------------------------------------- 1 | #main.py 2 | import pyb 3 | import upcd8544 4 | from machine import SPI,Pin 5 | from dht11 import DHT11 6 | def main(lcd_5110,dht,uart6): 7 | data_=dht.read_data() 8 | lcd_5110.lcd_write_string(' ',0,1)#添加一个分隔行 9 | lcd_5110.lcd_write_string('Temp:'+str(data_[0]),2,2) 10 | lcd_5110.lcd_write_string(' ',0,3) 11 | lcd_5110.lcd_write_string(' Hum:'+str(data_[1]),2,4) 12 | uart6.write(str(data_[0])+','+str(data_[1]))#通过串口将数据发送给v202 13 | if __name__ == '__main__': 14 | #init UART 15 | u6=pyb.UART(6,115200) 16 | #init DHT11 17 | dht=DHT11('X12') 18 | #init LCD5110 19 | SPI = pyb.SPI(1) 20 | RST = pyb.Pin('Y11') 21 | CE = pyb.Pin('Y10') 22 | DC = pyb.Pin('Y9') 23 | LIGHT = pyb.Pin('X4') 24 | #DIN=>X8-MOSI/CLK=>X6-SCK 25 | #DIN =>SPI(1).MOSI 'X8' data flow (Master out, Slave in) 26 | #CLK =>SPI(1).SCK 'X6' SPI clock 27 | lcd_5110 = upcd8544.PCD8544(SPI, RST, CE, DC, LIGHT) 28 | lcd_5110.lcd_write_string('TPYBoard v102',1,0) 29 | while True: 30 | main(lcd_5110,dht,u6) 31 | pyb.delay(2000) -------------------------------------------------------------------------------- /TPYBoard-v20x-master/TPYBoard v202 典型实例/08.家庭气象站/v102/tpybcdc.inf: -------------------------------------------------------------------------------- 1 | key = USB_VID val = f055 2 | key = USB_PID_CDC_MSC val = 9800 3 | key = USB_PID_CDC_HID val = 9801 4 | key = USB_PID_CDC val = 9802 5 | ; Windows USB CDC ACM Setup File 6 | ; Based on INF files which were: 7 | ; Copyright (c) 2000 Microsoft Corporation 8 | ; Copyright (C) 2007 Microchip Technology Inc. 9 | ; Likely to be covered by the MLPL as found at: 10 | ; . 11 | 12 | [Version] 13 | Signature="$Windows NT$" 14 | Class=Ports 15 | ClassGuid={4D36E978-E325-11CE-BFC1-08002BE10318} 16 | Provider=%MFGNAME% 17 | LayoutFile=layout.inf 18 | DriverVer=03/11/2010,5.1.2600.3 19 | 20 | [Manufacturer] 21 | %MFGNAME%=DeviceList, NTamd64 22 | 23 | [DestinationDirs] 24 | DefaultDestDir=12 25 | 26 | ;--------------------------------------------------------------------- 27 | ; Windows 2000/XP/Server2003/Vista/Server2008/7 - 32bit Sections 28 | 29 | [DriverInstall.nt] 30 | include=mdmcpq.inf 31 | CopyFiles=DriverCopyFiles.nt 32 | AddReg=DriverInstall.nt.AddReg 33 | 34 | [DriverCopyFiles.nt] 35 | usbser.sys,,,0x20 36 | 37 | [DriverInstall.nt.AddReg] 38 | HKR,,DevLoader,,*ntkern 39 | HKR,,NTMPDriver,,usbser.sys 40 | HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider" 41 | 42 | [DriverInstall.nt.Services] 43 | AddService=usbser, 0x00000002, DriverService.nt 44 | 45 | [DriverService.nt] 46 | DisplayName=%SERVICE% 47 | ServiceType=1 48 | StartType=3 49 | ErrorControl=1 50 | ServiceBinary=%12%\usbser.sys 51 | 52 | ;--------------------------------------------------------------------- 53 | ; Windows XP/Server2003/Vista/Server2008/7 - 64bit Sections 54 | 55 | [DriverInstall.NTamd64] 56 | include=mdmcpq.inf 57 | CopyFiles=DriverCopyFiles.NTamd64 58 | AddReg=DriverInstall.NTamd64.AddReg 59 | 60 | [DriverCopyFiles.NTamd64] 61 | usbser.sys,,,0x20 62 | 63 | [DriverInstall.NTamd64.AddReg] 64 | HKR,,DevLoader,,*ntkern 65 | HKR,,NTMPDriver,,usbser.sys 66 | HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider" 67 | 68 | [DriverInstall.NTamd64.Services] 69 | AddService=usbser, 0x00000002, DriverService.NTamd64 70 | 71 | [DriverService.NTamd64] 72 | DisplayName=%SERVICE% 73 | ServiceType=1 74 | StartType=3 75 | ErrorControl=1 76 | ServiceBinary=%12%\usbser.sys 77 | 78 | ;--------------------------------------------------------------------- 79 | ; Vendor and Product ID Definitions 80 | 81 | [SourceDisksFiles] 82 | [SourceDisksNames] 83 | [DeviceList] 84 | %DESCRIPTION%=DriverInstall, USB\VID_f055&PID_9800&MI_00, USB\VID_f055&PID_9800&MI_01, USB\VID_f055&PID_9801&MI_00, USB\VID_f055&PID_9801&MI_01, USB\VID_f055&PID_9802 85 | 86 | [DeviceList.NTamd64] 87 | %DESCRIPTION%=DriverInstall, USB\VID_f055&PID_9800&MI_00, USB\VID_f055&PID_9800&MI_01, USB\VID_f055&PID_9801&MI_00, USB\VID_f055&PID_9801&MI_01, USB\VID_f055&PID_9802 88 | 89 | ;--------------------------------------------------------------------- 90 | ; String Definitions 91 | 92 | [Strings] 93 | MFGFILENAME="tpybcdc" 94 | MFGNAME="MicroPython" 95 | DESCRIPTION="TPYBoard USB Comm Port" 96 | SERVICE="USB Serial Driver" 97 | -------------------------------------------------------------------------------- /TPYBoard-v20x-master/TPYBoard v202 典型实例/08.家庭气象站/v202/main.py: -------------------------------------------------------------------------------- 1 | import machine 2 | import network 3 | import socket 4 | from machine import Pin 5 | from machine import UART 6 | import time 7 | u2=UART(0,115200)#串口初始化 8 | led = Pin(2, Pin.OUT).value(1)#板载小蓝灯 默认关闭 9 | def http_get(temp,hum): 10 | url='http://old.tpyboard.com/esp8266/SensorTest.php?t='+temp+'&h='+hum+'' 11 | _, _, host, path = url.split('/', 3) 12 | addr = socket.getaddrinfo(host, 80)[0][-1] 13 | s = socket.socket() 14 | s.connect(addr) 15 | s.send(bytes('GET /%s HTTP/1.0\r\nHost: %s\r\n\r\n' % (path, host), 'utf8')) 16 | while True: 17 | data = s.recv(50) 18 | if data: 19 | recive=str(data, 'utf8').upper() 20 | #print(str(data, 'utf8'), end='') 21 | if(recive.find('YES')>-1): 22 | print('Send Data OK') 23 | else: 24 | break 25 | s.close() 26 | def do_connect(): 27 | wlan = network.WLAN(network.STA_IF) 28 | wlan.active(True) 29 | if not wlan.isconnected(): 30 | print('connecting to network...') 31 | wlan.connect('essid', 'password') 32 | while not wlan.isconnected(): 33 | pass 34 | print('network config:', wlan.ifconfig()) 35 | do_connect() 36 | led = Pin(2, Pin.OUT).value(0)#连接wifi成功 点亮LED 37 | while 1: 38 | data_=u2.read() 39 | if data_!=None: 40 | data_=data_.decode('utf8')#数组转成字符串 41 | data_a=data_.split(',')#分割 42 | temp_=str(data_a[0])#温度 43 | hum_=str(data_a[1])#湿度 44 | http_get(temp_,hum_)#发送给服务器 45 | time.sleep(2) -------------------------------------------------------------------------------- /TPYBoard-v20x-master/TPYBoard v202 典型实例/09.MQTT协议接入OneNET平台/boot.py: -------------------------------------------------------------------------------- 1 | #连接本地网络 2 | def do_connect(): 3 | import network 4 | sta_if = network.WLAN(network.STA_IF) 5 | ap_if = network.WLAN(network.AP_IF) 6 | if ap_if.active(): 7 | ap_if.active(False) 8 | if not sta_if.isconnected(): 9 | print('connecting to network...') 10 | sta_if.active(True) 11 | sta_if.connect('WIFI名称','密码') #wifi的SSID和密码 12 | while not sta_if.isconnected(): 13 | pass 14 | print('network config:', sta_if.ifconfig()) 15 | do_connect() -------------------------------------------------------------------------------- /TPYBoard-v20x-master/TPYBoard v202 典型实例/09.MQTT协议接入OneNET平台/main.py: -------------------------------------------------------------------------------- 1 | import mqtt 2 | mqtt.main() -------------------------------------------------------------------------------- /TPYBoard-v20x-master/TPYBoard v202 典型实例/09.MQTT协议接入OneNET平台/mqtt.py: -------------------------------------------------------------------------------- 1 | from simple import MQTTClient 2 | from machine import Pin 3 | import machine 4 | import micropython 5 | #选择G4引脚 6 | g4 = Pin(4, Pin.OUT, value=0) 7 | # MQTT服务器地址域名为:183.230.40.39,不变 8 | SERVER = "183.230.40.39" 9 | #设备ID 10 | CLIENT_ID = "deviceID" 11 | #随便起个名字 12 | TOPIC = b"TurnipRobot" 13 | #产品ID 14 | username='productID' 15 | #产品APIKey: 16 | password='APIKey' 17 | state = 0 18 | def sub_cb(topic, msg): 19 | global state 20 | print((topic, msg)) 21 | if msg == b"on": 22 | g4.value(1) 23 | state = 1 24 | print("1") 25 | elif msg == b"off": 26 | g4.value(0) 27 | state = 0 28 | print("0") 29 | elif msg == b"toggle": 30 | state = 1 - state 31 | g4.value(state) 32 | 33 | def main(server=SERVER): 34 | #端口号为:6002 35 | c = MQTTClient(CLIENT_ID, server,6002,username,password) 36 | c.set_callback(sub_cb) 37 | c.connect() 38 | c.subscribe(TOPIC) 39 | print("Connected to %s, subscribed to %s topic" % (server, TOPIC)) 40 | try: 41 | while 1: 42 | c.wait_msg() 43 | finally: 44 | c.disconnect() -------------------------------------------------------------------------------- /TPYBoard-v20x-master/TPYBoard v202 典型实例/09.MQTT协议接入OneNET平台/simple.py: -------------------------------------------------------------------------------- 1 | import usocket as socket 2 | import ustruct as struct 3 | from ubinascii import hexlify 4 | 5 | class MQTTException(Exception): 6 | pass 7 | 8 | class MQTTClient: 9 | 10 | def __init__(self, client_id, server, port=0, user=None, password=None, keepalive=0, 11 | ssl=False, ssl_params={}): 12 | if port == 0: 13 | port = 8883 if ssl else 1883 14 | self.client_id = client_id 15 | self.sock = None 16 | self.server = server 17 | self.port = port 18 | self.ssl = ssl 19 | self.ssl_params = ssl_params 20 | self.pid = 0 21 | self.cb = None 22 | self.user = user 23 | self.pswd = password 24 | self.keepalive = keepalive 25 | self.lw_topic = None 26 | self.lw_msg = None 27 | self.lw_qos = 0 28 | self.lw_retain = False 29 | 30 | def _send_str(self, s): 31 | self.sock.write(struct.pack("!H", len(s))) 32 | self.sock.write(s) 33 | 34 | def _recv_len(self): 35 | n = 0 36 | sh = 0 37 | while 1: 38 | b = self.sock.read(1)[0] 39 | n |= (b & 0x7f) << sh 40 | if not b & 0x80: 41 | return n 42 | sh += 7 43 | 44 | def set_callback(self, f): 45 | self.cb = f 46 | 47 | def set_last_will(self, topic, msg, retain=False, qos=0): 48 | assert 0 <= qos <= 2 49 | assert topic 50 | self.lw_topic = topic 51 | self.lw_msg = msg 52 | self.lw_qos = qos 53 | self.lw_retain = retain 54 | 55 | def connect(self, clean_session=True): 56 | self.sock = socket.socket() 57 | addr = socket.getaddrinfo(self.server, self.port)[0][-1] 58 | self.sock.connect(addr) 59 | if self.ssl: 60 | import ussl 61 | self.sock = ussl.wrap_socket(self.sock, **self.ssl_params) 62 | premsg = bytearray(b"\x10\0\0\0\0\0") 63 | msg = bytearray(b"\x04MQTT\x04\x02\0\0") 64 | 65 | sz = 10 + 2 + len(self.client_id) 66 | msg[6] = clean_session << 1 67 | if self.user is not None: 68 | sz += 2 + len(self.user) + 2 + len(self.pswd) 69 | msg[6] |= 0xC0 70 | if self.keepalive: 71 | assert self.keepalive < 65536 72 | msg[7] |= self.keepalive >> 8 73 | msg[8] |= self.keepalive & 0x00FF 74 | if self.lw_topic: 75 | sz += 2 + len(self.lw_topic) + 2 + len(self.lw_msg) 76 | msg[6] |= 0x4 | (self.lw_qos & 0x1) << 3 | (self.lw_qos & 0x2) << 3 77 | msg[6] |= self.lw_retain << 5 78 | 79 | i = 1 80 | while sz > 0x7f: 81 | premsg[i] = (sz & 0x7f) | 0x80 82 | sz >>= 7 83 | i += 1 84 | premsg[i] = sz 85 | 86 | self.sock.write(premsg, i + 2) 87 | self.sock.write(msg) 88 | #print(hex(len(msg)), hexlify(msg, ":")) 89 | self._send_str(self.client_id) 90 | if self.lw_topic: 91 | self._send_str(self.lw_topic) 92 | self._send_str(self.lw_msg) 93 | if self.user is not None: 94 | self._send_str(self.user) 95 | self._send_str(self.pswd) 96 | resp = self.sock.read(4) 97 | assert resp[0] == 0x20 and resp[1] == 0x02 98 | if resp[3] != 0: 99 | raise MQTTException(resp[3]) 100 | return resp[2] & 1 101 | 102 | def disconnect(self): 103 | self.sock.write(b"\xe0\0") 104 | self.sock.close() 105 | 106 | def ping(self): 107 | self.sock.write(b"\xc0\0") 108 | 109 | def publish(self, topic, msg, retain=False, qos=0): 110 | pkt = bytearray(b"\x30\0\0\0") 111 | pkt[0] |= qos << 1 | retain 112 | sz = 2 + len(topic) + len(msg) 113 | if qos > 0: 114 | sz += 2 115 | assert sz < 2097152 116 | i = 1 117 | while sz > 0x7f: 118 | pkt[i] = (sz & 0x7f) | 0x80 119 | sz >>= 7 120 | i += 1 121 | pkt[i] = sz 122 | #print(hex(len(pkt)), hexlify(pkt, ":")) 123 | self.sock.write(pkt, i + 1) 124 | self._send_str(topic) 125 | if qos > 0: 126 | self.pid += 1 127 | pid = self.pid 128 | struct.pack_into("!H", pkt, 0, pid) 129 | self.sock.write(pkt, 2) 130 | self.sock.write(msg) 131 | if qos == 1: 132 | while 1: 133 | op = self.wait_msg() 134 | if op == 0x40: 135 | sz = self.sock.read(1) 136 | assert sz == b"\x02" 137 | rcv_pid = self.sock.read(2) 138 | rcv_pid = rcv_pid[0] << 8 | rcv_pid[1] 139 | if pid == rcv_pid: 140 | return 141 | elif qos == 2: 142 | assert 0 143 | 144 | def subscribe(self, topic, qos=0): 145 | assert self.cb is not None, "Subscribe callback is not set" 146 | pkt = bytearray(b"\x82\0\0\0") 147 | self.pid += 1 148 | struct.pack_into("!BH", pkt, 1, 2 + 2 + len(topic) + 1, self.pid) 149 | #print(hex(len(pkt)), hexlify(pkt, ":")) 150 | self.sock.write(pkt) 151 | self._send_str(topic) 152 | self.sock.write(qos.to_bytes(1, "little")) 153 | while 1: 154 | op = self.wait_msg() 155 | if op == 0x90: 156 | resp = self.sock.read(4) 157 | #print(resp) 158 | assert resp[1] == pkt[2] and resp[2] == pkt[3] 159 | if resp[3] == 0x80: 160 | raise MQTTException(resp[3]) 161 | return 162 | 163 | # Wait for a single incoming MQTT message and process it. 164 | # Subscribed messages are delivered to a callback previously 165 | # set by .set_callback() method. Other (internal) MQTT 166 | # messages processed internally. 167 | def wait_msg(self): 168 | res = self.sock.read(1) 169 | self.sock.setblocking(True) 170 | if res is None: 171 | return None 172 | if res == b"": 173 | raise OSError(-1) 174 | if res == b"\xd0": # PINGRESP 175 | sz = self.sock.read(1)[0] 176 | assert sz == 0 177 | return None 178 | op = res[0] 179 | if op & 0xf0 != 0x30: 180 | return op 181 | sz = self._recv_len() 182 | topic_len = self.sock.read(2) 183 | topic_len = (topic_len[0] << 8) | topic_len[1] 184 | topic = self.sock.read(topic_len) 185 | sz -= topic_len + 2 186 | if op & 6: 187 | pid = self.sock.read(2) 188 | pid = pid[0] << 8 | pid[1] 189 | sz -= 2 190 | msg = self.sock.read(sz) 191 | self.cb(topic, msg) 192 | if op & 6 == 2: 193 | pkt = bytearray(b"\x40\x02\0\0") 194 | struct.pack_into("!H", pkt, 2, pid) 195 | self.sock.write(pkt) 196 | elif op & 6 == 4: 197 | assert 0 198 | 199 | # Checks whether a pending message from server is available. 200 | # If not, returns immediately with None. Otherwise, does 201 | # the same processing as wait_msg. 202 | def check_msg(self): 203 | self.sock.setblocking(False) 204 | return self.wait_msg() 205 | -------------------------------------------------------------------------------- /TPYBoard-v20x-master/TPYBoard v202 典型实例/10.MQTT协议2:上传数据点到OneNET平台/boot.py: -------------------------------------------------------------------------------- 1 | #连接本地网络 2 | def do_connect(): 3 | import network 4 | sta_if = network.WLAN(network.STA_IF) 5 | ap_if = network.WLAN(network.AP_IF) 6 | if ap_if.active(): 7 | ap_if.active(False) 8 | if not sta_if.isconnected(): 9 | print('connecting to network...') 10 | sta_if.active(True) 11 | sta_if.connect('WIFI名称','密码') #wifi的SSID和密码 12 | while not sta_if.isconnected(): 13 | pass 14 | print('network config:', sta_if.ifconfig()) 15 | do_connect() -------------------------------------------------------------------------------- /TPYBoard-v20x-master/TPYBoard v202 典型实例/10.MQTT协议2:上传数据点到OneNET平台/main.py: -------------------------------------------------------------------------------- 1 | import mqtt 2 | mqtt.main() -------------------------------------------------------------------------------- /TPYBoard-v20x-master/TPYBoard v202 典型实例/10.MQTT协议2:上传数据点到OneNET平台/mqtt.py: -------------------------------------------------------------------------------- 1 | from simple import MQTTClient 2 | from machine import Pin 3 | import machine 4 | import micropython 5 | import json 6 | 7 | #选择G4引脚 8 | g4 = Pin(4, Pin.OUT, value=0) 9 | # MQTT服务器地址域名为:183.230.40.39,不变 10 | SERVER = "183.230.40.39" 11 | #设备ID 12 | CLIENT_ID = "deviceID" 13 | #随便起个名字 14 | TOPIC = b"TurnipRobot" 15 | #产品ID 16 | username='productID' 17 | #产品APIKey: 18 | password='APIKey' 19 | state = 0 20 | #要上报的数据点 21 | message = {'datastreams':[{ 22 | 'id':'temperature', 23 | 'datapoints':[{'value':35}]} 24 | ]} 25 | 26 | def pubdata(data): 27 | j_d = json.dumps(data) 28 | j_l = len(j_d) 29 | arr = bytearray(j_l + 3) 30 | arr[0] = 1 #publish数据类型为json 31 | arr[1] = int(j_l / 256) # json数据长度 高位字节 32 | arr[2] = j_l % 256 # json数据长度 低位字节 33 | arr[3:] = j_d.encode('ascii') # json数据 34 | return arr 35 | 36 | def sub_cb(topic, msg): 37 | global state 38 | print((topic, msg)) 39 | if msg == b"on": 40 | g4.value(1) 41 | state = 1 42 | print("1") 43 | elif msg == b"off": 44 | g4.value(0) 45 | state = 0 46 | print("0") 47 | elif msg == b"toggle": 48 | state = 1 - state 49 | g4.value(state) 50 | 51 | def main(server=SERVER): 52 | #端口号为:6002 53 | c = MQTTClient(CLIENT_ID, server,6002,username,password) 54 | c.set_callback(sub_cb) 55 | c.connect() 56 | c.subscribe(TOPIC) 57 | print("Connected to %s, subscribed to %s topic" % (server, TOPIC)) 58 | #publish报文上传数据点 59 | c.publish('$dp',pubdata(message)) 60 | print('publish message:',message) 61 | 62 | try: 63 | while 1: 64 | c.wait_msg() 65 | finally: 66 | c.disconnect() -------------------------------------------------------------------------------- /TPYBoard-v20x-master/TPYBoard v202 典型实例/10.MQTT协议2:上传数据点到OneNET平台/simple.py: -------------------------------------------------------------------------------- 1 | import usocket as socket 2 | import ustruct as struct 3 | from ubinascii import hexlify 4 | 5 | class MQTTException(Exception): 6 | pass 7 | 8 | class MQTTClient: 9 | 10 | def __init__(self, client_id, server, port=0, user=None, password=None, keepalive=0, 11 | ssl=False, ssl_params={}): 12 | if port == 0: 13 | port = 8883 if ssl else 1883 14 | self.client_id = client_id 15 | self.sock = None 16 | self.server = server 17 | self.port = port 18 | self.ssl = ssl 19 | self.ssl_params = ssl_params 20 | self.pid = 0 21 | self.cb = None 22 | self.user = user 23 | self.pswd = password 24 | self.keepalive = keepalive 25 | self.lw_topic = None 26 | self.lw_msg = None 27 | self.lw_qos = 0 28 | self.lw_retain = False 29 | 30 | def _send_str(self, s): 31 | self.sock.write(struct.pack("!H", len(s))) 32 | self.sock.write(s) 33 | 34 | def _recv_len(self): 35 | n = 0 36 | sh = 0 37 | while 1: 38 | b = self.sock.read(1)[0] 39 | n |= (b & 0x7f) << sh 40 | if not b & 0x80: 41 | return n 42 | sh += 7 43 | 44 | def set_callback(self, f): 45 | self.cb = f 46 | 47 | def set_last_will(self, topic, msg, retain=False, qos=0): 48 | assert 0 <= qos <= 2 49 | assert topic 50 | self.lw_topic = topic 51 | self.lw_msg = msg 52 | self.lw_qos = qos 53 | self.lw_retain = retain 54 | 55 | def connect(self, clean_session=True): 56 | self.sock = socket.socket() 57 | addr = socket.getaddrinfo(self.server, self.port)[0][-1] 58 | self.sock.connect(addr) 59 | if self.ssl: 60 | import ussl 61 | self.sock = ussl.wrap_socket(self.sock, **self.ssl_params) 62 | premsg = bytearray(b"\x10\0\0\0\0\0") 63 | msg = bytearray(b"\x04MQTT\x04\x02\0\0") 64 | 65 | sz = 10 + 2 + len(self.client_id) 66 | msg[6] = clean_session << 1 67 | if self.user is not None: 68 | sz += 2 + len(self.user) + 2 + len(self.pswd) 69 | msg[6] |= 0xC0 70 | if self.keepalive: 71 | assert self.keepalive < 65536 72 | msg[7] |= self.keepalive >> 8 73 | msg[8] |= self.keepalive & 0x00FF 74 | if self.lw_topic: 75 | sz += 2 + len(self.lw_topic) + 2 + len(self.lw_msg) 76 | msg[6] |= 0x4 | (self.lw_qos & 0x1) << 3 | (self.lw_qos & 0x2) << 3 77 | msg[6] |= self.lw_retain << 5 78 | 79 | i = 1 80 | while sz > 0x7f: 81 | premsg[i] = (sz & 0x7f) | 0x80 82 | sz >>= 7 83 | i += 1 84 | premsg[i] = sz 85 | 86 | self.sock.write(premsg, i + 2) 87 | self.sock.write(msg) 88 | #print(hex(len(msg)), hexlify(msg, ":")) 89 | self._send_str(self.client_id) 90 | if self.lw_topic: 91 | self._send_str(self.lw_topic) 92 | self._send_str(self.lw_msg) 93 | if self.user is not None: 94 | self._send_str(self.user) 95 | self._send_str(self.pswd) 96 | resp = self.sock.read(4) 97 | assert resp[0] == 0x20 and resp[1] == 0x02 98 | if resp[3] != 0: 99 | raise MQTTException(resp[3]) 100 | return resp[2] & 1 101 | 102 | def disconnect(self): 103 | self.sock.write(b"\xe0\0") 104 | self.sock.close() 105 | 106 | def ping(self): 107 | self.sock.write(b"\xc0\0") 108 | 109 | def publish(self, topic, msg, retain=False, qos=0): 110 | pkt = bytearray(b"\x30\0\0\0") 111 | pkt[0] |= qos << 1 | retain 112 | sz = 2 + len(topic) + len(msg) 113 | if qos > 0: 114 | sz += 2 115 | assert sz < 2097152 116 | i = 1 117 | while sz > 0x7f: 118 | pkt[i] = (sz & 0x7f) | 0x80 119 | sz >>= 7 120 | i += 1 121 | pkt[i] = sz 122 | #print(hex(len(pkt)), hexlify(pkt, ":")) 123 | self.sock.write(pkt, i + 1) 124 | self._send_str(topic) 125 | if qos > 0: 126 | self.pid += 1 127 | pid = self.pid 128 | struct.pack_into("!H", pkt, 0, pid) 129 | self.sock.write(pkt, 2) 130 | self.sock.write(msg) 131 | if qos == 1: 132 | while 1: 133 | op = self.wait_msg() 134 | if op == 0x40: 135 | sz = self.sock.read(1) 136 | assert sz == b"\x02" 137 | rcv_pid = self.sock.read(2) 138 | rcv_pid = rcv_pid[0] << 8 | rcv_pid[1] 139 | if pid == rcv_pid: 140 | return 141 | elif qos == 2: 142 | assert 0 143 | 144 | def subscribe(self, topic, qos=0): 145 | assert self.cb is not None, "Subscribe callback is not set" 146 | pkt = bytearray(b"\x82\0\0\0") 147 | self.pid += 1 148 | struct.pack_into("!BH", pkt, 1, 2 + 2 + len(topic) + 1, self.pid) 149 | #print(hex(len(pkt)), hexlify(pkt, ":")) 150 | self.sock.write(pkt) 151 | self._send_str(topic) 152 | self.sock.write(qos.to_bytes(1, "little")) 153 | while 1: 154 | op = self.wait_msg() 155 | if op == 0x90: 156 | resp = self.sock.read(4) 157 | #print(resp) 158 | assert resp[1] == pkt[2] and resp[2] == pkt[3] 159 | if resp[3] == 0x80: 160 | raise MQTTException(resp[3]) 161 | return 162 | 163 | # Wait for a single incoming MQTT message and process it. 164 | # Subscribed messages are delivered to a callback previously 165 | # set by .set_callback() method. Other (internal) MQTT 166 | # messages processed internally. 167 | def wait_msg(self): 168 | res = self.sock.read(1) 169 | self.sock.setblocking(True) 170 | if res is None: 171 | return None 172 | if res == b"": 173 | raise OSError(-1) 174 | if res == b"\xd0": # PINGRESP 175 | sz = self.sock.read(1)[0] 176 | assert sz == 0 177 | return None 178 | op = res[0] 179 | if op & 0xf0 != 0x30: 180 | return op 181 | sz = self._recv_len() 182 | topic_len = self.sock.read(2) 183 | topic_len = (topic_len[0] << 8) | topic_len[1] 184 | topic = self.sock.read(topic_len) 185 | sz -= topic_len + 2 186 | if op & 6: 187 | pid = self.sock.read(2) 188 | pid = pid[0] << 8 | pid[1] 189 | sz -= 2 190 | msg = self.sock.read(sz) 191 | self.cb(topic, msg) 192 | if op & 6 == 2: 193 | pkt = bytearray(b"\x40\x02\0\0") 194 | struct.pack_into("!H", pkt, 2, pid) 195 | self.sock.write(pkt) 196 | elif op & 6 == 4: 197 | assert 0 198 | 199 | # Checks whether a pending message from server is available. 200 | # If not, returns immediately with None. Otherwise, does 201 | # the same processing as wait_msg. 202 | def check_msg(self): 203 | self.sock.setblocking(False) 204 | return self.wait_msg() 205 | -------------------------------------------------------------------------------- /TPYBoard-v20x-master/TPYBoard v202 典型实例/11.利用单片机快速实现家庭智能控制平台/device.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TPYBoard/developmentBoard/535a975480a6755394cedfe3708a05952d9b6539/TPYBoard-v20x-master/TPYBoard v202 典型实例/11.利用单片机快速实现家庭智能控制平台/device.html -------------------------------------------------------------------------------- /TPYBoard-v20x-master/TPYBoard v202 典型实例/11.利用单片机快速实现家庭智能控制平台/fail.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TPYBoard/developmentBoard/535a975480a6755394cedfe3708a05952d9b6539/TPYBoard-v20x-master/TPYBoard v202 典型实例/11.利用单片机快速实现家庭智能控制平台/fail.html -------------------------------------------------------------------------------- /TPYBoard-v20x-master/TPYBoard v202 典型实例/11.利用单片机快速实现家庭智能控制平台/info.txt: -------------------------------------------------------------------------------- 1 | admin,123456 -------------------------------------------------------------------------------- /TPYBoard-v20x-master/TPYBoard v202 典型实例/11.利用单片机快速实现家庭智能控制平台/login.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TPYBoard/developmentBoard/535a975480a6755394cedfe3708a05952d9b6539/TPYBoard-v20x-master/TPYBoard v202 典型实例/11.利用单片机快速实现家庭智能控制平台/login.html -------------------------------------------------------------------------------- /TPYBoard-v20x-master/TPYBoard v202 典型实例/11.利用单片机快速实现家庭智能控制平台/main.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TPYBoard/developmentBoard/535a975480a6755394cedfe3708a05952d9b6539/TPYBoard-v20x-master/TPYBoard v202 典型实例/11.利用单片机快速实现家庭智能控制平台/main.py -------------------------------------------------------------------------------- /TPYBoard-v20x-master/image/v201.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TPYBoard/developmentBoard/535a975480a6755394cedfe3708a05952d9b6539/TPYBoard-v20x-master/image/v201.jpg -------------------------------------------------------------------------------- /TPYBoard-v20x-master/image/v202.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TPYBoard/developmentBoard/535a975480a6755394cedfe3708a05952d9b6539/TPYBoard-v20x-master/image/v202.png -------------------------------------------------------------------------------- /TPYBoard-v70x-master/01.LCD5110显示环境信息/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TPYBoard/developmentBoard/535a975480a6755394cedfe3708a05952d9b6539/TPYBoard-v70x-master/01.LCD5110显示环境信息/README.md -------------------------------------------------------------------------------- /TPYBoard-v70x-master/01.LCD5110显示环境信息/SHT20.py: -------------------------------------------------------------------------------- 1 | """ 2 | >>> from SHT20 import SHT20 3 | 4 | """ 5 | 6 | import pyb 7 | from pyb import I2C 8 | 9 | SHT20_ADDR = const(0x40) 10 | SHT20_ADDR1 = const(0xE5) 11 | SHT20_REG_TEMP = const(0xE3) 12 | 13 | class SHT20(object): 14 | def __init__(self, i2c_num): 15 | self.i2c = I2C(i2c_num, I2C.MASTER, baudrate = 200000) 16 | def TEMP(self): 17 | self.i2c.send(SHT20_ADDR1, SHT20_ADDR) 18 | t1 = self.i2c.recv(1, SHT20_ADDR)[0] 19 | return t1 20 | def TEMP1(self): 21 | self.i2c.send(SHT20_REG_TEMP, SHT20_ADDR) 22 | t1 = self.i2c.recv(1, SHT20_ADDR)[0] 23 | return t1 24 | -------------------------------------------------------------------------------- /TPYBoard-v70x-master/01.LCD5110显示环境信息/font.py: -------------------------------------------------------------------------------- 1 | class FONT6_8: 2 | """docstring for FONT6_8""" 3 | FONTTYPE6_8 = [ 4 | [0x00, 0x00, 0x00, 0x00, 0x00, 0x00] # 20 5 | ,[0x00, 0x00, 0x00, 0x5f, 0x00, 0x00] # 21 ! 6 | ,[0x00, 0x00, 0x07, 0x00, 0x07, 0x00] # 22 " 7 | ,[0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14] # 23 # 8 | ,[0x00, 0x24, 0x2a, 0x7f, 0x2a, 0x12] # 24 $ 9 | ,[0x00, 0x23, 0x13, 0x08, 0x64, 0x62] # 25 % 10 | ,[0x00, 0x36, 0x49, 0x55, 0x22, 0x50] # 26 & 11 | ,[0x00, 0x00, 0x05, 0x03, 0x00, 0x00] # 27 ' 12 | ,[0x00, 0x00, 0x1c, 0x22, 0x41, 0x00] # 28 ( 13 | ,[0x00, 0x00, 0x41, 0x22, 0x1c, 0x00] # 29 ) 14 | ,[0x00, 0x14, 0x08, 0x3e, 0x08, 0x14] # 2a * 15 | ,[0x00, 0x08, 0x08, 0x3e, 0x08, 0x08] # 2b + 16 | ,[0x00, 0x00, 0x50, 0x30, 0x00, 0x00] # 2c , 17 | ,[0x00, 0x08, 0x08, 0x08, 0x08, 0x08] # 2d - 18 | ,[0x00, 0x00, 0x60, 0x60, 0x00, 0x00] # 2e . 19 | ,[0x00, 0x20, 0x10, 0x08, 0x04, 0x02] # 2f / 20 | ,[0x00, 0x3e, 0x51, 0x49, 0x45, 0x3e] # 30 0 21 | ,[0x00, 0x00, 0x42, 0x7f, 0x40, 0x00] # 31 1 22 | ,[0x00, 0x42, 0x61, 0x51, 0x49, 0x46] # 32 2 23 | ,[0x00, 0x21, 0x41, 0x45, 0x4b, 0x31] # 33 3 24 | ,[0x00, 0x18, 0x14, 0x12, 0x7f, 0x10] # 34 4 25 | ,[0x00, 0x27, 0x45, 0x45, 0x45, 0x39] # 35 5 26 | ,[0x00, 0x3c, 0x4a, 0x49, 0x49, 0x30] # 36 6 27 | ,[0x00, 0x01, 0x71, 0x09, 0x05, 0x03] # 37 7 28 | ,[0x00, 0x36, 0x49, 0x49, 0x49, 0x36] # 38 8 29 | ,[0x00, 0x06, 0x49, 0x49, 0x29, 0x1e] # 39 9 30 | ,[0x00, 0x00, 0x36, 0x36, 0x00, 0x00] # 3a : 31 | ,[0x00, 0x00, 0x56, 0x36, 0x00, 0x00] # 3b ; 32 | ,[0x00, 0x08, 0x14, 0x22, 0x41, 0x00] # 3c < 33 | ,[0x00, 0x14, 0x14, 0x14, 0x14, 0x14] # 3d = 34 | ,[0x00, 0x00, 0x41, 0x22, 0x14, 0x08] # 3e > 35 | ,[0x00, 0x02, 0x01, 0x51, 0x09, 0x06] # 3f ? 36 | ,[0x00, 0x32, 0x49, 0x79, 0x41, 0x3e] # 40 @ 37 | ,[0x00, 0x7e, 0x11, 0x11, 0x11, 0x7e] # 41 A 38 | ,[0x00, 0x7f, 0x49, 0x49, 0x49, 0x36] # 42 B 39 | ,[0x00, 0x3e, 0x41, 0x41, 0x41, 0x22] # 43 C 40 | ,[0x00, 0x7f, 0x41, 0x41, 0x22, 0x1c] # 44 D 41 | ,[0x00, 0x7f, 0x49, 0x49, 0x49, 0x41] # 45 E 42 | ,[0x00, 0x7f, 0x09, 0x09, 0x09, 0x01] # 46 F 43 | ,[0x00, 0x3e, 0x41, 0x49, 0x49, 0x7a] # 47 G 44 | ,[0x00, 0x7f, 0x08, 0x08, 0x08, 0x7f] # 48 H 45 | ,[0x00, 0x00, 0x41, 0x7f, 0x41, 0x00] # 49 I 46 | ,[0x00, 0x20, 0x40, 0x41, 0x3f, 0x01] # 4a J 47 | ,[0x00, 0x7f, 0x08, 0x14, 0x22, 0x41] # 4b K 48 | ,[0x00, 0x7f, 0x40, 0x40, 0x40, 0x40] # 4c L 49 | ,[0x00, 0x7f, 0x02, 0x0c, 0x02, 0x7f] # 4d M 50 | ,[0x00, 0x7f, 0x04, 0x08, 0x10, 0x7f] # 4e N 51 | ,[0x00, 0x3e, 0x41, 0x41, 0x41, 0x3e] # 4f O 52 | ,[0x00, 0x7f, 0x09, 0x09, 0x09, 0x06] # 50 P 53 | ,[0x00, 0x3e, 0x41, 0x51, 0x21, 0x5e] # 51 Q 54 | ,[0x00, 0x7f, 0x09, 0x19, 0x29, 0x46] # 52 R 55 | ,[0x00, 0x46, 0x49, 0x49, 0x49, 0x31] # 53 S 56 | ,[0x00, 0x01, 0x01, 0x7f, 0x01, 0x01] # 54 T 57 | ,[0x00, 0x3f, 0x40, 0x40, 0x40, 0x3f] # 55 U 58 | ,[0x00, 0x1f, 0x20, 0x40, 0x20, 0x1f] # 56 V 59 | ,[0x00, 0x3f, 0x40, 0x38, 0x40, 0x3f] # 57 W 60 | ,[0x00, 0x63, 0x14, 0x08, 0x14, 0x63] # 58 X 61 | ,[0x00, 0x07, 0x08, 0x70, 0x08, 0x07] # 59 Y 62 | ,[0x00, 0x61, 0x51, 0x49, 0x45, 0x43] # 5a Z 63 | ,[0x00, 0x00, 0x7f, 0x41, 0x41, 0x00] # 5b [ 64 | ,[0x00, 0x02, 0x04, 0x08, 0x10, 0x20] # 5c \ # 65 | ,[0x00, 0x00, 0x41, 0x41, 0x7f, 0x00] # 5d ] 66 | ,[0x00, 0x04, 0x02, 0x01, 0x02, 0x04] # 5e ^ 67 | ,[0x00, 0x40, 0x40, 0x40, 0x40, 0x40] # 5f _ 68 | ,[0x00, 0x00, 0x01, 0x02, 0x04, 0x00] # 60 ` 69 | ,[0x00, 0x20, 0x54, 0x54, 0x54, 0x78] # 61 a 70 | ,[0x00, 0x7f, 0x48, 0x44, 0x44, 0x38] # 62 b 71 | ,[0x00, 0x38, 0x44, 0x44, 0x44, 0x20] # 63 c 72 | ,[0x00, 0x38, 0x44, 0x44, 0x48, 0x7f] # 64 d 73 | ,[0x00, 0x38, 0x54, 0x54, 0x54, 0x18] # 65 e 74 | ,[0x00, 0x08, 0x7e, 0x09, 0x01, 0x02] # 66 f 75 | ,[0x00, 0x0c, 0x52, 0x52, 0x52, 0x3e] # 67 g 76 | ,[0x00, 0x7f, 0x08, 0x04, 0x04, 0x78] # 68 h 77 | ,[0x00, 0x00, 0x44, 0x7d, 0x40, 0x00] # 69 i 78 | ,[0x00, 0x20, 0x40, 0x44, 0x3d, 0x00] # 6a j 79 | ,[0x00, 0x7f, 0x10, 0x28, 0x44, 0x00] # 6b k 80 | ,[0x00, 0x00, 0x41, 0x7f, 0x40, 0x00] # 6c l 81 | ,[0x00, 0x7c, 0x04, 0x18, 0x04, 0x78] # 6d m 82 | ,[0x00, 0x7c, 0x08, 0x04, 0x04, 0x78] # 6e n 83 | ,[0x00, 0x38, 0x44, 0x44, 0x44, 0x38] # 6f o 84 | ,[0x00, 0x7c, 0x14, 0x14, 0x14, 0x08] # 70 p 85 | ,[0x00, 0x08, 0x14, 0x14, 0x18, 0x7c] # 71 q 86 | ,[0x00, 0x7c, 0x08, 0x04, 0x04, 0x08] # 72 r 87 | ,[0x00, 0x48, 0x54, 0x54, 0x54, 0x20] # 73 s 88 | ,[0x00, 0x04, 0x3f, 0x44, 0x40, 0x20] # 74 t 89 | ,[0x00, 0x3c, 0x40, 0x40, 0x20, 0x7c] # 75 u 90 | ,[0x00, 0x1c, 0x20, 0x40, 0x20, 0x1c] # 76 v 91 | ,[0x00, 0x3c, 0x40, 0x30, 0x40, 0x3c] # 77 w 92 | ,[0x00, 0x44, 0x28, 0x10, 0x28, 0x44] # 78 x 93 | ,[0x00, 0x0c, 0x50, 0x50, 0x50, 0x3c] # 79 y 94 | ,[0x00, 0x44, 0x64, 0x54, 0x4c, 0x44] # 7a z 95 | ,[0x00, 0x00, 0x08, 0x36, 0x41, 0x00] # 7b [ 96 | ,[0x00, 0x00, 0x00, 0x7f, 0x00, 0x00] # 7c | 97 | ,[0x00, 0x00, 0x41, 0x36, 0x08, 0x00] # 7d ] 98 | ,[0x00, 0x10, 0x08, 0x08, 0x10, 0x08] # 7e ~ 99 | ,[0x00, 0x78, 0x46, 0x41, 0x46, 0x78] # 7f (delete) 100 | ] 101 | 102 | def get_font6_8(self, data): 103 | return self.FONTTYPE6_8[bytearray(data)[0] - 0x20] 104 | 105 | -------------------------------------------------------------------------------- /TPYBoard-v70x-master/01.LCD5110显示环境信息/main.py: -------------------------------------------------------------------------------- 1 | # main.py -- put your code here! 2 | #main.py 3 | import pyb 4 | import upcd8544 5 | from machine import SPI,Pin 6 | from pyb import UART 7 | from sht20 import SHT20 8 | 9 | 10 | ds = SHT20(1) 11 | SPI = pyb.SPI(1) #DIN=>X8-MOSI/CLK=>X6-SCK 12 | #DIN =>SPI(1).MOSI 'X8' data flow (Master out, Slave in) 13 | #CLK =>SPI(1).SCK 'X6' SPI clock 14 | RST = pyb.Pin('X20') 15 | CE = pyb.Pin('X19') 16 | DC = pyb.Pin('X18') 17 | LIGHT = pyb.Pin('X17') 18 | lcd_5110 = upcd8544.PCD8544(SPI, RST, CE, DC, LIGHT) 19 | N2 = Pin('Y3', Pin.OUT_PP) 20 | N1 = Pin('Y6', Pin.OUT_PP) 21 | N1.low() 22 | pyb.delay(2000) 23 | N1.high() 24 | while True: 25 | ads = pyb.ADC(Pin('Y12')) 26 | a=ads.read() 27 | a=a/100 28 | a=33-a 29 | print("a=",a) 30 | H=ds.TEMP() 31 | S=ds.TEMP1() 32 | H=125*H/256-6 33 | S=175.72*S/256-46.85 34 | if(a<17): 35 | N2.high() 36 | lcd_5110.lcd_write_string('WENDU:',0,0) 37 | lcd_5110.lcd_write_string(str(S),0,1) 38 | lcd_5110.lcd_write_string('SHIDU:',0,2) 39 | lcd_5110.lcd_write_string(str(H),0,3) 40 | lcd_5110.lcd_write_string('LIANGDU:',0,4) 41 | lcd_5110.lcd_write_string(str(a),0,5) 42 | N2.low() -------------------------------------------------------------------------------- /TPYBoard-v70x-master/02.LCD5110显示当前经纬度/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TPYBoard/developmentBoard/535a975480a6755394cedfe3708a05952d9b6539/TPYBoard-v70x-master/02.LCD5110显示当前经纬度/README.md -------------------------------------------------------------------------------- /TPYBoard-v70x-master/02.LCD5110显示当前经纬度/font.py: -------------------------------------------------------------------------------- 1 | class FONT6_8: 2 | """docstring for FONT6_8""" 3 | FONTTYPE6_8 = [ 4 | [0x00, 0x00, 0x00, 0x00, 0x00, 0x00] # 20 5 | ,[0x00, 0x00, 0x00, 0x5f, 0x00, 0x00] # 21 ! 6 | ,[0x00, 0x00, 0x07, 0x00, 0x07, 0x00] # 22 " 7 | ,[0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14] # 23 # 8 | ,[0x00, 0x24, 0x2a, 0x7f, 0x2a, 0x12] # 24 $ 9 | ,[0x00, 0x23, 0x13, 0x08, 0x64, 0x62] # 25 % 10 | ,[0x00, 0x36, 0x49, 0x55, 0x22, 0x50] # 26 & 11 | ,[0x00, 0x00, 0x05, 0x03, 0x00, 0x00] # 27 ' 12 | ,[0x00, 0x00, 0x1c, 0x22, 0x41, 0x00] # 28 ( 13 | ,[0x00, 0x00, 0x41, 0x22, 0x1c, 0x00] # 29 ) 14 | ,[0x00, 0x14, 0x08, 0x3e, 0x08, 0x14] # 2a * 15 | ,[0x00, 0x08, 0x08, 0x3e, 0x08, 0x08] # 2b + 16 | ,[0x00, 0x00, 0x50, 0x30, 0x00, 0x00] # 2c , 17 | ,[0x00, 0x08, 0x08, 0x08, 0x08, 0x08] # 2d - 18 | ,[0x00, 0x00, 0x60, 0x60, 0x00, 0x00] # 2e . 19 | ,[0x00, 0x20, 0x10, 0x08, 0x04, 0x02] # 2f / 20 | ,[0x00, 0x3e, 0x51, 0x49, 0x45, 0x3e] # 30 0 21 | ,[0x00, 0x00, 0x42, 0x7f, 0x40, 0x00] # 31 1 22 | ,[0x00, 0x42, 0x61, 0x51, 0x49, 0x46] # 32 2 23 | ,[0x00, 0x21, 0x41, 0x45, 0x4b, 0x31] # 33 3 24 | ,[0x00, 0x18, 0x14, 0x12, 0x7f, 0x10] # 34 4 25 | ,[0x00, 0x27, 0x45, 0x45, 0x45, 0x39] # 35 5 26 | ,[0x00, 0x3c, 0x4a, 0x49, 0x49, 0x30] # 36 6 27 | ,[0x00, 0x01, 0x71, 0x09, 0x05, 0x03] # 37 7 28 | ,[0x00, 0x36, 0x49, 0x49, 0x49, 0x36] # 38 8 29 | ,[0x00, 0x06, 0x49, 0x49, 0x29, 0x1e] # 39 9 30 | ,[0x00, 0x00, 0x36, 0x36, 0x00, 0x00] # 3a : 31 | ,[0x00, 0x00, 0x56, 0x36, 0x00, 0x00] # 3b ; 32 | ,[0x00, 0x08, 0x14, 0x22, 0x41, 0x00] # 3c < 33 | ,[0x00, 0x14, 0x14, 0x14, 0x14, 0x14] # 3d = 34 | ,[0x00, 0x00, 0x41, 0x22, 0x14, 0x08] # 3e > 35 | ,[0x00, 0x02, 0x01, 0x51, 0x09, 0x06] # 3f ? 36 | ,[0x00, 0x32, 0x49, 0x79, 0x41, 0x3e] # 40 @ 37 | ,[0x00, 0x7e, 0x11, 0x11, 0x11, 0x7e] # 41 A 38 | ,[0x00, 0x7f, 0x49, 0x49, 0x49, 0x36] # 42 B 39 | ,[0x00, 0x3e, 0x41, 0x41, 0x41, 0x22] # 43 C 40 | ,[0x00, 0x7f, 0x41, 0x41, 0x22, 0x1c] # 44 D 41 | ,[0x00, 0x7f, 0x49, 0x49, 0x49, 0x41] # 45 E 42 | ,[0x00, 0x7f, 0x09, 0x09, 0x09, 0x01] # 46 F 43 | ,[0x00, 0x3e, 0x41, 0x49, 0x49, 0x7a] # 47 G 44 | ,[0x00, 0x7f, 0x08, 0x08, 0x08, 0x7f] # 48 H 45 | ,[0x00, 0x00, 0x41, 0x7f, 0x41, 0x00] # 49 I 46 | ,[0x00, 0x20, 0x40, 0x41, 0x3f, 0x01] # 4a J 47 | ,[0x00, 0x7f, 0x08, 0x14, 0x22, 0x41] # 4b K 48 | ,[0x00, 0x7f, 0x40, 0x40, 0x40, 0x40] # 4c L 49 | ,[0x00, 0x7f, 0x02, 0x0c, 0x02, 0x7f] # 4d M 50 | ,[0x00, 0x7f, 0x04, 0x08, 0x10, 0x7f] # 4e N 51 | ,[0x00, 0x3e, 0x41, 0x41, 0x41, 0x3e] # 4f O 52 | ,[0x00, 0x7f, 0x09, 0x09, 0x09, 0x06] # 50 P 53 | ,[0x00, 0x3e, 0x41, 0x51, 0x21, 0x5e] # 51 Q 54 | ,[0x00, 0x7f, 0x09, 0x19, 0x29, 0x46] # 52 R 55 | ,[0x00, 0x46, 0x49, 0x49, 0x49, 0x31] # 53 S 56 | ,[0x00, 0x01, 0x01, 0x7f, 0x01, 0x01] # 54 T 57 | ,[0x00, 0x3f, 0x40, 0x40, 0x40, 0x3f] # 55 U 58 | ,[0x00, 0x1f, 0x20, 0x40, 0x20, 0x1f] # 56 V 59 | ,[0x00, 0x3f, 0x40, 0x38, 0x40, 0x3f] # 57 W 60 | ,[0x00, 0x63, 0x14, 0x08, 0x14, 0x63] # 58 X 61 | ,[0x00, 0x07, 0x08, 0x70, 0x08, 0x07] # 59 Y 62 | ,[0x00, 0x61, 0x51, 0x49, 0x45, 0x43] # 5a Z 63 | ,[0x00, 0x00, 0x7f, 0x41, 0x41, 0x00] # 5b [ 64 | ,[0x00, 0x02, 0x04, 0x08, 0x10, 0x20] # 5c \ # 65 | ,[0x00, 0x00, 0x41, 0x41, 0x7f, 0x00] # 5d ] 66 | ,[0x00, 0x04, 0x02, 0x01, 0x02, 0x04] # 5e ^ 67 | ,[0x00, 0x40, 0x40, 0x40, 0x40, 0x40] # 5f _ 68 | ,[0x00, 0x00, 0x01, 0x02, 0x04, 0x00] # 60 ` 69 | ,[0x00, 0x20, 0x54, 0x54, 0x54, 0x78] # 61 a 70 | ,[0x00, 0x7f, 0x48, 0x44, 0x44, 0x38] # 62 b 71 | ,[0x00, 0x38, 0x44, 0x44, 0x44, 0x20] # 63 c 72 | ,[0x00, 0x38, 0x44, 0x44, 0x48, 0x7f] # 64 d 73 | ,[0x00, 0x38, 0x54, 0x54, 0x54, 0x18] # 65 e 74 | ,[0x00, 0x08, 0x7e, 0x09, 0x01, 0x02] # 66 f 75 | ,[0x00, 0x0c, 0x52, 0x52, 0x52, 0x3e] # 67 g 76 | ,[0x00, 0x7f, 0x08, 0x04, 0x04, 0x78] # 68 h 77 | ,[0x00, 0x00, 0x44, 0x7d, 0x40, 0x00] # 69 i 78 | ,[0x00, 0x20, 0x40, 0x44, 0x3d, 0x00] # 6a j 79 | ,[0x00, 0x7f, 0x10, 0x28, 0x44, 0x00] # 6b k 80 | ,[0x00, 0x00, 0x41, 0x7f, 0x40, 0x00] # 6c l 81 | ,[0x00, 0x7c, 0x04, 0x18, 0x04, 0x78] # 6d m 82 | ,[0x00, 0x7c, 0x08, 0x04, 0x04, 0x78] # 6e n 83 | ,[0x00, 0x38, 0x44, 0x44, 0x44, 0x38] # 6f o 84 | ,[0x00, 0x7c, 0x14, 0x14, 0x14, 0x08] # 70 p 85 | ,[0x00, 0x08, 0x14, 0x14, 0x18, 0x7c] # 71 q 86 | ,[0x00, 0x7c, 0x08, 0x04, 0x04, 0x08] # 72 r 87 | ,[0x00, 0x48, 0x54, 0x54, 0x54, 0x20] # 73 s 88 | ,[0x00, 0x04, 0x3f, 0x44, 0x40, 0x20] # 74 t 89 | ,[0x00, 0x3c, 0x40, 0x40, 0x20, 0x7c] # 75 u 90 | ,[0x00, 0x1c, 0x20, 0x40, 0x20, 0x1c] # 76 v 91 | ,[0x00, 0x3c, 0x40, 0x30, 0x40, 0x3c] # 77 w 92 | ,[0x00, 0x44, 0x28, 0x10, 0x28, 0x44] # 78 x 93 | ,[0x00, 0x0c, 0x50, 0x50, 0x50, 0x3c] # 79 y 94 | ,[0x00, 0x44, 0x64, 0x54, 0x4c, 0x44] # 7a z 95 | ,[0x00, 0x00, 0x08, 0x36, 0x41, 0x00] # 7b [ 96 | ,[0x00, 0x00, 0x00, 0x7f, 0x00, 0x00] # 7c | 97 | ,[0x00, 0x00, 0x41, 0x36, 0x08, 0x00] # 7d ] 98 | ,[0x00, 0x10, 0x08, 0x08, 0x10, 0x08] # 7e ~ 99 | ,[0x00, 0x78, 0x46, 0x41, 0x46, 0x78] # 7f (delete) 100 | ] 101 | 102 | def get_font6_8(self, data): 103 | return self.FONTTYPE6_8[bytearray(data)[0] - 0x20] 104 | 105 | -------------------------------------------------------------------------------- /TPYBoard-v70x-master/02.LCD5110显示当前经纬度/main.py: -------------------------------------------------------------------------------- 1 | import pyb 2 | import upcd8544 3 | from machine import SPI,Pin 4 | from pyb import UART 5 | 6 | leds = [pyb.LED(i) for i in range(1,5)] 7 | SPI = pyb.SPI(1) #DIN=>X8-MOSI/CLK=>X6-SCK 8 | #DIN =>SPI(1).MOSI 'X8' data flow (Master out, Slave in) 9 | #CLK =>SPI(1).SCK 'X6' SPI clock 10 | RST = pyb.Pin('X20') 11 | CE = pyb.Pin('X19') 12 | DC = pyb.Pin('X18') 13 | LIGHT = pyb.Pin('X17') 14 | lcd_5110 = upcd8544.PCD8544(SPI, RST, CE, DC, LIGHT) 15 | N2 = Pin('Y3', Pin.OUT_PP) 16 | N1 = Pin('Y6', Pin.OUT_PP) 17 | N1.low() 18 | pyb.delay(2000) 19 | N1.high() 20 | pyb.delay(10000) 21 | u2 = UART(4, 115200,timeout=100) 22 | 23 | def DataConver(str_,flag): 24 | wei_=float(str_)/100 25 | wei_arr=str(wei_).split('.') 26 | val_=100000 27 | if flag==0:#纬度 28 | val_=10000 29 | wei_arr[1]=str(float(wei_arr[1])/60*val_).replace('.','') 30 | weidu=wei_arr[0]+'.'+wei_arr[1] 31 | return weidu 32 | while True: 33 | pyb.LED(2).on() 34 | u2.write('AT+GPSLOC=1\r\n') 35 | pyb.delay(3000) 36 | _dataRead=u2.read() 37 | print('搜星=',_dataRead) 38 | pyb.delay(1000) 39 | u2.write('AT+GPSLOC=0\r\n') 40 | pyb.delay(200) 41 | print('BEIDOU') 42 | _dataRead=u2.read() 43 | if _dataRead!=None: 44 | print('原始数据=',_dataRead) 45 | print('原始数据长度:',len(_dataRead)) 46 | if 604: 52 | #*******************纬度计算******************** 53 | weidu=_dataRead1[1] 54 | WD=DataConver(weidu,0) 55 | #*******************经度计算******************** 56 | jingdu=_dataRead1[2] 57 | JD=DataConver(jingdu,1) 58 | if jingdu.find('0.0000')<0: 59 | N2.high() 60 | #***********************时间************************ 61 | lcd_5110.lcd_write_string('JINGDU:',0,0) 62 | lcd_5110.lcd_write_string(str(JD),0,1) 63 | lcd_5110.lcd_write_string('WEIDU:',0,2) 64 | lcd_5110.lcd_write_string(str(WD),0,3) -------------------------------------------------------------------------------- /TPYBoard-v70x-master/03.GPRS功能测试/font.py: -------------------------------------------------------------------------------- 1 | class FONT6_8: 2 | """docstring for FONT6_8""" 3 | FONTTYPE6_8 = [ 4 | [0x00, 0x00, 0x00, 0x00, 0x00, 0x00] # 20 5 | ,[0x00, 0x00, 0x00, 0x5f, 0x00, 0x00] # 21 ! 6 | ,[0x00, 0x00, 0x07, 0x00, 0x07, 0x00] # 22 " 7 | ,[0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14] # 23 # 8 | ,[0x00, 0x24, 0x2a, 0x7f, 0x2a, 0x12] # 24 $ 9 | ,[0x00, 0x23, 0x13, 0x08, 0x64, 0x62] # 25 % 10 | ,[0x00, 0x36, 0x49, 0x55, 0x22, 0x50] # 26 & 11 | ,[0x00, 0x00, 0x05, 0x03, 0x00, 0x00] # 27 ' 12 | ,[0x00, 0x00, 0x1c, 0x22, 0x41, 0x00] # 28 ( 13 | ,[0x00, 0x00, 0x41, 0x22, 0x1c, 0x00] # 29 ) 14 | ,[0x00, 0x14, 0x08, 0x3e, 0x08, 0x14] # 2a * 15 | ,[0x00, 0x08, 0x08, 0x3e, 0x08, 0x08] # 2b + 16 | ,[0x00, 0x00, 0x50, 0x30, 0x00, 0x00] # 2c , 17 | ,[0x00, 0x08, 0x08, 0x08, 0x08, 0x08] # 2d - 18 | ,[0x00, 0x00, 0x60, 0x60, 0x00, 0x00] # 2e . 19 | ,[0x00, 0x20, 0x10, 0x08, 0x04, 0x02] # 2f / 20 | ,[0x00, 0x3e, 0x51, 0x49, 0x45, 0x3e] # 30 0 21 | ,[0x00, 0x00, 0x42, 0x7f, 0x40, 0x00] # 31 1 22 | ,[0x00, 0x42, 0x61, 0x51, 0x49, 0x46] # 32 2 23 | ,[0x00, 0x21, 0x41, 0x45, 0x4b, 0x31] # 33 3 24 | ,[0x00, 0x18, 0x14, 0x12, 0x7f, 0x10] # 34 4 25 | ,[0x00, 0x27, 0x45, 0x45, 0x45, 0x39] # 35 5 26 | ,[0x00, 0x3c, 0x4a, 0x49, 0x49, 0x30] # 36 6 27 | ,[0x00, 0x01, 0x71, 0x09, 0x05, 0x03] # 37 7 28 | ,[0x00, 0x36, 0x49, 0x49, 0x49, 0x36] # 38 8 29 | ,[0x00, 0x06, 0x49, 0x49, 0x29, 0x1e] # 39 9 30 | ,[0x00, 0x00, 0x36, 0x36, 0x00, 0x00] # 3a : 31 | ,[0x00, 0x00, 0x56, 0x36, 0x00, 0x00] # 3b ; 32 | ,[0x00, 0x08, 0x14, 0x22, 0x41, 0x00] # 3c < 33 | ,[0x00, 0x14, 0x14, 0x14, 0x14, 0x14] # 3d = 34 | ,[0x00, 0x00, 0x41, 0x22, 0x14, 0x08] # 3e > 35 | ,[0x00, 0x02, 0x01, 0x51, 0x09, 0x06] # 3f ? 36 | ,[0x00, 0x32, 0x49, 0x79, 0x41, 0x3e] # 40 @ 37 | ,[0x00, 0x7e, 0x11, 0x11, 0x11, 0x7e] # 41 A 38 | ,[0x00, 0x7f, 0x49, 0x49, 0x49, 0x36] # 42 B 39 | ,[0x00, 0x3e, 0x41, 0x41, 0x41, 0x22] # 43 C 40 | ,[0x00, 0x7f, 0x41, 0x41, 0x22, 0x1c] # 44 D 41 | ,[0x00, 0x7f, 0x49, 0x49, 0x49, 0x41] # 45 E 42 | ,[0x00, 0x7f, 0x09, 0x09, 0x09, 0x01] # 46 F 43 | ,[0x00, 0x3e, 0x41, 0x49, 0x49, 0x7a] # 47 G 44 | ,[0x00, 0x7f, 0x08, 0x08, 0x08, 0x7f] # 48 H 45 | ,[0x00, 0x00, 0x41, 0x7f, 0x41, 0x00] # 49 I 46 | ,[0x00, 0x20, 0x40, 0x41, 0x3f, 0x01] # 4a J 47 | ,[0x00, 0x7f, 0x08, 0x14, 0x22, 0x41] # 4b K 48 | ,[0x00, 0x7f, 0x40, 0x40, 0x40, 0x40] # 4c L 49 | ,[0x00, 0x7f, 0x02, 0x0c, 0x02, 0x7f] # 4d M 50 | ,[0x00, 0x7f, 0x04, 0x08, 0x10, 0x7f] # 4e N 51 | ,[0x00, 0x3e, 0x41, 0x41, 0x41, 0x3e] # 4f O 52 | ,[0x00, 0x7f, 0x09, 0x09, 0x09, 0x06] # 50 P 53 | ,[0x00, 0x3e, 0x41, 0x51, 0x21, 0x5e] # 51 Q 54 | ,[0x00, 0x7f, 0x09, 0x19, 0x29, 0x46] # 52 R 55 | ,[0x00, 0x46, 0x49, 0x49, 0x49, 0x31] # 53 S 56 | ,[0x00, 0x01, 0x01, 0x7f, 0x01, 0x01] # 54 T 57 | ,[0x00, 0x3f, 0x40, 0x40, 0x40, 0x3f] # 55 U 58 | ,[0x00, 0x1f, 0x20, 0x40, 0x20, 0x1f] # 56 V 59 | ,[0x00, 0x3f, 0x40, 0x38, 0x40, 0x3f] # 57 W 60 | ,[0x00, 0x63, 0x14, 0x08, 0x14, 0x63] # 58 X 61 | ,[0x00, 0x07, 0x08, 0x70, 0x08, 0x07] # 59 Y 62 | ,[0x00, 0x61, 0x51, 0x49, 0x45, 0x43] # 5a Z 63 | ,[0x00, 0x00, 0x7f, 0x41, 0x41, 0x00] # 5b [ 64 | ,[0x00, 0x02, 0x04, 0x08, 0x10, 0x20] # 5c \ # 65 | ,[0x00, 0x00, 0x41, 0x41, 0x7f, 0x00] # 5d ] 66 | ,[0x00, 0x04, 0x02, 0x01, 0x02, 0x04] # 5e ^ 67 | ,[0x00, 0x40, 0x40, 0x40, 0x40, 0x40] # 5f _ 68 | ,[0x00, 0x00, 0x01, 0x02, 0x04, 0x00] # 60 ` 69 | ,[0x00, 0x20, 0x54, 0x54, 0x54, 0x78] # 61 a 70 | ,[0x00, 0x7f, 0x48, 0x44, 0x44, 0x38] # 62 b 71 | ,[0x00, 0x38, 0x44, 0x44, 0x44, 0x20] # 63 c 72 | ,[0x00, 0x38, 0x44, 0x44, 0x48, 0x7f] # 64 d 73 | ,[0x00, 0x38, 0x54, 0x54, 0x54, 0x18] # 65 e 74 | ,[0x00, 0x08, 0x7e, 0x09, 0x01, 0x02] # 66 f 75 | ,[0x00, 0x0c, 0x52, 0x52, 0x52, 0x3e] # 67 g 76 | ,[0x00, 0x7f, 0x08, 0x04, 0x04, 0x78] # 68 h 77 | ,[0x00, 0x00, 0x44, 0x7d, 0x40, 0x00] # 69 i 78 | ,[0x00, 0x20, 0x40, 0x44, 0x3d, 0x00] # 6a j 79 | ,[0x00, 0x7f, 0x10, 0x28, 0x44, 0x00] # 6b k 80 | ,[0x00, 0x00, 0x41, 0x7f, 0x40, 0x00] # 6c l 81 | ,[0x00, 0x7c, 0x04, 0x18, 0x04, 0x78] # 6d m 82 | ,[0x00, 0x7c, 0x08, 0x04, 0x04, 0x78] # 6e n 83 | ,[0x00, 0x38, 0x44, 0x44, 0x44, 0x38] # 6f o 84 | ,[0x00, 0x7c, 0x14, 0x14, 0x14, 0x08] # 70 p 85 | ,[0x00, 0x08, 0x14, 0x14, 0x18, 0x7c] # 71 q 86 | ,[0x00, 0x7c, 0x08, 0x04, 0x04, 0x08] # 72 r 87 | ,[0x00, 0x48, 0x54, 0x54, 0x54, 0x20] # 73 s 88 | ,[0x00, 0x04, 0x3f, 0x44, 0x40, 0x20] # 74 t 89 | ,[0x00, 0x3c, 0x40, 0x40, 0x20, 0x7c] # 75 u 90 | ,[0x00, 0x1c, 0x20, 0x40, 0x20, 0x1c] # 76 v 91 | ,[0x00, 0x3c, 0x40, 0x30, 0x40, 0x3c] # 77 w 92 | ,[0x00, 0x44, 0x28, 0x10, 0x28, 0x44] # 78 x 93 | ,[0x00, 0x0c, 0x50, 0x50, 0x50, 0x3c] # 79 y 94 | ,[0x00, 0x44, 0x64, 0x54, 0x4c, 0x44] # 7a z 95 | ,[0x00, 0x00, 0x08, 0x36, 0x41, 0x00] # 7b [ 96 | ,[0x00, 0x00, 0x00, 0x7f, 0x00, 0x00] # 7c | 97 | ,[0x00, 0x00, 0x41, 0x36, 0x08, 0x00] # 7d ] 98 | ,[0x00, 0x10, 0x08, 0x08, 0x10, 0x08] # 7e ~ 99 | ,[0x00, 0x78, 0x46, 0x41, 0x46, 0x78] # 7f (delete) 100 | ] 101 | 102 | def get_font6_8(self, data): 103 | return self.FONTTYPE6_8[bytearray(data)[0] - 0x20] 104 | 105 | -------------------------------------------------------------------------------- /TPYBoard-v70x-master/03.GPRS功能测试/main.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TPYBoard/developmentBoard/535a975480a6755394cedfe3708a05952d9b6539/TPYBoard-v70x-master/03.GPRS功能测试/main.py -------------------------------------------------------------------------------- /TPYBoard-v70x-master/04.短信功能/单条发送/font.py: -------------------------------------------------------------------------------- 1 | class FONT6_8: 2 | """docstring for FONT6_8""" 3 | FONTTYPE6_8 = [ 4 | [0x00, 0x00, 0x00, 0x00, 0x00, 0x00] # 20 5 | ,[0x00, 0x00, 0x00, 0x5f, 0x00, 0x00] # 21 ! 6 | ,[0x00, 0x00, 0x07, 0x00, 0x07, 0x00] # 22 " 7 | ,[0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14] # 23 # 8 | ,[0x00, 0x24, 0x2a, 0x7f, 0x2a, 0x12] # 24 $ 9 | ,[0x00, 0x23, 0x13, 0x08, 0x64, 0x62] # 25 % 10 | ,[0x00, 0x36, 0x49, 0x55, 0x22, 0x50] # 26 & 11 | ,[0x00, 0x00, 0x05, 0x03, 0x00, 0x00] # 27 ' 12 | ,[0x00, 0x00, 0x1c, 0x22, 0x41, 0x00] # 28 ( 13 | ,[0x00, 0x00, 0x41, 0x22, 0x1c, 0x00] # 29 ) 14 | ,[0x00, 0x14, 0x08, 0x3e, 0x08, 0x14] # 2a * 15 | ,[0x00, 0x08, 0x08, 0x3e, 0x08, 0x08] # 2b + 16 | ,[0x00, 0x00, 0x50, 0x30, 0x00, 0x00] # 2c , 17 | ,[0x00, 0x08, 0x08, 0x08, 0x08, 0x08] # 2d - 18 | ,[0x00, 0x00, 0x60, 0x60, 0x00, 0x00] # 2e . 19 | ,[0x00, 0x20, 0x10, 0x08, 0x04, 0x02] # 2f / 20 | ,[0x00, 0x3e, 0x51, 0x49, 0x45, 0x3e] # 30 0 21 | ,[0x00, 0x00, 0x42, 0x7f, 0x40, 0x00] # 31 1 22 | ,[0x00, 0x42, 0x61, 0x51, 0x49, 0x46] # 32 2 23 | ,[0x00, 0x21, 0x41, 0x45, 0x4b, 0x31] # 33 3 24 | ,[0x00, 0x18, 0x14, 0x12, 0x7f, 0x10] # 34 4 25 | ,[0x00, 0x27, 0x45, 0x45, 0x45, 0x39] # 35 5 26 | ,[0x00, 0x3c, 0x4a, 0x49, 0x49, 0x30] # 36 6 27 | ,[0x00, 0x01, 0x71, 0x09, 0x05, 0x03] # 37 7 28 | ,[0x00, 0x36, 0x49, 0x49, 0x49, 0x36] # 38 8 29 | ,[0x00, 0x06, 0x49, 0x49, 0x29, 0x1e] # 39 9 30 | ,[0x00, 0x00, 0x36, 0x36, 0x00, 0x00] # 3a : 31 | ,[0x00, 0x00, 0x56, 0x36, 0x00, 0x00] # 3b ; 32 | ,[0x00, 0x08, 0x14, 0x22, 0x41, 0x00] # 3c < 33 | ,[0x00, 0x14, 0x14, 0x14, 0x14, 0x14] # 3d = 34 | ,[0x00, 0x00, 0x41, 0x22, 0x14, 0x08] # 3e > 35 | ,[0x00, 0x02, 0x01, 0x51, 0x09, 0x06] # 3f ? 36 | ,[0x00, 0x32, 0x49, 0x79, 0x41, 0x3e] # 40 @ 37 | ,[0x00, 0x7e, 0x11, 0x11, 0x11, 0x7e] # 41 A 38 | ,[0x00, 0x7f, 0x49, 0x49, 0x49, 0x36] # 42 B 39 | ,[0x00, 0x3e, 0x41, 0x41, 0x41, 0x22] # 43 C 40 | ,[0x00, 0x7f, 0x41, 0x41, 0x22, 0x1c] # 44 D 41 | ,[0x00, 0x7f, 0x49, 0x49, 0x49, 0x41] # 45 E 42 | ,[0x00, 0x7f, 0x09, 0x09, 0x09, 0x01] # 46 F 43 | ,[0x00, 0x3e, 0x41, 0x49, 0x49, 0x7a] # 47 G 44 | ,[0x00, 0x7f, 0x08, 0x08, 0x08, 0x7f] # 48 H 45 | ,[0x00, 0x00, 0x41, 0x7f, 0x41, 0x00] # 49 I 46 | ,[0x00, 0x20, 0x40, 0x41, 0x3f, 0x01] # 4a J 47 | ,[0x00, 0x7f, 0x08, 0x14, 0x22, 0x41] # 4b K 48 | ,[0x00, 0x7f, 0x40, 0x40, 0x40, 0x40] # 4c L 49 | ,[0x00, 0x7f, 0x02, 0x0c, 0x02, 0x7f] # 4d M 50 | ,[0x00, 0x7f, 0x04, 0x08, 0x10, 0x7f] # 4e N 51 | ,[0x00, 0x3e, 0x41, 0x41, 0x41, 0x3e] # 4f O 52 | ,[0x00, 0x7f, 0x09, 0x09, 0x09, 0x06] # 50 P 53 | ,[0x00, 0x3e, 0x41, 0x51, 0x21, 0x5e] # 51 Q 54 | ,[0x00, 0x7f, 0x09, 0x19, 0x29, 0x46] # 52 R 55 | ,[0x00, 0x46, 0x49, 0x49, 0x49, 0x31] # 53 S 56 | ,[0x00, 0x01, 0x01, 0x7f, 0x01, 0x01] # 54 T 57 | ,[0x00, 0x3f, 0x40, 0x40, 0x40, 0x3f] # 55 U 58 | ,[0x00, 0x1f, 0x20, 0x40, 0x20, 0x1f] # 56 V 59 | ,[0x00, 0x3f, 0x40, 0x38, 0x40, 0x3f] # 57 W 60 | ,[0x00, 0x63, 0x14, 0x08, 0x14, 0x63] # 58 X 61 | ,[0x00, 0x07, 0x08, 0x70, 0x08, 0x07] # 59 Y 62 | ,[0x00, 0x61, 0x51, 0x49, 0x45, 0x43] # 5a Z 63 | ,[0x00, 0x00, 0x7f, 0x41, 0x41, 0x00] # 5b [ 64 | ,[0x00, 0x02, 0x04, 0x08, 0x10, 0x20] # 5c \ # 65 | ,[0x00, 0x00, 0x41, 0x41, 0x7f, 0x00] # 5d ] 66 | ,[0x00, 0x04, 0x02, 0x01, 0x02, 0x04] # 5e ^ 67 | ,[0x00, 0x40, 0x40, 0x40, 0x40, 0x40] # 5f _ 68 | ,[0x00, 0x00, 0x01, 0x02, 0x04, 0x00] # 60 ` 69 | ,[0x00, 0x20, 0x54, 0x54, 0x54, 0x78] # 61 a 70 | ,[0x00, 0x7f, 0x48, 0x44, 0x44, 0x38] # 62 b 71 | ,[0x00, 0x38, 0x44, 0x44, 0x44, 0x20] # 63 c 72 | ,[0x00, 0x38, 0x44, 0x44, 0x48, 0x7f] # 64 d 73 | ,[0x00, 0x38, 0x54, 0x54, 0x54, 0x18] # 65 e 74 | ,[0x00, 0x08, 0x7e, 0x09, 0x01, 0x02] # 66 f 75 | ,[0x00, 0x0c, 0x52, 0x52, 0x52, 0x3e] # 67 g 76 | ,[0x00, 0x7f, 0x08, 0x04, 0x04, 0x78] # 68 h 77 | ,[0x00, 0x00, 0x44, 0x7d, 0x40, 0x00] # 69 i 78 | ,[0x00, 0x20, 0x40, 0x44, 0x3d, 0x00] # 6a j 79 | ,[0x00, 0x7f, 0x10, 0x28, 0x44, 0x00] # 6b k 80 | ,[0x00, 0x00, 0x41, 0x7f, 0x40, 0x00] # 6c l 81 | ,[0x00, 0x7c, 0x04, 0x18, 0x04, 0x78] # 6d m 82 | ,[0x00, 0x7c, 0x08, 0x04, 0x04, 0x78] # 6e n 83 | ,[0x00, 0x38, 0x44, 0x44, 0x44, 0x38] # 6f o 84 | ,[0x00, 0x7c, 0x14, 0x14, 0x14, 0x08] # 70 p 85 | ,[0x00, 0x08, 0x14, 0x14, 0x18, 0x7c] # 71 q 86 | ,[0x00, 0x7c, 0x08, 0x04, 0x04, 0x08] # 72 r 87 | ,[0x00, 0x48, 0x54, 0x54, 0x54, 0x20] # 73 s 88 | ,[0x00, 0x04, 0x3f, 0x44, 0x40, 0x20] # 74 t 89 | ,[0x00, 0x3c, 0x40, 0x40, 0x20, 0x7c] # 75 u 90 | ,[0x00, 0x1c, 0x20, 0x40, 0x20, 0x1c] # 76 v 91 | ,[0x00, 0x3c, 0x40, 0x30, 0x40, 0x3c] # 77 w 92 | ,[0x00, 0x44, 0x28, 0x10, 0x28, 0x44] # 78 x 93 | ,[0x00, 0x0c, 0x50, 0x50, 0x50, 0x3c] # 79 y 94 | ,[0x00, 0x44, 0x64, 0x54, 0x4c, 0x44] # 7a z 95 | ,[0x00, 0x00, 0x08, 0x36, 0x41, 0x00] # 7b [ 96 | ,[0x00, 0x00, 0x00, 0x7f, 0x00, 0x00] # 7c | 97 | ,[0x00, 0x00, 0x41, 0x36, 0x08, 0x00] # 7d ] 98 | ,[0x00, 0x10, 0x08, 0x08, 0x10, 0x08] # 7e ~ 99 | ,[0x00, 0x78, 0x46, 0x41, 0x46, 0x78] # 7f (delete) 100 | ] 101 | 102 | def get_font6_8(self, data): 103 | return self.FONTTYPE6_8[bytearray(data)[0] - 0x20] 104 | 105 | -------------------------------------------------------------------------------- /TPYBoard-v70x-master/04.短信功能/单条发送/main.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TPYBoard/developmentBoard/535a975480a6755394cedfe3708a05952d9b6539/TPYBoard-v70x-master/04.短信功能/单条发送/main.py -------------------------------------------------------------------------------- /TPYBoard-v70x-master/04.短信功能/短信群发机/font.py: -------------------------------------------------------------------------------- 1 | class FONT6_8: 2 | """docstring for FONT6_8""" 3 | FONTTYPE6_8 = [ 4 | [0x00, 0x00, 0x00, 0x00, 0x00, 0x00] # 20 5 | ,[0x00, 0x00, 0x00, 0x5f, 0x00, 0x00] # 21 ! 6 | ,[0x00, 0x00, 0x07, 0x00, 0x07, 0x00] # 22 " 7 | ,[0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14] # 23 # 8 | ,[0x00, 0x24, 0x2a, 0x7f, 0x2a, 0x12] # 24 $ 9 | ,[0x00, 0x23, 0x13, 0x08, 0x64, 0x62] # 25 % 10 | ,[0x00, 0x36, 0x49, 0x55, 0x22, 0x50] # 26 & 11 | ,[0x00, 0x00, 0x05, 0x03, 0x00, 0x00] # 27 ' 12 | ,[0x00, 0x00, 0x1c, 0x22, 0x41, 0x00] # 28 ( 13 | ,[0x00, 0x00, 0x41, 0x22, 0x1c, 0x00] # 29 ) 14 | ,[0x00, 0x14, 0x08, 0x3e, 0x08, 0x14] # 2a * 15 | ,[0x00, 0x08, 0x08, 0x3e, 0x08, 0x08] # 2b + 16 | ,[0x00, 0x00, 0x50, 0x30, 0x00, 0x00] # 2c , 17 | ,[0x00, 0x08, 0x08, 0x08, 0x08, 0x08] # 2d - 18 | ,[0x00, 0x00, 0x60, 0x60, 0x00, 0x00] # 2e . 19 | ,[0x00, 0x20, 0x10, 0x08, 0x04, 0x02] # 2f / 20 | ,[0x00, 0x3e, 0x51, 0x49, 0x45, 0x3e] # 30 0 21 | ,[0x00, 0x00, 0x42, 0x7f, 0x40, 0x00] # 31 1 22 | ,[0x00, 0x42, 0x61, 0x51, 0x49, 0x46] # 32 2 23 | ,[0x00, 0x21, 0x41, 0x45, 0x4b, 0x31] # 33 3 24 | ,[0x00, 0x18, 0x14, 0x12, 0x7f, 0x10] # 34 4 25 | ,[0x00, 0x27, 0x45, 0x45, 0x45, 0x39] # 35 5 26 | ,[0x00, 0x3c, 0x4a, 0x49, 0x49, 0x30] # 36 6 27 | ,[0x00, 0x01, 0x71, 0x09, 0x05, 0x03] # 37 7 28 | ,[0x00, 0x36, 0x49, 0x49, 0x49, 0x36] # 38 8 29 | ,[0x00, 0x06, 0x49, 0x49, 0x29, 0x1e] # 39 9 30 | ,[0x00, 0x00, 0x36, 0x36, 0x00, 0x00] # 3a : 31 | ,[0x00, 0x00, 0x56, 0x36, 0x00, 0x00] # 3b ; 32 | ,[0x00, 0x08, 0x14, 0x22, 0x41, 0x00] # 3c < 33 | ,[0x00, 0x14, 0x14, 0x14, 0x14, 0x14] # 3d = 34 | ,[0x00, 0x00, 0x41, 0x22, 0x14, 0x08] # 3e > 35 | ,[0x00, 0x02, 0x01, 0x51, 0x09, 0x06] # 3f ? 36 | ,[0x00, 0x32, 0x49, 0x79, 0x41, 0x3e] # 40 @ 37 | ,[0x00, 0x7e, 0x11, 0x11, 0x11, 0x7e] # 41 A 38 | ,[0x00, 0x7f, 0x49, 0x49, 0x49, 0x36] # 42 B 39 | ,[0x00, 0x3e, 0x41, 0x41, 0x41, 0x22] # 43 C 40 | ,[0x00, 0x7f, 0x41, 0x41, 0x22, 0x1c] # 44 D 41 | ,[0x00, 0x7f, 0x49, 0x49, 0x49, 0x41] # 45 E 42 | ,[0x00, 0x7f, 0x09, 0x09, 0x09, 0x01] # 46 F 43 | ,[0x00, 0x3e, 0x41, 0x49, 0x49, 0x7a] # 47 G 44 | ,[0x00, 0x7f, 0x08, 0x08, 0x08, 0x7f] # 48 H 45 | ,[0x00, 0x00, 0x41, 0x7f, 0x41, 0x00] # 49 I 46 | ,[0x00, 0x20, 0x40, 0x41, 0x3f, 0x01] # 4a J 47 | ,[0x00, 0x7f, 0x08, 0x14, 0x22, 0x41] # 4b K 48 | ,[0x00, 0x7f, 0x40, 0x40, 0x40, 0x40] # 4c L 49 | ,[0x00, 0x7f, 0x02, 0x0c, 0x02, 0x7f] # 4d M 50 | ,[0x00, 0x7f, 0x04, 0x08, 0x10, 0x7f] # 4e N 51 | ,[0x00, 0x3e, 0x41, 0x41, 0x41, 0x3e] # 4f O 52 | ,[0x00, 0x7f, 0x09, 0x09, 0x09, 0x06] # 50 P 53 | ,[0x00, 0x3e, 0x41, 0x51, 0x21, 0x5e] # 51 Q 54 | ,[0x00, 0x7f, 0x09, 0x19, 0x29, 0x46] # 52 R 55 | ,[0x00, 0x46, 0x49, 0x49, 0x49, 0x31] # 53 S 56 | ,[0x00, 0x01, 0x01, 0x7f, 0x01, 0x01] # 54 T 57 | ,[0x00, 0x3f, 0x40, 0x40, 0x40, 0x3f] # 55 U 58 | ,[0x00, 0x1f, 0x20, 0x40, 0x20, 0x1f] # 56 V 59 | ,[0x00, 0x3f, 0x40, 0x38, 0x40, 0x3f] # 57 W 60 | ,[0x00, 0x63, 0x14, 0x08, 0x14, 0x63] # 58 X 61 | ,[0x00, 0x07, 0x08, 0x70, 0x08, 0x07] # 59 Y 62 | ,[0x00, 0x61, 0x51, 0x49, 0x45, 0x43] # 5a Z 63 | ,[0x00, 0x00, 0x7f, 0x41, 0x41, 0x00] # 5b [ 64 | ,[0x00, 0x02, 0x04, 0x08, 0x10, 0x20] # 5c \ # 65 | ,[0x00, 0x00, 0x41, 0x41, 0x7f, 0x00] # 5d ] 66 | ,[0x00, 0x04, 0x02, 0x01, 0x02, 0x04] # 5e ^ 67 | ,[0x00, 0x40, 0x40, 0x40, 0x40, 0x40] # 5f _ 68 | ,[0x00, 0x00, 0x01, 0x02, 0x04, 0x00] # 60 ` 69 | ,[0x00, 0x20, 0x54, 0x54, 0x54, 0x78] # 61 a 70 | ,[0x00, 0x7f, 0x48, 0x44, 0x44, 0x38] # 62 b 71 | ,[0x00, 0x38, 0x44, 0x44, 0x44, 0x20] # 63 c 72 | ,[0x00, 0x38, 0x44, 0x44, 0x48, 0x7f] # 64 d 73 | ,[0x00, 0x38, 0x54, 0x54, 0x54, 0x18] # 65 e 74 | ,[0x00, 0x08, 0x7e, 0x09, 0x01, 0x02] # 66 f 75 | ,[0x00, 0x0c, 0x52, 0x52, 0x52, 0x3e] # 67 g 76 | ,[0x00, 0x7f, 0x08, 0x04, 0x04, 0x78] # 68 h 77 | ,[0x00, 0x00, 0x44, 0x7d, 0x40, 0x00] # 69 i 78 | ,[0x00, 0x20, 0x40, 0x44, 0x3d, 0x00] # 6a j 79 | ,[0x00, 0x7f, 0x10, 0x28, 0x44, 0x00] # 6b k 80 | ,[0x00, 0x00, 0x41, 0x7f, 0x40, 0x00] # 6c l 81 | ,[0x00, 0x7c, 0x04, 0x18, 0x04, 0x78] # 6d m 82 | ,[0x00, 0x7c, 0x08, 0x04, 0x04, 0x78] # 6e n 83 | ,[0x00, 0x38, 0x44, 0x44, 0x44, 0x38] # 6f o 84 | ,[0x00, 0x7c, 0x14, 0x14, 0x14, 0x08] # 70 p 85 | ,[0x00, 0x08, 0x14, 0x14, 0x18, 0x7c] # 71 q 86 | ,[0x00, 0x7c, 0x08, 0x04, 0x04, 0x08] # 72 r 87 | ,[0x00, 0x48, 0x54, 0x54, 0x54, 0x20] # 73 s 88 | ,[0x00, 0x04, 0x3f, 0x44, 0x40, 0x20] # 74 t 89 | ,[0x00, 0x3c, 0x40, 0x40, 0x20, 0x7c] # 75 u 90 | ,[0x00, 0x1c, 0x20, 0x40, 0x20, 0x1c] # 76 v 91 | ,[0x00, 0x3c, 0x40, 0x30, 0x40, 0x3c] # 77 w 92 | ,[0x00, 0x44, 0x28, 0x10, 0x28, 0x44] # 78 x 93 | ,[0x00, 0x0c, 0x50, 0x50, 0x50, 0x3c] # 79 y 94 | ,[0x00, 0x44, 0x64, 0x54, 0x4c, 0x44] # 7a z 95 | ,[0x00, 0x00, 0x08, 0x36, 0x41, 0x00] # 7b [ 96 | ,[0x00, 0x00, 0x00, 0x7f, 0x00, 0x00] # 7c | 97 | ,[0x00, 0x00, 0x41, 0x36, 0x08, 0x00] # 7d ] 98 | ,[0x00, 0x10, 0x08, 0x08, 0x10, 0x08] # 7e ~ 99 | ,[0x00, 0x78, 0x46, 0x41, 0x46, 0x78] # 7f (delete) 100 | ] 101 | 102 | def get_font6_8(self, data): 103 | return self.FONTTYPE6_8[bytearray(data)[0] - 0x20] 104 | 105 | -------------------------------------------------------------------------------- /TPYBoard-v70x-master/04.短信功能/短信群发机/main.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TPYBoard/developmentBoard/535a975480a6755394cedfe3708a05952d9b6539/TPYBoard-v70x-master/04.短信功能/短信群发机/main.py -------------------------------------------------------------------------------- /TPYBoard-v70x-master/05.来电显示功能/font.py: -------------------------------------------------------------------------------- 1 | class FONT6_8: 2 | """docstring for FONT6_8""" 3 | FONTTYPE6_8 = [ 4 | [0x00, 0x00, 0x00, 0x00, 0x00, 0x00] # 20 5 | ,[0x00, 0x00, 0x00, 0x5f, 0x00, 0x00] # 21 ! 6 | ,[0x00, 0x00, 0x07, 0x00, 0x07, 0x00] # 22 " 7 | ,[0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14] # 23 # 8 | ,[0x00, 0x24, 0x2a, 0x7f, 0x2a, 0x12] # 24 $ 9 | ,[0x00, 0x23, 0x13, 0x08, 0x64, 0x62] # 25 % 10 | ,[0x00, 0x36, 0x49, 0x55, 0x22, 0x50] # 26 & 11 | ,[0x00, 0x00, 0x05, 0x03, 0x00, 0x00] # 27 ' 12 | ,[0x00, 0x00, 0x1c, 0x22, 0x41, 0x00] # 28 ( 13 | ,[0x00, 0x00, 0x41, 0x22, 0x1c, 0x00] # 29 ) 14 | ,[0x00, 0x14, 0x08, 0x3e, 0x08, 0x14] # 2a * 15 | ,[0x00, 0x08, 0x08, 0x3e, 0x08, 0x08] # 2b + 16 | ,[0x00, 0x00, 0x50, 0x30, 0x00, 0x00] # 2c , 17 | ,[0x00, 0x08, 0x08, 0x08, 0x08, 0x08] # 2d - 18 | ,[0x00, 0x00, 0x60, 0x60, 0x00, 0x00] # 2e . 19 | ,[0x00, 0x20, 0x10, 0x08, 0x04, 0x02] # 2f / 20 | ,[0x00, 0x3e, 0x51, 0x49, 0x45, 0x3e] # 30 0 21 | ,[0x00, 0x00, 0x42, 0x7f, 0x40, 0x00] # 31 1 22 | ,[0x00, 0x42, 0x61, 0x51, 0x49, 0x46] # 32 2 23 | ,[0x00, 0x21, 0x41, 0x45, 0x4b, 0x31] # 33 3 24 | ,[0x00, 0x18, 0x14, 0x12, 0x7f, 0x10] # 34 4 25 | ,[0x00, 0x27, 0x45, 0x45, 0x45, 0x39] # 35 5 26 | ,[0x00, 0x3c, 0x4a, 0x49, 0x49, 0x30] # 36 6 27 | ,[0x00, 0x01, 0x71, 0x09, 0x05, 0x03] # 37 7 28 | ,[0x00, 0x36, 0x49, 0x49, 0x49, 0x36] # 38 8 29 | ,[0x00, 0x06, 0x49, 0x49, 0x29, 0x1e] # 39 9 30 | ,[0x00, 0x00, 0x36, 0x36, 0x00, 0x00] # 3a : 31 | ,[0x00, 0x00, 0x56, 0x36, 0x00, 0x00] # 3b ; 32 | ,[0x00, 0x08, 0x14, 0x22, 0x41, 0x00] # 3c < 33 | ,[0x00, 0x14, 0x14, 0x14, 0x14, 0x14] # 3d = 34 | ,[0x00, 0x00, 0x41, 0x22, 0x14, 0x08] # 3e > 35 | ,[0x00, 0x02, 0x01, 0x51, 0x09, 0x06] # 3f ? 36 | ,[0x00, 0x32, 0x49, 0x79, 0x41, 0x3e] # 40 @ 37 | ,[0x00, 0x7e, 0x11, 0x11, 0x11, 0x7e] # 41 A 38 | ,[0x00, 0x7f, 0x49, 0x49, 0x49, 0x36] # 42 B 39 | ,[0x00, 0x3e, 0x41, 0x41, 0x41, 0x22] # 43 C 40 | ,[0x00, 0x7f, 0x41, 0x41, 0x22, 0x1c] # 44 D 41 | ,[0x00, 0x7f, 0x49, 0x49, 0x49, 0x41] # 45 E 42 | ,[0x00, 0x7f, 0x09, 0x09, 0x09, 0x01] # 46 F 43 | ,[0x00, 0x3e, 0x41, 0x49, 0x49, 0x7a] # 47 G 44 | ,[0x00, 0x7f, 0x08, 0x08, 0x08, 0x7f] # 48 H 45 | ,[0x00, 0x00, 0x41, 0x7f, 0x41, 0x00] # 49 I 46 | ,[0x00, 0x20, 0x40, 0x41, 0x3f, 0x01] # 4a J 47 | ,[0x00, 0x7f, 0x08, 0x14, 0x22, 0x41] # 4b K 48 | ,[0x00, 0x7f, 0x40, 0x40, 0x40, 0x40] # 4c L 49 | ,[0x00, 0x7f, 0x02, 0x0c, 0x02, 0x7f] # 4d M 50 | ,[0x00, 0x7f, 0x04, 0x08, 0x10, 0x7f] # 4e N 51 | ,[0x00, 0x3e, 0x41, 0x41, 0x41, 0x3e] # 4f O 52 | ,[0x00, 0x7f, 0x09, 0x09, 0x09, 0x06] # 50 P 53 | ,[0x00, 0x3e, 0x41, 0x51, 0x21, 0x5e] # 51 Q 54 | ,[0x00, 0x7f, 0x09, 0x19, 0x29, 0x46] # 52 R 55 | ,[0x00, 0x46, 0x49, 0x49, 0x49, 0x31] # 53 S 56 | ,[0x00, 0x01, 0x01, 0x7f, 0x01, 0x01] # 54 T 57 | ,[0x00, 0x3f, 0x40, 0x40, 0x40, 0x3f] # 55 U 58 | ,[0x00, 0x1f, 0x20, 0x40, 0x20, 0x1f] # 56 V 59 | ,[0x00, 0x3f, 0x40, 0x38, 0x40, 0x3f] # 57 W 60 | ,[0x00, 0x63, 0x14, 0x08, 0x14, 0x63] # 58 X 61 | ,[0x00, 0x07, 0x08, 0x70, 0x08, 0x07] # 59 Y 62 | ,[0x00, 0x61, 0x51, 0x49, 0x45, 0x43] # 5a Z 63 | ,[0x00, 0x00, 0x7f, 0x41, 0x41, 0x00] # 5b [ 64 | ,[0x00, 0x02, 0x04, 0x08, 0x10, 0x20] # 5c \ # 65 | ,[0x00, 0x00, 0x41, 0x41, 0x7f, 0x00] # 5d ] 66 | ,[0x00, 0x04, 0x02, 0x01, 0x02, 0x04] # 5e ^ 67 | ,[0x00, 0x40, 0x40, 0x40, 0x40, 0x40] # 5f _ 68 | ,[0x00, 0x00, 0x01, 0x02, 0x04, 0x00] # 60 ` 69 | ,[0x00, 0x20, 0x54, 0x54, 0x54, 0x78] # 61 a 70 | ,[0x00, 0x7f, 0x48, 0x44, 0x44, 0x38] # 62 b 71 | ,[0x00, 0x38, 0x44, 0x44, 0x44, 0x20] # 63 c 72 | ,[0x00, 0x38, 0x44, 0x44, 0x48, 0x7f] # 64 d 73 | ,[0x00, 0x38, 0x54, 0x54, 0x54, 0x18] # 65 e 74 | ,[0x00, 0x08, 0x7e, 0x09, 0x01, 0x02] # 66 f 75 | ,[0x00, 0x0c, 0x52, 0x52, 0x52, 0x3e] # 67 g 76 | ,[0x00, 0x7f, 0x08, 0x04, 0x04, 0x78] # 68 h 77 | ,[0x00, 0x00, 0x44, 0x7d, 0x40, 0x00] # 69 i 78 | ,[0x00, 0x20, 0x40, 0x44, 0x3d, 0x00] # 6a j 79 | ,[0x00, 0x7f, 0x10, 0x28, 0x44, 0x00] # 6b k 80 | ,[0x00, 0x00, 0x41, 0x7f, 0x40, 0x00] # 6c l 81 | ,[0x00, 0x7c, 0x04, 0x18, 0x04, 0x78] # 6d m 82 | ,[0x00, 0x7c, 0x08, 0x04, 0x04, 0x78] # 6e n 83 | ,[0x00, 0x38, 0x44, 0x44, 0x44, 0x38] # 6f o 84 | ,[0x00, 0x7c, 0x14, 0x14, 0x14, 0x08] # 70 p 85 | ,[0x00, 0x08, 0x14, 0x14, 0x18, 0x7c] # 71 q 86 | ,[0x00, 0x7c, 0x08, 0x04, 0x04, 0x08] # 72 r 87 | ,[0x00, 0x48, 0x54, 0x54, 0x54, 0x20] # 73 s 88 | ,[0x00, 0x04, 0x3f, 0x44, 0x40, 0x20] # 74 t 89 | ,[0x00, 0x3c, 0x40, 0x40, 0x20, 0x7c] # 75 u 90 | ,[0x00, 0x1c, 0x20, 0x40, 0x20, 0x1c] # 76 v 91 | ,[0x00, 0x3c, 0x40, 0x30, 0x40, 0x3c] # 77 w 92 | ,[0x00, 0x44, 0x28, 0x10, 0x28, 0x44] # 78 x 93 | ,[0x00, 0x0c, 0x50, 0x50, 0x50, 0x3c] # 79 y 94 | ,[0x00, 0x44, 0x64, 0x54, 0x4c, 0x44] # 7a z 95 | ,[0x00, 0x00, 0x08, 0x36, 0x41, 0x00] # 7b [ 96 | ,[0x00, 0x00, 0x00, 0x7f, 0x00, 0x00] # 7c | 97 | ,[0x00, 0x00, 0x41, 0x36, 0x08, 0x00] # 7d ] 98 | ,[0x00, 0x10, 0x08, 0x08, 0x10, 0x08] # 7e ~ 99 | ,[0x00, 0x78, 0x46, 0x41, 0x46, 0x78] # 7f (delete) 100 | ] 101 | 102 | def get_font6_8(self, data): 103 | return self.FONTTYPE6_8[bytearray(data)[0] - 0x20] 104 | 105 | -------------------------------------------------------------------------------- /TPYBoard-v70x-master/05.来电显示功能/main.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TPYBoard/developmentBoard/535a975480a6755394cedfe3708a05952d9b6539/TPYBoard-v70x-master/05.来电显示功能/main.py -------------------------------------------------------------------------------- /TPYBoard-v70x-master/README.md: -------------------------------------------------------------------------------- 1 |

The TPYBoard v70x Series

2 | 3 |

TPYBoard v702

4 | 5 | 6 | 7 | 8 | 9 | 典型实例文档资料:http://docs.tpyboard.com/ 10 | 11 | -------------------------------------------------------------------------------- /TPYBoard-v70x-master/image/v702.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TPYBoard/developmentBoard/535a975480a6755394cedfe3708a05952d9b6539/TPYBoard-v70x-master/image/v702.png --------------------------------------------------------------------------------