HOME - - - - - Lazarus Tutorials TOC - - - - - - Other material for programmers
Delicious Save this on Delicious

A really, really crude page...

PART 2: Using Lazarus to write software for Dallas 1-Wire MicroLans

This page is still a "raw" essay telling you how to use the Dallas 1-Wire chips (via the TMEX support SDK) WITH LAZARUS.

It follows on from dstl2hello_ds18b20.htm

It is BETTER in that the program is more "polished", more "complete", "better written".... But it is WORSE because the BASICS of using the 1-Wire chip are less obvious.

The earlier essay give MUCH more help with "What *IS* 1-Wire?" "What is it good for?"

Following on FROM this, I also offer dstl2hello_ds18b20-pt3.htm, sourcecode to do the same things, but more elegantly. The user will see little difference, but the way the code is structured is much more programmer friendly. Imperfect, yes... but several strides in the right direction. Details of "the 1-Wire stuff" hidden away (where it should be) in subroutines, so you can concentrate on what you want to do with the reading*S* you are harvesting. (The application still only reads one sensor, but from this version of the code, adding additional sensors would be nearly trivial.)

The BEST news?

There is a free zip archive with the sourcecode! (You may find many sections of the code "folded"... just click the little +/- indicator in the left margin. Collapsing "stuff" helps you focus on the parts which are currently of interest.)

There's a bug in the way the application starts up... it very rapidly says "TMExtendedStartSession failed... shutting down." unless the values in the ini file... which the program will create, if it didn't exist before... are right. So edit ini file with a text editor, by hand, before restarting the application, and try to run the program again, and all should be well.

The critical entries, which have to be right before you can get past "TMExtendedStartSession failed..." are...


ID-Chip A=1111.2222.3333.4444

You have to supply numbers where I've put X and Y (Adapter Type will probably be 6, if you have one of the USB adapters), and you have to replace the 1111.2222.3333.4444 with YOUR chip's ID.

It isn't hard to re-write the code to allow you to do this simply by changing the values in the edit boxes, and then try again to do the TMExtendedStartSession. It should also be noted that, in it's present state, changing the values in the edit boxes merely changes the values used THE NEXT TIME THE PROGRAM STARTS.

This WEBPAGE, so far, is a pretty poor dog's dinner. Download the sourcecode. Play with that.

I used 1-Wire with Delphi for many years, so was disappointed when Borland/ Embarcardo/ whatever they are called this week shut the hobbyist out of Delphi... and proportionately delighted when Lazarus came along. I've been using it for some time now, no regrets.

So the day came when I wanted to "do" 1-Wire... from Lazarus!

1-Wire isn't for the faint hearted... but it WILL reward you, if you make the effort.

