miercuri, 9 octombrie 2013

Module de transmisie/receptie radio si... Arduino (IV)

2 temperaturi citite cu LM335 transmise prin radio la un afisaj LCD cu 16 coloane si 2 randuri conectat prin adaptor i2c la Arduino

   Fata de precedentele articole, voi conecta 2 senzori de temperatura LM335 (pe care i-am prezentat aici) la o placa Arduino si sa transmit datele cu ajutorul unui modul de emisie pe frecventa de 433MHz, apoi voi receptiona datele cu ajutorul altei placi Arduino si voi afisa datele pe un ecran LCD cu 16 coloane si 2 randuri, conectat prin adaptor i2c. 
   Schema de conectare este:
   Un senzor este conectat la intrarea analogica 0, iar celalalt la intrarea analogica 1. Pentru a conecta usor si emitatorul si senzorii, am facut un mic montaj, un "brick":
   Poate parea ciudata schema asta, dar in mare are o bareta mama cu 8 pini, o bareta tata cu 2 pini pentru masa (gnd), o bareta tata cu 3 pini pentru +5V, 2 senzori LM335, unul conectat prin cablu de 1m, iar celalalt pus in bareta mama (pentru a putea testa si alte LM-uri 335)...
   Modulul conectat la placa Arduiono arata asa:
   Am scos un senzor pe fereastra si am alimentat placa Arduino cu un alimentator extern (nu apare in poza):
   Receptorul cu Arduino si afisaj LCD cu adaptor i2c:
   Am facut un filmulet explicativ, care se numeste two LM335 temperature transmission to a display wirelessly using Arduino (I):

   Programul (sketch-ul) pentru emitator este: 
/*.............................................................
Sending Multiple Variables Using VirtualWire. Transmitter
Author: Rodrigo Mompo Redoli
For controlrobotics.rodrigomompo.com
adapted sketch by niq_ro (Nicu FLORICA) from http://nicuflorica.blogspot.com  
..............................................................*/
#include <VirtualWire.h>

int t10 = 0; // initial temperature no.1 value;
int t20 = 0; // initial temperature no.2 value;
int t1 = 0.00; // initial calculated temperature no.1 value; 
int t2 = 0.00; // initial calculated temperature no.2 value; 

int temperaturePin1 = A0; // output from first LM335 is put at analog input no.0
int temperaturePin2 = A1; // output from second LM335 is put at analog input no.1

int ledPin = 13;
char Sensor1CharMsg[21];// The string that we are going to send trought rf 
 
void setup() {

 
 // LED 
 pinMode(ledPin,OUTPUT);
  
 
 // VirtualWire setup
 vw_setup(2000); // Bits per sec
 vw_set_tx_pin(12);// Set the Tx pin. Default is 12
 
}
 
void loop() {
  digitalWrite(ledPin, HIGH);  

  // Read and store Sensor Data

int t11 = 0;
int t21 = 0;
  for (int x=1; x <= 5; x++)
  {
// calculate the value  
t1 = analogRead(temperaturePin1); // read value from temperature from first sensor (LM335);
// t10 = 100.0*(5.0*t1/1023.0-2.980)+25.0;
//t11 = t10 + t1;
t11 = t11 + t1;

t2 = analogRead(temperaturePin2); // read value from temperature from second sensor (LM335);
//t20 = 100.0*(5.0*t1/1023.0-2.980)+25.0;
//t21 = t20 + t2;
t21 = t21 + t2;

delay (200);
  }   

int Sensor1Data = t11/5.0 ; // average and corrected temperature  
int Sensor2Data = t21/5.0;  // average and corrected temperature  

   
  sprintf(Sensor1CharMsg, "%d,%d", Sensor1Data, Sensor2Data);
  
 // Turn on a light to show transmitting
 vw_send((uint8_t *)Sensor1CharMsg, strlen(Sensor1CharMsg));
 vw_wait_tx(); // Wait until the whole message is gone

 // Turn off a light after transmission
 delay(100);
 digitalWrite(ledPin, LOW); 
 delay(3000);
 }
