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 3
     0  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,3
        oled_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

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
编译 Linux 内核需要以下步骤: 1. 获取 Linux 内核源代码。你可以从官方网站或 GitHub 上下载最新的内核源代码。 2. 安装交叉编译工具链。如果你的开发环境是 x86 架构的,你需要安装交叉编译工具链来编译适用于 ARM 架构的内核。你可以使用 apt-get 命令或其他包管理器来安装工具链。例如,在 Ubuntu 或 Debian 上,你可以使用以下命令来安装: ``` sudo apt-get install gcc-arm-linux-gnueabihf ``` 3. 配置内核。进入内核源代码目录,使用以下命令来配置内核: ``` make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- orangepi_zero2_defconfig ``` 这将使用默认配置文件来配置内核。 4. 编译内核。使用以下命令来编译内核: ``` make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- zImage dtbs modules ``` 这将编译内核镜像、设备树和内核模块。 5. 安装内核。将编译好的内核镜像和设备树文件复制到 SD 卡的 boot 分区中。例如,在 Ubuntu 或 Debian 上,你可以使用以下命令来安装: ``` sudo cp arch/arm/boot/zImage /media/boot/ sudo cp arch/arm/boot/dts/sun8i-h2-plus-orangepi-zero2.dtb /media/boot/ ``` 6. 配置引导加载程序。编辑 SD 卡的 boot 分区中的 boot.cmd 文件,并添加以下内容: ``` setenv bootargs console=ttyS0,115200 root=/dev/mmcblk0p2 rootwait panic=10 fatload mmc 0:1 ${kernel_addr_r} zImage fatload mmc 0:1 ${fdt_addr_r} sun8i-h2-plus-orangepi-zero2.dtb bootz ${kernel_addr_r} - ${fdt_addr_r} ``` 这将配置引导加载程序以加载内核镜像和设备树,并指定内核参数。 7. 生成引导加载程序镜像。使用以下命令来生成引导加载程序镜像: ``` mkimage -C none -A arm -T script -d boot.cmd boot.scr ``` 这将生成一个名为 boot.scr 的文件,它是引导加载程序镜像。 8. 将引导加载程序镜像复制到 SD 卡的 boot 分区中: ``` sudo cp boot.scr /media/boot/ ``` 9. 将 SD 卡插入 Orange Pi Zero 2 开发板,并启动板子。如果一切正常,你应该看到内核启动信息在串口终端中输出。 注意:这只是一个简单的指南,实际的操作可能会因环境和设备而有所不同。请确保你熟悉 Linux 内核编译和 Orange Pi Zero 2 开发板的使用。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值