
Chisty (Customer) asked a question.
I am not sure how and what libraries to use the SD Card as a Data logger through the P1AM-100
I added a code that I tried but didn't work
#include <P1AM.h>
#include <SPI.h>
#include <SD.h>
File myFile;
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
}
while (!P1.init()) {
; //wait for modules to sign on
}
Serial.print("Initializing SD card...");
if (!SD.begin(A3)) {
Serial.println("initialization failed!");
while (1);
}
Serial.println("initialization done.");
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
myFile = SD.open("test.txt", FILE_WRITE);
// if the file opened okay, write to it:
if (myFile) {
Serial.print("Writing to test datalogger test.txt...");
myFile.println("testing 1, 2, 3. /n Testing Datalogger");
// close the file:
myFile.close();
Serial.println("done.");
} else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
// re-open the file for reading:
myFile = SD.open("test.txt");
if (myFile) {
Serial.println("test.txt:");
// read from the file until there's nothing else in it:
while (myFile.available()) {
Serial.write(myFile.read());
}
// close the file:
myFile.close();
} else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
}
void loop() {
// nothing happens after setup
}
Hi Chisty,
I just used Productivity Blocks to get a quick sample.
I hope this helps you out.
Regards,
Garry
https://accautomation.ca/series/productivity-open-arduino-compatible-industrial-controller/
Thank You Garry for your kind help, I am going to try this out.
No Problem. This is one of the reasons that I like ProductivityBlocks. This will give you some basic code as a start.
Garry
Hey Chisty,
I believe your issue is probably that you have " if (!SD.begin(A3)) {" instead of " if (!SD.begin(SDCARD_SS_PIN)) {"
That function selects the chip select pin for the SD card. A3 is not routed to the SD card on our board, so it won't properly control it.
For a quick check if everything is working, use the example under SD>cardinfo in the Arduino IDE. Make sure to change the chip select pin in that example as well.
Thanks
Adam