Esp programmed by Arduino IDE

Dave Lowther

Joined Sep 8, 2016
101
The code programmed for the ESP by using the Arduino IDE can be applied directly to the Arduino UNO?
Depending on what libraries and features are used in your source code you may be able to re-build exactly the same source code to run on either the Uno or the ESP(32 etc) by changing Tools / Board. If there is something incompatible with your code for the selected board you should get a build error.
 

Thread Starter

Young2

Joined Dec 7, 2020
90
Depending on what libraries and features are used in your source code you may be able to re-build exactly the same source code to run on either the Uno or the ESP(32 etc) by changing Tools / Board. If there is something incompatible with your code for the selected board you should get a build error.
Yes, thanks a lot, I've received some error alerts.
Code:
C:\Users\Stone-6\AppData\Local\Temp\ccRJNuOI.ltrans0.ltrans.o: In function `loop':
E:\document\weather1/weather1.ino:36: undefined reference to `dht::read(int)'
collect2.exe: error: ld returned 1 exit status
exit status 1
Error while compiling for development board Arduino Uno.
 

Thread Starter

Young2

Joined Dec 7, 2020
90
hi Y2,
Please post your full Arduino sketch, I will try it out on my setup.
E
All I use in my project are sensors and I don't think I need to define any output pins in setup.
I modified my code a little and now it compiles without problems.

Code:
int lightState = 0;
bool TemperatureBool = false;
bool HumidityBool = false;
bool illuminationBool = false;
bool illuminationState = false;

uint8_t TemperatureValueInteger = 0;
uint8_t TemperatureValueDecimal = 0;
uint8_t TemperatureValue = 0;

uint8_t HumidityValue = 0;
uint8_t illuminationValue = 0;

uint8_t TemperatureOutput[8] = {0xA5, 0x5A, 0x05, 0x82, 0x00, 0x10, 0x00, 0x00}; //A5 5A 06 83 00 0A 01 00 02
uint8_t HumidityOutput[8] = {0xA5, 0x5A, 0x05, 0x82, 0x00, 0x15, 0x00, 0x00}; //A5 5A 06 83 00 14 01 00 05
uint8_t illuminationOutput[8] = {0xA5, 0x5A, 0x05, 0x82, 0x00, 0x20, 0x00, 0x00}; //A5 5A 06 83 00 18 01 00 08
uint32_t cout_i;
uint8_t RecievedTemp[40];

#include "dht11.h"
dht11 DHT;
#define DHT11_PIN 5
#define PIN_A 3


void setup() {
 
  Serial.begin(115200);
 
}

void loop() {

DHT.read(DHT11_PIN);
 
 if(Serial.available() != 0)
  {
    for(cout_i = 0; cout_i < 9; cout_i ++)
    {
        RecievedTemp[cout_i] = Serial.read();
    }
    switch(RecievedTemp[5])
    {
    case 0x0A://Temperature start
        TemperatureBool = true;
        break;
    case 0x0C://Temperature stop
        TemperatureBool = false;
        TemperatureValue = DHT.temperature;
        TemperatureOutput[7] = TemperatureValue;
        Serial.write(TemperatureOutput, 8);
        break;
    case 0x0E://Temperature back
        TemperatureBool = false;
        break;
    case 0x14://Humidity start
      HumidityBool = true;
        break;
    case 0x16://Humidity stop
        HumidityBool = false;
        HumidityValue = DHT.humidity;
        HumidityOutput[7] = HumidityValue;
        Serial.write(HumidityOutput, 8);
        break;
    case 0x13://Humidity back
        HumidityBool = false;
        break;
    case 0x18://illumination start
      illuminationBool = true;
      illuminationState = false;
        break;
    case 0x19://illumination stop
      illuminationBool = false;
      illuminationValue = analogRead(PIN_A);
      illuminationOutput[7] = illuminationValue;
      Serial.write(illuminationOutput, 8);
        break;
    case 0x17://illumination back
      illuminationValue = 0;
      illuminationBool = false;
      break;
    default:
        break;
    }
}
}
 
Top