Ubuntu Suomen keskustelualueet
Muut alueet => Muut käyttöjärjestelmät ja Linux-jakelut => Aiheen aloitti: ubu hui - 15.03.16 - klo:17.05
-
Hei
Työn alla on arduinopohjainen patterilla toimiva lämpömittari.
Eipä oikein toimi niinkuin haluaisin.
Ilmoittaa kyllä serial porttiin lämpötilan vaan ei näyttöön, näytössä on vain omituisen näköisiä harakanvarpaita.
#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal.h>
// LCD=======================================================
//initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
#define LCD_WIDTH 8
#define LCD_HEIGHT 2
// Data wire is plugged into pin 2 on the Arduino
#define ONE_WIRE_BUS 2
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
void setup(void)
{
Serial.begin(9600);
lcd.begin(LCD_WIDTH, LCD_HEIGHT, 1);
lcd.setCursor(1, 0);
// lcd.print("DS1820"); jos ottaa // pois niin printtaa näytölle tekstin oikein
delay(550);
// Start up the library
sensors.begin(); // IC Default 9 bit. If you have troubles consider upping it 12. Ups the delay giving the IC more time to process the temperature measurement
}
void loop(void)
{
// call sensors.requestTemperatures() to issue a global temperature
// request to all devices on the bus
//Serial.print("Requesting temperatures...");
sensors.requestTemperatures(); // Send the command to get temperatures
lcd.print(sensors.getTempCByIndex(0)); // printtaa näytölle harakanvarpaita
Serial.print(sensors.getTempCByIndex(0)); // jos pelkästään tämä rivi niin prittaa lämpötilan seriaaliin yhdelle riville
Serial.println(" "); // kun tämä on mukana printtaa lämpötilan alekkain seriaaliin
}
Mitkä menee pieleen?
Näyttö on mielestäni oikein kytketty, testasin ”hello word”- koodinpätkällä.
(Tosin näyttö ei olekaan 16x2 vaan 8x2, jossa vielä rivit ovat peräkkäin.)
Lämpötila printtautuu seriaaliin, joten anturikin toimii.
Olisiko vinkkejä asiaan, en ainakaan vielä ole löytänyt netistä apuja.
Nöyrimmästi kyselee,
ubu hui
-
Saatko tämän demon toimimaan ?
/*
LiquidCrystal Library - display() and noDisplay()
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 uses the
display() and noDisplay() functions to turn on and off
the display.
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
* 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
This example code is in the public domain.
http://arduino.cc/en/Tutorial/LiquidCrystalDisplay
*/
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
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() {
// Turn off the display:
lcd.noDisplay();
delay(500);
// Turn on the display:
lcd.display();
delay(500);
}
Lisäksi olethan kytkenyt näytöstä D0-D3 maahan, kuten myös R/W-pinnin näytöstä maahan ?
-
lcd.print(sensors.getTempCByIndex(0)); // printtaa näytölle harakanvarpaita
Entä jos muuttaa kyseisen rivin seuraavaksi ?
char test[20];
...
lcd.print(floatToString(test,sensors.getTempCByIndex(0),2,7,true)); // printtaa näytölle harakanvarpaita
...
googlaamalla löydetty, joten ei toimintatakuuta.
-
Joo, löytyi lisää tietoa...
file:///usr/share/doc/arduino-core/reference/LiquidCrystalPrint.html
Eli lyhyesti lcd.print ei tunne liukulukuja.
-
Kiitos vastauksista.
Näytön saa täyteen omaa tekstiä-->testattu koeohjelmalla.
char test[20];
...
lcd.print(floatToString(test,sensors.getTempCByIndex(0),2,7,true)); // printtaa näytölle harakanvarpaita
Herjaa määrittelystä (?) ei suostu kääntymään.
Eli lyhyesti lcd.print ei tunne liukulukuja.
Pitääköhän liukuluku muuttaa tekstiksi tai jotain, koska kuitenkin joku on saanut lämpötilan näytölle?
http://www.open-electronics.org/how-to-make-a-weather-station-with-arduino/ (http://www.open-electronics.org/how-to-make-a-weather-station-with-arduino/)
Heti kun ehdin, yritän perehtyä linkin koodiin. (Työnteko haittaa harrastuksia pahasti).
-ubu hui
-
Pitääköhän liukuluku muuttaa tekstiksi tai jotain, koska kuitenkin joku on saanut lämpötilan näytölle?
http://www.open-electronics.org/how-to-make-a-weather-station-with-arduino/ (http://www.open-electronics.org/how-to-make-a-weather-station-with-arduino/)
Tuolla on käytetty lcd.print-funktiota, joka hyväksyy liukuluvun ja toisena parametrina esitettävien desimaalien lukumäärän:
lcd.setCursor(0, 0);
lcd.print(STAMPA_T,1); //SHOW ONLY THE FIRST DECIMAL
lcd.write((uint8_t)0); //PRINT "°C" CHARACTER (IDE 1.0.1)
delay(200);
Eli kokeile esimerkiksi näin:
lcd.setCursor(0, 0);
lcd.print(sensors.getTempCByIndex(0), 1)
delay(200)
-
lcd.setCursor(0, 0);
lcd.print(sensors.getTempCByIndex(0), 1)
delay(200)
Ei toiminut tämä.
Päädyin kokeilemaan karsittua koodia täältä
http://www.open-electronics.org/how-to-make-a-weather-station-with-arduino/ (http://www.open-electronics.org/how-to-make-a-weather-station-with-arduino/)
Tuuppaa lämpötilan lcd-näyttöön, toki tässä vaiheessa vaatii pientä kalibrointia.
//CODE WRITTEN BY HARDWARE MAKERS www.hwmakers.eu
//http://www.open-electronics.org/how-to-make-a-weather-station-with-arduino/ //koko alkuperäinen koodi
// required libraries
#include <Wire.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
// VARIABLES DEFINITION AND INITIALIZATION
#define TEMP 2 //TEMPERATURE ACQUISITION ON ANALOG PIN 2
float val = 0.0;
float T = 0.0;
float VADC = 2.64; //alunperin 5 jolloin näytössä 89C, 2.64 jolloin näytössä 23.0C(vertailumittarissa 22.9C)
int DPR = 0;
int RHCORR = 0;
int PCORR = 0;
int TCORR = 0;
double STAMPA_T = 0;
byte degree[8] = { // CHARACTER "°C" DEFINITION
B10111,
B01000,
B10000,
B10000,
B10000,
B01000,
B00111,
};
void setup() {
Serial.begin(9600);
lcd.begin(8, 2);
lcd.createChar(0, degree); // "°C" SYMBOL
Wire.begin();
}
void loop() {
Serial.println();
// SERIAL METEO OUTPUT
STAMPA_T = (temp());
Serial.print("TEMPERATURA ");
Serial.write(176);
Serial.print("C; ");
// LCD METEO OUTPUT
lcd.setCursor(0, 0);
lcd.print(STAMPA_T, 1); //SHOW ONLY THE FIRST DECIMAL yhdellä desimaalilla
lcd.write((uint8_t)0); //PRINT "°C" CHARACTER (IDE 1.0.1)astemerkki näytölle
delay(750);
}
float temp() {
double nread = 100.0; // NUMBER OF READINGS
double somma = 0.0;
for (int i = 0; i < nread; i++)
{
val = analogRead(TEMP);
T = (((VADC / 1024.0 * val) - 0.5) * 100) + TCORR; //TEMPERATURE
somma += T;
}
delay(250);
return (somma / nread);
}
EDIT: eipä olekaan ratkaistu
ubu hui
-
Päädyin kokeilemaan karsittua koodia täältä
http://www.open-electronics.org/how-to-make-a-weather-station-with-arduino/ (http://www.open-electronics.org/how-to-make-a-weather-station-with-arduino/)
Tuuppaa lämpötilan lcd-näyttöön, toki tässä vaiheessa vaatii pientä kalibrointia.
Tuolla on käytetty analogista anturia ja Arduinon analogisia tuloja lämpötilan lukemiseen. Tämä ei onnistu Dallasin anturien kanssa, jotka ovat digitaalisia ja käyttävät 1-Wire-väylää. Tuo koodi ei siis voi toimia, jos et ole vaihtanut anturia toisenlaiseen.
-
Kiitos huomioista, nuolaisin ennen kuin tipahti :o
Tuolla on käytetty analogista anturia ja Arduinon analogisia tuloja lämpötilan lukemiseen. Tämä ei onnistu Dallasin anturien kanssa, jotka ovat digitaalisia ja käyttävät 1-Wire-väylää. Tuo koodi ei siis voi toimia, jos et ole vaihtanut anturia toisenlaiseen.
Dallasin anturi tosiaan, olin niin onnesta mykkyrällä kun sain jonkin selväkielisen lukeman näyttöön..
Poistin ratkaistu merkinnät.
ubu hui
-
Toimiiko seuraava, ja miten ?
#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal.h>
// LCD=======================================================
//initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
#define LCD_WIDTH 8
#define LCD_HEIGHT 2
// Data wire is plugged into pin 2 on the Arduino
#define ONE_WIRE_BUS 2
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
char test[20];
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
void setup(void)
{
Serial.begin(9600);
lcd.begin(LCD_WIDTH, LCD_HEIGHT, 1);
lcd.setCursor(1, 0);
// lcd.print("DS1820"); jos ottaa // pois niin printtaa näytölle tekstin oikein
delay(550);
// Start up the library
sensors.begin(); // IC Default 9 bit. If you have troubles consider upping it 12. Ups the delay giving the IC more time to process the temperature measurement
}
void loop(void)
{
// call sensors.requestTemperatures() to issue a global temperature
// request to all devices on the bus
//Serial.print("Requesting temperatures...");
sensors.requestTemperatures(); // Send the command to get temperatures
lcd.print(dtostrf(sensors.getTempCByIndex(0),2,7,test)); // printtaa näytölle harakanvarpaita
Serial.print(sensors.getTempCByIndex(0)); // jos pelkästään tämä rivi niin prittaa lämpötilan seriaaliin yhdelle riville
Serial.println(" "); // kun tämä on mukana printtaa lämpötilan alekkain seriaaliin
}
Itselläni kääntyi, mutta en jaksa tehdä kytkentää testatakseni.
-
Kamara, kiitos mielenkiinnosta, kirjoittamasi koodi kääntyi, vaan ei toiminut toivotulla tavalla.
Harakanvarpaita näyttö täyteen ;D Valitettavasti.
Minun viimeisin koodikokeiluni näyttää toimivan halutulla tavalla, näyttää lämmön ja se jopa vaihtuu kun lämmittää anturia näpeissä.. :P
Tosin niinhän minä luulin aikaisemminkin.
EDIT:lämpötila on luvatun 0.5 sisällä verrattuna kalibroituun Flukeen.
Lisäsin vielä ilmanpaineanturin (MPL3115A2) ja kosteusanturin (HIH4000-001) ja nekin onnistuin saamaan näytölle.
Pientä hienosäätöä vielä tarvitaan jotta löydän sopivan päivitysnopeuden näytölle.
Koodi on pitkähkö ja luultavasti sekava mutta jos joku haluaa laitan sen tänne näkyviin.
#include <OneWire.h>
#include <LiquidCrystal.h>
// LCD=======================================================
//initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
#define LCD_WIDTH 8
#define LCD_HEIGHT 2
/* DS18S20 Temperature chip i/o */
OneWire ds(9); // on pin 9
#define MAX_DS1820_SENSORS 1
byte addr[MAX_DS1820_SENSORS][8];
void setup(void)
{
lcd.begin(LCD_WIDTH, LCD_HEIGHT,1);
lcd.setCursor(0,0);
lcd.print("DS1820 Test");
if (!ds.search(addr[0]))
{
lcd.setCursor(0,0);
lcd.print("No more addresses.");
ds.reset_search();
delay(250);
return;
}
if ( !ds.search(addr[1]))
{
lcd.setCursor(0,0);
lcd.print("No more addresses.");
ds.reset_search();
delay(250);
return;
}
}
int HighByte, LowByte, TReading, SignBit, Tc_100, Whole, Fract;
char buf[20];
void loop(void)
{
byte i, sensor;
byte present = 0;
byte data[12];
for (sensor=0;sensor<MAX_DS1820_SENSORS;sensor++)
{
if ( OneWire::crc8( addr[sensor], 7) != addr[sensor][7])
{
lcd.setCursor(0,0);
lcd.print("CRC is not valid");
return;
}
if ( addr[sensor][0] != 0x10)
{
lcd.setCursor(0,0);
lcd.print("Device is not a DS18S20 family device.");
return;
}
ds.reset();
ds.select(addr[sensor]);
ds.write(0x44,1); // start conversion, with parasite power on at the end
delay(1000); // maybe 750ms is enough, maybe not
// we might do a ds.depower() here, but the reset will take care of it.
present = ds.reset();
ds.select(addr[sensor]);
ds.write(0xBE); // Read Scratchpad
for ( i = 0; i < 9; i++)
{ // we need 9 bytes
data[i] = ds.read();
}
LowByte = data[0];
HighByte = data[1];
TReading = (HighByte << 8) + LowByte;
SignBit = TReading & 0x8000; // test most sig bit
if (SignBit) // negative
{
TReading = (TReading ^ 0xffff) + 1; // 2's comp
}
Tc_100 = (TReading*100/2);
Whole = Tc_100 / 100; // separate off the whole and fractional portions
Fract = Tc_100 % 100;
sprintf(buf, "%c%d.%d\ ",SignBit ? '-' : '+', Whole, Fract < 10 ? 0 : Fract);//printtaa näytölle etumerkin ja lämpötilan kahdella desimaalilla
// sprintf(buf, "%d:%c%d.%d\337C ",sensor,SignBit ? '-' : '+', Whole, Fract < 10 ? 0 : Fract);// sensori:etumerkki, lämpötila kahdella desimaalilla
lcd.setCursor(0,sensor%LCD_HEIGHT);
lcd.print(buf);
}
}