Jump to content

Banner.jpg.b83b14cd4142fe10848741bb2a14c66b.jpg

Arduino for Beginners


Gina

Recommended Posts

Gina, could you attach the sketch so I can have a look (if you want)?

Sure can :)

Here it is :-


//
// FILE: dht_test.ino
// PURPOSE: DHT library test sketch for Arduino
//
#include <dht.h>
dht DHT;
#define DHT22_PIN 7
void setup()
{
Serial.begin(115200);
Serial.println("DHT TEST PROGRAM ");
Serial.print("LIBRARY VERSION: ");
Serial.println(DHT_LIB_VERSION);
Serial.println();
Serial.println("Type,\tstatus,\tHumidity (%),\tTemperature (C)");
}
void loop()
{
// READ DATA
Serial.print("DHT22, \t");
int chk = DHT.read22(DHT22_PIN);
switch (chk)
{
case DHTLIB_OK:
Serial.print("OK,\t");
break;
case DHTLIB_ERROR_CHECKSUM:
Serial.print("Checksum error,\t");
break;
case DHTLIB_ERROR_TIMEOUT:
Serial.print("Time out error,\t");
break;
default:
Serial.print("Unknown error,\t");
break;
}
}
//
// END OF FILE
//
Link to comment
Share on other sites

  • Replies 82
  • Created
  • Last Reply

Looks OK to me although it does not really output the temperature and humidity.

What output do you get in the serial monitor? Just random characters? Is the serial speed in the monitor set correctly (115200)?

Link to comment
Share on other sites

Sorted :)

  1. The serial speed was too high. That's why the Serial Monitor was showing garbage
  2. I had cut out more than I should have when removing the DHT11 from the test sketch, so not showing humidity and temperature.

Here's the working sketch :-


//
// FILE: dht_test.ino
// PURPOSE: DHT library test sketch for Arduino
//
#include <dht.h>
dht DHT;
#define DHT22_PIN 7
void setup()
{
Serial.begin(9600);
Serial.println("DHT TEST PROGRAM ");
Serial.print("LIBRARY VERSION: ");
Serial.println(DHT_LIB_VERSION);
Serial.println();
Serial.println("Type\tstatus\tHumidity (%)\tTemperature (C)");
}
void loop()
{
// READ DATA
Serial.print("DHT22 \t");
int chk = DHT.read22(DHT22_PIN);
switch (chk)
{
case DHTLIB_OK:
Serial.print("OK\t");
break;
case DHTLIB_ERROR_CHECKSUM:
Serial.print("Checksum error,\t");
break;
case DHTLIB_ERROR_TIMEOUT:
Serial.print("Time out error,\t");
break;
default:
Serial.print("Unknown error,\t");
break;
}
// DISPLAY DATA
Serial.print(DHT.humidity, 1);
Serial.print("\t\t");
Serial.println(DHT.temperature, 1);
delay(5000);
}
//
// END OF FILE
//
Link to comment
Share on other sites

Cheers Chris :)

I now have the DHT22 being read once per second and the temperature and humidity displayed on the LCD display together with the elapsed time since starting as well as on the Serial Monitor on the PC. This is hardly rocket science - most problems are just simple things, easily missed :D I've ordered a 20x4 LCD display as the 16x2 display would be very cramped with the data I wanrt to display.

I'm doing my own testing rather than just using your code as is, Chris, so that I can learn and by taking things a bit at a time, it's easy to debug the code. I've worked through your code and most makes perfect sense but I may query the pseudo exponential cooling to the set point when I have had time to study it further.

Link to comment
Share on other sites

Of course, that makes sense. I also prefer to learn it rather than just using someone else's code / design. But it might be useful to you as a reference and to show how to send commands to an Arduino.

The "pseudo exponential cooling" is so far untested code. I always had it running at full and still hadn't got enough cooling. So that part of the code will need some tweaking once I get the cooling low enough for it to make sense to actually lower the PWM duty cycle.

Link to comment
Share on other sites

Of course, that makes sense. I also prefer to learn it rather than just using someone else's code / design. But it might be useful to you as a reference and to show how to send commands to an Arduino.

Yes, thank you, it certainly will be helpful :)
The "pseudo exponential cooling" is so far untested code. I always had it running at full and still hadn't got enough cooling. So that part of the code will need some tweaking once I get the cooling low enough for it to make sense to actually lower the PWM duty cycle.
I've found the TECs work best just below full power and in practice I've been running at around 50% to give a -5C set point. I will need to get the humidity lower to go much below that though there have been times when I've run at -10C and occasionally at -15C without condensation. I guess it depends on how dry the silica gel is when it's put in and how well I keep the box sealed. I got the best results when I had the FR on and kept it on. ie. not opening up the light path to the atmosphere.

Regarding your code, it seems to me that you are turning the cooling right off when cold finger and set point tempersatures are equal whereas you need an amount of cooling to maintain the cold finger temperature. In other words (as i read it) your code will always produce a cold finger temperature that is somewhat above the desired temperature. I'll work through it and test it with particular values taaken from my test data.

Link to comment
Share on other sites

