Help with choosing class
I have this Arduino shield: https://wiki.dfrobot.com/LCD12864_Shield_SKU_DFR0287 attached to Arduino R4 WiFi board.
I can't figure out which class should I use.
According to docs, it uses D7, D8, D9, D10, D11, D13, A0 pins from which D7 is for backlit and A0 for joystick.
I use VS Code with PlatformIO. I tried this (and several other constructors):
#include <Arduino.h>
#include <U8g2lib.h>
// I should use HW (hardware I guess) for better performance, right?
// U8G2_ST7565_NHD_C12864_1_3W_HW_SPI u8g2(U8G2_R0, PIN_D10, PIN_D8);
U8G2_ST7565_NHD_C12864_1_3W_SW_SPI u8g2(U8G2_R0, D13, D11, D10, D8);
void setup()
{
u8g2.begin();
u8g2.setContrast(0);
}
void loop()
{
u8g2.clearBuffer();
u8g2.setFont(u8g2_font_ncenB14_tr);
u8g2.drawStr(0, 20, "Hello World!");
u8g2.sendBuffer();
}
But it doesn't work (display is blank).
I can see that
U8G2_ST7565_NHD_C12864_1_4W_SW_SPI(rotation, clk, data, cs, dc [, reset])
U8G2_ST7565_NHD_C12864_2_4W_SW_SPI(rotation, clk, data, cs, dc [, reset])
U8G2_ST7565_NHD_C12864_F_4W_SW_SPI(rotation, clk, data, cs, dc [, reset])
have exact same signature, is there any difference among them?
To answer your second question: https://github.com/olikraus/u8g2/wiki/u8g2setupcpp#buffer-size
TL;DR: RAM vs CPU tradeoff by limiting how many pixels are stored in memory.
You only can use sendBuffer with the F version; page loop (firstPage/nextPage) is required otherwise.
Thanks. I tried both options.
I guess I will just use the old U8Glib, I just need to add wiring_private.h manually.
I'd really prefer to use the supported version of the library though.
On the diagram above there is an association PIN 9 -> CD, but there is no CD parameter in a constructor. There is DC though. Does it refer to the same thing?
This is how I translate constructor parameters to the pins in the diagram:
For U8G2_ST7565_NHD_C12864_1_4W_HW_SPI
uint8_t cs -> SPI Interface: CS
uint8_t dc -> SPI Interface: CD <--- not sure about this
uint8_t reset -> SPI Interface: RST
For U8G2_ST7565_NHD_C12864_1_4W_SW_SPI
uint8_t clock -> SPI Interface: SCK
uint8_t data -> SPI Interface: MOSI
uint8_t cs -> SPI Interface: CS
uint8_t dc -> SPI Interface: CD <--- not sure about this
uint8_t reset -> SPI Interface: RST
For reference, this is code which works with U8glib.h (straight from the example on the dfrobot site:
U8GLIB_NHD_C12864 u8g(13, 11, 10, 9, 8);
void draw(void)
{
u8g2.setFont(u8g_font_unifont);
u8g2.drawCircle(64, 32, 20);
u8g2.drawStr(0, 10, "Hello World!");
}
void setup()
{
u8g2.begin();
u8g2.setContrast(0); // Config the contrast to the best effect
}
void loop()
{
u8g2.firstPage();
do
{
draw();
} while (u8g2.nextPage());
}
For U8G2_ST7565_NHD_C12864_1_4W_SW_SPI
uint8_t clock -> SPI Interface: SCK
uint8_t data -> SPI Interface: MOSI
uint8_t cs -> SPI Interface: CS
uint8_t dc -> SPI Interface: CD <--- not sure about this
uint8_t reset -> SPI Interface: RST
DC or CD should be the same (it meens DATA/COMMAND or COMMAND/DATA), so the mapping is correct and the constructor should be:
uint8_t clock -> SPI Interface: SCK -->13
uint8_t data -> SPI Interface: MOSI-->11
uint8_t cs -> SPI Interface: CS-->10
uint8_t dc -> SPI Interface: CD <--- not sure about this -->9
uint8_t reset -> SPI Interface: RST-->8
So the constructor should be:
U8G2_ST7565_NHD_C12864_1_4W_SW_SPI(U8G2_R0, D13, D11, D10, D9, D8);
BTW: in the example above, you have used the 3W SPI constructor: This will not work at all, because the display is (probably) configured in 4W SPI mode.
Not sure what example do you refer to, from my OP with u8g2 or the last message from Mar 13 with old library. The latter works perfectly well (it's running right now on my desk).
I've already tried U8G2_ST7565_NHD_C12864_1_4W_SW_SPI, it doesn't work. Screen is just blank:
#include <Arduino.h>
#include <U8g2lib.h>
U8G2_ST7565_NHD_C12864_1_4W_SW_SPI u8g2(U8G2_R0, D13, D11, D10, D9, D8);
void draw(void)
{
u8g2.setFont(u8g_font_6x13r);
auto time = "123456"; // myClock.getTime();
u8g2.drawStr(0, 10, time);
}
void setup()
{
u8g2.begin();
u8g2.setContrast(0);
}
void loop()
{
u8g2.firstPage();
do
{
draw();
} while (u8g2.nextPage());
delay(100);
}
In the picture the display seems to show the expected string 123456 very light. Maybe you need to adjust the constrast with u8g2.setContrast(...)