Thermocouple fonctionne, ça prend forme

This commit is contained in:
Grouch 2018-03-18 19:14:46 +01:00
parent 57a3b03563
commit 94fb67ba07
2 changed files with 143 additions and 19 deletions

View File

@ -1,51 +1,173 @@
#include <TimerOne.h>
#include <SPI.h>
#include <SD.h>
#include <SparkFun_ADXL345.h>
#include <SoftwareSerial.h>
SoftwareSerial BT(14,15);
ADXL345 adxl = ADXL345();
double pm;
//----------------------------------------------------------------------------------
// CONSTANTES
//----------------------------------------------------------------------------------
#define PIN_BT_RX 14
#define PIN_BT_TX 15
#define PIN_SD_CS 10
#define MAX6675_CS 8
#define MAX6675_SO 6
#define MAX6675_SCK 9
#define START "Start"
#define STOP "Stop"
const int chipSelect = 10;
File dataFile;
const char* ITEM_MENU[] = {"0. Paramètres", "1. Start" , "2. Stop"};
//----------------------------------------------------------------------------------
// VARIABLES
//----------------------------------------------------------------------------------
SoftwareSerial BT(PIN_BT_RX,PIN_BT_TX); // BLUETOOTH
ADXL345 adxl = ADXL345(); // Capteur ADXL
volatile int x,y,z; // Valeurs ADXL
volatile double tc1;
File dataFile; // Fichier sur carte SD
String dataString = ""; // String courante à écrire
unsigned long pm_flush; // Précédent millis() pour flush
volatile bool flag = false; // Flag acquisition
bool flag_run = false; // Flag acquis en cours
//----------------------------------------------------------------------------------
// PARAMETRES
//----------------------------------------------------------------------------------
volatile bool Voie_ON[]= { // Voies actives
true, true, true, true, true, true};
volatile double T = 500000; // Période acquisition µs
unsigned long T_FLUSH = 2000; // Période écriture fichier ms
//----------------------------------------------------------------------------------
// ISR ACQUISITION
//----------------------------------------------------------------------------------
void isrTimer1(){
Timer1.stop();
dataString = "";
Timer1.initialize(T);
// 0 = millis
// 1 = RTC
// 2,3,4 = X,Y,Z
// 5 = TC
if (Voie_ON[0]) {dataString += String(millis());}
if (Voie_ON[1]) {/*RTC!!*/}
if (Voie_ON[2] || Voie_ON[3] || Voie_ON[4]){
if (Voie_ON[2]) {dataString += " " + String(x);}
if (Voie_ON[3]) {dataString += " " + String(y);}
if (Voie_ON[4]) {dataString += " " + String(z);}
}
if (Voie_ON[5]) {dataString += " " + String(readTC());}
flag = true;
}
//----------------------------------------------------------------------------------
// CODE
//----------------------------------------------------------------------------------
void menu(){
for (byte i=0; i<3; i++){
Serial.println(ITEM_MENU[i]);
BT.println(ITEM_MENU[i]);
}
}
void setup() {
Serial.begin(9600);
BT.begin(9600);
BT.begin(9600);
Serial.print("Initializing SD card...");
BT.print("Initializing SD card...");
if (!SD.begin(chipSelect)) {
if (!SD.begin(PIN_SD_CS)) {
Serial.println("Card failed");
BT.println("Card failed");
while (1);
}
Serial.println("card initialized.");
BT.println("card initialized.");
pinMode(MAX6675_CS, OUTPUT);
pinMode(MAX6675_SO, INPUT);
pinMode(MAX6675_SCK, OUTPUT);
adxl.powerOn();
adxl.setRangeSetting(4);
dataFile = SD.open("datalog.txt", FILE_WRITE);
Timer1.stop();
menu();
//Timer1.attachInterrupt(isrTimer1);
Timer1.stop();
//isrTimer1();
//Timer1.start();
//Timer1.initialize(1000000);
}
double readTC() {
uint16_t v;
digitalWrite(MAX6675_CS, LOW);
delay(1);
// Read in 16 bits,
// 15 = 0 always
// 14..2 = 0.25 degree counts MSB First
// 2 = 1 if thermocouple is open circuit
// 1..0 = uninteresting status
v = shiftIn(MAX6675_SO, MAX6675_SCK, MSBFIRST);
v <<= 8;
v |= shiftIn(MAX6675_SO, MAX6675_SCK, MSBFIRST);
digitalWrite(MAX6675_CS, HIGH);
if (v & 0x4) // Bit 2 indicates if the thermocouple is disconnected
{return NAN;}
v >>= 3; // The lower three bits (0,1,2) are discarded status bits
return v*0.25; // The remaining bits are the number of 0.25 degree (C) counts
}
void loop() {
String dataString = "";
int x,y,z;
adxl.readAccel(&x, &y, &z);
dataString = String(String(millis()) + " " + String(x) +" "+ String(y) +" "+ String(z));
if (flag) {
dataFile.println(dataString);
Serial.println(dataString);
BT.println(dataString);
flag = false;
}
dataFile.println(dataString);
byte in = 0;
Serial.println(dataString);
BT.println(dataString);
delay(50);
if (Serial.available()>0){in = Serial.read();}
if ( BT.available()>0){in = BT.read();}
if (!flag_run && in == 49) {
Timer1.attachInterrupt(isrTimer1);
Timer1.initialize(T);
Serial.println(START);
BT.println(START);
flag_run = true;
}
if (flag_run && in == 50) {
Timer1.stop();
Serial.println(STOP);
BT.println(STOP);
flag_run = false;
menu();
}
if ((millis()-pm)>2000) {
if ((millis()-pm_flush)>T_FLUSH) {
dataFile.flush();
pm=millis();
pm_flush=millis();
}
if (Voie_ON[2] || Voie_ON[3] || Voie_ON[4]){
adxl.readAccel(&x, &y, &z);
}
}

2
README.md Normal file
View File

@ -0,0 +1,2 @@
Datalogger sur base Arduino.
En cours de déeloppement.