Running multiple oLED screens with Arduino Mega 2560

128x128 pixel 1.5" full colour OLED display with MicroSD card slot. [Product page]
Post Reply
aijii
Posts: 16
Joined: Thu Oct 03, 2013 12:06 pm

Running multiple oLED screens with Arduino Mega 2560

Post by aijii » Fri Oct 04, 2013 4:21 am

I assume this would involve:

1) multiple instances of FTOLED object
2) each instance set up to use a different chip select line on the atmega uProc ?

Will this work ? I'm about to go out and buy two or three of these things... any implications in doing so ? i.e. update speed, etc ?

angusgr
Freetronics Staff
Freetronics Staff
Posts: 853
Joined: Tue Apr 09, 2013 11:19 pm
Location: Melbourne, Australia
Contact:

Re: Running multiple oLED screens with Arduino Mega 2560

Post by angusgr » Fri Oct 04, 2013 5:59 am

Sounds like fun! Assuming you want to display different things on each screen, that's pretty much it. To use FTOLED with multiple modules you'll need a CS pin per OLED screen, you can share the DC pin to keep the pin count down.

For the RST pin you can either share one pin between all modules, or have one per module. If you decide to share between all modules then you will have to cheat a bit, so that FTOLED resets all the modules once (via the RST pin) when you call begin() on the first module, but doesn't then re-reset them when you call begin() on the other modules.

This method is a bit of a hack, but it should work nicely:

Code: Select all

OLED oled1(PIN_CS1, PIN_DC, PIN_RESET); // Note real reset pin
OLED oled2(PIN_CS2, PIN_DC, 52); // Leave pin 52 unconnected
OLED oled3(PIN_CS3, PIN_DC, 52); // Leave pin 52 unconnected

void setup() {
  oled1.begin(); // Note that we call begin() on oled1 first, which resets all 3 modules
  oled2.begin();
  oled3.begin();
}
Let me know if I can explain that further.

As regards refresh rate, the maximum frame rate is basically split between all the screens (the microcontroller can only be updating one screen at a time.) So with 3 screens the fastest you can update them is 1/3 the update rate for 1 screen. Whether this matters will depend on how fast you want to update them! The more pixels you update on the screen, the longer it takes.

If you want all the screens to display the same thing, you don't need to do any of this! Just write the program as if it was using one screen, and wire all the modules identically back to the same pins on the Mega (including one CS pin.) You'll get the same output on all of them, and the frame rate will be no different to if you had a single screen connected.

- Angus

Things
Posts: 36
Joined: Mon Aug 26, 2013 3:47 pm
Location: Cairns, Australia
Contact:

Re: Running multiple oLED screens with Arduino Mega 2560

Post by Things » Fri Oct 04, 2013 10:43 am

The Mega still runs at the same clock speed of 16Mhz, so the screen will run the same speed as it would on the regular 168/328p/32u4 versions of Arduino, just you have more RAM/Flash memory for storing stuff and more IO.

I've got a friend running the OLED on one of the goldilocks and it works a fair bit faster, even for a 4Mhz difference, I think you'll find the refresh rate pretty limiting running 3 screens separately, unless that wasn't an issue.

Although it's not just the refresh rate that suffers, but also the "draw" rate too (which I guess you could consider the same thing), so you'll notice it drawing the screen from 1 side to another.

However, I think the best way you can avoid slow refresh rates is trying to avoid using the library drawing functions as much as possible, such as the drawCircle functions. They involve floating point math, which on a 8bit micro is slow as anything already. Try and keep everything to integers/longs etc if you can, and you'll notice a very obvious difference. So if you find yourself constantly wanting to draw a circle, define it as a binary array and just write the pixels to the display, instead of trying to calculate it :)

aijii
Posts: 16
Joined: Thu Oct 03, 2013 12:06 pm

Re: Running multiple oLED screens with Arduino Mega 2560

Post by aijii » Sat Oct 05, 2013 2:38 am

okay - I got this working, eventually.

I did note that there is a cable length limit here... i don't know if this is exacerbated by the fact i've run 3 screens, each on a 1.3m cable (initially), in a star fashion.

I had to chop about 1/3rd off the length of each cable to make each screen work.

aijii
Posts: 16
Joined: Thu Oct 03, 2013 12:06 pm

Re: Running multiple oLED screens with Arduino Mega 2560

Post by aijii » Sat Oct 05, 2013 2:51 am

I forgot to add - thanks for your help guys!

As I start to throw some more at these screens, I'll keep you posted on how I go re:refresh rates.

I'm not intending to do a great deal, mainly text, with some bar graphs for now.

I might experiment with using BMPs for the more complicated stuff (like gauges etc) but for now numbers will do.

angusgr
Freetronics Staff
Freetronics Staff
Posts: 853
Joined: Tue Apr 09, 2013 11:19 pm
Location: Melbourne, Australia
Contact:

Re: Running multiple oLED screens with Arduino Mega 2560

Post by angusgr » Tue Oct 08, 2013 5:01 am

Thanks Things, I agree with all the excellent advice you've given.
Things wrote: However, I think the best way you can avoid slow refresh rates is trying to avoid using the library drawing functions as much as possible, such as the drawCircle functions. They involve floating point math, which on a 8bit micro is slow as anything already. Try and keep everything to integers/longs etc if you can, and you'll notice a very obvious difference. So if you find yourself constantly wanting to draw a circle, define it as a binary array and just write the pixels to the display, instead of trying to calculate it :)
Just for the record though, this isn't quite the case. No floating point math in the FTOLED library. The circle drawing stuff uses a variaton on Bresenham's line drawing algorithm, the midpoint circle algorithm, and is pure integer math. It would be much much slower if it used floating point!

Even so though the overall advice is good - if you want fast drawing, avoid calculating the curves if you can get away with defining arrays of pixels instead. :)

angusgr
Freetronics Staff
Freetronics Staff
Posts: 853
Joined: Tue Apr 09, 2013 11:19 pm
Location: Melbourne, Australia
Contact:

Re: Running multiple oLED screens with Arduino Mega 2560

Post by angusgr » Tue Oct 08, 2013 5:02 am

aijii wrote:okay - I got this working, eventually.

I did note that there is a cable length limit here... i don't know if this is exacerbated by the fact i've run 3 screens, each on a 1.3m cable (initially), in a star fashion.

I had to chop about 1/3rd off the length of each cable to make each screen work.
Thanks for letting us know. Did you happen to try a 1.3m cable with a single screen?

Things
Posts: 36
Joined: Mon Aug 26, 2013 3:47 pm
Location: Cairns, Australia
Contact:

Re: Running multiple oLED screens with Arduino Mega 2560

Post by Things » Tue Oct 08, 2013 11:55 am

angusgr wrote: Just for the record though, this isn't quite the case. No floating point math in the FTOLED library. The circle drawing stuff uses a variaton on Bresenham's line drawing algorithm, the midpoint circle algorithm, and is pure integer math.
Ah, clever :)

Post Reply