LCD 128x64 7920 problem

I have a program which has LCD pin description and message which should be displayed. So I add a LiquidCrystal.h library.
I think I should declare the type of used LCD and add the command to run the LCD program.
Please help me with that.
What I should with R/W and PBS pins ?

#1

// Digital pin definitions
// Digital pin 0 not used, however if we are using the serial port for debugging then it's serial input
const int debugTxPin = 1; // transmit pin reserved for debugging
const int encoderButtonPin = 2; // encoder button, also IN0 for waking up from sleep mode
const int earpiecePin = 3; // earpiece, aka OCR2B for tone generation
const int T0InputPin = 4;
const int coilDrivePin = 5;
const int LcdRsPin = 6;
const int LcdEnPin = 7;
const int LcdPowerPin = 8; // LCD power and backlight enable
const int T0OutputPin = 9;
const int lcdD0Pin = 10;
const int lcdD1Pin = 11; // pins 11-13 also used for ICSP
const int LcdD2Pin = 12;
const int LcdD3Pin = 13;

#2

// For diagnostic purposes, print the individual bin counts and the 2 indepedently-calculated gains and phases 
Serial.print(misses);
Serial.write(' ');

if (bin0 >= 0.0) Serial.write(' ');
Serial.print(bin0, 2);
Serial.write(' ');
if (bin1 >= 0.0) Serial.write(' ');
Serial.print(bin1, 2);
Serial.write(' ');
if (bin2 >= 0.0) Serial.write(' ');
Serial.print(bin2, 2);
Serial.write(' ');
if (bin3 >= 0.0) Serial.write(' ');
Serial.print(bin3, 2);
Serial.print(" ");
Serial.print(amp1, 2);
Serial.write(' ');
Serial.print(amp2, 2);
Serial.write(' ');
if (phase1 >= 0.0) Serial.write(' ');
Serial.print(phase1, 2);
Serial.write(' ');
if (phase2 >= 0.0) Serial.write(' ');
Serial.print(phase2, 2);
Serial.print(" ");

ted:

Have you looked here?
http://forum.hobbycomponents.com/viewtopic.php?f=75&t=1395

LCD Display Module Manual

reading that page you need to tell us if on the back of it R9 has an 8ohm resister or if R10 has the resistor.

also they are using:

/* Include the U8glib library */
#include "U8glib.h"

in their sketches.

This appears to be the display you have. The pins are documented in the pdf:

http://www.digole.com/images/file/Digole_12864_LCD.pdf

ted:
I have a program which has LCD pin description and message which should be displayed. So I add a LiquidCrystal.h library.
I think I should declare the type of used LCD and add the command to run the LCD program.
Please help me with that.
What I should with R/W and PBS pins ?

Please if you are going to post code post all the code and not just snippets.

The code you posted gives no context.
What libraries are being used?
What include files are being pulled in?

bitbank: This appears to be the display you have. The pins are documented in the pdf:

http://www.digole.com/images/file/Digole_12864_LCD.pdf

please use the url tags when posting links.

The code is very long that why I put only the parts related to LCD. I run tradicional " hello world " program from arduino examples and it is working ok, Ihave 5V pulses coming from Arduino uno to LCD, no such pulses when I run long program on any pin. When I remove R9 the screen is black.

When I try to put all program I have this message

The message exceeds the maximum allowed length (9000 characters).

ted: The code is very long that why I put only the parts related to LCD. I run tradicional " hello world " program from arduino examples and it is working ok, Ihave 5V pulses coming from Arduino uno to LCD, no such pulses when I run long program on any pin. When I remove R9 the screen is black.

When I try to put all program I have this message

The message exceeds the maximum allowed length (9000 characters).

the forum will not allow you to post the code because of length? bundle the code up in a zip archive and attach it.

that sounds like the Arduino UNO is running out of space.

The long sketch may be to large for the Arduino UNO. Do you have other Arduino Boards you could try it with? Something with more memory.

When you attempt to run the long code with the Arduino UNO does it compile without errors in Arduino IDE? What version of Arduino IDE are you using?

Turn on verbose output in Preferences.

|500x395

This is the link to original , it's compiling with no errors, generators are working ok, IDE 1.8.3

https://github.com/dc42/arduino/blob/master/MetalDetector/MetalDetector.ino

I think I have to use this program, but I have errors.

LCD_test_2:16: error: ‘prog_uint8_t’ does not name a type

const prog_uint8_t *ptr; // pointer to font table

