RepRapDiscount Full Graphic control with LiquidCrystal library
March 06, 2021 05:45AM
Hi guys,
I use Arduino Mega 2560 R3 + Ramps 1.4 + RepRapDiscount Full Graphic control (ST7920 128X64).
I want to write my own program for a machine that i build, i want control the LCD through LiquidCrystal library so i inseeted the next line:

#include LiquidCrystal.h
//LiquidCrystal lcd(LCD_PINS_RS, LCD_PINS_ENABLE, LCD_PINS_D4, LCD_PINS_D5, LCD_PINS_D6, LCD_PINS_D7);
LiquidCrystal lcd(16, 23, 17, 25, 27, 29);

I managed to get the backgroung light on but nothing on the screen.
the full programm is:

void setup() {
  lcd.begin(LCD_WIDTH, LCD_HEIGHT);
  Serial.begin(9600);
  lcd.clear();
  lcd.print("Hello"); // 
  lcd.setCursor(4, 1);
  lcd.print("Initializing");
  delay(5000); //WAIT FOR STABILLIZATION

  pinMode(BEEPER,OUTPUT);
  digitalWrite(BEEPER,HIGH);
  delay(100);
  digitalWrite(BEEPER,LOW);
}

void loop() {
  lcd.setCursor(0, 1);
  lcd.print(millis() / 1000);
}


i think that to pind are wrong
anybody knows how to help?
Thanks!!

Edited 1 time(s). Last edit at 03/06/2021 05:45AM by SaarNeu93.
Re: RepRapDiscount Full Graphic control with LiquidCrystal library
March 06, 2021 08:00AM
LiquidCrystal is for char based lcd's not pixel based.

"LiquidCrystal Library
This library allows an Arduino board to control LiquidCrystal displays (LCDs) based on the Hitachi HD44780 (or a compatible) chipset, which is found on most text-based LCDs. The library works with in either 4- or 8-bit mode (i.e. using 4 or 8 data lines in addition to the rs, enable, and, optionally, the rw control lines)."

From [www.arduino.cc]

You need to use U8glib.h (can also use U8g2lib.h, but example stayed with same version as used in marlin)

see [github.com] for an example arduino sketch using RAMPS and REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER

Edited 3 time(s). Last edit at 03/06/2021 08:19AM by Dust.
Re: RepRapDiscount Full Graphic control with LiquidCrystal library
March 07, 2021 06:33AM
Thanks Alot
that helped me
Re: RepRapDiscount Full Graphic control with LiquidCrystal library
March 08, 2021 05:31AM
Quote
Dust

see [github.com] for an example arduino sketch using RAMPS and REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER

Hi, Again
is there any chance to use rotary encoder instead of push buttons?
i searched the whole internet and nothing really came up.
Thanks!

Edit:
I found also the u8g2 library that has examples of rotary button and menu examples, but i flash the code to the arduino and only the backlight is on.

On the u8glib (working) the pinout is this:
// SPI Com: SCK = en = 23, MOSI = rw = 17, CS = di = 16
U8GLIB_ST7920_128X64_1X u8g(23, 17, 16);

On the u82glib (not working) the pinout should be this:
U8G2_ST7920_128X64_F_HW_SPI u8g2(U8G2_R0, /* CS=*/ 16, /* reset=*/ 17); // Feather HUZZAH ESP8266, E=clock=14, RW=data=13, RS=CS

here is a link for more information: Link

please help! thanks

Edited 1 time(s). Last edit at 03/08/2021 06:11AM by SaarNeu93.
Re: RepRapDiscount Full Graphic control with LiquidCrystal library
March 08, 2021 06:08AM
That example uses a rotary encoder.

#define BTN_EN1 31
#define BTN_EN2 33
#define BTN_ENC 35

BTN_EN1 is left rotation,
BTN_EN2 is right rotation
BTN_ENC is pressing encoder in.


