This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

display image sent over Bluetooth

Hi,

I want to display an image sent over Bluetooth on my screen which uses the driver st7735. So I have an application which can send images, and I receive data in the function nus_data_handler. With this application, I send array of 20 data (two first and last data are control data to know that an image is sent). The data sent are 4bytes for 1 pixel so RGBα, and 8 bites for red, 8 for green, 8 for blue and 8 for alpha. I display an image with the function nrf_gfx_bmp565_draw, so pixel format is RGB565. When I received data (R, G, and B), I convert these 3 data to one and transform them to RGB565 with this:

RGB16(red, green, blue) (((red >> 3) << 11) | ((green >> 2) << 5) | (blue >> 3))

I don't care about α for the conversion. After, I have the value of one pixel. I need to save this pixel value, so I created an array image_received of the image size (80x160 = 12800) with all element are 0xFFFF (white) in another file include in main.c. When I have the value of one pixel, I replace the element of image_received by this value. So at the end, I should have in image_received the image received by Bluetooth. When I try to display image_received, it doesn't work: it is the image of the beginning which is displayed, image_received is not updated. Here is my code who receive and display data.

if (p_evt->type == BLE_NUS_EVT_RX_DATA) {
    uint32_t err_code;
    NRF_LOG_DEBUG("Received data from BLE NUS. Writing data on UART.");
    NRF_LOG_HEXDUMP_DEBUG(p_evt->params.rx_data.p_data, p_evt->params.rx_data.length);
    printf("Received rx of length:%d\r\n", p_evt->params.rx_data.length);
    int pixel, red = -1, green = -1, blue = -1;
    for (int i = 0; i < p_evt->params.rx_data.length; i++) {
      printf("debug received %d at %d\r, i %d\n", p_evt->params.rx_data.p_data[i], p_evt->params.rx_data.length,i);
      array_data[i]=p_evt->params.rx_data.p_data[i];
      if ((i==2)|(i==6)|(i==10)){ 
          red = array_data[i];
          //printf("red %d \n", red);
      }
       if ((i==3)|(i==7)|(i==11)){ 
              green =array_data[i];
              //printf("green %d \n", green);
      }
      if ((i==4)|(i==8)|(i==12)){ //green ||(i==8)||(i=12)||(i==16))
              blue =array_data[i];
             // printf("blue %d \n", blue);
              pixel = RGB16(red, green, blue); //convert rdb24 to rgb16
             // printf("pixel %d \n", pixel);
              
              image_received[cpt_pixel] = pixel;
             // printf("valeur image %d \n", image_received[cpt_pixel]);
              cpt_pixel ++;
              printf("cpt pixel %d \n", cpt_pixel);
                         
      }
   if ((cpt_pixel == 100)|(cpt_pixel==150)|(cpt_pixel==200)){
      screen_clear(BLACK);
      nrf_gfx_background_set(p_lcd, (uint16_t const*)image_received);
      printf("display !!");
   }
   }

So I don't know how can I display an image sent over Bluetooth. On the internet, I only find answers to display an image on the application sent by nrf52; but my issue is the other way around. I think it's better to send data received in flash memory, so I can send an array with sd_flash_write, but I still have to stock data in image_received and after reading into the flash and display, but I don't know how to do it.

I use nrf 52832, with PCA10040, s 132, sdk15.3 and Segger embedded.

Parents
  • hi Iydie

    can you share the code or explain how you used the nrf_gfx_bmp565_draw function. im trying to display an image on my LCD with than function without any success.

    thanks

  • HI,

    I still can't display an image sent over Bluetooth, but I can display an image shared in a RAM like this:

    nrf_gfx_rect_t rect_step = NRF_GFX_RECT(26, 30,80 , 130);//nrf_gfx_width_get(p_lcd)
    APP_ERROR_CHECK(nrf_gfx_rect_draw(p_lcd, &rect_step, 2, BLACK, false));
    APP_ERROR_CHECK(nrf_gfx_bmp565_draw(p_lcd, &rect_step, step_img));

    The image I want to display is step_img and its format is:

    static const uint16_t step_img[]={
    0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,   // 0x0010 (16)
    0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xFFDE, 0x6308,   // 0x0020 (32)
    0x0000, 0x6310, 0xFFDE, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,   // 0x0030 (48)
    0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,   // 0x0040 (64)
    0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,   // 0x0050 (80)
    0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,   // 0x0060 (96)
    0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xFFFF, 0x0000, 0x0000,   // 0x0070 (112)
    0x0000, 0x0000, 0x2108, 0xFFFF,[...] }

  • the driver is ili9341, which is the same. when i modify the driver to display the image correct then now the text is reversed. wired. about the color - they are different , perhaps the driver is not config to 565

  • I have the same problem with the text. So when I want to display an image, I rotate the screen of 180, I display my image, and I rotate of 180 to return to the original position.

    For the colors, my problem was with nrf_gfx_bmp565_draw. I changed this function by replacing the 2 loops for with:

     uint32_t cpt=0;
    
        for (int32_t i = 0; i < p_rect->height; i++)
        {
            for (uint32_t j = 0; j < p_rect->width; j++)
            {
                cpt++;
                idx = (uint32_t) (p_rect->height)*(p_rect->width)-cpt;
                pixel = img_buf[idx];
                pixel_draw(p_instance, p_rect->x + j, p_rect->y + i, pixel);
                
            }
        }

  • Hi guys

    I made an optimized driver a while back for the Adafruit capacitive touch display, which should also be based on the ILI9341 driver. 

    I replaced many of the single pixel updates with buffer updates to speed up the display operations. 

    The modified drivers can be found in the adafruit_touch_display folder in this repo:
    https://github.com/NordicPlayground/nrf52-ble-multi-link-multi-role/tree/feature_tripple_phy_peripheral

    Feel free to try it out, hopefully it will improve performance also in your application Slight smile

    Best regards
    Torbjørn

  • thanks. a quick question. i want to save an image i create using Photoshop. but when i convert it and import it , the image is distorted and all i get on the LCD is unreadable. do you know what it the process from Photoshop all the way to the LCD (c file)?

  • Hi 

    What format do you save the file as in Photoshop?

    Most likely the problem is with the conversion from an image to a C file. Are you using the program recommended by lydie below?

    Best regards
    Torbjørn

Reply Children
No Data
Related