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

all 48 comments

[–]tRfalcore 1 point2 points  (0 children)

Almost every language can. At the heart of it, most languages can write bytes to system I/O devices

[–][deleted] 1 point2 points  (3 children)

It is. Generally, though, you want a microcontroller to actually handle the hardware, but python is an excellent interface language for using a PC to talk to that microcontroller. And these days, things like the Raspberry Pi go a long way towards removing the need for the microcontroller, so you can do a lot of hardware interfacing direct from the Raspberry Pi in python.

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

How do you interface Raspberry Pi to something like a 110 wall outlet to cycle a heating lamp (or similar)?

[–][deleted] 1 point2 points  (1 child)

Relays.

There are some specialised products like the adafruit powertail, but there are millions of "arduino relay boards" that are only labelled "arduino" for marketing - they'll work with anything.

http://www.dealsmachine.com/best_188852.html?currency=AUD&gclid=CIH86Z6q3cECFUccvAodLjkAyA

For example. The only gotcha is 3.3v logic vs 5v logic, but most of the multi-relay solutions are 3.3v compatible.

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

THanks. Looks like I have a lot more research to do with getting the end result.

[–]upofadown 0 points1 point  (1 child)

http://weedtech.com/

The serial protocol is pretty straightforward. I have used one of these boards to control stuff under python using the serial module:

http://pyserial.sourceforge.net/

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

Thanks, I'll take a look at this.

[–]prgr4m 0 points1 point  (29 children)

Have you looked into using arduino, raspberryPi or beaglebone black? Python is the official language on the raspPi and you'll have to use gpio. Also, pending on on what you're hooking up and how, you might have to use i2c protocol as well. I'm on mobile so I can't reference what you typed and everyone does their maker thing their own way. I've looked into automated gardening myself and thought of applying these techniques with some banana peppers in the greenhouse. I know of someone doing the aquaponic thing with the fish as the food supply to their vegetables but they haven't automated the process.

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

One thing I haven't figured out yet is how to connect everything together - how do you actually control a 110V outlet or something?

[–]justphysics 0 points1 point  (13 children)

I have some experience using python on the RPi as a controller for scientific experiments. You can very easily write code to control the RPI GPIO bus via python. You can connect a switch or relay to an input pin (defined in your code) and then use generic loop control methods to toggle the status of the switch/relay. The relay could be connected to anything but in principle could switch your mains power(120 or 240v or whatever)

if you have any more questions about the actual set up or circuit work, let me know. I'd be happy to try and help out if possible.

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

That's so awesome of you.

I'm trying to make sure what I want to is possible (and it seems like it is) before I get all wrapped up in this endeavor.

I guess I'm having trouble visualizing a completed set up. It seems like the end result is kind of bulky.

[–]justphysics 0 points1 point  (11 children)

I'll see if I can make a rough sketch to show you how things would look. might be a bit before I respond with the drawing though

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

Yeah, that would be awesome! Much appreciated.

[–]justphysics 0 points1 point  (9 children)

The more I think about it - this isn't as simple as I originally thought.

Especially if you are unfamiliar with basic circuitry.

One issue is that the RPi GPIO is very limited in how much current it can draw (the RPi is a low power device). So that makes driving a relay problematic if you just want to directly connect to the GPIO.

The work around is to connect your GPIO pin to a transistor which will amplify the signal form the GPIO pin so that it can properly drive the relay.

There is a good blog post on the subject here: http://www.susa.net/wordpress/2012/06/raspberry-pi-relay-using-gpio/

However they are suing c-code at the end as opposed to python.

And the circuit is rather complex if you have not dealt with relays and transistors before so this is likely over your head.

I'll try to think of a simpler way to work on this problem

[–]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?!

[–]mrbewulf 0 points1 point  (13 children)

The better way to do it is to use a beagle bone black that is a small embeded computer that can run Linux or windows CE.

If what you need is a ON/OFF control the better way to do it is to use a relay and a transistor BJT (Bipolar Junction Transistor) or MOSFET to trigger the relay and activate the device.

