HCuOLED library for SSD1307 & SH1106 based OLED displays

Useful guides, libraries, and example sketches to support our Arduino based products.
Post Reply
admin
Site Admin
Posts: 866
Joined: Sun Aug 05, 2012 4:02 pm

HCuOLED library for SSD1307 & SH1106 based OLED displays

Post by admin » Fri Apr 17, 2015 2:13 pm

Image



PLEASE NOTE: This library has now been replaced by the HCDisplay library and will no longer be supported. For new projects please use the HCDisplay library instead which can be found at this forum thread:

viewtopic.php?f=58&t=2827



Image

This Arduino library will allow you to display various text, graphics and and bitmaps on SSD1307 and SH1106 based uOLED displays. The library has been written specifically for our own uOLED displays including the following:

Hobby Components 0.96" uOLED displays (HCMODU0050 & HCMODU0052)
Hobby Components 1.3" uOLED displays (HCMODU0058 & HCMODU0059)
WeMos D1 mini OLED shield (HCWEMO0007)
Hobby Components 0.9" 128x32 uOLED displays (HCMODU0118 & HCMODU0119)

The library makes use of the Arduino's SPI interface (V0.2 now additionally support displays in I2C mode) to drive the displays in their default SPI configuration. However, the library is capable of driving multiple displays with a mix of previously mentioned controller types all from one Arduino. Each additional display will only require 3 additional digital pins.

You will need to download (please log in to download the library) and unzip this library to the Arduino development environments library area.

On Windows:
My Documents\Arduino\libraries\

On Mac:
Documents/Arduino/libraries/
or similarly for Linux.



Using the library

To use the library just include the HCuOLED.h header file and the standard SPI.h header file and then create an instance of the library for each display. E.g:

For SPI mode:

Code: Select all

#include <HCuOLED.h>
#include <SPI.h>
HCuOLED HCuOLED(DisplayType, CS, DC, RST);
Where:

DisplayType is the driver version of the display. Valid values are
SSD1306
SH1106
CS is the digital pin number used for the modules chip select pin (CS)
DC is the pin number used for the modules Data/Command pin (DC)
RST is the pin number used for the modules reset pin (RST)


For I2C mode:

Code: Select all

#include <HCuOLED.h>
#include <Wire.h>
HCuOLED HCuOLED(DisplayType, I2C_ADD, RST);

Where:

DisplayType is the driver version of the display. Valid values are
SSD1306
SH1106
WEMOS_D1_MINI_OLED
SSD1306_128_32
I2C_ADD is the I2C address of the display. This is normally either 0x3C or 0x3D.
RST is the pin number used for the modules reset pin (RST). This is an optional parameter and may be omitted if your display has internal reset circuitry (e.g. WeMos OLED).


The display buffer:
Because it is not possible to read the status of the screens display, the library will create a display buffer in RAM. Most of the functions outlined below will not write directly to the display but instead write to the display buffer. Nothing will be displayed on the module until the refresh function is executed which will write the entire contents of the displaybuffer to the display.

Note when using the library with multiple displays:
Due to tight RAM constraints of most Arduinos it is not possible to store a separate display buffer for each display. Therefore only one display buffer is created and is shared by each display. Therefore, when writing to a different display you will need to first clear the display buffer with the ClearBuffer() command to avoid display information from the previous screen being copied to the new screen.



The following functions are available with this library:

Code: Select all

HCuOLED.Reset();
Resets the display and configures it to a default state.

Code: Select all

HCuOLED.Init();
Initialises the display and configures it to a default state.

Note: This function is called by the above Reset() function. It has been added(V0.6) to allow multiple displays to be initialised when reset via the same digital pin. This function is not required when driving a single display or when multiple displays are reset using separate digital pins.

Code: Select all

HCuOLED.Refresh();
Writes the contents of the display buffer to the display.

Code: Select all

HCuOLED.ClearBuffer();
Clears the contents of the display buffer.

Code: Select all

HCuOLED.Flip_H();
Flips the display about its horizontal axis.

Code: Select all

HCuOLED.Flip_V();
Flips the display about its vertical axis.

Code: Select all

HCuOLED.Brightness(byte Level);
Sets the brightness of the display where:
Level is the brightness level of the display. Valid values for Level are
1 = Lowest brightness
255 = Highest brightness

Code: Select all