the code enve says this
void loop() {
  // Read the encoder and update encoderPos    
  encoder0PinNow = digitalRead(BTN_EN1);
  if ((encoder0PinALast == LOW) && (encoder0PinNow == HIGH)) {
    if (digitalRead(BTN_EN2) == LOW) {
      encoderPos++;
    } else {
      encoderPos--;
    }
  }
  encoder0PinALast = encoder0PinNow;
Re: RepRapDiscount Full Graphic control with LiquidCrystal library
March 08, 2021 06:28AM
That lcd on ramps is not using hardware spi only the sd card is using hardware spi.

use U8G2_ST7920_128X64_1_SW_SPI
Re: RepRapDiscount Full Graphic control with LiquidCrystal library
March 08, 2021 08:51AM
Quote
Dust
That example uses a rotary encoder.

#define BTN_EN1 31
#define BTN_EN2 33
#define BTN_ENC 35

BTN_EN1 is left rotation,
BTN_EN2 is right rotation
BTN_ENC is pressing encoder in.


the code enve says this
void loop() {
  // Read the encoder and update encoderPos    
  encoder0PinNow = digitalRead(BTN_EN1);
  if ((encoder0PinALast == LOW) && (encoder0PinNow == HIGH)) {
    if (digitalRead(BTN_EN2) == LOW) {
      encoderPos++;
    } else {
      encoderPos--;
    }
  }
  encoder0PinALast = encoder0PinNow;


Ok, so i managed to get the encoder working .. i modified dome of the code to show menu of =[A,B,C]
it does show the menu, and it does scroll up and down (somwtimes) but i have to rotate the encoder like 1/4 of a round to get the "scrolling" working (either direction).
#include 
#include 
#include 

// SPI Com: SCK = en = 23, MOSI = rw = 17, CS = di = 16
U8GLIB_ST7920_128X64_1X u8g(23, 17, 16);

#define BTN_EN1         31              // Left Rotation
#define BTN_EN2         33              // Right Rotation
#define BTN_ENC         35              // Pressing Encoder In.

//int selectionButton = 31, selectionButtonState, selectionButtonLastState = 0, cntSelectionButtonPressed = 1, cntSelectionButtonPressed2ForMenu2 = 0; //A1
//int menuButton = 33 , menuButtonState, menuButtonLastState = 0; // A0
//int scrollDownButton = 35 , scrollDownButtonState, scrollDownButtonLastState = 0; //A3
//boolean mainMenu = false;


int LastscrollRight = 0; 
int LastscrollLeft = 0; 
int caseNum = 1; 
boolean LastpushButton = false; 
int scrollRight = 0;
int scrollLeft = 0;
int pushButton = 0;
int encoderPos = 1;                     //Current encoder position
int encoder0PinALast;                   //Used to decode rotory encoder, last value
int encoder0PinNow;                     //Used to decode rotory encoder, current value
char posStr[4];                         //Char array to store encoderPos as a string  
char tmp_string[16];


void setup() {
  pinMode(BTN_EN1, INPUT);              // Set BTN_EN1 as an unput, half of the encoder
  digitalWrite(BTN_EN1, HIGH);          // turn on pullup resistors
  pinMode(BTN_EN2, INPUT);              // Set BTN_EN2 as an unput, second half of the encoder
  digitalWrite(BTN_EN2, HIGH);          // turn on pullup resistors
  pinMode(BTN_ENC, INPUT);              // Set BTN_ENC as an unput, encoder button
  digitalWrite(BTN_ENC, HIGH);          // turn on pullup resistors
  u8g.setFont(u8g_font_helvR08);        //Set the font for the display
  u8g.setColorIndex(1);                 // Instructs the display to draw with a pixel on. 
}

void loop() {
 Serial.begin(9600);
 scrollRight = digitalRead(BTN_EN2);
 scrollLeft = digitalRead(BTN_EN1);
 pushButton = digitalRead(BTN_ENC);

//   Read the encoder and update encoderPos    
  encoder0PinNow = digitalRead(BTN_EN2);
  if ((encoder0PinALast == HIGH) && (encoder0PinNow == LOW)) {
    if (digitalRead(BTN_EN2) == LOW) {
      encoderPos++;
    } else {
      encoderPos--;
    }
    if (encoderPos > 3 or encoderPos < 0){
      encoderPos = 1; 
    }
  }
  encoder0PinALast = encoder0PinNow;
//  Serial.println(scrollRight);
  Serial.println(encoderPos);
//  Serial.println(pushButton);

  u8g.firstPage();
  do{
    MainMenu();
  }while(u8g.nextPage());
}

void MainMenu(){
switch(encoderPos)
{

  case 1:
           u8g.setFont(u8g_font_6x13); 
           u8g.setPrintPos(15,15);
           u8g.print("> A");
           u8g.setPrintPos(15,25);
           u8g.print("  B");
           u8g.setPrintPos(15,35);
           u8g.print("  C");  
           break;
  case 2:     
           u8g.setFont(u8g_font_6x13); 
           u8g.setPrintPos(15,15);
           u8g.print("  A");
           u8g.setPrintPos(15,25);
           u8g.print("> B");
           u8g.setPrintPos(15,35);
           u8g.print("  C");  
           break;
           break;
  case 3:
           u8g.setFont(u8g_font_6x13); 
           u8g.setPrintPos(15,15);
           u8g.print("  A");
           u8g.setPrintPos(15,25);
           u8g.print("  B");
           u8g.setPrintPos(15,35);
           u8g.print("> C");  
           break;   
}
}


how do i update the menu more often or how should i make the scrolling more "smooth"

Thanks ALOT !

Edited 1 time(s). Last edit at 03/08/2021 08:53AM by SaarNeu93.
Sorry, only registered users may post in this forum.

Click here to login