Waveshare 1.54 inch with Arduino Zero

Updated on 23 September 2022
dev board RobotDyn M0 mini
firmware Arduino
chip SAMD21
chip Waveshare
features e-paper e-ink SPI
e-paper version 1
This tutorial is more than 1 year old. If the steps below do not work, then please check the latest versions and the documentations of the individual tools used.

Before starting

Dependancies

Ensure the following dependancies are downloaded and available:

Pre-requisites

Try these simpler or similar examples:

Code

Download code waveshare-1in54-e-paper-samd21g.ino
#include <Arduino.h>
#include <SPI.h>
#include "epd1in54.h"
#include "epdpaint.h"

#define COLORED     0
#define UNCOLORED   1

unsigned char image[1024];
Paint paint(image, 0, 0);
Epd epd;
int count = 0;
char count_string[] = {'0', '0', '0', '\0'};

void setup() {
  SerialUSB.begin(9600);
  while (!SerialUSB) { }
  SerialUSB.println("Start E-ink display...");
}

void loop() {
  sprintf(count_string, "%d", ++count);
  SerialUSB.println(count_string);

  if (epd.Init(lut_full_update) != 0) {
    SerialUSB.print("e-Paper init failed");
    return;
  }

  epd.ClearFrameMemory(0xFF);
  epd.DisplayFrame();
  epd.ClearFrameMemory(0xFF);
  epd.DisplayFrame();

  paint.SetRotate(ROTATE_0);
  paint.SetWidth(200);
  paint.SetHeight(24);

  paint.Clear(UNCOLORED);
  paint.DrawStringAt(10, 4, count_string, &Font16, COLORED);
  epd.SetFrameMemory(
    paint.GetImage(), 0, 50, paint.GetWidth(), paint.GetHeight());

  epd.DisplayFrame();

  delay(2000);
  epd.Sleep();
}

Makefile

BOARD?=arduino:samd:mzero_bl
PORT := $(shell ls /dev/cu.usbmodem*)

.PHONY: default lint all flash clean

default: all flash clean

lint:
	cpplint --extensions=ino --filter=-legal/copyright *.ino

all:
	arduino-cli compile --fqbn $(BOARD) ./

flash:
	arduino-cli upload -p $(PORT) --fqbn $(BOARD)

clean:
	rm -r build

Prototype

A photo of the actual setup.

Waveshare 1.54 inch with Arduino Zero prototype

Schematic

Wire up the hardware accordingly

Waveshare 1.54 inch with Arduino Zero schematic

Serial console

Serial output from the firmware.

Waveshare 1.54 inch with Arduino Zero serial console

Description

Version

Check the version of the Waveshare module and use the example code for version 1 and version 2 accordingly.

SPI

The 4 non-SPI pins are defined in epdif.h file:

#define RST_PIN         8
#define DC_PIN          9
#define CS_PIN          10
#define BUSY_PIN        7

The SPI pins for Arduino M0 / SAMD21G are defined as following:

SAMD21G Pin I/O Pin SERCOM-ALT Name
19 PB10 SERCOM4/PAD[2] MOSI
20 PB11 SERCOM4/PAD[3] SCK

Pins

Arduino Zero Waveshare E-Ink module SAMD21G
D7 BUSY PA21
D8 RST PA06
D9 DC PA07
D10 CS PA18
CLK SCK on ICSP connector PB11
DIN COPI on ISCP connector PB10

References

Watch