当前位置: 代码迷 >> 综合 >> 【Luat-air105】2.点屏-st7735
  详细解决方案

【Luat-air105】2.点屏-st7735

热度:13   发布时间:2023-12-05 20:26:04.0

1 前言

本章测试下air105+st7735显示。

2 硬件

在这里插入图片描述

3 驱动

在这里插入图片描述
本次使用的是spi2,对应的spi id为2

4 代码


-- 1. display: st7735+air105 spi2
function init_air105_st7735 ()-- spi test ok-- spi id is 2, cs is PB03-- spi_lcd = spi.deviceSetup(2,7,0,0,8,20000000,spi.MSB,1,1)spi_lcd = spi.deviceSetup(2,pin.PB03,0,0,8,2*1000*1000,spi.MSB,1,1)log.info("SPI OK")-- st7735 + esp32-- log.info("lcd.init",-- lcd.init("st7735",{port = "device",pin_dc = 6, pin_pwr = 11,pin_rst = 10,direction = 0,w = 128,h = 160,xoffset = 0,yoffset = 0},spi_lcd))-- air105 + st7735log.info("lcd.init",lcd.init("st7735",{
    port = "device",pin_dc = pin.PC00 ,pin_rst = pin.PB05,pin_pwr = pin.PC01,direction = 0,w = 128,h = 160,xoffset = 0,yoffset = 0},spi_lcd))-- log.info("lcd.init",-- lcd.init("st7735",{port = "device",pin_dc = 32 ,pin_rst = 21,pin_pwr = 33,direction = 0,w = 128,h = 160,xoffset = 0,yoffset = 0},spi_lcd))log.info("LCD OK")
endfunction display_line ()log.info("lcd.drawLine", lcd.drawLine(20,20,150,20,0x001F))log.info("lcd.drawRectangle", lcd.drawRectangle(20,40,120,70,0xF800))log.info("lcd.drawCircle", lcd.drawCircle(50,50,20,0x0CE0))-- sys.wait(1500)log.info("display demo")
endfunction display_str ()lcd.setFont(lcd.font_opposansm12)lcd.drawStr(40,10,"drawStr")lcd.setFont(lcd.font_opposansm16_chinese)lcd.drawStr(40,40,"drawStr测试")
end

main.lua

--- 模块功能:lcd- air105+st7735
-- @module lcd
-- @author youkai
-- @release 2022.02.20-- LuaTools需要PROJECT和VERSION这两个信息
PROJECT = "esp32_mpu6050"
VERSION = "1.0.0"log.info("main", PROJECT, VERSION)-- sys库是标配
_G.sys = require("sys")require("t1_display")     --setup lcdlog.info("end require")
--添加硬狗防止程序卡死
-- wdt.init(15000)--初始化watchdog设置为15s
-- sys.timerLoopStart(wdt.feed, 10000)--10s喂一次狗-- ----------------setup start----------------------
-- 初始化屏幕
init_air105_st7735 ()
display_line()
-- init_lvgl()
-- ----------------setup end-------------------------- ================main start================
sys.taskInit(function()-- ps:有wait不能放在外面sys.wait(1500)while 1 dosys.wait(10)end
end)
-- ================main end==================sys.run()

5 结果

在这里插入图片描述
显示成功。