Adafruit SSD1351 1.5'' bitmap display using arduino due

Post test messages here

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
vinnu1993
 
Posts: 2
Joined: Thu Jul 30, 2015 1:02 pm

Adafruit SSD1351 1.5'' bitmap display using arduino due

Post by vinnu1993 »

Hello everyone,
I am new to this forum and adafruit products. I am trying to draw a bitmap from PROGMEM. My 128x128 16 bit bmp has three strokes: RED BLUE and GREEN. My code works fine and I can see the strokes. BLUE stroke comes perfectly. However the Green stroke comes as RED and the RED as black. I tried to modify the code several times but I am not able to get rid of this issue. I will post my code below. The hex values are generated usinf LCD image converter for bitmap PROGMEM.
NOTE: when the same image is read from the SD card it outputs perfectly without any of the above stated issue.
Thanks,
Vishnu

Code: Select all

#include <Adafruit_GFX.h>
#include <Adafruit_SSD1351.h>
#include <SD.h>
#include <SPI.h>


// If we are using the hardware SPI interface, these are the pins (for future ref)
#define sclk 13
#define mosi 11
#define cs   5
#define rst  6
#define dc   4

// Color definitions
#define  BLACK           0x0000
#define BLUE            0x001F
#define RED             0xF800
#define GREEN           0x7E0
#define CYAN            0x07FF
#define MAGENTA         0xF81F
#define YELLOW          0xFFE0  
#define WHITE           0xFFFF

// to draw images from the SD card, we will share the hardware SPI interface
Adafruit_SSD1351 tft = Adafruit_SSD1351(cs, dc, rst);
 static prog_char PROGMEM lily128[]= {                        0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xf800, 0xf800, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, .............(16384 elements)
    


};
void setup() {
  
Serial.begin(9600);
tft.begin();

drawBitmap(lily128,128,128,0,0);

}

void loop() {
  

}
void drawBitmap( prog_char *bitmap, int width, int height, int at_x, int at_y)
{
    uint16_t r=0,g=0,b=0,k;
    k=0;
    uint16_t pixel;
    for (int i=0; i<height; i++)
    {
        for (int j=0; j<width; j++)
        {k=(j*width)+i;
             pixel = pgm_read_word(bitmap);
            bitmap++;
        
          r   =  (unsigned char)((pixel & RED));
          
         g =  ((pixel & GREEN));
           b  =  ((pixel & BLUE));
            
    tft.drawPixel(at_x+j,at_y+i,tft.Color565(r,g,b));     
   
       
        }
    }
}


User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Adafruit SSD1351 1.5'' bitmap display using arduino due

Post by adafruit_support_rick »

Code: Select all

             pixel = pgm_read_word(bitmap);
            bitmap++;
        
          r   =  (unsigned char)((pixel & RED));
          
         g =  ((pixel & GREEN));
           b  =  ((pixel & BLUE));
            
    tft.drawPixel(at_x+j,at_y+i,tft.Color565(r,g,b));     
Is your image already 16-bit color? The code you have written assumes that it is already 16-bit 565 RGB color. You take the 565 rgb apart, and then put it back together again, so that code is redundant.

If your image is NOT 16-bit 565 rgb, then you will have to do something different to separate out the colors.

What is the format of the image data?

User avatar
vinnu1993
 
Posts: 2
Joined: Thu Jul 30, 2015 1:02 pm

Re: Adafruit SSD1351 1.5'' bitmap display using arduino due

Post by vinnu1993 »

Hello,
So yes the image is 16 bit and i have tried passing it directly like this:

Code: Select all

tft.drawPixel(at_x+j,at_y+i,pixel);

yet it gives the same output.
The image format is 16 bit 128x128 565RGB bitmap
Everything is visible except for exchange in colours. Also I figured that 0xF800 gives black and 0xF80 gives red. This is another issue which I think is causing this.
Regards

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Adafruit SSD1351 1.5'' bitmap display using arduino due

Post by adafruit_support_rick »

I think you have a data type problem. Change the data type of the bitmap to this:

Code: Select all

 static uint16_t PROGMEM lily128[]= {                        0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 
Also, change the type in the drawBitmap function:

Code: Select all

void drawBitmap( uint16_t *bitmap, int width, int height, int at_x, int at_y)
You have the bitmap typed as char, but you're trying to initialize it with 16-bit unsigned values.

In drawBitmap, if bitmap is typed as char, then bitmap++ will not increment to the next 16-bit value, it will increment to the next 8-bit value.

Locked
Please be positive and constructive with your questions and comments.

Return to “Test Message Forum (closed)”