HCuOLED.Bitmap(Cols, ByteRows, BitmapData[]);
Copies a 1 dimensional array (of type const byte) containing bitmap information to the display buffer with the top left hand corner of the bitmap starting at the Cursor() coordinates where:

Cols is the X axis dimension of the bitmap in pixels.
ByteRows is the Y axis dimension of the bitmap in 8 pixel chunks.
BitmapData[] is a 1 dimensional array of type const byte containing the bitmap data. Each byte of the array represents on 8 pixel column of the bitmap.

Code: Select all

HCuOLED.Cursor(byte X, byte Y);
Sets the current cursor location used for positioning text and bitmaps in the screen where:
X is the X axis location where the bitmap or text will start from. Valid values are between 0 and 127
Y is the Y axis location where the bitmap or text will start from. Valid values are between 0 and 63

Code: Select all

HCuOLED.SetFont(Font);
Sets the font to by the Print() function. Where:
Font is the required font. Valid options are:
Terminal_8pt (a small fixed width 8x8 font)
MedProp_11pt (a medium proportional 2 row font)
LCDLarge_24pt (a large LCD style 4 row font)
sharpsharp_5pt (A tiny 5pt proportional font thanks to forum user ChrisSharp for creating this)
sharpsharp_6pt (A tiny 6pt proportional font thanks to forum user ChrisSharp for creating this)

Code: Select all

HCuOLED.Plot(X, Y);
Changes the pixel at a specified coordinate where:
X is the X axis of the pixel. Valid values are between 0 and 127
Y is the Y axis of the pixel. Valid values are between 0 and 63

Code: Select all

HCuOLED.Line(X1, Y1, X2, Y2);
Draws a single pixel width line where:
X1 is the start X axis coordinate of the line. Valid values are between 0 and 127
Y1 is the start Y axis coordinate of the line. Valid values are between 0 and 63
X2 is the end X axis coordinate of the line. Valid values are between 0 and 127
Y3 is the end Y axis coordinate of the line. Valid values are between 0 and 63

Code: Select all

HCuOLED.Rect(X1, Y1, X2, Y2, FillMode);
Draws a rectangle where:
X1 is the X axis coordinate for the first corner. Valid values are between 0 and 127
Y1 is the Y axis coordinate for the first corner. Valid values are between 0 and 63
X2 is the X axis coordinate for the opposite corner. Valid values are between 0 and 127
Y2 is the Y axis coordinate for the opposite corner. Valid values are between 0 and 63
FillMode specifies if the rectangle should be filled or not. Valid values are:
OUTLINE (draws a single pixel wide outlined rectangle)
SOLID (draws a filled rectangle)

Code: Select all

HCuOLED.Erase(X1, Y1, X2, Y2);
Erases rectangular area of the screen where:
X1 is the X axis coordinate for the first corner. Valid values are between 0 and 127
Y1 is the Y axis coordinate for the first corner. Valid values are between 0 and 63
X2 is the X axis coordinate for the opposite corner. Valid values are between 0 and 127
Y2 is the Y axis coordinate for the opposite corner. Valid values are between 0 and 63

Code: Select all

HCuOLED.DrawMode(DrawMode);
Sets the drawing mode for the Print(), Line(), Rect(), Bitmap() functions where:
DrawMode sets the drawing mode. Valid values are:
NORMAL (pixels are set to the foreground colour)
CLEAR (Pixels are set to the background colour)
INVERT (pixels are set to the opposite of their current state)

Code: Select all

HCuOLED.Print(TextString[])
Prints an alphanumeric string of text to the output buffer using the current font at the location set by Cursor() where:
TextString[] is a string of text.

Code: Select all

HCuOLED.Print(Value)
Prints a signed integer number to the output buffer using the current font at the location set by Cursor() where:
Value is a signed integer number of type long.

Code: Select all

HCuOLED.Print(Value, DecimalPlaces)
Prints a signed integer number with decimal place to the display buffer using the current font at the location set by Cursor() where:
Value is a signed integer number of type long.
DecimalPlaces is position of the decimal point starting from the right hand side

Code: Select all

HCuOLED.Print(value, digits, DecimalPlaces);
Prints a signed floating point number to the display buffer using the current font at the location set by Cursor() where:
value is a signed floating point number of type float
digits is the number of digits (including decimal places) to crop the number to. Maximum is 10 digits
DecimalPlaces is the number of decimal places to crop the number to.

Code: Select all

HCuOLED.GetPixel(X, Y);
Get the current state of a pixel where:
X is the x axis coordinate of the pixel
Y is the Y axis coordinate of the pixel

