User avatar
GerardWassink
Posts: 103
Joined: Sun Aug 02, 2015 5:57 pm
Location: Ulrum (Gr), Netherlands
Contact: Website

Wrestling with my Raspberry Pi servo HAT

Wed Sep 09, 2015 1:23 pm

Hi guys,

I installed a Servo HAT for my RPi today. Now I'm wrestling to get it to drive a servo. I followed the instructions to enable i2s and smbus etc.

Hence the output of i2cdetect is okay, afaict:

Code: Select all

pi@raspberrypi ~ $ 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 -- -- -- -- -- -- --                         
pi@raspberrypi ~ $ 
So now we have communications with the module, I guess...

I hooked up a servo to channel zero of the HAT (black wire near edge of board) and tried the example program, Servo_Example.py, but to no avail. Nothing happened.

Now I'm looking how I can get it to work with this simplified code:

Code: Select all

#!/usr/bin/python

from Adafruit_PWM_Servo_Driver import PWM
import time

# ===========================================================================
# Example Code
# ===========================================================================

# Initialise the PWM device using the default address
#pwm = PWM(0x40)

# I Want debug output
pwm = PWM(0x40, debug=True)

servoMin = 110  # Min pulse length out of 4096
servoMax = 510  # Max pulse length out of 4096

pwm.setPWMFreq(50)                      # Set frequency to 50 Hz

while (True):
  # Change speed of continuous servo on channel O
  pwm.setPWM(0, 0, servoMin)
  time.sleep(1)
  pwm.setPWM(0, 0, servoMax)
  time.sleep(1)
Still nothing...

What am I missing in the code? As far as I an tell I'm specifying all things that are needed.

If that's the fact, how can I check what else is wrong (perhaps hardware-wise?

Gerard
---------ooooO----- \\\\\|/// -----Oooo--------
Hacker on ELF-II, ZX80/1, Commodore 64, 8080, x86,
IBM 370 family mainframes
Machine code! Assembly! C good second.
Running Pi's with Hercules and S/370 OS's

-------------oooO-----------Oooo-------------

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

Re: Wrestling with my Raspberry Pi servo HAT

Wed Sep 09, 2015 1:28 pm

There isn't much to go wrong with a servo. Are they receiving power? Presumably you are using an external power supply. Do they work when driven directly from the Pi?

User avatar
GerardWassink
Posts: 103
Joined: Sun Aug 02, 2015 5:57 pm
Location: Ulrum (Gr), Netherlands
Contact: Website

Re: Wrestling with my Raspberry Pi servo HAT

Wed Sep 09, 2015 1:52 pm

I am measuring with a Fluke 73 multimeter on AC (V~) over the outer (black) pin and the inner (white) pin of the servo. It reads .791 Volt when the program is not running. When the program is running, it varies from about .151 to .831 Volt.

The Servo HAT is being fed by an external power supply of 5V, 2A =. Or so I thought... Measuring the output of the PSU: nothing. Darn.

Will report back here.
---------ooooO----- \\\\\|/// -----Oooo--------
Hacker on ELF-II, ZX80/1, Commodore 64, 8080, x86,
IBM 370 family mainframes
Machine code! Assembly! C good second.
Running Pi's with Hercules and S/370 OS's

-------------oooO-----------Oooo-------------

User avatar
mikronauts
Posts: 2822
Joined: Sat Jan 05, 2013 7:28 pm
Contact: Website

Re: Wrestling with my Raspberry Pi servo HAT

Wed Sep 09, 2015 1:56 pm

1) you have to measure DC

2) you should read 5V between the red and black wires

3) the signal pin will have a servo pulsoe on it (high for 500us - 2500us in a 20ms window) when working
GerardWassink wrote:I am measuring with a Fluke 73 multimeter on AC (V~) over the outer (black) pin and the inner (white) pin of the servo. It reads .791 Volt when the program is not running. When the program is running, it varies from about .151 to .831 Volt.

The Servo HAT is being fed by an external power supply of 5V, 2A =. Or so I thought... Measuring the output of the PSU: nothing. Darn.

Will report back here.
http://Mikronauts.com - home of EZasPi, RoboPi, Pi Rtc Dio and Pi Jumper @Mikronauts on Twitter
Advanced Robotics, I/O expansion and prototyping boards for the Raspberry Pi

User avatar
GerardWassink
Posts: 103
Joined: Sun Aug 02, 2015 5:57 pm
Location: Ulrum (Gr), Netherlands
Contact: Website

