So if you went and found an external library that works and ported the library code to your ino file is the library still external?
Same question
100% sure
Yes, i'm supposed to write my own code for everything
When is your assignment due? Cause you got a lot to learn.
Let me try that, thanks!
Okay, let me do that.
Does not compute
I'm not really sure. I could incorporate borrowed code into my own code, if that makes sense. But at the end it has to be my code
I assume that you have to be able explain how "your" code works
yes, true
step 1:
Search the datasheets of your temperature sensor.
When you have found it, read it.
You might read it two times.
When done, post a link to the datasheet.
ok, thanks
- Please post that code ... it will be the reference from this point forward.
- Also, please tell us where (use link) the libraries were downloaded.
The next step will be to integrate the libraries directly into your shetch using tabs and a slight edit to the main includes to allow the Arduino system to look into the local sketch directory instead of the Arduino\libraries folder.
#include <LiquidCrystal.h>
#include "DHT.h"
#define DHTPIN 8
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
void setup() {
lcd.begin(16, 2);
dht.begin();
lcd.print("Temp: Humid:");
}
void loop() {
delay(500);
lcd.setCursor(0, 1);
float h = dht.readHumidity();
float c = dht.readTemperature();
float f = dht.readTemperature(true);
if (isnan(h) || isnan(c)) {
lcd.print("ERROR");
return;
}
lcd.print(c);
lcd.setCursor(9,1);
lcd.print(h);
}
#include <LiquidCrystal.h>
#include "DHT.h"
#define DHTPIN 8
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
void setup() {
lcd.begin(16, 2);
dht.begin();
lcd.print("Temp: Humid:");
}
void loop() {
delay(500);
lcd.setCursor(0, 1);
float h = dht.readHumidity();
float c = dht.readTemperature();
float f = dht.readTemperature(true);
if (isnan(h) || isnan(c)) {
lcd.print("ERROR");
return;
}
lcd.print(c);
lcd.setCursor(9,1);
lcd.print(h);
}
I downloaded and installed the libraries within the Arduino IDE version 2.0.4
I found this one, and read it, it hasn't given me any direction. I'll search for another one.
DHT11 Humidity & Temperature Sensor (mouser.com)
Thank you.
Now, I want you to attempt to copy the DHT11 library files that in Arduino/libraries into your sketch directory ...

- Edit your #include to read:
// #include <dht11.h>
#include "dht11.h" // Changed <lib.h> to "lib.h" to point to files in local sketch directory
Exit the sketch. Then open the sketch again and you should see:
Compile and upload. You should still have a working sketch.
Pls confirm.
Assuming success, you will repeat the copy files process for the liquidCrystal files. When complete and the sketch is restarted, you should have:
That is not the best data sheet I've seen, but it does have the timing for the signal interface needed to read data from the DHT11, implementing that in code is going to be your job.
OK ... on my system here (I looked for 30 minutes to find a 10 year old box with DHT-11's from some distant purchase from China...) Here is what I did next.
- After having all 4 files, 2 .h and 2 .cpp, copied into the sketch directory, the next step is to combine the .cpp and the .h ...
Below is the results for dht. What I get is a single dht11.h file that is the combined code.
//
// FILE: dht11.h
// #include <Arduino.h>
#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
//
// 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
//
I compiled and get a clean upload. I tested by adding a couple of print statements (and Serial.begin() to the setup.
// solely for testing with console
Serial.print(c); Serial.print(F(" ..... ")); Serial.println (h);
My output:
19.00 ..... 30.00
19.00 ..... 30.00
19.00 ..... 30.00
19.00 ..... 30.00
19.00 ..... 30.00
19.00 ..... 30.00
Thus, the IDE now appears as:
After I combined the dht11.cpp into dht11.h (copying all of dht11.cpp to the end of dht11.h and eliminating a few statements as you can determine from the posted code) the dht11.cpp tab is simply deleted.
You will need to do exactly the same process with LiquidCrystal.cpp .... move all the cpp code into the .h and then a bit of cleanup and delete the tab.
Your real work begins now. You must determine if any of the functions in the library files are unused. If so, you can comment them in block to test ... that is
// below code is being blocked for testing before removal...
/*
... code to bypass
*/
Always test before deleting! Do keep a good copy of successes by simply resaving your sketch giving it a numerical suffix....
- sketch0 is the base
- sketch1 is the next good change
- sketch2 is the next ...
- and so on
You really need to have a safety net.
Once you eliminate any non-necessary functions you are not using; you need to consider rewiriting the integrated libraries to make them yours. Try to make this a fun experiment as you are going to have to keep a browser window open as you research what is really happening in the original code and how you intend on reworking it.
At this point I believe I have done about all that is appropriate ... without giving you all the answers. I do agree that such a task for a beginner coder is asking a lots, but you will learn a lots if you follow through.
Very best of luck!
Ray


