LCD上的额外符号

时间:2017-12-11 05:32:57

标签: arduino lcd

我试图将激光测距仪的读数显示在LCD上。我可以在上面显示序列号和" cm"但它不断添加两个似乎是中文的符号。这是我使用Arduino的第一个项目,有人可以帮帮我吗?

#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(100);

    // 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());
    }
  }

  delay(100);
  lcd.clear();
  lcd.println(dist);
  lcd.println(" cm");

}

它应该只在液晶显示屏上显示(测量)厘米 相反,我继续得到218--厘米 - , - 是两个中国符号。

image

1 个答案:

答案 0 :(得分:3)

它似乎显示回车符和换行符。

println替换为print