Re: Wrestling with my Raspberry Pi servo HAT

Wed Sep 09, 2015 1:59 pm

[blushing]
Measuring DC with a meter on AC does NOT work... 5.17 Volts reaching the Servo HAT properly.
[/blushing]

Values while running are the same as in my previous post.
---------ooooO----- \\\\\|/// -----Oooo--------
Hacker on ELF-II, ZX80/1, Commodore 64, 8080, x86,
IBM 370 family mainframes
Machine code! Assembly! C good second.
Running Pi's with Hercules and S/370 OS's

-------------oooO-----------Oooo-------------

User avatar
GerardWassink
Posts: 103
Joined: Sun Aug 02, 2015 5:57 pm
Location: Ulrum (Gr), Netherlands
Contact: Website

Re: Wrestling with my Raspberry Pi servo HAT

Wed Sep 09, 2015 2:02 pm

mikronauts wrote:1) you have to measure DC

2) you should read 5V between the red and black wires

3) the signal pin will have a servo pulsoe on it (high for 500us - 2500us in a 20ms window) when working
Measured AC on the black and white pin, that's where the values are based on.

Measuring DC on black and red pins yield 5.17 Volts.

Still no joy on the servo, what else can I check?


Gerard
---------ooooO----- \\\\\|/// -----Oooo--------
Hacker on ELF-II, ZX80/1, Commodore 64, 8080, x86,
IBM 370 family mainframes
Machine code! Assembly! C good second.
Running Pi's with Hercules and S/370 OS's

-------------oooO-----------Oooo-------------

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

Re: Wrestling with my Raspberry Pi servo HAT

Wed Sep 09, 2015 2:29 pm

You may be driving the servo beyond its end stops.

servoMin = 110 # Min pulse length out of 4096

That is 110/4096*20000 (50 Hz) so 537 µs.

servoMax = 510 # Max pulse length out of 4096

That is 510/4096*20000 (50 Hz) so 2490 µs.

A lot of servos only respond between 1000 - 2000 µs.

Try 204 (1000 µs), 307 (1500 µs) and 408 (2000 µs).

User avatar
GerardWassink
Posts: 103
Joined: Sun Aug 02, 2015 5:57 pm
Location: Ulrum (Gr), Netherlands
Contact: Website

Re: Wrestling with my Raspberry Pi servo HAT

Wed Sep 09, 2015 2:52 pm

Will try those values.

Do we "blow up" a servo when driven outside these boundaries? I did not hear anything at any moment (also not the first time).
---------ooooO----- \\\\\|/// -----Oooo--------
Hacker on ELF-II, ZX80/1, Commodore 64, 8080, x86,
IBM 370 family mainframes
Machine code! Assembly! C good second.
Running Pi's with Hercules and S/370 OS's

-------------oooO-----------Oooo-------------

User avatar
GerardWassink
Posts: 103
Joined: Sun Aug 02, 2015 5:57 pm
Location: Ulrum (Gr), Netherlands
Contact: Website

Re: Wrestling with my Raspberry Pi servo HAT

Wed Sep 09, 2015 2:55 pm

GerardWassink wrote:Will try those values.
Nope, nothing, using these values now:

Code: Select all

servoMin = 204  # Min pulse length out of 4096
servoMax = 307  # Max pulse length out of 4096

pwm.setPWMFreq(50)                      # Set frequency to 50 Hz
---------ooooO----- \\\\\|/// -----Oooo--------
Hacker on ELF-II, ZX80/1, Commodore 64, 8080, x86,
IBM 370 family mainframes
Machine code! Assembly! C good second.
Running Pi's with Hercules and S/370 OS's

-------------oooO-----------Oooo-------------

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

Re: Wrestling with my Raspberry Pi servo HAT

Wed Sep 09, 2015 2:58 pm

You can strip the gears off the sort of servos I buy (plastic gears). But they make quite a bit of noise while doing so.

I guess you have not connected your servo to position 0.

User avatar
GerardWassink
Posts: 103
Joined: Sun Aug 02, 2015 5:57 pm
Location: Ulrum (Gr), Netherlands
Contact: Website

Re: Wrestling with my Raspberry Pi servo HAT

Wed Sep 09, 2015 3:02 pm

I have the servo connected to position zero. (tried position 1 and 15 as well, modifying the code accordingly).
---------ooooO----- \\\\\|/// -----Oooo--------
Hacker on ELF-II, ZX80/1, Commodore 64, 8080, x86,
IBM 370 family mainframes
Machine code! Assembly! C good second.
Running Pi's with Hercules and S/370 OS's