Returns: A boolean value representing the state of the pixel at coordinate X,Y




Image
  1. /* FILE:    HCuOLED_Things_Example
  2.    DATE:    16/04/15
  3.    VERSION: 0.1
  4.    AUTHOR: Andrew Davies
  5.    
  6. REVISIONS:
  7.  
  8. 12/03/15 Created version 0.1
  9.  
  10.  
  11. This example uses the line, rectangle and bitmap graphic functions together with
  12. the INVERT DrawMode to create a simple animation.
  13.  
  14. To use this example connect your uOLED display to the following pins of your
  15. Arduino:
  16.  
  17.  
  18. MODULE..........ARDUINO
  19. GND.............GND
  20. VCC.............3.3V
  21. D0 (CLK)........D13
  22. D1 (DATA).......D11
  23. RST (RESET).....D8
  24. DC..............D9
  25. CS (SS).........D10
  26.  
  27.  
  28. You may copy, alter and reuse this code in any way you like, but please leave
  29. reference to HobbyComponents.com in your comments if you redistribute this code.
  30. This software may not be used directly for the purpose of promoting products that
  31. directly compete with Hobby Components Ltd's own range of products.
  32.  
  33. THIS SOFTWARE IS PROVIDED "AS IS". HOBBY COMPONENTS MAKES NO WARRANTIES,
  34. WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED
  35. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ACCURACY OR
  36. LACK OF NEGLIGENCE. HOBBY COMPONENTS SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE
  37. FOR ANY DAMAGES INCLUDING, BUT NOT LIMITED TO, SPECIAL, INCIDENTAL OR
  38. CONSEQUENTIAL DAMAGES FOR ANY REASON WHATSOEVER. */
  39.  
  40. #include "HCuOLED.h"
  41. #include "SPI.h"
  42.  
  43. /* Example bitmap */
  44. const PROGMEM byte Tiny_Logo_Resistor[] =
  45. {
  46.   0xC0, 0xE0, 0x30, 0x30, 0xF0, 0xE0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x80, 0xE0, 0x38, 0x0E, 0x07, 0x1E, 0x78, 0xE0, 0x80, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x70, 0x1C, 0x07, 0x0F, 0x3C, 0xF0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x80, 0xF0, 0x3C, 0x0F, 0x07, 0x1C, 0x70, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x80, 0xE0, 0x78, 0x1E, 0x07, 0x0E, 0x38, 0xE0, 0x80, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xE0, 0xF0, 0x30, 0x30, 0xE0, 0xC0,
  47.   0x00, 0x01, 0x03, 0x03, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x0F, 0x3C, 0x38, 0x0E, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x07, 0x1E, 0x38, 0x1C, 0x07, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x0E, 0x38, 0x38, 0x0E, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x07, 0x1C, 0x38, 0x1E, 0x07, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x0E, 0x38, 0x3C, 0x0F, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x03, 0x01, 0x00,
  48. };
  49.  
  50.  
  51. /* Digital pin number for the displays chip select pin */
  52. #define CS_DI 10
  53. /* Digital pin number for the displays data/command pin */
  54. #define DC_DI 9
  55. /* Digital pin number for the displays reset pin */
  56. #define RST_DI 8
  57.  
  58. /* Array indexes for the X and Y coordinates */
  59. #define X1 0
  60. #define Y1 1
  61. #define X2 2
  62. #define Y2 3
  63.  
  64. /* Arrays to store coordinates and direction for the line, rectangle and bitmap */
  65. byte Box[4] = {1,1,20,20};
  66. byte BoxDir[4] = {1,1,1,1};
  67. byte Line[4] = {100,25,120,55};
  68. byte LineDir[4] = {-1,-1,-1,-1};
  69. byte Bitmap[2] = {40,40};
  70. byte BitmapDir[2] = {-1,-1};
  71.  
  72.  
  73.  
  74. /* Create an instance of the library (uncomment one of the lines below) */
  75. //HCuOLED HCuOLED(SSD1307, SS_DI, DC_DI, RST_DI); // For SSD1307 displays (HCMODU0050 & HCMODU0052)
  76. HCuOLED HCuOLED(SH1106, CS_DI, DC_DI, RST_DI); // For SH1106 displays (HCMODU0058 & HCMODU0059)
  77.  
  78.  
  79. void setup()
  80. {
  81.  
  82.   /* Reset the display */
  83.   HCuOLED.Reset();
  84. }
  85.  
  86. void loop()
  87. {
  88.   /* Display some text using a small 8x8 fixed width font */
  89.   HCuOLED.SetFont(Terminal_8pt);
  90.   HCuOLED.Cursor(44,0);
  91.   HCuOLED.Print("HOBBY");
  92.   HCuOLED.Cursor(20,10);
  93.   HCuOLED.Print("COMPONENTS");
  94.  
  95.   /* Display a number using a large 4 line LCD style font */
  96.   HCuOLED.Cursor(20,24);
  97.   HCuOLED.SetFont(LCDLarge_24pt);
  98.   HCuOLED.Print("HCuOLED");
  99.  
  100.   /* Change the draw mode from NORMAL to INVERT */
  101.   HCuOLED.DrawMode(INVERT);
  102.   while(1)
  103.   {
  104.     /* Move the positions of the 3 objects */
  105.     MoveRect();
  106.     MoveLine();
  107.     MoveBitmap();
  108.    
  109.     /* Draw the objects to the display buffer */
  110.     HCuOLED.Rect(Box[X1],Box[Y1],Box[X2],Box[Y2], SOLID);
  111.     HCuOLED.Line(Line[X1],Line[Y1],Line[X2],Line[Y2]);
  112.    
  113.     HCuOLED.Cursor(Bitmap[X1],Bitmap[Y1]);
  114.     HCuOLED.Bitmap(84, 2, Tiny_Logo_Resistor);
  115.    
  116.     /* Write the display buffer to the screen */
  117.     HCuOLED.Refresh();
  118.    
  119.     /* Draw the objects again. As we are in INVERT mode this will remove them */
  120.     HCuOLED.Rect(Box[X1],Box[Y1],Box[X2],Box[Y2], SOLID);
  121.     HCuOLED.Line(Line[X1],Line[Y1],Line[X2],Line[Y2]);
  122.    
  123.     HCuOLED.Cursor(Bitmap[X1],Bitmap[Y1]);
  124.     HCuOLED.Bitmap(84, 2, Tiny_Logo_Resistor);
  125.   }
  126. }
  127.  
  128.  
  129. /* Update the X and Y coordinates for the box */
  130. void MoveRect(void)
  131. {
  132.   if(Box[X1] == 0 || Box[X1] == 127)
  133.     BoxDir[X1] *= -1;
  134.   Box[X1] += BoxDir[X1];
  135.  
  136.   if(Box[Y1] == 0 || Box[Y1] == 63)
  137.     BoxDir[Y1] *= -1;
  138.   Box[Y1] += BoxDir[Y1];
  139.  
  140.   if(Box[X2] == 0 || Box[X2] == 127)
  141.     BoxDir[X2] *= -1;
  142.   Box[X2] += BoxDir[X2];
  143.  
  144.   if(Box[Y2] == 0 || Box[Y2] == 63)
  145.     BoxDir[Y2] *= -1;
  146.   Box[Y2] += BoxDir[Y2];  
  147. }
  148.  
  149. /* Update the X and Y coordinates for the Line */
  150. void MoveLine(void)
  151. {
  152.   if(Line[X1] == 0 || Line[X1] == 127)
  153.     LineDir[X1] *= -1;
  154.   Line[X1] += LineDir[X1];
  155.  
  156.   if(Line[Y1] == 0 || Line[Y1] == 63)
  157.     LineDir[Y1] *= -1;
  158.   Line[Y1] += LineDir[Y1];
  159.  
  160.   if(Line[X2] == 0 || Line[X2] == 127)
  161.     LineDir[X2] *= -1;
  162.   Line[X2] += LineDir[X2];
  163.  
  164.   if(Line[Y2] == 0 || Line[Y2] == 63)
  165.     LineDir[Y2] *= -1;
  166.   Line[Y2] += LineDir[Y2];  
  167. }
  168.  
  169. /* Update the X and Y coordinates for the bitmap */
  170. void MoveBitmap(void)
  171. {
  172.   if(Bitmap[X1] == 0 || Bitmap[X1] == 43)
  173.     BitmapDir[X1] *= -1;
  174.   Bitmap[X1] += BitmapDir[X1];
  175.  
  176.   if(Bitmap[Y1] == 0 || Bitmap[Y1] == 47)
  177.     BitmapDir[Y1] *= -1;
  178.   Bitmap[Y1] += BitmapDir[Y1];
  179. }


