Nickodemous
Posts: 3
Joined: Wed Nov 15, 2017 6:55 pm

Using 16 Channel Servo driver with Pi3 but not finding Servos

Wed Nov 15, 2017 7:33 pm

I'm using this 12 bit 16 channel pwn driver: http://wiki.sunfounder.cc/index.php?tit ... rvo_Driver
which a connected to a variant of the T cobbler to my Raspberry Pi 3. Testing using two FS5103R servos which work properly when hooked to my Arduino.

I followed some steps I found on line to make sure ic2 pre-reqs are installed and enabled. It seems this would validate everything running correctly:

Code: Select all

pi@raspberrypi:~ $ lsmod | grep i2c
i2c_bcm2835             7167  0
i2c_dev                 6913  0
pi@raspberrypi:~ $ sudo i2cdetect -l
i2c-1	i2c       	bcm2835 I2C adapter             	I2C adapter
Problem is when I try to find the address of whatever servos I have attached, I'm not seeing anything (have actually tried all 10 servos I have laying around)

Code: Select all

pi@raspberrypi:~ $ sudo i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --  
I'm using 3.3 from the cobbler for the vcc and powering the servos using an independent power supply connected to the screw terminals on the driver board.

Really appreciate any help here, building a robot with my girls and have out grown the adruino in the first prototypes.

beta-tester
Posts: 1152
Joined: Fri Jan 04, 2013 1:57 pm
Location: de_DE

Re: Using 16 Channel Servo driver with Pi3 but not finding Servos

Fri Nov 17, 2017 8:46 pm

Nickodemous wrote:
Wed Nov 15, 2017 7:33 pm
I followed some steps I found on line to make sure ic2 pre-reqs are installed and enabled.
what steps you exactly followed to enable i²c?
as far as i know there are settings in raspi-config available that should do it for you, if you are using the most recent version of raspbian and raspi-config.
{ I only give negative feedback }
RPi Model B (rev1, 256MB) & B (rev2, 512MB) & B+, RPi2B (1GB), 64GB microSDXC1 class 10, HDMI 1920x1080, keyboard-mouse-combo (wireless), PiCamera, ethernet-cable, 5V/1.2A power supply, Wifi dongle (rt5370)

User avatar
joan
Posts: 12816
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Using 16 Channel Servo driver with Pi3 but not finding Servos

Fri Nov 17, 2017 10:52 pm

You haven't connected the servo driver board to the I2C bus. Double check the connections. The board has an I2C address, servos connected via the board do not have their own I2C address.

User avatar
OutoftheBOTS
Posts: 438
Joined: Tue Aug 01, 2017 10:06 am

Re: Using 16 Channel Servo driver with Pi3 but not finding Servos

Mon Nov 20, 2017 1:57 am

This is a very standard board design for driving servos. I use several version of it on a number of my robots.

