User avatar
rleyden
Posts: 67
Joined: Thu Jun 14, 2012 2:17 am

Re: kernel patch for Dallas 1-wire interface

Thu Aug 16, 2012 10:58 pm

Frank Buss wrote:I've applied the patch to the Raspbian kernel, this is the new repository:
Frank,
Thanks for the Raspbian patch. I got my DS18B20 sensor probe working after some trial and error.
I didn’t initially add a resistor to my pre-wired probe ( http://www.ebay.com/itm/1pcs-Waterproof ... 969wt_1503 ) because the Ebay listing said “no external components required”. Without the resistor the sensor is not detected. With a 4 K ohm resistor, everything was fine.

I also tried the method in your first post (I hadn’t read to the end of this thread). There were no errors but “lsmod” showed that w1-gpio hadn’t loaded. Of course, I didn't have the resistor at that point either.
Rich

User avatar
szrpj
Posts: 6
Joined: Tue Jul 03, 2012 9:17 pm
Contact: Website

Re: kernel patch for Dallas 1-wire interface

Sat Aug 18, 2012 9:27 pm

Frank, you are awesome and everything works great (few DS18B20). I hope all those patches will be in "default" raspberrypi/linux soon enough.

eldiabolosk
Posts: 15
Joined: Wed Aug 15, 2012 12:27 am

Re: kernel patch for Dallas 1-wire interface

Sun Aug 19, 2012 3:33 am

netomx wrote:Well now I use mplayer and it's working great, thank you guys. I made a little script, but I saw here that you use perl, and a lot of things, so I just used BASH

Code: Select all

#!/bin/bash
SENSORES=$(cat /sys/bus/w1/devices/w1_bus_master1/w1_master_slaves)
for item in ${SENSORES[*]}
do
VALOR=$(cat /sys/bus/w1/devices/$item/w1_slave | grep t= | cut -f2 -d= | awk '{print $1/1000}')
echo $VALOR
done
Save it to whatever name you want and give permissions, chmod a+x yourscript

and run it like this ./yourscript

enjoy it! I'll make another one but with some voices of MW3 and UrbanAssault =D

Hi,

Thanks for the BASH Script.
I am brand new to all this. I am fluent in BASH. Can use just BASH control devices? Such as reading temp sensors, control valves, etc? What is the advantage of using Tcl?

Ed

Thanks

eldiabolosk
Posts: 15
Joined: Wed Aug 15, 2012 12:27 am

Re: kernel patch for Dallas 1-wire interface

Sun Aug 19, 2012 3:38 am

pygmy_giant wrote:sorted it - needed to update lib/modules aswell as the /boot files ... couldn't use hexxeh's updater as I don't have a linux compatible internet connection as yet - I only have a 3g mobile broadband dongle (need to inxtall some bits and bobs to get it working) - have been thinking that it could possibly also be used as a GPS positioning device...?

GPS: I was thinking about such thing. For seismic acquisition work you can use GPS to sync time. I would love to know know more about it

WiFi: What do you have on mind. Could you use a WiFi modul from on old laptop that had debian drivers? Just an idea. Bear on mind I am brand new to all the hardware world. (It is quite exciting... where have I been all that time?)

User avatar
szrpj
Posts: 6
Joined: Tue Jul 03, 2012 9:17 pm
Contact: Website

Re: kernel patch for Dallas 1-wire interface

Sun Aug 19, 2012 10:04 pm

This is a thread for another topic (not 1-wire support, but some sort of "1-wire scripts"). But anyway — all those scripts should, in the first place, check if the CRC is OK and if it is print the result.

netomx
Posts: 80
Joined: Tue Oct 11, 2011 4:06 am

Re: kernel patch for Dallas 1-wire interface

Mon Aug 20, 2012 1:21 am

eldiabolosk wrote:
netomx wrote:Well now I use mplayer and it's working great, thank you guys. I made a little script, but I saw here that you use perl, and a lot of things, so I just used BASH

Code: Select all

#!/bin/bash
SENSORES=$(cat /sys/bus/w1/devices/w1_bus_master1/w1_master_slaves)
for item in ${SENSORES[*]}
do
VALOR=$(cat /sys/bus/w1/devices/$item/w1_slave | grep t= | cut -f2 -d= | awk '{print $1/1000}')
echo $VALOR
done
Save it to whatever name you want and give permissions, chmod a+x yourscript

and run it like this ./yourscript

enjoy it! I'll make another one but with some voices of MW3 and UrbanAssault =D

Hi,

Thanks for the BASH Script.
I am brand new to all this. I am fluent in BASH. Can use just BASH control devices? Such as reading temp sensors, control valves, etc? What is the advantage of using Tcl?

Ed

Thanks
Well, yeah. Look fot eh GPIO sensors, and you can echo 1 or 0 to an output.

davidmam
Posts: 101
Joined: Tue Dec 06, 2011 4:13 pm

Re: kernel patch for Dallas 1-wire interface

Mon Aug 20, 2012 8:40 am

The wiringPi library privides a nice command line interface to the GPIO port - well worth looking at.

maui
Posts: 25
Joined: Sun Jul 08, 2012 10:10 am

Re: kernel patch for Dallas 1-wire interface

Wed Aug 22, 2012 7:47 am

yeah wiring pi is very cool :)

