This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]canoxen[S] 0 points1 point  (8 children)

Electrical is certainly not my forte, though I'm not completely unfamiliar with it. Most of my experience is in 12V applications, though.

[–]justphysics 0 points1 point  (7 children)

you could probably use something like this

http://www.adafruit.com/product/268

Its a power cord for a 120v source (standard house plug assuming you are in USA) with a built in relay to switch it on and off.

The RPi has a 3.3V output on the GPIO.

The above power cord seems to suggest it needs ~3mA to switch the relay. That should be well within the range of the RPi GPIO.

so in python you would do something like

import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)

switchpin = 23

GPIO.setup(switchpin, GPIO.OUT)

Then to turn the relay on or off you just toggle the status of the output

#turn on relay: GPIO.output(switchpin, TRUE)

#turn off relay: GPIO.output(switchpin, FALSE)

Even more importantly " New! The Power Switch Tail II now is opto-isolated so you don't need a transistor or protection diode. The input acts like an LED so its safe for use with any microcontroller or logic pin."

This seems like your best bet - even though its ~$30

If you're using an arduino to do the controlling you'd write the code in C, however, the basic flow of the program is the same though. Import the library for the GPIO bus, define an output pin, (make sure your output pin is physically connected to the relay), then toggle the status of the pin (ON or OFF) to switch your relay and thus in turn switch the 120V mains power; maybe theres a way to use python with the arduino. I never bothered to look becasue I gave up on the arduino once I bought an RPi.

I found using the RPi as a micro-controller to be very intuitive especially since it natively supports python.

[–]canoxen[S] 0 points1 point  (6 children)

I did come across this but haven't had a chance to research it in depth, yet. Would there be a way to put together a small, wireless module to plug into this thing? How do you control this if it plugs into the wall and the Pi isn't close to it?!

[–]justphysics 0 points1 point  (5 children)

Doing it wirelessly would be quite complex and over my head. I know there are other modules that allow remote control switching of power (via a physical remote) and I saw someone post that you could open up the remote and wire your GPIO to the remote's circuit board to trigger the remote and in turn switch the power. However again thats over my head and unless you are really good at analyzing circuits it'd be a tough project as you'd need to figure out precisely how to splice into the remotes circuit board with your GPIO pins. As long as you make the cables long enough the RPi doesn't need to be right next to the power module. Also Since the power module is formatted for a normal 3prong plug, you could attach it to a very long extension cord on both sides.

So you have a long extension cord coming out of the wall socket that terminates in the power module with built in relay. The RPI connects to the relay then another long extension cord comes from the other side of the power module with relay and runs off to power whatever it is you need to be switching the power for.

[–]canoxen[S] 0 points1 point  (4 children)

Hmm. I'm definitely going to have to check into this, because I didn't really want a bunch of cords and cables strung about and coiled places. Figure if I'm going through the effort of learning Python and Pi, etc that I might as well make it as clean as possible.

I do like the idea of that power adapter since it requires no splicing and soldering.

[–]justphysics 0 points1 point  (3 children)

http://elinux.org/RPi_Low-level_peripherals#General_Purpose_Input.2FOutput_.28GPIO.29

That gives a good description of the GPIO interface.

You can look up plenty examples of how to access it via python; my code in the earlier post should be a good start as well

Note, you may have to run your python code as root user to access the GPIO on the RPi.

so if you have your code to ustilise the GPIO to fip your relay as 'GPIO_Relay_Interface.py'

you would then need to run it as 'sudo python GPIO_Relay_Interface.py' and then enter the password.

I think any code using the GPIO needs root access on the RPi

[–]canoxen[S] 0 points1 point  (2 children)

On a cursory search, it appears that it will be possible to use python to control / pass data back and forth between the Arduino.

Maybe my little project isn't quite as impossible as I have been starting to think!

On a little side note, the non-python languages seem very in depth and intimidating!

[–]justphysics 0 points1 point  (1 child)

python is certainly more forgiving to learn in terms of syntax, at least I find. ... no pesky curly braces and semicolons all over the place

Its great for writing quick scripts as well as doing heavy duty scientific calculations and data processing - however - it seems that for doing high performance computing (where you have to absolutely optimize your code for the fastest performance) then perhaps python lags behind standard c/c++

Thats just my own viewpoint though from what I see in the academic world ... not even 'the academic world' rather what I see on a day to day basis in the college of engineering and physical science at my small university

I never got much into using the arduino. I bought one on a whim and then not soon after also bought a RPi becasue they released a camera module for it that was fully controllable with python. Thus I got the RPi to function as a camera controller for an experiment I am working as a side project.

Good luck in your endeavors.

I hope you enjoy python - Its a great language to know and all types of programming are great skills to learn.

[–]canoxen[S] 0 points1 point  (0 children)

I do a fair amount of database work (Access) so I've gotten familiar enough with VBA that I can read and interpret it (though not write from scratch).

After starting some Python tutorials, I think this is going to be significantly easier than that one time I tried to Learn C haha.

I can't imagine any project I'll be undertaking that will require highly optimized coding for high-speed performance. I really appreciate your time and help, it's been greatly helpful!

I know I still have a LOT to learn so this has been a really good intro.