MCP230xx code?
Moderators: adafruit_support_bill, adafruit

Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/

MCP230xx code?

by OhNoItsMrBill on Sun Feb 17, 2013 9:15 am

I am working on a project that is using the MCP23017. I am confused by your library and tutorial for this product. If I open the code in the Python IDLE, do the edits and save. That works. The code will only execute with terminal commands, however will not run from IDLE. IDLE complains that your syntax of tabs is messed up. Because of this, importing the library into my code is not working. Any tips?

Thanks,
Bill
OhNoItsMrBill
 
Posts: 20
Joined: Mon Sep 17, 2012 6:50 pm

Re: MCP230xx code?

by adafruit on Sun Feb 17, 2013 4:55 pm

you might have to replace the tabs with spaces, its something that IDLE might be sensitive to - we'll eventually readapt our python code to spaces instead of tabs but there's no ETA so for now please do it by hand.
User avatar
adafruit
 
Posts: 11679
Joined: Thu Apr 06, 2006 3:21 pm
Location: nyc

Re: MCP230xx code?

by tldr on Sun Feb 17, 2013 7:13 pm

the file doesn't look like they mix tabs and spaces at the beginnings of lines in any sort of irresponsible manner so you might try

Code: Select all | TOGGLE FULL SIZE
 sed "s/\t/        /g" Adafruit_MCP230xx.py > foooo


then you can try out foooo on the python interpreter and if it works replace the mcp23007 library with foooo. don't have an mcp23007 handy or i'd try it myself.
"If I had known it was harmless, I would have killed it myself." - Phillip K. Dick, A Scanner Darkly
User avatar
tldr
 
Posts: 466
Joined: Thu Aug 30, 2012 12:34 am

Re: MCP230xx code?

by OhNoItsMrBill on Sun Feb 17, 2013 7:46 pm

Tldr the file did have a few lines that were found using "Untabify Region". However, it looks like the code has to be run with Sudo as the GPIO appears to need root access. Is there any way around this?
OhNoItsMrBill
 
Posts: 20
Joined: Mon Sep 17, 2012 6:50 pm

Re: MCP230xx code?

by tldr on Mon Feb 18, 2013 8:36 am

OhNoItsMrBill wrote: However, it looks like the code has to be run with Sudo as the GPIO appears to need root access. Is there any way around this?


sudo is probably the easiest way to run your code. the other possibility would be to change the ownership or permissions on the various device files. problem is i'm not sure when or where these are created. some of them only seem to exist while your script is running. some of them can be created if you are logged in as root, (but i can't log in as root on my pi), or if you use "sudo -i", (which will effectively log you in as root).
"If I had known it was harmless, I would have killed it myself." - Phillip K. Dick, A Scanner Darkly
User avatar
tldr
 
Posts: 466
Joined: Thu Aug 30, 2012 12:34 am