how to connect waveshare 1.54" e paper screen with samd21

hi guys, i'm new into the arduino world and i am a complete noob.
I'm having trouble understanding how to connect this screen with this m0 board, mostly because of the spi connection, and because i can't find a working library for this board.
this board uses something called sercom to create spi and i2c protocol, as they say in the website -->SAMD21 Mini/Dev Breakout Hookup Guide - learn.sparkfun.com, and i didn't really understand how to use it...

if someone could help me i will be really gratefull, thanks in advice! :stuck_out_tongue_winking_eye:

You first need to find out how your board is usable with the Arduino IDE.
I have just now no time to read the document your link points to.
You add support for Arduino SAMD using the boards manager.

You need to add board information for your board as described in the Hookup Guide.

Then find the board that matches your board here:

C:\Users\xxx\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.17\variants

If you had added the board information of your board, you should find it there.

pins_arduino.h is the file to look at for start; it just includes

variant.h

There you find which pins are used for SPI, and which SERCOM is used.

In your application you usually just use the standard SPI library.

You can adapt the Waveshare demo example to your board, pins in file epdio.h

Or you can try my library GxEPD

Report your progress or your problems; I will try to help.

really thanks a lot for replying to my question, and sorry for the late answer, i'm new to the forum and i tought that it would send me an email or something if someone replied to my message.

i can't find the arduino15 folder in appdata, i searched in every user folder but i'm still unable to find it.
you said that i could use your library, does it support my board?

thanks in advice and sorry for my noobish questions!

I would need to know how you added the package for your m0 board to Arduino IDE.

When adding SAMD support by Board Manager, it should go to the mentioned Appdata path.
Other packages are in .../documents/Arduino/hardware.

GxEPD supports SAMD, but I have only one MKR1000, and can only test with this board.

Continue with more questions, maybe I can help.

yeyy i found the variant.h file!
it was located in C:\Users\xxxxxxx\Documents\ArduinoData\packages\SparkFun\hardware\samd\1.4.0\variants\SparkFun_SAMD_Mini.
inside of it i found the spi part, but i'm still a bit confused, there it is:

/*

  • SPI Interfaces
    */
    #define SPI_INTERFACES_COUNT 1
    // Instead of using SERCOM4, and the SPI-header pins, the Mini Breakout
    // uses pins 10-13 for SPI, on the unused sercom1
    #define PIN_SPI_MISO (12u)
    #define PIN_SPI_MOSI (11u)
    #define PIN_SPI_SCK (13u)
    #define PIN_SPI_SS (10u)
    #define PERIPH_SPI sercom1
    // Pad Map: 0 1 2 3
    // MOSI (TX) SCK SS MOSI (RX)
    #define PAD_SPI_TX SPI_PAD_0_SCK_1
    #define PAD_SPI_RX SERCOM_RX_PAD_3

static const uint8_t SS = PIN_SPI_SS;
static const uint8_t MOSI = PIN_SPI_MOSI;
static const uint8_t MISO = PIN_SPI_MISO;
static const uint8_t SCK = PIN_SPI_SCK;

why are the pins numered with a letter near them?

if it can help, there is a pin map for my board: pin map

thanks for the help!

why are the pins numered with a letter near them?

Do you mean the lowercase u at the end of the number?

12u tells the compiler that the number 12 should be treated as unsigned integer.

12u is pin 12 on your board, D12 ~ means it can be used as digital output with pulse width modulation, PA19 tells us it is bit 19 of port A of the processor.

You should update your Arduino IDE to the actual version; then your package would go in AppData.

Jean-Marc

Thanks for the help, I'll try now to use your library.

May you please help me hooking up the board and the screen? I'm a bit confused on what pin to use for what.

Thanks in advice

Can someone please tell me which pin of the screen goes to what pin on the board?
Thanks a lot!

pino70:
Can someone please tell me which pin of the screen goes to what pin on the board?
Thanks a lot!

@pino70

Ok, you seem to need more help than I have expected.

Lets start with the connection for MKR1000, as provided in the example GxEPD_SPI_TestExample:

// this comment is added to know the parameter sequence
// GxIO_SPI(SPIClass& spi, int8_t cs, int8_t dc, int8_t rst = -1, int8_t bl = -1);
// GxGDEP015OC1(GxIO& io, uint8_t rst = 9, uint8_t busy = 7);