iar sketch-ul de receptor este:
/*.............................................................
Sending Multiple Variables Using VirtualWire. Receiver
Author: Rodrigo Mompo Redoli
For http://controlrobotics.rodrigomompo.com
adapted sketch by niq_ro (Nicu FLORICA) from http://nicuflorica.blogspot.com
..............................................................*/

#include <Wire.h> // use Wire library for protocol i2c (A4 = SDA & A5 = SCL)
#include <LiquidCrystal_I2C.h> // use LiquidCrystal_I2C library for control LCD on i2c protocol
LiquidCrystal_I2C lcd(0x20,16,2); // 0x20 is adresss for LCC 16x2

#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

// Sensors 
int Sensor1Data;
int Sensor2Data;
int t1, t2;
float t10, t20;
 
char StringReceived[21]; 

// other  
int led = 13; //pin for LED
int j=1; // count the messages
int timp1, timp2, dt; // times  

void setup() {
  lcd.init(); // initialing the LCD display
  lcd.backlight(); //backlight is now ON
  lcd.begin(16, 2); // set up the LCD's number of columns and rows: 
  
   // 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 
    // 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();       

 lcd.setCursor(1, 0); // put cursor at colon 2 and row 0 = left/up
 lcd.print("niq_ro's rx is"); // print a text
 lcd.setCursor(1, 1); // put cursor at colon 0 and row 0 = left/down
 lcd.print("ready on 433MHz"); // print a text
 delay (2000);
 lcd.clear(); // clear the screen
 lcd.setCursor(14, 0); 
 lcd.print("0/");
timp2 = 0; 
} // 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);
// put the data number from begin
   lcd.clear(); // clear the screen
if (j<10) lcd.setCursor(14, 0); // put cursor at colon 14 and row 1
if ((j>=10) and (j<100)) lcd.setCursor(13, 0); // put cursor at colon 13 and row 1
if ((j>=100) and (j<1000)) lcd.setCursor(12, 0); // put cursor at colon 12 and row 1
if ((j>=1000) and (j<10000)) lcd.setCursor(11, 0); // put cursor at colon 11 and row 1  
   lcd.print(j);
   lcd.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",&Sensor1Data, &Sensor2Data); // Converts a string to an array
digitalWrite(led, LOW);        
t1 = Sensor1Data;
t2 = Sensor2Data;

t10 = (100.0*(5.0*t1/1023.0-2.980)+25.0)-1.0;
t20 = (100.0*(5.0*t2/1023.0-2.980)+25.0);


    lcd.setCursor(0, 0);
    lcd.print("t1="); 
    if (t10<10) lcd.print(" "); 
    if (t10>0.0) lcd.print("+"); 
    lcd.print(t10,1);
    lcd.write(0b11011111);
    lcd.print("C");
    lcd.setCursor(0, 1);
    lcd.print("t2="); 
    if (t20<10) lcd.print(" "); 
    if (t20>0.0) lcd.print("+"); 
    lcd.print(t20,1);
    lcd.write(0b11011111);
    lcd.print("C");


timp2 = timp1; // new time replace olt time;
j=j++; // count the message         

 memset( StringReceived, 0, sizeof( StringReceived));// This line is for reset the StringReceived

}


// calculate time from last data received
timp1 = hour()*3600 + minute()*60 + second();
dt = timp1-timp2;

if (dt<10) lcd.setCursor(14, 1); // put cursor at colon 14 and row 1
if ((dt>=10) and (dt<100)) lcd.setCursor(13, 1); // put cursor at colon 13 and row 1
if ((dt>=100) and (dt<1000)) lcd.setCursor(12, 1); // put cursor at colon 12 and row 1
if ((dt>=1000) and (dt<10000)) lcd.setCursor(11, 1); // put cursor at colon 11 and row 1
  lcd.print(dt);
  lcd.print("s");
}

   - va urma -

Niciun comentariu:

Trimiteți un comentariu