grandad
New Member
No Quite So Confused.
Posts: 30
Raspberry Pi: Yes
Other Device: 2nd Pi, PCs, iPad, Android Tablet and many, many gadgets!
|
Post by grandad on Mar 4, 2014 12:13:55 GMT -8
Hi all,
I have the i2c bus set up on my Pi using level shifting of SCL/SDA and an MCP23017 to give me 5 volt capable outputs from the Pi. This also gives me better drive current, as I use a separate 5 volt supply to the MCP23017. I can run my little python programs from a terminal with no problem, but I would like to incorporate something in Local.py to allow a state change on any of the sixteen GPIOs of the MCP23017 in reaction to, say a temperature state detected and reported by RasPiConnectServer, or to a button press within the app. Has anyone achieved anything like this with RasPiConnectServer, or can point me to a relevant thread/article? (yep! I have used search)
I've taken a look at the Project Curacao Local.py, but that doesn't seem appropriate.
TIA Martin
|
|
|
Post by SDL on Mar 13, 2014 10:41:01 GMT -8
Martin,
What do you mean "allow a state change on any"? You mean take a button and change the state on a GPIO? If you are talking about using a temperature to change GPIOs, then you need a program that would run all the time, not just only on refresh as the RasPiConnectServer does.
This would be like the main program of Project Curacao rather than a Local.py
Best regards,
BP
|
|
grandad
New Member
No Quite So Confused.
Posts: 30
Raspberry Pi: Yes
Other Device: 2nd Pi, PCs, iPad, Android Tablet and many, many gadgets!
|
Post by grandad on Mar 14, 2014 2:22:46 GMT -8
BP, Yes you are of course correct - I obviously hadn't thought it through  I suppose, then, that I would like to be able to control the MCP23017 outputs from, say a button in the app, which would seem more appropriate. I have attempted to incorporate my little i2c python programs into a Local.py but as yet have not succeeded. If at first you don't succeed............. etc. etc. Martin
|
|
grandad
New Member
No Quite So Confused.
Posts: 30
Raspberry Pi: Yes
Other Device: 2nd Pi, PCs, iPad, Android Tablet and many, many gadgets!
|
Post by grandad on Mar 22, 2014 6:44:08 GMT -8
Well, I have now managed to use the i2c bus to control an MCP23017 and illuminate / extinguish an LED by use of buttons within the app - Whoop! So now I am tinkering with the idea of using opto isolators and triacs to enable me to control BIG 230v stuff with the app. The defines and button code is below. Maybe it will help some other poor noob  ( all in Local.py obviously) Loving RasPiConnectServer more and more each day!Martin import smbus # to talk to i2c
# define i2c MCP23017 registers IODIRA = 0x00 IODIRB = 0x01 IPOLA = 0x02 IPOLB = 0x03 GPINTENA = 0x04 GPINTENB =0x05 DEFVALA = 0x06 DEFVALB = 0x07 INTCONA = 0x08 INTCONB = 0x09 IOCON0 = 0x0A ICON1 = 0x0B GPPUA = 0x0C GPPUB = 0x0D INTFA = 0x0E INTFB = 0x0F INTCAPA =0x10 INTCAPB = 0x11 GPIOA = 0x12 GPIOB = 0x13 OLTA = 0x14 OLTB = 0x15
# Setup i2c bus and MCP23017 GPIO pins bus = smbus.SMBus(1) # use 0 for Rev 1 Raspi address = 0x20 # i2c address of MCP23017 bus.write_byte_data(address, IODIRA, 0x00) # GPIOA all outputs bus.write_byte_data(address, GPIOA, 0x00) # GPIOA pins low bus.write_byte_data(address, IODIRB, 0xFF) # GPIOB all inputs bus.write_byte_data(address, GPPUB, 0xFF) # GPIOB pull-ups
==========================
if (objectType == ACTION_BUTTON_UITYPE):
if (Config.debug()): print "ACTION_BUTTON_UTYPE of %s found" % objectServerID
# B-12 - play a sound and turn on an LED on the Raspberry Pi if (objectServerID == "B-12"):
#check for validate request # validate allows RasPiConnect to verify this object is here if (validate == "YES"): outgoingXMLData += Validate.buildValidateResponse("YES") outgoingXMLData += BuildResponse.buildFooter() return outgoingXMLData
# not validate request, so execute
# note that python is in the main directory for this call, not the local directory
output = subprocess.call(["aplay", "sounds/shutter.wav"]) bus.write_byte_data(address, GPIOA, 0x01) # turn on LED responseData = "OK" outgoingXMLData += BuildResponse.buildResponse(responseData) outgoingXMLData += BuildResponse.buildFooter() return outgoingXMLData
|
|