JonathanS
Posts: 33
Joined: Mon Dec 17, 2012 4:14 am

DS18B20 Low Refresh Rate

Mon May 19, 2014 6:09 pm

I am using the DS18B20 digital temperature sensor for monitoring temperature on the RPi.

My biggest problem is its refresh rate. Using the code below I am getting about 1.2 refreshes/sec. This is a bit low for what I am using it for and would like it to be around 10 refreshes/sec.

Is this the limitation of the sensor itself? Are there other sensors I could use that would give more refreshes/sec?

The code I used is posted below, thank you for the help!

Code: Select all

from __future__ import division
import os
import glob
import time

os.system('modprobe w1-gpio')
os.system('modprobe w1-therm')

base_dir = '/sys/bus/w1/devices/'
device_folder = glob.glob(base_dir + '28*')[0]
device_file = device_folder + '/w1_slave'

def read_temp_raw():
    f = open(device_file, 'r')
    lines = f.readlines()
    f.close()
    return lines

def read_temp_f():
    lines = read_temp_raw()
    while lines[0].strip()[-3:] != 'YES':
        time.sleep(0.2)
        lines = read_temp_raw()
    equals_pos = lines[1].find('t=')
    if equals_pos != -1:
        temp_string = lines[1][equals_pos+2:]
        temp_c = float(temp_string) / 1000.0
        temp_f = temp_c * 9.0 / 5.0 + 32.0
        return temp_f

startTime = time.time()*1000
numberOfRefreshes = 0
millisecondsToRun = 30000
	
while time.time()*1000 - startTime < millisecondsToRun:
    read_temp_f()
    numberOfRefreshes += 1

print "Refresh Rate = " + str(numberOfRefreshes/(millisecondsToRun/1000)) + " refreshes/sec"

User avatar
DeeJay
Posts: 2027
Joined: Tue Jan 01, 2013 9:33 pm
Location: East Midlands, UK

Re: DS18B20 Low Refresh Rate

Mon May 19, 2014 6:32 pm

From the sensor datasheet here - http://www.maximintegrated.com/datashee ... vp/id/2812
Converts Temperature to 12-Bit Digital Word in 750ms (Max)
That looks as if 1.2 refreshes per sec is pretty much what you might expect?
How To Ask Questions The Smart Way: http://www.catb.org/~esr/faqs/smart-questions.html
How to Report Bugs Effectively: http://www.chiark.greenend.org.uk/~sgtatham/bugs.html

danjperron
Posts: 3402
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: DS18B20 Low Refresh Rate

Mon May 19, 2014 7:20 pm

You could change the resolution of the DS18B20. By reducing to 11 bits instead of 12 it will run twice faster.

I don't know how to change it with the RPI but with a arduino it is easy.
P.S. If you change the bit resolution, the probe will be set for the resolution in eerom. Even if you power off the probe , it will be set to that resolution.

I never test a modified probe on the RPI but I assume it will work.

But in my opinion the heat transfer speed is really the issue. How to do you intend to transfer the heat to the sensor?
Having a very fast sensor doesn't work very well if the heat transfer is not very good. I didn't find any speck about the
heat transfer speed. Better use a TO-92 case with direct contact, not a sealed metal probe.


I.M.O. The best sensors to check temperature fast are the ones looking at infrared signal.
(Black body radiation theory).

Daniel

User avatar
Jufo
Posts: 25
Joined: Fri May 23, 2014 11:49 am
Location: Warsaw, Poland
Contact: Website

Re: DS18B20 Low Refresh Rate

Fri May 23, 2014 11:57 am

How to change this resolution ?, any solution ?, maybe new library for ds18b20...
Best Regards
Robert

danjperron
Posts: 3402
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: DS18B20 Low Refresh Rate

Fri May 23, 2014 3:37 pm

Maybe sending a small stream using the SPI of the Raspberry pi should do.

I will try it this week end.


But I'm convince that the delay in temperature between the sensor and what you want to measure will be worst than one second. I don't think that the physical heat transfer will be fast enough.

