Cari amici ho realizzato una stazione meteo con LoRa SX1276 Trasmissione tutto bene Ricezione anche finchè non ho voluto implementare il sistema di ricezione con una scheda SD cablata su Arduino UNO. Da questo forum ho appreso che essendo LoRa e SD sullo stesso percorso dovevo separare i tempi di attuazione e creare un pin software .Quindi rubacchiando qua e la ho realizzato il seguente sketch:
#include <Vcc.h>
const float VccMin = 0.0; // Minimum expected Vcc level, in Volts.
const float VccMax = 5.0; // Maximum expected Vcc level, in Volts.
const float VccCorrection = 1.0/1.0; // Measured Vcc by multimeter divided by reported Vcc
Vcc vcc(VccCorrection);
#include <SimpleDHT.h>
SimpleDHT22 dht22(A0);
#include <Wire.h>
#include <SPI.h>
#include <LoRa.h>
#include <SD.h> // SD library
// Used for software SPI
#define LoRa_CLK 13
#define LoRa_MISO 12
#define LoRa_MOSI 11
// Used for hardware & software SPI
#define LoRa_CS1 10
#define SD_SCK 13
#define SD_MISO 12
#define SD_MOSI 11
#define SD_CS2 8
int CS1= 10;
int CS2= 8;
File file; // file object that is used to read and write data
void setup() {
Serial.begin(9600);
SPI.begin;
float temperature = 0;
float humidity = 0;
dht22.read2(&temperature, &humidity, NULL);
Serial.println(" DATI INTERNO");
Serial.println("");
Serial.print("Temperature: ");Serial.print ((float)temperature); Serial.println(" C");
Serial.print("Humidity: ");Serial.print((float)humidity); Serial.println(" RH%");
Serial.println("");
delay(1000);
float v = vcc.Read_Volts();
Serial.print("VCC = ");
Serial.print(v);
Serial.println(" Volts");
float p = vcc.Read_Perc(VccMin, VccMax);
Serial.print("VCC = ");
Serial.print(p);
Serial.println(" %");
Serial.println("");
LoRa.begin(CS1);
if (!LoRa.begin(CS1)){
Serial.println("Starting LoRa failed!");
while (1);
}
Serial.println("LoRa Receiver waiting...");
delay(1000);
}
void loop() {
// try to parse packet
int packetSize = LoRa.parsePacket();
if (packetSize) {
Serial.println("Received packet: ");
// read packet
while (LoRa.available()) {
Serial.print((char)LoRa.read());
}
delay(10);
}
}
void writeFile() //writing something to the SD card
{
if (!SD.begin(CS2)) { // Initialize SD card
Serial.println("Errore SD");
return;
}
Serial.println("SD pronta");
Serial.println("");
if (SD.exists("file.txt")) {
SD.remove("file.txt");
file = SD.open("file.txt", FILE_WRITE); // open "file.txt" to write data; make sure that you want to write in the same file that you created in the setup()
if (file) {
file.println((char)LoRa.read()); // write number to file; in this case, the temperature with 2 decimals precision
file.close(); // close file
} else {
Serial.println("Could not open file (writing).");
} } }
````Testo preformattato`
LoRa parte la scheda SD pure ma il sistema si inchioda. Si accetta la carità`Testo preformattato``Testo preformattato`