orangepi——i2c协议,0led显示
orangepi接口:
orangepi@orangepizero2:~$ gpio readall+------+-----+----------+------+---+ H616 +---+------+----------+-----+------+| GPIO | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | GPIO |+------+-----+----------+------+---+----++----+---+------+----------+-----+------+| | | 3.3V | | | 1 || 2 | | | 5V | | || 229 | 0 | SDA.3 | OFF | 0 | 3 || 4 | | | 5V | | || 228 | 1 | SCL.3 | OFF | 0 | 5 || 6 | | | GND | | || 73 | 2 | PC9 | OFF | 0 | 7 || 8 | 0 | ALT2 | TXD.5 | 3 | 226 || | | GND | | | 9 || 10 | 0 | ALT2 | RXD.5 | 4 | 227 || 70 | 5 | PC6 | ALT5 | 0 | 11 || 12 | 0 | OFF | PC11 | 6 | 75 || 69 | 7 | PC5 | ALT5 | 0 | 13 || 14 | | | GND | | || 72 | 8 | PC8 | OFF | 0 | 15 || 16 | 0 | OFF | PC15 | 9 | 79 || | | 3.3V | | | 17 || 18 | 0 | OFF | PC14 | 10 | 78 || 231 | 11 | MOSI.1 | ALT4 | 0 | 19 || 20 | | | GND | | || 232 | 12 | MISO.1 | ALT4 | 0 | 21 || 22 | 0 | OFF | PC7 | 13 | 71 || 230 | 14 | SCLK.1 | ALT4 | 0 | 23 || 24 | 0 | ALT4 | CE.1 | 15 | 233 || | | GND | | | 25 || 26 | 0 | OFF | PC10 | 16 | 74 || 65 | 17 | PC1 | OFF | 0 | 27 || 28 | | | | | || 272 | 18 | PI16 | OFF | 0 | 29 || 30 | | | | | || 262 | 19 | PI6 | OFF | 0 | 31 || 32 | | | | | || 234 | 20 | PH10 | ALT3 | 0 | 33 || 34 | | | | | |+------+-----+----------+------+---+----++----+---+------+----------+-----+------+| GPIO | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | GPIO |+------+-----+----------+------+---+ H616 +---+------+----------+-----+------+
可以看出,0引脚为SDA,1引脚为SCL
1、启动之后查看根目录是否存在i2c设备节点
ls /dev/:根目录下的dev查看设备驱动底层,可以看到i2c-3和i2c-5
orangepi@orangepizero2:~$ ls /dev/
autofs lirc0 ram15 tty13 tty42 ttyS5
block log ram2 tty14 tty43 tv
btrfs-control loop0 ram3 tty15 tty44 uhid
bus loop1 ram4 tty16 tty45 uinput
cec loop2 ram5 tty17 tty46 urandom
cedar_dev loop3 ram6 tty18 tty47 vcs
char loop4 ram7 tty19 tty48 vcs1
console loop5 ram8 tty2 tty49 vcs2
core loop6 ram9 tty20 tty5 vcs3
cpu_dma_latency loop7 random tty21 tty50 vcs4
cuse loop-control rfkill tty22 tty51 vcs5
deinterlace mapper rtc tty23 tty52 vcs6
disk mem rtc0 tty24 tty53 vcs7
disp memory_bandwidth shm tty25 tty54 vcsa
dlm-control mmcblk0 slog_wcn0 tty26 tty55 vcsa1
dlm-monitor mmcblk0p1 slog_wcn1 tty27 tty56 vcsa2
dlm_plock mqueue snd tty28 tty57 vcsa3
fb0 net spidev0.0 tty29 tty58 vcsa4
fd network_latency spidev1.1 tty3 tty59 vcsa5
full network_throughput sst_storage tty30 tty6 vcsa6
fuse null stderr tty31 tty60 vcsa7
gpiochip0 ppp stdin tty32 tty61 vhci
gpiochip1 ptmx stdout tty33 tty62 watchdog
hdmi pts sunxi-reg tty34 tty63 watchdog0
hugepages ptyp0 sunxi_soc_info tty35 tty7 wcn_op
hwrng ram0 sunxi-wlan tty36 tty8 zero
i2c-3 ram1 tty tty37 tty9 zram0
i2c-5 ram10 tty0 tty38 ttyBT0 zram1
initctl ram11 tty1 tty39 ttyBT1 zram2
input ram12 tty10 tty4 ttyp0
kmem ram13 tty11 tty40 ttyS0
kmsg ram14 tty12 tty41 ttyS1
2、测试i2c,安装i2c-tools,装到默认路径下的
sudo apt-get inatall i2c-tools
3、安装完成,输入命令:sudo i2cdetect -y 3
能查看到3c表示oled的屏幕,
orangepi@orangepizero2:~$ sudo i2cdetect -y 30 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- 3c -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
4、复制代码,进行修改
cp ../wiringPi_from_windows/wiringOP-master/examples/oled_demo.c .
/** 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_demo(struct display_info *disp) {int i;char buf[100];//putstrto(disp, 0, 0, "Spnd spd 2468 rpm");// oled_putstrto(disp, 0, 9+1, "Spnd cur 0.46 A");oled_putstrto(disp, 0, 9+1, "Welcome to");disp->font = font1;// oled_putstrto(disp, 0, 18+2, "Spnd tmp 53 C");oled_putstrto(disp, 0, 18+2, "----OrangePi----");disp->font = font2;// oled_putstrto(disp, 0, 27+3, "DrvX tmp 64 C");oled_putstrto(disp, 0, 27+3, "This is 0.96OLED");oled_putstrto(disp, 0, 36+4, "");oled_putstrto(disp, 0, 45+5, "");disp->font = font1;// oled_putstrto(disp, 0, 54, "Total cur 2.36 A");oled_putstrto(disp, 0, 54, "*****************");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);if (e < 0) {show_error(1, e);} else {e = oled_init(&disp);if (e < 0) {show_error(2, e);} else {printf("---------start--------\n");if (oled_demo(&disp) < 0)show_error(3, 777);printf("----------end---------\n");}}return 0;
}
编译:./build.sh oled_demo.c /dev/i2c-3
运行:sudo ./a.out /dev/i2c-3
运行结果:
orangepi@orangepizero2:~/hardwaresoft$ ./build.sh oled_demo.c /dev/i2c-3
./build.sh
oled_demo.c
orangepi@orangepizero2:~/hardwaresoft$ sudo ./a.out /dev/i2c-3
---------start--------
----------end---------
5、oled显示自己想要的字符
/** 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 my oled");//0代表行,9+1代表列,“welcome to my oled”是内容disp->font = font2;//字体设置,一共有3种字体选择,1,2,3oled_putstrto(disp, 0, 9+11, " ##yangzerui## ");disp->font = font2;oled_send_buffer(disp);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;
}
编译运行:
orangepi@orangepizero2:~/hardwaresoft$ ./build.sh oled_demo.c
./build.sh
oled_demo.c
orangepi@orangepizero2:~/hardwaresoft$ sudo ./a.out /dev/i2c-3
orangepi——i2c协议,0led显示相关推荐
- 用STM32F103达成基于I2C协议的AHT20温湿度传感器和OLED屏显示汉字
目录 一 I2C协议简介 硬件I2C与软件I2C 二 代码和ATH20芯片实现温湿度的串口显示 三 用stm32f103芯片的SPI和IIC接口接上OLED屏显示中文姓名温湿度 1 先用文字字模生成器 ...
- FPGA进阶(2):基于I2C协议的EEPROM驱动控制
文章目录 第49讲:基于I2C协议的EEPROM驱动控制 理论部分 设计与实现 i2c_ctrl i2c_rw_data eeprom_byte_rd_wr tb_eeprom_byte_rd_wr ...
- STM32CubeIDE开发(十六),I2C协议采集传感器数据(SHTC1、LTR-553ALS、BMP280、LSM6DSL、MMC3680KJ)
目录 一.I2C总线协议 二.I2C协议的两种从机应对方式 三.传感器信息 四.工程创建及引脚配置 五.STCH1传感器实现 六.LTR_553ALS传感器(light sensor [ALS] an ...
- 基于I2C协议的EEPROM驱动控制(笔记整理)
一.目标 要求:设计一个使用I2C通讯协议的EEPROM读写控制器.使用写按键向EEPROM中写入1~10共10字节数据:使用读按键读出之前写入的数据并显示在数码管上. 分析:①首先按键控制读写操作按 ...
- 基于I2C协议利用STM32进行温湿度传感器的数据采集
目录 一.I2C总线通信协议的介绍 1.I2C简介 2.I2C总线时序图 3.五种速率 4.四种信号 5.I2C的优缺点 6.软件IIC和硬件IIC 二.创建工程 1.实验目的 2.工具的选择 3.相 ...
- STM32F103基于I2C协议的AHT20温湿度传感器的数据采集
目录 一.I2C 1.I2C 协议简介 2.I2C 物理层 3.协议层 通讯的起始和停止信号 数据有效性 响应 4. 软件I2C"和"硬件I2C 二.实现AHT20采集程序 1.A ...
- STM32F103完成基于I2C协议的AHT20温湿度传感器的数据采集
文章目录 一.I2C总线通讯协议 1.I2C总线简介 2.I2C 协议的物理层和协议层 2.1物理层 2.2协议层 3.I2C的两种方式--硬件I2C和软件I2C 3.1硬件I2C 3.2软件I2C ...
- I2C协议靠这16张图彻底搞懂(超详细)
文章目录 背景 硬件层 数据传输协议 实际上如何工作? 单个主设备连接多个从机 多个主设备连接多个从机 如何编程? 总结 背景 I²C(Inter-Integrated Circuit),中文应该叫集 ...
- I2C协议+实现源码
文章目录 摘要 I2C通信协议 简介 补充 空闲状态 start和stop信号 应答信号 数据有效性规定 数据传输 延时 I2C协议的实现源码 硬件说明 头文件 sys.h 主函数 初始化I2C 产生 ...
最新文章
- nvGRAPH API参考分析(二)
- 20181023-2 贡献分配
- 秒赞机器人好友_空间说说秒赞机器人
- 概述VB.NET正则表达式简化程序代码
- 【转】MATLAB的polar函数 极坐标绘制最大半径怎样设置
- clamav Java_ClamAV安装使用及API例子
- android136 360 拖拽
- 与一线Linux嵌入式开发工程师的对话
- 在不重装系统的情况下创建Linux的Swap分区
- scala中的基础语法
- Hive date_format函数入门
- Spring源码之ApplicationContext(七)获取消息资源
- AHK生成随机但不重复的数字
- [收藏】正确使用SqlConnection对象,兼谈数据库连接池
- 电位器/电阻器型号命名方法
- malloc.h头文件以及malloc函数
- Awesome Competitive Programming
- 微博营销的价值与注意点
- JUC并发编程基石AQS源码之结构篇-ReentrantLock
- 计算机 硬盘 数据,我们电脑硬盘里的数据还能保存多久?