Nano 33 IOT, Multiple DS18B20 Sensors, Micro SD Card Module

I have the Nano 33 IOT, Multiple DS18B20 temp sensors (addresses recorded), and a Micro SD card module. Everything is wired correctly, I know from testing.

I can read and display the sensor data from the DS18B20's onto the serial monitor no problem. I can even use the example code to read / write and verify the data onto the Micro SD card. My only issue is writing the temp data to the card. I'd love to use the internal RTC to include a time stamp on each data entry. I would like to read the temp sensors once per minute. The file should probably be a CSV to use Excel spreadsheets or something similar.

I have looked all over on how to put the data onto the SD card but I'm not seeing anything that works like I have setup. I want to use the temp sensors address in the code.

At some point I would love to include sensor readings from the onboard 6DOF sensor and an added GPS sensor at some point. I really just want to focus on the temp sensors writing onto the SD card.

How do I tell it how to separate the columns and whatnot?

Please let me know if you need any additional info on this project. I really appreciate any and all help I may get.

CSV means
Comma seperated variable
So seperate your variables with commas.

There is a data logging example included with the SD library.

I should have known on the CSV thing.

I've been trying to modify the datalogging example to work with my needs. with no luck.

Your code is a state secret then, is it?

The code I'm currently working on is pasted below. It's what I got done so far in the little free time I have had. I took the datalogger example and started adding the multi temp sensor code i tested to work. I'm not sure where to go next.

#include <SPI.h>
#include <SD.h>
#include <OneWire.h>
#include <DallasTemperature.h>

const int chipSelect = 10;

// Data wire is plugged into port 4 on the Arduino
#define ONE_WIRE_BUS 4

// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);

// Addresses of 3 DS18B20s
uint8_t InsideBoxTemp[8] = { 0x28, 0x11, 0x60, 0xf3, 0x58, 0x20, 0x01, 0x5b };
uint8_t OutsideBoxTemp[8] = { 0x28, 0x3e, 0x8c, 0x78, 0x58, 0x20, 0x01, 0x7f };

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  sensors.begin();
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }


  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() {
  // make a string for assembling the data to log:
  String dataString = "";

  // read three sensors and append to the string:
  for (int analogPin = 0; analogPin < 3; analogPin++) {
    int sensor = analogRead(analogPin);
    dataString += String(sensor);
    if (analogPin < 2) {
      dataString += ",";
    }
  }

  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  File dataFile = SD.open("Temp01.txt", FILE_WRITE);

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

I think your temperature code is rubbish, so go to one that works.
"Arduino 1-Wire Tutorial" Arduino 1-Wire Tutorial
Opening and closing the file in the loop is a bad idea, but not immediately fatal. Open once in setup.

My temperature code works perfectly fine, thanks!

Ok...

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