1
votes

I'm having issues displaying the serial monitor on an lcd. I am not getting any error and the LCD is lit up so I don't think I wired it wrong. I am able to open up the serial monitor/plotter and see in information changing so my other component is also working so the problem must be in the code...

#include <LiquidCrystal.h>

/**
 * LIDARLite I2C Example
 * Author: Garmin
 * Modified by: Shawn Hymel (SparkFun Electronics)
 * Date: June 29, 2017
 * 
 * Read distance from LIDAR-Lite v3 over I2C
 * 
 * See the Operation Manual for wiring diagrams and more information:
 * http://static.garmin.com/pumac/LIDAR_Lite_v3_Operation_Manual_and_Technical_Specifications.pdf
 */

#include <Wire.h>
#include <LIDARLite.h>


const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
// Globals
LIDARLite lidarLite;
int cal_cnt = 0;

void setup()
{
  Serial.begin(9600); // Initialize serial connection to display distance readings

  lidarLite.begin(0, true); // Set configuration to default and I2C to 400 kHz
  lidarLite.configure(0); // Change this number to try out alternate configurations


  lcd.begin(16, 2);
  // initialize the serial communications:
}

void loop()
{
  int dist;

  // At the beginning of every 100 readings,
  // take a measurement with receiver bias correction
  if ( cal_cnt == 0 ) {
    dist = lidarLite.distance();      // With bias correction
  } else {
    dist = lidarLite.distance(false); // Without bias correction
  }

  // Increment reading counter
  cal_cnt++;
  cal_cnt = cal_cnt % 100;

  // Display distance
  Serial.print(dist);
  Serial.println(" cm");

  delay(10);

    // when characters arrive over the serial port...
  if (Serial.available()) { 
    // wait a bit for the entire message to arrive
    delay(100);
    // clear the screen
    lcd.clear();
    // read all the available characters
    while (Serial.available() > 0) {
      // display each character to the LCD
      lcd.write(Serial.read());
    }
  }
}

The LCD should be displaying the changing measurements

The LCD is lit up and I can adjust the back light but I can't get anything to show up.

1

1 Answers

2
votes

Just because the LCD is "lit" doesn't mean it's wired correctly. In fact, the backlighting circuit is usually totally separate from the data and control signals circuits. I would start by checking the assumption that it's wired correctly with a simple command to print a known value to the LCD:

lcd.clear();
lcd.println("TEST");

If this works, then you know the LCD is working and can look elsewhere for the problem.

If this doesn't work, I'd question your assumption that it's hooked up correctly, but if you still get nothing but "blue blocks" then it might be something as simple as your contrast is not correct. It can be tricky getting the contrast and brightness to a good combination for readability. See if your display has a small potentiometer (usually adjustable with a very small Philips-head driver) on the back and carefully adjust the contrast.

Brightness is often changeable through software commands but most LCDs default to high brightness when first booted up.

If changing contrast doesn't work, you may have a real wiring problem and then it really is off-topic for this forum. In that case you should sketch a schematic and post on Electrical Engineering stack.