Pixy2 and SSD1306 and Servo

Hi, I hope I can describe my issue clearly enough…

I have a Pixy2 connected to Arduino Uno through ICSP header and am successfully driving a robotic cart.
To enhance the user feedback of the cart, I want to display certain output on a SSD1306 OLED display connected to the Uno through the I2C - SCL/SDA pins.

I had this all working and added the OLED as a later enhancement and I have struggled to get the OLED to initialise. I have broken the code down to the below example for simplicity.


  1. I have changed the I2C address for the OLED to 0x3D (from the default 0x3C) but this didn’t fix the issue.
  2. If I uncomment the Servo declaration (//Servo leftServo;) then the OLED fails to initialise.

Any help would be greatly appreciated.

Sample code is…

#include <Arduino.h>
#include <Servo.h>
#include <SPI.h>
#include <Pixy2.h>
#include <PIDLoop.h>

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Fonts/FreeSansOblique9pt7b.h>

#define SCREEN_WIDTH 128 // OLED display width,  in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define I2C_ADDRESS 0x3D // I2C address for OLED display (or 0x3C)

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
Pixy2 pixy;

//Servo leftServo;

void setup()
    Serial.println(F("Initialising SSD1306"));

    if (!display.begin(SSD1306_SWITCHCAPVCC, I2C_ADDRESS))
        Serial.println(F("SSD1306 allocation failed"));
        while (true);
    Serial.println(F("SSD1306 allocation SUCCES"));

	// some stuff - happy to share...

void loop()
	// some stuff - happy to share...

What is the OLED module that you are using and how have you wired it?

If you leave the servo line in, then what happens?

To confirm the address of the OLED use the address scan utility:
How to Scan I2C Address in Arduino - Hackster.io

When you have confirmed the address, load and run an example from the Adafruit SSD1306 Examples folder, selecting one that matches your OLED size and adjusting the address, if necessary…


Hi Jeff,

The OLED is an SSD1306 (128x64). It is wired to the Uno through the SCL/SDA pins (A5/A4).
Yes I have confirmed the OLED address (0x3D) and have it running on a testbed to confirm.

If I leave the Servo line in the code drops to:
Serial.println(F(“SSD1306 allocation failed”));

If I leave the Servo line out then the OLED initialises correctly (but then of course I lose my servos :-))


1 Like

I can’t think of any connection between servos and I2C. One possibility is that you are running out of memory - check that the program is not too big for the UNO. Are all the string literals in Flash?

It might make a difference if you can confirm that all the servos are using ports that support PWM in hardware. Otherwise, you could try using a different library for one of those functions

1 Like

Thanks Jeff, I will chase down your suggestions :+1:

1 Like