目录
OLED屏幕
Orangepi的IIC接口
- 由 26pin 的原理图可知, Orange Pi Zero 2 可用的 i2c 为 i2c3
- 启动 linux 系统后, 先确认下/dev 下存在 i2c-3 的设备节点从命令运行结果能观察到系统支持I2C-3和I2C-5的驱动,而H616的外设我们看到只有一个IIC接 口,用的是IIC-3 Linux一切皆文件,每个硬件设备“对应”一个文件,由驱动程序提供映射
- 开始测试 i2c, 首先安装 i2c-tools
sudo apt-get install i2c-tools
案例:
/*
* Copyright (c) 2015, Vladimir Komendantskiy
* MIT License
*
* SSD1306 demo of block and font drawing.
*/
//
// fixed for OrangePiZero by HypHop
//
#include <errno.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <stdint.h>
#include "oled.h"
#include "font.h"
int oled_show(struct display_info *disp) {
int i;
char buf[100];
oled_putstrto(disp, 0, 9+1, "Welcome to");
disp->font = font1;
oled_send_buffer(disp);
disp->font = font3;
for (i=0; i<100; i++) {
sprintf(buf, "Spnd spd %d rpm", i);
oled_putstrto(disp, 0, 0, buf);
oled_putstrto(disp, 135-i, 36+4, "===");
oled_putstrto(disp, 100, 0+i/2, ".");
oled_send_buffer(disp);
}
//oled_putpixel(disp, 60, 45);
//oled_putstr(disp, 1, "hello");
return 0;
}
void show_error(int err, int add) {
//const gchar* errmsg;
//errmsg = g_strerror(errno);
printf("\nERROR: %i, %i\n\n", err, add);
//printf("\nERROR\n");
}
void show_usage(char *progname) {
printf("\nUsage:\n%s <I2C bus device node >\n", progname);
}
int main(int argc, char **argv) {
int e;
char filename[32];
struct display_info disp;
if (argc < 2) {
show_usage(argv[0]);
return -1;
}
memset(&disp, 0, sizeof(disp));
sprintf(filename, "%s", argv[1]);
disp.address = OLED_I2C_ADDR;
disp.font = font2;
e = oled_open(&disp, filename);
e = oled_init(&disp);
oled_show(&disp);
return 0;
}
注:运行需指令文件路径 sudo ./a.out /dev/i2c-3