uwefed:
Presuppongo che hai un Arduino UNO.
Hai bisogno di 2 segnai CS. Questo lo hai giá capito. Non puoi usare il Pin 11 come CS0 perche il pin 11 viene usato dalla SPI. Usa un alto pin (eccetto 10,11,12,e 13).
Ciao Uwe
L'ho iniziato con arduino uno, adesso sono passato al mega ADK che per quanto mi hanno detto dovrebbe funzionare lo stesso senza cambiamenti.
Quindi devo far passare il pin CS0 da 11 ad un altro, lo stesso anche per il CS1?
PaoloP:
Usi l'IDE 0.22 o 0.23?
Se NO, ci linki le librerie che stai usando?
P.S. Hai copiato male. Manca una graffa alla fine del codice.
#include <MAX6675.h>
#include <EEPROM.h> //devo includere la libreria EEP
#include <SdFat.h>
#include <SdFatUtil.h>
#include <ctype.h>
//Create the variables to be used by SdFat Library
Sd2Card card;
SdVolume volume;
SdFile root;
SdFile file;
char name[] = "Test.txt"; //Create an array that contains the name of our file.
char buffer[256]; //This will be a data buffer for writing contents to the file.
char in_char=0;
int index=0; //Index will keep track of our position within the contents buffer.
int CS1= 10;
int CS0 = 11; // CS pin on MAX6675
int SO = 12; // SO pin of MAX6675
int SCK_ = 13; // SCK pin of MAX6675
int units = 1; // Units to readout temp (0 = ÀöF, 1 = ÀöC), ovvero l'unità di misura
float temp_out = 0.0; // Temperature output varible
double errore = 0.0;
MAX6675 temp0(CS0,SO,SCK_,units,error0); // Inizializzo l'amplificatore;
//MAX6675 temp1(CS0,SO,SCK_,units,error1);
//MAX6675 temp2(CS0,SO,SCK_,units,error2);
//MAX6675 temp3(CS0,SO,SCK_,units,error3);
//MAX6675 temp4(CS0,SO,SCK_,units,error4);
//MAX6675 temp5(CS0,SO,SCK_,units,error5);
//MAX6675 temp6(CS0,SO,SCK_,units,error6);
//MAX6675 temp7(CS0,SO,SCK_,units,error7);
char val = '0';
char temp = '0';
int canale=0;
// definisco di Binary COntrol Input, ovvero servono per selezionare il canale in uscita dai Mux;
int a = 2;
int b = 3;
int c = 4;
int d = 5;
int e = 6;
int f = 7;
int inh1 = 8;
int inh2 = 9;
void setup() {
//a,b,c sono uscite da arduino in ingresso al mux;
pinMode(a,OUTPUT);
pinMode(b,OUTPUT);
pinMode(c,OUTPUT);
pinMode(d,OUTPUT);
pinMode(e,OUTPUT);
pinMode(f,OUTPUT);
pinMode(inh1,OUTPUT);
pinMode(inh2,OUTPUT);
pinMode(CS0,OUTPUT);
pinMode(CS1,OUTPUT);
Serial.begin(9600);
Serial.print("Initializing SD card... \n");
// make sure that the default chip select pin is set to
// output, even if you don't use it:
pinMode(10, OUTPUT); //Pin 10 must be set as an output for the SD communication to work.
card.init(); //Initialize the SD card and configure the I/O pins.
volume.init(card); //Initialize a volume on the SD card.
root.openRoot(volume); //Open the root directory in the volume.
}
void loop () {
file.open(root, name, O_CREAT | O_APPEND | O_WRITE); //Open or create the file 'name' in 'root' for writing to the end of the file.
Serial.print("Mux 1 acceso, Mux 2 spento \n") ;
file.print("Mux 1 acceso, Mux 2 spento \n"); //Write the 'contents' array to the end of the file.
file.close();
digitalWrite(inh2,HIGH);
delay(100);
digitalWrite(inh1,LOW);
delay(100);
canale=0;
digitalWrite(a,LOW);
digitalWrite(b,LOW);
digitalWrite(c,LOW);
// Serial.println("chan 0");
errore = error0;
delay(1000);
digitalWrite(CS1,LOW);
digitalWrite(CS0,LOW);
temp_out = temp0.read_tempe(12 , errore);
digitalWrite(CS0,HIGH);
digitalWrite(CS1,HIGH);
file.open(root, name, O_CREAT | O_APPEND | O_WRITE); //Open or create the file 'name' in 'root' for writing to the end of the file.
sprintf(buffer,"channel:", canale," temperature:", temp_out); //Write the 'contents' array to the end of the file.
file.println(buffer);
file.close();
Serial.print( "channel: " );
Serial.print( canale );
Serial.print( " temperature: " );
Serial.println( temp_out ); // Print the temperature to Serial
delay(1000); // Wait one second
canale=1;
digitalWrite(a,HIGH);
digitalWrite(b,LOW);
digitalWrite(c,LOW);
//Serial.println("chan 1");
errore = error1;
delay(1000);
digitalWrite(CS1,LOW);
digitalWrite(CS0,LOW);
temp_out = temp0.read_tempe(12 , errore);
digitalWrite(CS0,HIGH);
digitalWrite(CS1,HIGH);
file.open(root, name, O_CREAT | O_APPEND | O_WRITE); //Open or create the file 'name' in 'root' for writing to the end of the file.
sprintf(buffer,"channel:", canale," temperature:", temp_out); //Write the 'contents' array to the end of the file.
file.println(buffer);
file.close();
Serial.print( "channel: " );
Serial.print( canale );
Serial.print( " temperature: " );
Serial.println( temp_out ); // Print the temperature to Serial
delay(1000); // Wait one second
canale=2;
digitalWrite(a,LOW);
digitalWrite(b,HIGH);
digitalWrite(c,LOW);
//Serial.println("chan 2");
errore = error2;
delay(1000);
digitalWrite(CS1,HIGH);
digitalWrite(CS0,LOW);
temp_out = temp0.read_tempe(12 , errore);
digitalWrite(CS0,HIGH);
digitalWrite(CS1,LOW);
file.open(root, name, O_CREAT | O_APPEND | O_WRITE); //Open or create the file 'name' in 'root' for writing to the end of the file.
sprintf(buffer,"channel:", canale," temperature:", temp_out); //Write the 'contents' array to the end of the file.
file.println(buffer);
file.close();
Serial.print( "channel: " );
Serial.print( canale );
Serial.print( " temperature: " );
Serial.println( temp_out ); // Print the temperature to Serial
delay(1000); // Wait one second
canale=3;
digitalWrite(a,HIGH);
digitalWrite(b,HIGH);
digitalWrite(c,LOW);
errore = error3;
delay(1000);
digitalWrite(CS1,HIGH);
digitalWrite(CS0,LOW);
temp_out = temp0.read_tempe(12 , errore);
digitalWrite(CS0,HIGH);
digitalWrite(CS1,LOW);
file.open(root, name, O_CREAT | O_APPEND | O_WRITE); //Open or create the file 'name' in 'root' for writing to the end of the file.
sprintf(buffer,"channel:", canale," temperature:", temp_out); //Write the 'contents' array to the end of the file.
file.println(buffer);
file.close();
Serial.print( "channel: " );
Serial.print( canale );
Serial.print( " temperature: " );
Serial.println( temp_out ); // Print the temperature to Serial
delay(1000);
}
EDIT: Devi impostare il 6675 per utilizzare dei pin generici (tipo 6, 7 e 8 ) perché usa una SPI software. Siccome la SD usa invece la SPI hardware va in conflitto.
Utilizzo l'ide 1.0.4, il programma continua ancora per molto replicando la lettura del SPI, ho copiato solo la prima parte.
Grazie