MCP230xx.py issues... :)

Talk about Adafruit Raspberry Pi® accessories!

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.py issues... :)

Postby waltermixxx » Mon Mar 11, 2013 9:35 pm

Hi there, here is my code I am trying to run...
I made sure Adafruit_MCP230xx.py and Adafruit_I2C.py are in the same folder as my MCP23017wm.py folder.
I'm using the WebIDE as well :)

Code: Select all
#! /usr/bin/python

from Adafruit_I2C import Adafruit_I2C
from Adafruit_MCP230xx import Adafruit_MCP230xx
import smbus

mcp = Adafruit_MCP230xx(busnum = 1, address = 0x20, num_gpios = 16)

mcp.config(0, OUTPUT)
mcp.config(1, OUTPUT)
mcp.config(8, OUTPUT)
mcp.config(9, OUTPUT)

mcp.output(0, 1)
mpc.output(1, 1)
mcp.output(8, 1)
mcp.output(9, 1)


I get the following error:

Traceback (most recent call last):
file "MCP23017wm.py", Line 4, in <module>
from Adafruit_MCP230xx import Adafruit_MCP230xx
ImportError: cannot import name Adafruit_MCP230xx

not sure why...
as indicated above both Adafruit_MCP230xx.py and Adafruit_I2C.py are in the folder with my MCP23017wm.py file...
using an Adafruit PiPlate :) and occidentalist, and the latest WebIDE installed this evening...

any help appreciated :)
waltermixxx
 
Posts: 8
Joined: Sat Apr 10, 2010 1:36 am

Re: MCP230xx.py issues... :)

Postby waltermixxx » Mon Mar 11, 2013 9:51 pm

Ok, I fixed it, wow it's very sensitive to upper and lower case letters... :) my first mistake was the xx being lower case in the from xxx import line 5, then instead of using mcp.config(0,OUTPUT) i used mcp.config(x, 0) where x was the pin on the mcp23017 chip :) so I have it working now... i updated the python script to turn them on, then off :)

:)

Code: Select all
#! /usr/bin/python

from time import sleep
from Adafruit_I2C import Adafruit_I2C
from Adafruit_MCP230xx import Adafruit_MCP230XX
import smbus

mcp = Adafruit_MCP230XX(busnum = 1, address = 0x20, num_gpios = 16)
# configuring these 4 pins as outputs :)
mcp.config(0, 0)
mcp.config(1, 0)
mcp.config(8, 0)
mcp.config(9, 0)

mcp.output(0, 1)
mcp.output(1, 1)
mcp.output(8, 1)
mcp.output(9, 1)

sleep(4)

mcp.output(0, 0)
mcp.output(1, 0)
mcp.output(8, 0)
mcp.output(9, 0)
waltermixxx
 
Posts: 8
Joined: Sat Apr 10, 2010 1:36 am

Re: MCP230xx.py issues... :)

Postby adafruit_support_mike » Tue Mar 12, 2013 3:47 pm

That's one of the hitch-steps in learning to think like a programmer. Computers can't 'read' code, they just treat it as patterns of bits. Humans, OTOH, interpret everything we read and associate a meaning with it.

Probably 90% of programming errors involve "human reads it one way but computer interprets the pattern of bits another way" issues.
When you void a product warrany, you give up your right to sue the manufacturer if something goes wrong and accept full responsibility for whatever happens next. And then you truly own the product.
User avatar
adafruit_support_mike
 
Posts: 1322
Joined: Thu Feb 11, 2010 1:51 pm

Re: MCP230xx.py issues... :)

Postby joep » Wed Mar 13, 2013 2:52 pm

Hi, all... I'm running into issues with the MCP230xx sample code myself... Trying to run it from the WebIDE, just as-is, I get the following nasty messages:
webide@raspberrypi /usr/share/adafruit/webide/repositories/Adafruit-Raspberry-Pi-Python-Code/Adafruit_MCP230xx $ sudo python Adafruit_MCP230xx.py
Traceback (most recent call last):
File "Adafruit_MCP230xx.py", line 183, in <module>
mcp = Adafruit_MCP230XX(address = 0x20, num_gpios = 8)
File "Adafruit_MCP230xx.py", line 45, in __init__
self.i2c = Adafruit_I2C(address=address, bus=smbus.SMBus(busnum))
IOError: [Errno 2] No such file or directory
webide@raspberrypi

Copying the program to my-ip-projects doesn't seem to work at all.... the "my-pi-projects" repository has an entry
for Adafruit_MCP230xx.py, but there's nothing in it, despite having opened the read-only versions of each of the 2 files in the "official" repository, and clicking on the "copy this project to my pi projects" link....

I'm more than a little confused.....

JoeP
joep
 
Posts: 5
Joined: Wed Jan 16, 2013 4:25 pm


Return to Adafruit Raspberry Pi® accessories

Who is online

Users browsing this forum: No registered users and 2 guests

Stuff to buy from the Adafruit store and links to product documentation!


New Products [105]

Raspberry Pi[80]
 
FLORA[23]
 
Bunnie Studios[9]
 
FPGA[1]
 
mbed[11]
Arduino[60]
 
NETduino[14]
 
BeagleBone[24]
 
Android[6]
 
XBee[10]
More Dev Boards[30]


 
BoArduino[8]
 
SpokePOV[4]
 
TV-B-Gone[4]
 
MiniPOV[3]
 
SIM reader[3]
 
Microtouch[5]
 
Clocks & Watches[18]
 
Drawdio[4]
 
Brain Machine[1]
 
Game of Life[2]
 
MintyBoost[2]
More DIY Kits[16]


 
MaKey MaKey[3]
 
Tweet-a-Watt[5]
 
Young Engineers[33]
 
Discover Electronics[2]
 
Snap Circuits[4]
 
littleBits[3]
 
Project packs[8]


 
Breakout Boards[33]
LCDs & Displays[48]
Components & Parts[69]
Batteries & Power[49]
EL Wire/Tape/Panel[52]
LEDs[108]
 
Wireless[14]
Cables[60]
 
Lasers[6]
Sensors/Parts[145]
 
Enclosures/Cases[11]
 
Solar[11]
 
RFID / NFC[13]
Prototyping[69]
 
iDevices[13]
Tools[71]
 
Wearables[39]
 
CNC[37]
 
Robotics[29]
 
3D printing[1]
 
Materials[24]


 
Stickers[41]
 
Skill badges[55]
 
Books[25]
 
Circuit Playground[7]
 
Gift Certificates[4]