GxIO_Class io(SPI, 4, 7, 6);
GxEPD_Class display(io, 6, 5);

This translates to the following connection mapping:

// mapping suggestion for SAMD21, e.g. MKR1000, see .../variants/.../pins_arduino.h for your board
// NOTE: there are variants with different pins for SPI ! CHECK SPI PINS OF YOUR BOARD
// BUSY -> 5, RST -> 6, DC -> 7, CS -> SS(4), CLK -> SCK(9), DIN -> MOSI(8), GND -> GND, 3.3V -> 3.3V

Now we need to adapt to your board:

#define PIN_SPI_MISO         (12u)
#define PIN_SPI_MOSI         (11u)
#define PIN_SPI_SCK          (13u)
#define PIN_SPI_SS           (10u)
#define PERIPH_SPI           sercom1
// mapping suggestion for SAMD21, e.g. SparkFun SAMD21 Mini Breakout, see .../variants/.../pins_arduino.h for your board
// NOTE: there are variants with different pins for SPI ! CHECK SPI PINS OF YOUR BOARD
// BUSY -> 5, RST -> 6, DC -> 7, CS -> SS(10), CLK -> SCK(13), DIN -> MOSI(11), GND -> GND, 3.3V -> 3.3V

Only SCK and MOSI are fixed by mapping selected in the HW SPIClass (SERCOM is flexible), all other pins can be freely chosen, as long they do not conflict with other uses.

Jean-Marc

ok, i have connected the following screen pin with the following board pin:

screen board
busy D5
rst D6
dc D7
cs D10
clk D13
din D11
gnd gnd
3.3V vcc (with a multimeter I measured it and it gives 3.20v to the screen)

now, i tried looking up the code, but it uses some words that i have never used in c++ so i dont really understand it, for example #if defined(...) or #elif... may you please give me a little example for this configuration?
just to initializate the screen, for the rest i will look at the wiki of your library.

thanks a lot for your help and I am really sorry for wasting your time in some noobish questions.

Following the previous message i managed to make this: GxIO_Class io(SPI, 10, 5, 6);
GxEPD_Class display(io, 6, 5); but i dont really know where to put it.

I have the suspicion that your noobiness is not real. Is this a trap? are you a clone of some already known poster trying to trick me?

Be warned, the moderators know the IP address and can check.

Look in the example GxEPD_SPI_TestExample.ino where the contructors for MKR1000 are, then just change these for your wiring.

i'm not a fake, and why would this be a trap? ask a moderator for my ip if you want, i am really noob, and i am trying to make a watch, i am still studying c++ at school and this is my first year of c++.
i'm sorry if that bothered you or something but i dont have malicious intentions, i just want to learn as much as i want, if you dont believe me i can show you some photos of my project.
anyway, thanks for helping me

ZinggJM:
Look in the example GxEPD_SPI_TestExample.ino where the contructors for MKR1000 are, then just change these for your wiring.

i tried doing that, but it doesn't work, any ideas?

This is a contradiction to your previous post, where you asked where to put the constructors.

i tried doing that, but it doesn't work, any ideas?

No chance to help you if you are not specific enough; what did you try, and what does not work?

GxEPD was never meant for complete noobs, nevertheless many Newbies successfully use it with moderate help needed.

I will no longer answer to this topic. There is a main topic for Waveshare SPI e-papers, where you might get answers from posters with more patience.

i tried using the code that you said to use, i uncommented the model of my display (leaving just one uncommented), and i changed the values in ARDUINO_ARCH_SAMD as you said, i uploaded it but nothing showes up. there is the code:

/************************************************************************************
   GxEPD_SPI_TestExample : test example for e-Paper displays from Dalian Good Display Co., Ltd.: www.good-display.com

   based on Demo Example from Good Display, now available on http://www.good-display.com/download_list/downloadcategoryid=34&isMode=false.html

   Author : J-M Zingg

   Version : 2.0

   Support: limited, provided as example, no claim to be fit for serious use

   connection to the e-Paper display is through DESTM32-S2 connection board, available from Good Display

   DESTM32-S2 pinout (top, component side view):
         |-------------------------------------------------
         |  VCC  |o o| VCC 5V  not needed
         |  GND  |o o| GND
         |  3.3  |o o| 3.3     3.3V
         |  nc   |o o| nc
         |  nc   |o o| nc
         |  nc   |o o| nc
   MOSI  |  DIN  |o o| CLK     SCK
   SS    |  CS   |o o| DC      e.g. D3
   D4    |  RST  |o o| BUSY    e.g. D2
         |  nc   |o o| BS      GND
         |-------------------------------------------------
*/

