Baby Monitor Ferris Wheel

I was mentioning to friends about building a baby monitor with a lot of functionality and some mentioned a mobile (not a mobile phone) that the baby could look at. I couldnt think of an elegent way to do it but when looking on ebay for baby mobiles, I cam across knex ferris wheels. I was going to get one until I came across this monster

knexwheel

Yes people. its a giant 8500 piece 6ft high/wide motorised knex ferris wheel and for me it was love at first sight 🙂

So after a quick trip half way up the country and a huge concern that it it would not fit in my car (I had to break it down into quarters), I managed to reassemble it in my house and get it working.

Now the fun can begin – How could I control the motor from a a raspberry pi command line ?

(1) Hardware Setup

The first thing I did was by a simple motor controller for the raspberry pi

I had some specific requirements which were

(a) I didnt want to solder anything (because Im rubbish at it)

(b) I wanted it to be connected to the PI – not Ardunio

(c) I need the gpio pins exposed even with the motor controller attached (in case I wanted to do something else gpio related)

I came accross an article on a boy that had developed a motor for the raspberry pi and I figured what better way to encourage a young budding genius than to buy his product so I purchase this

https://ryanteck.uk/add-ons/6-ryanteck-rpi-motor-controller-board-0635648607160.html

Ths motor has an external power input (the pi does not supply the power to the motor) and 2 output channels. I thought I only needed one but I have used the 2nd channel for something else (more later).

 

ryanteck-rpi-motor-controller-board

I like to do as little wiring as possible and I dont like to adapt things in a way that they cant be used again, so did the following:

The knex ferris wheel came with a 12V 1A power supply with a 2.1mm connector on the end. It looked like this

21connector

So I went onto ebay and bought a 5m extension cable for this lead. This way I would only be cutting the extension lead rather than the original power supply lead.

21extenssion

 

Now for the clever bit. I cut the extension lead 1m from the female end. I now have 2 wires, one with a female end and one with a male end. I connected the wires from the female end into the power input on the motor controller marked VCC2. Make sure you get the positive and negative wires correct or you will damage the motor and/or raspberry pi.

I connected the wires from the male end into the output on the motor controller marked motor-1 (the wiring polarity does not matter on this one).

Finally, connect the original power supply of the knex ferris wheel into the female socket going into the VCC2 input of the motor controller and connect the male output from motor1 on the motor controller to the actual motor on the ferris wheel.

Now we have fully connected the power supply to the raspberry pi and onto the knex ferris wheel without damaging the knex power supply.

With the raspberry pi turned off, push the motor controller down over the gpio pins of the raspberry pi, then plug in the knex power supply and finally turn on the raspberry pi.

Conceptually, the motor is a simple relay between the power supply and the actual knex motor and we can turn the relay on or off by applying power to gpio pins (pins 17 and 18 in this case)

(2) Software Setup

I didnt know anything about python or motor control but there was an exellent tutorial from raspberrypiguy available at

 

So immediately, i was able to create the following pythion script called knexon.py in /var/www/html

The script takes a commandline parameter which is the number of seconds you want to turn the motor on for.

Example:

.python ./knexon.py 10

will turn the motor on for 10 seconds

./python ./knexon.py 0

will turn the motor off. Basically the script consists of 3 functions called InitialiseIO, MotorOn and MotorOff

#!/usr/bin/python
# A program to control the movement of a single motor using the RTK MCB!
# Composed by The Raspberry Pi Guy to accompany his tutorial! and modified
# by wherethingsareborn to take the parameter input

# Let's import the modules we will need!
import time
import sys
import RPi.GPIO as GPIO

ontime=0;

def MotorOn():
 print('Starting motor...')
 GPIO.output(17, True)
 GPIO.output(18, False)
 return

def InitialiseIO():
 GPIO.setmode(GPIO.BCM)
 GPIO.setwarnings(False)
 GPIO.setup(17,GPIO.OUT)
 GPIO.setup(18,GPIO.OUT)
 return

def MotorOff():
 print('Stopping motor...')
 GPIO.output(17, False)
 GPIO.output(18, False)
 return

# Script starts here

ontime=(float)(sys.argv[1]);

InitialiseIO();
if ontime > 0:
 MotorOn();
 time.sleep(ontime)
MotorOff();
quit()

Once you have saved this script, make sure you change the ownership to www-data as follows:

chown www-data:www-data knexon.py

Then run the command as follows:

python ./knexon.py 30

and if you have followed the info above, your ferris wheel should star turning.

Dont believe is that simple ? then take a look at this.

 

 

WhereThingsAreBorn 🙂

 

 

 

 

 

 

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s