Need help in coding to display Pixy 2 camera result on LCD and OLed Display along with distance sensor

#1

Dear All,

I need your help in coding to display the pixy2 result on LCD and LED with Ultrasonic by using Arduino UNO. Currently, I am getting the output when I attached pixy 2 camera with an OLED display and Ultrasonic Sensor with Arduino UNO. but when I attached the LCD display with SDA and SCL. The whole system stops working. that’s happening of Multiple I2 C devices are connected with Arduino UNO?

#include <OLED_I2C.h>
#include <Wire.h>
#include <Pixy2.h>

#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);

Pixy2 pixy;
OLED myOLED(SDA, SCL); // Remember to add the RESET pin if your display requires it…
extern uint8_t SmallFont[];
extern uint8_t MediumNumbers[];
extern uint8_t BigNumbers[];
int trigPin = 5; // Trigger
int echoPin = 6; // Echo
long duration, cm, inches;

void setup()

{
lcd.init();
lcd.backlight();
lcd.setCursor(3,0);
lcd.print(“Sign Board”);
lcd.setCursor(2,1);
lcd.print(“Detection System”);
delay(5000);
lcd.clear();

Serial.begin(9600);
Serial.print(“Starting…\n”);
// we need to initialize the pixy object
pixy.init();
// Change to line tracking program
pixy.changeProg(“line”);

pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);

if(!myOLED.begin(SSD1306_128X64))
while(1); // In case the library failed to allocate enough RAM for the display buffer…
myOLED.setFont(SmallFont);

}

void loop()
{
int8_t i;
char buf[128];
myOLED.clrScr();
pixy.line.getAllFeatures();

// UltraSonic Sensor
digitalWrite(trigPin, LOW);
delayMicroseconds(5);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);

pinMode(echoPin, INPUT);
duration = pulseIn(echoPin, HIGH);

// Convert the time into a distance
cm = (duration/2) / 29.1; // Divide by 29.1 or multiply by 0.0343
inches = (duration/2) / 74; // Divide by 74 or multiply by 0.0135

// OLED Display
{
myOLED.clrScr();
myOLED.setFont(SmallFont);
myOLED.print(“Distance:”, LEFT, 0);
myOLED.print("In Centimeters = ", LEFT, 20);
myOLED.print("In Inches = ", LEFT, 46);
{
myOLED.setFont(BigNumbers);
myOLED.printNumI(cm, RIGHT, 10);
myOLED.printNumI(inches, RIGHT, 40);
myOLED.update();
}
delay(250);
}

if (pixy.line.barcodes)
{
if (pixy.line.barcodes->m_code==0){
pixy.line.barcodes->print();
myOLED.clrScr();
myOLED.setFont(SmallFont);
myOLED.print(“STOP:”, CENTER, 32);
delay(250);
}
{
if (cm > 0 && cm < 15)
{
myOLED.setFont(SmallFont);
myOLED.print(“Please Slow Down your car”, LEFT, 32);
myOLED.print(“Car”, CENTER, 40);
myOLED.update();
}
delay(500);
myOLED.update();
myOLED.clrScr();

}
}
Serial.print(inches);
Serial.print("in, ");
Serial.print(cm);
Serial.print(“cm”);
Serial.println();
}

0 Likes