Gostaria de saber quais os tipos de logger estão sendo usados para aquisição de dados, dos sensores?

Exibições: 386

Respostas a este tópico

Arduino + SD Card

Murilo eu tenho uma estação da spark fun, e os codigos de um LM35, RHt03 e um BPM085 todos os sensores e codigos eu consegui testar  de forma separada porem não consegui juntar todos os codigos em um só, para rodar simuntaneo, vc poderia me ajudar...?

#include <Wire.h>

 

#define BMP085_ADDRESS 0x77  // I2C address of BMP085

 

const unsigned char OSS = 0;  // Oversampling Setting

 

// Calibration values

int ac1;

int ac2;

int ac3;

unsigned int ac4;

unsigned int ac5;

unsigned int ac6;

int b1;

int b2;

int mb;

int mc;

int md;

 

// b5 is calculated in bmp085GetTemperature(...), this variable is also used in bmp085GetPressure(...)

// so ...Temperature(...) must be called before ...Pressure(...).

long b5;

 

void setup(){

  Serial.begin(9600);

  Wire.begin();

 

  bmp085Calibration();

}

 

void loop()

{

  float temperature = bmp085GetTemperature(bmp085ReadUT()); //MUST be called first

  float pressure = bmp085GetPressure(bmp085ReadUP());

  float atm = pressure / 101325; // "standard atmosphere"

  float altitude = calcAltitude(pressure); //Uncompensated caculation - in Meters

 

  Serial.print("Temperatura: ");

  Serial.print(temperature, 2); //display 2 decimal places

  Serial.println("deg C");

 

  Serial.print("Pressao : ");

  Serial.print(pressure, 0); //whole number only.

  Serial.println(" Pa");

 

  Serial.print("Standard Atmosphere: ");

  Serial.println(atm, 4); //display 4 decimal places

 

  Serial.print("Altitude: ");

  Serial.print(altitude, 2); //display 2 decimal places

  Serial.println(" M");

 

  Serial.println();//line break

 

  delay(1000); //wait a second and get values again.

}

 

// Stores all of the bmp085's calibration values into global variables

// Calibration values are required to calculate temp and pressure

// This function should be called at the beginning of the program

void bmp085Calibration()

{

  ac1 = bmp085ReadInt(0xAA);

  ac2 = bmp085ReadInt(0xAC);

  ac3 = bmp085ReadInt(0xAE);

  ac4 = bmp085ReadInt(0xB0);

  ac5 = bmp085ReadInt(0xB2);

  ac6 = bmp085ReadInt(0xB4);

  b1 = bmp085ReadInt(0xB6);

  b2 = bmp085ReadInt(0xB8);

  mb = bmp085ReadInt(0xBA);

  mc = bmp085ReadInt(0xBC);

  md = bmp085ReadInt(0xBE);

}

 

// Calculate temperature in deg C

float bmp085GetTemperature(unsigned int ut){

  long x1, x2;

 

  x1 = (((long)ut - (long)ac6)*(long)ac5) >> 15;

  x2 = ((long)mc 11)/(x1 + md);

  b5 = x1 + x2;

 

  float temp = ((b5 + 8)>>4);

  temp = temp /10;

 

  return temp;

}

 

// Calculate pressure given up

// calibration values must be known

// b5 is also required so bmp085GetTemperature(...) must be called first.

// Value returned will be pressure in units of Pa.

long bmp085GetPressure(unsigned long up){

  long x1, x2, x3, b3, b6, p;

  unsigned long b4, b7;

 

  b6 = b5 - 4000;

  // Calculate B3

  x1 = (b2 * (b6 * b6)>>12)>>11;

  x2 = (ac2 * b6)>>11;

  x3 = x1 + x2;

  b3 = (((((long)ac1)*4 + x3)OSS) + 2)>>2;

 

  // Calculate B4

  x1 = (ac3 * b6)>>13;

  x2 = (b1 * ((b6 * b6)>>12))>>16;

  x3 = ((x1 + x2) + 2)>>2;

  b4 = (ac4 * (unsigned long)(x3 + 32768))>>15;

 

  b7 = ((unsigned long)(up - b3) * (50000>>OSS));

  if (b7 < 0x80000000)

    p = (b71)/b4;

  else

    p = (b7/b4)1;

 

  x1 = (p>>8) * (p>>8);

  x1 = (x1 * 3038)>>16;

  x2 = (-7357 * p)>>16;

  p += (x1 + x2 + 3791)>>4;

 

  long temp = p;

  return temp;

}

 

