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.

  • Hi 

    If I understand you correctly only the original 0xFFFF (white) data is displayed?

    Have you used the debugger to check what is stored in the image_received buffer before the nrf_gfx_background_set command is run?

    How do you declare the image_received buffer?

    On a side note I would consider rewriting the loop function like this for clarity and efficiency:

    for(int i = 2; i < 'length'; i += 4)
    {
        red = array_data[i];
        green = array_data[i + 1];
        blue = array_data[i + 2];
        
        // Do processing
    }

    Best regards
    Torbjørn

  • 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,[...] }

  • Hi, sorry for my late answer and thanks for your reply.

    Yes, I try to display image_received, but this array is changed when I receive data.

    I don't know how can I check what is stored in image_received with the debugger. Do you have an idea?

  • i have a bmp image (320 x 240) and i want to transform it to C matrix array of 16bit (320 x 240).

    how did you do that?

Related