OLED屏—IIC协议

文章介绍了在OrangePiZero2上如何启动Linux系统并确认I2C-3设备节点的存在。通过安装i2c-tools进行I2C通信测试,特别是针对H616外设的IIC-3接口。作者提供了使用OLED显示的示例代码,展示了如何初始化、设置字体并显示文本。
摘要由CSDN通过智能技术生成

由 26pin 的原理图可知, Orange Pi Zero 2 可用的 i2c 为 i2c3

 启动 linux 系统后, 先确认下/dev 下存在 i2c-3 的设备节点

从命令运行结果能观察到系统支持I2C-3和I2C-5的驱动,而H616的外设我们看到只有一个IIC接 口,用的是IIC-3

Linux一切皆文件,每个硬件设备“对应”一个文件,由驱动程序提供映射

 ls /dev/i2c-

开始测试 i2c, 首先安装 i2c-tools

sudo apt-get install i2c-tools
 sudo i2cdetect -y 3

使用官方提供的oled_demo.c

 cp ../wiringOP/examples/oled_demo.c .

 ./build.sh oled_demo.c
sudo ./a.out /dev/i2c-3
#include <string.h>
#include <stdio.h>
#include <stdint.h>
#include <font.h>
#include <oled.h>

int oled_show(struct display_info *disp )
{
    oled_putstrto(disp,0,9+1,"Welcome       to");
    disp->font=font1;
    oled_putstrto(disp,0,18+2,"----Mr Du ------");
    disp->font=font2;
    oled_send_buffer(disp);


    return 0;
}


int main()
{
    struct display_info disp;
    memset(&disp,0,sizeof(disp));

    disp.address=OLED_I2C_ADDR;
    disp.font=font2;

    oled_open(&disp,"/dev/i2c-3");
    oled_init(&disp);
    oled_show(&disp);

    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值