Here is a quick update to the previous blog post in which we setup EnOcean Transervir module and tested PushButton switch(PTM210) ,Magnet Contact Transmitter(STM329) and the Temperature sensor(STM332) with FHEM home automation server(Pi Control Hub:Spoke 2:Blinds Automation-- Setting up EnOcean Sensor and Blinking LEDs ). As part of this post we will drive a gear motor when the PushButton switch is pressed as shown in the video below.Basically the gear motor will help us open and close the blinds.
Also as part of the video, the gear motor turns clockwise when the Magnet Contact Transmitter switch is closed.
In addition to the Raspberry Pi B+ we will also need a motor driver to connect the gear motor the GPIO pins,here I am using SparkFun Motor Driver - Dual TB6612FNG and we will also need a power source , for this I am temporarily using a 4 AA battery pack..
Once you have setup FHEM installed,as detailed in the previous blog post , here are the additional steps that you will have to follow
#1 Solder a wire to 5V pin on the Raspberry Pi's back
#2 Build the circuit
Once you have connected the EnOcean transceiver module to the Pi , add the motor driver to the bread board and make the following connections
- PWMA on motor driver to GPIO 21 on the Pi
- AIN2 to GPIO 6
- AIN1 to GPIO 12
- STBY to GPIO 5
- VCC to 5V GPIO pin
- GND to one of the GND pins on the Pi
- Also connect the GND from the battery source to the GND
- Vm connect the battery pack +ve
- A01 connect one end of the motor
- A02 to the other end of the motor
#3 Run the program to test the gear motor as shown in the video above
Copy paste the code below to you Pi using nano
sudo nano ControlMotorEnoceanPi.py
run the python program using
sudo python ControlMotorEnoceanPi.py
import telnetlib import RPi.GPIO as GPIO import time #Connection details to the fhem server installed on the same Pi #For the telnet details check out URL - http://IpAddressOfPi:8083/fhem?detail=telnetPort HOST = "127.0.0.1" PORT = 7072 tell = telnetlib.Telnet() #Connecting to the fhem server tell.open(HOST,PORT) #Send command to intiantiate fhem server to get the data tell.write("inform on\n") def string_after(s, delim): return s.partition(delim)[2] #Connection to the motor driver,using the SparkFun Motor Driver - Dual TB6612FNG PWMA = 21 AIN2 = 6 AIN1 = 12 STBY = 5 GPIO.setmode(GPIO.BCM) GPIO.setup(PWMA,GPIO.OUT) GPIO.setup(AIN2,GPIO.OUT) GPIO.setup(AIN1,GPIO.OUT) GPIO.setup(STBY,GPIO.OUT) def openBlinds(): GPIO.output(AIN1, GPIO.LOW) GPIO.output(AIN2, GPIO.HIGH) GPIO.output(STBY, GPIO.HIGH) GPIO.output(PWMA, GPIO.HIGH) def closeBlinds(): GPIO.output(AIN1, GPIO.HIGH) GPIO.output(AIN2, GPIO.LOW) GPIO.output(STBY, GPIO.HIGH) GPIO.output(PWMA, GPIO.HIGH) def stopBlinds(): GPIO.output(AIN1, GPIO.LOW) GPIO.output(AIN2, GPIO.LOW) GPIO.output(STBY, GPIO.HIGH) GPIO.output(PWMA, GPIO.HIGH) try: while True: #get the value after the carriage return output = tell.read_until("\n") #Check the value of the button press of the Pushbutton Transmitter switch module - blinds open close if "channel" in output: print output if "A0" in output: openBlinds() print "A0 Open blinds motor clockwise" if "AI" in output: closeBlinds() print "AI close blinds" if "B0" in output: stopBlinds() print "B0 stop the motor" if "BI" in output: print "Button BI is pressed" #Check the value of the Magnet Contact Transmitter module - Door open close if "contact" in output: print output if "closed" in output: openBlinds() print "Mangentic contact closed" else: stopBlinds() print "Magenetic contact open" #clean up GPIO when exiting out of the program using ctrl+C except KeyboardInterrupt: GPIO.cleanup()
Here is the output of the program
Here is equivalent output on FHEM's event monitor when the PushButton switch(PTM210) pressed,and the magnet is brought close to Magnet Contact Transmitter(STM329)
Top Comments