Converting Uno Code to WeMos D1 R2 for DfRobot Weather Station

I am trying to use the DfRobot weather station code on a WeMos D1 R2 board.

I have confirmed that with the Uno the output works as intended but on the WeMos D1 R2 it does not. And not sure why it's not running.

On the Arduino Uno board, this code works as intended.
But on the D1, no response.

/*!
 * @file  SEN0186.ino
 * @brief DFRobot brings you this new version of the weather station kit that integrates anemometer, wind vane and rain gauge.
 * @copyright  Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
 * @license  The MIT License (MIT)
 * @author  DFRobot
 * @version  V1.0
 * @date  2023-08-03
 */

char                 databuffer[35];
double               temp;

void getBuffer()                                                                    //Get weather status data
{
  int index;
  for (index = 0; index < 35; index++) {
    if (Serial.available()) {
      databuffer[index] = Serial.read();
      if (databuffer[0] != 'c') {
        index = -1;
      }
    } else {
      index--;
    }
  }
}

int transCharToInt(char* _buffer, int _start, int _stop)                             //char to int)
{
  int _index;
  int result = 0;
  int num = _stop - _start + 1;
  int _temp[num];
  for (_index = _start; _index <= _stop; _index++) {
    _temp[_index - _start] = _buffer[_index] - '0';
    result = 10 * result + _temp[_index - _start];
  }
  return result;
}

int transCharToInt_T(char* _buffer)
{
  int result = 0;
  if (_buffer[13] == '-') {
    result = 0 - (((_buffer[14] - '0') * 10) + (_buffer[15] - '0'));
  } else {
    result = ((_buffer[13] - '0') * 100) + ((_buffer[14] - '0') * 10) + (_buffer[15] - '0');
  }
  return result;
}

int WindDirection()                                                                  //Wind Direction
{
  return transCharToInt(databuffer, 1, 3);
}

float WindSpeedAverage()                                                             //air Speed (1 minute)
{
  temp = 0.44704 * transCharToInt(databuffer, 5, 7);
  return temp;
}

float WindSpeedMax()                                                                 //Max air speed (5 minutes)
{
  temp = 0.44704 * transCharToInt(databuffer, 9, 11);
  return temp;
}

float Temperature()                                                                  //Temperature ("C")
{
  temp = (transCharToInt_T(databuffer) - 32.00) * 5.00 / 9.00;
  return temp;
}

float RainfallOneHour()                                                              //Rainfall (1 hour)
{
  temp = transCharToInt(databuffer, 17, 19) * 25.40 * 0.01;
  return temp;
}

float RainfallOneDay()                                                               //Rainfall (24 hours)
{
  temp = transCharToInt(databuffer, 21, 23) * 25.40 * 0.01;
  return temp;
}

int Humidity()                                                                       //Humidity
{
  return transCharToInt(databuffer, 25, 26);
}

float BarPressure()                                                                  //Barometric Pressure
{
  temp = transCharToInt(databuffer, 28, 32);
  return temp / 10.00;
}

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

void loop()
{
  getBuffer();                                                                      //Begin!
  Serial.print("Wind Direction: ");
  Serial.print(WindDirection());
  Serial.println("  ");
  Serial.print("Average Wind Speed (One Minute): ");
  Serial.print(WindSpeedAverage());
  Serial.println("m/s  ");
  Serial.print("Max Wind Speed (Five Minutes): ");
  Serial.print(WindSpeedMax());
  Serial.println("m/s");
  Serial.print("Rain Fall (One Hour): ");
  Serial.print(RainfallOneHour());
  Serial.println("mm  ");
  Serial.print("Rain Fall (24 Hour): ");
  Serial.print(RainfallOneDay());
  Serial.println("mm");
  Serial.print("Temperature: ");
  Serial.print(Temperature());
  Serial.println("C  ");
  Serial.print("Humidity: ");
  Serial.print(Humidity());
  Serial.println("%  ");
  Serial.print("Barometric Pressure: ");
  Serial.print(BarPressure());
  Serial.println("hPa");
  Serial.println("");
  Serial.println("");
}

Any help would be greatly appreciated

The way the adapter board connects to the Uno on the DFRobot page is not recommended. It is connected to the Rx & Tx pins on the Uno. The page says to disconnect the adapter board during sketch upload, otherwise it will interfere with the upload. But then the page says to connect the adapter board and use Serial Monitor at the same time. I am surprised that even works!

I would recommend choosing two other pins on the Wemos and using software serial to communicate to the adapter board.

I am also concerned that the adapter board will be outputting a 5V signal, and the Wemos inputs are 3.3V and could be damaged. I would recommend using a 10K & 22K voltage divider to reduce the (presumed) 5V signal from the adapter to ~3.3V.

1 Like

THAT WORKED!!! Switching the pins and moving to software serial solved my issue! You sir, are a scholar and a gentleman.

Good to hear. Perhaps you can post your updated code, and a schematic (hand drawn is fine) for the benefit of others in the future ?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.