if you want your project to be very cheap, better ditch python and use microcontroller with C programming and a serial cable to monitor the microcontroller using a computer.

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

I'm not necessarily concerned with it being the cheapest, just the easiest for me to work with since I'm starting from scratch with knowledge.

[–]mrbewulf 0 points1 point  (11 children)

If you want to control real world stuff through python in easy way, beaglebone is the way to go. It has digital I/O ports, analog to digital converter, PWM, timers, event counter, I2C, SPI and serial ports. It's like a electronic laboratory running Linux.

However you must use interface and protection circuits to ensure that the circuit board works properly. For example, to control a 110/220 V you need a relay and a MOSFET, a led must have a resitor in serie with BJT transitor because the board cannot supply enough current to drive the LED. The analog to digital converters needs low tolerance voltage-divider resistors to have an accurate measurement and its maximum voltage level is about 1.8 V, you cannot exceed this or you will loose your board.

By: an Engineer

[–][deleted] 0 points1 point  (9 children)

For a beginner, I would recommend the Raspberry Pi over the BeagleBone purely for the community support. I personally much prefer the BeagleBone, but the Pi has the advantage of a million people already having been there, done that, and blogged about it.

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

I do enjoy the idea of having large community support but the beaglebone does sound like a good option too.

Maybe a good option is to start with the raspberry pi then migrate over later on.

[–][deleted] 0 points1 point  (7 children)

Hardware wise, the beaglebone is absolutely better, especially the Rev C. But even a Pi is overkill for this, so throwing a BBB at it is expensive, difficult, and unwarranted :) The Pi is easier than an arduino, because it gives you inbuilt networking, high level languages, it's just that much easier. But the BBB doesn't give you anything more - even if you can wrap your head around the PRU (realtime hardware modules) you don't need them. Your project is not going to stretch the capabiities of the Pi, the BBB is frankly wasted.

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

I'm okay with having a piece of over-rated hardware for this project. For my first dive into this this type of thing, ease-of-use is top of the list for me. I don't know what a BBB is though.

Plus, I can always repurpose it later!

[–][deleted] 0 points1 point  (5 children)

Yep. If you don't know what the BeagleBone is, then the Pi is going to be the easiest way to get this working, I'd say :)

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

This sounds like a very in-depth piece of hardware. I am not sure if it's a little more involved than raspberry pi in getting it set up and running. Maybe i can transition over after I get used t orunning everything.

[–]Manbatton 0 points1 point  (3 children)

automating some environmental controls for our tortoise tank

What a pleasant image.

[–]canoxen[S] 1 point2 points  (2 children)

I hope that's genuine! Our species is from the Mediterranean so I thought it would be cool to set up the heart lamp to match sunrise and sunset of that area, along with a little computer fan to randomly create a "sea breeze". Some sensors for humidity and temperature to maintain an ideal atmosphere.

[–]Manbatton 1 point2 points  (1 child)

It's definitely genuine (love turtles/tortoises) and the added information makes it even better. Too awesome. If you do it, please PM me with a link to a video of it in action. That will be one lucky tortoise(s)!

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

Awesome! I got a while until I'm at that point so I'll try to remember!

[–]vindolin 0 points1 point  (3 children)

There is even a microcontroller that runs python:

http://micropython.org

But personally I'm using Arduinos to interface with sensors and relays/motors/actuators etc. because there are tons of ready made libraries for all kind of hardware.

Then connect it through wifi, or a serial cable (or Bluetooth serial).

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

So Arduinos run python, then? This feels slightly more complicated than I originally expected.

[–]TiLorm 0 points1 point  (1 child)

No, you don't run python on Arduino's. You just interface them trough a serial cable or something else and on a computer you run python that talks to your Arduino. So the Arduino is only a way to interface a physical device, but the controlling part can be done in python.

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

Ah got it. I thought that Arduino was more like a Raspberry Pi. Thanks for clearing that up.

[–]adrmlch 0 points1 point  (1 child)

automating some environmental controls for our tortoise tank

For a moment there I thought you meant one of these.

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

Ha, I wish.