^

LCD_test_2:98: error: ‘prog_uint8_t’ does not name a type

void bitmap(uint8_t x0, uint8_t y0, uint8_t width, uint8_t height, const prog_uint8_t data);

#include <Arduino.h>
#include <avr/pgmspace.h>
#include <Print.h>

// Enumeration for specifying drawing modes
enum PixelMode
{
  PixelClear = 0,    // clear the pixel(s)
  PixelSet = 1,      // set the pixel(s)
  PixelFlip = 2      // invert the pixel(s)
};

// Struct for describing a font table, always held in PROGMEM
struct LcdFont
{
  const prog_uint8_t *ptr;   // pointer to font table
  uint8_t startCharacter;    // character code (e.g. ASCII) of the first character in the font
  uint8_t endCharacter;      // character code of the last character in the font
  uint8_t height;            // row height in pixels - only this number of pixels will be fetched and drawn - maximum 16 in this version of the sofware
  uint8_t width;             // max character width in pixels (the font table contains this number of bytes or words per character, plus 1 for the active width)  
};

// Class for driving 128x64 graphical LCD fitted wirth ST7920 controller
// This drives the GLCD in serial mode so that it needs just 2 pins.
// Preferably, we use SPI to do the comms.

// Derive the LCD class from the Print class so that we can print stuff to it in alpha mode
class Lcd7920 : public Print
{
public:
  // Construct a GLCD driver.
  //  cPin = clock pin (connects to E pin of ST7920)
  //  dPin = data pin (connects to R/W pin of ST7920)
  // useSpi = true to use hardware SPI. If true then cPin must correspond to SCLK, dPin must correspond to MOSI, and SS must be configured as an output.
  Lcd7920(uint8_t cPin, uint8_t dPin, bool useSpi);    // constructor
  
  // Write a single character in the current font. Called by the 'print' functions. Works in both graphic and alphanumeric mode.
  // If in graphic mode, a call to setFont must have been made before calling this.
  //  c = character to write
  // Returns the number of characters written (1 if we wrote it, 0 otherwise)
  virtual size_t write(uint8_t c);                 // write a character

  // Initialize the display. Call this in setup(). If using graphics mode, also call setFont to select initial text font.
  //  gmode = true to use graphics mode, false to use ST7920 alphanumeric mode.
  void begin(bool gmode);
  
  // Select the font to use for subsequent calls to write() in graphics mode. Must be called before calling write() in graphics mode.
  //  newFont = pointer to font descriptor in PROGMEM
  void setFont(const PROGMEM LcdFont *newFont);
  
  // Select normal or inverted text (only works in graphics mode)
  void textInvert(bool b);
  
  // Clear the display. Works in both graphic and alphanumeric mode. Also selects non-inverted text.
  void clear();
  
  // Set the cursor position
  //  r = row. In alphanumeric mode this is text row number. 
  //           In graphics mode it is the number of pixels from the top of the display to the top of the character.
  //  c = column. In alphanumeric mode this must be even (S7920 restriction becasue the characters are double width).
  //              In graphics ode this is the number of pixels from the left hand edge of the display and the left hand edge of the character.
  void setCursor(uint8_t r, uint8_t c);        // 'c' in alpha mode, should be an even column number
  
  // Flush the display buffer to the display. In graphics mode, calls to write, setPixel, line and circle will not be committed to the display until this is called.
  void flush();
  
  // Set, clear or invert a pixel
  //  x = x-coordinate of the pixel, measured from left hand edge of the display
  //  y = y-coordinate of the pixel, measured down from the top of the display
  //  mode = whether we want to set, clear or invert the pixel
  void setPixel(uint8_t x, uint8_t y, PixelMode mode);
  
  // Read a pixel. Returns true if the pixel is set, false if it is clear.
  //  x = x-coordinate of the pixel, measured from left hand edge of the display
  //  y = y-coordinate of the pixel, measured down from the top of the display
  bool readPixel(uint8_t x, uint8_t y);
  
  // Draw a line.
  //  x0 = x-coordinate of one end of the line, measured from left hand edge of the display
  //  y0 = y-coordinate of one end of the line, measured down from the top of the display
  //  x1, y1 = coordinates of the other end od the line
  //  mode = whether we want to set, clear or invert each pixel
  void line(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, PixelMode mode);
  
