Project showcase

2€ OLED I2C Analog Pin Dynamic Plotting © GPL3+

Cool project to begin with 128x64 OLED, done with a twisted logic to fix the refresh flashing screen.

  • 7,032 views
  • 0 comments
  • 14 respects

Components and supplies

A000066 iso both
Arduino UNO & Genuino UNO
it could be done with nano with enough memory (atmega328)
×1
Adafruit 128X64 LED LCD OLED
×1
11026 02
Jumper wires (generic)
×1
Bourns 3362p 1 103lf image 160px
Single Turn Potentiometer- 10k ohms
FOR TESTING
×1
EXTERNAL POWER 5V for the oled, arduino is not enough
×1
12002 04
Breadboard (generic)
×1

Apps and online services

About this project

A purchase for 2,7€ from AliExpress, though, to be honest, by the time it arrived I had forgotten why I purchased it in the first place.

Proudly done in two hours during a hot night. First of all, you need to download the libraries needed in the code below and uncomment one #define thing at the <Adafruit_SSD1306.h>. We comment the 128x32 define line and uncomment the 128x64 define line because our screen has 128x64 pixels of definition.

Short scheme of how the pixels are mapped in our screen:

The origin of coordinates is for some silly reason located on the top left of the screen, and our function display.drawFastVLine can't draw negative heights, so we are going to play with the cursor point along with the databar height.

The rest is commented in the code file. Enjoy your hacking!

Code

OLED code, initial text and analog readC/C++
///coded by Javier Muoz Sez with the help of https://github.com/klauscam/Arduino-Cellular-Automata/blob/master/CellularAutomata.ino
//any question ,suggestion, joboffer, or singing telegram adress to javimusama@gmail.com
//enjoy

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


#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
#define retardo 60
#define escalaejey 10 //en pixels
int i=0,j=0,ii=0,iii=0,muevepantalla=0;
uint8_t arraydatos[129];
uint8_t arrayauxiliar[129];

void setup()   {                  
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C); //initialize with the I2C addr 0x3C (128x64)
  display.clearDisplay();
  display.display();
  
  //comment below part to erase the text or put in your own
  display.setCursor(10,22);
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.println(F("Javi es to pepino"));
  ////////////////////////////////////////////////////
  
  pinMode(A0,INPUT);

  //initialice data array with all 0
  for(i=0;i<=129;i++)
  {arraydatos[i]=0;}
  i=0;
  for(i=0;i<=129;i++)
  {arrayauxiliar[i]=0;}
  i=0;
}


void loop() {
grid();//SET A FANCY GRID

//THIS FUNCTION DOES THE MAGIC
  for(iii=0;iii<=128;iii++)
  {

if(arraydatos[iii+1]<=arraydatos[iii])//IF OLD DATA IS GREATER THAN NEW DATA STORES 1 IN ARRAYAUXILIAR
{arrayauxiliar[iii]=1;}
if(arraydatos[iii]==0){arrayauxiliar[iii]=0;}//IF NOT MAKE SURE THAT 0 IS STORED IN ARRAYAUXILIAR
if(arraydatos[iii+1]==arraydatos[iii])
{arrayauxiliar[iii]=0;}
arraydatos[iii]=arraydatos[iii+1];//COPY THE DATA ONE POSITION TO THE LEFT
  }


  
arraydatos[127]=map(analogRead(A0),0,1023,0,63);//NEW DATA READ FROM ANALOG PIN STORED AT THE END OF THE ARRAY

plotdata();
  }




  void grid ()//EASY FUNCTION , DRAW A WHITE DOT MULTIPLE TIMES MAKING A GRID
{
for(ii=0;ii<=43;ii++)
{
for(i=0;i<=7;i++)
{
  display.drawPixel(ii*3,escalaejey*i,WHITE);
}

}
      display.display();
}

  





void plotdata()//THIS DOES SOME MAGIC TOO
{
  for(i=0;i<=126;i++)
{  
  if(arrayauxiliar[i]==1){display.drawFastVLine(i,0,63-arraydatos[i],BLACK);}//IF NEW DATA VALUE IS SMALLER THAN OLD DATA VALUE WE NEED TO BUILD THE DATA SECTOR BY SWITCHINGOFF pixels which otherwise would remain ON.
  if(arrayauxiliar[i]==0){display.drawFastVLine(i,63-arraydatos[i],arraydatos[i],WHITE);} //IF NOT JUST SWITCH ON THE PIXELS CREATING A VerticalLine
}
   display.display();

}

Schematics

OLED SCHEMATIC
:)
Oled

Comments

Similar projects you might like

Level Platform Using Accelerometer

Project tutorial by Mark Tashiro

  • 16,966 views
  • 15 comments
  • 29 respects

Toggle LED with NFC Tag and PIN

Project showcase by vincent wong

  • 12,823 views
  • 9 comments
  • 40 respects

Ultrasonic Sensor with Alarm, LCD and Temperature

Project tutorial by MichDragstar

  • 4,651 views
  • 7 comments
  • 19 respects

tinyGlow Smart LEDs

by Alex Glow

  • 3,799 views
  • 3 comments
  • 24 respects
Add projectSign up / Login