Buenas tardes a todos, y gracias por adelantado por vuestra ayuda.
Quiero poner una pantalla OLED 128x64 I2C con un logo en un proyecto que usa un sensor de color TCS34725 I2C pero no consigo que inicialice la pantalla.
Por separado cada programa realiza su trabajo correctamente, pero cuando fundo los dos proyectos estoy metiendo la pata en algo que me esta volviendo loco.
Por favor podeis echarle un ojo.
He escaneado las direcciones obteniendo 0X3C para la pantalla y 0x29 para el sensor.
Muchas gracias y disculpa si se trata de una tonteria pero no soy capaz de verlo.
#include <Servo.h>
#include <Wire.h>
#include "Adafruit_TCS34725.h"
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define ANCHO_PANTALLA 128 // Ancho de la pantalla OLED
#define ALTO_PANTALLA 64 // Alto de la pantalla OLED
#define OLED_RESET -1 // Pin reset incluido en algunos modelos de pantallas (-1 si no disponemos de pulsador).
#define DIRECCION_PANTALLA 0x3C //Dirección de comunicacion
Adafruit_SSD1306 display(ANCHO_PANTALLA, ALTO_PANTALLA, &Wire, OLED_RESET);
#define LOGO_WIDTH 84
#define LOGO_HEIGHT 52
const unsigned char PROGMEM logo[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x80, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xc2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x7f, 0xe3, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xff, 0xf0, 0xf8, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xff, 0xf8, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x1f, 0xff, 0xf8, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xff, 0xf1, 0xff, 0x80,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xff, 0xe3, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xff, 0xff, 0xc3, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xff, 0xc3, 0x00, 0x7f,
0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0x82, 0x00, 0x1f, 0xf0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0xfe, 0x00, 0x00, 0x0f, 0xe4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0xfc, 0x00, 0x00,
0x07, 0xdc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x38, 0x03, 0xfc, 0x03, 0x32, 0x00, 0x00, 0x00,
0x00, 0x00, 0x09, 0x90, 0x0f, 0xff, 0x00, 0x4e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x60, 0x3f,
0xff, 0x80, 0x98, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13, 0x80, 0x7f, 0xff, 0xc0, 0x67, 0x80, 0x00,
0x00, 0x00, 0x00, 0x1c, 0x00, 0x7f, 0xff, 0xe0, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00,
0x7f, 0xff, 0xe0, 0x3f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x80, 0x7f, 0xff, 0xf0, 0x3f, 0x80,
0x00, 0x00, 0x00, 0x00, 0x3f, 0x80, 0x3f, 0xff, 0xf0, 0x3f, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x3f,
0x81, 0x3f, 0xff, 0xf0, 0x1f, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x81, 0x1f, 0xff, 0xf0, 0x1f,
0xc0, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x01, 0x3f, 0xff, 0xf0, 0x1f, 0xc0, 0x00, 0x00, 0x00, 0x00,
0x7f, 0x01, 0x33, 0xf9, 0xf0, 0x1f, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x20, 0x70,
0x1f, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x80, 0x20, 0x20, 0x1f, 0xc0, 0x00, 0x00, 0x00,
0x00, 0x7f, 0x00, 0x00, 0x60, 0x20, 0x1f, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x80, 0x01, 0x10,
0x60, 0x1f, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x33, 0x80, 0xcf, 0x1f, 0xe0, 0x3f, 0xc0, 0x00, 0x00,
0x00, 0x00, 0x30, 0x00, 0xff, 0x0f, 0xe0, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x7f,
0x1f, 0xc0, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x23, 0x00, 0x07, 0x1c, 0x00, 0xff, 0x80, 0x00,
0x00, 0x00, 0x00, 0x03, 0xc0, 0x03, 0xfc, 0x00, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x07, 0xf8,
0x03, 0xf8, 0x00, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x07, 0xfc, 0x03, 0xf8, 0x00, 0x7f, 0xc0,
0x00, 0x00, 0x00, 0x00, 0x07, 0xf8, 0x00, 0x60, 0x00, 0x7f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x07,
0xf8, 0x00, 0x00, 0x00, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xfc, 0x00, 0x00, 0x06, 0x60,
0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xff, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x0f, 0xff, 0x80, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xff, 0xe0, 0x00, 0xff,
0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xfe, 0x07, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x7f, 0xff, 0x0f, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0x8f,
0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xfe, 0xd7, 0xfe, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x03, 0xfe, 0xd7, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe,
0xd7, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0xd7, 0x80, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00
};
Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_50MS, TCS34725_GAIN_4X);
Servo wheelServo; // create a servo object to control a servo
Servo chuteServo; // create another servo object to control a servo
const int calibrating = 0; //change this to 0 when you want to run the machine and to 1 when you set it up for the first time
const int wheelOverRun = 190; //decrease this if the skittle goes past the colour sensor or increase it if the skittle stops before it reaches the sensor
const int contactSwitch = 8;
const int resetButtonPin = 7;
int switchState;
int arrayIndexToAimAt;
int redCount = 0;
int greenCount = 0;
int yellowCount = 0;
int orangeCount = 0;
int purpleCount = 0;
float redReading, greenReading, blueReading; //somewhere to store our colour sensor readings
const int arrayRows = 6;
const int arrayColumns = 6;
int SAMPLES[arrayRows][arrayColumns] = { // array goes red value, green value, blue value, colour, difference to sample (update by code later), angle for depositor
{84, 78, 82, "Red", 0, 0}, //red -0
{59, 105, 77, "Green", 0, 40}, //green -1
{84, 96, 61, "Yellow", 0, 80}, //yellow -2
{102, 75, 65, "Orange", 0, 120}, //orange -3
{63, 85, 95, "Purple", 0, 150}, //purple -4
{62, 87, 93, "No Skittle", 0, 75}, //no skittle -5
};
// Determines the number of samples stored in the array
const byte samplesCount = sizeof(SAMPLES) / sizeof(SAMPLES[0]);
void setup()
{
pinMode(contactSwitch, INPUT_PULLUP);
pinMode(resetButtonPin, INPUT);
Serial.begin(9600);
if(!display.begin(SSD1306_SWITCHCAPVCC, DIRECCION_PANTALLA)) {
Serial.println(F("Fallo en la asignacion de SSD1306"));
}
if (tcs.begin()) {
//Serial.println("Found sensor");
} else {
Serial.println("No TCS34725 found ... check your connections");
while (1); // halt!
}
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.println("LaBuhardillaDelLoco");
display.display();
display.drawLine(0, 10, 128, 10, WHITE);
display.display();
display.drawBitmap( (display.width() - LOGO_WIDTH ) / 2,((display.height()- LOGO_HEIGHT) / 2 )+7, logo, LOGO_WIDTH, LOGO_HEIGHT, WHITE);
display.display();
wheelServo.attach(5); // attaches the servo on pin d5 to the servo object
chuteServo.attach(6); // attaches the servo on pin d6 to the servo object
printArray(SAMPLES) ;
}
void loop()
{

