Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
problems with 18b20
12-10-2015, 11:05 AM,
#21
RE: problems with 18b20
Fixed in next version.
Thank you.
It is easier to complain than it is to do, but it is better to do than it is to complain.
Reply
19-10-2015, 03:52 PM,
#22
RE: problems with 18b20
Hi,
I modified the ds18b20.c lib, made some improvments on existing  functions and added some new.
Using the 1wire.c lib posted before I had no more problem.

Changes are as follow:
1) DS18B20ReadRom():
     Added CRC calc

2) Added a global var SCRATCHPAD[9] in order to have the scratchpad available in main program; only for debug

3) Various changes on DS18B20Read() function:
      Removed DS18B20Configure() inside the function to fix resolution problem
      Fix resolution problem on temp. calculation
      Added Timeout to avoid infinite loop.

4) Added DS18S20Read() function.

5) Changes in DS18B20Configure():
       fix prototype: s8 TH, s8 TL -> DS18B20Configure(u8 pin, u8 rom, s8 TH, s8 TL, u8 config)
       check TH and TL in range
       Store TH, TL and config on non-volatile memory with command COPY_SCRATCHPAD


6) Added DS18B20GetTemperatureByIndex() function

7) Added DS18B20DeviceCount() function.

8) Added DS18B20Begin() function.

Find Attached library, pdl file and usage example.
I tested with 8 sensors on the bus (mix of DS18B20 and DS18S20), and simulated a failure (1 sensor off).


Code:
Reading#: 109  ---- Sensors on the bus:7
Device#01: 10 F2 71 8A 02 08 00 BC ---- Temp: 19.37 C
Device#02: 10 FA 8A 8A 02 08 00 CB ---- Temp: 19.18 C
Device#03: 10 99 AE 94 02 08 00 9B ---- Temp: 19.06 C
Device#04: 10 D5 90 8A 02 08 00 98 ---- Temp: 19.50 C
Device#05: 28 B8 03 C7 05 00 00 7C ---- Temp: 19.12 C
Device#06: 28 F6 A7 C7 05 00 00 36 ---- Temp: 19.62 C
Device#07: 28 B9 B8 C6 05 00 00 FB ---- Temp: 19.00 C

Repeat start!
Reading#: 110  ---- Sensors on the bus:8
Device#01: 10 F2 71 8A 02 08 00 BC ---- Temp: 19.37 C
Device#02: 10 FA 8A 8A 02 08 00 CB ---- Temp: 19.25 C
Device#03: 10 09 69 8A 02 08 00 74 ---- Temp: 19.68 C
Device#04: 10 99 AE 94 02 08 00 9B ---- Temp: 19.06 C
Device#05: 10 D5 90 8A 02 08 00 98 ---- Temp: 19.43 C
Device#06: 28 B8 03 C7 05 00 00 7C ---- Temp: 19.12 C
Device#07: 28 F6 A7 C7 05 00 00 36 ---- Temp: 19.62 C
Device#08: 28 B9 B8 C6 05 00 00 FB ---- Temp: 19.00 C


Can someone else test this lib and give a feedback?
Thanks,
Luca


Attached Files
.c   18b20.c (Size: 33.68 KB / Downloads: 5)
.pdl   1wire.pdl (Size: 1.07 KB / Downloads: 4)
.pde   DS18x20_multi-sensor.pde (Size: 2.45 KB / Downloads: 4)
Reply
22-10-2015, 08:33 PM,
#23
RE: problems with 18b20
Hey
I was also making a project with DS18B20 with Pinguino 26J50.
I have bad readings in the original code and in your code.
I've tried powering DS18B20 with 3.3 V and 5V - no differences.

My code:
Code:
    TEMPERATURE t;
// parameter resolution removed after updating 18b20.c
    if (DS18B20.read(ONEWIREBUS, SKIPROM, &t))
    {
                    value = t.integer;
    }
value is displayed on LCD and it is always "85".
I have 4.7k Ohm resistor between DS18B20 pins as in documentation.
Any ideas what may be wrong?
Reply
23-10-2015, 07:23 PM, (This post was last modified: 23-10-2015, 07:59 PM by brikker.)
#24
RE: problems with 18b20
Hi B4lfiz4r,
your sensor is a DS18B20 or DS18S20?
I tested the code again and it works for me.
Let me know

Could you try this code and post results?

Code:
#define ONEWIREBUS    2

u8 w = 0;
char temp_sign = 0;

void setup() {
   //DS18B20.begin(ONEWIREBUS);
   // put your setup code here, to run once:    
}

void loop() {
       TEMPERATURE t;
       if (DS18B20.read(ONEWIREBUS, SKIPROM, &t)) {
       //if (DS18B20.getTemperatureByIndex(ONEWIREBUS, 1, &t)) {
           if (t.sign) {
               temp_sign = 45;                      // ascii "-"
           } else {
               temp_sign = 43;                      // ascii "+"
           }
           CDC.printf("Scratchpad: %02X %02X %02X %02X %02X %02X %02X %02X %02X  --- Temp: %c%02d.%02d C\r\n",
           SCRATCHPAD[0], SCRATCHPAD[1], SCRATCHPAD[2], SCRATCHPAD[3], SCRATCHPAD[4],
           SCRATCHPAD[5], SCRATCHPAD[6], SCRATCHPAD[7], SCRATCHPAD[8], temp_sign, t.integer, t.fraction);
       }          
       w++;
       delay(3000);
}
Thanks
Bye
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)