Beginners seeking help

I want to use the Stone touch screen with Arduino UNO to do a weather station project, I saw the article on the web is done by using ESP32, I want to change the code of ESP32 to the code of Arduino, but I changed half of it and found it is not complete, although the basic functions are written out but the code inside the setup is not given.
I am now hesitant what code should be written in setup? I have written a baud rate myself.
This is the code I wrote halfway through.

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

void loop() {

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};
uint8_t HumidityOutput[8] = {0xA5, 0x5A, 0x05, 0x82, 0x00, 0x15, 0x00, 0x00};
uint8_t illuminationOutput[8] = {0xA5, 0x5A, 0x05, 0x82, 0x00, 0x20, 0x00, 0x00};
uint32_t cout_i;
uint8_t RecievedTemp[40];

  
 if(Serial.available() != 0)
  {
    for(cout_i = 0; cout_i < 9; cout_i ++)
    {
        RecievedTemp[cout_i] = Serial.read();
    }
    switch(RecievedTemp[5])
    {
    case 0x0D://Temperature start
        TemperatureBool = true;
        break;
    case 0x0E://Temperature stop
        TemperatureBool = false;
        TemperatureOutput[6] = 0;
        TemperatureOutput[7] = 0;
        Serial.write(TemperatureOutput, 8);
        break;
    case 0x0F://Temperature back
        TemperatureBool = false;
        break;
    case 0x11://Humidity start
      HumidityBool = true;
        break;
    case 0x12://Humidity stop
        HumidityBool = false;
        HumidityValue = 0;
        HumidityOutput[7] = HumidityValue;
        Serial.write(HumidityOutput, 8);
        break;
    case 0x10://Humidity back
        HumidityBool = false;
        break;
    case 0x14://illumination start
      illuminationBool = true;
      illuminationState = false;
        break;
    case 0x15://illumination stop
      illuminationBool = false;
      illuminationValue = 0;
      illuminationOutput[7] = illuminationValue;
      Serial.write(illuminationOutput, 8); 
        break;
    case 0x13://illumination back
      illuminationValue = 0;
      illuminationBool = false;
      break;
    default:
        break;
    }
}
}

what is a "Stone touch screen"? link?

link to the article?

you use Serial but where is the data coming from?

I suspect some of these don't warrant local-only scope.

Stone touch screen is a serial screen.
and here is the article link: https://www.stoneitech.com/application/energy-project/stone-hmi-display-esp32-weather-station.html
Because the source code of the article I referenced was incomplete, I tried to modify it, and here is the code I modified.

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

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

int HumidityValue = 0;
int 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 "dht.h"
dht DHT;
#define DHT11_PIN 5
int humi=0;
int temp=0;
#define PIN_A 3
int illum=0;

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

void loop() {

DHT.read(DHT11_PIN);
humi=DHT.humidity;
temp=DHT.temperature;
illum=analogRead(PIN_A);
  
 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=temp;
        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 = humi;
        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 = illum;
      illuminationOutput[7] = illuminationValue;
      Serial.write(illuminationOutput, 8); 
        break;
    case 0x17://illumination back
      illuminationValue = 0;
      illuminationBool = false;
      break;
    default:
        break;
    }
}
}

But a new problem soon appeared.

