
Po wpisaniu kodu na wyswietlaczu pojawiły się tzw "śmieci" ,które bardzo szybko się przesuwają.Autor tego termometru zastosował u siebie czujnik DS 335Z a ja mam u siebie DS18b20 ,mam tez inny wyświetlacz segmentowy ,w projekcie był jeden 4 cyfrowy a ja mam 2 podwójne połączone ze soba .Próbuje przekształcić oryginalny skech na kod który bedzie czytał temperature z mojego ds18b20 i wyszło coś takiego. Po jego wgraniu wyswietlacz pokazuje temperature ale nie jest to stabilny odczyt ponieważ cyfry dalej dosyć szybko się przesuwają i dodatkowo odczyt wyświetlany jest od prawej strony.Kiedy wchodze w monitor szeregowy to tam temperatura jest pokazywana prawidłowo .Co zrobić aby wyswietlacz przestał mrugać a odczyt był od lewej strony chociażby z jednym miejscem po przecinku.Pomoże ktoś?
Na zdjeciu w taki sposób pokazuje 19 st.C
Kod:
/*
* Temperature Sensor Displayed on 4 Digit 7 segment common anode
* Created by Rui Santos, https://randomnerdtutorials.com
*/
#include &tOneWire.h&t
#include &tDallasTemperature.h&t
OneWire oneWire(A0); //Podłączenie do A0
DallasTemperature sensors(&oneWire); //Przekazania informacji do biblioteki
const int digitPins[4] = {
5,6,7,8}; //4 common anode pins of the display
const int clockPin = 2; //74HC595 Pin 11
const int latchPin = 3; //74HC595 Pin 12
const int dataPin = 4; //74HC595 Pin 14
const int tempPin = A0; //temperature sensor pin
const byte digit[10] = //seven segment digits in bits
{
B00111111, //0
B00000110, //1
B01011011, //2
B01001111, //3
B01100110, //4
B01101101, //5
B01111101, //6
B00000111, //7
B01111111, //8
B01101111 //9
};
int digitBuffer[4] = {
0};
int digitScan = 0, flag=0, soft_scaler = 0;
;
float tempK, tempC, tempF, temp;
void setup(void){
Serial.begin(9600);
sensors.begin(); //Inicjalizacja czujnikow
for(int i=0;i&t4;i++)
{
pinMode(digitPins[i],OUTPUT);
}
pinMode(tempPin, INPUT);
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(tempPin, INPUT);
}
//writes the temperature on display
void updateDisp(){
for(byte j=0; j&t4; j++)
digitalWrite(digitPins[j], LOW);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, B11111111);
digitalWrite(latchPin, HIGH);
delayMicroseconds(0.1);
digitalWrite(digitPins[digitScan], HIGH);
digitalWrite(latchPin, LOW);
if(digitScan==2)
shiftOut(dataPin, clockPin, MSBFIRST, ~(digit[digitBuffer[digitScan]] | B10000000)); //print the decimal point on the 3rd digit
else
shiftOut(dataPin, clockPin, MSBFIRST, ~digit[digitBuffer[digitScan]]);
digitalWrite(latchPin, HIGH);
digitScan++;
if(digitScan&t3) digitScan=0;
}
void loop(void){
// tempK = (((analogRead(tempPin)/ 1024.0) * 5.0) * 100.0);
//Converts Kelvin to Celsius minus 2.5 degrees error
// tempC = tempK - 273.0;
// tempF = ((tempK - 2.5) * 9 / 5) - 459.67;
//Celsius temperature display
// tempC = int( sensors.requestTemperatures);
// sensors.requestTemperatures(); //Pobranie temperatury czujnika
float tempC=sensors.getTempCByIndex(0);
Serial.print("Aktualna temperatura: ");
Serial.println(sensors.getTempCByIndex(0));
// Serial.print(tempC);
digitBuffer[3] = int(tempC)/1000;
digitBuffer[2] = (int(tempC)%1000)/100;
digitBuffer[1] = (int(tempC)%100)/10;
digitBuffer[0] = (int(tempC)%100)%10;
updateDisp();
delay(1);