Originally used a 20x4 led screen to display information received via an IR receiver with this code and it seemed to be working.
// Seems to work
#include <IRremote.h>
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
void dump(decode_results *results)
{
// Dumps out the decode_results structure.
// Call this after IRrecv::decode()
int count = results->rawlen;
if (results->decode_type == UNKNOWN) {
Serial.print("Unknown encoding: ");
}
else if (results->decode_type == NEC) {
Serial.print("Decoded NEC: ");
}
else if (results->decode_type == SONY) {
Serial.print("Decoded SONY: ");
}
else if (results->decode_type == RC5) {
Serial.print("Decoded RC5: ");
}
else if (results->decode_type == RC6) {
Serial.print("Decoded RC6: ");
}
Serial.print(results->value, HEX);
Serial.print(" (");
Serial.print(results->bits, DEC);
Serial.println(" bits)");
Serial.print("Raw (");
Serial.print(count, DEC);
Serial.print("): ");
for (int i = 1; i < count; i++)
{ //The change is inside this loop. Changed to HEX for easy copy and paste.
Serial.print("");
Serial.print(results->rawbuf[i]*USECPERTICK, DEC);
Serial.print(", ");
}
Serial.println();
}
const int RECV_PIN=3;
IRrecv irrecv(RECV_PIN);
decode_results results;
//Set the pins on the I2C chip used for LCD connections
//ADDR,EN,R/W,RS,D4,D5,D6,D7
LiquidCrystal_I2C lcd(0x27,2,1,0,4,5,6,7); // 0x27 is the default I2C bus address of the backpack-see article
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
irrecv.blink13(true);
// Set off LCD module
lcd.begin (20,4); // 20 x 4 LCD module
lcd.setBacklightPin(3,POSITIVE); // BL, BL_POL
lcd.setBacklight(HIGH);
lcd.print("Hello, I'm ready to");
lcd.setCursor(0,1);
lcd.print("receive IR codes");
}
void loop()
{
if (irrecv.decode(&results))
{
Serial.println("Hex:\t\tDecimal:");
Serial.print(results.value, HEX);
Serial.print("\t");
Serial.println(results.value, DEC);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("IR Signal Read:");
lcd.setCursor(0,1);
lcd.print("DEC: ");
lcd.print(results.value, DEC);
lcd.setCursor(0,2);
lcd.print("HEX: ");
lcd.print(results.value, HEX);
dump(&results);
irrecv.resume(); // Receive the next value
}
}
Received some OLED screens and tested the screen functioning with the demo in Examples->Adafruit SSD1306->ssd1306_128x64_i2c
Trying to implement the OLED with the IR receiving code with this
// 0 - 15 yellow
// 16 - 64 blue
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <IRremote.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
const int RECV_PIN=3;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
Serial.begin(9600);
if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS))
{
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
// Show initial display buffer contents on the screen --
// the library initializes this with an Adafruit splash screen.
display.display();
delay(2000); // Pause for 2 seconds
// Clear the buffer
display.clearDisplay();
// Draw a single pixel in white
display.drawPixel(10, 10, SSD1306_WHITE);
// Show the display buffer on the screen. You MUST call display() after
// drawing commands to make them visible on screen!
display.display();
delay(2000);
irrecv.enableIRIn(); // Start the receiver
irrecv.blink13(true);
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0, 16);
// Display static text
display.println("Hello, I'm ready to\nreceive IR codes");
display.display();
}
void dump(decode_results *results)
{
// Dumps out the decode_results structure.
// Call this after IRrecv::decode()
int count = results->rawlen;
if (results->decode_type == UNKNOWN)
{
Serial.print("Unknown encoding: ");
}
else if (results->decode_type == NEC)
{
Serial.print("Decoded NEC: ");
}
else if (results->decode_type == SONY)
{
Serial.print("Decoded SONY: ");
}
else if (results->decode_type == RC5)
{
Serial.print("Decoded RC5: ");
}
else if (results->decode_type == RC6)
{
Serial.print("Decoded RC6: ");
}
Serial.print(results->value, HEX);
Serial.print(" (");
Serial.print(results->bits, DEC);
Serial.println(" bits)");
Serial.print("Raw (");
Serial.print(count, DEC);
Serial.print("): ");
for (int i = 1; i < count; i++)
{ //The change is inside this loop. Changed to HEX for easy copy and paste.
Serial.print("");
Serial.print(results->rawbuf[i]*USECPERTICK, DEC);
Serial.print(", ");
}
Serial.println();
for (int i = 1; i < count; i++)
{ //The change is inside this loop. Changed to HEX for easy copy and paste.
Serial.print("0x");
Serial.print(results->rawbuf[i]*USECPERTICK, HEX);
Serial.print(", ");
}
Serial.println();
}
void loop()
{
if (irrecv.decode(&results))
{
Serial.println("Hex:\t\tDecimal:");
Serial.print(results.value, HEX);
Serial.print("\t");
Serial.println(results.value, DEC);
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0, 16);
// Display static text
display.println("IR signal read:\n");
display.print("Decimal: ");
display.println(results.value, DEC);
display.print("Hex: ");
display.println(results.value, HEX);
display.display();
dump(&results);
irrecv.resume(); // Receive the next value
}
}
Nothing happens on the screen and get "SSD1306 allocation failed" in the Serial. The problem is line 17
IRrecv irrecv(RECV_PIN)
What's the issue here?