Buongiorno a tutti,
ho fatto un programma (arduino uno)che mi legge una sonda di temperatura (MAX 6675) e poi invia i dati al cellulare via bluetooth.
Fin qui tutto bene, ho aggiunto la parte per fare il data logger utilizzando lo shield della DEEK-ROBOT (clone adafruit), e non mi va più la parte bluetooth.
Premetto che se divido le due parti di codice, i programmi relativi funzionano egregiamente (data logger e bluetooth separati).Credo che ci sia un conflitto con Serial.begin e Serial.print .
Qui il codice.
/*
BIRRA SD card datalogger + BLUETOOTH
This example shows how to log data from three analog sensors
to an SD card using the SD library.
This example code is in the public domain.
*/
#include <max6675.h>
#include <Wire.h>
char BluetoothData; // the Bluetooth data received
int interval=2000; //Sample every 2 seconds
int fanSpeed;
//sonda birra
int thermoDO = 10;
int thermoCS = 11;
int thermoCLK = 12;
MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);
int Tbirra=thermocouple.readCelsius();
int TbirraImpostata = 20;
#include <SPI.h>
#include <SD.h>
const int chipSelect = 10;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
/* while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
*/
Serial.print("Initializing SD card...");
// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
// don't do anything more:
return;
}
Serial.println("card initialized.");
}
void loop() {
// make a string for assembling the data to log:
String dataString = "";
//Pause before taking next measurement
delay(interval);
// ricezione dal telefonino
if (Serial.available()){
BluetoothData=Serial.read(); //Get next character from bluetooth
//Set New temp birra
if(BluetoothData=='N'){
TbirraImpostata=Serial.parseInt();
}
// tempo rilevamento
if(BluetoothData=='S') {
interval=Serial.parseInt()*1000;
}
}
int Tbirra=thermocouple.readCelsius();
// read three sensors and append to the string:
dataString += String(Tbirra);
//Send data over Bluetooth
Serial.print("*T"+String(Tbirra)+"*");
if (Tbirra<TbirraImpostata-50) Serial.print("*LR255G0B0*"); //Red
if (Tbirra>TbirraImpostata-50&&Tbirra<TbirraImpostata-20) Serial.print("*LR255G200B0*"); //Orange
if (Tbirra>TbirraImpostata-20&&Tbirra<TbirraImpostata+10) Serial.print("*LR0G255B0*"); //Green
if (Tbirra=TbirraImpostata-10) Serial.print("*SV100*"); //suono
// 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("datalog.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 datalog.txt");
}
}
Praticamente senza la parte del data logging
int Tbirra=thermocouple.readCelsius();
mi da correttamente la temperatura,
dopo mi da 0
Grazie in anticipo per l’aiuto