
Originally Posted by
kirberich
So I've done a bit of digging, and it turns out the error might actually lie in my display, not in my code. I've tried out Sumotoy's very nice library for the same display, and when using it with overclocking it breaks exactly like this one.
I recommend you try using the library at 96MHz and just see if it works - if it doesn't, there is one thing you can do: do #define SLOW_SPI before including the library. This will slow down the SPI communication from 18 to 15mhz, which, at least for me, makes the display work. The downside is that this does slow down the display quite a lot, so you might find you get better speed with a non-overclocked teensy.
Let me know how it goes!
Thanks for the reply. Still love the uber-performance of this library.
Sadly, I'm having a lot of trouble integrating it with my project that drives APA102 LEDs. I suspect that something in the SSD library is not cooperating with other things that use the SPI bus.
Setting FASTLEDTEST to 1 int he following sketch drives the APA102s, but not the display (more than a frame or two).. Disabling FASTLEDTEST, the display works fine.
Code:
#define FASTLEDTEST 1
#define SLOW_SPI
#include <Arduino.h>
#include <SPI.h>
#include <ssd1351.h>
// use this to do Color c = RGB(...) instead of `RGB c = RGB(...)` or ssd1351::LowColor c = RGB(...)
// because it's slightly faster and guarantees you won't be sending wrong colours to the display.
// Choose color depth - IndexedColor, LowColor and HighColor currently supported
// typedef ssd1351::IndexedColor Color;
// typedef ssd1351::LowColor Color;
typedef ssd1351::HighColor Color;
// Choose display buffering - NoBuffer or SingleBuffer currently supported
// auto display = ssd1351::SSD1351<Color, ssd1351::NoBuffer, 128, 96>();
auto display = ssd1351::SSD1351<Color, ssd1351::SingleBuffer, 128, 128>();
#include <FastLED.h>
#define NUM_LEDS 42
CRGB leds[NUM_LEDS];
bool up = false;
int pos = 127;
const int particles = 256;
int offsets[particles];
int x_pos[particles];
int y_pos[particles];
Color particle_colors[particles];
void setup() {
Serial.begin(9600);
Serial.println("Booting...");
display.begin();
Serial.println("Display set up.");
if( FASTLEDTEST )
{
pinMode( 7, OUTPUT );
FastLED.addLeds<APA102, BGR>(leds, NUM_LEDS);
FastLED.setBrightness(10);
}
for (int i = 0; i < particles; i++) {
x_pos[i] = random(0, 128);
y_pos[i] = random(0, 96);
particle_colors[i] = ssd1351::RGB(0, i + 10, i/2 + 10);
}
}
void loop() {
for( int i = 0 ; i < NUM_LEDS ; i++ )
leds[i] = CRGB::Green;
leds[millis()/100 % NUM_LEDS] = CRGB::White;
if( FASTLEDTEST )
{
// beginTransaction prevents SPI bus conflicts
SPI.beginTransaction(SPISettings(24000000, MSBFIRST, SPI_MODE0));
digitalWrite(7, HIGH); // enable access to LEDs
FastLED.show();
digitalWrite(7, LOW);
SPI.endTransaction(); // allow other libs to use SPI again
}
unsigned long before = millis();
display.fillScreen(ssd1351::RGB());
Color circleColor = ssd1351::RGB(0, 128, 255);
for (int i = 0; i < particles; i++) {
offsets[i] += random(-2, 3);
display.drawLine(
x_pos[i] + offsets[i],
y_pos[i] + offsets[i],
pos,
80 + sin(pos / 4.0) * 20,
particle_colors[i]
);
display.drawCircle(
x_pos[i] + offsets[i],
y_pos[i] + offsets[i],
1,
circleColor
);
}
display.updateScreen();
Serial.println(millis() - before);
if (up) {
pos++;
if (pos >= 127) {
up = false;
}
} else {
pos--;
if (pos < 0) {
up = true;
}
}
}