树莓派3B驱动ST7789V

记录一下利用树莓派3B驱动ST778V显示用户桌面的问题。
最开始是用香橙派orangepi one驱动ST7789V的,但是一直没成功,最后放弃了,改用树莓派3B驱动。
参考的例程是微雪官方的文档https://www.waveshare.net/wiki/1.3inch_LCD_Module,
可以根据自己的屏幕尺寸进行修改,我的屏幕是在网上买的,商家说的是2.4寸,分辨率是240*320的。我按照这个教程,修改了一些参数,之后发现屏幕有反应,但是无图像显示,一片空白。
微雪的文档中提供了测试例程

sudo apt-get install unzip -y
sudo wget https://www.waveshare.net/w/upload/8/8d/LCD_Module_RPI_code.zip
sudo unzip ./LCD_Module_RPI_code.zip
cd LCD_Module_RPI_code/RaspberryPi/
cd c
sudo make clean
sudo make -j 8
sudo ./main 2.4   //我的屏幕尺寸是2.4寸

这个测试例程是完全没有问题的,但是显示的颜色好像不太对
在这里插入图片描述
最后参考了另一位博主的文章,解决了问题https://blog.csdn.net/u010280030/article/details/146280843?spm=1001.2014.3001.5502

	LCD_2IN4_WriteData_Byte(0x55);
	LCD_2IN4_Write_Command(0x36); // Memory Access Control
	LCD_2IN4_WriteData_Byte(0x08);
	LCD_2IN4_Write_Command(0x21); //添加0x21命令
	LCD_2IN4_Write_Command(0xB1);

具体的得去参考ST7789V的手册了,这是修改后的效果

在这里插入图片描述
最后就是显示树莓派桌面了,这个参照微雪的文档做就行了,但是有一个问题,我的屏幕明明是2.4寸的,按照文档执行

sudo cmake -DSPI_BUS_CLOCK_DIVISOR=20 -DWAVESHARE_2INCH4_LCD=ON -DBACKLIGHT_CONTROL=ON -DSTATISTICS=0 ..

屏幕是无显示的,但是有反应,就是屏幕会息屏,然后点击鼠标,屏幕又会点亮。最后突发奇想执行了另外的命令

sudo cmake -DSPI_BUS_CLOCK_DIVISOR=20 -DWAVESHARE_2INCH_LCD=ON -DBACKLIGHT_CONTROL=ON -DSTATISTICS=0 ..

然后就成功了,用2寸屏幕的命令点亮了2.4.寸的屏幕,搞不懂为什么。
在这里插入图片描述
但是还有一个问题,这个显示颜色好像还是反色的,还是跟初始化代码有关?最后看了源码后,在Waveshare_fbcp/src/config下面有一个config.h,打开后找到#define DISPLAY_INVERT_COLORS,发现这个宏定义是被注释掉的,而在st7789.cpp文件中,可以看见

#ifdef ST7789
    //SPI_TRANSFER(0xBA/*DGMEN: Enable Gamma*/, 0x04);
    bool invertColors = true;
#else
    bool invertColors = false;
#endif
#ifdef DISPLAY_INVERT_COLORS
    invertColors = !invertColors;
#endif

    if (invertColors)
      SPI_TRANSFER(0x21 /*Display Inversion On*/);
    else
      SPI_TRANSFER(0x20 /*Display Inversion Off*/);

    SPI_TRANSFER(0x13 /*NORON: Partial off (normal)*/);
    usleep(10 * 1000);

这里定义的是ST7789,而我用的屏幕芯片是ST7789V,invertColors默认应该是false,如果没有定义DISPLAY_INVERT_COLORS,执行的是SPI_TRANSFER(0x20);所以,将注释的#define DISPLAY_INVERT_COLORS恢复,然后在重新编译和运行就正常了。

mkdir build
cd build
cmake -DSPI_BUS_CLOCK_DIVISOR=20 -DWAVESHARE_2INCH_LCD=ON -DBACKLIGHT_CONTROL=ON -DSTATISTICS=0 ..  //这里用2寸屏幕的,不知道为啥
sudo make -j
sudo ./fbcp

在这里插入图片描述
其他的开机启动的,参考微雪的文档操作就可以了。
更新
在运行sudo ./fbcp的时候,树莓派可能会报错

