Cannot get 2.9" epaper to work with Teensy

Status
Not open for further replies.

Maes2ro

Active member
I'm working with a 2.9" 3 colour waveshare module, but I am struggling with running it with a Teensy. I started testing using the epd2in9b-demo (attached) that is downloadable from the Waveshare Wicki, and this runs perfectly on both Arduino Uno and Arduino Micro. However I just cannot get it to work with either Teensy 3.2 or Teensy 3.6.

In order to do more diagnostics, I have been trying to use the 'Teensy_epd2in9_simplexfont' sketch written by PaulS (from this thread 'Is there a simple E-paper driver for Teensy LC?' ), but this does not work either. Admittedly I do not have a Teensy LC, and am using a 3.2, but I don't believe there is a significant difference in this context. I have however ordered an LC, just to complete the trials.

I have been doing some old fashioned diagnostics with Print statements, and can see that the sketch hangs at the first encounter of the WaitUntilIdle call, where it would seem that the Busy line is not changing state.

I'm clearly missing something, so would greatly appreciate any input.
 

Attachments

  • epd2in9b-demo.ino
    3.7 KB · Views: 93
  • imagedata.cpp
    48.2 KB · Views: 73
  • imagedata.h
    1.3 KB · Views: 69
Hi,

Just uploaded my code to a Teensy 3.1 and can confirm that it's working fine:

IMG_20190323_213408.jpg

IMG_20190323_213500.jpg

Since you are using a 3-color display, the demo code is different and may have an issue.
Which display are you actually using? Type B or Type C?

Regards,
Paul
 
Display type

Hi,

Just uploaded my code to a Teensy 3.1 and can confirm that it's working fine:

View attachment 16226

View attachment 16227

Since you are using a 3-color display, the demo code is different and may have an issue.
Which display are you actually using? Type B or Type C?

Regards,
Paul

Hi Paul

It's a type B I think, Black/White/Red. Although there is nothing on the screen printing to say either way.

Looking more closely at the reverse of the module, it seems to be jumpered for 4-line SPI

Regards
Stirling
 
Hi Stirling,

My 2-color display is strapped from the factory at 3-line SPI. Not really sure that would make a difference since 4-wire SPI also includes MISO [which is not used for this display].

Furthermore, I checked the code for the B type and it is significantly different from the A type; compare epd2in9.h and epd2in9b.h.
It looks like a completely different TCON chip.
Tried to run the epd2in9b demo code but that did not work. Not surprising, since, for example, the polarity of the Busy signal is reversed between Type A and Type B...

Are you sure you connected all the wires from display correctly to your Teensy 3.2?

Regards,
Paul
 
While I was thinking along about your issue, I recalled that I filed an issue for the epd library last year: https://github.com/soonuse/epd-library-arduino/issues/2.
Github member Soonuse is apparently the person that creates the Waveshare code.
He fixed the epdif.cpp file and closed the issue.

Capture.PNG

However, this fix is not reflected in the downloadable code on the Waveshare site!

So a simple edit of Arduino\Libraries\epd2in9b\epdif.cpp from
Code:
    SPI.beginTransaction(SPISettings(2000000, MSBFIRST, SPI_MODE0));
    SPI.begin();
to
Code:
    SPI.begin();
    SPI.beginTransaction(SPISettings(2000000, MSBFIRST, SPI_MODE0));
may do the trick.

Regards,
Paul
 
While I was thinking along about your issue, I recalled that I filed an issue for the epd library last year: https://github.com/soonuse/epd-library-arduino/issues/2.
Github member Soonuse is apparently the person that creates the Waveshare code.
He fixed the epdif.cpp file and closed the issue.

View attachment 16228

However, this fix is not reflected in the downloadable code on the Waveshare site!

So a simple edit of Arduino\Libraries\epd2in9b\epdif.cpp from
Code:
    SPI.beginTransaction(SPISettings(2000000, MSBFIRST, SPI_MODE0));
    SPI.begin();
to
Code:
    SPI.begin();
    SPI.beginTransaction(SPISettings(2000000, MSBFIRST, SPI_MODE0));
may do the trick.

Regards,
Paul

Hi Paul

Well, that's pretty subtle!
That has done the trick for the demo code though so at least I know that the 3.2 and panel work together.

I'm intrigued, why does that bug not affect the Arduino?

Thank you very much for your help with this, I would never have found that for myself. And now it's time to write some application code of my own. :)

Best Regards
Stirling
 
Hi Stirling,

Glad to hear this worked out for you!

I'm intrigued, why does that bug not affect the Arduino?

My guess is it has to do with the different SPI libraries that are used for compilation for Arduino and Teensy.
Arduino is using C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src\SPI.h & SPI.cpp, while Teensy uses C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SPI\SPI.h & SPI.cpp.

Looked into both SPI.h & SPI.cpp files but could not spot an obvious cause [I'm not a pro in software coding]. Perhaps someone else on this forum knows?

Regards,
Paul
 
Looked into both SPI.h & SPI.cpp files but could not spot an obvious cause [I'm not a pro in software coding]. Perhaps someone else on this forum knows?
Maybe ;)

My guess calling SPI.beginTransaction as the first call in SPI will crash the processor. Why? Because as a default you do not have access to the register memory space for SPI.

That is why the first thing SPI.begin() does is: hardware().clock_gate_register |= hardware().clock_gate_mask;

This tells the system that allow access to the registers associated with the specific SPI object...

One obvious potential fix would be to add that line to SPI.beginTranaction as well. But: the begin function will then still overwrite the data that beginTransction tried to set anyway.
So best to rearrange those calls in that library.

Kurt
 
However, this fix is not reflected in the downloadable code on the Waveshare site!

I messaged Github member Soonuse, whether he could update the downloadable democode on the Waveshare website.
He did and now the democode for the different displays contains the correct SPI.begin(); SPI.beginTransaction(SPISettings(2000000, MSBFIRST, SPI_MODE0)); sequence.

@KurtE:
Your explanation definitely makes sense, but I still wonder why the wrong SPI invocation sequence apparently did work on Arduino and did not work on Teensy.

Regards,
Paul
 
Status
Not open for further replies.
Back
Top