I just connect it with jumper wires. Connect from Raspberry pi 3.3v to VCC (you won't need to connect anything to V+ as it is used for a level shifter when using a 5v MCU) connect GND to ground then of course SDA to SDA and SCL to SCL.

You won't need any power to the servo terminal or any servos attached to talk to the PCA9685 chip. When you attach the 3.3v to VCC and GND the red power light should come on to show you the chip has powered up. After the SDA and SCL wires r connected you should be able to detect the board with i2cdetect -y 1

I wrote a my own very basic driver for this board.

Code: Select all

# Copyright (c) 2017 Out of the BOTS
# http://outofthebots.com.au/
# Author: Shane Gingell
#
# Redistribution and use in source and binary forms, with or without 
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, 
#    this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, 
#    this list of conditions and the following disclaimer in the documentation 
#    and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 
# OR TORT INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.



# Servo class provides very basic functionality for controlling 
# sevoing using the PCA9685 chipset with a RPi. 


import smbus #import the System Mangement package for I2C coms
import time

class Servo :

  global bus
  global address
  bus = smbus.SMBus(1) #RPi3 uses bus 1 but if using bus 0 then change here
  address = 0x40 #factory standard I2C slave address change if needed
  
  @classmethod
  def __init__(self): #initizing will turn on all servos and set to poiition 0
    bus.write_byte_data(address, 0x01, 0x04)
    bus.write_byte_data(address, 0x00, 0x01)
    time.sleep(0.005)

    oldreg0 = bus.read_byte_data(address, 0x00)
    newreg0 = (oldreg0 & 0x7F) | 0x10
    bus.write_byte_data(address, 0, newreg0)

    prescale = int((25000000/(4096*50))-1)
    bus.write_byte_data(address, 0xFE, prescale)

    bus.write_byte_data(address, 0, oldreg0)
    time.sleep(0.005)
    bus.write_byte_data(address, 0, oldreg0 | 0x80)

    bus.write_byte_data(address, 0xFA, 0)
    bus.write_byte_data(address, 0xFB, 0)
    bus.write_byte_data(address, 0xFC, 0x33)
    bus.write_byte_data(address, 0xFD, 0x01)  
  
  def set_servo (self,servo_number, position): #routine for setting servo positions. no error checking
	attemps = 5
	for trys in range (attemps):
	  try:
	    step = 202//90
	    if position < -90 : position = -90
	    if position > 90 : position = 90
	    if position == 0 : offtime = 307	
	    else  : offtime = 307 + (step * position)    
	    startreg = servo_number * 4 + 8    
	    bus.write_byte_data(address, startreg, offtime & 0xff)    
	    bus.write_byte_data(address, startreg+1, offtime >> 8)
	    return	
	  except:	  
	    print"try failed " + str(trys)
	print "reached max attemps exiting"

#still much funtionality missing especally a shutdown down function.
  




and here is a very simple example program to use it :)

Code: Select all

from Servo import Servo #import servo class

robot = Servo()  #create instance of Servo

#set first 8 servos to position 60 degree and set next 8 servos to -60 degrees
robot.set_servo (0, 60)
robot.set_servo (2, 60)
robot.set_servo (3, 60)
robot.set_servo (4, 60)
robot.set_servo (5, 60)
robot.set_servo (6, 60)
robot.set_servo (7, 60)
robot.set_servo (8, -60)
robot.set_servo (9, -60)
robot.set_servo (10, -60)
robot.set_servo (11, -60)
robot.set_servo (12, -60)
robot.set_servo (13, -60)
robot.set_servo (14, -60)
robot.set_servo (15, -60)


# do beaware I haven't created a shutdown toutine so even after the program termintes 
# the PCA9685 will continue to hold these positions until power down.

Nickodemous
Posts: 3
Joined: Wed Nov 15, 2017 6:55 pm

Re: Using 16 Channel Servo driver with Pi3 but not finding Servos

Mon Nov 20, 2017 3:33 pm

beta-tester wrote:
Fri Nov 17, 2017 8:46 pm
what steps you exactly followed to enable i²c?
as far as i know there are settings in raspi-config available that should do it for you, if you are using the most recent version of raspbian and raspi-config.
Used a few different sourced. First looked at this: http://radiostud.io/howto-i2c-communication-rpi/
which basically did the following:
* enabled I2C in raspi-config
* sudo apt-get install python-smbus python3-smbus python-dev python3-dev
* sudo apt-get install i2c-tools

Then used this guide for hooking up/testing controller: https://learn.adafruit.com/adafruit-16- ... pi-for-i2c

Nickodemous
Posts: 3
Joined: Wed Nov 15, 2017 6:55 pm

Re: Using 16 Channel Servo driver with Pi3 but not finding Servos

Mon Nov 20, 2017 4:03 pm

Issue solved. From what I described no one said "you're doing it wrong", but just reaffirmed the connections I thought I set up. So I jumpered directly to the board (skipped the cobbler) and it worked:

Code: Select all

sudo i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: 40 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: 70 -- -- -- -- -- -- --                   
Afterwards debugged the original setup and found my fricken bread board was missing a conductor in a line of holes - one of which I was using for the driver. Thanks for you're help guys, successfully driving 4 servos and ready to start building a robot!

Return to “Advanced users”

Who is online

Users browsing this forum: No registered users and 26 guests