DHT11 не компилируется скетч

lean_74
Offline
Зарегистрирован: 22.12.2015

Подскажите, пожалуста, что не так? стоит раскоментировать строчку 98 или 99 выдает ошибку 

"collect2.exe: error: ld returned 5 exit status", типовой пример компилируется и работает, Ардуино нано 328 с загрузчиком optiboot, IDE 1.6.13

#include <avr/wdt.h>
#include <EEPROM.h>
#include "DHT.h"
#include <OneWire.h>
OneWire ds(7); 
#define START_CONVERT 0
#define READ_TEMP 1

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

//номера выводов кнопок
#define BUTTON1 3
#define BUTTON2 4
#define BUTTON3 5


//int counter=0;//для проверки вачдога

volatile uint8_t minut=0;
volatile uint8_t chas=0;
volatile uint8_t sec=0;
volatile uint8_t den=0;
//int i;
//int old_sec=0;
int temp=0; // температура Далласа
float temp2=0; // температура DHT
float hum=0;

void readSet(){
 den=EEPROM.read(0);
 chas=EEPROM.read(1);
 minut=EEPROM.read(2);
 sec=EEPROM.read(100);
  if (den>31){
    den=0; // 
  } 
  if (chas>24){
    chas=0; // 
  } 
  if (minut>60){
    minut=0; // 
  } 
  
}
  
void setup(){
   wdt_disable(); // запретили как можно скорее собаку, что-бы не уйти в бесконечный ребут
   Serial.begin(9600);
   readSet();
   dht.begin();

//для проверки вачдога    
//  Serial.println("Starting...");
//  delay(1000); // что-бы четче видеть рестар скетча
//для проверки вачдога  
 
  

//базовые настройки часов
TCCR1A=(1<<WGM11); //режим14 FAST PWM 
TCCR1B=(1<<CS12)|(1<<WGM13)|(1<<WGM12); //делить частоту CPU на 256
ICR1=62499;  // (16000000MHz /div256) -1 = 1 раз в секунду
TIMSK1=(1<<TOIE1); //разрешить прерывание

  tempProcess(START_CONVERT);//конвентируем dallas



  wdt_enable(WDTO_8S); // активировали таймер, каждые 8 секунд его нужно сбрасывать

}

ISR (TIMER1_OVF_vect) { 
sec++ ; //инкремент переменной каждую секунду 
  temp= tempProcess(READ_TEMP);//читаем темпратуру с далласа
  tempProcess(START_CONVERT); // сразу запрос на конвертацию

if (sec>59){sec=0; minut++;  } 
if (minut>59){minut=0; chas++; EEPROM.write(1, chas);} // при записи каждый час хватит памяти на 11 лет
if (chas>23){chas=0;den++; EEPROM.write(0, den);}// но нам главное знать день инкубации
if (den>30){den=0; } // частный случай для нас не принципиальный, у нас день инкубации
}

void loop(){
 wdt_reset(); // говорим собаке что "В Багдаде все спокойно", начинается очередной отсчет 8-х секунд.
  
//if (sec ==old_sec){i++;}
//else {i=0; old_sec=sec;}

 delay(2000);

  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
 
//  hum = dht.readHumidity();
//  temp2 = dht.readTemperature();
//   if (isnan(h) || isnan(t)) {
//    Serial.println("Failed to read from DHT sensor!");
//    return;
//  }
 
//  Serial.print("Temperature2 = ");
//  // Serial.print(temp); //если в целых *С
//  Serial.print(t);// Serial.print(",");Serial.print(temp%10);//если в десятых *C
//  Serial.println(" *C");
  Serial.print("Humidity = ");
  Serial.print(hum);// Serial.print(",");Serial.print(temp%10);//если в десятых *C
  Serial.println(" %");
// delay(1000);//только для примера

  Serial.print("Temperature = ");
  // Serial.print(temp); //если в целых *С
  Serial.print(temp/10); Serial.print(",");Serial.print(temp%10);//если в десятых *C
  Serial.println(" *C");
  
Serial.write("Day=");
Serial.print(den);
Serial.write(' ');

Serial.print(chas);
Serial.write(':');
Serial.print(minut);
Serial.write(':');
Serial.print(sec);
//Serial.write("  i=");
//Serial.print(i);

Serial.println();
//для проверки вачдога
//   Serial.println(counter); // Это проверка вачдога
//   counter++;
//   
//   if(counter==9){
//       Serial.println("visim....");
//
//      while(true){} // создаем зависание, через 8 секунды должен произойти ресет, так как не вызывается wdt_reset();
//   }
//   delay(500);
//для проверки вачдога
}
//============================== 
int tempProcess(boolean ch){
  int t=0; 
  if(!ch){
    ds.reset(); 
    ds.write(0xCC);
    ds.write(0x44);
  }
  else{
    ds.reset();
    ds.write(0xCC);
    ds.write(0xBE);
    t= ds.read(); 
    t = t | (ds.read()<<8); 
    //return  t>>4;//целые *C, десятые отброшены
    //return  (t+8)>>4;//целые *С с округлением
    return  (t*10)>>4;//целое в десятых *C (214=>21,4*C)
  }
}
// чтение
int EEPROM_int_read(int addr) {    
  byte raw[2];
  for(byte i = 0; i < 2; i++) raw[i] = EEPROM.read(addr+i);
  int &num = (int&)raw;
  return num;
}

