Re: Monochrome 128*64 OLED screen - SSD1306 driver questions
Re: Monochrome 128*64 OLED screen - SSD1306 driver questions
Re: Monochrome 128*64 OLED screen - SSD1306 driver questions
Re: Monochrome 128*64 OLED screen - SSD1306 driver questions
Re: Monochrome 128*64 OLED screen - SSD1306 driver questions
#include <SPI.h>
inline void SSD1306::spiwrite(uint8_t c) {
shiftOut(sid, sclk, MSBFIRST, c);
}
void SSD1306::ssd1306_command(uint8_t c) {
digitalWrite(cs, HIGH);
digitalWrite(dc, LOW);
digitalWrite (cs, LOW);
SPI.transfer (c); // clock out one byte
digitalWrite(cs, HIGH);
}
void SSD1306::ssd1306_data(uint8_t c) {
digitalWrite(cs, HIGH);
digitalWrite(dc, HIGH);
digitalWrite (cs, LOW);
SPI.transfer (c); // clock out one byte
digitalWrite(cs, HIGH);
}
#define OLED_DC 8
#define OLED_CS 10 // SPI slave-select
#define OLED_CLK 13 // hardware SPI clock
#define OLED_MOSI 11 // hardware SPI MOSI
#define OLED_RESET 7
#include <SPI.h>
Serial.begin(9600);
SPI.begin ();
Signal Chip out --> Arduino pin
Reset 3 --> 7 (was 13)
CS 5 --> 10 (was 12)
D/C 9 --> 8 (was 11)
CLK 11 --> 13 (was 10)
DAT/MOSI 14 --> 11 (was 9)
Re: Monochrome 128*64 OLED screen - SSD1306 driver questions
Re: Monochrome 128*64 OLED screen - SSD1306 driver questions
Thank you for the link. I am very interested in improving the performance, since it is a little bit slow right now.
Re: Monochrome 128*64 OLED screen - SSD1306 driver questions
NickGammon wrote:Thank you for the link. I am very interested in improving the performance, since it is a little bit slow right now.
In the context of the above message, I thought you might be interested in code that sent the data 50 times as fast.
Re: Monochrome 128*64 OLED screen - SSD1306 driver questions
Re: Monochrome 128*64 OLED screen - SSD1306 driver questions
NickGammon wrote:Just wanted you to know that I successfully got the OLED screen to work with hardware SPI. The bit-banging you currently use clocks bytes out a rate of one per 150 microseconds, but the hardware will do it in 3 microseconds. So that is 50 times faster! (This is on a Uno).
Changes needed were minimal.
In file SSD1306.cpp:
Add near the start:
- Code: Select all | TOGGLE FULL SIZE
#include <SPI.h>
Near the end, delete:
- Code: Select all | TOGGLE FULL SIZE
inline void SSD1306::spiwrite(uint8_t c) {
shiftOut(sid, sclk, MSBFIRST, c);
}
And change ssd1306_command and ssd1306_data to read:
- Code: Select all | TOGGLE FULL SIZE
void SSD1306::ssd1306_command(uint8_t c) {
digitalWrite(cs, HIGH);
digitalWrite(dc, LOW);
digitalWrite (cs, LOW);
SPI.transfer (c); // clock out one byte
digitalWrite(cs, HIGH);
}
void SSD1306::ssd1306_data(uint8_t c) {
digitalWrite(cs, HIGH);
digitalWrite(dc, HIGH);
digitalWrite (cs, LOW);
SPI.transfer (c); // clock out one byte
digitalWrite(cs, HIGH);
}
In the example sketch, change the pins to be:
- Code: Select all | TOGGLE FULL SIZE
#define OLED_DC 8
#define OLED_CS 10 // SPI slave-select
#define OLED_CLK 13 // hardware SPI clock
#define OLED_MOSI 11 // hardware SPI MOSI
#define OLED_RESET 7
And add:
- Code: Select all | TOGGLE FULL SIZE
#include <SPI.h>
Then, in setup, after:
- Code: Select all | TOGGLE FULL SIZE
Serial.begin(9600);
Add:
- Code: Select all | TOGGLE FULL SIZE
SPI.begin ();
The wiring from the CD4050 chip to the Arduino is now this:
- Code: Select all | TOGGLE FULL SIZE
Signal Chip out --> Arduino pin
Reset 3 --> 7 (was 13)
CS 5 --> 10 (was 12)
D/C 9 --> 8 (was 11)
CLK 11 --> 13 (was 10)
DAT/MOSI 14 --> 11 (was 9)
I don't know why you would want "to use other pins". The hardware pins are there, why not use them? You can always run other SPI devices by simply sharing the 3 main SPI pins (CLK, MISO, MOSI) and dedicating a different SS pin for each different device.
Re: Monochrome 128*64 OLED screen - SSD1306 driver questions
Re: Monochrome 128*64 OLED screen - SSD1306 driver questions
tallgirl wrote:Greets,
I had a problem with the LiquidCrystal library running entirely too slow. One of the posters who'd made a comment up above, Nick, pointed me back to this thread and the changes he made.
Not to be completely blunt, but the attitude that the change wasn't needed is wrong. I wasted about 30 hours debugging everything else, because I mistakenly assumed the SPI code was more efficient than it was.
The actual change to use the hardware SPI pins is very simple -- test to see if the clock and data pins are the same as the hardware ones, and if so, use SPI. The speedup was huge. Big enough that it makes the difference between having a product that my customers will buy, and one that I wouldn't be able to sell.
I'd hope that you will recognize that "It's good enough" can make the difference between products been saleable, and not so saleable.
Re: Monochrome 128*64 OLED screen - SSD1306 driver questions
Re: Monochrome 128*64 OLED screen - SSD1306 driver questions