سلام دوستان
من برای اتصال سخت افزاری micro SD به آردوینو مدل Nano پین UB ، RXD ، DB و ERR مریوط به micro SD رو به صورت تقسیم ولتاژی به ترتیب به D4 و TX و D6 و D7 برد آردوینو وصل کردم. میخواستم بپرسم از لحاظ سخت افزاری درست انجام شده؟؟؟؟؟؟؟
همچنین کد مربوط به ارسال چهار داده ی سنسور به صورت سریالی به micro SD رو ضمیمه کردم. هیچ فایلی ایجاد نمیکنه در واقع open نمیکنه. ممنون میشم راهنماییم کنید. :sad:
من برای اتصال سخت افزاری micro SD به آردوینو مدل Nano پین UB ، RXD ، DB و ERR مریوط به micro SD رو به صورت تقسیم ولتاژی به ترتیب به D4 و TX و D6 و D7 برد آردوینو وصل کردم. میخواستم بپرسم از لحاظ سخت افزاری درست انجام شده؟؟؟؟؟؟؟
همچنین کد مربوط به ارسال چهار داده ی سنسور به صورت سریالی به micro SD رو ضمیمه کردم. هیچ فایلی ایجاد نمیکنه در واقع open نمیکنه. ممنون میشم راهنماییم کنید. :sad:
کد:
#include<EEPROM.h>
#include<LiquidCrystal.h>
//#include <SoftwareSerial.h>
#include<SD.h>
#include<SPI.h>
const int groundpin = 18; // analog input pin 4 -- ground
const int powerpin = 19; // analog input pin 5 -- voltage
const int xpin = A5; // x-axis of the accelerometer
const int ypin = A4; // y-axis
const int zpin = A3; // z-axis
const int HRpin=A1;
const String XHEADER = "X: ";
const String YHEADER = "Y: ";
const String ZHEADER = "Z: ";
const String HRHEADER = "HR: ";
String dataString;
//int DB;
//int ledpin=22;
File dataFile;
//int mydata1;
//int mydata2;
//int mydata3;
//int mydata4;
const String TAB = "\t";
/*const int RXD;
const int UB;
const int ERR;
const int DB;*/
LiquidCrystal lcd(12,11,5,4,3,2);
//int bluetoothTx = 2;
//int bluetoothRx = 3;
//SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);
void setup() {
lcd.begin(16,2);
// initialize the serial communications:
Serial.begin(9600);
// Power and ground the necessary pins. Providing power to both
// the analog and digital pins allow me to just use the breakout
// board and not have to use the normal 5V and GND pins
//Setup Bluetooth serial connection to android
//bluetooth.begin(115200);
//bluetooth.print("data");
//delay(100);
//bluetooth.println("U,9600,N");
//bluetooth.begin(9600);
//pinMode(ledPin,22);
pinMode(groundpin, OUTPUT);
pinMode(powerpin, OUTPUT);
digitalWrite(groundpin, LOW);
digitalWrite(powerpin, HIGH);
}
void loop() {
int val1=0;
val1 = analogRead(xpin); // read the input pin
int val2=0;
val2 = analogRead(ypin); // read the input pin
int val3=0;
val3= analogRead(zpin); // read the input pin
int val4=0;
val4= analogRead(HRpin); // read the input pin
// read sensor and append to the string:
for (int analogPin=1;analogPin<=4;analogPin++) {
Serial.print(XHEADER + analogRead(xpin) + TAB);
Serial.print(YHEADER + analogRead(ypin) + TAB);
Serial.print(ZHEADER + analogRead(zpin)+TAB);
Serial.print(HRHEADER + analogRead(HRpin));
Serial.println();
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("data1.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 data1.txt");
}
/* Serial.print(XHEADER + analogRead(xpin) + TAB);
Serial.print(YHEADER + analogRead(ypin) + TAB);
Serial.print(ZHEADER + analogRead(zpin)+TAB);
Serial.print(HRHEADER + analogRead(HRpin));
Serial.println();*/
/* lcd.setCursor(0,0);
lcd.print(val1);
lcd.setCursor(8,0);
lcd.print(val2);
lcd.setCursor(0,1);
lcd.print(val3);*/
delay(200);
}



دیدگاه