Showing posts with label raspberry pi. Show all posts
Showing posts with label raspberry pi. Show all posts

Thursday, January 16, 2014

Raspberry Pi and a PIR Sensor

Today, I successfully used the Human Sensor PIR module with the RPi. I ordered this: http://www.amazon.com/gp/product/B007XQRKD4/

I followed this blog post. The only change was different GPIO port numbers:
http://www.millamilla.com/?p=18

When moving in front of the sensor, the LED turns on.

Worked great!

There are two manual adjustments on the module:
  • Sensitive Setting: turn to right, distance increases (about 7m); turn to left, distance reduces (about 3m)
  • Time Setting: turn to right, time increases (about 300 seconds); turn to left, time reduces (about 5 seconds).

Monday, January 13, 2014

Raspberry Pi and WiFi

I purchased a Edimax EW-7811Un wireless USB adapter (http://www.amazon.com/Edimax-EW-7811Un-Wireless-Adapter-Wizard/dp/B003MTTJOY) for my raspberry pi,

Setup:

With the ethernet still plugged in, I remoted in and used the WPA_GUI tool (shortcut already on the desktop). I was able to connect but when I tried it with the ethernet disconnected, it didn't work.

Long story short (after lots of troubleshooting), I needed to save the configuration in the WPA_GUI tool. It's been working since.

Another possible cause of the intermittent problem is with the usb hub (d-link dub-h7). When plugged into the pi, the pi would not start and when restarting right away without the usb hub, the wifi adapter (usb) wouldn't work. I suspect that power from the usb hub was causing the fuse to open for a short period of time, rendering the usb port inoperable until it closes again.

Wednesday, January 8, 2014

Raspberry Pi and Temperature Sensor

Today I successfully connected the DS18B20 temperature sensor to the RPi. I ordered the waterproof version that comes with ~ 2 ft leads.

I used the following Adafruit lesson to the letter and it worked great:
http://learn.adafruit.com/adafruits-raspberry-pi-lesson-11-ds18b20-temperature-sensing/overview

Monday, December 30, 2013

RPi - Controlling a Servo Motor

Today I set up the Raspberry Pi to control a servo motor.

For the hardware setup, I referred to chapter 10 from the Raspberry Pi Cookbook. Aside from the Pi, I only used the Pi Cobbler, a 1k resistor, and a 4AA battery pack. I didn't use any other special components. In the future, I'll consider getting a specialized breakout board for controlling servos.

For the software, I started with the code from this blog post:  http://www.doctormonk.com/2012/07/raspberry-pi-gpio-driving-servo.html
Note that in Simon Monk's post, he uses a transistor in his circuit that I didn't use based on the circuit in the book.

My first attempt didn't work well. The servo would turn very slowly, arriving at the 180 degree position, and stay there. I could feel the motor working but there was little to no movement.

After further research, I made some modifications to the starting code including changing the order of the True and False statements and playing with the timing. Things started to work. I was reading that servos needed between a .001 and .002 second pulse to move between 0 and 180 degrees respectively. I was finding those to be too long. For my servo, the range was between .00055 and .002. I don't know if that is a servo thing or if that helps to compensate for a delay from the RPi itself.

Finally, I added some code to accept an angle 0-180 as input and convert that angle into the appropriate timing of the pulses. I also had that input affect the number of loops because for shorter angle changes, a greater number of loop iterations would result in the motor jumping around slightly after reaching the desired angle. Now I can probably convert this to a function and use with other programs.

I had been reading about others experiencing a jittery movement when only using GPIO to control the servo but once I figured out the appropriate timing and loops, I found that it moved very smoothly. I don't know if there are other factors that I'm not experiencing that could affect the performance.

The Code:

import RPi.GPIO as GPIO
import time
import math

pin = 18
refresh_period = 0.02

prev_angle = 90           #initiate previous angle

GPIO.setmode(GPIO.BCM)

GPIO.setup(pin, GPIO.OUT)
GPIO.output(pin, False)

while True:
    angle = int(input('Angle: '))

    # convert degrees (0-180) to the servo pulse (.00055 to .002ms)
    pulse = (angle * .00000805555) + .00055

    # determine the number of loops based on degrees needed to travel, a shorter distance (degrees) to travel = fewer loops
    loops = math.ceil(math.fabs(prev_angle - angle) * .135) + 2
    prev_angle = angle

    # move the servo arm
    for i in range(1, loops):
        time.sleep(refresh_period)
        GPIO.output(pin, True)
        time.sleep(pulse)
        GPIO.output(pin, False)


The circuit:

The servo I used:

The servo specs:

Years ago, I created a very simple robotic arm that waves and was able to revive it once again with the RPi!





Saturday, December 28, 2013

RPi - Python and Blinking LED

I successfully created a python script to blink an LED attached to the RPi/Pi Cobbler.

The circuit attaches to the 3.3V output, routes through the LED, a 470R, and back to GPIO pin 18.

I wrote it using IDLE on the RPi GUI.

I used this blog post as my guide: http://www.thirdeyevis.com/pi-page-2.php
I also referred to this one and even started to set up the WebIDE: http://www.akeric.com/blog/?tag=pi-cobbler

The code:

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.OUT)