Daniel

BMS Doug
Posts: 3824
Joined: Thu Mar 27, 2014 2:42 pm
Location: London, UK

Re: DS18B20 Low Refresh Rate

Fri May 23, 2014 3:46 pm

Jufo wrote:How to change this resolution ?, any solution ?, maybe new library for ds18b20...
pages 7 & 8 of this data sheet detail how to change the resolution across the one wire network. 9 bit resolution has a conversion time of 93.75ms which should allow 10 samples / second.
Doug.
Building Management Systems Engineer.

User avatar
FLYFISH TECHNOLOGIES
Posts: 1750
Joined: Thu Oct 03, 2013 7:48 am
Location: Ljubljana, Slovenia
Contact: Website

Re: DS18B20 Low Refresh Rate

Fri May 23, 2014 3:51 pm

Hi,
Jufo wrote:How to change this resolution ?
You can change the resolution with 0x4E command.
To decrease resolution to 0.5 deg (conversion time is then below 100ms), the command's 3rd parameter (byte) must contain value 0x1F.


Best wishes, Ivan Zilic.
Running out of GPIO pins and/or need to read analog values?
Solution: http://www.flyfish-tech.com/FF32

danjperron
Posts: 3402
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: DS18B20 Low Refresh Rate

Fri May 23, 2014 4:29 pm

You didn't tell us yet how you are doing the heat transfer. I think this is the weak point anyway.


I'm not sure that the raspberry pi will behave faster even if you put the probe faster.

This is one wire system and the Raspberry Pi will check for other sensor . I really don't know the full cycle behavior of the
Raspberry Pi 1 wire implementation.


I start to think that you will need a small cpu like a arduino mini to get the maximum speed of the sensor.

B.T.W. Do you need only one sensor?

I did have a project which is a remote sensor system using different physical link, RS-485, serial TTL , Xbee,....
I do have the code for 2 I/O that handle the DS18B20. It will handle the bit resolution of the sensor but I do capture of sensor every second. The code could be change (removing the wait).

Have a look at this post. If you need more than one probe and want to capture the temperature fast. it is easy to use one module for each and gather the information. I did test and the system handle 200+ transactions/sec.

http://www.raspberrypi.org/forums/viewt ... 12#p538112

Daniel

danjperron
Posts: 3402
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: DS18B20 Low Refresh Rate

Sat May 24, 2014 8:44 pm

Ok this is a small code in C.

You will be able to change the DS18B20 configuration.

But even if you change the sample rate, the Raspberry Pi 1Wire system won't change its own rate. Than it is not good if you use the build-in driver.

My code works but it is in the user space. You will have to run it many times since it won't always works.
Exact timing is not very good in user space.

You could derive this C code to have a faster reading but you will have to add the Serial identification code. I just use the skip code mode.

To compile it just do

gcc -o configDS18B20 configDS18B20.c

This is the console output . This demonstrate that I need to retry often to change the settings but since you need to do it only once, it is not a problem.

Code: Select all

[email protected] ~ $ sudo ./configDS18B20
[email protected] ~ $ sudo ./configDS18B20
.....42 01 4E 55 7F FF 0E 10 72 
12 bits  Temperature:  20.12 +/- 0.062500 Celsius
DS18B20 Resolution (9,10,11 or 12) ?9
Try to set 9 bits  config=1F
[email protected] ~ $ sudo ./configDS18B20
.....42 01 4E 55 7F FF 0E 10 72 
12 bits  Temperature:  20.12 +/- 0.062500 Celsius
DS18B20 Resolution (9,10,11 or 12) ?9
Try to set 9 bits  config=1F
[email protected] ~ $ sudo ./configDS18B20
.....42 01 4E 55 1F FF 0E 10 E2 
09 bits  Temperature:  20.12 +/- 0.500000 Celsius
DS18B20 Resolution (9,10,11 or 12) ?

B.T.W. I'm using the GPIO10 , the SPIO MOSI. Be sure that you are not using the SPI, but you could change to any GPIO by changing the DS_PIN in the source code. You can't use the GPIO4 unless you disable the 1wire driver.

