DS2408 onewire gpio4

376 views
Skip to first unread message

Toshi Bass

unread,
Feb 17, 2015, 8:10:35 AM2/17/15
to web...@googlegroups.com
Hi

Today I decided to tidy up things I left on the "back burner" on the very fist item I uncounted a problem.

Ages ago I built and successfully implemented a one-wire bus master circuit utilizing a DS2408 chip etc it works faultlessly and I transferred all my DS18B20's from the existing installation on GPIO 4 but I never got around to re-purposing GPIO4 back to a normal INPUT / OUTPUT so this morning I removed the resistor that is no longer used for the DS18B20 and expected if I restart the pi it would detect that and revert back to a normal pin, well it didn't work, so I googled how to install a DS18B20 to see if I had installed something to get the sensors working:

Nothing in  sudo nano /boot/config.txt 
Nothing in  sudo nano globals.py

sudo nano /etc/modules has:

#w1-gpio
#w1-therm
snd-bcm2835
i2c-bcm2708
i2c-dev
rtc-ds1307

So no problem there, I did a  sudo ./setup.sh skip-apt   no difference if I try to use gpio4 after setting it to OUTPUT it still get :

     GPIO.digitalWrite(4, value)
_webiopi.GPIO.InvalidDirectionException: The GPIO channel is not an OUTPUT

So the question's are - how does webiopi detect that GPIO4 is being used as a one-wrre pin initially and how do I revert back to a normal GPIO pin now its not being used for one-wire ?

Toshi

Andreas Riegg

unread,
Feb 17, 2015, 8:56:17 AM2/17/15
to web...@googlegroups.com
Hi Toshi,

you're caught in one of the automatisms of WebIOPi ...

The problem is the w1-gpio kernel driver, it configures GPIO4 to work as 1-wire master channel.

I assume you are sill using 1-wire devices plugged into a DS2482 master (not DS2408 ...). If you use any WebIOPi 1-wire device (e.g. a DS18B20) that uses class OneWire, WebIOPi tries to automatically load this module. It tries this even if you comment this out in /etc/modulesand it also does this if your 1-wire devices are attached to a hardware master chip like the DS2482. Without a patch you can't change this ...

See line 25 of bus.py:

    "ONEWIRE": {"enabled": False, "gpio": {4:"DATA"}, "modules": ["w1-gpio"], "wait": 2}

What can be done?

You may try to set the module w1-gpio on the Linux modules blacklist, this may hinder WebIOPi from loading, but this may create an Exception and stop WebIOPi from starting...

You may change line 25 of bus.py to


    "ONEWIRE": {"enabled": False, "gpio": {}, "modules": []}

call
sudo ./setup.sh skip-apt and see if that helps.

Andreas


Toshi Bass

unread,
Feb 17, 2015, 12:21:49 PM2/17/15
to web...@googlegroups.com

Hi Andreas

Thanks for you reply:

I have been running webiopi with w1-gpio blacklisted in  /etc/modules  for months so I can confirm it does not create an Exception, actually I had to blacklist this to prevent a problem with the raspberry camera module.

And unfortunately the hack to bus.py has no effect, just to confirm what I did :

I modified  /home/pi/webiopi/python/webiopi/devices/bus.py and pasted in "ONEWIRE": {"enabled": False, "gpio": {}, "modules": []}  instead of the original line

did  sudo ./setup.sh skip-apt

Then restarted the pi and checked result (no change)

Then I checked /usr/local/lib/python3.2/dist-packages/WebIOPi-0.7.0-py3.2-linux-armv6l.egg/webiopi/devices/bus.py to confirm the mod was present (it was)

Can you think of anything else that we could try that could effects this, if not then no real problem I will just live with it ?

Toshi

Toshi Bass

unread,
Feb 17, 2015, 12:32:53 PM2/17/15
to web...@googlegroups.com

