Friday, March 18, 2016

Raspberry Pi - 81 DS18B20 Sensors on Multiple GPIO



Video Explanation


Two ways to get multiple GPIO working.

Bitbanging your gpio or using a modified kernel w1-therm module which requires editing some source files and recompiling the kernel.  I will cover the kernel mod later because of how extensive it is.  So this post will be on using the BitBangingDS18B20 program found here on github

My Temperature Grid Source is found here.  The grid is a websocket/web server in Python and runs the DS18B20Scan program and sends the data through the websocket on temperature change.  In order to get it to do it at the same time you will have to run each Bus/Pin on it's own thread.  I used the twisted
Here's the Basic code of how I brought the BitBangingDS18B20 code into my python project:

def DS18B20_Bus(pin,data):
        pins = [4,17,27,5,6,13,19,26,21]
        pins.reverse()
        pin = pins[int(pin)-1]
        busdata = []
        position = 0
        args = 'sudo ./DS18B20Scan -gpio {} -t {} -F'.format(pin,30).split(' ')
        process = Popen(args, stdout=PIPE)
        (results, err) = process.communicate()
        exit_code = process.wait()
        probes = re.findall('(\d{2}-\w{12} ):\s+(\d{0,2}).bits\s Temperature:\s(\d{1,3}.\d{1,4})', results)
        bus = pins.index(pin)+1
        #print probes
        for probe in probes:
            try:
               # print data[probe[0].replace(" ",'')]
                if data.has_key(probe[0].replace(" ",'')):
                    position=data[probe[0].replace(" ",'')]["Pos"]
                else:
                    position +=1
                    print probe, bus

                temperatureInfo = {"ID":probe[0].replace(" ",''),"Pos":position,"Bus":
                    bus,"Temperature": round(float(probe[2]),3)} #,'Time': time.time()
                if probe[2] !="185.0000":
                    busdata.append(temperatureInfo)
            except:
                pass
        return busdata



Benchmarked

How does this compare to the 1-wire modules, Kernel Module??




Hope this helps
-Ninja Nate

No comments :

Post a Comment