Hi! I am a total beginner in using Arduino, so I am very confused. Sorry if I am doing something obviously wrong here that I shouldn't have missed.
I am trying to make a temperature logger that measures surface temperature every 15 minutes using the Mini Ultra board with atmega4808 (https://www.rocketscream.com/blog/product/mini-ultra/), MLX90614 sensor, Adafruit MicroSD SPI or SDIO Card Breakout Board, and using 2 x AA batteries as a power source. I am using the UPDI-USB-Serial Adapter V2 to connect the board to IDE (https://www.rocketscream.com/blog/product/updi-usb-serial-adapter-v2/)
Using my code I have made it work correctly on several different boards, but not this one. But I do not get an error message, the IDE program acts as if it works, but then nothing happens..
This is the code:
#include <SPI.h>
#include <SD.h>
#include <Adafruit_MLX90614.h>
Adafruit_MLX90614 mlx = Adafruit_MLX90614();
const int chipSelect = 0;
// change to the digital pin used on board
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
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.");
if (!mlx.begin()) {
Serial.println("Error connecting to MLX sensor. Check wiring.");
while (1);
};
File dataFile = SD.open("datalog.csv", FILE_WRITE);
String header = "";
if (dataFile)
{
header += String("Time");
header += ",";
header += String("Ambient 1");
header += ",";
header += String("Object 1");
header += ",";
header += String("Ambient 2");
header += ",";
header += String("Object 2");
header += ",";
header += String("Ambient 3");
header += ",";
header += String("Object 3");
header += ",";
dataFile.println(header);
dataFile.close();
}
}
void loop() {
// make a string for assembling the data to log:
String dataString = "";
Serial.print("Ambient = "); Serial.print(mlx.readAmbientTempC());
Serial.print("*C\tObject = "); Serial.print(mlx.readObjectTempC()); Serial.println("*C");
dataString += String(millis());
dataString += (",");
dataString += String(mlx.readAmbientTempC());
dataString += String(",");
dataString += String(mlx.readObjectTempC());
dataString += String(",");
delay(1000);
Serial.print("Ambient = "); Serial.print(mlx.readAmbientTempC());
Serial.print("*C\tObject = "); Serial.print(mlx.readObjectTempC()); Serial.println("*C");
dataString += String(mlx.readAmbientTempC());
dataString += String(",");
dataString += String(mlx.readObjectTempC());
dataString += String(",");
delay(1000);
Serial.print("Ambient = "); Serial.print(mlx.readAmbientTempC());
Serial.print("*C\tObject = "); Serial.print(mlx.readObjectTempC()); Serial.println("*C");
dataString += String(mlx.readAmbientTempC());
dataString += String(",");
dataString += String(mlx.readObjectTempC());
// 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("datalog.csv", 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 datalog.csv");
}
Serial.println();
delay(30000);
}
And here is a very simple illustration made in pain of how I have connected everything, followed by the pinout of the board:
I can also note that the sensor example code nor the SDcard info code (found under examples in IDE) does not work, but the "Blink" example does work. My code above, and all the examples works when I connect to Nano Every (4809), Arduino MKR WIFI 1010, or an Arduino MKR Zero, but I need it to work with Mini Ultra for my project.
I am using MegacoreX and programmer Jtag2updi.
Any help or feedback is appreciated!
Thanks