Arduino:1.8.13 (Windows 7), Development Boards:"Arduino Uno"
C:\Users\Stone-6\AppData\Local\Temp\ccRJNuOI.ltrans0.ltrans.o: In function `loop':

E:\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.

I have modified my code, please help me to check it.

you include #include "dht.h"

where does it come from?

which library did you import (or write?)

The page you are referring to says

Because of the Arduino ide development, we must install “dhtnew.h” library to use this module.

which is a different library.
All in all it would be helpful if you could more post more information about you and your project

You are working on an informatic project and what is most needed in an informatic project is information imagine: do the other users here in the forum have a clear picture of what you are trying to do?

To speed up finishing your project you should invest some time into writing additional information I'm 100% sure that this WILL speed up finishing your project.

So please go through this checklist and if you find an item you haven't posted yet post it

  • did you write which exact type of microcontroller you are using?
  • description of your programming skills and knowledge
  • description of your knowledge about electronics
  • description of the functionality you want to have written in normal works avoiding programming terms
  • do you have an oscilloscope? Yes / No
  • do you have a digital multimeter (DMM) Yes / No)
  • your age
  • did you post your complete sketch?
  • if relevant did you post a link to a datasheet of each component you are using?
  • if relevant did you post a handdrawn schematic or your wiring?
  • if you got a compiler-error. Did you post the complete compiler-output into a code-section?

If you don't post all this information because you want a "quick answer" to your detail problem It is very likely to turn out that all that happens is having mutliple waiting-times with mutliple asking back for details until the other users do have a clear picture of what you want to do.

best regards Stefan

This is a project we developed together, my development partner is hospitalized due to a virus, and I am very embarrassed to continue this topic in this way, because I can't develop the project by myself now because of my partner's departure. I hope to finish it soon before he gets out of the hospital and inspire him to be hopeful for our small team.

Hi vincomgo,

my well-being wishes to ballestero.

In this forum the highly prefered schematic-drawings are hand-drawn
anything other than hand-drawn is just a waiste of time or even worse to read.
So please post a hand-drawn picture of the wiring.

Most libraries need a initialisation through a function-call in setup begin() or init()
so please look-up the demo-codes to see what kind of initialisation is needed.

always

post the current version of your code as the

complete sketch

There is an automatic function for doing this in the Arduino-IDE
just three steps

  1. press Ctrl-T for autoformatting your code
  2. do a rightclick with the mouse and choose "copy for forum"
  3. paste clipboard into write-window of a posting

and post the serial output that you receive.

As an additional remark:
I got the impression that there is a user out there with a lot of changing names that does what I call low-level trolling

  • beeing short on information
  • jumping from aspect to aspect
  • showing almost no progress in own effort and learning

To distinguish between such trolling and real questions I have decided to only give support if someone is able to fully implement the requests and instructions I give. That is a tough requirement. Now questions and answers in this forum are completely voluntary. As a questioner you can also say "No, I don't want that". You can freely choose whether you want to follow this requirement or not.

Another instruction from me is: If you ever have a question about anything I requested you must do a try on your own, describe this try and then ask a specific question.
So it is up to you to give full answers or not.

best regards Stefan

Here is the complete code after modification.

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;
    }
}
}

this is still not solid... fix it..

you could make your code more readable by using selfexplaining constants instead of hardcoded numbers with comments. The self-explaining names will make the comment obsolete.

const byte TEMPERATURE_START = 0x00A;

case TEMPERATURE_START:
  TemperatureBool = true;
  break;

best regards Stefan

whilst that will work, the extra 0 is not needed :slight_smile:

Maybe it would be better to use Serial.readBytes (RecievedTemp, 9)?

I added some notes, not sure if this is understandable.

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}; //Write edit box command is 0
uint8_t HumidityOutput[8] = {0xA5, 0x5A, 0x05, 0x82, 0x00, 0x15, 0x00, 0x00}; //Write edit box command is 0
uint8_t illuminationOutput[8] = {0xA5, 0x5A, 0x05, 0x82, 0x00, 0x20, 0x00, 0x00}; //Write edit box command is 0
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)//Read the instruction array, one bit at a time, and loop 8 times to read the complete instruction.
  {
    for(cout_i = 0; cout_i < 9; cout_i ++)
    {
        RecievedTemp[cout_i] = Serial.read();
    }
    switch(RecievedTemp[5])//The sixth element of the instruction array is the address bit. Different address bits represent different controls and functions.
    {
    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;
    }
}
}

have I seen what was shown in your serial monitor? NO!

can I think with your head to easily be able to understand what functionality you want? NO!

Do I have a stonetouch display laying on my table to try to replicate what your code does? NO!

Can I do clairvoyance to:

  • see how you wired your stone-display to your arduino? NO!
  • if the stone-display is working? NO!
  • look into the RAM of your arduino which commands get executed ? NO!

How should I help then?
What does your code trying to achieve?
if my checklist did not help try reading this

best regards Stefan

OP is gone fishing... not sure more answers are needed.

It seems @vincomgo has taken over, so.

a7

Hi guys, I found the error, I made an error while writing my own library file for dht11 and I corrected it now.

Here is the dht11.h:

#ifndef dht11_h
#define dht11_h

#if defined(ARDUINO) && (ARDUINO >= 100)
#include <Arduino.h>
#else
#include <WProgram.h>
#endif

#define DHT11LIB_VERSION "0.4.1"

#define DHTLIB_OK				0
#define DHTLIB_ERROR_CHECKSUM	-1
#define DHTLIB_ERROR_TIMEOUT	-2

class dht11
{
public:
    int read(int pin);
	int humidity;
	int temperature;
};
#endif
//
// END OF FILE
//

Here is the dht11.cpp:

//
//    FILE: dht11.cpp
// VERSION: 0.4.1
// PURPOSE: DHT11 Temperature & Humidity Sensor library for Arduino
// LICENSE: GPL v3 (http://www.gnu.org/licenses/gpl.html)
//
// DATASHEET: http://www.micro4you.com/files/sensor/DHT11.pdf
//
// HISTORY:
// George Hadjikyriacou - Original version (??)
// Mod by SimKard - Version 0.2 (24/11/2010)
// Mod by Rob Tillaart - Version 0.3 (28/03/2011)
// + added comments
// + removed all non DHT11 specific code
// + added references
// Mod by Rob Tillaart - Version 0.4 (17/03/2012)
// + added 1.0 support
// Mod by Rob Tillaart - Version 0.4.1 (19/05/2012)
// + added error codes
//

#include "dht11.h"

// Return values:
// DHTLIB_OK
// DHTLIB_ERROR_CHECKSUM
// DHTLIB_ERROR_TIMEOUT
int dht11::read(int pin)
{
	// BUFFER TO RECEIVE
	uint8_t bits[5];
	uint8_t cnt = 7;
	uint8_t idx = 0;

	// EMPTY BUFFER
	for (int i=0; i< 5; i++) bits[i] = 0;

	// REQUEST SAMPLE
	pinMode(pin, OUTPUT);
	digitalWrite(pin, LOW);
	delay(18);
	digitalWrite(pin, HIGH);
	delayMicroseconds(40);
	pinMode(pin, INPUT);

	// ACKNOWLEDGE or TIMEOUT
	unsigned int loopCnt = 10000;
	while(digitalRead(pin) == LOW)
		if (loopCnt-- == 0) return DHTLIB_ERROR_TIMEOUT;

	loopCnt = 10000;
	while(digitalRead(pin) == HIGH)
		if (loopCnt-- == 0) return DHTLIB_ERROR_TIMEOUT;

	// READ OUTPUT - 40 BITS => 5 BYTES or TIMEOUT
	for (int i=0; i<40; i++)
	{
		loopCnt = 10000;
		while(digitalRead(pin) == LOW)
			if (loopCnt-- == 0) return DHTLIB_ERROR_TIMEOUT;

		unsigned long t = micros();

		loopCnt = 10000;
		while(digitalRead(pin) == HIGH)
			if (loopCnt-- == 0) return DHTLIB_ERROR_TIMEOUT;

		if ((micros() - t) > 40) bits[idx] |= (1 << cnt);
		if (cnt == 0)   // next byte?
		{
			cnt = 7;    // restart at MSB
			idx++;      // next byte!
		}
		else cnt--;
	}

	// WRITE TO RIGHT VARS
        // as bits[1] and bits[3] are allways zero they are omitted in formulas.
	humidity    = bits[0]; 
	temperature = bits[2]; 

	uint8_t sum = bits[0] + bits[2];  

	if (bits[4] != sum) return DHTLIB_ERROR_CHECKSUM;
	return DHTLIB_OK;
}
//
// END OF FILE
//