Adafruit sharp module

Status
Not open for further replies.
Here is still code that updates the whole screen with random data (noise). According to the display specifications 2 MHz is max SPI clock, but tested it up to 16 MHz, there is clearly starts to have problems, 10 MHz seems to work fine but not sure if it would cause damage on long run.

with 2 MHz the update for the whole screen is 18 fps, faster if less lines are updated.

with 10 MHz ca. 83 fps :0

Code:
#include <SPI.h>
#define CS 10


// write line command 0x80, reversed 0x01
// clear memory command 0x20, reversed 0x04
// static mode command 0x00 
// VCOM bit 0x40 , reversed 0x02

byte Vcom;
byte Line;
uint32_t synchTime;

void setup() {
  
  pinMode (CS, OUTPUT);
  SPI.begin(); 
  SPI.beginTransaction(SPISettings(2000000, LSBFIRST, SPI_MODE0));
  clearDisplay();  
}

void loop() {
  
  Vcom = Vcom ? 0x00 : 0x02;

  //clearDisplay();
  drawScreen(0, 240);

  Serial.print("Frame rate: ");Serial.print(1000/(millis()-synchTime)); Serial.println(" fps");
  synchTime = millis();
  
}

void drawScreen(byte firstLine, byte lastLine) {
  byte lineData[50];
  digitalWrite(CS,HIGH);
  SPI.transfer(0x01 | Vcom);//Command
  for (int y = firstLine; y <= lastLine; y++) 
  { 
  SPI.transfer(y); //line number
  for (int x = 0; x <50; x++) { lineData[x] = random(255);}//data for one line
  SPI.transfer(lineData, 50);
  SPI.transfer(0x00); //Trailer for line
  }
  SPI.transfer(0x00); //Trailer for screen
  digitalWrite(CS,LOW);
}


void clearDisplay() {
  digitalWrite(CS,HIGH);
  SPI.transfer(0x04 | Vcom);
  SPI.transfer(0x00);
  digitalWrite(CS,LOW);
}
 
Last edited:
The electrical connection

Screenshot 2021-05-05 at 10.54.58.jpg

Screenshot 2021-05-05 at 10.55.35.jpg
 
This is highly optimised and running at 10MHz SPI clock, drawing just the lines that have updates, drawing a 4x14 pixel block that moves just 1 pixel at every update, the video is slowed down with iPhone7, not sure of the ration , nyt the display update rate is above 1000 fps.


Code:
#include <SPI.h>
#define CS 10

uint8_t screenData[50][240];//50 holds 8 x 50 = 400 B/W pixels

// write line command 0x80, reversed 0x01
// clear memory command 0x20, reversed 0x04
// static mode command 0x00 
// VCOM bit 0x40 , reversed 0x02

uint8_t Vcom;
uint8_t Line;
uint32_t synchTime;
bool  pixStat;
uint8_t xByte;
uint8_t xBit;
bool pix;
uint16_t Pix_x=16;
uint8_t  Pix_y=4;

void setup() {
  
  pinMode (CS, OUTPUT);
  SPI.begin(); 
  //2MHz is officially supported max, may break someting above but 10 MHz seems to work
  //test at your own risk.
  SPI.beginTransaction(SPISettings(2000000, LSBFIRST, SPI_MODE0));
  clearDisplay();  
  for (int y = 0; y <= 240; y++)  { for (int x = 0; x < 50; x++) {screenData[x][y]=0xFF; }}
}

void loop() {
  
  Vcom = Vcom ? 0x00 : 0x02;


  Pix_x++;
  if (Pix_x > 390) { Pix_x = 16; Pix_y++;}
  if (Pix_y > 230) { Pix_x = 16; Pix_y = 4;}

  


     pix     = true;  //bright
     pixelsSet(Pix_x-14, Pix_y, pix);
     pixelsSet(Pix_x-14, Pix_y+1, pix);
     pixelsSet(Pix_x-14, Pix_y+2, pix);
     pixelsSet(Pix_x-14, Pix_y+3, pix);
     pixelsSet(Pix_x-14, Pix_y+4, pix);
     pix     = false;  //dark
     pixelsSet(Pix_x, Pix_y, pix);
     pixelsSet(Pix_x, Pix_y+1, pix);
     pixelsSet(Pix_x, Pix_y+2, pix);
     pixelsSet(Pix_x, Pix_y+3, pix);
     pixelsSet(Pix_x, Pix_y+4, pix);

  //delay(1);
 
  //clearDisplay();
  drawScreen(Pix_y, Pix_y+4);

  Serial.print("Frame rate: ");Serial.print(1000/(millis()-synchTime)); Serial.println(" fps");
  synchTime = millis();
  
}

void drawScreen(uint8_t firstLine, uint8_t lastLine) {
  uint8_t lineData[50];
  digitalWrite(CS,HIGH);
  SPI.transfer(0x01 | Vcom);//Command
  for (int y = firstLine; y <= lastLine; y++) 
  { 
  SPI.transfer(y); //line number
  for (int x = 0; x <50; x++) { lineData[x] = screenData[x][y];}//data for one line
  SPI.transfer(lineData, 50);
  SPI.transfer(0x00); //Trailer for line
  }
  SPI.transfer(0x00); //Trailer for screen
  digitalWrite(CS,LOW);
}


void clearDisplay() {
  digitalWrite(CS,HIGH);
  SPI.transfer(0x04 | Vcom);
  SPI.transfer(0x00);
  digitalWrite(CS,LOW);
}


void pixelsSet(uint16_t x, uint8_t y, bool pix) {   
  
  xByte   = screenData[x/8][y]; //the byte to manipulate
  xBit    = x%8;                //the bit to manipulate
  pixStat = xByte & bit(xBit);  //is the xbit currently 1 or 0

  //if needed change the pixel to pix
  if(pix == true  && pixStat == false ){ screenData[x/8][y] = bitSet  (xByte, xBit); }
  if(pix == false && pixStat == true  ){ screenData[x/8][y] = bitClear(xByte, xBit); }
  }
 
Last edited:
With the above codes there is still problem with LSB and MSB, it just seems the display mixes both, causing totally unnecessary problems. It apears the line numbers are on different order than rest.
 
Status
Not open for further replies.
Back
Top