  // Draw a circle
  //  x0 = x-coordinate of the centre, measured from left hand edge of the display
  //  y0 = y-coordinate of the centre, measured down from the top of the display
  //  redius = radius of the circle in pixels
  //  mode = whether we want to set, clear or invert each pixel
  void circle(uint8_t x0, uint8_t y0, uint8_t radius, PixelMode mode);
  
  // Draw a bitmap
  //  x0 = x-coordinate of the top left, measured from left hand edge of the display. Currently, must be a multiple of 8.
  //  y0 = y-coordinate of the top left, measured down from the top of the display
  // width = width of bitmap in pixels. Currently, must be a multiple of 8.
  // rows = height of bitmap in pixels
  // data = bitmap image in PROGMEM, must be ((width/8) * rows) bytes long
  void bitmap(uint8_t x0, uint8_t y0, uint8_t width, uint8_t height, const prog_uint8_t data[]);
  
private:
  bool gfxMode;
  bool extendedMode;
  bool useSpi;
  bool textInverted;
  uint8_t clockPin, dataPin;
  uint16_t lastCharColData;                   // data for the last non-space column, used for kerning
  uint8_t row, column;
  uint8_t startRow, startCol, endRow, endCol; // coordinates of the dirty rectangle
  uint8_t image[(128 * 64)/8];                // image buffer, 1K in size (= half the RAM of the Uno)
  const PROGMEM struct LcdFont *currentFont;  // pointer to descriptor for current font
  
  void sendLcdCommand(uint8_t command);
  void sendLcdData(uint8_t data);
  void sendLcd(uint8_t data1, uint8_t data2);
  void sendLcdSlow(uint8_t data);
  void commandDelay();
  void setGraphicsAddress(unsigned int r, unsigned int c);
  void ensureBasicMode();
  void ensureExtendedMode();
};

ted: I think I have to use this program, but I have errors.

LCD_test_2:16: error: 'prog_uint8_t' does not name a type

const prog_uint8_t *ptr; // pointer to font table

^

LCD_test_2:98: error: 'prog_uint8_t' does not name a type

void bitmap(uint8_t x0, uint8_t y0, uint8_t width, uint8_t height, const prog_uint8_t data[]);

In looking at arduino-1.8.5/hardware/tools/avr/avr/include/avr/pgmspace.h the typedef of prog_uint8_t is deprecated. That code is old and not up to date. Where did you get that code?

Why must you use that code?

Have you tried the U8glib library?

You should update Arduino IDE to 1.8.5

Hmmm... this type of display is covered by u8g2. In fact I have used such a display as an example here: https://github.com/olikraus/u8g2/wiki/setup_tutorial.

Install u8g2 via the Arduino Libarary manager.

Oliver

Thanks guys for any advices. I was trying to use what was sugested by author of the program.

"Lcd7920 This is a simple library to drive 128x64 graphic LCDs based on the ST7920 chip in serial mode, thereby using only two Arduino pins (preferably the MOSI and SCLK pins to get best speed). It is smaller but less comprehensive than U8glib."

"Install u8g2 via the Arduino Libarary manager. " - I was trying that , but the pins used there are different, so I switch to LCD 16X2 - I need only two lines. In orginal examples for it I changed the pins as they are in that program and inplemented it to author program (dc42 program). After those changes I have "Hallo World " in dc 42 program. I want to disable - //lcd.print("hello, world!"); in void setup() and activate everything below that. I have shortened the program so that it can be put in a post.

I am confused how to do that because in LCD 16X2 program - lcd.print("hello, world!"); - is in void setup () but in DC 42- lcd.print - is in void loop()

LCD 16X2 program

/*
  LiquidCrystal Library - Hello World

 Demonstrates the use a 16x2 LCD display.  The LiquidCrystal
 library works with all LCD displays that are compatible with the
 Hitachi HD44780 driver. There are many of them out there, and you
 can usually tell them by the 16-pin interface.

 This sketch prints "Hello World!" to the LCD
 and shows the time.

  The circuit:
 * LCD RS pin to digital pin 12
 * LCD Enable pin to digital pin 11
 * LCD D4 pin to digital pin 5
 * LCD D5 pin to digital pin 4
 * LCD D6 pin to digital pin 3
 * LCD D7 pin to digital pin 2
 * LCD R/W pin to ground
 * LCD VSS pin to ground
 * LCD VCC pin to 5V
 * 10K resistor:
 * ends to +5V and ground
 * wiper to LCD VO pin (pin 3)

 Library originally added 18 Apr 2008
 by David A. Mellis
 library modified 5 Jul 2009
 by Limor Fried (http://www.ladyada.net)
 example added 9 Jul 2009
 by Tom Igoe
 modified 22 Nov 2010
 by Tom Igoe
 modified 7 Nov 2016
 by Arturo Guadalupi

 This example code is in the public domain.

 http://www.arduino.cc/en/Tutorial/LiquidCrystalHelloWorld

*/

