428 views|0 replies

410

Posts

3

Resources
The OP
 

【Jiangxinchuang D133CBS】I2C drive OLED display [Copy link]

 This post was last edited by TL-LED on 2024-9-11 23:33

Test the I2C interface and drive the OLED display.

1. Hardware Circuit

The externally connected I2C port on the circuit board is I2C0 corresponding to the J11 plug-in.

1.1、I2C0 interface circuit diagram

1.2 Hardware connection diagram

2. Configure I2C

2.1. Open I2C0

2.2. Enable I2C driver debugging and routines

3. Configure third-party libraries

3.1. Select SSD1306 library

3.2. Select I2C0 and enable test routine

After the selection is completed, execute the command pkgs --update to update the library file

After the download is complete, you will find the source file in the packages directory

IV. Procedure

4.1、ssd1306_tests.c

/*
 * Copyright (c) 2020, RudyLo <luhuadong@163.com>
 *
 * SPDX-License-Identifier: MIT License
 *
 * Change Logs:
 * Date           Author       Notes
 * 2020-11-15     luhuadong    the first version
 */

#include <rtthread.h>
#include <rtdevice.h>
#include <board.h>

#include <string.h>
#include <stdio.h>
#include "ssd1306.h"
#include "ssd1306_tests.h"

void ssd1306_TestBorder()
{
    ssd1306_Fill(Black);

    uint32_t start = rt_tick_get();
    uint32_t end = start;
    uint8_t x = 0;
    uint8_t y = 0;
    do {
        ssd1306_DrawPixel(x, y, Black);

        if((y == 0) && (x < 127))
            x++;
        else if((x == 127) && (y < 63))
            y++;
        else if((y == 63) && (x > 0)) 
            x--;
        else
            y--;

        ssd1306_DrawPixel(x, y, White);
        ssd1306_UpdateScreen();
    
        rt_thread_mdelay(5);
        end = rt_tick_get();
    } while((end - start) < 8000);
   
    rt_thread_mdelay(1000);
}

void ssd1306_TestFonts()
{
    ssd1306_Fill(Black);
    ssd1306_SetCursor(2, 0);
    ssd1306_WriteString("Font 16x26", Font_16x26, White);
    ssd1306_SetCursor(2, 26);
    ssd1306_WriteString("Font 11x18", Font_11x18, White);
    ssd1306_SetCursor(2, 26+18);
    ssd1306_WriteString("Font 7x10", Font_7x10, White);
    ssd1306_SetCursor(2, 26+18+10);
    ssd1306_WriteString("Font 6x8", Font_6x8, White);
    ssd1306_UpdateScreen();
}

void ssd1306_TestFPS()
{
    ssd1306_Fill(White);
   
    uint32_t start = rt_tick_get();
    uint32_t end = start;
    int fps = 0;
    char message[] = "ABCDEFGHIJK";
   
    ssd1306_SetCursor(2,0);
    ssd1306_WriteString("Testing...", Font_11x18, Black);
   
    do {
        ssd1306_SetCursor(2, 18);
        ssd1306_WriteString(message, Font_11x18, Black);
        ssd1306_UpdateScreen();
       
        char ch = message[0];
        memmove(message, message+1, sizeof(message)-2);
        message[sizeof(message)-2] = ch;

        fps++;
        end = rt_tick_get();
    } while((end - start) < 5000);
   
    rt_thread_mdelay(1000);

    char buff[64];
    fps = (float)fps / ((end - start) / 1000.0);
    snprintf(buff, sizeof(buff), "~%d FPS", fps);
   
    ssd1306_Fill(White);
    ssd1306_SetCursor(2, 18);
    ssd1306_WriteString(buff, Font_11x18, Black);
    ssd1306_UpdateScreen();
}

void ssd1306_TestLine()
{
    ssd1306_Line(1,1,SSD1306_WIDTH - 1,SSD1306_HEIGHT - 1,White);
    ssd1306_Line(SSD1306_WIDTH - 1,1,1,SSD1306_HEIGHT - 1,White);
    ssd1306_UpdateScreen();
    return;
}

void ssd1306_TestRectangle()
{
    uint32_t delta;

    for(delta = 0; delta < 5; delta ++) 
    {
        ssd1306_DrawRectangle(1 + (5*delta),1 + (5*delta) ,SSD1306_WIDTH-1 - (5*delta),SSD1306_HEIGHT-1 - (5*delta),White);
    }
    ssd1306_UpdateScreen();
    return;
}

void ssd1306_TestCircle()
{
    uint32_t delta;

    for(delta = 0; delta < 5; delta ++) 
    {
        ssd1306_DrawCircle(20* delta+30, 30, 10, White);
    }
    ssd1306_UpdateScreen();
    return;
}

