Witajcie męczę się kilka dni już z zapisem danych z czujnika DS18B20 na karcie sd i dostaję informacje przy kompilacji że zmienna "float" nie może zostać zapisana po zmianie na int zapisuje ale pokazuje w cały świat. Oto fragment kodu:
serdeczne dzięki za pomoc
Kod:
#include <SPI.h>
#include <SD.h>
#include <OneWire.h>
#include <DS18B20.h>
#include <iostream>
#include <stdio.h>
const int chipSelect = 10;
#define ONEWIRE_PIN 2
byte address[8] = {0x28, 0x1, 0x4F, 0x2C, 0x6, 0x0, 0x0, 0x1C};
OneWire onewire(ONEWIRE_PIN);
DS18B20 sensors(&onewire);
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial)
sensors.begin();
sensors.request(address);
{
}
Serial.print("Initializing SD card...");
// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
// don't do anything more:
return;
}
Serial.println("card initialized.");
}
void loop() {
delay(2000);
if (sensors.available())
{
float temperature = sensors.readTemperature(address);
sensors.request(address);
}
File dataFile = SD.open("datalog.txt", FILE_WRITE);
// if the file is available, write to it:
if (dataFile) {
dataFile.println(address);
dataFile.close();
// print to the serial port too:
Serial.println(address);
Serial.println();
}
// if the file isn't open, pop up an error:
else {
Serial.println("error opening datalog.txt");
}
}
serdeczne dzięki za pomoc