Image


The latest version (V1.0) of the library can be downloaded here:
HCuOLED.zip



Older versions

V0.9:
HCuOLED.zip
V0.8:
HCuOLED.zip
V0.7:
HCuOLED.zip
V0.6:
HCuOLED.zip
V0.5:
HCuOLED.zip
V0.4:
HCuOLED.zip
V0.3:
HCuOLED.zip
V0.2:
HCuOLED.zip
V0.1:
HCuOLED.zip


Change Log:

16/04/15 version 0.1: Original version
06/12/16 version 0.2: Added compatibility with ESP8266
Added support for uOLED displays in I2C mode
Added support for WeMos D1 mini OLED shield (see item HCWEMO0007)
Made speed improvement to erase function (thanks to vladyslav-savchenko)
22/05/17 version 0.3: Added support for 128x32 OLED display (see items HCMODU0118 & HCMODU0119)
02/11/18 version 0.4: Fixed issue which cause the integer value of 0 not to be printed.
06/01/19 version 0.5: Change unsigned int to uint16_t in font.h file to fix error when compiling for Wemos boards
18/05/19 version 0.6: Added Brightness() function to allow adjustment of displays brightness level
Removed initialisation code from Reset() and added a new Init() function to allow multiple displays to be reset from the same pin
Added command to pull CS pin high in the Init() function.
24/02/21 version 0.7: Add 2 additonal tiny fonts: sharpsharp_5pt & sharpsharp_6pt thanks to Chris Sharp for creating the fonts.
Also added different font spacing for each font.