// include the library code:
#include <LiquidCrystal.h>

// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 6, en = 7, d4 = 10, d5 = 11, d6 = 12, d7 = 13;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

void setup() {
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("hello, world!");
}

void loop() {
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  lcd.print(millis() / 1000);
}

Shorted DC42 program.

// Induction balance metal detector

// We run the CPU at 16MHz and the ADC clock at 1MHz. ADC resolution is reduced to 8 bits at this speed.

// Timer 1 is used to divide the system clock by about 256 to produce a 62.5kHz square wave. 
// This is used to drive timer 0 and also to trigger ADC conversions.
// Timer 0 is used to divide the output of timer 1 by 8, giving a 7.8125kHz signal for driving the transmit coil.
// This gives us 16 ADC clock cycles for each ADC conversion (it actually takes 13.5 cycles), and we take 8 samples per cycle of the coil drive voltage.
// The ADC implements four phase-sensitive detectors at 45 degree intervals. Using 4 instead of just 2 allows us to cancel the third harmonic of the
// coil frequency.

// Timer 2 will be used to generate a tone for the earpiece or headset.

// Other division ratios for timer 1 are possible, from about 235 upwards.

// Wiring:
// Connect digital pin 4 (alias T0) to digital pin 9
// Connect digital pin 5 through resistor to primary coil and tuning capacitor
// Connect output from receive amplifier to analog pin 0. Output of receive amplifier should be biased to about half of the analog reference.
// When using USB power, change analog reference to the 3.3V pin, because there is too much noise on the +5V rail to get good sensitivity.

#define TIMER1_TOP  (249)        // can adjust this to fine-tune the frequency to get the coil tuned (see above)

#define USE_3V3_AREF  (1)        // set to 1 of running on an Arduino with USB power, 0 for an embedded atmega28p with no 3.3V supply available

// include the library code:
#include <LiquidCrystal.h>

// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 6, en = 7, d4 = 10, d5 = 11, d6 = 12, d7 = 13;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);



// Digital pin definitions
// Digital pin 0 not used, however if we are using the serial port for debugging then it's serial input
const int debugTxPin = 1;        // transmit pin reserved for debugging
const int encoderButtonPin = 2;  // encoder button, also IN0 for waking up from sleep mode
const int earpiecePin = 3;       // earpiece, aka OCR2B for tone generation
const int T0InputPin = 4;
const int coilDrivePin = 5;
const int LcdRsPin = 6;
const int LcdEnPin = 7;
const int LcdPowerPin = 8;       // LCD power and backlight enable
const int T0OutputPin = 9;
const int lcdD0Pin = 10;
const int lcdD1Pin = 11;         // pins 11-13 also used for ICSP
const int LcdD2Pin = 12;
const int LcdD3Pin = 13;

// Analog pin definitions
const int receiverInputPin = 0;
const int encoderAPin = A1;
const int encoderBpin = A2;
// Analog pins 3-5 not used

//////////////////////////////////////////////////////////////////////////                  
#1   not related to LCD contents
//////////////////////////////////////////////////////////////////////////
void setup()
{

 // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  //lcd.print("hello, world!");


  ////////////////////////////////////////////////////////
#2 not related to LCD contents
  ///////////////////////////////////////////////////////
  
  Serial.begin(19200); 
}

// Timer 0 overflow interrupt. This serves 2 purposes:
// 1. It clears the timer 0 overflow flag. If we don't do this, the ADC will not see any more Timer 0 overflows and we will not get any more conversions.
// 2. It increments the tick counter, allowing is to do timekeeping. We get 62500 ticks/second.
//////////////////////////////////////////////////////////
#3 not related to LCD contents
/////////////////////////////////////////////////////////

