使用Arduino读取bmp图片并在1.44寸的小液晶显示
本帖最后由 维博哥哥 于 2016-10-11 19:33 编辑之前搞了好久Arduino Due,在驱动液晶ILI9481的时候,一直弄不出来。然后想用usb接口驱动北通游戏手柄还是弄不出来,于是就转战stm32,想学学这底层到底怎么弄。弄stm32估计都快半个月了吧,又在IIC上面驱动BMA180搞不出来。心灰意懒,还是做arduino好玩,没事还能出来写写帖子。
这其实是好久之前做的小实验,读取bmp文件并显示出来。挺有意思的主要这次图片不再是把图片转化成文本文件,而是直接的二进制文件,真正的二进制文件。说到二进制的图片文件,bmp估计是最简单的一种了。除了文件头,后面就是图片数据。其实吧,这些文件都是很简单的,关键是找到很好的教材,我就是找到写得很整齐的小程序是用c写的,直接生成一个bmp图片。程序我挂在后面,因为之前对结构体不是很懂,所以看很多都不是很懂,有了这个程序基本上明白。
说回我们的这次小实验,使用的设备128*128像素的小液晶,一个SD卡读卡器,一个8G的TF卡。如图所示,中间的ov7670是没有用到的。
#include <SPI.h>
#include <SD.h>
#include <UTFT.h>
UTFT myGLCD(ST7735S,A2,A1,A5,A4,A3);
File myFile;
byte a;
unsigned short pic;
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
myGLCD.InitLCD(PORTRAIT);
Serial.print("Initializing SD card...");
// On the Ethernet Shield, CS is pin 4. It's set as an output by default.
// Note that even if it's not used as the CS pin, the hardware SS pin
// (10 on most Arduino boards, 53 on the Mega, 14 on the Leonardo) must be left as an output
// or the SD library functions will not work.
if (!SD.begin(4)) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");
// re-open the file for reading:
myFile = SD.open("4.bmp");
if (myFile) {
Serial.println("4.bmp:");
// read from the file until there's nothing else in it:
while (myFile.available()) {
//跳过前0x36个字节的头
for(int i=0;i<0x36;i++)
{
Serial.print(myFile.read(),HEX);
Serial.print(" ");
}
//把rgb24转换成rgb16,128*128像素转换成hex是0x4000
for(int i=0;i<0x4000;i++)
{
a = myFile.read();
pic = (a*32/256)<<11;
a = myFile.read();
pic |= (a*64/256)<<5;
a = myFile.read();
pic |= (a*32/256);
}
Serial.println("OK");
}
// close the file:
myFile.close();
} else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
}
void loop()
{
// nothing happens after setup
myGLCD.fillScr(255, 255, 255);
myGLCD.drawBitmap (0, 0, 128, 128, pic, 1);
delay(5000);
}
学习ing.... M0 :o:o:o:o很有意思
不错,学习一下。:D 下一步要结合ov7670了吗 大神...求教,如何能让小车根据bmp的图像规划路线自动行走?就是些横纵线!或者jpg的也行! GXJAMES 发表于 2016-10-18 16:46
大神...求教,如何能让小车根据bmp的图像规划路线自动行走?就是些横纵线!或者jpg的也行!
亲,你这问题太大了,你把bmp图片读出来,然后图像处理,然后。。。 能留个联系方式吗?想问点东西,麻烦啦
这是我QQ:1510976232 楼主在吗?帮帮我呗 GXJAMES 发表于 2016-10-18 16:46
大神...求教,如何能让小车根据bmp的图像规划路线自动行走?就是些横纵线!或者jpg的也行!
把bmp图识别成黑白点阵,把点阵和实际行走脉冲对应起来,再按着点阵走就可以了, 好,學習了。
謝謝 能不能在SD卡上创建个图像文件,然后把拍照的数据存在图像里,然后电脑可以直接打开,不知道怎么弄 benson 发表于 2017-1-6 16:38
能不能在SD卡上创建个图像文件,然后把拍照的数据存在图像里,然后电脑可以直接打开,不知道怎么弄
可以,保存成bmp格式图片比较好 wcx7758258 发表于 2016-11-11 14:29
能留个联系方式吗?想问点东西,麻烦啦
这是我QQ:1510976232
哪需要这么麻烦?不就是小车嘛,有左右轮啊,用光电探测,分别控制左右轮,不就行了吗?
页:
[1]
2