def Blink(numTimes,speed):
    for i in range(0,numTimes):
        print "Iteration " + str(i+1)
        GPIO.output(18,True)
        time.sleep(speed)
        GPIO.output(18,False)
        time.sleep(speed)
    print "Done"
    GPIO.cleanup()

iterations = raw_input("Enter total number of times to blink: ")
speed = raw_input("Enter length of each blink(seconds): ")

Blink(int(iterations),float(speed))


Tuesday, December 24, 2013

Simple LED Circuit

My Pi Cobbler arrived the other day and finally got around to playing. Created a simple LED circuit using the 3.3 V and ground pins on the cobbler. No Pi functionality was used other than as a source of power.

I used this blog post as a guide.
https://projects.drogon.net/raspberry-pi/gpio-examples/tux-crossing/gpio-examples-1-a-single-led/

Next, I'll control the LED via gpio on the pi.


Circuit:

Friday, November 29, 2013

AutoRemote and Linux

I successfully paired Raspberry Pi with two android devices via AutoRemote.

I used the instructions here http://joaoapps.com/autoremote/linux/ but was getting an invalid key error. This is because I was trying to use the personal url rather than the personal key. The difference is explained here: http://joaoapps.com/autoremote/personal/ .

I set these connections up using the internal IP but will try to add registrations using a public IP so I can control from anywhere. I'll need to set up port fowarding in my router. I'll also need to come up with the best way to always know my home public IP.

I also successfully sent commands from my phone to the RPi.
  • sudo halt
  • aplay [filepath]

Wednesday, November 27, 2013

Playing Audio on Rasperry Pi

I successfully played an audio file (.wav) out the headphone jack using the command:

aplay [name of file]

I also tried to adjust the volume using amixer but it didn't seem to make a difference. I'll need to play with that some more.

Transfer Files from Windows to Raspberry Pi

I wanted to transfer a .wav file from my windows machine to the raspberry pi.

I found this blog post and successfully used WinSCP.

http://www.neil-black.co.uk/transfer-files-across-your-network-from-windows-to-a-raspberry-pi#.Upaw-sTUBiI

Use the SCP protocol rather than FTP or SFTP.

Tuesday, November 26, 2013

Sunday, November 24, 2013

Eject USB Drive - Error and Fix

Earlier today, I successfully used a USB drive in my raspberry pi but when I went to eject the drive by right clicking on the drive in the file manager (via the desktop), I got an error message: "Error starting job: Failed to execute child process "eject". No such file."

Found this thread: http://www.raspberrypi.org/phpBB3/viewtopic.php?t=18364

Installed "eject" using the command line:

sudo apt-get install eject

Works now.

Rasp Pi: USB Thumbdrive

First time trying a USB thumb drive in the raspberry pi. After plugging it in, I remoted in (RDP) and it was already mounted as a drive in the file system. I didn't need to do anything.

I need to test whether it would have been mounted if I only remoted in via terminal (SSH). Was it the x interface that mounted it or the plugging in of the drive at the OS level that mounted it?



Resources:

Wednesday, November 20, 2013

Shutting Down the Raspberry Pi

Two options for shutting down the raspberry pi from the command line:

sudo shutdown -h now

or

sudo halt

Sunday, November 17, 2013

Connect Digital Camera to Raspberry Pi

I tried to connect an older digital camera, the Cannon Powershot Elph SD1000, to the raspberry pi and use it to take pictures remotely.

I installed gphoto2.

After a number of attempts, I saw that while accessing files on the SD1000 is possible, taking photos is not.

We have a couple of other old digital cameras around, I'll try those when I get the chance.

startx

From the command line, use 

startx 

to launch the desktop GUI.


(Raspian Wheezy OS)

Friday, November 15, 2013

New Raspberry Pi



I received my new raspberry pi as a birthday present.

I ordered the Raspberry Pi Model B Board with 8GB O/S Card from MCM Electronics for just under $40.

I already had a 1 amp, 5 volt micro USB charger from an old cell phone. While the minimum is 700 milliamps, everyone recommends at least 1 amp.

I connected it to our home network via ethernet. A wireless adapter is on the wishlist.

I didn't have an HDMI tv close to a network drop so I used the analog port to connect to an old tv. At first, no video appeared but then I needed to press 4 at startup so that the pi would output to analog NTSC.

I borrowed a USB mouse and keyboard from another computer in order to get things setup.

Everything working great so far.