Output serial monitor to a 128X64 LCD on nano

Bought a 128X64 0.96 inch LCD with a 4 pin and would like to just output serial monitor to the LCD.

I have a sketch that does what I need but it outputs to a different type of LCD. My LCD uses Adafruit_SSD1306 library, not LiquidCrystal.h

Here is the skitch I need modified for the 128x64 LCD:

#define analogPin 0          
#define chargePin 13         
#define dischargePin 8        
#define resistorValue 10000.0F  
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

unsigned long startTime;
unsigned long elapsedTime;
float microFarads;                
float nanoFarads;

void setup(){
  pinMode(chargePin, OUTPUT);     
  digitalWrite(chargePin, LOW); 
  lcd.begin(16, 2); 
}

void loop(){
  digitalWrite(chargePin, HIGH);  
  startTime = millis();
  while(analogRead(analogPin) < 648){       
  }

  elapsedTime= millis() - startTime;
  microFarads = ((float)elapsedTime / resistorValue) * 1000;   
  lcd.print(elapsedTime);       
  lcd.print(" mS");
  delay(2000);  
  lcd.clear();
  delay(500);

  if (microFarads > 1){
    lcd.print(microFarads);       
    lcd.print(" uF");   
    delay(2000);    
  }

  else{
    nanoFarads = microFarads * 1000.0;      
    lcd.print(nanoFarads);         
    lcd.print(" nF");          
    delay(2000); 
  }

  lcd.clear();
  digitalWrite(chargePin, LOW);            
  pinMode(dischargePin, OUTPUT);            
  digitalWrite(dischargePin, LOW);          
  while(analogRead(analogPin) > 0){         
  }

  pinMode(dischargePin, INPUT);      
}

Start by looking at examples in the Adafruit_SSD1306 library and get them to work. Next it should be a matter of adjusting/replacing the calls to the current lcd methods.

Perhaps you are confusing LCD with OLED? SSD1306 indicates an OLED display.

Post your attempt to modify it, and explain how it behaves compared to how you wanted it to behave.

If you are hoping someone will do these modifications for you, we can move this topic to a section of the forum where you can offer money in exchange for this service. Personally I would be very careful about offering money there, not everyone is trustworthy.

Why?

I would recommend the U8G2 library. It has a feature called "U8log" which behaves similar to serial monitor. It also consumes far less of the Uno's limited memory, compared to the Adafruit library.

Ok so I found a library ssd1306 by Alexey to print text to the 1" 128x64 LCD

~this is the LCD I'm referring to: https://www.ebay.com/itm/315044873043

Edited the sketch but now I get this error:

Compilation error: cannot convert 'float' to 'const char' for argument '3' to 'void LCDTextDraw(int, int, const char)'

It's to the reference to these two lines. I really don't know how to convert this the correct way

    LCDTextDraw(20, 40, microFarads);
    LCDTextDraw(20, 40, nanoFarads);

Here is my sketch attempt right now:

// https://forum.arduino.cc/t/print-text-at-any-y-value-on-ssd1306/1183364

////////////// LCD Stuff see website at top
#include "ssd1306.h"
#include "nano_gfx.h"
const int PIN_I2C_SCL = 16;
const int PIN_I2C_SDA = 13;
//////////////

#define analogPin 0          
#define chargePin 13         
#define dischargePin 8        
#define resistorValue 10000.0F  



unsigned long startTime;
unsigned long elapsedTime;
float microFarads;                
float nanoFarads;

void setup(){
  pinMode(chargePin, OUTPUT);     
  digitalWrite(chargePin, LOW); 

////////////// LCD Stuff see website at top
  pinMode(PIN_I2C_SCL, OUTPUT);
  pinMode(PIN_I2C_SDA, OUTPUT);
  LCDInit();
  LCDScreenClear(true);
////////////// END LCD
}

void loop(){
  digitalWrite(chargePin, HIGH);  
  startTime = millis();
  while(analogRead(analogPin) < 648){       
  }

  elapsedTime= millis() - startTime;
  microFarads = ((float)elapsedTime / resistorValue) * 1000;  
  
  LCDScreenClear(true);
  LCDTextDraw(20, 10, elapsedTime);
  LCDTextDraw(20, 20, " mS");
  
  delay(2000);  
  //LCDScreenClear(true);
  delay(500);

  if (microFarads > 1){
    LCDTextDraw(20, 40, microFarads);
    LCDTextDraw(20, 50, " uF"); 
    delay(2000);    
  }

  else{
    nanoFarads = microFarads * 1000.0;              
    LCDTextDraw(20, 40, nanoFarads);
    LCDTextDraw(20, 50, " nF");  
    delay(2000); 
  }

  LCDScreenClear(true);

  digitalWrite(chargePin, LOW);            
  pinMode(dischargePin, OUTPUT);            
  digitalWrite(dischargePin, LOW);          
  while(analogRead(analogPin) > 0){         
  }

  pinMode(dischargePin, INPUT);      
}


