Totalul afișărilor de pagină

test imagine

joi, 10 octombrie 2013

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

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


   Deoarece m-am gandit ca nu toata lumea foloseste comanda afisajului LCD pe 2 fire (i2c), adica nu are acea interfata, m-am apucat sa conectez afisajul clasic, cu 6 fire utile (si 2 alimentare):
   Schema de conectare a modulului de emisie si a celor 2 senzori de temperatura LM335Z la placa Arduino este aceeasi ca cea din articolul anterior:
   La partea de receptor, se schimba modul de conectare:


   Initial, am incercat sa folosesc configuratia din exemplele Arduino, adica asta:
si sa conectez receptorul la pinul 7.. am constatat ca se bloc ca activare apartii de receptor, am conectat si la alti pini si aceeasi eroare, asa ca m-am ami uitat pe documentatia librariei WirtualWre (vezi explicatiile de la skyduino.wordpress.com si mi-am dat seama ca foloseam pinul D11 (digital 11), asa ca am modificat configuratia cum e prezentat mai sus...
   Sketch-ul pentru receptor devine:
  
/*.............................................................
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
version 5.1
..............................................................*/

#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
/*                                    -------------------
                                      |  LCD  | Arduino |
                                      -------------------
 LCD RS pin to digital pin 7          |  RS   |   D7    |
 LCD Enable pin to digital pin 6      |  E    |   D6    |
 LCD D4 pin to digital pin 5          |  D4   |   D5    |
 LCD D5 pin to digital pin 4          |  D5   |   D4    |
 LCD D6 pin to digital pin 3          |  D6   |   D3    |
 LCD D7 pin to digital pin 2          |  D7   |   D2    |
 LCD R/W pin to ground                |  R/W  |   GND   |
                                      -------------------
*/
#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.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); 
 lcd.print("Arduino is ready"); // print a text
// VirtualWire 
    // Bits per sec
    vw_setup(2000);
    // set pin for connect receiver module 
    vw_set_rx_pin(11);  
    // Start the receiver PLL running
    vw_rx_start();
    
 delay (500);
 lcd.clear(); // clear the screen
 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");
}
   
   Am facut is un mic filmulet, numit two LM335 temperature transmission to a display wirelessly using Arduino (II):


Niciun comentariu:

Trimiteți un comentariu