树莓派使用教程5:i2c驱动OLED屏

1.树莓派开启i2c

sudo raspi-config

选择 Advanced Options -> I2C ->yes 启动i2C内核驱动;

运行lsmod命令查看i2c是否启动 ;

2.i2c-tools

i2c-tools这个工具在i2c硬件监控设备识别和故障诊断是非常重要。

树莓派系统自带了i2c-tools,如果系统没有,输入如下命令安装:

sudo apt-get install i2c-tools 

查询i2c设备:

i2cdetect -y 1

//-y 代表取消用户交互过程,直接执行指令;
//1 代表I2C总线编号;

其中0x3c代表oled屏幕的地址

i2c-tools还有如下命令:

i2cdump
i2cset
i2cget

//具体使用方法自行百度

3.驱动OLED屏

OLED屏是淘宝10块钱买的

输入指令,查询树莓派管脚定义:

pinout
gpio readall

按照系统提示接线

github上搜索了几个nodejs库,测试成功,直接上代码:

const i2c = require('i2c-bus')
const font = require('oled-font-5x7')

const bus = i2c.openSync(1)

const opts={
    width:128,
    height:64,
    address:0x3c
}

const oled= new require('oled-i2c-bus')(bus,opts)

oled.clearDisplay()

oled.setCursor(1,1)
oled.writeString(font,2,'Welcome',1,true)

oled.setCursor(1,20)
oled.writeString(font,2,'www.v5w.com',1,true)

现在oled屏上已经有显示输出了

学习更多知识,加QQ群:1098090823
威武网 » 树莓派使用教程5:i2c驱动OLED屏

提供最优质的资源集合

立即查看 了解详情