Interfacing OLED SSD1306 with nRF52832 on Zephyr

Subject: Query: Interfacing OLED SSD1306 with nRF52832 on Zephyr

Dear Zephyr Dev Zone Community,

I hope this message finds you well. I am currently working on a project that involves interfacing an OLED SSD1306 display with an nRF52832 microcontroller using the Zephyr RTOS. I have encountered some challenges during the integration process and would greatly appreciate your assistance in resolving them.

Specifically, I am facing issues with initializing and communicating with the OLED SSD1306 display through the nRF52832 microcontroller. Despite following the documentation and examples available, I have been unable to achieve successful communication and display output.

Here are some key details about my setup and the issues I'm encountering:

  1. Hardware Setup:

    • OLED SSD1306 display (specify model/version if applicable)
    • nRF52832 microcontroller development board
    • Connections made using (I2C/SPI) interface
    • Power supply and wiring configurations
  2. Software Environment:

    • Zephyr RTOS version: [Specify version]
    • Development environment/tools used: [Specify IDE, SDK, etc.]
    • Relevant code snippets/configuration files: [Provide snippets of initialization code, device tree configuration, etc.]
  3. Issues Encountered:

    • Initialization problems: Difficulty initializing the OLED display driver.
    • Communication errors: Unable to establish communication between the microcontroller and the OLED display.
    • Display output: No output or incorrect display output observed on the OLED screen.

I would greatly appreciate any guidance, tips, or insights you can provide to help me overcome these challenges and successfully interface the OLED SSD1306 display with the nRF52832 microcontroller on the Zephyr RTOS.

Thank you very much for your time and assistance. I look forward to your valuable input and suggestions.

Best regards, Aman

Parents Reply Children
  • /*overlay file*/
    &arduino_i2c {                                                                                
        status = "okay";  
        compatible = "nordic,nrf-twi";                                                                  
      //  zephyr,concat-buf-size = <2048>;                                                      
                                                                                             
        ssd1306fb: ssd1306fb@3c {                                                                          
                compatible = "solomon,ssd1306fb";                                            
                reg = <0x3c>;                                                                
                label = "SSD1306";                                                            
                width = <128>;                                                                
                height = <64>;                                                                
                segment-offset = <0>;                                                        
                page-offset = <0>;                                                            
                display-offset = <0>;                                                        
                multiplex-ratio = <63>;                                                      
                segment-remap;                                                                
                com-invdir;
                inversion-on;                                                                  
                prechargep = <0x22>;                                                          
        };                                                                                    
    };
  • /*prj*/

    CONFIG_GPIO=y
    
    CONFIG_HEAP_MEM_POOL_SIZE=16384
    CONFIG_MAIN_STACK_SIZE=4096
    
    CONFIG_DEBUG_OPTIMIZATIONS=y
    CONFIG_ASSERT=y
    
    CONFIG_I2C=y
    
    CONFIG_DISPLAY=y
    CONFIG_DISPLAY_LOG_LEVEL_DBG=y
    # CONFIG_LOG_STRDUP_BUF_COUNT=
    
    CONFIG_SSD1306=y
    CONFIG_SSD1306_REVERSE_MODE=y
    # CONFIG_SSD1306_SH1106_COMPATIBLE=n
    
    CONFIG_LOG=y
    
    # Console
    CONFIG_CONSOLE=y
    CONFIG_UART_CONSOLE=y
    CONFIG_STDOUT_CONSOLE=y
    CONFIG_PRINTK=y
    CONFIG_EARLY_CONSOLE=y
    CONFIG_USE_SEGGER_RTT=y
    CONFIG_RTT_CONSOLE=y
    
    # CFB
    CONFIG_CFB_LOG_LEVEL_DBG=y
    CONFIG_CHARACTER_FRAMEBUFFER=y
  • /*main*/
    #include <zephyr/zephyr.h>
    #include <zephyr/device.h>
    #include <zephyr/drivers/display.h>
    #include <zephyr/display/cfb.h>
    #include <stdio.h>
    #define FRAMEBUFFER_SIZE_MULTIPLIER 2
    
    void main()
    {
    const struct device *dev;
    uint8_t font_width;
    uint8_t font_height;
    uint16_t display_width;
    uint16_t display_height;
    // struct char_framebuffer *fb = &char_fb;
    
    dev = device_get_binding("SSD1306");
    
    if (dev == NULL)
    {
    printk("Device not found\n");
    return;
    }
    
    if (display_set_pixel_format(dev, PIXEL_FORMAT_MONO10) != 0)
    {
    printk("Failed to set required pixel format\n");
    return;
    }
    
    printk("initialized %s\n", "SSD1306");
    
    if (cfb_framebuffer_init(dev))
    {
    printk("Framebuffer initialization failed!\n");
    return;
    }
    
    // fb->size = fb->x_res * fb->y_res / fb->ppt * FRAMEBUFFER_SIZE_MULTIPLIER;
    
    int err = (cfb_framebuffer_clear(dev, true));
    // printk("%d\n", err);
    cfb_framebuffer_invert(dev);
    display_blanking_off(dev);
    
    if (cfb_get_font_size(dev, 0, &font_width, &font_height))
    {
    printk("Failed to get font size\n");
    return;
    }
    
    display_width = cfb_get_display_parameter(dev, CFB_DISPLAY_WIDTH);
    display_height = cfb_get_display_parameter(dev, CFB_DISPLAY_HEIGH);
    
    const char *text = "Hello, World!";
    const uint16_t text_width = font_width;
    const uint16_t text_height = font_height;
    
    // Adjust starting position to display text at the bottom
    const uint16_t *start_x = (display_width - text_width)/2;
    const uint16_t *start_y = display_height - text_height/2;
    
    printk("start_x=%d\n", start_x);
    printk("start_y=%d\n", start_y);
    
    if (cfb_draw_text(dev, text, start_x, start_y))
     {
    printk("Failed to print string\n");
    return;
    }
    
    // cfb_invert_area(dev,0, 22,text_width,text_height);
     cfb_framebuffer_finalize(dev); // display_blanking_on(dev);
    }
Related