Oh sorry forgot to mention, yes I mixed up the DS's -- 3 DS2408 - 6 DS18B20's and a couple of DS2413 connected to the DS2482-800 one-wire bus master.

Toshi 

Andreas Riegg

unread,
Feb 18, 2015, 7:52:32 AM2/18/15
to web...@googlegroups.com
Hi Toshi,

well this looks to be a bit more less obvious behaviour ...

The cheap answer for the business folks would be ... just live with it, its just one GPIO and you have more of them, its not worth the time to look for the problem :-)

For the maker folks ... well you have to analyse this now step by step first to get hints what could cause this effect.

The exception you get results from line 211 in bridge.c, so for any reason the GPIO 4 is not configured correct and the test fails.

You mentioned that you configured GPIO 4 as output, how did you do that? Are you sure that this call succeeded and left the port permanent to be an output?

As a starting point, I would just start WebIOPi, look at the RPi header HTML pages and watch the behaviour of the GPIO 4 pin.

Does it show up as IN, OUT or anything else (including nothing)?

If it shows as IN, can you switch it to OUT by clicking?

If it shows OUT, can you toggle the value?

If this does not work you can create a custom script that has a setup() method where GPIO 4 gets set to be an output with a Python call. Does this work without exception? If you call just after this the getFunction, does it still show OUT?

Aside this, you can also do some testing on shell level. I have attached a shell script that has commands (and comments how to use them) how to use GPIO ports from a pure shell (completely outside WebIOPi). You may try those commands and see what happens here with GPIO 4.

Andreas
server.sh

Toshi Bass

unread,
Feb 18, 2015, 12:43:30 PM2/18/15
to web...@googlegroups.com
Hi Andreas

Thanks again for your response, as I was writing this I did some test to ensure what I was saying was absolutely correct and It appears I was mistaken the modification in the post above has made a difference, I can now set GPIO 4 as a output or a input and it works fine in python

    print(GPIO.getFunction(4))  >> 0 if it's set to IN and 1 if it's set to OUTPUT 

    print(GPIO.digitalRead(4))  >> True if I GPIO.digitalWrite(4, 0 )  False if I GPIO.digitalWrite(4, 1)

The only problem is the GPIO-Monitor still shows ONE-WIRE and does not change color when the output changes (that's why I thought the mod made no difference) 

If make a button for GPIO4 in Index.html  here,s the kicker it does nothing but the color is Blue the same as the ONE-WIRE box on the GPIO-Monitor so we area little closer in fact as far as I am concerned close enough.

Toshi 


Andreas Riegg

unread,
Feb 19, 2015, 6:02:41 AM2/19/15
to web...@googlegroups.com
Hi Toshi,

what you see in the GPIO Monitor is a fairly complex cooperation of Python code (on RPi) and JScript code (within yor Browser). It looks like sometimes something is broken here, so you can't always rely on what you see in the Monitor. I had once the situation that I openend the GPIO Monitor and all Labels that show normally "IN" or "OUT" were just empty and showing nothing or showed "ALT" ... but after clicking on them, the correct labels reappeared. But I don't remember what was the exact constellation of Board revision, Raspbian revision etc. and I did not further investigate what caused the problem.

The patch from above only makes sure that w1-gpio kernel driver does not get loaded automatically when it is not needed. But it does not repair any things that have to do with webiopi.js that creates the GPIO Monitor when combined with the HTML page for the Monitor - and I will keep my fingers off that. Plus, there is some code in webiopi.js that does special things with GPIO4 ... I will also keep my fingers off that.

As a bottom line "warning" tip, if anyone uses any 1-wire functionality of WebIOPi please keep in mind that GPIO 4 may behave or look strange and just refrain from using it as a normal GPIO port. There is a small number of "untampered" native GPIOs and if the overall number does not fit for your project, use some breakout board with a chip that has dedicated digital I/O ports that work without hassles.

Andreas
Reply all
Reply to author
Forward
0 new messages