Hi everyone,
Today my Arduino Uno Wifi rev2 came in, as i was having trouble with the SRAM capacity of my Uno. What I'm trying to do, is connect to the arduino a motion sensor, of which the output is saved to an SD card. The idea was that the system could measure without being connected to the computer. I used the following code (ignore the custom libraries):
#include <XSens.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
//Initializing XSens at ADDRESS 0X1D
XSens xsens(0x6b);
File myFile;
const int chipSelect = 4;
void setup() {
Serial.begin(9600);
Wire.begin();
//Wake up process
xsens.begin();
Serial.print("Initializing SD card...");
if (!SD.begin(chipSelect)) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");
}
void loop() {
//Read mesurements (Reads all data given by the AHRS)
myFile = SD.open("kloek.txt", FILE_WRITE);
if (myFile) {
myFile.println("testing 1, 2, 3.");
// close the file:
myFile.close();
Serial.println("done.");
} else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
delay(1000);
}
This worked fine. I could also edit to code to write data from the sensor to the SD card, no issues. However, the serial monitor had to be opened before the writing to the SD card began. I figured I could just remove the lines containing "Serial" and I added 3 lines to make the led blink whenever there was an error with opening the file. The code is as follows (again ignore the custom libraries):
#include <XSens.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
//Initializing XSens at ADDRESS 0X1D
XSens xsens(0x6b);
File myFile;
const int chipSelect = 4;
void setup() {
Serial.begin(9600);
Wire.begin();
//Wake up process
xsens.begin();
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
//Read mesurements (Reads all data given by the AHRS)
xsens.updateMeasures();
myFile = SD.open("test.txt", FILE_WRITE);
if (myFile) {
// myFile.println("testing 1, 2, 3.");
for(int i = 0 ; i < 3; ++i){
myFile.print(xsens.getEulerd()[i]);
myFile.print(" ");
}
for(int i = 0 ; i < 3; ++i){
myFile.print(xsens.getFAccel()[i]);
myFile.print(" ");
}
myFile.print(xsens.getStime()/10);
myFile.println(" ");
// close the file:
myFile.close();
} else {
// if the file didn't open, print an error:
digitalWrite(LED_BUILTIN, HIGH);
delay(20);
digitalWrite(LED_BUILTIN, LOW);
}
delay(1000);
}
After I uploaded this, the L started blinking with one second intervals, suggesting that the program was not writing anything, and this was the case after I checked the SD card. Now, when I try to upload a new sketch, It gets stuck uploading. This is also the case for the BareMinumum sketch. The program on the Arduino is still running as I see the light blinking. There seems to be no exchange between the Arduino and the computer. I also found that somewhere along the way, the port switched from COM8 to COM9. I tried to find similar problems on the forums but the solutions didnt work out for me.
Things that I tried:
-Reboot computer
-Reinstall drivers
-Disabling Bluetooth ports
-Holding the reset button while uploading
-Checked the board and port in the "Tools" menu
-Connecting my Arduino Uno and uploading different sketches, which worked fine
Sorry for the whole "story", but as im quite inexperienced with Arduino, I'm trying to provide you with the information that I understand. I hope I made my issue clear.
Thank you in advance and kind regards,
L