This is the source code

Code: Select all

// modified version to read DS18B20 in bit banging
//
//  24 May 2014
//  Daniel Perron
//
// Use At your own risk




//
//  How to access GPIO registers from C-code on the Raspberry-Pi
//  Example program
//  15-January-2012
//  Dom and Gert
//  Revised: 15-Feb-2013


// Access from ARM Running Linux

#define BCM2708_PERI_BASE        0x20000000
#define GPIO_BASE                (BCM2708_PERI_BASE + 0x200000) /* GPIO controller */


#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <unistd.h>
#include <time.h>

#define PAGE_SIZE (4*1024)
#define BLOCK_SIZE (4*1024)

int  mem_fd;
void *gpio_map;

// I/O access
volatile unsigned *gpio;


// GPIO setup macros. Always use INP_GPIO(x) before using OUT_GPIO(x) or SET_GPIO_ALT(x,y)
#define INP_GPIO(g) *(gpio+((g)/10)) &= ~(7<<(((g)%10)*3))
#define OUT_GPIO(g) *(gpio+((g)/10)) |=  (1<<(((g)%10)*3))
#define SET_GPIO_ALT(g,a) *(gpio+(((g)/10))) |= (((a)<=3?(a)+4:(a)==4?3:2)<<(((g)%10)*3))

#define GPIO_SET *(gpio+7)  // sets   bits which are 1 ignores bits which are 0
#define GPIO_CLR *(gpio+10) // clears bits which are 1 ignores bits which are 0

#define GPIO_READ(g)  (*(gpio + 13) &= (1<<(g)))


#define DS18B20_SKIP_ROM 		0xCC
#define DS18B20_CONVERT_T 		0x44
#define DS18B20_READ_SCRATCHPAD         0xBE
#define DS18B20_WRITE_SCRATCHPAD        0x4E
#define DS18B20_COPY_SCRATCHPAD         0x48

unsigned char ScratchPad[9];
double  temperature;
int   resolution;

void setup_io();


#define  DS_PIN  10


int  DoReset(void)
{
 int loop;

   INP_GPIO(DS_PIN);


   usleep(1000);

   INP_GPIO(DS_PIN);
   OUT_GPIO(DS_PIN);
   
   // pin low for 480 us
   GPIO_CLR=1<<DS_PIN;
   usleep(480);
   INP_GPIO(DS_PIN);
   usleep(60);
   if(GPIO_READ(DS_PIN)==0)
   {
     usleep(380);
     return 1;
   }
 
  return 0;
}

#define DELAY1US  smalldelay();

void  smalldelay(void)
{
  int loop2;
   for(loop2=0;loop2<100;loop2++);
}



void WriteByte(unsigned char value)
{
  unsigned char Mask=1;
  int loop;

   for(loop=0;loop<8;loop++)
     {
       INP_GPIO(DS_PIN);
       OUT_GPIO(DS_PIN);
       GPIO_CLR= 1 <<DS_PIN;

       if((value & Mask)!=0)
        {
           DELAY1US
            INP_GPIO(DS_PIN);
           usleep(60);

        }
        else
        {
           usleep(60);
           INP_GPIO(DS_PIN);
           usleep(1);
        }
      Mask*=2;
      usleep(60);
    }


   usleep(100);
}


unsigned char ReadBit(void)
{
   INP_GPIO(DS_PIN);
   OUT_GPIO(DS_PIN);
   // PIN LOW
   GPIO_CLR= 1 << DS_PIN;
   DELAY1US
   // set INPUT
   INP_GPIO(DS_PIN);
   DELAY1US
   DELAY1US
   DELAY1US
   if(GPIO_READ(DS_PIN)!=0)
     return 1;
   return 0;
}

