Help coding boot/splash screen with Text

Hello there!
it’s my first post in this forum. I’m a total newbie to Arduino and have almost zero coding experience.
I wish to implement a boot up screen before the main program kicks in, for let’s say a couple of seconds then switch to the main program which is not my sketch or programming.

Note that the boot screen is simply a text with big fonts.
So far with my very limited knowledge, I have failed to do so.
The boot screen doesn’t show when I place it in void setup()
Maybe it should be put elsewhere? with different coding commands?

I am using a SSH1106 based 1.3" OLED and a u8g2 based library for fonts

The code that needs to be on the boot screen is this one:

  u8g2.setFont(u8g2_font_bubble_tr);  // choose a suitable font
  u8g2.drawStr(20, 30, "SSSM");  // write something to the internal memory
  u8g2.setFont(u8g2_font_profont12_tr);
  u8g2.drawStr(20, 40, "by A. Jaouhar");

Any help from members would be greatly appreciated,
I am attaching the whole .ino code to the message to make it easier for anyone to help,
Thanks a lot!

Ali

SketchFinal.ino (8.27 KB)

I am attaching the whole .ino code to the message to make it easier for anyone to help,
Thanks a lot!

The code that you attached does not attempt to draw a splash screen in setup()
How did you try to do it ?

UKHeliBob:
The code that you attached does not attempt to draw a splash screen in setup()
How did you try to do it ?

Ah yes, my bad, I removed it before uploading it, I did some trial and error before where I put this code underneath setup() but all it gave me was a blank screen:

  u8g2.setFont(u8g2_font_bubble_tr);  // choose a suitable font
  u8g2.drawStr(20, 30, "SSSM");  // write something to the internal memory
  u8g2.setFont(u8g2_font_profont10_tr);
  u8g2.drawStr(20, 40, "by Paul De Backer");
  u8g2.sendBuffer();          // transfer internal memory to the display
  delay(1000);
  u8g2.clearBuffer();

it gave me a blank screen for the amount of delay I mentioned(1000).
Not even sure if this part is even necessary or correct? I just copied it from a pre-existing sketch...