pi@raspberrypi:~/myfiles/Waveshare_fbcp/build $ sudo ./fbcp 
bcm_host_get_peripheral_address: 0x3f000000, bcm_host_get_peripheral_size: 16777216, bcm_host_get_sdram_address: 0xc0000000
BCM core speed: current: 250000000hz, max turbo: 400000000hz. SPI CDIV: 20, SPI max frequency: 20000000hz
Allocated DMA channel 7
Allocated DMA channel 1
Enabling DMA channels Tx:7 and Rx:1
DMA hardware register file is at ptr: 0x75cab000, using DMA TX channel: 7 and DMA RX channel: 1
DMA hardware TX channel register file is at ptr: 0x75cab700, DMA RX channel register file is at ptr: 0x75cab100
DMA RX channel 1 was assigned another peripheral map 5!
DMA channel 0 has peripheral map 0 (is lite channel: 0, currently active: 0, current control block: (nil))
DMA channel 1 has peripheral map 5 (is lite channel: 0, currently active: 1, current control block: 0xff4ce620)
DMA channel 2 has peripheral map 11 (is lite channel: 0, currently active: 1, current control block: (nil))
DMA channel 3 has peripheral map 17 (is lite channel: 0, currently active: 1, current control block: (nil))
DMA channel 4 has peripheral map 13 (is lite channel: 0, currently active: 1, current control block: (nil))
DMA channel 5 has peripheral map 0 (is lite channel: 0, currently active: 0, current control block: (nil))
DMA channel 6 has peripheral map 13 (is lite channel: 0, currently active: 1, current control block: (nil))
DMA channel 7 has peripheral map 0 (is lite channel: 1, currently active: 0, current control block: (nil))
DMA channel 8 has peripheral map 0 (is lite channel: 1, currently active: 0, current control block: (nil))
DMA channel 9 has peripheral map 0 (is lite channel: 1, currently active: 0, current control block: (nil))
DMA channel 10 has peripheral map 0 (is lite channel: 1, currently active: 0, current control block: (nil))
DMA channel 11 has peripheral map 0 (is lite channel: 1, currently active: 0, current control block: (nil))
DMA channel 12 has peripheral map 0 (is lite channel: 1, currently active: 0, current control block: (nil))
DMA channel 13 has peripheral map 0 (is lite channel: 1, currently active: 0, current control block: (nil))
DMA channel 14 has peripheral map 0 (is lite channel: 1, currently active: 0, current control block: (nil))
DMA RX channel was assigned another peripheral map!

大概意思是说DMA被占用,导致冲突了,只需要将树莓派的配置文件/boot/config.txt中的dtparam=audio=on给注释掉就可以了。

Arduino和Raspberry Pi配合使用ST7789驱动芯片可以制作图形化界面的小游戏。ST7789是一种常用的TFT LCD显示屏控制芯片。下面是一个简化版的步骤和基础代码示例: 1. **硬件连接**: - 连接ST7789树莓派,通常通过SPI总线。连接MOSI、MISO、SCLK、CS(数据线、时钟线、片选线)。 - 对于Arduino Uno或其衍生板,可能需要额外连接电源和地。 2. **库安装**: - Arduino上可能需要安装`Adafruit_ST7789`库,对于Raspberry Pi则可能需要相应的Python库,如`RPi.GPIO`和`st7789`。 3. **Arduino代码示例(C++)**: ```cpp #include <Adafruit_ST7789.h> Adafruit_ST7789 tft = Adafruit_ST7789(DC, CS, RST, spi); // DC=pin for the data/command pin, CS=pin for chip select, RST=pin for reset void setup() { tft.begin(); // Initialize the display fillScreen(tft.color565(0x00FF00)); // Fill with a green color } void loop() { drawCircle(100, 100, 40, tft.color565(0xFF0000)); // Draw a red circle at (100, 100) with radius 40 delay(1000); // Pause for a second } ``` 4. **Raspberry Pi代码示例(Python)**: ```python import spidev from PIL import Image, ImageDraw, ImageFont import time import st7789 disp = st7789.ST7789(spi=spidev.SpiDev(), cs=0, dc=1, rst=-1, width=240, height=320) def draw_circle(x, y, r, color): disp.draw.filled_circle((x, y), r, color) disp.display() while True: draw_circle(100, 100, 40, (255, 0, 0)) # Red circle time.sleep(1) # Wait a second ``` 请注意,这只是一个非常基础的示例,并不适合做复杂的游戏。实际游戏开发会涉及更复杂的用户交互和画面管理。如果你想构建一个2048小游戏,你需要理解游戏规则、数据结构以及如何在LCD上动态更新显示。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值