22/03/21 version 0.8: Added GetPixel() function to get the current state of a pixel at a specified coordinate.
Updated font description in Fonts.h file from 'const unsigned int' to 'const short unsigned int' to remove compile error when compiling for WeMos D1

11/01/22 version 0.9: Updated Bitmap() and Cursor() functions to allow bitmaps and text to be printed partially off screen

14/01/22 version 1.0: Fixed bug that caused the Flip_H() & Flip_V() functions to not work.


Libraries, example code, and diagrams are provided as an additional free service by Hobby Components and are not sold as part of this product. We do no provide any guarantees or warranties as to their accuracy or fitness for purpose.

Descriptions and diagrams on this page are copyright Hobby Components Ltd and may not be reproduced without permission.
You do not have the required permissions to view the files attached to this post.

pkdkak01
Posts: 1
Joined: Sun Dec 25, 2016 12:17 am

Re: HCuOLED library for SSD1307 & SH1106 based OLED displays

Post by pkdkak01 » Sun Dec 25, 2016 12:25 am

hello..
this is best library for monochrome oled with higher FPS (30-40 FPS) on I2C, i have problem with Bitmap, how to convert them to byte?? :roll:

andrew
Site Admin
Posts: 1374
Joined: Sun Aug 05, 2012 4:15 pm

Re: HCuOLED library for SSD1307 & SH1106 based OLED displays

Post by andrew » Thu Dec 29, 2016 12:18 pm

There are a few pieces of software available that are designed for converting bitmaps to byte arrays specifically for use with monochrome LCDs. However you need to that will convert the pixels of the bitmap to an array in the correct order. For the HCuOLED library this needs to be a 1 dimensional array where each byte (8 bits) represents one 8 bit column of pixels. This one should be able to do it:

http://www.avrportal.com/?page=image2glcd

Make sure you save your image as a 2 colour (black and white) bitmap. Make a note of the resolution and enter it into the x & y text boxes in the program.
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.

GuitarPhil
Posts: 7
Joined: Mon Jan 19, 2015 3:47 pm

Re: HCuOLED library for SSD1307 & SH1106 based OLED displays

Post by GuitarPhil » Mon Oct 22, 2018 1:00 pm

Any ideas why I'm getting this compiler error regarding Wire.h?

Arduino: 1.6.5 (Windows 8.1), Board: "Arduino Uno"

In file included from HCuOLED_Text_Example.ino:42:0:
F:\Arduino\libraries\HCuOLED/HCuOLED.h:38:18: fatal error: Wire.h: No such file or directory
#include <Wire.h>
^
compilation terminated.
Multiple libraries were found for "SPI.h"

Used: F:\Arduino\libraries\SPI

Not used: F:\Arduino IDE 160\Arduino\hardware\arduino\avr\libraries\SPI

Error compiling.

Regards,

Phil.

