3Domse3
Member
I want to hook up my Micro-SD Card with my Teensy 4.0. I want to use the SPI-Pins of my Teensy rather than the pads on the back (I connected it correct but for CS i used Pin 10 instead of 4 and changed chipSelect to 10). Is this possible? And how do I get the SD library to work with my board? I'm only getting errors
I already talked with someone on Reddit (maybe the chat will help): https://www.reddit.com/r/arduino/comments/enm4a5/question_i_want_to_hook_up_my_microsd_card_with/
I hope nothing is mission or it is too messy. It's my first post on aa forum like this...
Error message: no matching function for call to 'SDClass:pen(String&, int)'
I already talked with someone on Reddit (maybe the chat will help): https://www.reddit.com/r/arduino/comments/enm4a5/question_i_want_to_hook_up_my_microsd_card_with/
I hope nothing is mission or it is too messy. It's my first post on aa forum like this...
Error message: no matching function for call to 'SDClass:pen(String&, int)'
Code:
#include <SPI.h>
#include <SD.h>
#include <math.h>
#define LED_PIN 2
const int chipSelect = 10;
long randNumber;
String filename = "";
String dataString = "";
unsigned long i = 3;
unsigned long nr = 2;
unsigned long old_t = 0;
unsigned long delta_t = 0;
/*
unsigned long long i = 3;
unsigned long long nr = 2;
unsigned long long old_t = 0;
unsigned long long delta_t = 0;
*/
void setup() {
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, LOW);
Serial.begin(115200);
Serial.print("Initializing SD card... ");
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present!");
digitalWrite(LED_PIN, HIGH);
while (1);
}
Serial.println("Card initialized.");
randomSeed(analogRead(0));
randNumber = random(10000000, 100000000);
filename += String(randNumber);
filename += String(".txt");
[B]File dataFile = SD.open(filename, FILE_WRITE); // Line of Error[/B]
if (dataFile) {
dataFile.println("Nr;Prime;Calc_Time(us);Runtime(us)");
dataString = "";
dataString += String("1;2;0;");
dataString += String(micros());
dataFile.println(dataString);
dataFile.close();
}
else {
Serial.print("Error opening ");
Serial.print(filename);
Serial.println(".");
digitalWrite(LED_PIN, HIGH);
while (1);
}
Serial.println();
}
void loop() {
old_t = 0;
old_t = micros();
long prime = is_prime(i);
delta_t = micros() - old_t;
if (prime == 1) {
Serial.println(nr);
dataString = "";
dataString += String(nr);
dataString += String(";");
dataString += String(i);
dataString += String(";");
dataString += String(delta_t);
dataString += String(";");
dataString += String(micros());
File dataFile = SD.open(filename, FILE_WRITE);
if (dataFile) {
dataFile.println(dataString);
dataFile.close();
}
else {
Serial.print("Error opening ");
Serial.print(filename);
Serial.println(".");
digitalWrite(LED_PIN, HIGH);
while (1);
}
nr++;
}
i = i + 2;
}
bool is_prime(uint32_t n){
if(n<=1) return false;
else if (n<=3) return true;
else if(n%2==0 or n%3==0) return false;
uint32_t i= 5;
while (i * i <=n)
{
if(n%i== 0 or n%(i + 2) == 0) return false;
i+=6;
}
return true;
nr++;
}