I wrote a script myself a while ago. And I did a crc check, because I was getting a lot of false crc's

Of course you have to change the path for your device ;)

Code: Select all

########  simple script to get 18B20 data ######
## this script waits for a correct crc check ##
# - you need to apt-get install bc
# - change the directory of the sensor

#!/bin/bash

crc="NO"  

while [ $crc = "NO" ]
do
sensor_output=$(cat /sys/bus/w1/devices/28-000002c5b242/w1_slave | cut -c 30-)
crc=$(echo $sensor_output | cut -c 7-10 )
#echo $crc
done
temp_raw=$(echo $sensor_output | cut -c 11-)
temp=$(echo "0.001 * $temp_raw" | bc) 

echo $temp
exit 0
btw: Frank, is the kernel patched in the new Raspbian Image (2012-8-16)? ;)

dom
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5138
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge

Re: kernel patch for Dallas 1-wire interface

Thu Aug 23, 2012 3:42 pm

maui wrote:btw: Frank, is the kernel patched in the new Raspbian Image (2012-8-16)? ;)
No, but it is now in the official kernel source tree, and the latest kernel (available through rpi-update).

netomx
Posts: 80
Joined: Tue Oct 11, 2011 4:06 am

Re: kernel patch for Dallas 1-wire interface

Thu Aug 23, 2012 4:31 pm

dom wrote:
maui wrote:btw: Frank, is the kernel patched in the new Raspbian Image (2012-8-16)? ;)
No, but it is now in the official kernel source tree, and the latest kernel (available through rpi-update).
Thank you! will update today! That's the only thing that was stopping me to upgrade!

stes
Posts: 3
Joined: Fri Jun 15, 2012 1:07 am

Re: kernel patch for Dallas 1-wire interface

Fri Aug 24, 2012 8:36 pm

I've updated but my temperature data shows alot more errors than with the non-raspian (June) version. The non-raspbian 1-wire ran perfectly. Also, after a little time I lose my wifi connection. I'll try again with the next raspbian version.

irp
Posts: 10
Joined: Sun Aug 12, 2012 1:30 pm

Re: kernel patch for Dallas 1-wire interface

Sat Aug 25, 2012 9:05 am

Hi Folks,

I have three DS18B20's, and have installed 3.2.27+ on my raspbian image, and modprobed the w1-gpio module.

I see the /sys/bus/w1 directory populated. cat /sys/bus/w1/devices/w1_bus_master1/w1_master_slaves shows the two I have currently connected, while w1_master_slave_count also shows a correct count of two.

