Library modifications for different OLED drivers

Hi!

Recently i made some Arduboy clones using OLEDS with SSH1106 and SSD1309 drivers.

I’ve done some modifications in the libraries Arduboy / Arduboy2 and i think it’s good open a new thread for discussing the modifications.

For the 1.3’’ SSH1106 screen i take some code from a library shared through this community… (I can´t remember the thread…)

The changes in code are in the src/core/core.cpp and src/Arduboy2core.cpp for arduboy and arduboy2 libraries.

In Arduboy2/src/arduboy2core.cpp relace the two ‘paintscreen’ funcions with this:

void Arduboy2Core::paintScreen(uint8_t *image, bool clear){
	for (int8_t i = 7; i >= 0; i--)
	{
    LCDCommandMode();
    SPI.transfer(0xB0 + i);		// Set row
    SPI.transfer(0x02);		// 0x02, Set lower column address (use 0x00 for SD1306 and SSD1309)
    SPI.transfer(0x10); // Set higher column address
    LCDDataMode();
     
    for (uint16_t j = 128; j > 0; j--)
    {
		if(clear) image[i*128+128-j] = 0;
		  SPI.transfer(image[i*128+128-j]);
    }
	}	
}
void Arduboy2Core::paintScreen(const uint8_t *image)
{ 
	for (int8_t i = 7; i >= 0; i--)
	{
    LCDCommandMode();
    SPI.transfer(0xB0 + i);		// Set row
    SPI.transfer(0x02);		// 0x02, Set lower column address (use 0x00 for SD1306 and 1309)
    SPI.transfer(0x10); // Set higher column address
    LCDDataMode();
    
    for (uint16_t j = 128; j > 0; j--)
        {
		      SPI.transfer(image[i*128+128-j]);
        }
	}
}

And for the Arduboy/src/core/core.cpp in the Arduboy library replace the paintScreen funcion for this code:

void ArduboyCore::paintScreen(unsigned char image[])
{
for (int8_t i = 7; i >= 0; i–)
{
LCDCommandMode();
SPI.transfer(0xB0 + i); // Set row
SPI.transfer(0x02); // 0x02, Set lower column address (use 0x00 for SD1306 and 1309)
SPI.transfer(0x10); // Set higher column address
LCDDataMode();

  for (uint16_t j = 128; j > 0; j--)
  {
  	  SPI.transfer(image[i*128+128-j]);
  }

}
}

Since the last update of Arduboy2, the command SPI.transfer now is SPItransfer (no dot) 

(thanks @Nono_Nano )

i’m pretty sure that with only this changes the SH1106 works well but i wrote this modifications some weeks ago and maybe i forgot something.

The good thing it’s that this code works for SSD1306, SSD1309 (2.42’’ OLED) and SH1106 and the only change it’s the 0x02 value in one line. (a horizontal offset) So you can easily adapt for to your driver.

And the bad thing it’s that consumes more memory. not much but i can’t load Evade that occupies 99% of memory. (Solved deleting a some parts of the soundtrack data :grin:)

Try and comment if worked or have some issues.

I know there’s a lot of programmers in the community and this changes may not be the better solution but it worked forme.

I’m not very experienced programming Arduboy software, one of my next projects will be a game for this great machine.
But for now this is my small contribution for the programmers and makers having issues with the differents OLED drivers.

Cheers!

2 Likes

Thank you for sharing! I still haven’t got round to building my fakeduboy yet but definitely this weekend! The old thread is here:

2 Likes

Good luck qith your fakeduboy and take it easy!!
Thanks for linking the SH1106 thread!!

Another bad thing is that it takes more time, so games that are close to using 100% CPU load per frame may run slower.

For sketches that use nextFrame() with the Arduboy2 library, you can check for this by changing all nextFrame() calls to nextFrameDEV() temporarily. If the yellow TX LED above the reset button flashes or stays on, then the sketch is running slower than the set frame rate.

Thanks for contribution, didn’t know that. I’ll keep it in mind when programming. :relaxed:

After upgrade at latest Arduboy2 library, I changed “SPI.transfer” in “SPItransfer” to running in SSH1106

2 Likes

Sure!! Didn’t understand your reply until i updated the library.

SPI.transfer now is SPItransfer (without dot)
1 Like

Actually, it’s now arduboy.SPItransfer (or whatever you named your Arduboy2 object followed by .SPItransfer).

mmm…inside the library files the arduboy. prefix is not needed because you are into the class definition.

From the sketch (outside the class definition) the object arduboy. is needed.to invoque SPItransfer method.

The modifications proposed are for the library files.

This ‘arduino ide’ style of ‘classes/objects’ in arduino is still a bit confusing for me but works as classic Java or C++ Objects. Just a different syntax on class definitions.

1 Like

Oops, sorry, you are correct.

1 Like

Anyone been able to get mystic ballon to work with SSH1106 1.3 screen and if so what mod did you have to make? Thanks

Yes I did. I started out @FerJerez sugestions but optimized it a bit further (still not satisfied though) and added the changes to arduboy and arduboy 2 libraries. Then I got an original Arduboy (YAY! :smiley: ) and needed to find a easy way to compile for different Arduboy versions and made a board package for Arduino IDE.

Long story short. You can Install my board package from https://github.com/MrBlinky/Arduboy/tree/master/board-support then select Arduboy from the boards menu followed by the variant you’re using (Arduino board + OLED display) There’s no code support for the SSD1309 yet because I’m still waiting for my 2.4" SSD1309 OLED display to arrive for testing.

I also ran out of memory when compiling Evade at first. But I went optimizing the Arduboy library a bit and managed to free more then enough to make it compile :sunny: (FYI I optimized the OLED Chip Select by keeping it always on and knocked off a whopping 42 bytes of buttonsState() function)

3 Likes

@Mr.Blinky Hi,how are you? I ordered 7pin SPI Oled 1.3 SSH1106.I want to ask you, Is it worth it to make diy arduboy or should i buy another Oled . Can we modificate this SSH1106 Oled?

You can use that with the board package.

But I think there is a performance decrease, it runs slower than normal display I think?

Hi @Dejvi

You can make a Homemade Arduboy using SH1106 display. You need to recompile the games though to play them on a SH1106 display. You decide whether it is worth to you or not.

If you want to be able to easily upload existing precompiled games (hex files) then you’d need an SSD1306 display. An SSD1309 display can also be used by patching games on the fly using one of my python scripts.

Not sure what you want to modify. You can’t modify the display into an SSD1306 if that’s what you mean.

I just want to play games this is all I want🙂.I need to ask you something,is there any video that shows how to make arduboy with SSH1106,how to recompile the games because to be honest my english is not so good and i dont have much information about Arduino program.

Install the Homemade package then select the settings in the screenshot @bateske posted above.

AFAIK there’s no video tutorial but the wiring is on the above page. theres also this image as a wiring guide.

I’m assuming you’re gonna use a Pro Micro with the SS1106 so I recommend to use the alternate wiring.

Thank you for the iiformation.Oled is on the way, I will try to make it.If i have any problem i will ask you :slightly_smiling_face:

Hi,how are you? I want to ask yoy something.
1.Are VDD and GND connected right in this photo?
2.Can i Connect GND of butons to the left first GND of Pro Micro?

Hi, I’m fine thanks for asking.

Yes

Yes you can. All GND pads are inter connected so it doesn’t really matter to which GND you connect the buttons.

2 Likes