1. 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.
    Dismiss Notice

PIC data logger

Discussion in 'Microcontrollers' started by Nigel Goodwin, Apr 10, 2016.

  1. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,331
    Likes:
    653
    Location:
    Derbyshire, UK
    ONLINE
    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
     
  2. alec_t

    alec_t Well-Known Member Most Helpful Member

    Joined:
    Jul 10, 2011
    Messages:
    9,325
    Likes:
    1,231
    Location:
    Cardiff, Wales
    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?
     
  3. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,331
    Likes:
    653
    Location:
    Derbyshire, UK
    ONLINE
    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:

    http://www.lazarus-ide.org/
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. alec_t

    alec_t Well-Known Member Most Helpful Member

    Joined:
    Jul 10, 2011
    Messages:
    9,325
    Likes:
    1,231
    Location:
    Cardiff, Wales

    Thanks for the link.
     
  6. Mikebits

    Mikebits Well-Known Member

    Joined:
    May 24, 2008
    Messages:
    6,217
    Likes:
    175
    Location:
    San Diego, Ca
    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.
     
  7. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,331
    Likes:
    653
    Location:
    Derbyshire, UK
    ONLINE
    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
     
  8. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,331
    Likes:
    653
    Location:
    Derbyshire, UK
    ONLINE
  9. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,310
    Likes:
    914
    Location:
    Rochdale UK
    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!!
     
  10. NorthGuy

    NorthGuy Well-Known Member

    Joined:
    Sep 8, 2013
    Messages:
    1,218
    Likes:
    206
    Location:
    Northern Canada
    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.
     
  11. Les Jones

    Les Jones Well-Known Member

    Joined:
    May 15, 2015
    Messages:
    1,474
    Likes:
    191
    Location:
    Lancashire UK
    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.
     
  12. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,240
    Likes:
    645
    Location:
    Ex Yorks' Hants UK
    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
     
  13. Les Jones

    Les Jones Well-Known Member

    Joined:
    May 15, 2015
    Messages:
    1,474
    Likes:
    191
    Location:
    Lancashire UK
    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.
     
  14. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,331
    Likes:
    653
    Location:
    Derbyshire, UK
    ONLINE
    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
     
  15. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,310
    Likes:
    914
    Location:
    Rochdale UK
    Nigel Goodwin The FPC comipler has an inbuilt serial unit!! I also found one on the synapse web site... There are a couple of USB units as well....

    Which one did you use....
     
  16. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,331
    Likes:
    653
    Location:
    Derbyshire, UK
    ONLINE
    I used the Synapse one.

    The FPC one seemed rather 'vague' :D
     
  17. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,310
    Likes:
    914
    Location:
    Rochdale UK
    I think I'll just use an FTDI chip as well..
     
  18. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,331
    Likes:
    653
    Location:
    Derbyshire, UK
    ONLINE
  19. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,331
    Likes:
    653
    Location:
    Derbyshire, UK
    ONLINE
    Just to keep things updated, here's a current screen-shot of the logger software, over 90,000 seconds running, with samples every two seconds.

    Logger2.png
     
  20. Les Jones

    Les Jones Well-Known Member

    Joined:
    May 15, 2015
    Messages:
    1,474
    Likes:
    191
    Location:
    Lancashire UK
    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.
     
  21. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,331
    Likes:
    653
    Location:
    Derbyshire, UK
    ONLINE
    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
     

Share This Page