void loop()
{
  while (!sampleReady) {}
  uint32_t oldTicks = ticks;
  
  if (digitalRead(encoderButtonPin) == LOW)
  {
    // Calibrate button pressed. We save the current phase detector outputs and subtract them from future results.
    // This lets us use the detector if the coil is slightly off-balance.
    // It would be better to everage several samples instead of taking just one.
    for (int i = 0; i < 4; ++i)
    {
      calib[i] = averages[i];
    }
    sampleReady = false;
    Serial.print("Calibrated: ");
    for (int i = 0; i < 4; ++i)
    {
      Serial.write(' ');
      Serial.print(calib[i]);
    }
    Serial.println();
  }
  else
  { 
    /////////////////////////////////////////////////////
#4 not related to LCD contents
     ////////////////////////////////////////////////////
    }
        
    // For diagnostic purposes, print the individual bin counts and the 2 indepedently-calculated gains and phases                                                        
    Serial.print(misses);
    Serial.write(' ');
    
    if (bin0 >= 0.0) Serial.write(' ');
    Serial.print(bin0, 2);
    Serial.write(' ');
    if (bin1 >= 0.0) Serial.write(' ');
    Serial.print(bin1, 2);
    Serial.write(' ');
    if (bin2 >= 0.0) Serial.write(' ');
    Serial.print(bin2, 2);
    Serial.write(' ');
    if (bin3 >= 0.0) Serial.write(' ');
    Serial.print(bin3, 2);
    Serial.print("    ");
    Serial.print(amp1, 2);
    Serial.write(' ');
    Serial.print(amp2, 2);
    Serial.write(' ');
    if (phase1 >= 0.0) Serial.write(' ');
    Serial.print(phase1, 2);
    Serial.write(' ');
    if (phase2 >= 0.0) Serial.write(' ');
    Serial.print(phase2, 2);
    Serial.print("    ");
    
    // Print the final amplitude and phase, which we use to decide what (if anything) we have found)
    if (ampAverage >= 0.0) Serial.write(' ');
    Serial.print(ampAverage, 1);
    Serial.write(' ');
    if (phaseAverage >= 0.0) Serial.write(' ');
    Serial.print((int)phaseAverage);
    
    // Decide what we have found and tell the user
    if (ampAverage >= threshold)
    {
      // When held in line with the centre of the coil:
      // - non-ferrous metals give a negative phase shift, e.g. -90deg for thick copper or aluminium, a copper olive, -30deg for thin alumimium.
      // Ferrous metals give zero phase shift or a small positive phase shift.
      // So we'll say that anything with a phase shift below -20deg is non-ferrous.
      if (phaseAverage < -20.0)
      {
        Serial.print(" Non-ferrous");
      }
      else
      {
        Serial.print(" Ferrous");
      }
      float temp = ampAverage;
      while (temp > threshold)
      {
        Serial.write('!');
        temp -= (threshold/2);
      }
    }   
    Serial.println();
   }
  while (ticks - oldTicks < 16000)
  {
  }
}

ted:

You do not have a 16x2 display and cannot use that Library with the display that you do have.

The U8g2 library is what you need to use.

If you do not read nor understand what we are writing tell us.

You are ignoring questions and suggestions.

Did you upgrade Arduino IDE to 1.8.5?

I do not know what more any of us can do for you.
I honestly do not know.

I have LCD16X2 and what I described in post #13 was based on that LCD.
I was trying U8g2 and “Hello World” is working with LCD 128x64 7920 but have problem with the pins arrangement, some of the pins are already used/ocupated by DC42 program.
I swiched to LCD16X2 because I was used it before.
IDE to 1.8.5 - I have not updated yet, I dont think that the Issue is there.

ted: I have LCD16X2 and what I described in post #13 was based on that LCD. I was trying U8g2 and "Hello World" is working with LCD 128x64 7920 but have problem with the pins arrangement, some of the pins are already used/ocupated by DC42 program. I swiched to LCD16X2 because I was used it before. IDE to 1.8.5 - I have not updated yet, I dont think that the Issue is there.

Arduino IDE is an issue. I have Arduino IDE 1.8.5 and I know I have newer versions of libraries than Arduino IDE 1.8.3.

I cannot help you since we have different Arduino IDE environments.

If you want help you need to upgrade to Arduino IDE 1.8.5

Go back to the very beginning.

What is it exactly that you are wanting to do? What is it exactly that you want help with?

DC42 is an Arduino Sketch for an induction metal detector.

What type of 16x2 LCD do you have? Post a photograph of the back of the 16x2 LCD

I have clicked on 1.8.5 and it’s appeared 1.8.6
I want to have display to work as on the link.

I need help to implement LCD program to DC 42 sketch.
Thank You for your support