Pages: 1 ... 6 7 [8] 9   Go Down
Author Topic: DS18B20 & onewire.h  (Read 14890 times)
0 Members and 1 Guest are viewing this topic.
UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12630
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hummm, is breadboard needs bridge leads where "W" marks are?


I feel sure that sync has hit the nail on the head. Well done, syncsmiley
Logged

I only provide help via the forum - please do not contact me for private consultancy.

West Midlands, UK
Offline Offline
Jr. Member
**
Karma: 0
Posts: 61
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hummm, is breadboard needs bridge leads where "W" marks are?

Hahahahilarious.....

Sync thats what the problem was.......

I didn't know that there was a break in the breadboard now did I lmao!

I am now registering "ALL" of the sensors.....

I knew there wasn't anything wrong with the sensors or the arduino but I didn't know about the breadboard lol....

Thats something I wont forget in a while!!!
Thats taken the best part of a week to sort out hahaha!

So how would I amend the code to register each ID address of the sensors to each index value in the bus so that it locks in the position....?
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 485
Posts: 18778
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Good suggestion, Nick, to ask for another photo, huh?

Quote
So how would I amend the code to register each ID address of the sensors to each index value in the bus so that it locks in the position....?

Well how about trying to work that one out for yourself? It's good practice to try to do something, and if it doesn't work, you can post what you tried and explain how it didn't work.

To get you started, there is a typedef in the header file for the device address:

Code:
typedef uint8_t DeviceAddress[8];

And there is a function to get the temperature if you have an address:

Code:
  // sends command for one device to perform a temperature conversion by address
  bool requestTemperaturesByAddress(uint8_t*);

And you know the addresses:

Code:
Device 0 Address: 28184D640300009B
Device 1 Address: 28789364030000A4
Device 2 Address: 28341E640300008B
Device 3 Address: 2892375B030000BC
Device 4 Address: 28BA515703000034
Device 5 Address: 28864C64030000F4
Device 6 Address: 28CE455B03000001
Device 7 Address: 28BEF263030000D3

So just combine all that knowledge.
Logged


West Midlands, UK
Offline Offline
Jr. Member
**
Karma: 0
Posts: 61
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This is baking my noodle!

Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 613
Posts: 49330
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
This is baking my noodle!
Is it well done, yet?
Logged

West Midlands, UK
Offline Offline
Jr. Member
**
Karma: 0
Posts: 61
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

whats this....

uint8_t

and also this...

uint8_t*

Do these reference the device address in brackets as the 16 digit number (DeviceAddress) or the index value on the bus (IndexValue) as denoted by the *


?

typedef uint8_t DeviceAddress[8]; //


Does this mean I would have to do something like this....
typedef uint8_t DeviceAddress[16]; //  for 16 digits in the hexadecimal ID number

#define 28184D640300009B index 0 //defines sensor id address at index 0 in the array

Then would I have to create an instance for each index to pass on the DallasTemperature for each sensor id address as you would do if it were for each seperate pin location.

bool requestTemperaturesByAddress(uint8_t*);

Would be interpreted as

DallasTemperature sensors(28184D640300009B); //passes the onewire reference to the sensor id address as defined on the (ONE_WIRE_BUS)index value

or would it be...

TemperaturesByAddress(28184D640300009B);



I'm trying to keep it consistant and I just would like to share what I'm thinking before I start messing around with Nicks program....
I would of posted earlier but what happened was my 3 year old son knocked the project on the floor and I put one of the wires in the wrong place and I wasn't getting any readings...
I needed to take some deep breathes and count to ten lol!
Logged

West Midlands, UK
Offline Offline
Jr. Member
**
Karma: 0
Posts: 61
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
This is baking my noodle!
Is it well done, yet?

Gas mark 9 mate lol....
Logged

Brisbane, Australia
Offline Offline
Edison Member
*
Karma: 33
Posts: 1122
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Wow Sean, you have more questions there than you know you've asked.  I'll try to do them justice...
Quote
whats this....

