私はこれで数日間忙しく、毎回空っぽになってきました。シンプルな一時ロギング デバイスを作成しようとしています。
シリアルモニターを使用してファイルを作成および書き込みするための実用的なコードがありますが、これはうまく機能しますが、他のデバイスと接触させた瞬間(スイッチを使用してLCDディスプレイをナビゲートすると、書き込み部分で失敗します)
コードは選択した名前のファイルを作成しますが、そのファイルに書き込みません これは私の問題です
これが私のコードです。
// Date and time functions using a DS1307 RTC connected via I2C and Wire lib
//A4 -- SDA
//A5 -- SCL
// 2 -- DS ///// Not needed really I dont think
// It is assumed that the LCD module is connected to
// the following pins using a levelshifter to get the
// correct voltage to the module.
// SCK - Pin 0
// MOSI - Pin 1
// DC - Pin 2
// RST - Pin 3
// CS - Pin 5
//
/*
* SD card attached to SPI bus as follows:
** MOSI - pin 11
** MISO - pin 12
** CLK - pin 13
** CS - pin 10
*/
#include <LCD5110_Graph.h>
#include <SD.h>
#include <Wire.h>
#include "RTClib.h"
LCD5110 myGLCD(0,1,2,3,5);
RTC_DS1307 RTC;
extern uint8_t SmallFont[];
extern uint8_t TinyFont[];
int up=6,down=8,enter=4,right=7,left=9; ////worked out new ones
File root;
char fileName[12];
void setup()
{
Wire.begin();
RTC.begin();
myGLCD.InitLCD();
myGLCD.clrScr();
myGLCD.setFont(SmallFont);
while (! RTC.isrunning())
{
myGLCD.print("RTC NOT running!",CENTER,18);
myGLCD.update();
Wire.begin();
RTC.begin();
}
myGLCD.print("RTC NOW running!",CENTER,18);
myGLCD.update();
delay(1000);
myGLCD.clrScr();
myGLCD.print("Start",CENTER,18);
myGLCD.update();
delay(1000);
pinMode(10, OUTPUT);
if (!SD.begin(10))
{
myGLCD.print("FAILED!",CENTER,18);
myGLCD.update();
delay(1000);
}
else
{
myGLCD.print("DONE",CENTER,18);
myGLCD.update();
delay(1000);
}
pinMode(up,INPUT);
pinMode(down,INPUT);
pinMode(enter,INPUT);
pinMode(left,INPUT);
pinMode(right,INPUT);
pinMode (A0,INPUT);
}
void loop()
{
myGLCD.print("Names now",CENTER,18);
myGLCD.update();
delay(1000);
menu();
float Temp
root = SD.open(fileName,FILE_WRITE);
DateTime now = RTC.now();
if(root) {
for(int p=0;p<5;p++)
{
myGLCD.print("DONE 2",CENTER,18);
myGLCD.update();
delay(1000);
/////////// Code to get the current temp
Temp = log(((34611200/analogRead(A0)) - 33800));
Temp = 1 / (0.000815883 + (0.000222435 * Temp) + (0.000000104 * Temp * Temp * Temp));
Temp = Temp - 273.15; // Convert Kelvin to Celcius
myGLCD.clrScr();
myGLCD.print("Temp",CENTER,18);
myGLCD.update();
pinMode(10,OUTPUT);
root.print(Temp);
root.print(" ---- ");
root.print(now.hour());
root.print(":");
root.print(now.minute());
root.print(" ");
root.print(now.day());
root.print("/");
root.print(now.month());
root.print("/");
root.println(now.year());
delay(2000);
}
root.close();
}
else {
myGLCD.print("Failed",CENTER,18);
myGLCD.update();
delay(1000);
}
root.close();
}
void menu()
{
//////////// menu to select what you want to do (create a file)
/// then goes to picker to select name
}
void picker()
{
//// code to put a selection for a file name on the LCD USER selects this file name after that
////////// .txt is added to the name
}
どんな助けでも大歓迎です。どうもありがとう :)