Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC data logger

Status
Not open for further replies.

Nigel Goodwin

Super Moderator
Most Helpful Member
Just thought members might be interested in what I'm playing with at the moment, I'm involved in a project to design and build a data logger project for a friend, so for a start I've been playing with doing both the PIC side and the PC side as well, as it needs to be uploadable to a PC to display a graph of the resulting data.

There's a number of different points to consider, but while playing I thought a simple two channel voltage logger would be handy, so I put one together using an 8 pin PIC 12F1840 and an FTDI USB/Serial converter, which simply receives an instruction from the PC, does two readings (actually 20 and averages them) and sends them back. The PC then plots this as a graph.

I've also recently been playing with a DHT22 temperature/humidity sensor - and this morning I thought "why not log that as well" - so I've made a quick PIC program, based on the existing hardware I've been using (16F1827 based), and simply fed the output to the two channel logger software used with the 12F1840 voltage logger (which is why the labelling doesn't make any sense).

Here's a screen shot of it's first run:

The red trace is humidity (relative %), and the blue is temperature (degrees c) - the first 'blip' is me breathing directly on the sensor, and the second larger 'blip' is me squirting the sensor with a can of freezer. The sensor is taking a VERY long time to recover though, the temperature is back up to 14.8c now, but the humidity is still 99.9% :D

The PC program by the way is written using Lazarus, a free 'Delphi type' compiler.

L0gger1.png
 
Nice. Does Lazarus come with libraries for high-level things such as windows, buttons, serial comms etc, or do you have to roll your own at Windoze API level?
 
Nice. Does Lazarus come with libraries for high-level things such as windows, buttons, serial comms etc, or do you have to roll your own at Windoze API level?

It comes with pretty well all that, and it's multi OS as well. Serial comms isn't there as standard, but you can download a unit to do it.

Have a look:

https://www.lazarus-ide.org/
 
Thanks for the link.
 
Hi Nigel, I just learned C++ last year and still not quite proficient at it. Been using it for embedded stuff up to this point. I been wanting to make a GUI based interface for a few projects, but was not quite sure the best way to go about it. One person on STack-exchange suggested I go with QT-creator, but I been having trouble with it installing properly so I was looking for something else.
Your Lazarus IDE looks cool, but I have no experience at all with Delphi, or Pascal. It sounds like Lazarus is Pascal, but I may just not understand what I read on the link you provided. Would I be able to use C++ with Lazarus or would I have to learn a whole new programming language? Or maybe a better question would be, with my only programming language being C++, would it be very difficult to pick up on this Lazarus IDE? Any help/suggestions you can offer would be great. Thanks in advance.
 
Hi Nigel, I just learned C++ last year and still not quite proficient at it. Been using it for embedded stuff up to this point. I been wanting to make a GUI based interface for a few projects, but was not quite sure the best way to go about it. One person on STack-exchange suggested I go with QT-creator, but I been having trouble with it installing properly so I was looking for something else.
Your Lazarus IDE looks cool, but I have no experience at all with Delphi, or Pascal. It sounds like Lazarus is Pascal, but I may just not understand what I read on the link you provided. Would I be able to use C++ with Lazarus or would I have to learn a whole new programming language? Or maybe a better question would be, with my only programming language being C++, would it be very difficult to pick up on this Lazarus IDE? Any help/suggestions you can offer would be great. Thanks in advance.

Lazarus is Pascal, but it's not that much different to C - in fact I've always found Pascal far easier to learn than C, which is why it used to be the teaching language of choice at Universities.

I've been trying to learn C on the PIC for a while now, and in fact I'm writing the PIC software using XC8, and the PC software in Pascal/Lazarus - it makes it a little confusing switching from one to the other all the time :p

Download Lazarus and have a play, it's free :D

First basic difference is:

C - {/}
Pascal - Begin/End
 
