ЖК-дисплей не работает в смоделированной среде

Я использую Tinkercad, и, поскольку я впервые программирую ЖК-дисплей, я просто скопировал процедуру подключения контактов и заставил ее работать.

Дело в том, что он просто загорается, ничего не отображая, я пробовал как подключать, так и отключать контакт R / W, но это тоже не работает, ничего не будет отображаться.

Что я пропустил? Остальные функции кода работают нормально.

Изображение схемы:

Изображение схемы

Это код:

#include <LiquidCrystal.h>

const int pin = 0; // analog pin
float celsius = 0, farhenheit =0; // temperature variables
float millivolts; //Millivolts from the sensor
int sensor;

const int G_LED = 13;
const int Y_LED = 12;
LiquidCrystal lcd(10, 9, 5, 4, 3, 2); // Building the LCD


void setup() {
  lcd.begin(16,2);              
  lcd.clear();                  
  lcd.setCursor(0,0);           
  lcd.print("C=");           // "C=", "F=" and "mV" should be printed
  lcd.setCursor(0, 1);       // on the LCD in a column  
  lcd.print("F=");           
  lcd.setCursor(0, 2);            
  lcd.print("mV=");
  
  pinMode(G_LED, OUTPUT);
  pinMode(Y_LED, OUTPUT);

  Serial.begin(9600); 
}

void loop() {
  sensor = analogRead(pin);                    // Reading the value from the LM35 sensor using the A0 ingress
  millivolts = (sensor / 1023.0) * 5000;       // Converting the value in a number that indicates the millivolts
  celsius = ((sensor * 0.00488) - 0.5) / 0.01; // Celsius value (10 mV for each degree, 0°=500mV)
  farhenheit = celsius * 1.8 + 32;             // Fahrenheit value
 
  lcd.setCursor(4, 2);                         // Set the cursor at the right of "mV="
  lcd.print(millivolts);                       // Print the mV value
  lcd.setCursor(4, 0);                         // Same here for °C and °F
  lcd.print(celsius);
  lcd.setCursor(4, 1);

  Serial.print(farhenheit);

  if (millivolts < 700) {    // Green LED is on when the temperature is under or equal to 20° 
  // if (celsius < 20) {     // Alternative
    analogWrite(G_LED, 255);
    analogWrite(Y_LED, 0); }
  else {
    analogWrite(G_LED, 0);
    analogWrite(Y_LED, 255); // Yellow LED is on when the temperature is above of 20°C
  }  
  delay(1000);
}

person Wandering    schedule 20.12.2020    source источник
comment
Вы пробовали эту распиновку в реальной жизни? также, пожалуйста, дайте ссылку на эскиз Tinker-CAD.   -  person James Barnett    schedule 24.12.2020
comment
@JamesBarnett нет, я еще не пробовал, у меня даже нет материалов, вот ссылка на tinkercad: tinkercad.com/things/crc5uG2Br5x   -  person Wandering    schedule 26.12.2020
comment
Я думаю, что проблема связана с тем, что вы использовали сложную в использовании распиновку, попробуйте более традиционный метод. (P.S. Вы не настроили датчики в Tinkercad). Отвечу на вопрос, когда исправлю проблему или найду альтернативу).   -  person James Barnett    schedule 27.12.2020


Ответы (1)


Исправить. Я не смог найти ошибку, но подозреваю, что она возникла из-за странного расположения соединений. Вы также пытались установить курсор на строку 3, но на ЖК-дисплее, который вы использовали, не было 3 строк, это был 16x2 LCD.

Что я сделал. Итак, я переделал весь проект, подключил новый ЖК-дисплей, на этот раз с цифровым контрастом, чтобы его можно было динамически изменять. Я также позаботился о том, чтобы включить датчик, который вы использовали в своем последнем проекте. В целом проект представляет собой Arduino, управляющую ЖК-дисплеем и выводящую температуру в градусах Фаренгейта и милливольтах.

Вот ссылка на проект (Tinkercad).

Код:

#include <LiquidCrystal.h> 
// Adds the liquid crystal lib

int contrast = 40; // Set the contrast of the LCD
LiquidCrystal lcd (12, 11, 5, 4, 3, 2); // Instantiate the LCD

float fahrenheit;
float millivolts;

void setup ()
{
  analogWrite(6, contrast); // Wrjte the contrast to the LCD
  lcd.begin(16, 2); // Init the LCD
}

void loop ()
{
  int sensor = analogRead(0);
  millivolts = (sensor/1023.0)*5000;
  fahrenheit = (((sensor*0.00488)-0.5)/0.01)*1.8+32;
  
  lcd.setCursor(0, 0); 
  lcd.print("Temp(F):");
  lcd.setCursor(11, 0);
  lcd.print(fahrenheit);
  
  lcd.setCursor(0, 1);
  lcd.print("Volts(mV):");
  lcd.setCursor(12, 1);
  lcd.print(millivolts);
}

Диаграмма Диаграмма

person James Barnett    schedule 26.12.2020