andrew
Site Admin
Posts: 1374
Joined: Sun Aug 05, 2012 4:15 pm

Re: HCuOLED library for SSD1307 & SH1106 based OLED displays

Post by andrew » Mon Oct 22, 2018 2:35 pm

Do you actually have the Wire.h file on your computer? Looking at your error it looks like it should be in the following path:

F:\Arduino IDE 160\Arduino\hardware\arduino\avr\libraries\Wire\src\Wire.h


Also, unrelated to your problem I notice you seem to have an extra copy of the SPI library in your F:\Arduino\libraries\ folder. You shouldn't need this extra copy and it may cause you issues when using the SPI interface.
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.

GuitarPhil
Posts: 7
Joined: Mon Jan 19, 2015 3:47 pm

Re: HCuOLED library for SSD1307 & SH1106 based OLED displays

Post by GuitarPhil » Mon Oct 22, 2018 3:30 pm

Thanks for the rapid response Andrew.

I checked and found that my Wire library is in an older Arduino IDE installation. I'll try copying it to the Arduino IDE 160 folder but oddly, my own sketches using the Wire library all compile ok, but I'm using #include <Wire.h> within the sketch itself and I do have a copy of Wire in a libraries folder that's in the Sketch folder so maybe that's why it can find it?

Sounds like I need to clean up my libraries folders!

Regards,

Phil.

GuitarPhil
Posts: 7
Joined: Mon Jan 19, 2015 3:47 pm

Re: HCuOLED library for SSD1307 & SH1106 based OLED displays

Post by GuitarPhil » Mon Oct 22, 2018 3:49 pm

Well that didn't work :-(

Here's the verbose output after copying Wire to the Arduino IDE 160 libraries folder:


Arduino: 1.6.5 (Windows 8.1), Board: "Arduino Uno"

Using library HCuOLED in folder: F:\Arduino\libraries\HCuOLED (legacy)

Using library SPI in folder: F:\Arduino\libraries\SPI (legacy)



F:\Arduino IDE 160\Arduino\hardware\tools\avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IF:\Arduino IDE 160\Arduino\hardware\arduino\avr\cores\arduino -IF:\Arduino IDE 160\Arduino\hardware\arduino\avr\variants\standard -IF:\Arduino\libraries\HCuOLED -IF:\Arduino\libraries\SPI C:\Users\Philip\AppData\Local\Temp\build1717650456508710747.tmp\HCuOLED_Text_Example.cpp -o C:\Users\Philip\AppData\Local\Temp\build1717650456508710747.tmp\HCuOLED_Text_Example.cpp.o

In file included from HCuOLED_Text_Example.ino:42:0:
F:\Arduino\libraries\HCuOLED/HCuOLED.h:38:18: fatal error: Wire.h: No such file or directory
#include <Wire.h>
^
compilation terminated.
Multiple libraries were found for "SPI.h"

Used: F:\Arduino\libraries\SPI

Not used: F:\Arduino IDE 160\Arduino\hardware\arduino\avr\libraries\SPI

Error compiling.


And this is part of the verbose output from successfully compiling another sketch using Wire lib:

Build options changed, rebuilding all
Using library EEPROM in folder: F:\Arduino\libraries\EEPROM (legacy)
Using library Wire in folder: F:\Arduino\libraries\Wire (legacy)
Using library HTI2CLCD in folder: F:\Arduino\libraries\HTI2CLCD (legacy)
Using library LiquidTWI2 in folder: F:\Arduino\libraries\LiquidTWI2 (legacy)
Using library SoftwareSerial in folder: F:\Arduino\libraries\SoftwareSerial (legacy)
Using library Rotary in folder: F:\Arduino\libraries\Rotary (legacy)

Regards,

Phil

GuitarPhil
Posts: 7
Joined: Mon Jan 19, 2015 3:47 pm

Re: HCuOLED library for SSD1307 & SH1106 based OLED displays

Post by GuitarPhil » Mon Oct 22, 2018 7:48 pm

OK so I got it working. I had to install the latest Arduino IDE (1.8.7) over the top of the old version so now everything compiles as it should.

Thanks for you help and maybe this can also help anyone else who may have had a similar problem.

Regards,

Phil.

GuitarPhil
Posts: 7
Joined: Mon Jan 19, 2015 3:47 pm

HCuOLEd.Print() won't display zero

Post by GuitarPhil » Thu Nov 01, 2018 9:44 pm