// Read 1 byte from the BMP085 at 'address'

char bmp085Read(unsigned char address)

{

  unsigned char data;

 

  Wire.beginTransmission(BMP085_ADDRESS);

  Wire.write(address);

  Wire.endTransmission();

 

  Wire.requestFrom(BMP085_ADDRESS, 1);

  while(!Wire.available())

    ;

 

  return Wire.read();

}

 

// Read 2 bytes from the BMP085

// First byte will be from 'address'

// Second byte will be from 'address'+1

int bmp085ReadInt(unsigned char address)

{

  unsigned char msb, lsb;

 

  Wire.beginTransmission(BMP085_ADDRESS);

  Wire.write(address);

  Wire.endTransmission();

 

  Wire.requestFrom(BMP085_ADDRESS, 2);

  while(Wire.available()<2)

    ;

  msb = Wire.read();

  lsb = Wire.read();

 

  return (int) msb8 | lsb;

}

 

// Read the uncompensated temperature value

unsigned int bmp085ReadUT(){

  unsigned int ut;

 

  // Write 0x2E into Register 0xF4

  // This requests a temperature reading

  Wire.beginTransmission(BMP085_ADDRESS);

  Wire.write(0xF4);

  Wire.write(0x2E);

  Wire.endTransmission();

 

  // Wait at least 4.5ms

  delay(5);

 

  // Read two bytes from registers 0xF6 and 0xF7

  ut = bmp085ReadInt(0xF6);

  return ut;

}

 

// Read the uncompensated pressure value

unsigned long bmp085ReadUP(){

 

  unsigned char msb, lsb, xlsb;

  unsigned long up = 0;

 

  // Write 0x34+(OSS6) into register 0xF4

  // Request a pressure reading w/ oversampling setting

  Wire.beginTransmission(BMP085_ADDRESS);

  Wire.write(0xF4);

  Wire.write(0x34 + (OSS6));

  Wire.endTransmission();

 

  // Wait for conversion, delay time dependent on OSS

  delay(2 + (3OSS));

 

  // Read register 0xF6 (MSB), 0xF7 (LSB), and 0xF8 (XLSB)

  msb = bmp085Read(0xF6);

  lsb = bmp085Read(0xF7);

  xlsb = bmp085Read(0xF8);

 

  up = (((unsigned long) msb 16) | ((unsigned long) lsb 8) | (unsigned long) xlsb) >> (8-OSS);

 

  return up;

}

 

void writeRegister(int deviceAddress, byte address, byte val) {

  Wire.beginTransmission(deviceAddress); // start transmission to device

  Wire.write(address);       // send register address

  Wire.write(val);         // send value to write

  Wire.endTransmission();     // end transmission

}

 

int readRegister(int deviceAddress, byte address){

 

  int v;

  Wire.beginTransmission(deviceAddress);

  Wire.write(address); // register to read

  Wire.endTransmission();

 

  Wire.requestFrom(deviceAddress, 1); // read a byte

 

  while(!Wire.available()) {

    // waiting

  }

 

  v = Wire.read();

  return v;

}

 

float calcAltitude(float pressure){

 

  float A = pressure/101325;

  float B = 1/5.25588;

  float C = pow(A,B);

  C = 1 - C;

  C = C /0.0000225577;

 

  return C;

}

Codigo do LM35 e RHT03 Juntos

// teste dos sensores umidade e temperatura projeto UFMS

#include "DHT.h"

#define DHTPIN 4     // what pin we're connected to

