Close

Getting Started with an OLED Display

A project log for Open Tag

The best game of laser tag you've never played. Choose your class - from a sniper to a pyro, and customize your own game of laser tag!

opentagopentag 08/29/2020 at 06:470 Comments

So, I switched from a LCD to an OLED. And man, is it smaller. The 0.96" screen is much smaller, but you have much more control over what each pixel displays. Thanks to Adafruit's Graphics Library and SSD1306 library, these displays are easy to control with an arduino. I found a handy tutorial, plugged it in, and...

Nothing.

No display.

So, I checked the address settings, found the display, and got it displaying. Hooray!

And then, I got a great recommendation from someone on hackaday to use icons instead of text to display status. So, after I played around with the words and numbers for a bit to get a feel for the device,  I needed to add icons. But I didn't want to make the images myself. Not when there's the internet. So a few searches later, and I found this tutorial and this tutorial on how to make images you can display on an OLED using an arduino. The tutorial had a link to an application that you have to use on a computer. I thought it was going to download something (it doesn't, it's browser based, but I didn't want to click it) so I found the original here. I then found a bunch of images that I wanted to put on the OLED, like fire, a snowflake, skull and crossbones, etc. 

I got images for all 6 status' that you can have. Converted them all to byte arrays, using the tool and put them all on the arduino. It turned out great, and I can fit all of the status effects on the OLED screen.

OLED first test

I updated the laser tag code with the OLED code and it

crashed. 

Huh.

Well, went digging into the code and found that whenever I had a bunch of debug information to the serial monitor, I couldn't connect to the OLED. My code just wouldn't run. I tried hunting down where in the code it was breaking, spending quite a bit of time commenting and uncommenting lines of code. Eventually, I took to the internet, and low and behold someone already had this problem, posted about it, and it was answered. Turns out, the OLED I'm using is a 128x64, and requires about 1 kB of RAM. Since the ATmega328p (arduino) only has 2kB of RAM, I can't have more than 50% of the RAM used after compiling my code, or there won't be enough space to run the display. In fact, you need to get it down to 30% ish so that there is still enough RAM to do other things. Like, you know, run your code or store other variables. Also, I learned that, storing strings in lines with Serial.print stores it in RAM. That used up a lot of my memory, well over 50%, so the OLED would fail. It just didn't have enough RAM. Well, the guys at arduino built a way to keep those strings from taking up all your memory, as described here. Using the F( ) command stores strings in flash memory rather than RAM, so now I have enough RAM and everything compiles. 

Yay. I wish I had known that earlier, but, you sometimes find out about the hardware and software limitations of the libraries and hardware you use after getting and installing them. If I wanted to run more displays, I'd really need to get a microprocessor with more RAM. Or use smaller displays. Or different displays. Ok, there are lots of ways to fix this problem, but for now, it's fixed.

Except that whenever I send a tag, I get something on the IR sensor output. It may be my power's doing some weird jig or something. Or some interference. Or a wire's got loose again. Either way, that's a debugging problem for another time. For now, it's working. 

Mostly.

Discussions