Using a cheap Chinese ST7735 type 128x160 display with the TFT_ST7735 library (https://github.com/Bodmer/TFT_ST7735). I'm using an Arduino Mega 2560, hardware SPI.

Example works perfectly, modifying for my own purposes I'm getting an image skewed with digital artifact through it and parts of the image displaying out of order. (Top appears at bottom).

I can't for the life of me work out what's wrong here, image converted with online tool suggested by library from a 140x80 bitmap. I have also tried with the image origin at 0,0.

Main Code:

 #include <TFT_ST7735.h> // Graphics and font library for ST7735 driver chip
#include <SPI.h>
#include "zack14080.h"

TFT_ST7735 tft = TFT_ST7735();  // Invoke library, pins defined in User_Setup.h

void setup()
  tft.setRotation(1);  // landscape


  // Draw the icons
  drawIcon(zack14080,((tft.width()-zack14080Width)/2), ((tft.height()-zack14080Height)/2), zack14080Width, zack14080Height);


void loop()

// This is the function to draw the icon stored as an array in program memory (FLASH)

// To speed up rendering we use a 64 pixel buffer
#define BUFF_SIZE 64

// Draw array "icon" of defined width and height at coordinate x,y
// Maximum icon size is 255x255 pixels to avoid integer overflow

void drawIcon(const unsigned short* icon, int16_t x, int16_t y, int8_t width, int8_t height) {

  uint16_t  pix_buffer[BUFF_SIZE];   // Pixel buffer (16 bits per pixel)

  // Set up a window the right size to stream pixels into
  tft.setAddrWindow(x, y, x + width - 1, y + height - 1);

  // Work out the number whole buffers to send
  uint16_t nb = ((uint16_t)height * width) / BUFF_SIZE;

  // Fill and send "nb" buffers to TFT
  for (int i = 0; i < nb; i++) {
    for (int j = 0; j < BUFF_SIZE; j++) {
      pix_buffer[j] = pgm_read_word(&icon[i * BUFF_SIZE + j]);
    tft.pushColors(pix_buffer, BUFF_SIZE);

  // Work out number of pixels not yet sent
  uint16_t np = ((uint16_t)height * width) % BUFF_SIZE;

  // Send any partial buffer left over
  if (np) {
    for (int i = 0; i < np; i++) pix_buffer[i] = pgm_read_word(&icon[nb * BUFF_SIZE + i]);
    tft.pushColors(pix_buffer, np);

Then the bitmap:

// Generated by   : ImageConverter 565 Online
// Generated from : zack140180.gif
// Time generated : Wed, 02 Oct 19 23:16:32 +0200  (Server timezone: CET)
// Image Size     : 140x80 pixels
// Memory usage   : 22400 bytes

#include <avr/pgmspace.h>
const uint16_t zack14080Width = 140;
const uint16_t zack14080Height = 80;

const unsigned short zack14080[11200] PROGMEM={
0xFFFF, 0xFFFF, 0xFFE6, 0xFEA6, 0x9D4C, 0x9C0C, 0x9D4C, 0x9C06, 0x9C0C, 0x9D4C, 0x9C0C, 0x9D4C, 0xCD46, 0xFFE0, 0xFFEC, 0xFFE6,   // 0x0010 (16) pixels
0xCD4C, 0x9D46, 0x640C, 0x32B3, 0x62AC, 0x9C0C, 0xCEA6, 0xFEA0, 0xFFE0, 0xFFEC, 0xCEA6, 0x9D4C, 0x9C0C, 0x9D4C, 0x9C0C, 0x9C06,   // 0x0020 (32) pixels


Any suggests as to what I'm doing wrong here?

  • which example are you talking about? – jsotola Oct 2 '19 at 22:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.