// Uncomment whatever type you're using!

//#define DHTTYPE DHT11   // DHT 11

#define DHTTYPE DHT22   // DHT 22  (AM2302)

//#define DHTTYPE DHT21   // DHT 21 (AM2301)

// Connect pin 1 (on the left) of the sensor to +5V

// Connect pin 2 of the sensor to whatever your DHTPIN is

// Connect pin 4 (on the right) of the sensor to GROUND

// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

DHT dht(DHTPIN, DHTTYPE);

const int LM35 = A0; // Pino Analogico onde vai ser ligado ao pino 2 do LM35

const int REFRESH_RATE = 2000;  //Tempo de atualização entre as leituras em ms

const float CELSIUS_BASE = 0.4887585532746823069403714565; //Base de conversão para Graus Celsius ((5/1023) * 100)

void setup() {

  Serial.begin(9600);

  Serial.println("Teste do sensor de umidade e de temperatura UFMS!");

  dht.begin();

}

void loop() {

  // Reading temperature or humidity takes about 250 milliseconds!

  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)

  float h = dht.readHumidity();

  float t = dht.readTemperature();

  Serial.print("Temperatura 1: LM35 ");

  Serial.println(readTemperature());

  delay(REFRESH_RATE);

  // check if returns are valid, if they are NaN (not a number) then something went wrong!

  if (isnan(t) || isnan(h)) {

    Serial.println("Falha no sensor de umidade DHT");

  } else {

    Serial.print("Umidade: "); 

    Serial.print(h);

    Serial.print(" %\t");

    Serial.print("Temperatura 2: ");

    Serial.print(t);

    Serial.println(" *C");

  }

}

float readTemperature(){

  return (analogRead(LM35) * CELSIUS_BASE);

}

Codigo do Direção e velocidade do vento e pluviometro Junstos

#define uint  unsigned int

#define ulong unsigned long

 

#define PIN_ANEMOMETER  2     // Digital 2

#define PIN_VANE        5     // Analog 5

 

 

// How often we want to calculate wind speed or direction

#define MSECS_CALC_WIND_SPEED 5000

#define MSECS_CALC_WIND_DIR   5000

 

 

volatile int numRevsAnemometer = 0; // Incremented in the interrupt

ulong nextCalcSpeed;                // When we next calc the wind speed

ulong nextCalcDir;                  // When we next calc the direction

ulong time;                         // Millis() at each start of loop().

 

// ADC readings:

#define NUMDIRS 8

ulong   adc[NUMDIRS] = {26, 45, 77, 118, 161, 196, 220, 256};

 

 

char *strVals[NUMDIRS] = {"W","NW","N","SW","NE","S","SE","E"};

byte dirOffset=0;

 

 

void setup()

{

   Serial.begin(9600);

   pinMode(PIN_ANEMOMETER, INPUT);

   digitalWrite(PIN_ANEMOMETER, HIGH);

   attachInterrupt(0, countAnemometer, FALLING);

   nextCalcSpeed = millis() + MSECS_CALC_WIND_SPEED;

   nextCalcDir   = millis() + MSECS_CALC_WIND_DIR;

}

 

//=======================================================

// Main loop.

//=======================================================

void loop()

{

   time = millis();

 

   if (time >= nextCalcSpeed)

   {

      calcWindSpeed();

      nextCalcSpeed = time + MSECS_CALC_WIND_SPEED;

   if (nextCalcSpeed > nextCalcDir)   {

      calcWindDir();

      nextCalcDir = time + MSECS_CALC_WIND_DIR;

   }

  }

}

//=======================================================

// Interrupt handler for anemometer. Called each time the reed

// switch triggers (one revolution).

//=======================================================

void countAnemometer() {

   numRevsAnemometer++;

}

 

//=======================================================

// Calculate the wind speed, and display it (or log it, whatever).

// 1 rev/sec = 1.492 mph

//=======================================================

void calcWindSpeed()

