Newhaven Products > OLEDs

NHD-0216AW-IB3 with Arduino Uno Code example?

<< < (2/2)

Chris O.:
Whoops it appears I have more than one of these libraries all over in different Arduino installations  :-[.
Well this time I did test it and it compiles, i hate to do this to you but you have to try again with these files.

keywords.txt / OLedI2C.cpp / OLedI2C.h
The 3 files should be in %your arduino dir%\libraries\OLedI2C\
The directory name must match the library name for libraries to work.

OLedI2C.cpp

--- Code: ---// 1602-OLED-Arduino-Library/OLedI2C.cpp
// keywords.txt / OLedI2C.cpp / OLedI2C.h
// The 3 files should be in %your arduino dir%\libraries\OLedI2C\
// The directory name must match the library name for libraries to work.

/*
This is my first Library to make writing to the OLED 1602
 Display much easier, the display is based on the SSD1311.
 The display has 16 characters and 2 lines.
 The library is far from complete and may be prone to errors.
 Feedback welcome, visit www.gadjet.co.uk
 Phil Grant 2013
 Scrolling contributed by Nathan Chantrell http://nathan.chantrell.net/
 Updated 06/11/2013 to include the cursPos data in the sendString function
 sendString("string", col, row)
 */
#include "OLedI2C.h"

#if (ARDUINO <  100)
#include <WProgram.h>
#else
#include <Arduino.h>
#endif

#include "Wire.h"
////////////////#define OLED_Address 0x3c
#define OLED_Command_Mode 0x80
#define OLED_Data_Mode 0x40

OLedI2C::OLedI2C(){
}
OLedI2C::~OLedI2C(){
}

uint8_t _OLED_Address; //global variable initialization

void OLedI2C::init(uint8_t OLED_Address) {

  _OLED_Address = OLED_Address;

  // *** I2C initial *** //
  delay(100);
  sendCommand(0x2A); //function set (extended command set)
  sendCommand(0x71); //function selection A
  sendData(0x00); // disable internal VDD regulator (2.8V I/O). data(0x5C) = enable regulator (5V I/O)
  sendCommand(0x28); //function set (fundamental sendCommand set)
  sendCommand(0x08); //display off, cursor off, blink off
  sendCommand(0x2A); //function set (extended command set)
  sendCommand(0x79); //OLED command set enabled
  sendCommand(0xD5); //set display clock divide ratio/oscillator frequency
  sendCommand(0x70); //set display clock divide ratio/oscillator frequency
  sendCommand(0x78); //OLED command set disabled
  sendCommand(0x09); //extended function set 4 line
  sendCommand(0x06); //COM SEG direction
  sendCommand(0x72); //function selection B
  sendData(0x00); //ROM CGRAM selection
  sendCommand(0x2A); //function set (extended command set)
  sendCommand(0x79); //OLED command set enabled
  sendCommand(0xDA); //set SEG pins hardware configuration
  sendCommand(0x10); //set SEG pins hardware configuration
  sendCommand(0xDC); //function selection C
  sendCommand(0x00); //function selection C
  sendCommand(0x81); //set contrast control
  sendCommand(0x7F); //set contrast control
  sendCommand(0xD9); //set phase length
  sendCommand(0xF1); //set phase length
  sendCommand(0xDB); //set VCOMH deselect level
  sendCommand(0x40); //set VCOMH deselect level
  sendCommand(0x78); //OLED command set disabled
  sendCommand(0x28); //function set (fundamental command set)
  sendCommand(0x01); //clear display
  sendCommand(0x80); //set DDRAM address to 0x00
  sendCommand(0x0C); //display ON

  delay(150);
  sendCommand(0x0C);  // **** Turn on Display
  delay(150);
}

// void OLedI2C::cursPos(uint8_t col, uint8_t row)
// {
// int row_offsets[] = { 0x00, 0x40 };
// sendCommand(0x80 | (col + row_offsets[row]));
// }

void OLedI2C::cursPos(uint8_t col, uint8_t row)
{
  int row_offsets[] = {
    0x00, 0x20, 0x40, 0x60   };// **************THIS WAS THE CHANGE FOR 4 LINES
  sendCommand(0x80 | (col + row_offsets[row])); //was 0x80
}

// NEW 03-23-2015
// cloumn, row / setCursor
void OLedI2C::setCursor(uint8_t col, uint8_t row)
{
  int row_offsets[] = {
    0x00, 0x20, 0x40, 0x60   };// **************
  sendCommand(0x80 | (col + row_offsets[row]));
}

void OLedI2C::clearLcd()
{
  sendCommand(0x01);
}

// arduino com.
void OLedI2C::clear() // *********Compatible with LiquidCrystal lib.
{
  sendCommand(0x01);
}

void OLedI2C::home()
{
  sendCommand(0x02);
}

void OLedI2C::lcdOff()
{
  sendCommand(0x08);  // **** Turn on Off
}

void OLedI2C::lcdOn()
{
  sendCommand(0x0C);  // **** Turn on On
}

void OLedI2C::noDisplay() // *********Compatible with LiquidCrystal lib.
{
  sendCommand(0x08);  // **** Turn on Off
}

void OLedI2C::display() // *********Compatible with LiquidCrystal lib.
{
  sendCommand(0x0C);  // **** Turn on On
}

// Turns the underline cursor on/off
void OLedI2C::noCursor() {
  sendCommand(0x0C);   // **** Turn Off underline cursor
}
void OLedI2C::cursor() {
  sendCommand(0x0E);  // **** Turn On underline cursor
}

// Turn on and off the blinking cursor
void OLedI2C::noBlink() {
  sendCommand(0x0C);  // **** Turn Off blinking cursor
}
void OLedI2C::blink() {
  sendCommand(0x0D);  // **** Turn On blinking cursor
}


void OLedI2C::sendCommand(unsigned char command)
{
  Wire.beginTransmission(_OLED_Address); // **** Start I2C
  Wire.write(OLED_Command_Mode);      // **** Set OLED Command mode
  Wire.write(command);
  Wire.endTransmission();                  // **** End I2C
}

// ARDUINO 0.23 ~ ARDUINO 1.0.0 and Up ======= Print ==============================================
#if (ARDUINO <  100)
inline void OLedI2C::write(uint8_t value) {
  sendData(value);
}
#else
inline size_t OLedI2C::write(uint8_t value) {
  sendData(value);
}
#endif

void OLedI2C::setDoubleH(uint8_t MODE) // 09-19-2015 / Double Height Display MODE 0~4
// MODE: "0"=Normal 4-line, "1"=Bottom half Double Height, "2"=Middle Double Height, "3"=Top/Bottom Double Height, "4"=Top Double Height
{
  sendCommand(0x2A);// Function Set  (extended command set / Extension register, RE ("1")set) B00101010
  sendCommand(B00001001);//Extended Function Set (FW = "0": 5-dot font width, black/white invert cursor DIS,NW = "1": 3-line or 4-line display mode)
  switch (MODE) {
  case 0:    //MODE 0 4x20-line
    sendCommand(0x28);// Function Set (Go Back to Fundamental Command Set)//101000
    break;
  case 1:    //MODE 1 0x10 / Double Height (4-line)/Display-dot shift
    sendCommand(B00010000); //MODE 2
    sendCommand(0x2C);//101100 Function Set ( when (N=1 :4-line )and(NW=1), Double height =1 Enable, Extension register, RE"0", Extension register, IS"0" )
    break;
  case 2:    //MODE 2 0x14 / Double Height (4-line)/Display-dot shift
    sendCommand(B00010100);   //MODE 2 0x14 / Double Height (4-line)/Display-dot shift
    sendCommand(0x2C);//101100 Function Set ( when (N=1 :4-line )and(NW=1), Double height =1 Enable, Extension register, RE"0", Extension register, IS"0" )
    break;
  case 3:    //MODE 3 0x18 / Double Height (4-line)/Display-dot shift (DH’ = "0": dot scroll enable (POWER UP))
    sendCommand(B00011000);
    //sendCommand(B00011001); //MODE 3 0x19 / Double Height (4-line)/Display-dot shift (DH’ = "1": display shift enable)
    sendCommand(0x2C);//101100 Function Set ( when (N=1 :4-line )and(NW=1), Double height =1 Enable, Extension register, RE"0", Extension register, IS"0" )
    break;
  case 4:
    sendCommand(B00011100);  //MODE 4 0x1C / Double Height (4-line)/Display-dot shift(DH’ = "0": display shift DIS)
    sendCommand(0x2C);//101100 Function Set ( when (N=1 :4-line )and(NW=1), Double height =1 Enable, Extension register, RE"0", Extension register, IS"0" )
    break;
  }
}

void OLedI2C::sendFloat(float digit, uint8_t dec, uint8_t nad, uint8_t col, uint8_t row)
{
  char line[10];//Ten characters, I hope that's enough
  dtostrf(digit,dec,nad,line);//Convert the float value to a string
  sendString(line, col, row);
}

void OLedI2C::setContrast(unsigned char contrast) // contrast as 0x00 to 0xFF
{
  //Set OLED Command set
  sendCommand(0x2A);        //Function Set  N = 1, BE = 0, RE = 1 Set, REV = "0": normal display (POR)  B00101010
  sendCommand(0x79);        //OLED Characterization / 0x79 B1111001 =  OLED command set is enabled
  sendCommand(0x81);  // Set Contrast
  sendCommand(contrast); // send contrast value
  sendCommand(0x78);  // OLED Characterization / 0x78 B1111000 =Exiting Set OLED Command set disabled (POR)
  sendCommand(0x28);       // Function Set / B101000 (Go Back to Fundamental Command Set)
}

void OLedI2C::sendString(const char *String, uint8_t col, uint8_t row)
{
  cursPos(col, row);
  unsigned char i=0;
  while(String[i])
  {
    sendData(String[i]);      // *** Show String to OLED
    i++;
  }
}

void OLedI2C::sendData(unsigned char data)
{
  Wire.beginTransmission(_OLED_Address);  // **** Start I2C
  Wire.write(OLED_Data_Mode);      // **** Set OLED Data mode
  Wire.write(data);
  Wire.endTransmission();                     // **** End I2C
}

void OLedI2C::scrollString(char* message, byte row, unsigned int time)//written by Nathan Chantrell http://nathan.chantrell.net/
{
  char buffer[16];
  for (byte i=0;i<strlen(message)+16;i++) {
    byte pos = i+1;
    for (byte j=0;j<16;j++) {
      if ((pos<16)||(pos>strlen(message)+15)) { // pad and trail with blank spaces
        buffer[j]=' ';
      }
      else buffer[j]=message[pos-16];
      pos++;
    }
    //cursPos(0,row); removed by PG
    sendString(buffer, 0, row); //Edited by PG tho include the cursor pos within the sendString command
    delay(time);
  }
}




//#define OLED_Command_Mode 0x80
//#define OLED_Data_Mode 0x40
// NEW 03-23-2015
// Allows us to fill the first 8 CGRAM locations
// with custom characters
void OLedI2C::createChar(uint8_t location, uint8_t charmap[])
{
  location &= 0x7; // we only have 8 locations 0-7
  //Wire.beginTransmission(_OLED_Address);
  //Wire.write(OLED_Data_Mode | (location << 3)); // SETCGRAMADDR 0x40  [ Wire.write(B01000000); ]
  //Wire.endTransmission();

  Wire.beginTransmission(_OLED_Address); // **** Start I2C
  Wire.write(OLED_Command_Mode); // 0x80
  Wire.write(0x40 | (location << 3));      // **** Set OLED Command mode
  Wire.endTransmission();                  // **** End I2C
 

  for (uint8_t i = 0 ; i < 8 ; i++) {
    Wire.beginTransmission(_OLED_Address); // **** Start I2C
    Wire.write(OLED_Data_Mode);      // **** Set OLED Data mode
    Wire.write(charmap[i]);
    Wire.endTransmission();                     
  }
}
 
/*
// NEW 03-31-2015
// Allows us to fill the first 8 CGRAM locations
// with custom characters
void OLedI2C::createChar(uint8_t location, uint8_t charmap[])
{
  location &= 0x7;            // we only have 8 locations 0-7

    sendCommand(0x40 | (location << 3));

  for (int i=0; i<8; i++)
  {
    sendData(charmap[i]);      // call the virtual write method
  }
}
*/
--- End code ---

OLedI2C.h

--- Code: ---// 1602-OLED-Arduino-Library/OLedI2C.h

/*
OLedI2C.h
OLED 1602 Library for the I2C
OLED display from WIDE.HK
Also my first attempt at a Library
Phil Grant Sept 2013
www.gadjet.co.uk
Scrolling contributed by Nathan Chantrell http://nathan.chantrell.net/
Updated 06/11/2013 to include the cursPos data within the sendString function.
*/
#ifndef OLedI2C_h
#define OLedI2C_h
#include "Arduino.h"
#include "Wire.h" // NEED FIX
//#include <i2c_t3.h> //Enhanced I2C library for Teensy 3.0/3.1/LC devices

#include "Print.h"


class OLedI2C : public Print {
public:
OLedI2C();
~OLedI2C();
// void init(); // OLD
            void init(uint8_t OLED_Address);
void sendCommand(unsigned char command);
void sendString(const char *String, uint8_t col, uint8_t row);
void sendFloat(float digit, uint8_t dec, uint8_t nad, uint8_t col, uint8_t row);
void sendData(unsigned char data);
void clearLcd();
            void clear();
            void home();
            void noDisplay();
            void display();
            void noCursor();
            void cursor();
            void noBlink();
            void blink();
void cursPos(uint8_t, uint8_t); // cloumn, row
            void setCursor(uint8_t, uint8_t); // *********Compatible with LiquidCrystal lib.
            void setCursor2(uint8_t, uint8_t); // 03-23-2015 / cloumn, row / setCursor
void scrollString(char* message, byte row, unsigned int time); //written by Nathan Chantrell http://nathan.chantrell.net/
void lcdOff();
void lcdOn();
            void setDoubleH(uint8_t); // 09-19-2015 / Double Height Display MODE 0~4
void setContrast(uint8_t contrast); // contrast should be the hex value between 0x00 and 0xFF
            void createChar(uint8_t, uint8_t[]); // NEW 03-23-2015 / Allows us to fill the first 8 CGRAM locations with custom characters

            // Compatible = ARDUINO= 0.23 = 1.6.5 ================
            #if (ARDUINO <  100)
            virtual void write(uint8_t);
            #else
            virtual size_t write(uint8_t);
            #endif // my code ==========================
};
#endif
--- End code ---

keywords.txt

--- Code: ---#######################################
# Syntax Coloring Map For OLedI2C
#######################################

#######################################
# Datatypes (KEYWORD1)
#######################################

OLedI2C KEYWORD1

#######################################
# Methods and Functions (KEYWORD2)
#######################################

init KEYWORD2
sendCommand KEYWORD2
sendData KEYWORD2
sendString KEYWORD2
sendFloat KEYWORD2
clearLcd KEYWORD2
clear KEYWORD2
home KEYWORD2
noDisplay KEYWORD2
display KEYWORD2
noCursor KEYWORD2
cursor KEYWORD2
noBlink KEYWORD2
blink KEYWORD2
cursPos KEYWORD2
setCursor KEYWORD2
createChar KEYWORD2
scrollString KEYWORD2
lcdOn KEYWORD2
lcdOff KEYWORD2
setContrast KEYWORD2
setDoubleH KEYWORD2

#######################################
# Constants (LITERAL1)
#######################################
--- End code ---

Another example

--- Code: ---/*
  Example sketch to display Strings and float values on the OLED
  1602 display  from Wide.HK. This uses a Lbrary that I've
  put together containing some basic functions.
  The I2C Address is set to 0x3C in OLedI2C.cpp
  Phil Grant 2013 www.gadjet.co.uk  07/11/13
*/

#include "Wire.h"
#include "OLedI2C.h"
OLedI2C LCD;
#define I2C_ADDR 0x3c  // Define I2C Address, 0x3c or 0x3d

float digit; //Variable to hold sample temperature value

void setup()
{
  Wire.begin();
  LCD.init(I2C_ADDR); // initialize the lcd with I2C Address
  digit = 21.6; //This would normally be the float value returned from a temp sensor or other sensor
}
void loop()
{
  LCD.sendString("Temp", 0, 0); //Now includes the cursor position data (col, row)
  LCD.sendFloat(digit, 5, 2, 7, 0); //Send the float value to the display starting
  //at col 7 row 1 with 5 digits and 2 decimal places
  while (1);
}
--- End code ---


Also the I2C address 0x3c may need to be edit for the screen you use.
Just run this and open the serial monitor it should show you the correct address.
 i2c_scanner

--- Code: ---// i2c_scanner
 //
 // This program (or code that looks like it)
 // can be found in many places.
 // For example on the Arduino.cc forum.
 // The original author is not know.
 //
 // This sketch tests the standard 7-bit addresses
 // from 0 to 127. Devices with higher bit address
 // might not be seen properly.
 //
 // Adapted to be as simple as possible by Arduino.cc user Krodal
 //
 // June 2012
 // Using Arduino 1.0.1
 //
#include <Wire.h>
void setup()
 {
   Wire.begin();
 
  Serial.begin(9600);
   Serial.println("\nI2C Scanner");
 }
void loop()
 {
   byte error, address;
   int nDevices;
 
  Serial.println("Scanning...");
 
  nDevices = 0;
   for(address = 0; address <= 127; address++ )
  {
     // The i2c_scanner uses the return value of
     // the Write.endTransmisstion to see if
     // a device did acknowledge to the address.
     Wire.beginTransmission(address);
     error = Wire.endTransmission();
 
    if (error == 0)
     {
       Serial.print("I2C device found at address 0x");
       if (address<16)
        Serial.print("0");
       Serial.print(address,HEX);
       Serial.println(" !");
 
      nDevices++;
     }
     else if (error==4)
    {
       Serial.print("Unknow error at address 0x");
       if (address<16)
        Serial.print("0");
       Serial.println(address,HEX);
     }   
   }
   if (nDevices == 0)
     Serial.println("No I2C devices found\n");
   else
     Serial.println("done\n");
 
  delay(8000);           // wait 8 seconds for next scan
 }


--- End code ---

mprowe:
Oh, I'm really sorry Chris,

But it is still no-go for me! I've pasted the first few "red" lines below. Is there a more effective way to give you the compilation log?
The message in the Arduino IDE output window is "Error compiling for board Arduino/Genuino Uno"  - This is where I started?


--- Code: ---Linking everything together...
"/home/mprowe/.arduino15/packages/arduino/tools/avr-gcc/4.9.2-atmel3.5.4-arduino2/bin/avr-gcc"  [... truncated ...]
/tmp/ccnQrlgR.ltrans0.ltrans.o: In function `__static_initialization_and_destruction_0':
/home/mprowe/Arduino/nhd-i2c/oled-example/oled-example.ino:11: undefined reference to `OLedI2C::OLedI2C()'
/tmp/ccnQrlgR.ltrans0.ltrans.o: In function `setup':
--- End code ---

Regards, Martin

Chris O.:
Sorry for the late reply but it does appear you have the library not installed correctly.


--- Quote ---Is there a more effective way to give you the compilation log?
--- End quote ---
You can enabled this; Show verbose output during Compilation and Upload enabled in File > Preferences.

The undefined reference to OLedI2C::OLedI2C() seems to be showing up because the example is trying to look for OLedI2C in nhd-i2c folder.
This is the last four lines of my successful compilation:

--- Code: ---Using library Wire at version 1.0 in folder: C:\Documents and Settings\USER NAME HERE\Desktop\arduino-1.8.1\hardware\arduino\avr\libraries\Wire
Using library OLedI2C in folder: C:\Documents and Settings\USER NAME HERE\Desktop\arduino-1.8.1\libraries\OLedI2C (legacy)
Sketch uses 3640 bytes (11%) of program storage space. Maximum is 32256 bytes.
Global variables use 294 bytes (14%) of dynamic memory, leaving 1754 bytes for local variables. Maximum is 2048 bytes.
--- End code ---

Test code used:

--- Code: ---// library by Phil Grant 2013 www.gadjet.co.uk
// OLedI2C library http://gadjetsblog.blogspot.com/2013/09/oled-1602-display-and-library-for.html

// I2C Wire Library Newhaven Display NHD-0420CW OLED TEST

// Wire Library, This library allows you to communicate with I2C / TWI devices
// Board           I2C / TWI pins
// Uno, Ethernet   A4 (SDA), A5 (SCL)
// Mega2560        20 (SDA), 21 (SCL)
// Leonardo         2 (SDA),  3 (SCL)
// Due             20 (SDA), 21 (SCL), SDA1, SCL1
//Teensy 3.0/3.1   18 (SDA), 19 (SCL),Back Side 30 (SDA1), 29 (SCL1)

#include <Wire.h>

#define I2C_ADDR 0x3c  // Define I2C Address, 0x3c or 0x3d
#include <OLedI2C.h>
OLedI2C LCD;

// custom font arrays
byte newChar1[8] = {
  B11011,
  B11111,
  B11111,
  B11111,
  B11111,
  B11111,
  B11111,
  B10101
};

byte newChar2[8] = {
  B10000,
  B01000,
  B00101,
  B00100,
  B00100,
  B00101,
  B01000,
  B10000
};

byte newChar3[8] = {
  B10001,
  B01010,
  B01110,
  B00100,
  B00100,
  B01110,
  B01010,
  B10001
};

byte newChar4[8] = {
  B11111,
  B11111,
  B11111,
  B00100,
  B00100,
  B11111,
  B11111,
  B11111
};

byte newChar5[8] = { // 5TH custom font
  B10101,
  B10000,
  B10110,
  B00001,
  B00000,
  B10001,
  B01010,
  B00000
};

void setup() {
  Wire.begin(); // Start Wire Library
  LCD.init(I2C_ADDR); // initialize the lcd with I2C Address
  //delay(1000);
  // Store custom font data in 420CW Oled
  LCD.createChar(0, newChar1);
  LCD.createChar(1, newChar2);
  LCD.createChar(2, newChar3);
  LCD.createChar(3, newChar4);
  LCD.createChar(4, newChar5);
  LCD.createChar(5, newChar5);
  LCD.createChar(6, newChar5);
  LCD.createChar(7, newChar5);


  LCD.sendString("SETUP ()", 0, 0);    //("String", col, row)
  delay(1000);
}

void loop() {
  //////////// set Contrast test 1 ////////////////
  LCD.sendString("set Contrast test DW", 0, 0);    //("String", col, row)
  for (int Contrast = 255; Contrast > 0; Contrast = Contrast-- / 2 ) {
    LCD.setContrast(Contrast); // Set Contrast (Minimum allowed 0) 0~255
    LCD.setCursor(9, 1); //(col,row)
    LCD.print(Contrast);
    LCD.print("    "); //clear
    delay(300); //delay not necessary as its sending a lot of Commands wich has delay inside the lib.

  }
  delay(2000); // 2sec. delay

  LCD.clearLcd();
  LCD.sendString("set Contrast test UP", 0, 0);    //("String", col, row)
  for (int Contrast = 0; Contrast < 510; Contrast = Contrast++ * 2 ) {
    LCD.setContrast(Contrast); // Set Contrast (Minimum allowed 0) 0~255
    LCD.cursPos(9, 1); //(col,row)
    LCD.print(Contrast);
    LCD.print("    "); //clear
    delay(300); //delay not necessary as its sending a lot of Commands wich has delay inside the lib.
  }
  delay(2000); // 2sec. delay
  LCD.clearLcd();

  // Double Height(4-line) Test
  LCD.sendString("Double Height(4x20)", 0, 0);
  LCD.sendString("Test", 8, 1);
  delay(2000); // 2sec. delay
  LCD.setDoubleH(1);
  LCD.sendString("MODE 1", 0, 2);
  delay(1000); // 1sec. delay
  LCD.setDoubleH(2);
  LCD.sendString("MODE 2", 0, 2);
  delay(1000); // 1sec. delay
  LCD.setDoubleH(3);
  LCD.sendString("MODE 3", 0, 1);
  delay(1000); // 1sec. delay
  LCD.sendString("      ", 0, 1); // clear MODE 3 from Oled

  LCD.setDoubleH(4);
  LCD.sendString("MODE 4", 0, 2);
  delay(1000); // 1sec. delay
  LCD.setDoubleH(0); //back to 4x20
  LCD.sendString("MODE 0 (4-line)", 0, 2);
  delay(3000); // 3sec. delay
  LCD.clearLcd();

  //////////// Print custom font Using Wire.h Library test 2 ////////////////
  LCD.setDoubleH(3); // MODE 1
  LCD.sendString("Print custom font / Wire Library", 0, 0);    //("String", col, row)
  LCD.sendString("custom font -->", 0, 3);
  delay(3000); // 1sec. delay
  LCD.setDoubleH(0);
  delay(1000); // 1sec. delay
  LCD.cursPos(16, 3); //(col,row) / set up position
  // Test  / Print custom font 5 using Wire.h Library
  Wire.beginTransmission(I2C_ADDR); // start condition + Define I2C Address where the US2066 is, and set  R/W# bit to logic “0” write mode.
  // Print custom font
  Wire.write(B01000000); // control byte or the data byte, Co and D/C# bits following by six “0”’s.
  //Wire.write(B00000011); //DEC 3 // print custom font 4  [8bit (hi bit 0000/low bit 0011
  Wire.write(4); //DEC 4 / 5th custom font (Zero based array indexing.....)
  Wire.endTransmission(); // stop condition / 7) The write mode will be finished when a stop condition is applied.
  delay(3000); // 3sec. delay
  LCD.clearLcd();
  delay(1000); //1sec. delay

  //////////// Print 2 custom font Using LCD.sendData test 3 ////////////////
  LCD.sendString(" Print two custom   fonts / LCD.sendData", 0, 0);    //("String", col, row)
  LCD.cursPos(2, 2); //(col,row)
  LCD.print("---> ");
  delay(1000); // 1sec. delay
  LCD.sendData(0); //Print custom font 1 (Zero based array indexing.....)
  LCD.print(" <---> ");
  delay(1000); // 1sec. delay
  LCD.sendData(char(1)); //Print custom font 2
  delay(3000); // 3sec. delay
  LCD.clearLcd();
  delay(1000);

  //LCD.scrollString("test", 2, 100);

  //////////// command test ////////////////
  /*
    sendCommand(0x2A);//function set (extended command set)
    sendCommand(0x71); //function selection A
    sendData(0x00);    //disable internal VDD regulator (2.8V I/O). data(0x5C) = enable regulator (5V I/O)
    sendCommand(0x28); //function set (fundamental sendCommand set)
    sendCommand(0x08); //display off, cursor off, blink off
    sendCommand(0x2A); //function set (extended command set)
    sendCommand(0x79); //OLED command set enabled
    sendCommand(0xD5); //set display clock divide ratio/oscillator frequency
    sendCommand(0x70); //set display clock divide ratio/oscillator frequency
    sendCommand(0x78); //OLED command set disabled
    sendCommand(0x09); //extended function set (4-lines) / last bit=1 : 3-line or 4-line display mode
    sendCommand(0x06); //COM SEG direction
    sendCommand(0x72); //function selection B
    sendData(B00000000);   //ROM CGRAM selection
    sendCommand(0x2A); //function set (extended command set)
    sendCommand(0x79); //OLED command set enabled
    sendCommand(0xDA); //set SEG pins hardware configuration
    sendCommand(0x10); //set SEG pins hardware configuration
    sendCommand(0xDC); //function selection C
    sendCommand(0x00); //function selection C
    sendCommand(0x81); //set contrast control
    sendCommand(0x7F); //set contrast control
    sendCommand(0xD9); //set phase length
    sendCommand(0xF1); //set phase length
    sendCommand(0xDB); //set VCOMH deselect level
    sendCommand(0x40); //set VCOMH deselect level
    sendCommand(0x78); //OLED command set disabled
    sendCommand(0x28); //function set (fundamental command set)
    sendCommand(0x01); //clear display
    sendCommand(0x80); //set DDRAM address to 0x00
    sendCommand(0x0C); //display ON

    delay(150);
    sendCommand(0x0C);  // **** Turn on Display
    delay(150);*/
}
--- End code ---

mprowe:
Hi Chris,

Thank you very much for staying with me on this. It is greatly appreciated.  Looking at the "Library in the wrong location" first.
While yes, it could be, but this is the results of this line of inquiry here.

1. I have three library locations (don't know why?), they are:
   a) /home/mprowe/Arduino/libraries/
   b) /home/mprowe/.arduino15/packages/arduino/hardware/avr/1.6.18/libraries/
   c) /opt/arduino-1.8.0/libraries/

2. For testing purposes only, I have put your library in all three locations - with a customized library.properties file.

3. The log output (below) shows that it has found all three  & is using the copy at (2.b) see lines 86 to 89. This is alongside the wire library.


--- Code: ---74 Linking everything together...
75 "/home/mprowe/.arduino15/packages/arduino/tools/avr-gcc/4.9.2-atmel3.5.4-arduino2/bin/avr-gcc" [.... truncated by me]
76 /tmp/ccVbwl16.ltrans0.ltrans.o: In function `__static_initialization_and_destruction_0':
77 /home/mprowe/Arduino/nhd-i2c/oled-example/oled-example.ino:16: undefined reference to `OLedI2C::OLedI2C()'
78 /tmp/ccVbwl16.ltrans0.ltrans.o: In function `setup':
79 /home/mprowe/Arduino/nhd-i2c/oled-example/oled-example.ino:24: undefined reference to `OLedI2C::init(unsigned char)'
80 /tmp/ccVbwl16.ltrans0.ltrans.o: In function `loop':
81 /home/mprowe/Arduino/nhd-i2c/oled-example/oled-example.ino:29: undefined reference to `OLedI2C::sendString(char const*, unsigned char, unsigned char)'
82 /home/mprowe/Arduino/nhd-i2c/oled-example/oled-example.ino:30: undefined reference to `OLedI2C::sendFloat(float, unsigned char, unsigned char, unsigned char, unsigned char)'
83 /tmp/ccVbwl16.ltrans0.ltrans.o: In function `_GLOBAL__sub_D_LCD':
84 /home/mprowe/Arduino/nhd-i2c/oled-example/oled-example.ino:16: undefined reference to `OLedI2C::~OLedI2C()'
85 collect2: error: ld returned 1 exit status
86 Multiple libraries were found for "OLedI2C.h"
87  Used: /home/mprowe/.arduino15/packages/arduino/hardware/avr/1.6.18/libraries/OLedI2C
88  Not used: /home/mprowe/Arduino/libraries/OLedI2C.home
89  Not used: /opt/arduino-1.8.0/libraries/OLedI2C.opt
90 Using library Wire    at version 1.0 in folder: /home/mprowe/.arduino15/packages/arduino/hardware/avr/1.6.18/libraries/Wire
91 Using library OLedI2C at version 1.0 in folder: /home/mprowe/.arduino15/packages/arduino/hardware/avr/1.6.18/libraries/OLedI2C
92 exit status 1
93 Error compiling for board Arduino/Genuino Uno.

--- End code ---

4. Compiling with only one copy of the OLedI2C in each location. First run with OLedI2C in 2.a), second run with OLedI2C in 2.b) and finaly with OLedI2C in location 2.c) still results in a compilation error?

5. I have placed a full copy of the compilation log ftp://mpr75@talktalk.net@www.mpr75.talktalk.net/oled-example.log. This is what I meant in the last over, about sharing the full log file. In many forums you can upload and link these files but I can not find any way to do the same on this site? If you can find the time to have a look at the whole whole log file in the hope that any other clues should "jump out"?

Best regards, Martin

mprowe:
Hi Chris,

Short note to bring you up to date with my latest testing.

I have installed the Windows Aurduino IDE (1.8.3) https://www.arduino.cc/download_handler.php?f=/arduino-1.8.3-windows.exe in an attempt to replicate your success. Unfortunately, your example will still will not compile using the OLedI2C library. The error log is almost exactly the same as I get on my Linux machine.

Secondly, to try and avoid any OS dependency’s,  I have done the same using the official web based workbench, Arduino Create. Yet again, no compilation success!! I have posted the verbose error log here http://www.mpr75.talktalk.net/. At my (low-level) of understanding all three logs seem similar. To me, it is suggesting a path-resolution problem in OLedI2C.ccp or its dependencies?

I am guessing that your Windows machine has had a personal environment variable setup that is allowing you to compile?

Regards, Martin

Navigation

[0] Message Index

[*] Previous page

Go to full version