[color=#222222]u8g2.sendBuffer();          // transfer internal memory to the display[/color]
[color=#222222]delay(1000);[/color]
[color=#222222]u8g2.clearBuffer();[/color]
[color=#222222]

Please follow the advice on posting code given in Read this before posting a programming question

In particular note the advice to Auto format code in the IDE and to use code tags when posting code here as it prevents some combinations of characters in code being interpreted as HTML commands such as italics, bold or a smiley character, all of which render the code useless

If the code exceeds the 9000 character inline limit then attach it to a post

Noted UKHeliBob, thanks,I just edited my previous codes.

I just tried a code from this post, but it didn't work out either:

this is part of the code where I think the boot screen code is supposed to be:

void setup(void)
{
	Serial.begin(115200);
 randomSeed(analogRead(0));   //   seed random number generator


    int time = random(2000, 4001);   // get random number between 2000 and 4000 for the 2-4 seconds


  u8g2.setFont(u8g2_font_bubble_tr);  // choose a suitable font
  u8g2.drawStr(20, 30, "SSSM");  // write something to the internal memory
  u8g2.setFont(u8g2_font_profont10_tr);
  u8g2.drawStr(20, 40, "by Paul De Backer");
  u8g2.sendBuffer();          // transfer internal memory to the display
  u8g2.clearBuffer();


   delay(2500);  // wait for the 2 to 4 seconds


   //  Whatever other code the rest of your setup needs.
}


void loop(){


  // main code here
}
#ifdef OLED
	u8g2.begin();
#endif
	randomSeed(analogRead(0));
}


int i = 0;


void loop(void)
{

I'm getting these errors:

error: 'u8g2' does not name a type

  u8g2.begin();

  ^~~~

error: expected constructor, destructor, or type conversion before '(' token
  randomSeed(analogRead(0));
error: expected declaration before '}' token
 }
 ^
exit status 1
'u8g2' does not name a type

I can't figure out what's wrong or how should I proceed or modify with my limited knowledge, in fact I am learning C++ as I'm finalizing this project

Can anyone offer any help with this?

For a start, if u8g2 needs a .begin() you should be doing this in setup() BEFORE you use it. I have never seen a .begin() that is called in loop() every time loop runs.

Secondly, you should really post all the code as what you posted does not have a declaration for u8g2 and the compiler also thinks this is a problem. The issue is often not in the section you think it is and you will get limited help if others can’t read your mind (which most people cannot do).

marco_c:
For a start, if u8g2 needs a .begin() you should be doing this in setup() BEFORE you use it. I have never seen a .begin() that is called in loop() every time loop runs.

Secondly, you should really post all the code as what you posted does not have a declaration for u8g2 and the compiler also thinks this is a problem. The issue is often not in the section you think it is and you will get limited help if others can’t read your mind (which most people cannot do).

Hello Marco and thank you for the reply.
I actually attached the whole code without the boot up screen section in the 1st post.
I’m putting it again embedded in this post.

Here it is in full with how it is giving me a blank screen, the code you commented about was from a splash screen code I copied from another post for trial and error purposes, therefore wasn’t uploading and was giving me errors.

This one uploads through arduino IDE and turns out with no errors but gives me a blank screen for the duration I state the Delay() time, you can see the u8g2.drawstr commands underneath void setup():

I’m attaching it again with this code inside underneath void setup():

u8g2.setFont(u8g2_font_bubble_tr);  // choose a suitable font
u8g2.drawStr(20, 30, "SSSM");  // write something to the internal memory
u8g2.setFont(u8g2_font_profont10_tr);
u8g2.drawStr(20, 40, "by P.De Backer");
u8g2.sendBuffer();          // transfer internal memory to the display
u8g2.clearBuffer();

Please let me know what’s wrong and what should I do to make the boot up screen appear, appreciated!
Ali

SSM_FINAL.ino (8.56 KB)

OK, I missed the attachment the first time around.

Can you confirm that you have tried the ug28 examples and that you can see the display working? That will mean that your wiring and choice of display parameters is correct. The "HelloWorld example would be a good start.

Also, if this is what you want to do:

I wish to implement a boot up screen before the main program kicks in, for let's say a couple of seconds then switch to the main program which is not my sketch or programming.

Shouldn't there be a delay() statement after your screen code in setup() so the message can be read?

marco_c:
OK, I missed the attachment the first time around.

Can you confirm that you have tried the ug28 examples and that you can see the display working? That will mean that your wiring and choice of display parameters is correct. The "HelloWorld example would be a good start.

Also, if this is what you want to do:Shouldn't there be a delay() statement after your screen code in setup() so the message can be read?

Yes Marco, Confirmed. in fact, if I use any drawing commands based on u8g2 anywhere between the u8g2.firstPage() an u8g2.nextPage() command, it works and shows the text I typed and font I chose albeit overlaid on the main program, a total mess, so it doesn't serve the purpose of a boot/welcome screen I wanted.

It's weird these commands don't show on screen when they're underneath void setup() since I want to make them appear for a limited time just once.

Yes I used delay() right after the u8g2 commands under void setup() but the screen only goes blank for the duration I mention between the brackets, nothing shows, as if the commands before weren't recognized. For example, when I mention delay(3000) it stays blank for 3 seconds then the program appears on screen...
I'm confused as to what we're missing...

You are using a frame buffer instead of a full buffer, so the sendBuffer() and clearBuffer() will not work.

Try substituting this for your setup() function:

void setup(void)
{
  Serial.begin(115200);

#ifdef OLED
  u8g2.begin();

  u8g2.firstPage();
  do {
    u8g2.setFont(u8g2_font_bubble_tr);  // choose a suitable font
    u8g2.drawStr(20, 30, "SSSM");  // write something to the internal memory
    u8g2.setFont(u8g2_font_profont10_tr);
    u8g2.drawStr(20, 40, "by Paul De Backer");
  } while ( u8g2.nextPage() );
#endif
  randomSeed(analogRead(0));
}

Also, I notice an error about 15 lines from the end of the sketch:

  if (movingAverageCount = movingAveragePts) {

david_2018:
You are using a frame buffer instead of a full buffer, so the sendBuffer() and clearBuffer() will not work.

Try substituting this for your setup() function:

void setup(void)

{
 Serial.begin(115200);

#ifdef OLED
 u8g2.begin();

u8g2.firstPage();
 do {
   u8g2.setFont(u8g2_font_bubble_tr);  // choose a suitable font
   u8g2.drawStr(20, 30, "SSSM");  // write something to the internal memory
   u8g2.setFont(u8g2_font_profont10_tr);
   u8g2.drawStr(20, 40, "by Paul De Backer");
 } while ( u8g2.nextPage() );
#endif
 randomSeed(analogRead(0));
}





Also, I notice an error about 15 lines from the end of the sketch:



if (movingAverageCount = movingAveragePts) {

That totally worked!
Thank you David! I appreciate it a lot!
I think I understand what you did.
I would like to learn more about frame buffer, since I have limited knowledge in C++.
I just added a delay command, delay(2000) after while ( u8g2.nextPage() );and it worked perfectly like I wanted it to be.
What about that mistake? I don't get anything in the Arduino IDE telling me there's an error after verifying. What does this error affect?
Ali

alja94:
Yes Marco, Confirmed. in fact, if I use any drawing commands based on u8g2 anywhere between the u8g2.firstPage() an u8g2.nextPage() command, it works and shows the text I typed and font I chose albeit overlaid on the main program, a total mess, so it doesn't serve the purpose of a boot/welcome screen I wanted.

Note the 1 in the constructor, that indicates you are using a frame buffer.

U8G2_SH1106_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0);

With a frame buffer, you always need to use the display loop to send data to the display:

  // picture loop  
  u8g2.firstPage();  
  do {
    //display commands
  } while( u8g2.nextPage() );

The display is divided up into subsections (frames), and the library can only process one at a time. firstPage() starts at the first frame, then the library processes the display commands, only writing to the display the portion of those commands that appear in the current frame. nextPage() advances to the next frame, and all the display commands are processed again, until the last frame is complete and the do/while loop exits. The advantage is that much less memory is required on the Arduino than for a full display buffer, the disadvantage is that the display commands must be processed multiples times and will take longer to execute.

  if (movingAverageCount = movingAveragePts) {

= assigns movingAverageCount the value in movingAveragePTS, == compares their values

This actually is a valid if statement, although I have not seen it used much, so does not get flagged as an error. movingAverageCount is assigned the value of movingAveratePts, then that value is evaluated as true or false, with false being 0 and true being any non-zero value.

Very informative David, thank you!
Had no idea this 1 meant a frame buffer.
I will further read about the matter an indulge myself :slight_smile:

If I encounter any other problems I'll certainly let you know!
Thank you so much again!

A slight criticism...
You mention copying and pasting, then putting code in where it ‘seems’ right.
The ONLY way to develop or modify software is to understand what it does and HOW it does it.

Just punching away will unfortunately never result in reliable, repeatable code.

lastchancename:
A slight criticism...
You mention copying and pasting, then putting code in where it ‘seems’ right.
The ONLY way to develop or modify software is to understand what it does and HOW it does it.

Just punching away will unfortunately never result in reliable, repeatable code.

No problem!
It took me a couple of days to understand many things, and it was fun! :slight_smile:
Learned how the Arduino IDE works, how to upload, verify, write basic commands, install libraries.
Unbricked my Arduino micro pro...
How to define a screen, learned what the sections of the code meant, to a certain extent, orders, how to define, experimented a lot with text and drawing fonts and shapes. Everything was practically new to me.

I never intended to learn coding or programming by the way. I was just making a project I needed where coding was involved and I had absolutely neither knowledge nor experience whatsoever in it. I had the main program that was written by someone else and had to do some slight modifications in order to make it work like I wanted and had to tinker a bit with trial and error.
That's not to say I didn't try to understand or did I immediately ask for help. . I just didn't expect I would cover everything especially that it wasn't my goal to start with. Just when I hit a wall and couldn't comprehend what was faulty after doing some research that I asked the guidance of experienced members in the community.

Next time I'm doing a project with code involved, I'll have a background at least, even if a pretty basic one^_^

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.