// Supporting Arduino Forum Topics:
// Waveshare e-paper displays with SPI: http://forum.arduino.cc/index.php?topic=487007.0
// Good Dispay ePaper for Arduino : https://forum.arduino.cc/index.php?topic=436411.0

// mapping suggestion from Waveshare 2.9inch e-Paper to Wemos D1 mini
// BUSY -> D2, RST -> D4, DC -> D3, CS -> D8, CLK -> D5, DIN -> D7, GND -> GND, 3.3V -> 3.3V

// mapping suggestion for ESP32, e.g. LOLIN32, see .../variants/.../pins_arduino.h for your board
// NOTE: there are variants with different pins for SPI ! CHECK SPI PINS OF YOUR BOARD
// BUSY -> 4, RST -> 16, DC -> 17, CS -> SS(5), CLK -> SCK(18), DIN -> MOSI(23), GND -> GND, 3.3V -> 3.3V

// mapping suggestion for AVR, UNO, NANO etc.
// BUSY -> 7, RST -> 9, DC -> 8, CS-> 10, CLK -> 13, DIN -> 11

// include library, include base class, make path known
#include <GxEPD.h>

// select the display class to use, only one
#include <GxGDEP015OC1/GxGDEP015OC1.cpp>    // 1.54" b/w
//#include <GxGDEW0154Z04/GxGDEW0154Z04.cpp>  // 1.54" b/w/r
//#include <GxGDE0213B1/GxGDE0213B1.cpp>      // 2.13" b/w
//#include <GxGDEW0213Z16/GxGDEW0213Z16.cpp>  // 2.13" b/w/r
//#include <GxGDEH029A1/GxGDEH029A1.cpp>      // 2.9" b/w
//#include <GxGDEW029Z10/GxGDEW029Z10.cpp>    // 2.9" b/w/r
//#include <GxGDEW027C44/GxGDEW027C44.cpp>    // 2.7" b/w/r
//#include <GxGDEW042T2/GxGDEW042T2.cpp>      // 4.2" b/w
//#include <GxGDEW075T8/GxGDEW075T8.cpp>      // 7.5" b/w
//#include <GxGDEW075Z09/GxGDEW075Z09.cpp>    // 7.5" b/w/r

// uncomment next line for drawBitmap() test
#include GxEPD_BitmapExamples

// FreeFonts from Adafruit_GFX
#include <Fonts/FreeMonoBold9pt7b.h>
#include <Fonts/FreeMonoBold12pt7b.h>
#include <Fonts/FreeMonoBold18pt7b.h>
#include <Fonts/FreeMonoBold24pt7b.h>


#include <GxIO/GxIO_SPI/GxIO_SPI.cpp>
#include <GxIO/GxIO.cpp>

#if defined(ESP8266)

// generic/common.h
//static const uint8_t SS    = 15;
//static const uint8_t MOSI  = 13;
//static const uint8_t MISO  = 12;
//static const uint8_t SCK   = 14;
// pins_arduino.h
//static const uint8_t D8   = 15;
//static const uint8_t D7   = 13;
//static const uint8_t D6   = 12;
//static const uint8_t D5   = 14;

// GxIO_SPI(SPIClass& spi, int8_t cs, int8_t dc, int8_t rst = -1, int8_t bl = -1);
GxIO_Class io(SPI, SS, D3, D4); // arbitrary selection of D3, D4 selected for default of GxEPD_Class
// GxGDEP015OC1(GxIO& io, uint8_t rst = D4, uint8_t busy = D2);
GxEPD_Class display(io); // default selection of D4, D2
// my IoT connection, busy on MISO
//GxEPD_Class display(io, D4, D6);

#elif defined(ESP32)

// pins_arduino.h, e.g. LOLIN32
//static const uint8_t SS    = 5;
//static const uint8_t MOSI  = 23;
//static const uint8_t MISO  = 19;
//static const uint8_t SCK   = 18;

