ola pessoal to criando uma rede rs485 com dois arduinos, cada arduino possui cartao de memoria, clock e dois dht 11 nao estou conseguindo programar os dois dht 11 no arduino e nem enviando os dados para a memoria alguem pode me ajudar

quem souber da pra negociar ate porque estuo atrasada com esse trabalho

ate

Exibições: 551

Responder esta

Respostas a este tópico

Não entendi bem sua dificuldade.

Fizemos uma rede RS485 para instalar o scadabr como mestre e arduinos como escravos.Descreve um pouco mais.

pessola tem esse codigo ele compila porem o problema e que os dados nao estao sendo enviados para o cartao de memoria, os dados aparecem na tela mas nao vao para o cartao aparece o erro " "error opening datalog.txt"

agradeço se alguem me disse o que ta errado

obrigada

#include <DHT.h>
#include <stdio.h>
#include <string.h>
#include <DS1302.h>
#include <SD.h>
/*  SD CARD
  ** MOSI - pin 11
 ** MISO - pin 12
 ** CLK - pin 13
 ** CS - pin 10
 */

//DHT 11
// 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

#define DHTPINA 3  
#define DHTPINB 13
#define DHTTYPE DHT11   // definir o tipo de DHT utilizado: DHT11
DHT dht(DHTPINB,DHTTYPE);
DHT dht1(DHTPINA,DHTTYPE);
// CLOCK DS1302
/* coneção dos principais pinos do modulo RTC:
   pino VCC do modulo na alimentação de 5V do arduino;
   pino GND do modulo no GND do arduino;
   pino RST no pino 5 do arduino;
   pino DAT no pino 6 do arduino;
   pino CLK no pino 7 do arduino */
uint8_t RST = 5;
uint8_t DAT = 6;
uint8_t CLK = 7;
char buf[50];
char day[10];
DS1302 rtc(RST, DAT, CLK);


void print_time()
{
  Time t = rtc.time();
  /* Nome do dia da semana */
  memset(day, 0, sizeof(day));  /* clear day buffer */
  switch (t.day) {
    case 1:       strcpy(day, "Domingo");       break;
    case 2:       strcpy(day, "Segunda");      break;
    case 3:      strcpy(day, "Terca");      break;
    case 4:      strcpy(day, "Quarta");      break;
    case 5:      strcpy(day, "Quinta");      break;
    case 6:      strcpy(day, "Sexta");      break;
    case 7:      strcpy(day, "Sabado");      break;
  }
   snprintf(buf, sizeof(buf), "%s %04d-%02d-%02d %02d:%02d:%02d",
           day,
           t.yr, t.mon, t.date,
           t.hr, t.min, t.sec);
   Serial.print( buf );
   
}

void setup() {
  Serial.begin(9600);
 //SD CARD
 
  Serial.print("Initializing SD card...");
  // make sure that the default chip select pin is set to
  // output, even if you don't use it:
  pinMode(10, OUTPUT);
   // see if the card is present and can be initialized:
  if (!SD.begin(4)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    return;
  }
  Serial.println("card initialized.");
 
  //DHT11
  dht.begin();
  dht1.begin();
  //RTC CLOCK DS 1302
  // Initialize a new chip by turning off write protection and clearing the
     //clock halt flag. These methods needn't always be called. See the DS1302
     //datasheet for details.
 rtc.write_protect(false);
  rtc.halt(false);
  Time t(2013,06,04, 13, 23, 00, 6);
  rtc.time(t);
}

void loop() {
 
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  float l = dht1.readHumidity();
  float m = dht1.readTemperature();
    // imprimir na tela
    Serial.print("ARDUINO 1: ");
    print_time();
    Serial.print("  Umidade 1: ");
    Serial.print(h);
    Serial.print("%\t");
    Serial.print("  Temperatura 1: ");
    Serial.print(t);
    Serial.print("*C");
    Serial.print("   Umidade 2:");
    Serial.print(l);
    Serial.print("%\t");
    Serial.print("Temperatura 2: ");
    Serial.print(m);
    Serial.println("*C");
 
   
 // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
 
  File datafile = SD.open("datalog.txt", FILE_WRITE);
  // if the file is available, write to it:
  if (datafile) {
    datafile.println("ARDUINO 1: ");
    print_time();
    datafile.println("  Umidade 1: ");
    datafile.println(h);
    datafile.close();
   
  }  
  // if the file isn't open, pop up an error:
  else {
    Serial.println("error opening datalog.txt");
  }  
  delay(100);
 
}

RSS

© 2024   Criado por Marcelo Rodrigues.   Ativado por

Badges  |  Relatar um incidente  |  Termos de serviço