-------------oooO-----------Oooo-------------

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

Re: Wrestling with my Raspberry Pi servo HAT

Wed Sep 09, 2015 3:10 pm

GerardWassink wrote:I have the servo connected to position zero. (tried position 1 and 15 as well, modifying the code accordingly).
If you haven't tested the servos now may be the time to do so.

My pigpio will let you do so from the command line.

Connect power to the servo. Connect a ground between the Pi and the servo power supply. Connect a jumper wire between a GPIO and the servo control pin.

sudo pigpiod # start daemon

pigs s 4 1000 # 1000 µs pulses to GPIO 4 (change for your GPIO)
pigs s 4 1500
pigs s 4 2000

User avatar
GerardWassink
Posts: 103
Joined: Sun Aug 02, 2015 5:57 pm
Location: Ulrum (Gr), Netherlands
Contact: Website

Re: Wrestling with my Raspberry Pi servo HAT

Wed Sep 09, 2015 3:18 pm

Hi Joan,

This sounds good. Which module should I download? Should it be the deamon, or can we do with a module? If yes, which one?

Gerard
---------ooooO----- \\\\\|/// -----Oooo--------
Hacker on ELF-II, ZX80/1, Commodore 64, 8080, x86,
IBM 370 family mainframes
Machine code! Assembly! C good second.
Running Pi's with Hercules and S/370 OS's

-------------oooO-----------Oooo-------------

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

Re: Wrestling with my Raspberry Pi servo HAT

Wed Sep 09, 2015 3:20 pm

GerardWassink wrote:Hi Joan,

This sounds good. Which module should I download? Should it be the deamon, or can we do with a module? If yes, which one?

Gerard
It is one install so it doesn't make any difference from that point of view. For testing purpose using pigs via the daemon is quicker. You could use the Python module but that also uses the daemon.

User avatar
GerardWassink
Posts: 103
Joined: Sun Aug 02, 2015 5:57 pm
Location: Ulrum (Gr), Netherlands
Contact: Website

Re: Wrestling with my Raspberry Pi servo HAT

Wed Sep 09, 2015 3:36 pm

Never mind, found the github entry at the bottom, now running

Code: Select all

sudo ./x_pigpio    # All passed
sudo pigpiod       # check
./x_pigpiod_if      #  All passed
./x_pigpio.py       # All Passed
sudo pigs s 21 1000
sudo pigs s 21 1500
sudo pigs s 21 2000

All work! So the servo is good...
---------ooooO----- \\\\\|/// -----Oooo--------
Hacker on ELF-II, ZX80/1, Commodore 64, 8080, x86,
IBM 370 family mainframes
Machine code! Assembly! C good second.
Running Pi's with Hercules and S/370 OS's

-------------oooO-----------Oooo-------------

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

Re: Wrestling with my Raspberry Pi servo HAT

Wed Sep 09, 2015 3:42 pm

Just a question of finding out what's wrong with the HAT. Does it have any jumpers? Perhaps one needs to be set.

By the way you only need sudo to start the pigpio daemon (and run C programs linked with the library). pigs and the Python module do not need sudo.

User avatar
GerardWassink
Posts: 103
Joined: Sun Aug 02, 2015 5:57 pm
Location: Ulrum (Gr), Netherlands
Contact: Website

Re: Wrestling with my Raspberry Pi servo HAT

Wed Sep 09, 2015 4:25 pm

joan wrote:Just a question of finding out what's wrong with the HAT. Does it have any jumpers? Perhaps one needs to be set.
It's this Servo HAT by Adafruit. In the documentation there is no mention of jumpers whatsoever, so I wouldn't know...
---------ooooO----- \\\\\|/// -----Oooo--------
Hacker on ELF-II, ZX80/1, Commodore 64, 8080, x86,
IBM 370 family mainframes
Machine code! Assembly! C good second.
Running Pi's with Hercules and S/370 OS's

-------------oooO-----------Oooo-------------

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

Re: Wrestling with my Raspberry Pi servo HAT

Wed Sep 09, 2015 4:35 pm

It's a bit hard to see what could be wrong. Do you expect the I2C device at 0x70 as well as at 0x40?

User avatar
GerardWassink
Posts: 103
Joined: Sun Aug 02, 2015 5:57 pm
Location: Ulrum (Gr), Netherlands
Contact: Website

Re: Wrestling with my Raspberry Pi servo HAT

