date numerice transmise prin radio memorate pe card SD folosind 2 placi Arduino
Pe ecranul de monitorizare seriala avem informatiile urmatoare:
iar pe cardul SD in documentul fisier.txt sunt scrise aceleasi informatii...
Sketch-ul de receptor este:
/*.............................................................
Sending Multiple Variables Using VirtualWire. Receiver
Author: Rodrigo Mompo Redoli
For http://controlrobotics.rodrigomompo.com
The SD circuit:
* SD card attached to SPI bus as follows:
** MOSI - pin 11
** MISO - pin 12
** CLK - pin 13
** CS - pin 4
created Nov 2010
by David A. Mellis
modified 9 Apr 2012
by Tom Igoe
alse, I use SD example from http://www.roroid.ro
adapted sketch by niq_ro (Nicu FLORICA) from http://nicuflorica.blogspot.com
..............................................................*/
#include <VirtualWire.h> // use Virtual library for decode signal from Rx module
#include <Time.h> // use Time library for control the time between data from receiver
#include <SD.h> // use SD library
File fisier;
// Sensors
int Sensor1Data;
int Sensor2Data;
int Sensor3Data;
int Sensor4Data;
int suma;
char StringReceived[22];
// other
int led = 13; //pin for LED
int j=1; // count the messages
void setup() {
// set the time for record time and value
setTime(0,0,0,25,9,13); // set time to Saturday 8:29:00am Jan 1 2011
pinMode(led, OUTPUT);
// VirtualWire
// Initialise the IO and ISR
// Required for DR3100
// Bits per sec
vw_setup(2000);
// set pin for connect receiver module
vw_set_rx_pin(7);
// Start the receiver PLL running
vw_rx_start();
Serial.begin(9600);
Serial.println("Receptorul lui niq_ro e pregatit sa primeasca mesaje, ");
Serial.print("pregatesc si cardul de memorie SD...");
// On the Ethernet Shield, CS is pin 4. It's set as an output by default.
// Note that even if it's not used as the CS pin, the hardware SS pin
// (10 on most Arduino boards, 53 on the Mega) must be left as an output
// or the SD library functions will not work.
pinMode(10, OUTPUT);
if (!SD.begin(4)) {
Serial.println("dar a aparut o eroare...");
return;
}
Serial.println("care este si el gata.");
File fisier = SD.open("niq_ro.txt", FILE_WRITE); // open a new file
if (fisier) { //daca fisierul este disponibil vom scrie in el
fisier.println("www.tehnic.go.ro");
fisier.println("o noua sesiune de teste de receptie cu module RF");
fisier.close();
Serial.println("www.tehnic.go.ro");
Serial.println("o noua sesiune de teste de receptie cu module RF");
Serial.println("---------------------------------------------------");
}
// if is an error
else {
Serial.println("Nu am putut deschide fisierul niq_ro.txt");
}
} // END void setup
void loop(){
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
//Taking the data from the control base
if (vw_get_message(buf, &buflen))
{
digitalWrite(led, HIGH);
Serial.print("Pachet date nr. "); // print a message
Serial.print(j); // number of message
Serial.print(": ");
int i;
// Message with a good checksum received, dump it.
for (i = 0; i < buflen; i++)
{
// Fill Sensor1CharMsg Char array with corresponding
// chars from buffer.
StringReceived[i] = char(buf[i]);
// Serial.print(StringReceived[i]);
}
sscanf(StringReceived, "%d,%d,%d,%d,%d,%d",&Sensor1Data, &Sensor2Data,&Sensor3Data,&Sensor4Data); // Converts a string to an array
//Serial.print();
if (hour()<10) Serial.print("0");
Serial.print(hour());
Serial.print(":");
if (minute()<10) Serial.print("0");
Serial.print(minute());
Serial.print(":");
if (second()<10) Serial.print("0");
Serial.print(second());
Serial.print(" : ");
digitalWrite(led, LOW);
Serial.print(Sensor1Data);
Serial.print(" + ");
Serial.print(Sensor2Data);
Serial.print(" + ");
Serial.print(Sensor3Data);
Serial.print(" + ");
Serial.print(Sensor4Data);
Serial.print(" = ");
suma = Sensor1Data + Sensor2Data + Sensor3Data + Sensor4Data;
Serial.println(suma);
// write on SD card
if (hour()<10) fisier.print("0");
fisier.print(hour());
fisier.print(":");
if (minute()<10) fisier.print("0");
fisier.print(minute());
fisier.print(":");
if (second()<10) fisier.print("0");
fisier.print(second());
fisier.print(" : ");
//digitalWrite(led, LOW);
fisier.print(Sensor1Data);
fisier.print(" + ");
fisier.print(Sensor2Data);
fisier.print(" + ");
fisier.print(Sensor3Data);
fisier.print(" + ");
fisier.print(Sensor4Data);
fisier.print(" = ");
fisier.println(suma);
// Turn off light to and await next message
j=j++; // count the message
}
memset( StringReceived, 0, sizeof( StringReceived));// This line is for reset the StringReceived
}
Sketch-ul de emitator este ultimul din prima parte.Pentru a putea conecta modulul SD, care folosea pinul D11, a trebuit sa conectez receptorul la alt pin liber si am ales pe D7.
Mesajul de pe monitorizarea seriala, respectiv din fisierul text creat sunt:
Niciun comentariu:
Trimiteți un comentariu