Ingo LohsScruffR
Published © LGPL

Interfacing a serial Display 128x64 b/w with Particle Photon

Itead Studio #DIS008

IntermediateProtip1 hour89

Things used in this project

Hardware components

Itead Display 128x64 black/white
×1
Jumper wires (generic)
Jumper wires (generic)
8 pieces female/female connected direct to the Particle Photon
×1
Photon
Particle Photon
×1

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Code

ST7565 Lib for Particle

C/C++
#include "ADAFRUIT_ST7565.h"

const int pinSI   = MOSI;   // SPI Slave In - A5 - PIN 13  
const int pinSCLK = SCK;    // SPI Clock    - A3 . PIN 12  
const int pinBLA  = TX;     // Back Licht (PWM)  - PIN 16 output
const int pinRS   = A7;     // Register Select   - PIN WKP 
const int pinCS   = A2;     // Chip Select       - PIN  1
const int pinRES  = RX;     // Reset             - PIN  2 
// PIN 14 VDD <> 3V3
// PIN 15 VSS <> GND

ST7565 glcd(pinSI, pinSCLK, pinRS, pinRES, pinCS);

#define LOGO16_GLCD_HEIGHT 16
#define LOGO16_GLCD_WIDTH  16


//Define ST7565_HSPI to use default SPI Port
//Define ST7565_HSPI1 to use SPI1
//Comment this out if you want to use software SPI
#define ST7565_HSPI

//SYSTEM_MODE(SEMI_AUTOMATIC);

// a bitmap of a 16x16 fruit icon
const static unsigned char __attribute__ ((progmem)) logo16_glcd_bmp[]={
0x30, 0xf0, 0xf0, 0xf0, 0xf0, 0x30, 0xf8, 0xbe, 0x9f, 0xff, 0xf8, 0xc0, 0xc0, 0xc0, 0x80, 0x00,
0x20, 0x3c, 0x3f, 0x3f, 0x1f, 0x19, 0x1f, 0x7b, 0xfb, 0xfe, 0xfe, 0x07, 0x07, 0x07, 0x03, 0x00, };


void setBL() {
  static int8_t  delta = +10;
  static uint8_t val = 2*delta;
  
  val += delta;
  if (val <= abs(delta) || (255 - abs(delta)) <= val)
    delta *= -1;
    
  analogWrite(pinBLA, val);
}

Timer timBL(100, setBL);

void setup(){
  Particle.function("setContrast", setContrast);
  pinMode(pinBLA, OUTPUT);
  //timBL.start();
    analogWrite(pinBLA, 255);


//	RGB.control(true);

	uint8_t xpos = 44;

	// initialize and set the contrast to 0x18
	glcd.begin(0x18);
	glcd.st7565_set_brightness(128);
	glcd.drawstring(xpos, 1, "Current");
	glcd.display(); // show splashscreen
	delay(1000);
	/*for(xpos;xpos<50;xpos++){
		glcd.drawstring(xpos,1,"current");
		char *intStr;
		itoa(xpos,intStr,10);
		glcd.drawstring(0,0,intStr);
		glcd.display();
		delay(1000);
	}*/

	glcd.display();
	glcd.clear();

	// draw a single pixel
	glcd.setpixel(10, 10, BLACK);
	glcd.display();        // show the changes to the buffer
	delay(2000);
	glcd.clear();

	// draw many lines
	testdrawline();
	glcd.display();       // show the lines
	delay(2000);
	glcd.clear();

	// draw rectangles
	testdrawrect();
	glcd.display();
	delay(2000);
	glcd.clear();

	// draw multiple rectangles
	testfillrect();
	glcd.display();
	delay(2000);
	glcd.clear();

	// draw mulitple circles
	testdrawcircle();
	glcd.display();
	delay(2000);
	glcd.clear();

	// draw a black circle, 10 pixel radius, at location (32,32)
	glcd.fillcircle(32, 32, 10, BLACK);
	glcd.display();
	delay(2000);
	glcd.clear();

	// draw the first ~120 characters in the font
	testdrawchar();
	glcd.display();
	delay(2000);
	glcd.clear();

	// draw a string at location (0,0)
	glcd.drawstring(0, 0, "Ingo Lohs gruesst auf diesem Wege ganz herzlich und dankt fuer den Scruff-Support");
	glcd.display();
	delay(2000);
	glcd.clear();

	// draw a bitmap icon and 'animate' movement
	testdrawbitmap(logo16_glcd_bmp, LOGO16_GLCD_HEIGHT, LOGO16_GLCD_WIDTH);
}

void loop(){
    // draw a string at location (0,0)
	glcd.drawstring(0, 0, "Ingo Lohs gruesst auf diesem Wege ganz herzlich und dankt fuer den Scruff-Support");
	glcd.display();
	
}


#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2

void testdrawbitmap(const uint8_t *bitmap, uint8_t w, uint8_t h) {
  uint8_t icons[NUMFLAKES][3];
  randomSeed(666);     // whatever seed

  // initialize
  for (uint8_t f=0; f< NUMFLAKES; f++) {
    icons[f][XPOS] = random(128);
    icons[f][YPOS] = 0;
    icons[f][DELTAY] = random(5) + 1;
  }

  while (1) {
    // draw each icon
    for (uint8_t f=0; f< NUMFLAKES; f++) {
      glcd.drawbitmap(icons[f][XPOS], icons[f][YPOS], logo16_glcd_bmp, w, h, BLACK);
    }
    glcd.display();
    delay(200);

    // then erase it + move it
    for (uint8_t f=0; f< NUMFLAKES; f++) {
      glcd.drawbitmap(icons[f][XPOS], icons[f][YPOS],  logo16_glcd_bmp, w, h, 0);
      // move it
      icons[f][YPOS] += icons[f][DELTAY];
      // if its gone, reinit
      if (icons[f][YPOS] > 64) {
	icons[f][XPOS] = random(128);
	icons[f][YPOS] = 0;
	icons[f][DELTAY] = random(5) + 1;
      }
    }
  }
}


void testdrawchar(void) {
  for (uint8_t i=0; i < 168; i++) {
    glcd.drawchar((i % 21) * 6, i/21, i);
  }
}

void testdrawcircle(void) {
  for (uint8_t i=0; i<64; i+=2) {
    glcd.drawcircle(63, 31, i, BLACK);
  }
}


void testdrawrect(void) {
  for (uint8_t i=0; i<64; i+=2) {
    glcd.drawrect(i, i, 128-i, 64-i, BLACK);
  }
}

void testfillrect(void) {
  for (uint8_t i=0; i<64; i++) {
      // alternate colors for moire effect
    glcd.fillrect(i, i, 128-i, 64-i, i%2);
  }
}

void testdrawline() {
  for (uint8_t i=0; i<128; i+=4) {
    glcd.drawline(0, 0, i, 63, BLACK);
  }
  for (uint8_t i=0; i<64; i+=4) {
    glcd.drawline(0, 0, 127, i, BLACK);
  }

  glcd.display();
  delay(1000);

  for (uint8_t i=0; i<128; i+=4) {
    glcd.drawline(i, 63, 0, 0, WHITE);
  }
  for (uint8_t i=0; i<64; i+=4) {
    glcd.drawline(127, i, 0, 0, WHITE);
  }
}

int setContrast(const char* arg) {
  int contrast = constrain(atoi(arg), 0, 255);
  glcd.st7565_set_brightness(contrast);
  return contrast;
}

Credits

Ingo Lohs

Ingo Lohs

48 projects • 156 followers
I am well over 40 years and come from the middle of Germany.
ScruffR

ScruffR

3 projects • 3 followers

Comments