But you DO depend on some code supplied (free) by Dallas. (Dalsemi/ Maxim... whatever THEY are called this week.

In particular something that started as a unit for Delphi, but WHICH WORKS WITH LAZARUS... if you poke one simple little line into it.

The code is in iBTMEXPW.pas.

To use it with Lazarus, the simple (if clumsy and inefficient) way is to put a copy of it in each project's main folder. The folder with the app's main unit's .pas file.


{$mode delphi}//Added by ((insert your name))

... right at the top, just after the "Unit iBTMEXPW;" line.

(You don't... why would you? (But given that I wondered, maybe you will)... need to put the {$mode delphi} into anything else needed by this.)

Jumbled info, to be hammered into a proper web page in due course...

LDN031... the software that comes with this (see above for download link... the link gives you .exe AND all the sourcecode... is an evolution of LDN030. If you are getting started with 1-Wire, start with that and its tutorial.

LDN031 is not greatly changed from LDN030 in terms of what it can do, or even, particularly, in how it does it. But it is, I hope....

More "user friendly" (at cost of some overheads)... in particular, the code doesn't have to be re-written to change chip ID, port number, adapter type... these are set in an ini file which is managed by the program.

It's been "tidied", and made "more elegant"... if less pedestrian/ obvious. "Stuff" has been parceled into SRs.

A start has been made towards using sub-units. Imperfect... but a start.

To pass complex results between main unit and sub-unit has involved using user defined records. Don't let them scare you... they aren't too bad. See my tutorial on user defined records.

One big "new bit"...

Now there's a button to say "read the tture sensor repeatedly, until further notice".

In a trivial addition, now you get a crude graph of the readings, too. Whee!

In other news...

The first version, LDN030, would seize up when it was doing a conversion. And if you clicked "quit" while it was doing a conversion, it wouldn't "remember"... and clicking "quit" again later didn't work, you had to click on a DIFFERENT button, and THEN it Quit! Argh!

I changed WaitABit to use "Sleep(ms)". And that seems a whole lot better... in limited tests. I don't know a lot about "sleep"... that may bring its own "issues"... but I haven't found them yet.

Secondary window...

The memo displaying the readings has been moved to a window of its own.

No big deal.

Here's how I did that, if you are interested. Nothing, specifically, to do with using 1-Wire chips.

How I created what you see in LDN031, starting from LDN030:

Used "File/ New Form"

Saved it as "readings_window.pas" (Lazarus advises against mixed case in FILE names, but is quite happy to allow mixed case elsewhere... variables, components, etc.)

Added "readings_readings" to the "Uses" clause of ldn031.pas.

Set, of the new form...

name: ReadingsF1

visible to "true"
bordericons... none.

In it's "formcreate"...

caption:='Temperature readings from DS031';

Gave it a memo called "meReadings"

Now.. here's a bit that still "tricks" me. (I told you I was the "one eyed king", didn't I?)

So far, I had an app with a second window, the one we just created, the one managed by the code in readings_wiondow.pas.

And on that window (form), I had a memo component: meReadings. (I also had ANOTHER meReadings... the original one, on the main form.)

When I ran the application at that point, I could SEE both windows. (If you don't, move the one you can see around- maybe the other is under it!)... but things were, for the moment, still written to the OLD meReadings.

Here's how I fixed that!...

There are two "meReadings.lines.insert..." lines in the main code.

I inserted "ReadingsF1." in front of both. NOT "readings_window", the name of the UNIT. but "ReadingsF1", the name of the form the meReadings memo I wanted was **ON**.

(Once that was done, I could delete the old meReadings from the main window, from ldn031f1.


Sorry there are so many rough edges... in the tutorial. THANK YOU for whatever effort you have put into reading it. Emails (see below) would encourage me that SOMEONE (besides me) wants to do 1-Wire with Lazarus, and I might put even more time into this. The code in the zip archive DOES WORK... as long as you put valid values for what is connected to your computer into the edit boxes for Adapter Type, Port Number and ChipID.

But... despite all of the above whining... WHEN YOU KNOW HOW... 1-Wire is a delight, and not TOO difficult! And it WORKS with Lazarus, hurrah! (Well, seems to so far. Early days.)

   Search this site or the web        powered by FreeFind
  Site search Web search
Site Map    What's New    Search   BEWARE: There is stuff at my other two sites that this search won't reveal. Go to either site (see links below) and use that site's FreeFind search button.

In addition to the tutorials for which this page serves as Table of Contents, I have other sites with material you might find useful.....

Sheepdog Software homepage.
My Arunet homepage.
... and some links to specific pages within them you might want....

Main index to MicroLan stuff.
Some pages for programmers.
Using the parallel port with programs written in Delphi.

Ad from page's editor: Yes.. I do enjoy compiling these things for you... hope they are helpful. However.. this doesn't pay my bills!!! If you find this stuff useful, (and you run an MS-DOS or Windows PC) please visit my freeware and shareware page, download something, and circulate it for me? Links on your page to this page would also be appreciated!
Click here to visit editor's freeware, shareware page.

Link to Tutorials main page
Here is how you can contact this page's author, Tom Boyd.

Valid HTML 4.01 Transitional Page tested for compliance with INDUSTRY (not MS-only) standards, using the free, publicly accessible validator at validator.w3.org

If this page causes a script to run, why? Because of things like Google panels, and the code for the search button. Why do I mention scripts? Be sure you know all you need to about spyware.

....... P a g e . . . E n d s .....