B4R Question ESP32-2424S012

daveinhull

Active Member
Licensed User
Longtime User
Hi,

I've just got an ESP-2424D012 which is an ESP32 with integrated 240x240 round display, see attached specification.
The sample code that comes with it is in C and I can work with it and successfully upload to the device, but would very much like to work in B4R.
It appears to use a libary called LGFX. In Ardunio it uses ESP32C2 Dev Module, but I can't find that in B4R, althogh there are similar.

Can anyone start me off in the right direction to use B4X with this device.

I did take a look at a coding exmaple for a similar ESP32 with integrated display by Peter Simpson, but alothough it connects to my network, nothing happens so I guess I'm using the wrong libary or board (don't know how to reference the link)
https://www.b4x.com/android/forum/t...led-display-connected-to-wifi-inline-c.81149/

B4R Code Snippet ESP32 with built in OLED display connected to WiFi - Inline C​

Many thanks
Dave
 

KiloBravo

Active Member
Licensed User
Here is another simple library. https://github.com/JoeMaputo/GC9A01A_lite/blob/main/LCD.cpp
Sounds to me like you do not have the pins for SPI defined correctly in B4R. What are the default pins in the Arduino code ?

This might help. https://randomnerdtutorials.com/esp32-spi-communication-arduino/

Also, if you use the SPI library linked above by Candide you can define the pins for MISO and MOSI.
I believe the Arduino defaults the MISO ans MOSI, so you may need to change them.
From Candide's Wrapped rSPI32 lib
void begin1(byte sck, byte miso, byte mosi, byte ss);
 
Upvote 0

daveinhull

Active Member
Licensed User
Longtime User
@KiloBravo thanks, although I've already found this, my initial problem was what pins are being used on the ESP32 for the SPI bus (fond this as they are standard) and also for the display control (CS, RST & DC, BL), which I got from the working Arduino code.

I went back to the inline code test and tried as you suggested to rename Setup and Loop in the simple code that I know works in the Arduino IDE and this now compiles and uploads, and to a degree works in that I can flash the backlight from B4R using inline C code.
But the actual B4R identical inline code doesn't do what the equivalent Arduino code does; it just doesn't do anything.

I also tried to get the simple GC9A01 demo code you pointed me at working (in Arduino initially), but while it compiles it doesn't do anything. As you said it is very simple code which just uses the SPI bus to send commands and data to draw some very basic shapes, triangle, square, etc. But it doesn't work and I think this is because of the GC9A01 initialisation setup and this is where I've come to a dead-end as the example code uses some undocumented commands, so I've no idea what they are doing.

I can't find the equivalent setup in the LVGL library (which I do know works).
What would be rally useful (and I've not found it yet) is some very basic guidance, example code, demo with comments that explains how to initialise the GC9A01 - the data sheet is good, but it is just that, a datasheet and doesn't explain what is mandatory to properly configure the GC9A01

So status:
Arduino full demo supplied with GC9A01: Working fully
Arduino cut down demo to simple text display: Working fully *
Arduino GC9A01 Demo: Compiles and I can flash the backlight, but not functioning as designed
B4R Inline cut down demo to simple text display: Compiles, flashes backlight, but not working (see * above)
Library wrapping: eek no

Oh I wish I'd never started but will keep plodding on.

Thanks again for your support.
Dave

[EDIT @KiloBravo sorry wrote this before I saw your second message, seen all that about the Candide's code and am using begin1 as you say]
 
Upvote 0

KiloBravo

Active Member
Licensed User
I still think the problem is your pin assignments. Flashing the Backlight is just toggling the BL pin.
These pins display control (CS, RST & DC, BL). They are not defining the MISO or MOSI pins.
If I had a module I would try and help you but I do not.

Read thru this post.
https://www.b4x.com/android/forum/t...ive-two-bytes-back-as-int.136846/page-2#posts <<< it is for a ILI9488 display but the SPI communications are relevant.

In Candide's lib I defined the pins like so ....
'CHANGE HERE THE PIN NUMBERS (SCK, MISO, MOSI, CS)
'SS/CS =15 MISO=12 MOSI=13 SCK =14 T_IRQ = 0
SPI.ESP32_SPI_Set_Pins(14,12,13,15)
SPI.CSPinDeActivate(SPI.CS__SPI)
tirqPin.Initialize(0,tirqPin.MODE_INPUT_PULLUP)

I think you need to get SPI working in B4R. Read the datasheet and try and send one single command over the SPI lines to get a response. Log the response. You should be able to send a single command or read one register from the module to check a setting without going thru the entire setup/initialize routine. Once you verify you can send and receive one byte/command from the module then you can start working on the setup/initialize routine, etc...
 
Upvote 0

KiloBravo

Active Member
Licensed User
I would also look at this link very carefully and see what pins he is using. https://github.com/carlfriess/GC9A01_demo/blob/main/demo.gif
He is using an Arduino Micro but you can clearly see by the colored wires which pins on the Arduino Micro connect to which pins on the GC9A01 module. The pinout for the Arduino Micro should tell you which pins are MISO and MOSI. Without those pins defined correctly nothing will work because you cannot send or receive data or commands.
 
Upvote 0

daveinhull

Active Member
Licensed User
Longtime User
Finally got it to do what I want (many thanks @KiloBravo).

It all came down to getting this right:
B4X:
SPI.begin(6,-1,7,10);
But I'm sure I had already tried that, although I've tried so many things in both Arduino and B4R I wasn't sure what I'd done.
The GC9A01A_lite_main demo really helped, although there were a couple of bugs in the code which when sort, compiled, downloaded and worked.
I think went back to the GC9A01_demo, changed the SPI.begin and it worked too👍👍👍

So, now I've got something I work from (and understand), I can now go back into B4R and recreate the same code and hopefully build a bunch of routines, which maybe someone clever than me can convert into a library for everyone to use.

I got so low yesterday I just left it (had a couple of red wines) and came back to it today and with a fresh head (hmmm) change the one line and bing, it worked.

Thanks
 
Upvote 0

KiloBravo

Active Member
Licensed User
That's great glad you stuck it out and figured it out. Now the fun begins!

P.S. I have come to learn, whenever I think B4R is the problem, it always turns out to be me! ;)
 
Upvote 0
Top