Hallo liebe Arduino Gemeinde,
ich versuche seit Tagen krampfhaft einen Dallas 18B20 auszulesen und den Temperaturwert auf dem Sure Electronics 24x16 Dot Matrix Modul auszugeben.
Momentaner Stand:
Auslesen des 18B20 und serielles senden der Werte an den PC funktionieren.
Ausgabe von Texten auf dem Sure Display funktioniert.
Was ich allerdings nicht hinbekomme, den Ausgelesenen Temp.wert
vom 18B20 auf dem Display anzuzeigen.
Ich muss zugeben das ich noch nicht so richtig in der Materie drinn steck, also hab ich kurzer Hand 2 Beispiele zu einem zusammengewürfelt. Bis auf ein kleines Timing Problem beim Auslesen des 18B20 läuft das auch recht gut zusammen.
Aber ich bekomme es einfach nich gebacken den Messwert auszugebebn :(:(
ich hoffe ihr könnt mir helfen.
/*
Copyright (C) 2010 Adam Thomas
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program.
*/
#include <ht1632.h>
#include "font.h"
#include <stdlib.h>
#include <MHV_io_ArduinoDuemilanove328p.h>
#include <DallasTemperature.h>
DallasTemperature tempSensor; // You may instantiate as many copies as you require.
void * operator new(size_t size);
void operator delete(void * ptr);
void * operator new(size_t size) {
return malloc(size);
}
void operator delete(void * ptr) {
free(ptr);
}
uint8_t revbits(uint8_t arg) {
uint8_t result=0;
if (arg & (_BV(0))) result |= _BV(7);
if (arg & (_BV(1))) result |= _BV(6);
if (arg & (_BV(2))) result |= _BV(5);
if (arg & (_BV(3))) result |= _BV(4);
if (arg & (_BV(4))) result |= _BV(3);
if (arg & (_BV(5))) result |= _BV(2);
if (arg & (_BV(6))) result |= _BV(1);
if (arg & (_BV(7))) result |= _BV(0);
return result;
}
HT1632 *matrix[4];
uint8_t max_cols = 127;
int16_t col_offset = max_cols;
HT1632 *cur_mat = 0;
char *string = "Aussentemperatur: ";
char *first_char = string;
uint8_t first_char_col = 0;
char *cptr = first_char;
uint8_t char_col = first_char_col;
void setup ()
{
digitalWrite(4,HIGH);
digitalWrite(5,HIGH);
digitalWrite(6,HIGH);
digitalWrite(7,HIGH);
matrix[0] = new HT1632( MHV_ARDUINO_PIN_4,MHV_ARDUINO_PIN_8,MHV_ARDUINO_PIN_10,MHV_ARDUINO_PIN_9, HT1632::pmos_8commons );
matrix[1] = new HT1632( MHV_ARDUINO_PIN_5,MHV_ARDUINO_PIN_8,MHV_ARDUINO_PIN_10,MHV_ARDUINO_PIN_9, HT1632::pmos_8commons, false );
matrix[2] = new HT1632( MHV_ARDUINO_PIN_6,MHV_ARDUINO_PIN_8,MHV_ARDUINO_PIN_10,MHV_ARDUINO_PIN_9, HT1632::pmos_8commons, false );
matrix[3] = new HT1632( MHV_ARDUINO_PIN_7,MHV_ARDUINO_PIN_8,MHV_ARDUINO_PIN_10,MHV_ARDUINO_PIN_9, HT1632::pmos_8commons, false );
Serial.begin(9600);
tempSensor.begin(12); // Data wire is plugged into port 12 on the Arduino
}
void loop ()
{
// Ask the library whether the device is valid
switch(tempSensor.isValid())
{
case 1:
Serial.println("Invalid CRC");
tempSensor.reset(); // Attempts to redetect IC
return;
case 2:
Serial.println("Not a valid device");
tempSensor.reset(); // Attempts to redetect IC
return;
}
// getTemperature returns a float.
float temp = (tempSensor.getTemperature());
Serial.print ("Aussentemperatur: ");
Serial.print (temp);
Serial.print("C");
Serial.println();
char *string = "Temp: ";
char *first_char = string;
uint8_t first_char_col = 0;
char *cptr = first_char;
uint8_t char_col = first_char_col;
for (int i=0; i<100; i++){
uint8_t char_index, char_width;
uint16_t char_offset;
uint8_t first_char_width;
if( *first_char > DEDP105_FONT_FIRST_CHAR + DEDP105_FONT_CHAR_COUNT || *first_char < DEDP105_FONT_FIRST_CHAR ) {
char_index = DEDP105_FONT_CHAR_UNKNOWN;
} else {
char_index = *first_char - DEDP105_FONT_FIRST_CHAR;
}
first_char_width = pgm_read_byte( &dedp105_font_widths[char_index] );
if( col_offset < 0 ) {
if( ++first_char_col > first_char_width ) {
first_char_col = 0;
if( *(++first_char) == '\0' ) {
first_char = string;
col_offset = max_cols;
}
if( *first_char > DEDP105_FONT_FIRST_CHAR + DEDP105_FONT_CHAR_COUNT || *first_char < DEDP105_FONT_FIRST_CHAR ) {
char_index = DEDP105_FONT_CHAR_UNKNOWN;
} else {
char_index = *first_char - DEDP105_FONT_FIRST_CHAR;
}
first_char_width = pgm_read_byte( &dedp105_font_widths[char_index] );
}
}
cptr = first_char;
char_col = first_char_col;
char_width = first_char_width;
char_offset = pgm_read_word(&dedp105_font_offsets[char_index]);
uint8_t pixels;
for( byte col = 0; col < max_cols+1; ++col ) {
switch(col) {
case 0:
case 32:
case 64:
case 96:
if( cur_mat )
cur_mat->deselect();
cur_mat = matrix[(int)(col/32)];
cur_mat->set_mode( HT1632::write_mode );
cur_mat->send_address( 0 );
break;
}
if( cur_mat ) {
pixels = 0;
if( col_offset < col && *cptr != '\0' ) {
if( char_col < char_width ) {
pixels = pgm_read_byte(&dedp105_font[(int)(char_offset + char_col)]);
}
++char_col;
if( char_col > char_width ) {
char_col = 0;
cptr++;
if( *cptr > DEDP105_FONT_FIRST_CHAR + DEDP105_FONT_CHAR_COUNT || *cptr < DEDP105_FONT_FIRST_CHAR ) {
char_index = DEDP105_FONT_CHAR_UNKNOWN;
} else {
char_index = *cptr - DEDP105_FONT_FIRST_CHAR;
}
char_width = pgm_read_byte(&dedp105_font_widths[char_index]);
char_offset = pgm_read_word(&dedp105_font_offsets[char_index]);
}
}
cur_mat->send_data(pixels);
cur_mat->send_data(pixels>>4);
}
}
col_offset--;
delay(100);
}
}
mfg Jens