Hi Nigel, I just learned C++ last year and still not quite proficient at it. Been using it for embedded stuff up to this point. I been wanting to make a GUI based interface for a few projects, but was not quite sure the best way to go about it. One person on STack-exchange suggested I go with QT-creator, but I been having trouble with it installing properly so I was looking for something else.
Your Lazarus IDE looks cool, but I have no experience at all with Delphi, or Pascal. It sounds like Lazarus is Pascal, but I may just not understand what I read on the link you provided. Would I be able to use C++ with Lazarus or would I have to learn a whole new programming language? Or maybe a better question would be, with my only programming language being C++, would it be very difficult to pick up on this Lazarus IDE? Any help/suggestions you can offer would be great. Thanks in advance.
You'll find Pascal very easy.... This is OOP programming without the headache... I used to play with Delphi some years ago.... BUT!! I knew C and C++ so it was superfluous for me... BUT!! ( again ) I used to use VB6 a lot and windows 7+ wont work with the VB6 IDE so this looks like a really good RAD tool that I can port all my old VB6 programs to..

Nigel Goodwin .. Thanks for the link.. I'll certainly give this a go!!
 
Pascal is certainly much better than C++. Delphi's Pascal used to be a great compiler, perhaps one of the best compilers in the world. I looked at Free Pascal (FPC), which comes with Lazarus, may be ten years ago, and I found it to be worse than Delphi. On contemporary computers, old Delphi compiler can compile 200,000 lines in an instant.

At any rate, Pascal is much more natural than C++ and produces better results.
 
Hi Nigel,
This is a question about the DHT22 so a bit off topic. I am using a DHT22 connected to an ESP8266 so I can read the temperature and humidity in my workshop from a computer in the house. I find that it seems to send the readings from the previous time data was requested. For example the first time I request a reading in the morning I get values that correspond to that values the previous night. (When I last requested a reading) I get the impression that it sends data then does a reading. I wonder if you have noticed this ?

Les.
 
hi Les.
I use the DHT22 with a 16F887, using Oshonsoft compiler, with the Servoin command, I get the requested reading.
Are you allowing sufficient time for the wait.

Eric.

rd_dht:
TRISC.0 = 0 'pin to output
PORTC.0 = 0 'init DHT
WaitMs 20
PORTC.0 = 1
WaitUs 30
TRISC.0 = 1 'set data pin
 
Hi Eric,
Thanks for that information. I think the code works by checking if more than 2 seconds has elapsed since the last reading. I use the term "I think" as the code is written in "C" and my ability at programing in "C" is almost zero. The code is a very slightly modified version of some example code for the ESP8266 (Wi Fi module.) I have another DHT22 on order so I will try it out with a PIC chip or 8 bit Atmel chip programmed in assembler. I will then know exactly how it behaves. Thanks again.

Les.
 
Hi Nigel,
This is a question about the DHT22 so a bit off topic. I am using a DHT22 connected to an ESP8266 so I can read the temperature and humidity in my workshop from a computer in the house. I find that it seems to send the readings from the previous time data was requested. For example the first time I request a reading in the morning I get values that correspond to that values the previous night. (When I last requested a reading) I get the impression that it sends data then does a reading. I wonder if you have noticed this ?

No, but I did alter the program I use so it 'throws away' the first attempted reading, as that always returned an error.

I've been meaning to connect one to an ESP8266 - but not got round to it yet :D
 
Hi Nigel,
I was thinking of the same solution that you have used. Read the sensor, delay 2 seconds and then read the sensor again. This is the example code that I used to connect the DHT22 to the ESP8266 There is a line of code missing in the listing. (I did not work it out and I do not understand why it is needed. I found the information by Googling.) This line (void gettemperature();) needs to be added after this line (const char* password ="YourRouterPassword";

Les.
 
Been doing some more playing with Lazarus, added extra sample timings and split the graph into two section. This screen shot shows what happens when you squirt a DHT22 with a can of freezer :D

Logger3.png
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top