If I try to display a variable (int or long) which has a zero value, the 0 doesn't appear on the display!

For example, adapting the HCuOLED Example code for HCuOLED_Text_Example, the display should show:

-101 A zero:0
-101 A zero:0
-123.05

but instead I get:

-11 A Zero:
-11 A zero:
-123.05

i..e no zeros between the -1 and the 1.

Only the last line displays the zero. The problem only occurs if the value is zero, zeroes in numbers like 10, 1205 etc. are OK.

Is this me or is there a problem with teh library?

Thanks,

Phil.

Code: Select all

/* FILE:    HCuOLED_Text_Example
   DATE:    16/04/15
   VERSION: 0.1

  REVISIONS:

  12/03/15 Created version 0.1


  This is an example of how to display text and numbers using the HCuOLED library
  on a SSD1307 or SH1106 based OLED display module such as:

  Hobby Components 0.96" uOLED displays (HCMODU0050 & HCMODU0052)
  Hobby Components 1.3" uOLED displays (HCMODU0058 & HCMODU0059)

  To use this example connect your uOLED display to the following pins of your
  Arduino:


  MODULE..........ARDUINO
  GND.............GND
  VCC.............3.3V
  D0 (CLK)........D13
  D1 (DATA).......D11
  RST (RESET).....D8
  DC..............D9
  CS (SS).........D10


  You may copy, alter and reuse this code in any way you like, but please leave
  reference to HobbyComponents.com in your comments if you redistribute this code.
  This software may not be used directly for the purpose of promoting products that
  directly compete with Hobby Components Ltd's own range of products.

  THIS SOFTWARE IS PROVIDED "AS IS". HOBBY COMPONENTS MAKES NO WARRANTIES,
  WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED
  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ACCURACY OR
  LACK OF NEGLIGENCE. HOBBY COMPONENTS SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE
  FOR ANY DAMAGES INCLUDING, BUT NOT LIMITED TO, SPECIAL, INCIDENTAL OR
  CONSEQUENTIAL DAMAGES FOR ANY REASON WHATSOEVER. */

#include "HCuOLED.h"
#include "SPI.h"

/* Digital pin number for the displays chip select pin */
#define CS_DI 10
/* Digital pin number for the displays data/command pin */
#define DC_DI 9
/* Digital pin number for the displays reset pin */
#define RST_DI 8


/* Create an instance of the library (uncomment one of the lines below) */
//HCuOLED HCuOLED(SSD1307, SS_DI, DC_DI, RST_DI); // For SSD1307 displays (HCMODU0050 & HCMODU0052)
HCuOLED HCuOLED(SH1106, CS_DI, DC_DI, RST_DI); // For SH1106 displays (HCMODU0058 & HCMODU0059)


void setup()
{
  /* Reset the display */
  HCuOLED.Reset();
}

void loop()
{
  long j = 0;
  /* Display some text using a small 8x8 fixed width font */
  HCuOLED.Cursor(0, 0);
  HCuOLED.SetFont(Terminal_8pt);

  for (int i = -1; i < 2; i++) {
    HCuOLED.Print(i);
  }
  HCuOLED.Print(" A zero:");
  HCuOLED.Print(j);

  /* Display some text using a medium 2 line proportional font */
  HCuOLED.Cursor(0, 20);
  HCuOLED.SetFont(MedProp_11pt);
  for (int i = -1; i < 2; i++) {
    HCuOLED.Print(i);
  }
  HCuOLED.Print(" A zero:");
  HCuOLED.Print(j);
  /* Display a number using a large 4 line LCD style font */
  HCuOLED.Cursor(28, 40);
  HCuOLED.SetFont(LCDLarge_24pt);
  HCuOLED.Print(-12305, 2);

  /* Output the display buffer to the screen */
  HCuOLED.Refresh();

  /* Nothing more to do */
  while (1);
}

andrew
Site Admin
Posts: 1374
Joined: Sun Aug 05, 2012 4:15 pm

Re: HCuOLED library for SSD1307 & SH1106 based OLED displays

Post by andrew » Fri Nov 02, 2018 10:09 am

Thanks for spotting this, it is a bug which I've now (hopefully) fixed. You can download the new fixed version (0.4) from the first post of this thread. You don't need to reinstall the entire library, just copy over the HCuOLED.cpp file to your installed library folder and that should make the necessary changes to your currently installed version.
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.

Post Reply

Return to “Arduino”