trying to log data after RF 433mhz receiver

Hi,
I've setup one arduino to read Humidity Temereatue and Frequency of sound. I have this data sent to receiving arduino that reads and shows in serial monitor.
Here is the code for the receiver:

// Include RadioHead Amplitude Shift Keying Library
#include <RH_ASK.h>
#include <SPI.h>


// Define output strings
String str_humid;
String str_temp;
String str_freq;
String str_out;
// Create Amplitude Shift Keying Object
RH_ASK rf_driver;

void setup()
{ // Initialize ASK Object
 rf_driver.init();
 // Setup Serial Monitor
 Serial.begin(9600); 

}

void loop()
{ // Set buffer to size of expected message  (note: see Ask_receiverTest to make this variable.
 //uint8_t buf[RH_ASK_MAX_MESSAGE_LEN];
 uint8_t buf[17];
   uint8_t buflen = sizeof(buf);
 // Check if received packet is correct size
 if (rf_driver.recv(buf, &buflen))
 { // Message received with valid checksum
   // Get values from string
   // Convert received data into string
   str_out = String((char*)buf);
   
   // The entire message is in the String str_out
   // Split string into three values

   // First, find the offsets of the two commas
   int comma1 = str_out.indexOf(",");
   int comma2 = str_out.indexOf(",", comma1+1);

   // Then extract the substrings
   str_humid = str_out.substring(0, comma1);         // before first comma
   str_temp = str_out.substring(comma1+1, comma2);  // between the two commas
   str_freq = str_out.substring(comma2+1);          // after the second comma

   
   // Print values to Serial Monitor
   Serial.print("Humidity: ");
   Serial.print(str_humid);
   Serial.print("  - Temp: ");
   Serial.print(str_temp);
    Serial.print(" - Frequency: ");
    Serial.println(str_freq);

 }  }

I want to log the data on the data logging shield V1.0, Ive tried to combine the both codes but I'm not getting any transmittion from the receiving arduino when I add the data logging elements to it
here is the code that Ive combined with my receiver code:

// Include RadioHead Amplitude Shift Keying Library
#include <RH_ASK.h>
#include <SPI.h>
#include <SD.h>

const int chipSelect = 10;

// Define output strings
String str_humid;
String str_temp;
String str_freq;
String str_out;
// Create Amplitude Shift Keying Object
RH_ASK rf_driver;

void setup()
{ {// Initialize ASK Object
 rf_driver.init();
 // Setup Serial Monitor
 Serial.begin(9600); }



 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:
   while (1);
 }
 Serial.println("card initialized.");
}


void loop()
{ // Set buffer to size of expected message  (note: see Ask_receiverTest to make this variable.
 //uint8_t buf[RH_ASK_MAX_MESSAGE_LEN];
 uint8_t buf[17];
   uint8_t buflen = sizeof(buf);
 // Check if received packet is correct size
 if (rf_driver.recv(buf, &buflen))
 { // Message received with valid checksum
   // Get values from string
   // Convert received data into string
   str_out = String((char*)buf);
   
   // The entire message is in the String str_out
   // Split string into three values

   // First, find the offsets of the two commas
   int comma1 = str_out.indexOf(",");
   int comma2 = str_out.indexOf(",", comma1+1);

   // Then extract the substrings
   str_humid = str_out.substring(0, comma1);         // before first comma
   str_temp = str_out.substring(comma1+1, comma2);  // between the two commas
   str_freq = str_out.substring(comma2+1);          // after the second comma

   
   // Print values to Serial Monitor
   Serial.print("Humidity: ");
   Serial.print(str_humid);
   Serial.print("  - Temp: ");
   Serial.print(str_temp);
    Serial.print(" - Frequency: ");
    Serial.println(str_freq);

 }
 
 File dataFile = SD.open("datalog.txt", FILE_WRITE);

 // if the file is available, write to it:
 if (dataFile) {
   dataFile.println(str_humid);
   dataFile.println(str_temp);
   dataFile.println(str_freq); 
   dataFile.println(str_out);   
   dataFile.close();
   // print to the serial port too:
   Serial.println(str_humid);
   Serial.println(str_temp);
   Serial.println(str_freq);
 }
 // if the file isn't open, pop up an error:
 else {
   Serial.println("error opening datalog.txt");
 }}

I know that my coding isnt up to standard, so I need a little help in the right direction
Thank you

Please edit your post to add code tags ("</>" button on post editor).

If you are using an AVR-based Arduino (Uno, Nano, etc.) don't use Strings. They cause memory problems and unpredictable crashes.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.