{

   int x, iSpeed;

   // This will produce mph * 10

   // (didn't calc right when done as one statement)

   long speed = 24011;

   speed *= numRevsAnemometer;

   speed /= MSECS_CALC_WIND_SPEED;

   iSpeed = speed;         // Need this for formatting below

 

   Serial.println("Velocidade do Vento: ");

   x = iSpeed / 10;

   Serial.print(x);

   Serial.print(" KM/h");

   Serial.println("");

 

   numRevsAnemometer = 0;        // Reset counter

}

 

void calcWindDir() {

       int val;

   byte x, reading;

 

   val = analogRead(PIN_VANE);

   val >>=2;                        // Shift to 255 range

   reading = val;

 

   // Look the reading up in directions table. Find the first value

   // that's >= to what we got.

   for (x=0; x<NUMDIRS; x++) {

      if (adc[x] >= reading)

         break;

   }

   //Serial.println(reading, DEC);

   x = (x + dirOffset) % 8;   // Adjust for orientation

   Serial.print("  Dir: ");

   Serial.println(strVals[x]);

}

Olá Ramon, amanhã cedo vou montar pra voceê, blz? Tenho um código mais simples para o BMP

Fico no aguardo! se puder passar seu contato e-mail ou whats? eu to desenvolvendo uma pesquisa ambiental e tô com sérios problemas kkkk, mas desde já agradeço!

Testa esse código aí rsrs

#include <Wire.h>
#include "DHT.h"

#define uint unsigned int
#define ulong unsigned long
#define PIN_ANEMOMETER 2
#define PIN_VANE 5

#define DHTPIN 4
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);

#define MSECS_CALC_WIND_SPEED 5000
#define MSECS_CALC_WIND_DIR 5000

#define BMP085_ADDRESS 0x77

const int LM35 = A0; // Pino Analogico onde vai ser ligado ao pino 2 do LM35
const int REFRESH_RATE = 2000; //Tempo de atualização entre as leituras em ms
const float CELSIUS_BASE = 0.4887585532746823069403714565; //Base de conversão para Graus Celsius ((5/1023) * 100)
const unsigned char OSS = 0; // Oversampling Setting

volatile int numRevsAnemometer = 0; // Incremented in the interrupt
ulong nextCalcSpeed; // When we next calc the wind speed
ulong nextCalcDir; // When we next calc the direction
ulong time; // Millis() at each start of loop().

// ADC readings:
#define NUMDIRS 8
ulong adc[NUMDIRS] = {26, 45, 77, 118, 161, 196, 220, 256};


char *strVals[NUMDIRS] = {"W","NW","N","SW","NE","S","SE","E"};
byte dirOffset=0;

int ac1;
int ac2;
int ac3;
unsigned int ac4;
unsigned int ac5;
unsigned int ac6;
int b1;
int b2;
int mb;
int mc;
int md;

// b5 is calculated in bmp085GetTemperature(...), this variable is also used in bmp085GetPressure(...)
// so ...Temperature(...) must be called before ...Pressure(...).
long b5;

short temperature;
long pressure;

// Use these for altitude conversions
const float p0 = 101325; // Pressure at sea level (Pa)
float altitude;

void setup()
{
Serial.begin(9600);
Wire.begin();
bmp085Calibration();
Serial.println("Teste do sensor de umidade e de temperatura UFMS!");
dht.begin();
pinMode(PIN_ANEMOMETER, INPUT);
digitalWrite(PIN_ANEMOMETER, HIGH);
attachInterrupt(0, countAnemometer, FALLING);
nextCalcSpeed = millis() + MSECS_CALC_WIND_SPEED;
nextCalcDir = millis() + MSECS_CALC_WIND_DIR;
}

