4d Systems OLED arduino shield

Has anyone any help/code for this shield using Arduino 021? I've not even been able to get the thing to display from a 32MB SD card... I should mention I've not tried any other version of Arduino. I have a UNO and the 1.7" µOLED-160-G1 version of the display.

So... Anyone able to help me please? Thanks.
Kevin

Wish I was helpful to you, but I'm just getting started with my 4Display-Shield. Have you found anything yet?

Nope. Nothing yet. Hope to figure this display out sometime soon. Maybe over xmas.

Take care.
Kevin

Hey man, got mine working. I'll post code after work. I had to find a few tricks, like unplugging the RX jumper on the OLED shield when you upload to the Arduino, and opening the Serial Monitor to do a reset on the Arduino/OLED 'cause I can't reach the reset switch. More later.

My PDE file:

#include "Oled.h"
#include <string.h>

#define DIGI_A        2    // Values changed in line with
#define DIGI_B        3    // data from shieldlist.org
#define DIGI_C        4    //
#define OLED_WIDTH    160
#define OLED_HEIGHT   128

OLED myOLED(7,8,2500,115200);

int color= 0;
int tick = 0;

int ax = random(1,50);
int ay = random(1,10);
int ag = 1;
int af = 3;

int bx = random(50,160);
int by = random(30,128);
int bg = 3;
int bf = 2;

int latch=0;
int colour = 0;
int delta = 5;
int change = delta;

void setup()
{
  Serial.begin(57600);
  pinMode(10, OUTPUT);
  digitalWrite(10,HIGH);
  myOLED.Init();
  myOLED.Clear();

  int color1 = myOLED.get16bitRGB(255,0,0);
  int color2 = myOLED.get16bitRGB(0,0,255);

  int ax = random(92)+2;
  int ay = random(60)+2;
  int bwidth = random(92-ax);
  int bheight = random(60-ay);

  myOLED.PenSize(1);
  myOLED.DrawRectangle(0, 0, OLED_WIDTH - 1, OLED_HEIGHT - 1, myOLED.get16bitRGB(255,0,0));
}

void loop()
{
  colour += change;
  if (colour > (255-delta)) change = -delta;
  if (colour < delta) change = delta;
  myOLED.DrawString(20, 45, 2, myOLED.get16bitRGB(0,0,colour), 3, 3, "12:58");
  myOLED.DrawString(45, 10, 0, myOLED.get16bitRGB(255-colour,0,0), 3, 3, "Test");
}

The OLED.h file:

/*
      Oled.h - Oled Display library for Arduino & 4d Systems Serial OLEDs
      Copyright(c) 2010 Paul Karlik 
      Original Source Copyright(c)2007 Oscar Gonzalez

      Licensed under the MIT license: 
      http://www.opensource.org/licenses/mit-license.php
      
      THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
      IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
      AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
      OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
      THE SOFTWARE.
      
      16bitColor from RGB by YAPAN.org's small utilities for Arduino
      http://www.opensource.org/licenses/bsd-license.php
*/

#ifndef Oled_h
#define Oled_h

#include <inttypes.h>

#define OLED_BAUDRATE                  57600
#define OLED_RESETPIN                  8  
#define OLED_INITDELAYMS            1000

#define      OLED_DETECT_BAUDRATE              0x55

#define      OLED_CLEAR                  0x45
#define      OLED_BKGCOLOR                  0x42
#define      OLED_COPYPASTE                  0x63

#define OLED_SAVE_CHAR                  0x41
#define OLED_DISPLAY_CHAR            0x44

#define      OLED_LINE                  0x4C
#define      OLED_CIRCLE                  0x43
#define      OLED_CIRCLEFILL                  0x69
#define      OLED_PUTPIXEL                  0x50
#define      OLED_READPIXEL                  0x52
#define      OLED_RECTANGLE                  0x72
#define OLED_SETPEN                  0x70
#define      OLED_SETFONTSIZE            0x46
#define      OLED_FONT5X7                  0x01
#define      OLED_FONT8X8                  0x02
#define      OLED_FONT8X12                  0x03
#define OLED_TEXT                       0x53
#define      OLED_TEXTFORMATED            0x54