Wed Sep 09, 2015 4:38 pm

I did expect the x70 to pop up, because it is also mentioned at this instruction page (bottom picture).

Thanks for your time so far!

I guess I'm gonna dump it in the Adafruit forum now...
---------ooooO----- \\\\\|/// -----Oooo--------
Hacker on ELF-II, ZX80/1, Commodore 64, 8080, x86,
IBM 370 family mainframes
Machine code! Assembly! C good second.
Running Pi's with Hercules and S/370 OS's

-------------oooO-----------Oooo-------------

User avatar
GerardWassink
Posts: 103
Joined: Sun Aug 02, 2015 5:57 pm
Location: Ulrum (Gr), Netherlands
Contact: Website

Re: Wrestling with my Raspberry Pi servo HAT

Fri Sep 11, 2015 11:59 am

Please see for follow-up and good end-result this Adafruit topic.

Again: thanks for the help!

Gerard
---------ooooO----- \\\\\|/// -----Oooo--------
Hacker on ELF-II, ZX80/1, Commodore 64, 8080, x86,
IBM 370 family mainframes
Machine code! Assembly! C good second.
Running Pi's with Hercules and S/370 OS's

-------------oooO-----------Oooo-------------

BMS Doug
Posts: 4422
Joined: Thu Mar 27, 2014 2:42 pm
Location: London, UK

Re: Wrestling with my Raspberry Pi servo HAT

Fri Sep 11, 2015 12:11 pm

GerardWassink wrote:Please see for follow-up and good end-result this Adafruit topic.

Again: thanks for the help!

Gerard
Guys!

I'm joyed as well as flabbergasted... The servo HAT all of a sudden decided to kick in. I have NO idea what I did... Perhaps it got frightened by all you guys help. Anyway, the code below gave me a nice result now.
So it just started working with no clue as to why?
That's the worst kind of solution, just leaves you scratching your head and wondering what went wrong.
Doug.
Building Management Systems Engineer.

User avatar
DougieLawson
Posts: 41020
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Wrestling with my Raspberry Pi servo HAT

Sun Sep 13, 2015 8:14 am

BMS Doug wrote: That's the worst kind of solution, just leaves you scratching your head and wondering what went wrong.
In the thirty plus years I've done software support most of the problems like that have been a PEBKAC.
Any language using left-hand whitespace for syntax is ridiculous

Any DMs sent on Twitter will be answered next month.
Fake doctors - are all on my foes list.

Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

User avatar
GerardWassink
Posts: 103
Joined: Sun Aug 02, 2015 5:57 pm
Location: Ulrum (Gr), Netherlands
Contact: Website

Re: Wrestling with my Raspberry Pi servo HAT

Sun Sep 13, 2015 8:38 am

DougieLawson wrote: In the thirty plus years I've done software support most of the problems like that have been a PEBKAC.
In my thirty-five years of experience I have met a whole bunch of self proclaimed specialists who by the way really know what they're talking about, but more often then not wait until the last moment to weigh in and "enlighten" us with vile comments.

It is those comments that stem from PEBKAC!

Doug I dare you to point out what the problem is here, instead of arrogantly insulting my intelligence.
---------ooooO----- \\\\\|/// -----Oooo--------
Hacker on ELF-II, ZX80/1, Commodore 64, 8080, x86,
IBM 370 family mainframes
Machine code! Assembly! C good second.
Running Pi's with Hercules and S/370 OS's

-------------oooO-----------Oooo-------------

User avatar
DougieLawson
Posts: 41020
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Wrestling with my Raspberry Pi servo HAT

Sun Sep 13, 2015 7:55 pm

If we assume there isn't a hidden bug (and you've not given any evidence of that) then software things don't just break (unless it's a hardware failure), software things don't just start working without something being changed.

The most likely reason for "it just working" is that some part of the config has changed and that's always going to be something that is done by you editing something or by you running some one-shot program that changes something.
Any language using left-hand whitespace for syntax is ridiculous

Any DMs sent on Twitter will be answered next month.
Fake doctors - are all on my foes list.

Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

mkphillips
Posts: 1
Joined: Mon Feb 01, 2016 6:17 pm

Re: Wrestling with my Raspberry Pi servo HAT

Mon Feb 01, 2016 6:27 pm

I would guess that a that a very small piece of solder or something that was conductive was laying around on the board, and fell off when the board was moved. Even too much flux buildup can cause problems.

Return to “Interfacing (DSI, CSI, I2C, etc.)”