However....cding into the device directory (28-000003c1f78a or 28-000003c202d4 in my case) shows no w1_slave file...Anyone have any ideas ? Did I miss a step somewhere ? Are my devices just not generating data ? (And yes, I have a 4k7 resistor between Vcc and Data.

irp
Posts: 10
Joined: Sun Aug 12, 2012 1:30 pm

Re: kernel patch for Dallas 1-wire interface

Sat Aug 25, 2012 9:51 pm

Doh! My bad, I hadn't loaded the w1_therm module. That'll teach me to do these things early in the morning. All works great now, and I'll add the third one tomorrow

Sorry for the noise

Iain

User avatar
Frank Buss
Posts: 92
Joined: Fri Jan 06, 2012 4:39 pm
Contact: Website

Re: kernel patch for Dallas 1-wire interface

Mon Aug 27, 2012 10:36 pm

Good news: The 1-wire patch is now merged in the official Raspberry Pi Linux kernel and I guess will be included in the next Raspbian release, including the RTC support for DS1307:

https://github.com/raspberrypi/linux/pull/92

All the other patches for I2C, SPI etc. from this thread are already included in the next kernel version.

Phisatho
Posts: 5
Joined: Tue Jul 24, 2012 6:23 pm

Re: kernel patch for Dallas 1-wire interface

Sun Sep 02, 2012 5:02 pm

Hi Frank,

Thanks for the great work. It is now all too easy to do an ls to read from a 1-wire device. (My only complaint would be that it it is too easy!. I would have preferred the 1wireWrite, 1wireRead way).

Am I right in guessing that the /sys/bus/w1/devices/ is a virtual folder rather than a physical folder on the drive?

Are the devices periodically polled or read only when I do a ls?

I am trying a 18S20 sensor which is correctly reported. Thus the kernel module is autosensing the device type and computing the results accordingly.

Which 1wire devices are compatible with the module? How easy is it to add another device?

Phisatho
Posts: 5
Joined: Tue Jul 24, 2012 6:23 pm

Re: kernel patch for Dallas 1-wire interface

Sun Sep 02, 2012 5:06 pm

You have mentioned DS1307 as 1wire RTC. However, 1307 does not have 1wire interface, but i2c.

szigeti
Posts: 10
Joined: Thu Sep 06, 2012 1:29 pm

Re: kernel patch for Dallas 1-wire interface

Thu Sep 06, 2012 2:14 pm

How can read/write information directly from the DS2408?

The kernel found the devices

Code: Select all

pi@raspberrypi ~ $ ls /sys/bus/w1/devices/29-0000000fde25
driver  id  name  power  rw  subsystem  uevent
pi@raspberrypi ~ $
but the dmesg give the following:

Code: Select all

[  186.019990] w1_master_driver w1 bus master: Family 28 for 28.000003d1da64.88 is not registered.
[  186.079778] w1_master_driver w1 bus master: Family 28 for 28.0000040009a1.18 is not registered.
[  186.149775] w1_master_driver w1 bus master: Family 29 for 29.0000000fde25.18 is not registered.

szigeti
Posts: 10
Joined: Thu Sep 06, 2012 1:29 pm

Re: kernel patch for Dallas 1-wire interface

Fri Sep 07, 2012 10:58 am

After the loaded the (w1-ds2408) kernel module I see the following:

Code: Select all

pi@raspberrypi ~ $ ls -l /sys/bus/w1/devices/29-0000000fde25/
total 0
-r--r--r-- 1 root root    1 Sep  7 08:11 activity
-r--r--r-- 1 root root    1 Sep  7 08:11 cond_search_mask
-r--r--r-- 1 root root    1 Sep  7 08:11 cond_search_polarity
lrwxrwxrwx 1 root root    0 Sep  7 08:11 driver -> ../../../bus/w1/drivers/w1_slave_driver
-r--r--r-- 1 root root 4096 Sep  7 08:11 id
-r--r--r-- 1 root root 4096 Sep  7 08:11 name
-rw-rw-r-- 1 root root    1 Sep  7 08:18 output
drwxr-xr-x 2 root root    0 Sep  7 08:11 power
-r--r--r-- 1 root root    1 Sep  7 08:11 state
-rw-rw-r-- 1 root root    1 Sep  7 08:11 status_control
lrwxrwxrwx 1 root root    0 Sep  7 08:11 subsystem -> ../../../bus/w1
-rw-r--r-- 1 root root 4096 Sep  7 08:11 uevent
pi@raspberrypi ~ $ 
How can read/write the ports?

jansonz
Posts: 1
Joined: Mon Sep 10, 2012 11:25 am

Re: kernel patch for Dallas 1-wire interface

Mon Sep 10, 2012 11:26 am

I have exactly the same issue.

Any suggestions?

Phisatho
Posts: 5
Joined: Tue Jul 24, 2012 6:23 pm

Re: kernel patch for Dallas 1-wire interface

Tue Sep 11, 2012 8:33 pm

I mashed up the code found here with some pyQT code to create a GUI

Code: Select all

#!/usr/bin/python


from PyQt4.QtCore import *
from PyQt4.QtGui import *



sensorlistfile = open("/sys/bus/w1/devices/w1_bus_master1/w1_master_slaves")
sensorlist = sensorlistfile.read()
sensorlistfile.close()
sensorlist = sensorlist.splitlines()



@pyqtSlot(QWidget)
def read(label):
	count = 0
	html_code = """ """
	for sensor in sensorlist:
		crc="NO"
		count += 1
		html_code = html_code +"""<h2>Sensor-""" + str(count) + """</h2>"""
		html_code = html_code +"""<p>""" + str(sensor) + """</p>"""
		while (crc=="NO"):
			tfile = open("/sys/bus/w1/devices/" + sensor + "/w1_slave")
			text = tfile.read()
			tfile.close()
			# Split the text with new lines (\n) .
			firstline = text.split("\n")[0]
			crc = firstline.split(" ")[11]
#			html_code = html_code +"""<body><p>""" + crc + """</p></body>"""
		secondline = text.split("\n")[1]
		# Split the line into words, referring to the spaces, and select the 10th word (counting from 0).
		temperaturedata = secondline.split(" ")[9]
		# The first two characters are "t=", so get rid of those and convert the temperature from a string to a number.
		temperature = float(temperaturedata[2:])
		# Put the decimal point in the right place and display it.
		temperature = temperature / 1000
	#	print temperature
		html_code = html_code +"""<h1>""" + str(temperature) + """&deg;C</h1>"""
		html_code = html_code +"""<h1> . </h1>"""
		html_code = html_code +"""<p> </p>"""
		html_code = html_code +"""<p> </p>"""
		html_code = html_code +"""<p> </p>"""
		html_code = html_code +"""<p> </p>"""
		html_code = html_code +"""<p> </p>"""
		html_code = html_code +"""<p> </p>"""
		
	label.setText(html_code)
	#	print
	


app = QApplication([])

# create the window and set the title
win = QWidget()

# setGeometry(x_pos, y_pos, width, height)
# 1, 1 --> widget will expand to fit lable size
win.setGeometry(100, 150, 1, 1)

# create the label and insert html code as text
label = QLabel()
read(label)

qbtn = QPushButton('Refresh')
qtbtn = QPushButton('Quit')
qbtn.clicked.connect(lambda:read(label))
qtbtn.clicked.connect(QCoreApplication.instance().quit)
# use the grid layout manager
grid = QGridLayout()

# addWidget(widget, row, column, rowSpan=1, columnSpan=1)
grid.addWidget(label, 0, 0)
grid.addWidget(qbtn, 1, 0)
grid.addWidget(qtbtn, 1, 1)

win.setLayout(grid)
win.setWindowTitle('1-wire Temp')
win.show()
app.exec_()

Hope this will be useful to someone.

nry
Posts: 11
Joined: Sun Jul 22, 2012 12:29 pm

Re: kernel patch for Dallas 1-wire interface

Fri Sep 14, 2012 10:44 pm

Got it working finally!

Should I need to do modprobe w1-gpio every time I reboot though?

I plan on using about 5 sensors with varying lengths of cable ranging from 1m to 10m what if anything should I do to the circuit to protect my Pi?

Can I use an external power source so it's not drawing all the power through the CPU?

Phisatho
Posts: 5
Joined: Tue Jul 24, 2012 6:23 pm

Re: kernel patch for Dallas 1-wire interface

Tue Sep 18, 2012 3:36 pm

You don't have to worry about power consumption.
1-wire devices generally consume only in the micro-amps range (it doesn't hurt to check the datasheets)

If you are powering externally, common the grounds of RPi and the power supply.
Further, keep the voltage at 3.3V to avoid potential complications. (I would think 5V should be safe as the 1-wire bus is open collector type - that is - neither the master (RPi) nor the slaves supply any current into the bus - instead, they draw current from the bus. In any case the pull-up resistor should be connected only to 3.3V and not 5V).

nry
Posts: 11
Joined: Sun Jul 22, 2012 12:29 pm

Re: kernel patch for Dallas 1-wire interface

Tue Sep 18, 2012 6:57 pm

Phisatho wrote:You don't have to worry about power consumption.
1-wire devices generally consume only in the micro-amps range (it doesn't hurt to check the datasheets)

If you are powering externally, common the grounds of RPi and the power supply.
Further, keep the voltage at 3.3V to avoid potential complications. (I would think 5V should be safe as the 1-wire bus is open collector type - that is - neither the master (RPi) nor the slaves supply any current into the bus - instead, they draw current from the bus. In any case the pull-up resistor should be connected only to 3.3V and not 5V).
Thanks for this, I just want to be careful to not damage my Pi
Obviously if I am running a bunch of runs to various sensors then there is a small chance a cable could get damaged and short

So any sort of protection to save the Pi would be nice, but having very little knowledge of electronics besides being able to solder up a circuit from a diagram I am a little stuck so please excuse my uselessness when it comes to this area :roll:

szigeti
Posts: 10
Joined: Thu Sep 06, 2012 1:29 pm

Re: kernel patch for Dallas 1-wire interface

Thu Sep 20, 2012 8:14 am

szigeti wrote:After the loaded the (w1-ds2408) kernel module I see the following:

Code: Select all

pi@raspberrypi ~ $ ls -l /sys/bus/w1/devices/29-0000000fde25/
total 0
-r--r--r-- 1 root root    1 Sep  7 08:11 activity
-r--r--r-- 1 root root    1 Sep  7 08:11 cond_search_mask
-r--r--r-- 1 root root    1 Sep  7 08:11 cond_search_polarity
lrwxrwxrwx 1 root root    0 Sep  7 08:11 driver -> ../../../bus/w1/drivers/w1_slave_driver
-r--r--r-- 1 root root 4096 Sep  7 08:11 id
-r--r--r-- 1 root root 4096 Sep  7 08:11 name
-rw-rw-r-- 1 root root    1 Sep  7 08:18 output
drwxr-xr-x 2 root root    0 Sep  7 08:11 power
-r--r--r-- 1 root root    1 Sep  7 08:11 state
-rw-rw-r-- 1 root root    1 Sep  7 08:11 status_control
lrwxrwxrwx 1 root root    0 Sep  7 08:11 subsystem -> ../../../bus/w1
-rw-r--r-- 1 root root 4096 Sep  7 08:11 uevent
pi@raspberrypi ~ $ 
How can read/write the ports?
I got the following examples from the kernel modul's developer but I don't have time to test it.
read: dd if=./output bs=1 count=1 | hexdump
write: echo \x01 |dd of=./output bs=1 count=1

I will be happy if somebody try it and send back every feedback.

repton
Posts: 91
Joined: Sat Mar 17, 2012 6:06 pm
Location: North Yorkshire, UK.
Contact: Website

Re: kernel patch for Dallas 1-wire interface

Thu Sep 27, 2012 2:36 pm

I had a play with this yesterday and with the latest kernel (downloaded via the rpi-update tool) it worked perfectly first time. For testing I've got it connected to four DS18B20 sensors, two of which are within a foot of the RasPi, the third is then at the other end of a 3m cat5 and then the last one another 8m length of cat5 away from that, so just over 11m in total from the RasPi. So far it's working a treat apart from an occasional error reading the sensor nearest the RasPi (3 times in just over 24h) which could be a faulty sensor as it is the same one every time. I've just swapped it out for a DS18S20 and I'll see if the same thing keeps happening.

I've attached a file showing how it's all connected at the moment for testing. I've used the "Pi Cobbler" from Adafruit to connect the expansion header to the breadboard and it certainly makes life easy.

Does anyone think there might be a market for a small cheap PCB to go onto the expansion header to make it easier to connect 1-Wire devices to the RasPi's GPIO pin? I was thinking along the lines of having an RJ45 socket plus screw terminals for the bus connection and possibly including a DS18B20 on the PCB too. I reckon it could be sold as a kit for about £8 or ready assembled for about £10.

Paul
Attachments
2012-09-27_testing_raspi.jpg
2012-09-27_testing_raspi.jpg (53.51 KiB) Viewed 10846 times
UK Supplier of 1-Wire components, kits and modules:
http://www.sheepwalkelectronics.co.uk/

Return to “Interfacing (DSI, CSI, I2C, etc.)”

Who is online

Users browsing this forum: No registered users and 5 guests