void loop()
{
//BMP

temperature = bmp085GetTemperature(bmp085ReadUT());
pressure = bmp085GetPressure(bmp085ReadUP());
altitude = (float)44330 * (1 - pow(((float) pressure/p0), 0.190295));

Serial.print("Temperature: ");
Serial.print(temperature, DEC);
Serial.println(" *0.1 deg C");
Serial.print("Pressure: ");
Serial.print(pressure, DEC);
Serial.println(" Pa");
Serial.print("Altitude: ");
Serial.print(altitude, 2);
Serial.println(" m");
Serial.println();

//DHT

float h = dht.readHumidity();
float t = dht.readTemperature();
Serial.print("Temperatura 1: LM35 ");
Serial.println(readTemperature());
delay(REFRESH_RATE);

if (isnan(t) || isnan(h)) {
Serial.println("Falha no sensor de umidade DHT");
} else {
Serial.print("Umidade: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperatura 2: ");
Serial.print(t);
Serial.println(" *C");
}
}
float readTemperature(){
return (analogRead(LM35) * CELSIUS_BASE);

//ANEMOMETRO PLUVIOMETRO E DIREÇÃO DO VENTO

time = millis();

if (time >= nextCalcSpeed)
{
calcWindSpeed();
nextCalcSpeed = time + MSECS_CALC_WIND_SPEED;
if (nextCalcSpeed > nextCalcDir) {
calcWindDir();
nextCalcDir = time + MSECS_CALC_WIND_DIR;
}
}

delay(1000);
}

// Stores all of the bmp085's calibration values into global variables
// Calibration values are required to calculate temp and pressure
// This function should be called at the beginning of the program
void bmp085Calibration()
{
ac1 = bmp085ReadInt(0xAA);
ac2 = bmp085ReadInt(0xAC);
ac3 = bmp085ReadInt(0xAE);
ac4 = bmp085ReadInt(0xB0);
ac5 = bmp085ReadInt(0xB2);
ac6 = bmp085ReadInt(0xB4);
b1 = bmp085ReadInt(0xB6);
b2 = bmp085ReadInt(0xB8);
mb = bmp085ReadInt(0xBA);
mc = bmp085ReadInt(0xBC);
md = bmp085ReadInt(0xBE);
}

// Calculate temperature given ut.
// Value returned will be in units of 0.1 deg C
short bmp085GetTemperature(unsigned int ut)
{
long x1, x2;

x1 = (((long)ut - (long)ac6)*(long)ac5) >> 15;
x2 = ((long)mc 11)/(x1 + md);
b5 = x1 + x2;

return ((b5 + 8)>>4);
}

// Calculate pressure given up
// calibration values must be known
// b5 is also required so bmp085GetTemperature(...) must be called first.
// Value returned will be pressure in units of Pa.
long bmp085GetPressure(unsigned long up)
{
long x1, x2, x3, b3, b6, p;
unsigned long b4, b7;

b6 = b5 - 4000;
// Calculate B3
x1 = (b2 * (b6 * b6)>>12)>>11;
x2 = (ac2 * b6)>>11;
x3 = x1 + x2;
b3 = (((((long)ac1)*4 + x3)OSS) + 2)>>2;

// Calculate B4
x1 = (ac3 * b6)>>13;
x2 = (b1 * ((b6 * b6)>>12))>>16;
x3 = ((x1 + x2) + 2)>>2;
b4 = (ac4 * (unsigned long)(x3 + 32768))>>15;

b7 = ((unsigned long)(up - b3) * (50000>>OSS));
if (b7 < 0x80000000)
p = (b71)/b4;
else
p = (b7/b4)1;

x1 = (p>>8) * (p>>8);
x1 = (x1 * 3038)>>16;
x2 = (-7357 * p)>>16;
p += (x1 + x2 + 3791)>>4;

return p;
}

// Read 1 byte from the BMP085 at 'address'
char bmp085Read(unsigned char address)
{
unsigned char data;

Wire.beginTransmission(BMP085_ADDRESS);
Wire.write(address);
Wire.endTransmission();

Wire.requestFrom(BMP085_ADDRESS, 1);
while(!Wire.available())
;

return Wire.read();
}

