Как переработать скетч (добавить вывод данных на дисплей)?
- Войдите на сайт для отправки комментариев
Чт, 21/04/2016 - 15:28
Есть рабочий скетч вывода данных с DHT11 на монитор порта:
// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain
#include "DHT.h"
#define DHTPIN 2 // what pin we're connected to
// Uncomment whatever type you're using!
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22 (AM2302)
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
// Connect pin 1 (on the left) of the sensor to +5V
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
Serial.println("DHTxx test!");
dht.begin();
}
void loop() {
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
float t = dht.readTemperature();
// check if returns are valid, if they are NaN (not a number) then something went wrong!
if (isnan(t) || isnan(h)) {
Serial.println("Failed to read from DHT");
} else {
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t);
Serial.println(" *C");
}
}
Нужно дописать его, дабы данные с DHT выводились не только на монитор порта, но и на LCD (2004).
Как вывести заданную информацию на дисплей я то понимаю, только вот как его настроить, инициализировать.
Читали про это? http://www.arduino.cc/en/Reference/LiquidCrystal
Нашли библиотеку?
Запускали примеры?
Тогда самое время это сделать.
Тут дисплей напрямую подключают, а я по шине I2C. Однако немного разобрался.
Читали про это? http://www.arduino.cc/en/Reference/LiquidCrystal
Выдаёт ошибку:
Вот код:
//#include <LiquidCrystal_I2C.h> // Example testing sketch for various DHT humidity/temperature sensors // Written by ladyada, public domain #include "DHT.h" #define DHTPIN 2 // what pin we're connected to // Uncomment whatever type you're using! #define DHTTYPE DHT11 // DHT 11 //#define DHTTYPE DHT22 // DHT 22 (AM2302) //#define DHTTYPE DHT21 // DHT 21 (AM2301) // Connect pin 1 (on the left) of the sensor to +5V // Connect pin 2 of the sensor to whatever your DHTPIN is // Connect pin 4 (on the right) of the sensor to GROUND // Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor DHT dht(DHTPIN, DHTTYPE); LiquidCrystal_I2C lcd(0x27, 20, 4); void setup() { Serial.begin(9600); Serial.println("DHTxx test!"); dht.begin(); lcd.begin(20, 4); lcd.setCursor(0, 1); lcd.print("Hello Dmitry"); // Print a message to the LCD. } void loop() { lcd.clear(); lcd.setCursor(0, 1); // Reading temperature or humidity takes about 250 milliseconds! // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor) float h = dht.readHumidity(); float t = dht.readTemperature(); // check if returns are valid, if they are NaN (not a number) then something went wrong! if (isnan(t) || isnan(h)) { Serial.println("Failed to read from DHT"); } else { Serial.print("Humidity: "); Serial.print(h); Serial.print(" %\t"); Serial.print("Temperature: "); Serial.print(t); Serial.println(" *C"); } }DiMan, теперь открывай файл LiquidCrystal_I2C.h и смотри как там объявлен метод begin()...
DiMan, теперь открывай файл LiquidCrystal_I2C.h и смотри как там объявлен метод begin()...
Издеваетесь.))))
DiMan, открывайте примеры из библиотеки и по образу и подобию.))))
Сразу подключил библиотеку LiquidCrystal_I2C.
Заглянул в пример, там настраивается дисплей. Мой вариант:
В сетапе вкл. дисплей:
Прописываем параметры подсветки:
Далее в примере высвечивается хеллоу ворд ("lcd.print("Hello, world!");"), а у меня должно быть высвечено приветсвие и в лупе крутится снятие показателей с датчика DHT11:
lcd.print("Hello Dmitry");Далее loop. Чистим дисплей:
Выставляем курсор, выводим название "температура", показатели температуры с DHT и знак цельсия:
lcd.setCursor(0, 0); lcd.print("Tem: "); lcd.print(t); lcd.print("C ");lcd.setCursor(0, 1); lcd.print("Hum: "); lcd.print(h); lcd.print("%");Вуаля! Не работает!
Ошибка:
//недоскетч аля Димас #include <LiquidCrystal_I2C.h> // Example testing sketch for various DHT humidity/temperature sensors // Written by ladyada, public domain #include "DHT.h" #define DHTPIN 2 // what pin we're connected to // Uncomment whatever type you're using! #define DHTTYPE DHT11 // DHT 11 //#define DHTTYPE DHT22 // DHT 22 (AM2302) //#define DHTTYPE DHT21 // DHT 21 (AM2301) // Connect pin 1 (on the left) of the sensor to +5V // Connect pin 2 of the sensor to whatever your DHTPIN is // Connect pin 4 (on the right) of the sensor to GROUND // Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor DHT dht(DHTPIN, DHTTYPE); LiquidCrystal_I2C lcd(0x27, 20, 4); void setup() { Serial.begin(9600); Serial.println("DHTxx test!"); dht.begin(); lcd.begin(); lcd.backlight(); lcd.print("Hello Dmitry"); } void loop() { lcd.clear(); // Reading temperature or humidity takes about 250 milliseconds! // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor) float h = dht.readHumidity(); float t = dht.readTemperature(); // check if returns are valid, if they are NaN (not a number) then something went wrong! if (isnan(t) || isnan(h)) { Serial.println("Failed to read from DHT"); } else { Serial.print("Humidity: "); Serial.print(h); Serial.print(" %\t"); Serial.print("Temperature: "); Serial.print(t); Serial.println(" *C"); lcd.setCursor(0, 0); lcd.print("Tem: "); lcd.print(t); lcd.print("C "); lcd.setCursor(0, 1); lcd.print("Hum: "); lcd.print(h); lcd.print("%"); } }LiquidCrystal_I2C.cpp:35: error: 'Wire' was not declared in this scope
Теперь открываем LiquidCrystal_I2C.cpp и смотрим метод begin(), он начинается так:
void LiquidCrystal_I2C::begin() { Wire.begin(); ...На этот Wire в строке 35 и ругается компилятор. В 4 строке LiquidCrystal_I2C.cpp подключен Wire.h
Ищешь wire.cpp и смотришь как там объявлена переменная Wire, вполне возможно она там названа по другому.
В общем, без понимания С++ тебе будет тяжело.
cpp? Вы шутите? 11кл, мы даже в паскале программ не пишем (только сейчас пойдут простые вроде "рассчитать периметр квадрата" и пр.)
В общем, без понимания С++ тебе будет тяжело.
cpp? Вы шутите? 11кл, мы даже в паскале программ не пишем (только сейчас пойдут простые вроде "рассчитать периметр квадрата" и пр.)
И что такого? Разве теперь запрещено читать литературу сверх программы?
#include "Wire.h" надо добавить толи перед толи после подключения #include "LiquidCristall_I2C" , ни помню. Само оно не подключается. Тоже наступал на эти грабли. :)
толи перед толи после подключения #include "LiquidCristall_I2C"
Перед.
"Page not found" можно найти где угодно.
А вообще - смотрите заголовочный файл библиотеки LiquidCrystal_I2C.h - все основные сведения содержатся там. А если нужны тонкости - тогда LiquidCrystal_I2C.cpp