<< return to Pixycam.com

Pixy2 conflict with SSD1306

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.
However the OLED fails to initialise (if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3D)))
when I declare the Pixy2 object (Pixy2 pixy;)

Note:
I have changed the I2C address for the OLED to 0x3D (from the default 0x3C) but this didn’t fix the issue.

Has anyone else experienced this?
Thanks for any help.

Hmm, that’s odd. Pixy is configured by default to use the SPI port (which the ICSP header uses). What happens if you initialize the OLED first and then Pixy?

Edward

Hi Edward,

Yes it is very odd. I have tried re-ordering the code sequence but with no success.
I have made one further revelation as well. I have simplified the problem in the code shared below with the following notes:
I have changed the I2C address for the OLED to 0x3D (from the default 0x3C) but this didn’t fix the issue.
If I uncomment the Servo declaration (//Servo leftServo;) then the OLED fails to initialise.
Sample code is…

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 :-))

#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.begin(9600);
    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...
}

Hello,
It sounds like there is a conflict between the OLED and the servos. Perhaps Pixy is just an innocent bystander? What Arduino signals do the OLED and servos use?

Edward

I have a similar effect with vl53l0x Time-of-Flight sensors. I have an Arduino Nano with a Pixy connected to the IPSC Headers and an vl53l0x Time of Flight distance sensor connected to the I2C Bus. The Pixy2 Hello World sketch runs ok. So does the Adafruit test sketch for the distance sensor.
When I use both within the same sketch, either pixy.init() or sensor.begin() hang, depending on which one is used first. If i comment out one of them, the other one works perfectly ok. Are there any known fixes or workarounds for these problems?

Hello,
The Arduino ICSP connector uses SPI, which shouldn’t conflict with I2C. Since you have source code to the Pixy Arduino library, you could put some prints in the Pixy init() routine. See line 144 below:

(Tpixy.h is installed on your machine wherever the Arduino libraries are stored. You can modify it.) With the prints, you can determine where the code is hanging. It is likely hanging in line 149 where it opens the SPI port. Assuming it’s hanging there, it’s likely the other code is also calling SPI.begin() or doing something with the SPI port. (See this file, line 30.) But it’s going to require some investigating.

Edward

Thanks Edward, I’ll try that. The conflict occurs between pixy.init() and Adafruit_VL53L0X() constructor for the tof sensor object.
So I’ll look into that library too to investigate where the two libraries influence each other.