joi, 3 octombrie 2013

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

date transmise prin radio la un afisaj LCD cu 16 coloane si 2 randuri conectat prin modul i2c la Arduino

   In continuarea celor 2 parti, voi arata valorile primite de la emitator pe un afisaj LCD 16x2 (1602 = 16 coloane si 2 randuri, care este conectat la placa Arduino prin intermediul modului i2c.
   Schema de conectare este:
   Vreau sa afisez cele 4 valori numerice, numarul pachetului de date si timpul dintre pachetul de date si pana apare urmatorul... pentru a stii daca-s probleme de receptie:
   Am adaptat si scris urmatorul sketch pentru receptor:
/*.............................................................
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 Sensor3Data;
int Sensor4Data;
  
char StringReceived[22]; 

// 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.print(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,%d,%d,%d,%d",&Sensor1Data, &Sensor2Data,&Sensor3Data,&Sensor4Data); // Converts a string to an array
digitalWrite(led, LOW);        


lcd.setCursor(0, 0);
lcd.print(Sensor1Data);
lcd.print("&");
lcd.print(Sensor2Data);
lcd.print("&");
lcd.setCursor(0, 1);
lcd.print(Sensor3Data);
lcd.print("&");
lcd.print(Sensor3Data);

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");
}
   Pentru emitator am folosit tot sketch-ul prezentat la finalul primei parti.
 
   Pentru a fi mai explicit, am facut un mic filmulet cu telefonul (de asta e calitatea foarte scazuta), care se numeste Tx/Rx on 433MHz, 4 value send and displayed on 16x2 LCD:
   Daca tot am ajuns sa folosesc LCD-ul, am mers mai departe si am conectat la emitator senzorul DHT11 care masoara temperatura si umiditatea, similar cu articolul Ministatie meteo cu senzorul DHT11 si.. Arduino, doar ca acum o sa fie "uairles" (wireless), adica fara fir...



   Filmuletul demonstrativ (tot de o calitatea indoielnica) se numeste temperature and humidity from DTH11 send on 433Mhz to another Arduino with i2c LCD1602
   Pentru ca-s "baiat bun" pun si cele 2 sketch-uri: - pentru emitator:
/*.............................................................
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>

#include "DHT.h"
#define DHTPIN A2     // what pin we're connected to
#define DHTTYPE DHT11   // DHT 11 
DHT dht(DHTPIN, DHTTYPE);

int ledPin = 13;
char Sensor1CharMsg[21];// The string that we are going to send trought rf 
 
void setup() {
  dht.begin();  // initialing the DHT sensor
 
 // 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 Sensor1Data = dht.readHumidity();
  int Sensor2Data = dht.readTemperature();;
   
  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);
}
- pentru receptor:
/*.............................................................
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 h, t;
 
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);        
h = Sensor1Data;
t = Sensor2Data;

/*
lcd.setCursor(0, 0);
lcd.print(Sensor1Data);
lcd.print("&");
lcd.print(Sensor2Data);
lcd.print("&");
lcd.setCursor(0, 1);
//lcd.print(Sensor3Data);
//lcd.print("&");
//lcd.print(Sensor3Data);
*/
    lcd.setCursor(0, 0);
    lcd.print("temp="); 
    lcd.print(t);
    lcd.write(0b11011111);
    lcd.print("C");
    lcd.setCursor(0, 1);
    lcd.print("umid="); 
    lcd.print(h);
    lcd.print("%");

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");
}

4.10.2013
    Un filmulet de o calitate mai buna, se numeste temperature and humidity from DHT11 send on 433MHz to another Arduino with i2c LCD1602 (II)
8.10.2013
    Am inlocuit placuta mea Arduiniq (Arduino de casa) cu placa primita de la Nelu:
apoi am schimbat rolurile:
iar senzorul DHT11 masoara temperatura si umiditatea de afara...
   Dupa cum se constata e cam frig si cam umed afara:
   Am facut un filmulet cu noua configuratie, care se numeste temperature and humidity from DHT11 send on 433MHz to another Arduino with i2c LCD1602 (III):

Niciun comentariu:

Trimiteți un comentariu