I’ve been trying to figure out how to put multiple 1306’s on a single SPI line using the default constructor, wanted to post a few notes here to help anybody else.
Using the default constructor specifies a CS pin, but the constructor is only set up for a single display. By specifying a dummy value here, manual control can be taken over of the multiple chip select pins.
I only have 1 display hooked up right now, have another arriving saturday, then 2 more next week. Then I’ll post an update video.
Notes are amended at the bottom of the credit block.
Note that this implementation is with a Teensy 3.0. Because Paul put the LED on the SCK pin, it is easy to see when data is transferred, even using only 1 display to test4 connection ports.
/*********************************************************************
This is an example for our Monochrome OLEDs based on SSD1306 drivers
Pick one up today in the adafruit shop!
------> http://www.adafruit.com/category/63_98
This example is for a 128x64 size display using SPI to communicate
4 or 5 pins are required to interface
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, check license.txt for more information
All text above, and the splash screen must be included in any redistribution
HIGH = lock screen
LOW = enable screen
Always shows back-buffer when put low
ALL DISPLAYS HIGH
Sent display 1 data
DISPLAY 1 LOW
DISPLAY 1 HIGH
Clear screen
Sent display 2 data
DISPLAY 2 LOW
DISPLAY 2 HIGH
clear screen
Sent display 3 data
DISPLAY 3 LOW
DISPLAY 3 HIGH
clear screen
Sent display 4 data
DISPLAY 4 LOW
DISPLAY 4 HIGH
clear screen
top left- 20
top right- 21
bottom left- 10
bottom right- 9
*********************************************************************/
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_DC 15
#define OLED_CS 28 // use dummy value
#define OLED_CLK 13
#define OLED_MOSI 11
#define OLED_RESET 14
Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
#if (SSD1306_LCDHEIGHT != 64)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif
void setup() {
pinMode(20,OUTPUT);
pinMode(21,OUTPUT);
pinMode(10,OUTPUT);
pinMode(9,OUTPUT);
digitalWrite(20, LOW);
digitalWrite(21, LOW);
digitalWrite(10, LOW);
digitalWrite(9, LOW);
// by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
display.begin(SSD1306_SWITCHCAPVCC);
// init done
display.display(); // show splashscreen
delay(2000);
display.clearDisplay(); // clears the screen and buffer
// text display tests
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,0);
digitalWrite(20, HIGH);
digitalWrite(21, HIGH);
digitalWrite(10, HIGH);
digitalWrite(9, HIGH);
}
void loop() {
//block one
digitalWrite(20, LOW);
display.print("Time1: ");
display.println(millis());
display.print("data2: ");
display.println(millis());
display.print("data3: ");
display.println(millis());
display.print("data4: ");
display.println(millis());
display.print("data5: ");
display.println(millis());
display.print("data6: ");
display.println(millis());
display.print("data7: ");
display.println(millis());
display.print("data8: ");
display.println(millis());
display.display();
digitalWrite(20, HIGH);
display.clearDisplay();
display.setCursor(0,0);
display.display();
delay(500);
//block two
digitalWrite(21, LOW);
display.print("Time2: ");
display.println(millis());
display.display();
digitalWrite(21, HIGH);
display.clearDisplay();
display.setCursor(0,0);
display.display();
delay(500);
//block three
digitalWrite(10, LOW);
display.print("Time3: ");
display.println(millis());
display.display();
digitalWrite(10, HIGH);
display.clearDisplay();
display.setCursor(0,0);
display.display();
delay(500);
//block four
digitalWrite(9, LOW);
display.print("Time4: ");
display.println(millis());
display.display();
digitalWrite(9, HIGH);
display.clearDisplay();
display.setCursor(0,0);
display.display();
delay(500);
}