Monday 29 October 2012

Installing mysql and phpmyadmin


Installing mysql and phpmyadmin


To install mysql run the command

sudo apt-get install mysql-server mysql-client php5-mysql

you will need to confirm the installation, and also set a root admin password for use by mysql

To install phpmyadmin:

1. Go to http://www.phpmyadmin.net
2. Download the zip file (I would suggest downloading to /home/pi

3. Extract the zip file and rename the directory to "phpmyadmin"
4. Copy the directory "phpmyadmin" to /var/www

You can now check to see that its working by going to http://raspberrypi/phpmyadmin/

In preparation for doing some stuff in python connected to mysql you will need to run the following commands

sudo apt-get install libmysqlclient18
and then
sudo apt-get install python-mysqldb



Installing and setting up Apache, PHP

This is what I've done to get Apache & php installed and set up on my RaspberryPi.

Background reading


Things you may want to do before you install

Set a static IP address and Host name

Getting started

First things first update and upgrade the image by running the commands

sudo apt-get update && sudo apt-get upgrade

depending on when you last did this and how old your image is this may take 30 minutes or more.

So now on to installing apache

sudo apt-get install apache2 php5 libapache2-mod-php5

You may have noticed a couple of errors when installing, to fix you need to run the following commands
sudo groupadd www-data, then sudo usermod -g www-data www-data.

Now restart the apache web server by running the command sudo service apache2 restart

To enable htaccess files you must modify the config files, like so:

Type sudo nano /etc/apache2/sites-enabled/000-default and hit Return / Enter.
You'll see a line like the following:

"AllowOverride None" - change this to "AllowOverride ALL".
(Note that "AllowOverride None" appears in a couple of places. You want to update the one under <Directory /var/www/>)

To save your changes hold the Ctrl button and press the "x" key, then press "y" when prompted and hit Return / Enter.
Now restart apache with sudo service apache2 restart.

And that should be it :-)

Check Apache

You can check that its all working by opening up a web browser and entering the url: http://raspberrypi/

Alternatively from the pi itself go to http://127.0.0.1 or http://localhost

Thursday 25 October 2012

Controlling BigTrack Motors with my Raspberry Pi



After lots and lots of reading forums, reading the MagPi Magazine items on the GPIO, reading yet more forums, searching Google and generally stumbling about I have finally after many many months got my Raspberry Pi to control 2 motors. I have been honestly surprised that there aren't more articles giving practical examples of how to get the Raspberry Pi to do stuff like controlling Motors.

I've put this article to hopefully help anyone else who has been similarly struggling. I can't say that this is the perfect solution, I'm sure that you could argue that the Raspberry Pi is not the best device in practice to use, a lot of people have told me to do it using an Arduino .... but I don't have one of those, what I do have is a Raspberry Pi and to be honest I don't think its too bad at doing it.

Background reading and other references

I've very shamelessly found and used an instructables article which shows how to use the Arduino. I would recommend you read it, most of the instructions can be followed exactly, the only differences come towards the end when it comes to connecting it up to the Raspberry Pi instead of the Arduino. So have a look and read this here : http://www.instructables.com/id/Using-the-Sparkfun-Motor-Driver-1A-Dual-TB6612FNG-/?ALLSTEPS

Also if this is your first ever thing using the GPIO's then I would recommend that you start with the articles in the MagPi Magazines first as they will do a lot better job at explaining what's going on. Have a look here : http://www.themagpi.com/

The idea of the using a Big Track as a platform wasn't mine either, there have been some good articles in the MagPi Magazine, and some activity on the Raspberry Pi forums (http://www.raspberrypi.org/phpBB3/viewtopic.php?f=37&t=20751&p=202666#p202666)

Things you will need



Soldering the header pins to the TB6612FNG

This should be pretty easy, and its the only soldering needed. Basically the board comes without any pins, I used some breakaway header pins like these


Cut of 2 strips of 8 pins, and solder to each side of the controller and you should have something that looks like this




 Adding the controller to the bread board and start wiring 