uint8_t and also this... uint8_t*
uint8_t is a standard data type (representing an unsigned integer 8 bits long) which for the intent it is used here is as a pattern of 8 bits.  The one with the * is simply a data pointer to a variable of that type, but in the practical sense it's used here, it's a pointer to the first of these in an array of them, which is how the device address is stored.
Quote
Do these reference the device address in brackets as the 16 digit number (DeviceAddress) or the index value on the bus (IndexValue) as denoted by the *
The device address isn't a 16 digit number, but I can see why you'd be led to think that...more below.

These reference either part of the address, or the start of the address in memory.  I don't think there's any need to be hung up on that so I'll move on.  But it might be worth looking up something on pointers in C++ if you're not familiar with the concept (somewhere like http://www.cplusplus.com/doc/tutorial/pointers/ is a good start I think)
Quote
typedef uint8_t DeviceAddress[8]; //
Does this mean I would have to do something like this....
typedef uint8_t DeviceAddress[16]; //  for 16 digits in the hexadecimal ID number
No.  Let me explain as best I can (and it's far too many years since I did my degree so apologies in advance for inaccuracy - it's rust!)

The device ID is encoded as 64 bits.  This is being stored in the Dallas library as an array of 8x uint8_t bytes of 8 bits each (total 64 bits).  The thing that was printed out for you on the screen is just one possible representation of that, using 8x 2 character HEX values, each of them 0-padded if they're less than 16.  You can see the logic behind this by readin gteh printAddress() function in the tester example right at the bottom. (this is the function that creates the output you're quoting)
Code:
// function to print a device address
void printAddress(DeviceAddress deviceAddress)
{
  for (uint8_t i = 0; i < 8; i++)
  {
    if (deviceAddress[i] < 16) Serial.print("0");
    Serial.print(deviceAddress[i], HEX);
  }
}
It simply iterates through the array from location 0 to 7 and at each stop it takes the value, outputs a "0" first if it's less than 16 and then the HEX value.  Since each uint8_t location stores up to a value of 28 = 11111111 binary = 255 decimal the maximum possible HEX value is FF, and the smallest 00 (0-padded) therefore two characters each of the 8 values, thus the 16 characters you're reading.  It's not a 16 digit number, it's just been displayed that way for human consumption.  Hope that makes sense.