unsigned char ReadByte(void)
{

   unsigned char Mask=1;
   int loop;
   unsigned  char data=0;

  int loop2;


   for(loop=0;loop<8;loop++)
     {
       //  set output
       INP_GPIO(DS_PIN);
       OUT_GPIO(DS_PIN);
       //  PIN LOW
       GPIO_CLR= 1<<DS_PIN;
       DELAY1US
       //  set input
       INP_GPIO(DS_PIN);
       // Wait  2 us
       DELAY1US
       DELAY1US
       DELAY1US
       if(GPIO_READ(DS_PIN)!=0)
       data |= Mask;
       Mask*=2;
       usleep(60);
      }

    return data;
}



int ReadScratchPad(void)
{
   int loop;

    if(DoReset())
     {
       WriteByte(DS18B20_SKIP_ROM);
       WriteByte(DS18B20_READ_SCRATCHPAD);
       for(loop=0;loop<9;loop++)
         {
          ScratchPad[loop]=ReadByte();
        }
    return 1;
  }
  return 0;
}

unsigned char  CalcCRC(unsigned char * data, unsigned char  byteSize)
{
   unsigned char  shift_register = 0;
   unsigned char  loop,loop2;
   char  DataByte;

   for(loop = 0; loop < byteSize; loop++)
   {
      DataByte = *(data + loop);
      for(loop2 = 0; loop2 < 8; loop2++)
      {
         if((shift_register ^ DataByte)& 1)
         {
            shift_register = shift_register >> 1;
            shift_register ^=  0x8C;
         }
         else
            shift_register = shift_register >> 1;
         DataByte = DataByte >> 1;
      }
   }
   return shift_register;
}

int ReadSensor(void)
{
  int maxloop;
  int RetryCount;
  int loop;
  unsigned char  CRCByte;
  union {
   short SHORT;
   unsigned char CHAR[2];
  }IntTemp;


  time_t t = time(NULL);
  struct tm tm = *localtime(&t);

  temperature=-9999.9;

  for(RetryCount=0;RetryCount<3;RetryCount++)
  {

  if(!DoReset()) continue;

  // start a conversion
  WriteByte(DS18B20_SKIP_ROM);
  WriteByte(DS18B20_CONVERT_T);


  maxloop=0;
  // wait until ready
   while(!ReadBit())
   {
    putchar('.');
     maxloop++;
    if(maxloop>100000) break;
   }

  if(maxloop>100000) continue;


  if(!ReadScratchPad()) continue;

     for(loop=0;loop<9;loop++)
       printf("%02X ",ScratchPad[loop]);
     printf("\n");fflush(stdout);

  // OK Check sum Check;
  CRCByte= CalcCRC(ScratchPad,8);

  if(CRCByte!=ScratchPad[8]) continue;

  //Check Resolution
   resolution=0;
   switch(ScratchPad[4])
   {

     case  0x1f: resolution=9;break;
     case  0x3f: resolution=10;break;
     case  0x5f: resolution=11;break;
     case  0x7f: resolution=12;break;
   }

   if(resolution==0) continue;
    // Read Temperature

    IntTemp.CHAR[0]=ScratchPad[0];
    IntTemp.CHAR[1]=ScratchPad[1];


    temperature =  0.0625 * (double) IntTemp.SHORT;
      
      printf("%02d bits  Temperature: %6.2f +/- %f Celsius\n", resolution ,temperature, 0.0625 * (double)  (1<<(12 - resolution)));

    return 1;
   }
  return 0;
}




void WriteScratchPad(unsigned char TH, unsigned char TL, unsigned char config)
{
int loop;

    // First reset device

    DoReset();

    usleep(1000);
    // Skip ROM command
     WriteByte(DS18B20_SKIP_ROM);


     // Write Scratch pad

    WriteByte(DS18B20_WRITE_SCRATCHPAD);

    // Write TH

    WriteByte(TH);

    // Write TL

    WriteByte(TL);

    // Write config

    WriteByte(config);
}

void  CopyScratchPad(void)
{

   // Reset device
    DoReset();
    usleep(1000);

   // Skip ROM Command

    WriteByte(DS18B20_SKIP_ROM);

   //  copy scratch pad

    WriteByte(DS18B20_COPY_SCRATCHPAD);
    usleep(100000);
}


int main(int argc, char **argv)
{
  int loop;
  int config;
  // Set up gpi pointer for direct register access
  setup_io();
  if(ReadSensor())
    {
     printf("DS18B20 Resolution (9,10,11 or 12) ?");fflush(stdout);

    config=0;
    if(scanf("%d",&resolution)==1)
      {
        switch(resolution)
         {
           case 9:  config=0x1f;break;
           case 10: config=0x3f;break;
           case 11: config=0x5f;break;
           case 12: config=0x7f;break;
         }
      }

    if(config==0)
         printf("Invalid Value! Nothing done.\n");
    else
    {
      printf("Try to set %d bits  config=%2X\n",resolution,config);
      usleep(1000);
      WriteScratchPad(ScratchPad[2],ScratchPad[3],config);
      usleep(1000);
      CopyScratchPad();
    }
  }

  return 0;

} // main


//
// Set up a memory regions to access GPIO
//
void setup_io()
{
   /* open /dev/mem */
   if ((mem_fd = open("/dev/mem", O_RDWR|O_SYNC) ) < 0) {
      printf("can't open /dev/mem \n");
      exit(-1);
   }

   /* mmap GPIO */
   gpio_map = mmap(
      NULL,             //Any adddress in our space will do
      BLOCK_SIZE,       //Map length
      PROT_READ|PROT_WRITE,// Enable reading & writting to mapped memory
      MAP_SHARED,       //Shared with other processes
      mem_fd,           //File to map
      GPIO_BASE         //Offset to GPIO peripheral
   );

   close(mem_fd); //No need to keep mem_fd open after mmap

   if (gpio_map == MAP_FAILED) {
      printf("mmap error %d\n", (int)gpio_map);//errno also set!
      exit(-1);
   }

   // Always use volatile pointer!
   gpio = (volatile unsigned *)gpio_map;


} // setup_io

Daniel

User avatar
Jufo
Posts: 25
Joined: Fri May 23, 2014 11:49 am
Location: Warsaw, Poland
Contact: Website

Re: DS18B20 Low Refresh Rate

Sun May 25, 2014 11:06 am

I have two configuration implemented ds18b20 in my raspberry pi:
First 1-wire (gpio4) 4 x ds18b20 - very slowly reading, measuring 1 per 3s for all sensors (only ds18b20).
I think that the best way to obtain measuring time expected 1-2 per 1s for all sensor ds18b20 when I change resolution to 9 bit.
My sensor measuring:
1 sensor for CPU evapolator block (yes it works in scope -20C to +40C)
2 sensor for compressor
3 sensor for condenser1
4 sensor for condenser2
Second 1-wire (gpio17) 1 x DHT11 sensor for computer chasis (I know that it's very slow, it's only helpful sensor for envirment conditions - hum + temp).

Could you suggest how to resolve my problem easily? What's the best solution, in your opinion? :)

Thanks for help
Regards
Robert
Best Regards
Robert

danjperron
Posts: 3402
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: DS18B20 Low Refresh Rate

Sun May 25, 2014 12:02 pm

Well I will go with an Arduino device.

They are cheap, the funduino mini is good enough.

This way you could use the DS18B20 individually and speed up the process
with one sensor per arduino and transfer the data to a raspberry PI.


Did you look at the project on my previous post.
I'm doing the PCB for the 10 i/O version but look at the 2 I/O version.
This will be the best fit for you .
Each module could have a sensor attach to it and it will run each sensor at full rate.
It is using the modbus protocol with the RS-485 interface.

You will need 5 modules each corresponding to your previous post. And if you want 2 samples/sec you will be at 11 bits resolution.

Each module will be able the convert the DS18B20 sensor individually and by this increase the process speed.

I'm still on alpha prototype but I think it will be your best shot.
You could read all the sensors , except for the DHT12, at least twice per second.
It is limited by the sensor speed since the transfer rate is around 200 transactions/sec
Each Transaction will transfer one sensor data.


This is the Document (cut and paste from my water detect module).

https://docs.google.com/document/d/1Nex ... sp=sharing

This is the github for the 2 I/O module
https://github.com/danjperron/PicMultiPurpose.git

and the 10 I/O
https://github.com/danjperron/PIC_MULTI_10_IO.git

The 10 I/O module is more recent but it won't fit your need.

And this the post about it
http://www.raspberrypi.org/forums/viewt ... 12#p538112
I'm still waiting for already made usb to RS-485 module but everything works fine.
I could change the code to increase the DS18B20 speed cycle in the 2 I/O module.

B.T.W. I do have a Python Library and C code source code example on how to interfacing it.
The 2 I/O is not presently compatible with the 10 I/O version (The PicModule.py is different since I put a lock mecanism on the configuration register).
I put my effort on the 10 I/O but I will need to revise The 2 I/O and make them both compatible.


Are good are you with electronics and C coding?


Hope this help.

Daniel

danjperron
Posts: 3402
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: DS18B20 Low Refresh Rate

Sun May 25, 2014 12:11 pm

B.T.W.

I don't see the point to be faster than one sample every 10 sec, even 30 sec, for your setup. The raspberry PI itself should be enough.

My module will work but I don't really see why you need to check the temp twice per second.


Daniel

User avatar
FLYFISH TECHNOLOGIES
Posts: 1750
Joined: Thu Oct 03, 2013 7:48 am
Location: Ljubljana, Slovenia
Contact: Website

Re: DS18B20 Low Refresh Rate

Sun May 25, 2014 2:23 pm

Hi Robert,
Jufo wrote:Could you suggest how to resolve my problem easily?
The best approach is to first understand, what the problem actually is... You're focused on consequences.

A typical DS18B20 temperature measurement procedure contains three main steps. One option waits until the internal measurement is completed, where the second waits predefined amount of time.
Option a:
1) send command to start measurement
2) poll the sensor until measurement is completed
3) read result
4) goto step 1

Option b:
1) send command to start measurement
2) wait fixed amount of time (eg. 750ms)
3) read result
4) goto step 1

In case of multiple sensors, you can use non-optimized or optimized approach. According to your explanation, your implementation is not optimized (you perform three steps for sensor #1, then three for sensor #2, etc.). The optimized option is the following:
1) send command to sensor #1 to start measurement
2) send command to sensor #2 to start measurement
3) send command to sensor #3 to start measurement
4) send command to sensor #4 to start measurement
5) poll the sensor #1 until measurement is completed
6) read result from sensor #1
7) send command to sensor #1 to start measurement
8) poll the sensor #2 until measurement is completed (typically, this step is executed only once or in worst case just few times)
9) read result from sensor #2
10) send command to sensor #2 to start measurement
11) poll the sensor #3 until measurement is completed (typically, this step is executed only once or in worst case just few times)
12) read result from sensor #3
13) send command to sensor #3 to start measurement
14) poll the sensor #4 until measurement is completed (typically, this step is executed only once or in worst case just few times)
15) read result from sensor #4
16) send command to sensor #4 to start measurement
17) goto step 5

This procedure takes just slightly longer comparing to time spent when you read temperature from a single sensor, because when first sensor starts its measurement, instead of waiting it to complete, you're dealing with 2nd sensor, etc.


Best wishes, Ivan Zilic.
Running out of GPIO pins and/or need to read analog values?
Solution: http://www.flyfish-tech.com/FF32

danjperron
Posts: 3402
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: DS18B20 Low Refresh Rate

Sun May 25, 2014 5:17 pm

The way Yvan describe is the way to do it with an arduino!

But if you want to do that on the Raspberry PI, you will need to do your own driver in the kernel space. I don't think the current 1 wire driver has this option. The version I gave you is not %100 at all times, (timing issue) it is in user space.

Like I said I will go with an Arduino board.


Why do you need that speed in a cooler system? In my perspective , this is a very slow process. I will try figure out the temperature curve of all system first, analyze it and then I will check what is really the minimum sampling needed.

I'm practically certain that you over design your need.

Daniel

User avatar
FLYFISH TECHNOLOGIES
Posts: 1750
Joined: Thu Oct 03, 2013 7:48 am
Location: Ljubljana, Slovenia
Contact: Website

Re: DS18B20 Low Refresh Rate

Sun May 25, 2014 5:27 pm

Hi Daniel,
danjperron wrote:But if you want to do that on the Raspberry PI, you will need to do your own driver in the kernel space.
Don't scare him with the worst possible option... There are cheaper solution(s) than adding Arduino board for each sensor, and they work on RasPi without a need to write any driver code or touching the kernel.


Best wishes, Ivan Zilic.
Running out of GPIO pins and/or need to read analog values?
Solution: http://www.flyfish-tech.com/FF32

danjperron
Posts: 3402
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: DS18B20 Low Refresh Rate

Sun May 25, 2014 6:11 pm

No you just need one arduino mini or the cheap funduino version (Chinese version)

If you don't have any way to program the mini, use the arduino UNO is around $15 under $12 on alibaba.com.

I will put all sensor on the same Arduino pin and I will modify your previous step
by using the "SKIP CODE" command 0xcc, This way you could start conversion on all sensor at once, wait until all of them have the conversion done , using the bit reading function, and then use the serial number of each sensor to read each scratch pad register.

And finaly send the data to the serial port, /dev/ttyAMA0,of the Raspberry PI.



This is Fast elegant

Unless you know a way to use the Raspberry PI only, without another cpu.

I think this is the best method if you don't want to write into the kernel.



Daniel

danjperron
Posts: 3402
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: DS18B20 Low Refresh Rate

Sun May 25, 2014 6:50 pm

OK I found an option.

use the I2C to 1 Wire option board.

one like this one.

http://www.pridopia.co.uk/pi-2803-ad-da-1wire.html

or that one

http://www.sheepwalkelectronics.co.uk/p ... ucts_id=30

Now you will be able to send command directly to the sensor using I2C.


Daniel

User avatar
FLYFISH TECHNOLOGIES
Posts: 1750
Joined: Thu Oct 03, 2013 7:48 am
Location: Ljubljana, Slovenia
Contact: Website

Re: DS18B20 Low Refresh Rate

Sun May 25, 2014 7:48 pm

Hi,
danjperron wrote:OK I found an option.
use the I2C to 1 Wire option board.
Perform search also for USB to 1-Wire board.

[I just couldn't resist... ;-)]


Best wishes, Ivan Zilic.
Running out of GPIO pins and/or need to read analog values?
Solution: http://www.flyfish-tech.com/FF32

User avatar
Jufo
Posts: 25
Joined: Fri May 23, 2014 11:49 am
Location: Warsaw, Poland
Contact: Website

Re: DS18B20 Low Refresh Rate

Sun May 25, 2014 8:10 pm

danjperron wrote:B.T.W.
My module will work but I don't really see why you need to check the temp twice per second.
Daniel
OK, maybe 1 per 1s for all sensor ds18b20.
I'll want to create a PID for the speed compressor (BLDC motor with driver) as a function of temperature.
I would like to use the minimum number of electronics modules. In this moment I use:
I2C bus - LCD 4x20
I2C bus - RTC (modify Tiny RTC)
1-WIRE - 4 x ds18b20
1-WIRE - 1 x DHT11

In the near future:
??? - voltage regulator for speed command (Linear) moto-driver BLDC compressor (scope 0,5 - 4,5V)
??? - reading voltage for current output (0,1V = 1A, max ? 1V = 10A ) compressor (reading from moto driver BLDC): http://www.aspencompressor.com/Download ... 9_2012.pdf
keypad with 4 buttons for LCD
PWM - 3 x fan 12x12 cm 12V
PWM - 1 x fan 12x12 cm 12V
WEB interface, email and SNMP

First photo prototype:
http://icebox.pl/wp-content/gallery/con ... cf6899.jpg
I begin the adventure with python, but I working on Windows and Linux (CentOS, now in Debian).
danjperron wrote:OK I found an option.
use the I2C to 1 Wire option board.
Now you will be able to send command directly to the sensor using I2C.
Daniel
Ok, I try,
Thanks for help
Best Regards
Robert

danjperron
Posts: 3402
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: DS18B20 Low Refresh Rate

Sun May 25, 2014 8:41 pm

I think your PID will have problem if you are using 1 sample/sec. I did check And a lot of people notice that the sensor has lag time, When you touch it it will register later (~ 5 sec). Heat has to be transfer from outside to inside the chip.It is not fast. Even if you read the sensor every second it will gives you a readout it gets "n" seconds before. You should try some experiment and check your lag time. And you should use a sample rate which is slower than your lag time.

At least attach your sensor directly to a metal plate of the unit (motors, condenser, etc) and clamp it on both side, to increase heat transfer.


Daniel

User avatar
FLYFISH TECHNOLOGIES
Posts: 1750
Joined: Thu Oct 03, 2013 7:48 am
Location: Ljubljana, Slovenia
Contact: Website

Re: DS18B20 Low Refresh Rate

Sun May 25, 2014 9:16 pm

Hi,
danjperron wrote:At least attach your sensor directly to a metal plate of the unit (motors, condenser, etc) and clamp it on both side, to increase heat transfer.
... and use thermal transfer paste.


Best wishes, Ivan Zilic.
Running out of GPIO pins and/or need to read analog values?
Solution: http://www.flyfish-tech.com/FF32

User avatar
Jufo
Posts: 25
Joined: Fri May 23, 2014 11:49 am
Location: Warsaw, Poland
Contact: Website

Re: DS18B20 Low Refresh Rate

Mon May 26, 2014 6:56 am

danjperron wrote:I think your PID will have problem if you are using 1 sample/sec. I did check And a lot of people notice that the sensor has lag time, When you touch it it will register later (~ 5 sec). Heat has to be transfer from outside to inside the chip.It is not fast. Even if you read the sensor every second it will gives you a readout it gets "n" seconds before. You should try some experiment and check your lag time. And you should use a sample rate which is slower than your lag time.

At least attach your sensor directly to a metal plate of the unit (motors, condenser, etc) and clamp it on both side, to increase heat transfer.
Daniel
Ok, in your opinion (practice) optimal time (probably) for this case should be ?. Of course I must perform some test ;)
FLYFISH TECHNOLOGIES wrote: ... and use thermal transfer paste.
Best wishes, Ivan Zilic.
Of course, It standard for Me ;)
Best Regards
Robert

User avatar
Jufo
Posts: 25
Joined: Fri May 23, 2014 11:49 am
Location: Warsaw, Poland
Contact: Website

Re: DS18B20 Low Refresh Rate

Mon May 26, 2014 3:20 pm

It's good idea to use this :
http://brainfyre.wordpress.com/2012/10/ ... le-review/

For features:
- voltage regulator for speed command (Linear) moto-driver BLDC compressor (scope 0,5 - 4,5V)
- reading voltage for current output (0,1V = 1A, max ? 1V = 10A ) compressor (reading from moto driver BLDC).
Best Regards
Robert

danjperron
Posts: 3402
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: DS18B20 Low Refresh Rate

Mon May 26, 2014 3:24 pm

Yes a simple A/D to read is ok.

B.T.W. you could use it also for temperature sensor like the TMP35.

Daniel

User avatar
FLYFISH TECHNOLOGIES
Posts: 1750
Joined: Thu Oct 03, 2013 7:48 am
Location: Ljubljana, Slovenia
Contact: Website

Re: DS18B20 Low Refresh Rate

Mon May 26, 2014 3:54 pm

Hi,
Jufo wrote:It's good idea to use this :
- voltage regulator for speed command (Linear) moto-driver BLDC compressor (scope 0,5 - 4,5V)
Consider using PWM (if possible).


Best wishes, Ivan Zilic.
Running out of GPIO pins and/or need to read analog values?
Solution: http://www.flyfish-tech.com/FF32

Return to “Automation, sensing and robotics”