// GxIO_SPI(SPIClass& spi, int8_t cs, int8_t dc, int8_t rst = -1, int8_t bl = -1);
GxIO_Class io(SPI, SS, 17, 16); // arbitrary selection of 17, 16
// GxGDEP015OC1(GxIO& io, uint8_t rst = D4, uint8_t busy = D2);
GxEPD_Class display(io, 16, 4); // arbitrary selection of (16), 4

#elif defined(ARDUINO_ARCH_SAMD)

// variant.h of MKR1000
//#define PIN_SPI_MISO  (10u)
//#define PIN_SPI_MOSI  (8u)
//#define PIN_SPI_SCK   (9u)
//#define PIN_SPI_SS    (24u) // should be 4?
// variant.h of MKRZERO
//#define PIN_SPI_MISO  (10u)
//#define PIN_SPI_MOSI  (8u)
//#define PIN_SPI_SCK   (9u)
//#define PIN_SPI_SS    (4u)

GxIO_Class io(SPI, 10, 5, 6);
GxEPD_Class display(io, 6, 5);

#elif defined(_BOARD_GENERIC_STM32F103C_H_)

// STM32 Boards (STM32duino.com)
// Generic STM32F103C series
// aka BluePill
// board.h
//#define BOARD_SPI1_NSS_PIN        PA4
//#define BOARD_SPI1_MOSI_PIN       PA7
//#define BOARD_SPI1_MISO_PIN       PA6
//#define BOARD_SPI1_SCK_PIN        PA5
//enum {
//    PA0, PA1, PA2, PA3, PA4, PA5, PA6, PA7, PA8, PA9, PA10, PA11, PA12, PA13,PA14,PA15,
//  PB0, PB1, PB2, PB3, PB4, PB5, PB6, PB7, PB8, PB9, PB10, PB11, PB12, PB13,PB14,PB15,
//  PC13, PC14,PC15
//};
// variant.h
//static const uint8_t SS   = BOARD_SPI1_NSS_PIN;
//static const uint8_t SS1  = BOARD_SPI2_NSS_PIN;
//static const uint8_t MOSI = BOARD_SPI1_MOSI_PIN;
//static const uint8_t MISO = BOARD_SPI1_MISO_PIN;
//static const uint8_t SCK  = BOARD_SPI1_SCK_PIN;

// GxIO_SPI(SPIClass& spi, int8_t cs, int8_t dc, int8_t rst = -1, int8_t bl = -1);
GxIO_Class io(SPI, SS, 8, 9);
// GxGDEP015OC1(GxIO& io, uint8_t rst = 9, uint8_t busy = 7);
GxEPD_Class display(io, 9, 3);

#else

// pins_arduino.h, e.g. AVR
//#define PIN_SPI_SS    (10)
//#define PIN_SPI_MOSI  (11)
//#define PIN_SPI_MISO  (12)
//#define PIN_SPI_SCK   (13)

GxIO_Class io(SPI, SS, 8, 9); // arbitrary selection of 8, 9 selected for default of GxEPD_Class
//GxIO_DESTM32L io;
//GxIO_GreenSTM32F103V io;
GxEPD_Class display(io);

#endif

screen board
busy D5
rst D6
dc D7
cs D10
clk D13
din D11
gnd gnd
3.3V vcc (with a multimeter I measured it and it gives 3.20v to the screen)

GxIO_Class io(SPI, 10, 5, 6);
GxEPD_Class display(io, 6, 5);

don’t you see the error? DC is D7 !

GxIO_Class io(SPI, 10, 7, 6);
GxEPD_Class display(io, 6, 5);

ZinggJM:
don't you see the error? DC is D7 !

GxIO_Class io(SPI, 10, 7, 6);

GxEPD_Class display(io, 6, 5);

i tried doing that but nothing worked, so i tought that the display was somehow broken, i tried hocking it up to an arduino uno using the pins said in the code and it still didn't work, so i used the demo sketch on the waveshare website, and it worked.
after some digging i found a youtube video where a guy was using this display with your library, but the code was different, instead of:

GxIO_Class io(SPI, SS, 8, 9);

he used

GxIO_Class io(SPI, SS, 9, 8);

i changed that in your test code and it worked, what if my samd21 board had the same problem? maybe i have to use different numbers like with the arduino uno, but i dont know which numbers to use

Maybe its the SainSmart Arduno package that causes the issue.
I think I have seen negative comments about SainSmart and their products in this forum.

Bye