Why do it this way?  Simply because representing the 264 serial number in decimal would be a crazy big number, and representing each uint8_t as a character would lead to producing non-printable control characters (everything before 32 and after 126 in the extended ASCII table http://www.asciitable.com/) which would essentially make the output meaningless.

Hope that makes sense.  Bottom line is it's 64 bits, 8 x 8 bits only.  But that's normally hard to read  smiley
Quote
#define 28184D640300009B index 0 //defines sensor id address at index 0 in the array
Hmmm not quite.  This definition isn't correct, so I think it would look more like (but there is probably a more elegant way of doing this) that you'd define it as a byte array, something like (untested)
Code:
const DeviceAddress index0 {byte(40) byte(24) byte(78)...byte(155) }
I think I've represented each 2-character HEX as decimal correctly up to that point (to cheat, you can always use that ASCII table that has the HEX next to its decimal equiv too.  There's probably a way to cast each 2-digit HEX value to byte directly but I don't know it off the top of my brain...google-fu may help you on that.  That should create a constant called index0 that contains the 8 bytes you need to represent the 64 bit address as it is natively constructed.  Again, untested.  Normal caveats apply.  More caffeine required.

Just a suggestion though, I wouldn't call it index0.  If you're going to all this trouble you may as well call it KitchenSensor1 or something that makes more sense in the real world since the whole index numbering thing is not going to have any relevance to this project now.
Quote
Then would I have to create an instance for each index to pass on the DallasTemperature for each sensor id address as you would do if it were for each seperate pin location.
Yes, you'd need a constant declaration for each one.

And as for the rest well I think you can see from the above that you'd not be passing the functions the values spat out by tester as you read it for the good reason that that's not what it actually is.

Hope this helps,
Geoff
« Last Edit: January 31, 2012, 02:54:34 am by strykeroz » Logged

"There is no problem so bad you can't make it worse"
- retired astronaut Chris Hadfield

West Midlands, UK
Offline Offline
Jr. Member
**
Karma: 0
Posts: 61
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm trying my best to understand whats going on here...

Quote
The device address isn't a 16 digit number, but I can see why you'd be led to think that...more below.

Quote
typedef uint8_t DeviceAddress[8]; //
Does this mean I would have to do something like this....
typedef uint8_t DeviceAddress[16]; //  for 16 digits in the hexadecimal ID number

I should really examine the process before I start asking silly questions about the [8]&[16]. If it works in the first instance then it will be working in the second instance.
I understand that this refers to 8 bytes = (8x8) 64 bits (for each sensor ID)!

Code:
const DeviceAddress index0 {byte(40) byte(24) byte(78)...byte(155) }

So this would be interpreted as =

const 28184D640300009B index0

So wherever index0 is used (or kitchensensor1) it would point to that sensor? I'm not sure what all the bytes refers to again lol....

Its a shame that I couldn't just say that the first sensor that comes up on the bus would be the kitchensensor, but at least this way would mean that if a sensor did malfunction then the others wouldn't move up the list so I can't moan really!

Quote
Just a suggestion though, I wouldn't call it index0.  If you're going to all this trouble you may as well call it KitchenSensor1 or something that makes more sense in the real world since the whole index numbering thing is not going to have any relevance to this project now.

Quote
Then would I have to create an instance for each index to pass on the DallasTemperature for each sensor id address as you would do if it were for each seperate pin location.
Yes, you'd need a constant declaration for each one.

So would that be...

const DallasTemperature.kitchensensor1(28184D640300009B);

Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 485
Posts: 18778
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
const DeviceAddress index0 {byte(40) byte(24) byte(78)...byte(155) }

So this would be interpreted as =

const 28184D640300009B index0


This doesn't look very much like C (or C++) to me. How about working your way through some C tutorials? There are heaps on the web, very good ones. You seem to be pulling words out of the air and hoping for the best. None of that would compile. You need to know the absolute basics, like how to declare variables, and make arrays. This isn't it:

Code:
const DallasTemperature.kitchensensor1(28184D640300009B);

Look up how to make literals (ie. numbers or strings). And then how to make hex ones.

Look at the example code which comes with the DallasTemperature library. In that are declarations for things like insideThermometer which are a lot closer to what you need then your guesses. The examples are put there for a reason ... to help you.
Logged


West Midlands, UK
Offline Offline
Jr. Member
**
Karma: 0
Posts: 61
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't want to be rude or anything but if I wanted to learn indepth C or C++ I would go and do a 2 year course at college and as much as I would like to do that I just don't have the time at the moment!

I came onto the Arduino Forum for help with my problem where I could also get some understanding of how the language works in the programs for the Arduino....

So I posted in the most suitable forum...

Programming Questions = Understanding the language, error messages, etc

And at the beginning of my post I said "can please someone help me because this is driving me nuts"

I would of thought this being the Arduino Forum that this would of been the best place to come for help rather than trawling google again!
I really appreciate the help that I've had so far especially since I've had my arduino since june/july time and not made much progress which is why I've been on here every night, sometimes untill 4am in the morning (for the last 2 weeks) learning and trying to progress.


I know that I can bodge my project with the code that I have now but I would rather get it right and also shorten the time right down that its going to take me to finish it!
If you're not going to help me then please don't belittle me because of my lack of knowledge OR reply to my thread....

Nick you asked me a question....
Quote
Well how about trying to work that one out for yourself? It's good practice to try to do something, and if it doesn't work, you can post what you tried and explain how it didn't work.

 
float tempC = index0.getTempC(device address); 

I can't explain why this didn't work, maybe you can elaborate for me!

Do I have to insert the device address into the brackets as the HEX number?
Logged

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12630
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


I would of thought this being the Arduino Forum that this would of been the best place to come for help rather than trawling google again!
I really appreciate the help that I've had so far especially since I've had my arduino since june/july time and not made much progress which is why I've been on here every night, sometimes untill 4am in the morning (for the last 2 weeks) learning and trying to progress.


With respect, a large part of the problem is that you seem to be paying very little attention to advice you are given, and don't seem to have mastered even the basic syntax of the language. Your questions now are not 'how do I do this on an Arduino?' you are asking basic questions about the 'C' language syntax. There are plenty of places you can go to find out about how 'C' and C++ work. The language is extremely widely used and there are hundreds and thousands of tutorials online that will take you by the hand and answer these basic questions. The Arduino forum is quite specialised and is not the right place to come for advice about fundamentals of the 'C' language. The fact that the people here have continued to offer advice as long as they have is a testament to their patience in my opinion. As far as I can see, the only way that this forum could resolve your problems is for somebody to give you a picture of the hardware and write the sketch for you in its entirety.

You don't need to use anything complex, but if you can't handle basic issues like declaring variables and calling functions then you need to go away and learn the language.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

West Midlands, UK
Offline Offline
Jr. Member
**
Karma: 0
Posts: 61
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm still working on it.....
Logged

Brisbane, Australia
Offline Offline
Edison Member
*
Karma: 33
Posts: 1122
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Sean

Did you have a win?  Hope your project is going well.

It's been a little while since I got back and had a play with these, but do have something working where I'm addressing the sensors by their address.  It's slightly different to the untested example I gave in this thread so thought I'd best set that right.

The two comment lines are output from the demo sketch, and the description in brackets is what I know them to be granted I held one and watched the temperature rise to identify it.
Code:
// Device 0 Address: 28D4DAA90300003B (probe)
// Device 1 Address: 28BCB2B6030000D4 (on board)
DeviceAddress outsideSensor = {byte(40), byte(212), byte(218), byte(169), byte(3), byte(0), byte(0), byte(59) };
DeviceAddress insideSensor = {byte(40), byte(188), byte(178), byte(182), byte(3), byte(0), byte(0), byte(212) };
As you can see, I've dropped the const as defining them as constants caused the IDE to error on compile when I passed them to functions.  Also, there needed to be a comma between values that I omitted in my haste to type it last time.  Overall though the  concept is sound and calls to any functions in the dallas library work just as if it had discovered and provided the addresses.  You might recognise this as a slight mod of the standard example to display two sensor responses based on the addresses above :
Code:
void loop(void) {
  // call sensors.requestTemperatures() to issue a global temperature
  // request to all devices on the bus
  Serial.print("Requesting temperatures...");
  sensors.requestTemperatures(); // Send the command to get temperatures
  Serial.println("DONE");
  float tempCin = sensors.getTempC(insideSensor);
  float tempCout = sensors.getTempC(outsideSensor);

  Serial.print("Inside Temp C: ");
  Serial.print(tempCin);
  Serial.print(", outside Temp C: ");
  Serial.println(tempCout);
 
  delay(10000);

}
By the way found a very lazy way to convert the addresses.  After you get them printed out by the example sketch, copy and paste them somewhere, then two characters at a time copy and paste the addresses here http://string-functions.com/string-hex.aspx which will provide you with the 8 numbers to put in each of the byte arrays.  Tedious? Yes. But you only need to do it the once.

My intention is to use this rig to publish the temperature values to a graph on pachube over a WiFi link for a few days to ensure we're not getting any bogus values (one of the sensors is at the end of a 30.5m length of cable which will ultimately be run up to the peak of our roof...so want to make sure it works solidly)

Cheers, Geoff
Logged

"There is no problem so bad you can't make it worse"
- retired astronaut Chris Hadfield

Brisbane, Australia
Offline Offline
Edison Member
*
Karma: 33
Posts: 1122
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Sean

This notation also works:
Code:
// Device 0 Address: 28D4DAA90300003B (probe)
// Device 1 Address: 28BCB2B6030000D4 (on board)
DeviceAddress outsideSensor = { 0x28, 0xD4, 0xDA, 0xA9, 0x03, 0x00, 0x00, 0x3B };
DeviceAddress insideSensor = { 0x28, 0xBC, 0xB2, 0xB6, 0x03, 0x00, 0x00, 0xD4 };
Simply break your string into the 2 digit hexadecimal numbers, and prefix each one with 0x in the array.

It saves that conversion step, I've tested it, and it works.  Cheers ! Geoff
Logged

"There is no problem so bad you can't make it worse"
- retired astronaut Chris Hadfield

Pages: 1 ... 6 7 [8] 9   Go Up
Jump to: