aiw
Posts: 6
Joined: Tue Apr 22, 2014 12:18 pm

I2C reset?

Tue Apr 22, 2014 12:23 pm

I have the new Adafruit Occidentalis v0.2 loaded on my Pi and working great with my weather radio module. The problem I'm having is if I restart the python script for some reason I have to do a complete reboot of the Pi before I can successfully access the weather radio on the I2C bus again. I've tried to remove power from the radio to see if it was the radio that needed to be reset but that had no effect. It always needs the bus reset by rebooting.

Is there an easier way to do this within the the python script. For instance, if I set up a keyboard command to exit the script (sys.exit("program shutdown") can I also insert something that will reset the I2C bus so I don't have to reboot the Pi before it will successfully run the a script with an I2C device again.

The radio itself has a reset line and it does reset, but the address of the device can no longer be seen by the bus until reboot of the Pi.

User avatar
DougieLawson
Posts: 42213
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK

Re: I2C reset?

Tue Apr 22, 2014 7:56 pm

On Raspbian I can disable the I2C driver with
sudo rmmod i2c_dev
sudo rmmod i2c_bcm2708

I can re-enable it with
sudo modprobe i2c_bcm2708
sudo modprobe i2c_dev

That should work on other distros.
Languages using left-hand whitespace for syntax are ridiculous

DMs sent on https://twitter.com/DougieLawson or LinkedIn will be answered next month.
Fake doctors - are all on my foes list.

The use of crystal balls and mind reading is prohibited.

aiw
Posts: 6
Joined: Tue Apr 22, 2014 12:18 pm

Re: I2C reset?

Tue Apr 22, 2014 9:24 pm

Thanks for the reply!

Do you know if I would be able to call these system calls from within the python script as it closes out......

Not sure if this can be done since I'm fairly new to python.

aiw
Posts: 6
Joined: Tue Apr 22, 2014 12:18 pm

Re: I2C reset?

Tue Apr 22, 2014 9:33 pm

Tried to call these commands and they did not call errors, but when I tried to restart the python program the i2c device could not be detected. Might try the raspian image and see if there is any difference.

User avatar
DougieLawson
Posts: 42213
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK

Re: I2C reset?

Tue Apr 22, 2014 9:52 pm

You may want to see what modules are loaded with sudo lsmod before using sudo rmmod to remove them and sudo modprobe to put them back.

It seemed to work on my RPi running Raspbian (which has a MCP23017 mounted on the GPIO pins with an 8x8 LED on that).

There's lots of messages on dmesg when the I2C gets loaded and creates the devices in /dev.
Languages using left-hand whitespace for syntax are ridiculous

DMs sent on https://twitter.com/DougieLawson or LinkedIn will be answered next month.
Fake doctors - are all on my foes list.

The use of crystal balls and mind reading is prohibited.

aiw
Posts: 6
Joined: Tue Apr 22, 2014 12:18 pm

Re: I2C reset?

Wed Apr 23, 2014 2:17 am

OK, I ended up switching back to Raspian just to try and get this to work. I did fix it. I think the issue was in the fact that I wasn't using a "try" and "except" in the python file. As soon as I added those, most of my issues went away.

I will probably utilize a different SD card and load a fresh Occidentalis image to ensure it works on that image as well.

Thanks for the help.

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