// Read 2 bytes from the BMP085
// First byte will be from 'address'
// Second byte will be from 'address'+1
int bmp085ReadInt(unsigned char address)
{
unsigned char msb, lsb;

Wire.beginTransmission(BMP085_ADDRESS);
Wire.write(address);
Wire.endTransmission();

Wire.requestFrom(BMP085_ADDRESS, 2);
while(Wire.available()<2)
;
msb = Wire.read();
lsb = Wire.read();

return (int) msb8 | lsb;
}

// Read the uncompensated temperature value
unsigned int bmp085ReadUT()
{
unsigned int ut;

// Write 0x2E into Register 0xF4
// This requests a temperature reading
Wire.beginTransmission(BMP085_ADDRESS);
Wire.write(0xF4);
Wire.write(0x2E);
Wire.endTransmission();

// Wait at least 4.5ms
delay(5);

// Read two bytes from registers 0xF6 and 0xF7
ut = bmp085ReadInt(0xF6);
return ut;
}

// Read the uncompensated pressure value
unsigned long bmp085ReadUP()
{
unsigned char msb, lsb, xlsb;
unsigned long up = 0;

// Write 0x34+(OSS6) into register 0xF4
// Request a pressure reading w/ oversampling setting
Wire.beginTransmission(BMP085_ADDRESS);
Wire.write(0xF4);
Wire.write(0x34 + (OSS6));
Wire.endTransmission();

// Wait for conversion, delay time dependent on OSS
delay(2 + (3OSS));

// Read register 0xF6 (MSB), 0xF7 (LSB), and 0xF8 (XLSB)
Wire.beginTransmission(BMP085_ADDRESS);
Wire.write(0xF6);
Wire.endTransmission();
Wire.requestFrom(BMP085_ADDRESS, 3);

// Wait for data to become available
while(Wire.available() < 3)
;
msb = Wire.read();
lsb = Wire.read();
xlsb = Wire.read();

up = (((unsigned long) msb 16) | ((unsigned long) lsb 8) | (unsigned long) xlsb) >> (8-OSS);

return up;
}

void countAnemometer() {
numRevsAnemometer++;
}

void calcWindSpeed()
{
int x, iSpeed;
// This will produce mph * 10
// (didn't calc right when done as one statement)
long speed = 24011;
speed *= numRevsAnemometer;
speed /= MSECS_CALC_WIND_SPEED;
iSpeed = speed; // Need this for formatting below

Serial.println("Velocidade do Vento: ");
x = iSpeed / 10;
Serial.print(x);
Serial.print(" KM/h");
Serial.println("");

numRevsAnemometer = 0; // Reset counter
}

void calcWindDir() {
int val;
byte x, reading;

val = analogRead(PIN_VANE);
val >>=2; // Shift to 255 range
reading = val;

// Look the reading up in directions table. Find the first value
// that's >= to what we got.
for (x=0; x<NUMDIRS; x++) {
if (adc[x] >= reading)
break;
}
//Serial.println(reading, DEC);
x = (x + dirOffset) % 8; // Adjust for orientation
Serial.print(" Dir: ");
Serial.println(strVals[x]);
}

Arduino + SD Card.

Na estação remota e na estação que recebe os dados.

Quem tem dois tem um.
Quem tem um não tem nenhum.... rssssss

Olá Marcus, tenho um código de um projeto que eu iniciei a um tempo atrás. É um arduino conectado a um DHT11 e a um BMP180, registrando em um SD Card.

Bom dia Murilo.

Tenho um DHT22 e u, BMP180.
Pode disponibilizar este código?

Olá, passo sim. Assim que chegar em casa eu mando.

Att Murilo LN

Obrigado

e-mail = nogueiramarcus@ymail.com

Marcus, o código está no meu PC, e só vou ter acesso a ele sábado. Pode ser? 

Desculpe a demora.

Claro, sem problemas

RSS

Destaques

Registre-se no
Lab de Garagem
Clicando aqui

Convide um
amigo para fazer
parte

curso gratis de arduino

© 2018   Criado por Marcelo Rodrigues.   Ativado por

Badges  |  Relatar um incidente  |  Termos de serviço