Arduino code and Video for SSD1306 OLED 128 x 64 Display Robojax.com

This is the Arduino code for PCA6985 16 channel 12 bits servo controller

This video shows you how to use PCA6985 servo controller module for arduino.

this is the code to controll one or more servos using PCA6895. Modify it so it is used for your purpose. This code have a mappting methode so you enter your desired angle and it will convert it to appropriate pulse width. you will use pwm.setPWM(servo_number, 0, angleToPulse(angle) );

replace servo_number with the connector number like 0 ,2, up to 15 and the pulse is the value between 150 to 600 in this example. The angle is the a value between 0 to 180 degrees.

http://robojax.com/learn/arduino/
  1. download SSD1306 Manual
  2. SSD1306 Library (from Robojax.com)
  3. SSD1306 Library (from GetHub)

 /*
 * Original sourse: https://github.com/adafruit/Adafruit_SSD1306
 * This is the Arduino code SSD1306 OLED 128 x 64 Display
 * watch the video for details and demo http://youtu.be/UmYiHTOz-5k
 * This code have been modefied to print specific elements such as text, line, circle, rectangle etc.
 * I have added custom method to make printing text easy.
 *  * 
 * Written by Ahmad Nejrabi for Robojax Video channel www.Robojax.com
 * Date: Dec 17, 2017, in Ajax, Ontario, Canada
 * Permission granted to share this code given that this
 * note is kept with the code.
 * Disclaimer: this code is "AS IS" and for educational purpose only.
 * this code has been downloaded from http://robojax.com/learn/arduino/
 * 
 */

/*********************************************************************
This is an example for our Monochrome OLEDs based on SSD1306 drivers

  Pick one up today in the adafruit shop!
  ------> http://www.adafruit.com/category/63_98

This example is for a 128x64 size display using I2C to communicate
3 pins are required to interface (2 I2C and one reset)

Adafruit invests time and resources providing this open source code, 
please support Adafruit and open-source hardware by purchasing 
products from Adafruit!

Written by Limor Fried/Ladyada  for Adafruit Industries.  
BSD license, check license.txt for more information
All text above, and the splash screen must be included in any redistribution
*********************************************************************/

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2


#define LOGO16_GLCD_HEIGHT 64 
#define LOGO16_GLCD_WIDTH  128 
static const unsigned char PROGMEM logo16_glcd_bmp[] =
{ B00000000, B11000000,
  B00000001, B11000000,
  B00000001, B11000000,
  B00000011, B11100000,
  B11110011, B11100000,
  B11111110, B11111000,
  B01111110, B11111111,
  B00110011, B10011111,
  B00011111, B11111100,
  B00001101, B01110000,
  B00011011, B10100000,
  B00111111, B11100000,
  B00111111, B11110000,
  B01111100, B11110000,
  B01110000, B01110000,
  B00000000, B00110000 };

#if (SSD1306_LCDHEIGHT != 64)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif

void setup()   {                
  Serial.begin(9600);

  // by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3D (for the 128x64)
  // init done
  
}


void loop() {
 display.clearDisplay();
  robojaxText("Values", 3, 0, 2, false);
  robojaxText("V: 41v", 3, 22, 2, false);
  robojaxText("Temprature: 32C", 4, 45, 1, true);
  display.drawLine(1, 37, 100, 37, WHITE);
  display.drawRect(1, 20, 100,40, WHITE);
  //display.drawCircle(63,31, 31, WHITE);
   //display.startscrollright(0x00, 0x0F);
  display.display();
   delay(20000);
}

/*
 * robojaxText(String text, int x, int y,int size, boolean d)
 * text is the text string to be printed
 * x is the integer x position of text
 * y is the integer y position of text
 * z is the text size, 1, 2, 3 etc
 * d is either "true" or "false". Not sure, use true
 */
void robojaxText(String text, int x, int y,int size, boolean d) {

  display.setTextSize(size);
  display.setTextColor(WHITE);
  display.setCursor(x,y);
  display.println(text);
  if(d){
    display.display();
  }
  
  delay(100);
}

   

This is the Arduino code SSD1306 OLED 128 x 64 Display without custome method

this is the code make it possible to print text, line, rectangle, circle be printed on SSD1306 OLED display. For instrcutions please watch the video http://youtu.be/UmYiHTOz-5k

  1. download SSD1306 Manual
  2. SSD1306 Library (from Robojax.com)
  3. SSD1306 Library (from GetHub)

 /*
 * Original sourse: https://github.com/adafruit/Adafruit_SSD1306
 * This is the Arduino code SSD1306 OLED 128 x 64 Display
 * watch the video for details and demo http://youtu.be/UmYiHTOz-5k
 * This code have been modefied to print specific elements such as text, line, circle, rectangle etc.
 *  * 
 *  * 
 * Written by Ahmad Nejrabi for Robojax Video channel www.Robojax.com
 * Date: Dec 15, 2017, in Ajax, Ontario, Canada
 * Permission granted to share this code given that this
 * note is kept with the code.
 * Disclaimer: this code is "AS IS" and for educational purpose only.
 * This code has been downloaded from http://robojax.com/learn/arduino/
 * 
 */
/*********************************************************************
This is an example for our Monochrome OLEDs based on SSD1306 drivers

  Pick one up today in the adafruit shop!
  ------> http://www.adafruit.com/category/63_98

This example is for a 128x64 size display using I2C to communicate
3 pins are required to interface (2 I2C and one reset)

Adafruit invests time and resources providing this open source code, 
please support Adafruit and open-source hardware by purchasing 
products from Adafruit!

Written by Limor Fried/Ladyada  for Adafruit Industries.  
BSD license, check license.txt for more information
All text above, and the splash screen must be included in any redistribution
*********************************************************************/

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2


#define LOGO16_GLCD_HEIGHT 64 
#define LOGO16_GLCD_WIDTH  128 
static const unsigned char PROGMEM logo16_glcd_bmp[] =
{ B00000000, B11000000,
  B00000001, B11000000,
  B00000001, B11000000,
  B00000011, B11100000,
  B11110011, B11100000,
  B11111110, B11111000,
  B01111110, B11111111,
  B00110011, B10011111,
  B00011111, B11111100,
  B00001101, B01110000,
  B00011011, B10100000,
  B00111111, B11100000,
  B00111111, B11110000,
  B01111100, B11110000,
  B01110000, B01110000,
  B00000000, B00110000 };

#if (SSD1306_LCDHEIGHT != 64)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif

void setup()   {                
  Serial.begin(9600);

  // by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3D (for the 128x64)
  // init done
  



}


void loop() {
 display.clearDisplay();
 
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(2,1);// set the cursor at x=2, y=1 which is top left corner of display
  display.println("Robojax");// the actual text

  display.setCursor(2,18);
  display.println("YouTube");// set the cursor at x=2, y=18 which is top left under the first text line

 
 display.drawLine(0,16, display.width()-1, 16, WHITE); // drawing from th point x=0, y=16 to x=64-1 y=16
 
   display.display();
  display.startscrollright(0x00, 0x0F);
  delay(2000);
  display.stopscroll();
  delay(1000);
  display.startscrollleft(0x00, 0x0F);
  delay(2000);
  display.stopscroll();
  delay(1000);    
  display.startscrolldiagright(0x00, 0x07);
  delay(2000);
  display.startscrolldiagleft(0x00, 0x07);
  delay(2000);
  display.stopscroll();
   delay(10000);
}