void ssd1306_TestArc()
{
    ssd1306_DrawArc(30, 30, 30, 20, 270, White);
    ssd1306_UpdateScreen();
    return;
}

void ssd1306_TestPolyline()
{
    SSD1306_VERTEX loc_vertex[] =
    {
        {35,40},
        {40,20},
        {45,28},
        {50,10},
        {45,16},
        {50,10},
        {53,16}
    };

    ssd1306_Polyline(loc_vertex,sizeof(loc_vertex)/sizeof(loc_vertex[0]),White);
    ssd1306_UpdateScreen();
    return;
}

void ssd1306_TestAll()
{
    ssd1306_Init();

    ssd1306_TestFPS();
    rt_thread_mdelay(3000);

    ssd1306_TestBorder();

    ssd1306_TestFonts();
    rt_thread_mdelay(3000);

    ssd1306_Fill(Black);
    ssd1306_TestRectangle();
    ssd1306_TestLine();
    rt_thread_mdelay(3000);

    ssd1306_Fill(Black);
    ssd1306_TestPolyline();
    rt_thread_mdelay(3000);

    ssd1306_Fill(Black);
    ssd1306_TestArc();
    rt_thread_mdelay(3000);

    ssd1306_Fill(Black);
    ssd1306_TestCircle();
    rt_thread_mdelay(3000);

    ssd1306_Fill(Black);
    ssd1306_SetCursor(0, 0);
    ssd1306_WriteString("MCU:D133CBS", Font_11x18, White);
    ssd1306_SetCursor(0, 20);
    ssd1306_WriteString("I2C:OLED", Font_11x18, White);
    ssd1306_UpdateScreen();
    rt_thread_mdelay(3000);
}

#ifdef FINSH_USING_MSH
MSH_CMD_EXPORT(ssd1306_TestAll, test ssd1306 oled driver);
#endif

4.2、ssd1306_tests.h

/*
 * Copyright (c) 2020, RudyLo <luhuadong@163.com>
 *
 * SPDX-License-Identifier: MIT License
 *
 * Change Logs:
 * Date           Author       Notes
 * 2020-11-15     luhuadong    the first version
 */

#ifndef __SSD1306_TEST_H__
#define __SSD1306_TEST_H__

#include <_ansi.h>

_BEGIN_STD_C

void ssd1306_TestBorder(void);
void ssd1306_TestFonts(void);
void ssd1306_TestFPS(void);
void ssd1306_TestAll(void);
void ssd1306_TestLine(void);
void ssd1306_TestRectangle(void);
void ssd1306_TestCircle(void);
void ssd1306_TestArc(void);
void ssd1306_TestPolyline(void);



_END_STD_C

#endif // __SSD1306_TEST_H__

5. Program running

After downloading the program, execute ssd1306_TestAll in the serial terminal, and the following video will be displayed

101

This post is from Domestic Chip Exchange
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Featured Posts
ADSL dial-up error code analysis

Error 602 The port is already open The specified port is already openV m |"KNNW,DGuest Problem: The dial-up network can ...

[Detailed and practical] Chinese illustration of every parameter of power MOS tube!

The first part of the maximum rating parameters The maximum rating parameters, all values are obtained under the conditi ...

A set of common codes suitable for small projects

BabyOS Born for small projects, a weak operating system that needs to be fed collectively like a child. Why is it calle ...

TI eSMO library Fsmopos and Gsmopos parameter analysis

Author: Hardy Zhou In terms of motor sensorless control algorithm, TI provides eSMO sliding mode observer to calculate t ...

A very interesting experiment about KVL and Faraday's law of electromagnetic induction

This post was last edited by Buyixin on 2020-11-8 17:49 Question : https://www.bilibili.com/video/BV1ht411U7q7 Resp ...

[Construction Monitoring and Security System] 7. Kaluga Test TCP Client

Since the Kaluga board uses ESP32S2 as the main controller, it is natural to use Wi-Fi. 1. TCP client case The example ...

[Flower carving DIY] Interesting and fun music visualization series of small projects (20) - jewelry box mirror lamp

I suddenly had the urge to do a series of topics on music visualization. This topic is a bit difficult and covers a wide ...

Very good LATTICE FPGA learning materials

LATTICE DIAMOND user guide, very helpful for beginners

【Xianji HPM5361】Clion build download debugger

【HPM5361】Build, download and debug the program under Clion This article demonstrates how to use Clion in a Windows en ...

Temperature acquisition based on STC8H8K64U and DS18B20 and display on LabVIEW host computer

Previously, the ambient temperature was collected and displayed on the serial port through the STC microcontroller and ...

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list