Read the the instructables article for a good diagram showing what you need to wire up and to where (http://www.instructables.com/id/Using-the-Sparkfun-Motor-Driver-1A-Dual-TB6612FNG-/?ALLSTEPS)

Add the controller to the board

Here I've added the external power source and connected the ground

And the other bottom conner of the breadboard I have attached the Raspberry Pi. Note I have connected the positive up to 5v (Pin 2)

Next start adding the diodes, again following the diagram on the instructables article

Add a few more diodes and wires (the two green wires go off to the big track motors) and the first motor is connected


Add the other 4 diodes and you should be almost done. Below is my breadboard with everything nearly connected - basically everything except the Raspberry Pi

 And from the top

Attached the Raspberry Pi

Attaching the Raspberry Pi is pretty simple, I attached it up using the following pin numbers.

PWMA = Pin 7 (GPIO #4)
AIN2 = Pin 11 (GPIO #17)
AIN1 = Pin 12 (GPIO #18)
STBY = Pin 13 (GPIO #21)
BIN1 = Pin 15 (GPIO #22)
BIN2 = Pin 16 (GPIO #23)
PWMB = Pin 18 (GPIO #24)

It should now look something like this


Motor Control Sanity Check

I wrote this programme in Python. To run it you will need to make a file called sanity_motor_control.py. This programme is pretty simple, it will drive the motors in one direction for 5 seconds, then drive the motors in the other direction for another 5 seconds before switching off.

Its a good place to start to make sure that everything is connected up and running correctly.

#!user/bin/python

import time
import RPi.GPIO as GPIO

#Declare the GPIO settings
#print "Set GPIO Board numbers"
# to use Raspberry pi board pin numbers
GPIO.setmode(GPIO.BOARD)

# set up GPIO pins
GPIO.setup(7, GPIO.OUT) #Connected to PWMA
GPIO.setup(11, GPIO.OUT) #Connected to AIN2
GPIO.setup(12, GPIO.OUT) #Connected to AIN1
GPIO.setup(13, GPIO.OUT) #Connected to STBY
GPIO.setup(15, GPIO.OUT) #Connected to BIN1
GPIO.setup(16, GPIO.OUT) #Connected to BIN2
GPIO.setup(18, GPIO.OUT) #Connected to PWMB

#Specify the direct to turn the motor
#Clockwise AIN1/BIN1 = HIGH and AIN2/BIN2 = LOW
#Counter-Clockwise: AIN1/BIN1 = LOW and AIN2/BIN2 = HIGH

#First we will drive everything clockwise
#Set the direction of Motor A
GPIO.output(12, GPIO.HIGH) #Set AIN1
GPIO.output(11, GPIO.LOW) #Set AIN2
#Set the Speed / PWM for A
GPIO.output(7, GPIO.HIGH) #Set PWMA

#Set the direction of Motor B
GPIO.output(15, GPIO.HIGH) #Set BIN1
GPIO.output(16, GPIO.LOW) #Set BIN2
#Set the Speed / PWM for B
GPIO.output(18, GPIO.HIGH) #Set PWMA

#Make sure STBY is disabled - Set it to HIGH
GPIO.output(13, GPIO.HIGH)

time.sleep(5)

#Now drive the motor in the other direction (Counter Clockwise)
#Set the direction of Motor A
GPIO.output(12, GPIO.LOW) #Set AIN1
GPIO.output(11, GPIO.HIGH) #Set AIN2
#Set the Speed / PWM for A
GPIO.output(7, GPIO.HIGH) #Set PWMA

#Set the direction of Motor B
GPIO.output(15, GPIO.LOW) #Set BIN1
GPIO.output(16, GPIO.HIGH) #Set BIN2
#Set the Speed / PWM for B
GPIO.output(18, GPIO.HIGH) #Set PWMA

#Make sure STBY is disabled - Set it to HIGH
GPIO.output(13, GPIO.HIGH)

time.sleep(5)

#Now set everything to low (Switch everything Off)
GPIO.output(12, GPIO.LOW) #Set AIN1
GPIO.output(11, GPIO.LOW) #Set AIN2
GPIO.output(7, GPIO.LOW) #Set PWMA
GPIO.output(15, GPIO.LOW) #Set BIN1
GPIO.output(16, GPIO.LOW) #Set BIN2
GPIO.output(18, GPIO.LOW) #Set PWMA
GPIO.output(13, GPIO.LOW) #Set STBY


To run the programme run the command sudo python sanity_motor_control.py

I'm going to leave it at that for now I think. I'm working on a more complex example code which using the pygame library will allow you to control and drive the motors using the keyboard cursor keys. I'll updated as soon as I've got it a bit more sorted out. 

Saturday 9 June 2012

Control an LED on the internet - LIVE VIDEO FEED INCULDED

Go here to view a live video feed of an LED being controlled by my Raspberry Pi, with the option of controlling the LED

(Update 16-16-2012 LED demo stopped worked as SD card wiped itself, I'm currently working on re installing and updating)

http://aforalex.no-ip.biz/led/led_control_external.php

It works by:

  1. Simple PHP page that creates or deletes a file
  2. Python script running continuously looking for this file
  3. When it finds the file it switches the LED on, and when it doesn't it switches it off
The Webcam is currently being driving by a windows PC close by and hosted through a service called ustream. Ultimately I would like to have the webcam feed going through the PI also and control something a little bit more interesting :-) But for now its a nice proof of concept.

References: 

My RPi on the internet

So this is my RPi as a webserver on the internet. Its all just proof of concept stuff at the moment so not a great deal to see: http://aforalex.no-ip.biz/ . If its not working then it probably means that my Pi is switched off

Friday 8 June 2012

Links to things that I have found useful

These are some websites that I have found to be very useful, in no particular order

Setup and general information:



Internet / Web / PHP etc


Playing with the GPIO:




Electronics: