// GxEPD2_HelloWorld.ino by Jean-Marc Zingg
#include <SPI.h>
#define EPD_BUSY 38
#define EPD_CS 35
#define EPD_RST 37
#define EPD_DC 36
#define EPD_SCK 16
#define EPD_MISO 6 // Master-In Slave-Out not used, as no data from display. Floating.
#define EPD_MOSI 34 // EPD DIN
SPIClass fspi(FSPI);
#include <GxEPD2_BW.h>
//#include <GxEPD2_3C.h>
//#include <GxEPD2_7C.h>
#include <Fonts/FreeMonoBold9pt7b.h>
GxEPD2_BW<GxEPD2_213_B74, GxEPD2_213_B74::HEIGHT> display(GxEPD2_213_B74(/*CS=5*/ EPD_CS, /*DC=*/ EPD_DC, /*RST=*/ EPD_RST, /*BUSY=*/ EPD_BUSY)); // GDEM0213B74 122x250, SSD1680
void setup()
{
SPI.end();
fspi.end();
//_pSPIx.end();
fspi.begin(EPD_SCK, EPD_MISO, EPD_MOSI, EPD_CS); // remap hspi for EPD (swap pins)
// display.epd2.selectSPI(hspi, SPISettings(4000000, MSBFIRST, SPI_MODE0));
display.init(115200, true, 10, false, fspi, SPISettings(4000000, MSBFIRST, SPI_MODE0)); // extended init method with SPI channel and/or settings selection
// display.init(115200, true, 2, false); // USE THIS for Waveshare boards with "clever" reset circuit, 2ms reset pulse
helloWorld();
display.hibernate();
}
const char HelloWorld[] = "Hello World!";
void helloWorld()
{
display.setRotation(1);
display.setFont(&FreeMonoBold9pt7b);
display.setTextColor(GxEPD_BLACK);
int16_t tbx, tby; uint16_t tbw, tbh;
display.getTextBounds(HelloWorld, 0, 0, &tbx, &tby, &tbw, &tbh);
// center the bounding box by transposition of the origin:
uint16_t x = ((display.width() - tbw) / 2) - tbx;
uint16_t y = ((display.height() - tbh) / 2) - tby;
display.setFullWindow();
display.firstPage();
do
{
display.fillScreen(GxEPD_WHITE);
display.setCursor(x, y);
display.print(HelloWorld);
}
while (display.nextPage());
}
void loop() {};
But it doesn't work either.
Deva_Rishi had the suspicion that this could cause the problem
And it was found here
Do you think that has anything to do with the problem?
I mean, either starting the new SPI class doesnt work, connecting it to the display doesnt work, or something in the background changes the SPI config back to default somewhere
Ok, I can't work this way. I need consistent information in one place, so I don't need to scroll around and read multiple times. I got confused about the processor used.
Your title says ESP32S2, but I also saw ESP32S3 somewhere.
Your test system is ESP32S2, please confirm. And tell what board you select to compile for.
I have neither. But, I did a quick test with This Board. Using your code with appropriate pin numbers, it produces plausible SCK / MOSI signals on my logic analyzer. I don't have a your display so I have no idea if the data is correct. But, as I said, plausible.
So, my advise is to wait and get a logic analyzer (or oscilloscope) and look at your signals. Without knowing what's going on at the pin level you are just (again) throwing crap at the wall and hoping something sticks.
It looks like I had tried. But I don't remember any results, except the issue I raised.
It looks like only HSPI can be "matrixed" and only on ESP32S2:
#define FSPI 1 //SPI bus attached to the flash (can use the same data lines but different SS)
#define HSPI 2 //SPI bus normally mapped to pins 12 - 15, but can be matrixed to any pins
and HSPI and VSPI on standard ESP32. FSPI can't remap pins, as it would disable access to internal flash.
I found this page which explains a few options, and the method that is in your example is explained last.
The documentation for different ESP32 boards and the C2 & C3 variants in particular are even more confusing, because of the FSPI which appears to actually refer to what VSPI is on other boards, but that is not applicable here (it's about an ESP32-S2 now isn't it)
I only have devkit ESP32(S) boards, and there i have done successfully.
Agreed there !
But you do have to call
display.init();
or the display will for sure not work,
add that either before or after 'selectSPI()' who knows.
Still it may be a really good plan to contact the author of the library.
I am sure you can set the SPI pins for HSPI on a ESP32 devkit, and 99% sure for the S2, but to find why it is not working with the code from that particular library is always rather tricky.
Create a github account and go through the issues and start a discussion or open an issue (whichever seems more appropriate by looking at the open issues)
edit: (sorry posted wrong link to SPI info, this is correct now !)
I have read of a logic analyzer the first time in this thread. With it I should test if the pins that are assigned be used for the SPI right?
Can I not just put a Voltmeter between ground and the assigned SPI pins and look if something happens? Or another Arduino code with analog input enabled?
I see, I went back to hspi then.
Would it make sense to take out all the includes and copy the relevant parts of the libary to the main file, like the init function and so on, so there is really nothing missed in the background?
It would make sense to copy any of the relevant / used functions into the main INO file and completely get rid of any functions that are not used, and even get rid of all of the classes and just execute the parts that you want to execute, that said, chances of getting something that compiles are not that good given the understanding you have of the code.
It may also really make sense to try the alternate pin assignment thing with something which is known to work, like a SD-card. That way you can at least confirm that the alternate pin assignment is working, and it is just the library that isn't making it work for you.
No. You don't need to change anything in the library. You got sidetracked because of the second call to SPIClass::begin(), but this should be clear now.
On ESP32S2 it should be possible to remap pins of HSPI. But the predefined global SPI instance is on FSPI:
Oh no please!
Is there any other way we can work this out? Maybe moving over to github, private message or the german section of the forum (seeing your profile picture and that you are from switzerland, it would be easier?)
Almost, the small caps is a pointer that points to the SPI object with the capaitals HSPI, hence all the ->
which actually is confusing since FSPI is not the bus connected to the flash in this case i think, but yeah, ESP32 's and their variants are confusing.
Well take charge !
Look you know the code in the library, better than anyone and it will be easier for you to navigate.
I still think the alternate pin assignments should be checked with something as simple as an SD card, before we proceed.
I guess its over for a couple of weeks
The display might be broken now.
I got curious and changed back the code to original SPI pins but left the ones from the constructor custom. Then, the display suddenly showed random pixels.
Then I put back the pins from the constructor to the regular ones too (/*CS=5*/ 12, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4). so all pins were default again: refreshes but shows random pixels.
I unplugged everything, confirmed all pins are default: random pixels
Deleted the library and installed it again: refreshes and shows random pixels.
Copied the code that once worked: random pixels.
Tried a code with the old library GxEPD (not the second version), now the pixels are lighter but still random, nothing is really showing.
I will order two new displays and also the logic analyzer
Well first of all we dont know really if the project will ever work. I made a lot of smaller ones with 8 bit processors like attinys and had many projects with other development MCUs, but always with default SPI or i2c pins. Also, for the development part (except the SPI thing!!!), there is a lot of good documentation. I printed out all the datasheets and guids and went through them. This problem here is a whole other level for me and hopefully I will learn a lot from it.
I suggest you create a new topic with the title "How To Remap SPI pins on ESP32 S2 with GxEPD2?".
Address your first question @ZinggJM , and place a backlink to this topic in.
Copy the example GxEPD2_HelloWorld.ino, add your modifications and post it in the new topic.
I have S3, S2, C3, C2, or 3 of them, now, I think, so I can check. But I may need some days in this busy time.
BTW: I prefer English for technical discussions. And I prefer forum topics instead of personal messages.
You could connect an LED through a resistor to the MOSI pin, and modify the Blink example to send 0xFF or 0x00 through SPI, for a fast check.