//////////////////////////////////////////////
////////////// LCD Stuff see website at top
void LCDTextDraw(int x, int y, const char* text)
{
  EFontStyle fontStyle;
  
  ssd1306_printFixed(x, y, text, fontStyle);
}

void LCDRectDraw(int x, int y, int w, int h)
{
  ssd1306_fillRect(x, y, x + w, y + h);
}

void LCDScreenClear(bool fill)
{
  ssd1306_clearScreen();

  if (fill)
    LCDRectDraw(0, 0, 128, 64);
}

void LCDInit()
{
  ssd1306_setFixedFont(ssd1306xled_font6x8);
  ssd1306_128x64_i2c_initEx(PIN_I2C_SCL, PIN_I2C_SDA, 0);
}
/////////////// END LCD

You will have to convert the float to text first. You can do so with dtostrf

For your information, it's an OLED. It's not an LCD. Chinese sellers often include technically inappropriate words into the product descriptions to get more search results.

But, whatever the technology, it's a display.

// https://forum.arduino.cc/t/print-text-at-any-y-value-on-ssd1306/1183364

////////////// LCD Stuff see website at top
#include "ssd1306.h"
#include "nano_gfx.h"
const int PIN_I2C_SCL = 16;
const int PIN_I2C_SDA = 13;
//////////////

#define analogPin 0          
#define chargePin 13         
#define dischargePin 8        
#define resistorValue 10000.0F  



unsigned long startTime;
unsigned long elapsedTime;
float microFarads;                
float nanoFarads;
char buffer[21];

void setup(){
  pinMode(chargePin, OUTPUT);     
  digitalWrite(chargePin, LOW); 

////////////// LCD Stuff see website at top
  pinMode(PIN_I2C_SCL, OUTPUT);
  pinMode(PIN_I2C_SDA, OUTPUT);
  LCDInit();
  LCDScreenClear(true);
////////////// END LCD
}

void loop(){
  digitalWrite(chargePin, HIGH);  
  startTime = millis();
  while(analogRead(analogPin) < 648){       
  }

  elapsedTime= millis() - startTime;
  microFarads = ((float)elapsedTime / resistorValue) * 1000;  
  
  LCDScreenClear(true);
  LCDTextDraw(20, 10, elapsedTime);
  LCDTextDraw(20, 20, " mS");
  
  delay(2000);  
  //LCDScreenClear(true);
  delay(500);

  if (microFarads > 1){
    dtostrf(microFarads, 8, 2, buffer);
    LCDTextDraw(20, 40, buffer);
    LCDTextDraw(20, 50, " uF"); 
    delay(2000);    
  }

  else{
    nanoFarads = microFarads * 1000.0;              
    dtostrf(nanoFarads, 8, 2, buffer);
    LCDTextDraw(20, 40, buffer);
    LCDTextDraw(20, 50, " nF");  
    delay(2000); 
  }

  LCDScreenClear(true);

  digitalWrite(chargePin, LOW);            
  pinMode(dischargePin, OUTPUT);            
  digitalWrite(dischargePin, LOW);          
  while(analogRead(analogPin) > 0){         
  }

  pinMode(dischargePin, INPUT);      
}


//////////////////////////////////////////////
////////////// LCD Stuff see website at top
void LCDTextDraw(int x, int y, const char* text)
{
  EFontStyle fontStyle;
  
  ssd1306_printFixed(x, y, text, fontStyle);
}

void LCDRectDraw(int x, int y, int w, int h)
{
  ssd1306_fillRect(x, y, x + w, y + h);
}

void LCDScreenClear(bool fill)
{
  ssd1306_clearScreen();

  if (fill)
    LCDRectDraw(0, 0, 128, 64);
}

void LCDInit()
{
  ssd1306_setFixedFont(ssd1306xled_font6x8);
  ssd1306_128x64_i2c_initEx(PIN_I2C_SCL, PIN_I2C_SDA, 0);
}
/////////////// END LCD
1 Like

I actually figured out the "dtostrf" conversion :slight_smile:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.