Here's a photo of the Arduino reading temperature and humidity with a DHT22 and displaying the data on a 16x2 LCD display. As you can see it's pretty damp here even indoors. Humidity is usually around 50% indoors. The humidity agrees quite well with my weather station which shows that the weather station is not that bad for indoor humidity. The outside humidity is reading 99% the highest it goes. I'm looking forward to getting one of these DHT22s set up in my Stevenson screen box to get more accurate outdoor data.

post-13131-0-67812000-1344412652_thumb.j

Link to comment
Share on other sites

How is the humidity captured, is it a specific type of sensor (different from the temp sensor)?

There are two separate sensors in the DHT22 the humidity sensor is a capacitive device which is read by a microprocessor inside the DHT22 case. The temperature is another device which is also read by the microprocessor and then the data is combined into a single stream and read out from the DHT22 by the Arduino.
Could this be done without the display, with everything going to the PC?
Yes, indeed. I first tried the DHT22 without the LCD display - using the Serial Monitor provided in the Arduino IDE (Integrated Development Environment). But the data can also be passed to the computer in an application separate from the IDE - as Chris is doing and I shall be doing later for my camera cooling system.
Link to comment
Share on other sites

Thanks Gina, learning a lot from your excellent threads. When I finally get round to building my obsy your threads will be 'how-to' references. :cool::icon_salut:

Thank you :) Must try and get round to doing a shorter/abbreviated version of my enormous build thread. :D
Link to comment
Share on other sites

  • 2 weeks later...

Bought another book on Arduinos, this time much more advanced with a lot of techniques and information on controlling all sorts of things. It covers more basic stuff too that seems to get missed in other places. It's called Arduino Cookbook and written by Michael Margolis. Over 700 pages. http://www.amazon.co...ils_o00_s00_i00 This has already been a great help to me in improving the coding for my camera cooling control sketch.

I have ideas for more advanced projects too which I plan to post in separate threads. These include a home built weather station and home CCTV surveilance camera control.

Link to comment
Share on other sites

A couple of warnoings :-

There is NO autosave in the Arduino IDE so remember to save your work often so as not to lose it as has just happened to me!

From reading the Arduino forums, I've found another "nasty". If you unplug the USB while the Serial Monitor is running the IDE saves error messages to a log file repeatedly. This commonly occurs when you pack up at night, unplug the Arduino USB and leave the computer running overnight. Indeed I leave mine on all the time - it is uploading my weather data and webcam continuously (well every so often).

Link to comment
Share on other sites

I've found the Arduino Nano will NOT work with the Windows 7 64bit version of the IDE - it can't find the com port. Trying it in XP it works fine.

This is a nuisance as I would like to use a Nano for development. However, I've ordered another Uno to use for development. I'm hoping the sketches developed in W7 IDE will work with the Nano when copied over.

Link to comment
Share on other sites

My Nano works just fine on W7x64

Strange! I wonder what the difference is between your box and mine.

EDIT... Just remembered one difference - I'm running Arduino 1.0.1 and I think you're running an earlier version.

Link to comment
Share on other sites

I have now finally upgraded to Arduino 1.0.1. Though I have not updated the USB drivers and not yet connected my Nano again.

It's been a while but I seem to remember that it wasn't as straight-forward to get the Nano working as it was with the Uno. If memory serves well, there was a conflict with another USB-Serial driver.

Link to comment
Share on other sites

I have now finally upgraded to Arduino 1.0.1. Though I have not updated the USB drivers and not yet connected my Nano again.

It's been a while but I seem to remember that it wasn't as straight-forward to get the Nano working as it was with the Uno. If memory serves well, there was a conflict with another USB-Serial driver.

Ah, that sounds familiar :D I'll be interested to see what ypu find Chris :)
Link to comment
Share on other sites

My nano works with 1.0.1 on win7-64

What I find annoying though is every time you get a new arduino window opened you have to make sure the com port is selected again and that the board is set to "arduino nano w/ atmega328" otherwise I get sync errors

Link to comment
Share on other sites

My nano works with 1.0.1 on win7-64

What I find annoying though is every time you get a new arduino window opened you have to make sure the com port is selected again and that the board is set to "arduino nano w/ atmega328" otherwise I get sync errors

are you running the software as admin? This should then save your current selection I think

Sent from my iPhone using Tapatalk. Blame Apple for the typos and me for the content

Link to comment
Share on other sites

Now then... I want to get the Nano working with my desktop box running Windoze 7 64bit. I still can't get it to work! Must be something I'm doing wrong - but what?

I plug in the USB link to the Nano, go to System >>> Device Manager and there's a non working device which goes when I unplug the USB so that's definitely IT. When I try to install or replace the driver it says "The best driver is already installed for this device" with "Unknown Device" further down the box. Tried uninstalling then unplugging the Nano and plugging it back in again - just the same :(

SO... Am I doing it wrong? What is the correct proceedure? How are you people with a Nano (or two) working with W7 Pro 64bit doing it? Even with 50 years experience of computers of all sorts and sizes, I'm baffled! :(

Link to comment
Share on other sites

The odd thing is that there's no problem with the netbook running XP. But I prefer to use my desktop with full size keyboard and 22" monitor for development. Just checked the netbook with the latest cooling control sketch and it works as far as I can tell without everything connected. But if I get any problems I would prefer to debug with the desktop.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. By using this site, you agree to our Terms of Use.