Ok, i got a bit spare time and tried to store the data read from the DS18B20 on the Card,
i know exactly where my problem is ![]()
i can only store "strings" to the Sd-Card, and i only get "floats" from the sensors, so i have to convert float to string...
appearantly this isnt as easy as i thought. I´m searching now for over 3h to find a way to convert this. I found many links and big code snippets and people saying it works for them...but i can´t get it to work...
Maybe one of you knows a simple way to convert the floats one gets from the sensors to strings one can save to card..
I will post my code just in case somebody wants to watch the problem.
The conversion should take place just after the reading from the sensors in the "printTemperature" function
#include <OneWire.h>
#include <DallasTemperature.h>
#include "SDuFAT.h"
// Data wire is plugged into port 7 on the Arduino
#define ONE_WIRE_BUS 7
// 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);
// arrays to hold device address
DeviceAddress insideThermometer;
// variable used when reading from serial
byte inSerByte = 0;
void setup(void)
{
// start serial port
Serial.begin(9600);
// locate devices on the bus
Serial.print("Locating devices...");
sensors.begin();
Serial.print("Found ");
Serial.print(sensors.getDeviceCount(), DEC);
Serial.println(" devices.");
// report parasite power requirements
Serial.print("Parasite power is: ");
if (sensors.isParasitePowerMode()) Serial.println("ON");
else Serial.println("OFF");
// assign address manually. the addresses below will beed to be changed
// to valid device addresses on your bus. device address can be retrieved
// by using either oneWire.search(deviceAddress) or individually via
// sensors.getAddress(deviceAddress, index)
//insideThermometer = { 0x28, 0x1D, 0x39, 0x31, 0x2, 0x0, 0x0, 0xF0 };
// Method 1:
// search for devices on the bus and assign based on an index. ideally,
// you would do this to initially discover addresses on the bus and then
// use those addresses and manually assign them (see above) once you know
// the devices on your bus (and assuming they don't change).
if (!sensors.getAddress(insideThermometer, 0)) Serial.println("Unable to find address for Device 0");
// show the addresses we found on the bus
Serial.print("Device 0 Address: ");
printAddress(insideThermometer);
Serial.println();
// set the resolution to 12 bit (Each Dallas/Maxim device is capable of several different resolutions)
sensors.setResolution(insideThermometer, 12);
Serial.print("Device 0 Resolution: ");
Serial.print(sensors.getResolution(insideThermometer), DEC);
Serial.println();
}
// function to print the temperature for a device
void printTemperature(DeviceAddress deviceAddress)
{
// get the temperature
float tempC = sensors.getTempC(deviceAddress);
//floatToString conversion here!!!!
SD.print("hola.txt", );
delay(5000); //delay because of delay ;)
}
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
Serial.println("DONE");
// It responds almost immediately. Let's print out the data
printTemperature(insideThermometer); // Use a simple function to print out the data
}
// function to print a device address
void printAddress(DeviceAddress deviceAddress)
{
for (uint8_t i = 0; i < 8; i++)
{
if (deviceAddress[i] < 16) Serial.print("0");
Serial.print(deviceAddress[i], HEX);
}
}
There have to be 100 people out there having the same problem ![]()
Am i the only one not being able to fix this? ![]()
Greetings
Jean