how to unite two program to be one

how to unite two program to be one.
how to save the date which sensor get in datalog.txt
program of SD card
#include “FileLogger.h”

// define the pin that powers up the SD card
#define MEM_PW 8

// variable used when reading from serial
byte inSerByte = 0;

#define MESSAGE “Hello, this is my message. Just testing the FileLogger library.\r\n”
unsigned long length = sizeof(MESSAGE)-1;
byte buffer = MESSAGE;

void setup(void) {
pinMode(MEM_PW, OUTPUT);
digitalWrite(MEM_PW, HIGH);
Serial.begin(9600);
}

void loop(void) {
char command = ‘0’;
unsigned long t1, t2;

// Arduino expects one of a series of one-byte commands
if (Serial.available() > 0) {
int result;
inSerByte = Serial.read();
switch (inSerByte) {
case ‘W’:
result = FileLogger::append(“data.log”, buffer, length);
Serial.print(" Result: “);
if( result == 0) {
Serial.println(“OK”);
} else if( result == 1) {
Serial.println(“Fail initializing”);
} else if( result == 2) {
Serial.println(“Fail appending”);
}
break;
case ‘T’:
for(int i=0; i<10; i++) {
result = FileLogger::append(“data.log”, buffer, length);
Serial.print(” Result: ");
if( result == 0) {
Serial.println(“OK”);
} else if( result == 1) {
Serial.println(“Fail initializing”);
} else if( result == 2) {
Serial.println(“Fail appending”);
}
}
Serial.print(“Done”);
break;
}
}
}
program of temperture and humidity

#include <SHT1x.h>

// Specify data and clock connections and instantiate SHT1x object
#define dataPin 10
#define clockPin 11
SHT1x sht1x(dataPin, clockPin);

void setup()
{
Serial.begin(38400); // Open serial connection to report values to host
Serial.println(“Starting up”);
}

void loop()
{
float temp_c;
float temp_f;
float humidity;

// Read values from the sensor
temp_c = sht1x.readTemperatureC();
temp_f = sht1x.readTemperatureF();
humidity = sht1x.readHumidity();

// Print the values to the serial port
Serial.print("Temperature: ");
Serial.print(temp_c, DEC);
Serial.print("C / ");
Serial.print(temp_f, DEC);
Serial.print(“F. Humidity: “);
Serial.print(humidity);
Serial.println(”%”);

delay(2000);
}

you need to do several things:

  1. copy the headers and initializations to the other sketch (the stuff before the setup())
  2. combine the setup content into the same setup function
    2a) Decide which speed to use for the serial (you are using 2 different)
  3. combine the loop functions in one loop

after all this work (and when it is running well), you need (I guess) to use the temperature stuff writing into a buffer using sprintf for example, and then write the buffer to the filelogger...

char buffer[16];
sprintf(buffer,"%d",(int)sht1x.readTemperatureC()); // warning, this will not print floating point value
FileLogger::append("data.log", buffer, strlen(buffer));

#include "SHT1x.h"
#include "FileLogger.h"

#define dataPin 8
#define clockPin 9
SHT1x sht1x(dataPin, clockPin);

#define MEM_PW 8

void setup()
{
Serial.begin(9600);

pinMode(MEM_PW, OUTPUT);
digitalWrite(MEM_PW, HIGH);
}

void loop()
{

float temp = sht1x.readTemperatureC();
float humidity = sht1x.readHumidity();
char buffer[16];
Serial.print(temp, DEC);
Serial.print("C / ");
Serial.print(humidity, DEC);
Serial.println("%");
sprintf(buffer,"%d",(int)sht1x.readTemperatureC());
FileLogger::append("data.log", buffer, strlen(buffer));

delay(50);
}

I unite program but have a question.
?
The material state is wrong.

The compiler appears a wrong message as follow.

In function 'void loop()':
error: invalid conversion from 'byte*' to 'char*

Serial.print(temp, DEC);

You can try for ten places of decimals with a 'float' value, but you won't get them.

When posting code, please use the # (code) icon in the editor's toolbar.

In function 'void loop()':
error: invalid conversion from 'byte*' to 'char*

you need to do a so called 'type-cast':

FileLogger::append("data.log", (byte *)buffer, strlen(buffer));

anyway, let's also clean up the rest of the code for that the values that will not appear ok, you need to convert from float to an int.int representation to have 'nice' values 8) :

float temp = sht1x.readTemperatureC(); 
char buffer[16];
sprintf(buffer,"%d.%03d\n", (int)floor(temp),(int)((temp-floor(temp))*1000)); 
// change to "%d.%02d\n" and *100 if you want to print only 2 decimals

Serial.print(buffer); // it is convenient to use the same buffer, already filled with the data to show

FileLogger::append("data.log", (byte *)buffer, strlen(buffer));

I added also a \n in the format string, so you will have newlines in the log file.

HTH

how to unite two program to be one.

As a general question this belongs on a different forum...