基于树莓派Pico的嵌入式系统学习平台制作一款能控制LCD和电脑界面的“鼠标”
基于树莓派Pico的嵌入式系统学习平台制作的一款能控制LCD和电脑界面的“鼠标”
标签
嵌入式系统
显示
USB
2022寒假在家练
繁光与梦
更新2022-03-07
华东理工大学
753

流程图

FqYCC7g_aTGBHFGpo4G-reEwOqPe

项目需求:

本项目基于树莓派Pico的嵌入式系统学习平台制作的一款能控制LCD和电脑界面的“鼠标”,具体功能如下:

  1. 利用板上的四向摇杆和按键设计一款“鼠标”
  2. 在240*240的LCD屏幕内可以通过该鼠标进行菜单选择和参数控制(在屏幕上要有上图中图形化的箭头形状)
  3. 通过USB端口可以控制PC屏幕上的光标移动和点击操作,行使电脑鼠标的功能

设计思路:

首先同过使用st7789进行在lcd屏幕上绘制页面以及鼠标的图案,在通过判定,如果遥感有变化,清除原坐标上的鼠标在现坐标上绘制新的鼠标,实现鼠标的移动功能。然后使用hid库,进行对电脑鼠标的控制,再通过遥感相应增加减少x,y的值,使用tomove指令进行鼠标的移动。

控制pc屏幕上的光标:

可以使用circuitpython和micropython等多种方式实现,这里我使用了micropython并使用了官方的hid库来控制pc光标,通过对遥杆值的读取来确定遥感移动的方向,进行对屏幕中光标的绝对位置进行加减从而实现移动。

from hid import Mouse
from machine import Pin, SPI, ADC
m = Mouse()
xAxis = ADC(Pin(29))
yAxis = ADC(Pin(28))
buttonB = Pin(5,Pin.IN, Pin.PULL_UP) 
buttonA = Pin(6,Pin.IN, Pin.PULL_UP)
buttonSelect = Pin(8,Pin.IN, Pin.PULL_UP)
def move1():
    x=0
    y=0
    while True:
        xValue = xAxis.read_u16()
        yValue = yAxis.read_u16()
        buttonValueA = buttonA.value()
        buttonValueB = buttonB.value()
        buttonValueSelect = buttonSelect.value()
        '''m.move(x, y, 0, 0)'''
        m.moveto(x, y)
        if buttonValueA == 0:
            m.click(Mouse.BUTTON_LEFT)
            utime.sleep(0.1)
        if buttonValueB == 0:
            m.click(Mouse.BUTTON_RIGHT)
            utime.sleep(0.1)
        if xValue <= 1000:
            x -=100
        if(xValue >= 40000):
            x +=100
        if(yValue <= 1000):
            y -=100
        if(yValue >= 40000):
            y +=100
        if(buttonValueSelect == 0):
            m1()
            break

lcd屏幕显示

通过对st7789库的应用,实现对图像以及文字的显示,同时再次通过对摇杆值的读取与判断进行翻页的实现

def m3():
    global x, y, x1, y1
    while True:       
        xValue = xAxis.read_u16()
        yValue = yAxis.read_u16()
        buttonValueA = buttonA.value()
        buttonValueB = buttonB.value()      
        display.text(font2, "MOUSE", 80, 10)
        display.text(font2, "exit", 150, 200)
        display.text(font2, "mod", 10, 60)
        display.text(font2, "pc", 10, 100)
        display.blit_buffer(buf1, x, y, 15, 20)
        if yValue >= 40000:
            y+=20
            display.fill_rect(x1, y1, 60, 60, st7789.BLACK)
            x1 = x
            y1 = y
        if yValue <= 1000:
            y-=20
            display.fill_rect(x1, y1, 60, 60, st7789.BLACK)
            x1 = x
            y1 = y
        if xValue >= 40000:
            x+=20
            display.fill_rect(x1, y1, 60, 60, st7789.BLACK)
            x1 = x
            y1 = y
        if xValue <= 1000:
            x-=20
            display.fill_rect(x1, y1, 60, 60, st7789.BLACK)
            x1 = x
            y1 = y
        if x >= 150 and y >= 200 and buttonValueA == 0:
            utime.sleep(0.1)
            display.fill(st7789.BLACK)           
            s1()
            m2()
            break
        if x >= 10 and x <= 90 and y >= 60 and y <= 100 and buttonValueA == 0 :
            display.fill(st7789.BLACK)
            m1()
            break
        if x >= 10 and x <= 90 and y >= 100 and y <= 140 and buttonValueA == 0:
            move1()
            break

lcd上的鼠标

通过framebuf的图片快速显示,配合与上面相同的方法实现了图片的移动以及添加判定框增加其他部分的功能

def m1():
    global x, y, x1, y1
    while True:       
        xValue = xAxis.read_u16()
        yValue = yAxis.read_u16()
        buttonValueA = buttonA.value()
        buttonValueB = buttonB.value()      
        display.text(font2, "MOUSE", 80, 10)
        display.text(font2, "exit", 150, 200)
        display.text(font2, "mod", 10, 60)
        display.text(font2, "pc", 10, 100)
        display.blit_buffer(buf, x, y, 15, 20)
        if yValue >= 40000:
            y+=20
            display.fill_rect(x1, y1, 60, 60, st7789.BLACK)
            x1 = x
            y1 = y
        if yValue <= 1000:
            y-=20
            display.fill_rect(x1, y1, 60, 60, st7789.BLACK)
            x1 = x
            y1 = y
        if xValue >= 40000:
            x+=20
            display.fill_rect(x1, y1, 60, 60, st7789.BLACK)
            x1 = x
            y1 = y
        if xValue <= 1000:
            x-=20
            display.fill_rect(x1, y1, 60, 60, st7789.BLACK)
            x1 = x
            y1 = y
        if x >= 150 and y >= 200 and buttonValueA == 0:
            utime.sleep(0.1)
            display.fill(st7789.BLACK)           
            s1()
            m2()
            break
        if x >= 10 and x <= 90 and y >= 60 and y <= 100 and buttonValueA == 0:
            display.fill(st7789.BLACK)
            m3()
            break
        if x >= 10 and x <= 90 and y >= 100 and y <= 140 and buttonValueA == 0:
            move1()
            break

目前,项目已完成目标,可以实现对pc光标的控制以及在led上模拟鼠标,具体请参考演示视频。

主要问题

项目实施过程中遇到的主要难题及解决过程如下:

1.在初期不适应micropython编程导致出现许多语法错误;

2.对硬件的不熟悉,刷新时使用全刷,导致闪屏。最终通过部分刷屏的方法解决部分但仍未完全解决,在有图像的地方仍会闪屏。

未来计划

继续学习,想办法彻底解决闪屏问题。

Fg6IiOLW-PvKK7qIOI8oqCbychyq

FhkgsL5vjEFa5xbNu6rc7apdR5Ne

 

附件下载
新建文件夹 (2).7z
团队介绍
评论
0 / 100
查看更多
目录
硬禾服务号
关注最新动态
0512-67862536
info@eetree.cn
江苏省苏州市苏州工业园区新平街388号腾飞创新园A2幢815室
苏州硬禾信息科技有限公司
Copyright © 2023 苏州硬禾信息科技有限公司 All Rights Reserved 苏ICP备19040198号