// запись
void EEPROM_int_write(int addr, int num) {
  byte raw[2];
  (int&)raw = num;
  for(byte i = 0; i < 2; i++) EEPROM.write(addr+i, raw[i]);
}
//пример int
//// запись
//EEPROM_int_write(12, 1000); // адрес 12 (+2 байта)
//EEPROM_int_write(14, 2000); // адрес 14 (+2 байта)
//EEPROM_int_write(16, 3000); // адрес 16 (+2 байта)
//// чтение
//int d = EEPROM_int_read(12);
//int e = EEPROM_int_read(14);
//int f = EEPROM_int_read(16);

 

Jeka_M
Jeka_M аватар
Offline
Зарегистрирован: 06.07.2014

Проблема с Arduino IDE, точнее с линковщиком. Уже не раз обсуждалась.

https://www.google.com/search?q=collect2.exe%3A+error%3A+ld+returned+5+e...

lean_74
Offline
Зарегистрирован: 22.12.2015

Jeka_M пишет:

Проблема с Arduino IDE, точнее с линковщиком. Уже не раз обсуждалась.

https://www.google.com/search?q=collect2.exe%3A+error%3A+ld+returned+5+e...

Спасибо, конечно, но гуглом я пользоваться умею... там уже глядел, попробовал на других  IDE 1.6.5, 1.6.12 и почему тут же этот пример компилируется?

// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain

#include "DHT.h"

#define DHTPIN 11     // what digital pin we're connected to

// Uncomment whatever type you're using!
#define DHTTYPE DHT11   // DHT 11
//#define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321
//#define DHTTYPE DHT21   // DHT 21 (AM2301)

// Connect pin 1 (on the left) of the sensor to +5V
// NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1
// to 3.3V instead of 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

// Initialize DHT sensor.
// Note that older versions of this library took an optional third parameter to
// tweak the timings for faster processors.  This parameter is no longer needed
// as the current DHT reading algorithm adjusts itself to work on faster procs.
DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(9600);
  Serial.println("DHTxx test!");

  dht.begin();
}

void loop() {
  // Wait a few seconds between measurements.
  delay(2000);

  // 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();
  // Read temperature as Celsius (the default)
  float t = dht.readTemperature();
  // Read temperature as Fahrenheit (isFahrenheit = true)
  float f = dht.readTemperature(true);

  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  // Compute heat index in Fahrenheit (the default)
  float hif = dht.computeHeatIndex(f, h);
  // Compute heat index in Celsius (isFahreheit = false)
  float hic = dht.computeHeatIndex(t, h, false);

  Serial.print("Humidity: ");
  Serial.print(h);
  Serial.print(" %\t");
  Serial.print("Temperature: ");
  Serial.print(t);
  Serial.print(" *C ");
  Serial.print(f);
  Serial.print(" *F\t");
  Serial.print("Heat index: ");
  Serial.print(hic);
  Serial.print(" *C ");
  Serial.print(hif);
  Serial.println(" *F");
}

 

lean_74
Offline
Зарегистрирован: 22.12.2015

Jeka_M пишет:

Попробуйте заменить ld.exe, как там советуют.

Спасибо, скомпилировалось на IDE 1.0.5-r2