tjsheffler
Posts: 8
Joined: Sun Aug 25, 2013 4:51 pm

rpi-pwm and camera together?

Fri Aug 30, 2013 11:15 pm

New to RPi here. I started with Wheezy (july 2013) dist and have a nicely working camera.

I wanted to try controlling a servo with the PWM and it looked like the easiest way was to start with the Adafruit Occidentalis v0.2 distribution. I installed it, but it seemed that I could not get the camera enabled in raspi-config.

So I did this:

sudo apt-get update
sudo apt-get upgrade (this took a long time)
sudo raspi-config

I could then enable the camera. But I don't see the "pwm" entry in /sys/class/rpi-pwm/...

I'm wondering if my "apt-get upgrade" overwrote the adafruit kernel with a new wheezy kernel. Any ideas? Maybe the adafruit dist doesn't support the camera.

Thx for ideas.
T

User avatar
Hove
Posts: 1205
Joined: Sun Oct 21, 2012 6:55 pm
Location: Cotswolds, UK
Contact: Website

Re: rpi-pwm and camera together?

Sat Aug 31, 2013 7:02 am

Don't know about Occidentals, but RPi has inbuilt PWM that can be used to control servos / motors etc.

I use the RPIO interface to do this, but I believe the GPIO interface also supports the same function.

Here's the links:

http://pythonhosted.org/RPIO/pwm_py.html
https://code.google.com/p/raspberry-gpi ... n/wiki/PWM

You should already have the GPIO code installed as part of having the latest release on Wheezy
www.pistuffing.co.uk - Raspberry Pi and other stuffing!

tjsheffler
Posts: 8
Joined: Sun Aug 25, 2013 4:51 pm

Re: rpi-pwm and camera together?

Sat Aug 31, 2013 3:03 pm

Thanks Hove. RPIO seems to be just what I was looking for. Installed easily.
-T

User avatar
Hove
Posts: 1205
Joined: Sun Oct 21, 2012 6:55 pm
Location: Cotswolds, UK
Contact: Website

Re: rpi-pwm and camera together?

Sat Aug 31, 2013 4:31 pm

You're welcome. I've dug up my test code I used to work out how this all stuck together. I have 4 LEDs on 4 GPIO pins, all driven by the same PWM channel, but each with different PWM signals - I wanted to check they could be overwritten (which they can, so a 2ms pulse can be overwritten by a 1ms pulse - it wasn't clear from the spec to me whether it would work because you can add many non-overlapping pulses to a single GPIO pin, but it wasn't clear what would happen if you overwrote a long pulse with a shorter one).

Note the pin numbers are not the GPIO connector pin numbers - they are the chip pin numbers - there's loads of info about mapping between the two - search the forum for GPIO.BOARD and GPIO.BCM. You don't need anything like the number of imports I've used, I just cut and pasted these from my main project code to save time.

Code: Select all

#!/usr/bin/env python
from __future__ import division
import signal
import socket
import time
import string
import sys
import RPIO.PWM as PWM
import time
import math
import threading
import logging
from array import *
import select
import os
import struct

PWM.setup(1)                           # setup up PWM with 1us granularity (the smallest)
PWM.init_channel(0, 3000)              # setup channel 0 (0-15 available) with a 3ms pulse repeat rate

PWM.add_channel_pulse(0, 18, 0, 1000)  # turn on GPIO BCM pin 18 at 0us into the 3ms cycle and off 1000us later
PWM.add_channel_pulse(0, 23, 0, 1250)  # turn on GPIO BCM pin 23 at 0us into the 3ms cycle and off 1250us later
PWM.add_channel_pulse(0, 24, 0, 1500)  # turn on GPIO BCM pin 24 at 0us into the 3ms cycle and off 1500us later
PWM.add_channel_pulse(0, 25, 0, 2000)  # turn on GPIO BCM pin 25 at 0us into the 3ms cycle and off 1000us later

time.sleep(10)

PWM.add_channel_pulse(0, 18, 0, 2000)  # turn on GPIO BCM pin 18 at 0us into the 3ms cycle and off at 2000us later
PWM.add_channel_pulse(0, 23, 0, 1500)  # turn on GPIO BCM pin 23 at 0us into the 3ms cycle and off at 1500us later
PWM.add_channel_pulse(0, 24, 0, 1250)  # turn on GPIO BCM pin 24 at 0us into the 3ms cycle and off at 1250us later
PWM.add_channel_pulse(0, 25, 0, 1000)  # turn on GPIO BCM pin 25 at 0us into the 3ms cycle and off at 1000us later

time.sleep(10)

PWM.clear_channel_gpio(0, 25)
time.sleep(1)

PWM.clear_channel_gpio(0, 24)
time.sleep(1)

PWM.clear_channel_gpio(0, 23)
time.sleep(1)

PWM.clear_channel_gpio(0, 18)
time.sleep(1)

PWM.clear_channel(0)
PWM.cleanup()
www.pistuffing.co.uk - Raspberry Pi and other stuffing!

tjsheffler
Posts: 8
Joined: Sun Aug 25, 2013 4:51 pm

Re: rpi-pwm and camera together?

Wed Sep 04, 2013 11:14 pm

This little example helped me too. Thanks.

Return to “Raspberry Pi OS”