#define      OLED_COMMAND_CONTROL              0x59
#define      OLED_COMMAND_DISPLAY              0x01
#define      OLED_COMMAND_CONTRAST              0x02
#define      OLED_COMMAND_POWER            0x03

#define OLED_ACK                  0x06
#define OLED_NAK                   0x15

class OLED
{

  public:
    OLED(uint8_t pinPower, uint8_t pinReset, uint8_t baudRate, uint8_t startUpTimer);

    uint8_t Init();   
    unsigned int get16bitRGB(uint8_t red, uint8_t green, uint8_t blue);
  
    
    uint8_t ResetDisplay();
      uint8_t Clear();
      uint8_t PutPixel(uint8_t x, uint8_t y, unsigned int color);
      uint8_t PenSize(uint8_t size);
      uint8_t DrawLine(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2, unsigned int color);
      uint8_t DrawRectangle(uint8_t x, uint8_t y, uint8_t width, uint8_t height, unsigned int color);
      uint8_t DrawCircle(uint8_t x, uint8_t y, uint8_t radius, unsigned int color);
      uint8_t SetFontSize(uint8_t FontType);
      uint8_t DrawText(uint8_t column, uint8_t row, uint8_t font_size, char *mytext, unsigned int color);
        uint8_t DrawString(uint8_t column, uint8_t row, uint8_t font_size, unsigned int color, uint8_t width, uint8_t height, char* text);
      uint8_t DrawSingleChar(uint8_t column, uint8_t row, uint8_t font_size, uint8_t MyChar, unsigned int color);
      uint8_t CopyPast(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2, uint8_t width, uint8_t height);
      uint8_t SaveBitChar(uint8_t slot, uint8_t data1, uint8_t data2, uint8_t data3, uint8_t data4, uint8_t data5, uint8_t data6, uint8_t data7, uint8_t data8);
      uint8_t DisplayBitChar(uint8_t slot, uint8_t x, uint8_t y, unsigned int color);
      
  private:
      uint8_t _pinReset;
      uint8_t _pinPower;
      uint8_t _baudRate;
      uint8_t _startUpTimer;
      
    void write(uint8_t value);
        
};

#endif

The OLED.cpp file is in the next post...

Thanks very much for the update. I will give it a go tonight. Take care,
Kevin

Hy !
Thanks from me as well.
I received my 4D LCD display (the 1.44") and don't know yet how to use it.

Could you tell us as well which jumper to configure, how, for which mode, etc.
... or point us to a beginner's link.

#include "Oled.h"

#include <stdio.h>
#include <string.h>
#include <inttypes.h>
#include "WProgram.h"


OLED::OLED(uint8_t pinPower, uint8_t pinReset, uint8_t baudRate, uint8_t startUpTimer){

  _pinReset = pinReset;
  _pinPower = pinPower;
  _baudRate = baudRate;
  _startUpTimer = startUpTimer;
   
  pinMode(_pinPower, OUTPUT);
  pinMode(_pinReset, OUTPUT);
  digitalWrite(_pinPower, HIGH);
  //pinMode(_pinReset, OUTPUT);

}

void OLED::write(uint8_t value) {
  Serial.print(value, BYTE);
}

char GetResponse()
{
      byte incomingByte = OLED_ACK;
      while (!Serial.available()) { delayMicroseconds(150); }
      incomingByte = Serial.read();
      return incomingByte;
}

uint8_t OLED::Init()
{
      ResetDisplay();  
      delay(OLED_INITDELAYMS);
      Serial.write(OLED_DETECT_BAUDRATE); 
      GetResponse(); 
}

// YAPAN.org's small utilities for Arduino //
unsigned int OLED::get16bitRGB(uint8_t red, uint8_t green, uint8_t blue) 
{
  uint8_t r = red >> 3;                                      // red: 0-31
  uint8_t g = green >> 2;                                      // green: 0-63
  uint8_t b = blue >> 3;                                     // blue: 0-31

  unsigned int bitRGB = (r << 11) + (g << 5) + b;
  return bitRGB;
}

uint8_t OLED::Clear()
{
      Serial.write(OLED_CLEAR);
    GetResponse();
}

uint8_t OLED::ResetDisplay()
{
      digitalWrite(OLED_RESETPIN, LOW);
      delay(10);                  
      digitalWrite(OLED_RESETPIN, HIGH);
      delay(10);             
}

uint8_t OLED::PutPixel(uint8_t x, uint8_t y, unsigned int color)
{
      Serial.write(OLED_PUTPIXEL);
      Serial.write(x);                                    // X
      Serial.write(y);                                    // Y

      // Color
      Serial.write(color >> 8);                        // MSB                  
      Serial.write(color & 0xFF);                        // LSB

    GetResponse();
}

uint8_t OLED::PenSize(uint8_t size) {
  Serial.write(OLED_SETPEN);
  Serial.write(size);
   
  GetResponse();
}

uint8_t OLED::DrawLine(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2, unsigned int color)
{

      Serial.write(OLED_LINE);

      Serial.write(x1);                                    // X1
      Serial.write(y1);                                    // Y1
      Serial.write(x2);                                    // X2
      Serial.write(y2);                                    // Y2

      // Color
      Serial.write(color >> 8);                        // MSB                  
      Serial.write(color & 0xFF);                  // LSB

    GetResponse();

}

uint8_t OLED::DrawRectangle(uint8_t x, uint8_t y, uint8_t width, uint8_t height, unsigned int color)
{

      Serial.write(OLED_RECTANGLE); 

      Serial.write(x);                                    // X1
      Serial.write(y);                                    // Y1
      Serial.write(x+width);                              // X2
      Serial.write(y+height);                              // Y1

      // Color
      Serial.write(color >> 8);                        // MSB                  
      Serial.write(color & 0xFF);                        // LSB                        
      
      GetResponse();
}

uint8_t OLED::DrawCircle(uint8_t x, uint8_t y, uint8_t radius, unsigned int color)
{
    
    Serial.write(OLED_CIRCLE);

      Serial.write(x);                                    // X
      Serial.write(y);                                    // Y
      Serial.write(radius);                              // Radius

      // Color
      Serial.write(color >> 8);                        // MSB                  
      Serial.write(color & 0xFF);                        // LSB

    GetResponse();

}

uint8_t OLED::SetFontSize(uint8_t FontType)
{
    
    Serial.write(OLED_SETFONTSIZE);
    Serial.write(FontType);
    
    GetResponse();
}

uint8_t OLED::DrawText(uint8_t column, uint8_t row, uint8_t font_size, char *mytext, unsigned int color)
{

      Serial.write(0x73);                                    // Formated Text
        
    // Adjust to center of the screen (26 Columns at font size 0)
        int newCol = 13 - (strlen(mytext)/2);
   
        Serial.write(column);                               // Column    
      Serial.write(row);                               // Row
                  
      Serial.write(font_size);                         // Font Size
      
      // Color
      Serial.write(color >> 8);                        // MSB                  
      Serial.write(color & 0xFF);                        // LSB

      for (int i=0 ; i<strlen(mytext) ; i++)
      {
            Serial.print(mytext[i]);                   // character to write
      }
      
      Serial.print(0x00, BYTE);                         // string terminator (always 0x00)

    GetResponse();

}

// Added CMurphy 2010-12-12
uint8_t OLED::DrawString(uint8_t column, uint8_t row, uint8_t font_size, 
  unsigned int color, uint8_t width, uint8_t height, char* text)
{

  Serial.write(OLED_TEXT);
  Serial.write(column);
  Serial.write(row);
  Serial.write(font_size);
  // Color
  Serial.write(color >> 8);                        // MSB                  
  Serial.write(color & 0xFF);                        // LSB
  Serial.write(width);
  Serial.write(height);
  while(*text != '\0') Serial.write((char) *text++);
  Serial.write((uint8_t) 0);

  GetResponse();

}

uint8_t OLED::DrawSingleChar(uint8_t column, uint8_t row, uint8_t font_size, uint8_t MyChar, unsigned int color)
{

      Serial.write(OLED_TEXTFORMATED);
      
    Serial.write(MyChar);
    Serial.write(column);
    Serial.write(row);
        
      // Color
      Serial.write(color >> 8);                        // MSB                  
      Serial.write(color & 0xFF);                        // LSB

    GetResponse();

}

uint8_t OLED::CopyPast(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2, uint8_t width, uint8_t height)
{

      Serial.write(OLED_COPYPASTE);

      Serial.write(x1);                                    // X1
      Serial.write(y1);                                    // Y1
      Serial.write(x2);                                    // X2
      Serial.write(y2);                                    // Y2

      Serial.write(width);                              // Box Width      
      Serial.write(height);                              // Box Height

    GetResponse();

}

uint8_t OLED::SaveBitChar(uint8_t slot, uint8_t data1, uint8_t data2, uint8_t data3, uint8_t data4, uint8_t data5, uint8_t data6, uint8_t data7, uint8_t data8  )
{

      Serial.write(OLED_SAVE_CHAR);

      Serial.write(slot);                                    // Char Slot
      Serial.write(data1);                              // Data 1
      Serial.write(data2);                              // Data 2
      Serial.write(data3);                              // Data 3
      Serial.write(data4);                              // Data 4
      Serial.write(data5);                              // Data 5
      Serial.write(data6);                              // Data 6
      Serial.write(data7);                              // Data 7
      Serial.write(data8);                              // Data 8

    GetResponse();

}


uint8_t OLED::DisplayBitChar(uint8_t slot, uint8_t x, uint8_t y, unsigned int color)
{

      Serial.print(OLED_DISPLAY_CHAR, BYTE);

      Serial.write(slot);                                    // Char Slot
      Serial.write(x);                                    // X
      Serial.write(y);                                    // Y
      
      // Color
      Serial.write(color >> 8);                        // MSB                  
      Serial.write(color & 0xFF);                        // LSB

    GetResponse();

}

Sorry I haven't had time to write it up like I promised. Here's a quick run down on how to get this code running (sorry, assuming you're not super familiar with Arduino):

  • Create a new sketch and save it. Call it whatever you like.
  • Add two new tabs to your project and name them OLED.h and OLED.cpp.
  • Paste in the code from this and the my previous post.
  • Check the code compiles.
  • Plug your Arduino in to USB, mount the OLED shield and remove the bottom jumper on JP1 (serial receive) on the OLED shield.
  • Upload the program to the Arduino
  • Ensure the upload is complete, then replace the jumper
  • Open Serial Monitor in the Arduino application to perform a reset of the device.

You should now have a red border on the screen with red and blue text. Remember to have the jumper off when you upload!

Hope that's useful!

PS. Apologies to the original code authors (see comments) I haven't had time to give you proper attribution.

Great work Prawnhead. Got the display working thanks to you. Nice to see it doing something.

Now to get it to power down safely. Have you looked into that much?

Kevin

P.S. I am using the 4D Systems shield and the Arduino UNO.

I can't get mine to work.
Kevin, any chance you could describe what you did in details ?
f.e.:
the name you save your sketch as, is it used in the cpp or h file ? do I need to update a name somewhere else ? (what is the WProgram.h thing ?)
Do you keep the other 2 pins on when you took the bottom one off when uploading the sketch ?
Do you put them back ?
How do you reset the Arduino via the serial monitor ? you type reset and send it ? or serial.reset ? or something else ?

big thanks for your help ! :slight_smile:

You can name the sketch pde anything you want but name the cpp and h file the same as Prawnhead. I sent you some code that uses the cpp and h file but the demo of Prawns above works as well. Try and get his examples to work before moving on...

The only jumper pin you have to play with is the "Bottom" one. Keep the other two in place. Remove the botom jumper before you upload the sketch. When the sketch has been uploaded put the jumper back. Then you have to reset the uno and the best way to do this is by hitting the Serial Monitor button as the reset button is covered by the shield... You don't have to type anything because the arduinos are setup to reset the uC every time the Serial monitor is activated or if you change the baud rate etc.

As soon as you get it to work with Prawns code add the code that I sent you that "Power downs" the Oled display so as to not damage the display by just turning off the power to the display.

z = 0x0;
Serial.print(0x59,BYTE);
Serial.print(0x3,BYTE);
Serial.print(z,BYTE);

Hope this helps. All credit goes to Prawnhead for getting the display to work. I just added the powerdown feature.

Kevin