Can't Get Rpi Motor Hat To Work

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
phaze3131
 
Posts: 15
Joined: Tue Jan 19, 2016 8:20 pm

Can't Get Rpi Motor Hat To Work

Post by phaze3131 »

Hey guys, first of all thank you a lot for the help, as you will tell shortly, I'm at the stage where if I keep learning and practice a lot.. I might be a newbie soon.

General first question. How can I test my motorhat to see if I did everything correctly and that my Rpi is recognizing it. I can't find what gpio pins are actually being used by the motor hat.

The hat powers on and the green light is lit.

I followed the guide and installed the Adafruit software here:
https://learn.adafruit.com/adafruit-dc- ... g-software

Then I followed the guide to create python code to control my motor here:
https://learn.adafruit.com/adafruit-dc- ... -dc-motors

I made this script here:

Code: Select all

#!/usr/bin/python
from Adafruit_MotorHAT import Adafruit_MotorHAT, Adafruit_DCMotor

import time
import atexit

# create a default object, no changes to I2C address or frequency
mh = Adafruit_MotorHAT(addr=0x60)

myMotor = mh.getMotor(1)


while (True):
        print "Forward! "
        myMotor.run(Adafruit_MotorHAT.FORWARD)

But I just get this as output and the motor does not turn.

Code: Select all

pi@raspberrypi ~/adafruit/Adafruit-Motor-HAT-Python-Library/examples $ sudo python mytest.py
Traceback (most recent call last):
  File "mytest.py", line 2, in <module>
    from Adafruit_MotorHAT import Adafruit_MotorHAT, Adafruit_DCMotor
  File "/usr/local/lib/python2.7/dist-packages/Adafruit_MotorHAT-1.3.0-py2.7.egg/Adafruit_MotorHAT/__init__.py", line 1, in <module>
    from .Adafruit_MotorHAT import Adafruit_StepperMotor, Adafruit_DCMotor, Adafruit_MotorHAT
  File "/usr/local/lib/python2.7/dist-packages/Adafruit_MotorHAT-1.3.0-py2.7.egg/Adafruit_MotorHAT/Adafruit_MotorHAT.py", line 3, in <module>
    from Adafruit_PWM_Servo_Driver import PWM
  File "/usr/local/lib/python2.7/dist-packages/Adafruit_MotorHAT-1.3.0-py2.7.egg/Adafruit_MotorHAT/Adafruit_PWM_Servo_Driver.py", line 11, in <module>
    class PWM :
  File "/usr/local/lib/python2.7/dist-packages/Adafruit_MotorHAT-1.3.0-py2.7.egg/Adafruit_MotorHAT/Adafruit_PWM_Servo_Driver.py", line 35, in PWM
    general_call_i2c = Adafruit_I2C(0x00)
  File "/usr/local/lib/python2.7/dist-packages/Adafruit_MotorHAT-1.3.0-py2.7.egg/Adafruit_MotorHAT/Adafruit_I2C.py", line 43, in __init__
    self.bus = smbus.SMBus(busnum if busnum >= 0 else Adafruit_I2C.getPiI2CBusNumber())
IOError: [Errno 2] No such file or directory

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Can't Get Rpi Motor Hat To Work

Post by adafruit_support_rick »


phaze3131
 
Posts: 15
Joined: Tue Jan 19, 2016 8:20 pm

Re: Can't Get Rpi Motor Hat To Work

Post by phaze3131 »

Yea I did those steps, these are the outputs from doing them again:

Code: Select all

pi@raspberrypi ~ $ sudo apt-get install python-smbus
Reading package lists... Done
Building dependency tree
Reading state information... Done
python-smbus is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.

Code: Select all

pi@raspberrypi ~ $ sudo apt-get install i2c-tools
Reading package lists... Done
Building dependency tree
Reading state information... Done
i2c-tools is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.
I also went into raspiconfig again to check to make sure i2c was enabled but I couldn't find a way to check, so I did those steps again to enable it.

Installing software again.

Code: Select all

pi@raspberrypi ~ $ git clone https://github.com/adafruit/Adafruit-Motor-HAT-Python-Library.git
Cloning into 'Adafruit-Motor-HAT-Python-Library'...
remote: Counting objects: 50, done.
remote: Total 50 (delta 0), reused 0 (delta 0), pack-reused 50
Unpacking objects: 100% (50/50), done.

Code: Select all

pi@raspberrypi ~/Adafruit-Motor-HAT-Python-Library $ sudo apt-get install python-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
python-dev is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.

Code: Select all

pi@raspberrypi ~/Adafruit-Motor-HAT-Python-Library $ sudo python setup.py install
running install
Checking .pth file support in /usr/local/lib/python2.7/dist-packages/
/usr/bin/python -E -c pass
TEST PASSED: /usr/local/lib/python2.7/dist-packages/ appears to support .pth files
running bdist_egg
running egg_info
creating Adafruit_MotorHAT.egg-info
writing requirements to Adafruit_MotorHAT.egg-info/requires.txt
writing Adafruit_MotorHAT.egg-info/PKG-INFO
writing top-level names to Adafruit_MotorHAT.egg-info/top_level.txt
writing dependency_links to Adafruit_MotorHAT.egg-info/dependency_links.txt
writing manifest file 'Adafruit_MotorHAT.egg-info/SOURCES.txt'
reading manifest file 'Adafruit_MotorHAT.egg-info/SOURCES.txt'
writing manifest file 'Adafruit_MotorHAT.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-armv7l/egg
running install_lib
running build_py
creating build
creating build/lib.linux-armv7l-2.7
creating build/lib.linux-armv7l-2.7/Adafruit_MotorHAT
copying Adafruit_MotorHAT/Adafruit_MotorHAT.py -> build/lib.linux-armv7l-2.7/Adafruit_MotorHAT
copying Adafruit_MotorHAT/Adafruit_I2C.py -> build/lib.linux-armv7l-2.7/Adafruit_MotorHAT
copying Adafruit_MotorHAT/__init__.py -> build/lib.linux-armv7l-2.7/Adafruit_MotorHAT
copying Adafruit_MotorHAT/Adafruit_PWM_Servo_Driver.py -> build/lib.linux-armv7l-2.7/Adafruit_MotorHAT
creating build/bdist.linux-armv7l
creating build/bdist.linux-armv7l/egg
creating build/bdist.linux-armv7l/egg/Adafruit_MotorHAT
copying build/lib.linux-armv7l-2.7/Adafruit_MotorHAT/Adafruit_MotorHAT.py -> build/bdist.linux-armv7l/egg/Adafruit_MotorHAT
copying build/lib.linux-armv7l-2.7/Adafruit_MotorHAT/Adafruit_I2C.py -> build/bdist.linux-armv7l/egg/Adafruit_MotorHAT
copying build/lib.linux-armv7l-2.7/Adafruit_MotorHAT/__init__.py -> build/bdist.linux-armv7l/egg/Adafruit_MotorHAT
copying build/lib.linux-armv7l-2.7/Adafruit_MotorHAT/Adafruit_PWM_Servo_Driver.py -> build/bdist.linux-armv7l/egg/Adafruit_MotorHAT
byte-compiling build/bdist.linux-armv7l/egg/Adafruit_MotorHAT/Adafruit_MotorHAT.py to Adafruit_MotorHAT.pyc
byte-compiling build/bdist.linux-armv7l/egg/Adafruit_MotorHAT/Adafruit_I2C.py to Adafruit_I2C.pyc
byte-compiling build/bdist.linux-armv7l/egg/Adafruit_MotorHAT/__init__.py to __init__.pyc
byte-compiling build/bdist.linux-armv7l/egg/Adafruit_MotorHAT/Adafruit_PWM_Servo_Driver.py to Adafruit_PWM_Servo_Driver.pyc
creating build/bdist.linux-armv7l/egg/EGG-INFO
copying Adafruit_MotorHAT.egg-info/PKG-INFO -> build/bdist.linux-armv7l/egg/EGG-INFO
copying Adafruit_MotorHAT.egg-info/SOURCES.txt -> build/bdist.linux-armv7l/egg/EGG-INFO
copying Adafruit_MotorHAT.egg-info/dependency_links.txt -> build/bdist.linux-armv7l/egg/EGG-INFO
copying Adafruit_MotorHAT.egg-info/requires.txt -> build/bdist.linux-armv7l/egg/EGG-INFO
copying Adafruit_MotorHAT.egg-info/top_level.txt -> build/bdist.linux-armv7l/egg/EGG-INFO
zip_safe flag not set; analyzing archive contents...
creating dist
creating 'dist/Adafruit_MotorHAT-1.3.0-py2.7.egg' and adding 'build/bdist.linux-armv7l/egg' to it
removing 'build/bdist.linux-armv7l/egg' (and everything under it)
Processing Adafruit_MotorHAT-1.3.0-py2.7.egg
removing '/usr/local/lib/python2.7/dist-packages/Adafruit_MotorHAT-1.3.0-py2.7.egg' (and everything under it)
creating /usr/local/lib/python2.7/dist-packages/Adafruit_MotorHAT-1.3.0-py2.7.egg
Extracting Adafruit_MotorHAT-1.3.0-py2.7.egg to /usr/local/lib/python2.7/dist-packages
Adafruit-MotorHAT 1.3.0 is already the active version in easy-install.pth

Installed /usr/local/lib/python2.7/dist-packages/Adafruit_MotorHAT-1.3.0-py2.7.egg
Processing dependencies for Adafruit-MotorHAT==1.3.0
Searching for Adafruit-GPIO==0.9.3
Best match: Adafruit-GPIO 0.9.3
Processing Adafruit_GPIO-0.9.3-py2.7.egg
Adafruit-GPIO 0.9.3 is already the active version in easy-install.pth

Using /usr/local/lib/python2.7/dist-packages/Adafruit_GPIO-0.9.3-py2.7.egg
Searching for spidev==3.1
Best match: spidev 3.1
Processing spidev-3.1-py2.7-linux-armv7l.egg
spidev 3.1 is already the active version in easy-install.pth

Using /usr/local/lib/python2.7/dist-packages/spidev-3.1-py2.7-linux-armv7l.egg
Finished processing dependencies for Adafruit-MotorHAT==1.3.0

Again running my script I get this as output:

Code: Select all


pi@raspberrypi ~/Adafruit-Motor-HAT-Python-Library/examples $ sudo python mytest.py
Traceback (most recent call last):
  File "mytest.py", line 2, in <module>
    from Adafruit_MotorHAT import Adafruit_MotorHAT, Adafruit_DCMotor
  File "/usr/local/lib/python2.7/dist-packages/Adafruit_MotorHAT-1.3.0-py2.7.egg/Adafruit_MotorHAT/__init__.py", line 1, in <module>
    from .Adafruit_MotorHAT import Adafruit_StepperMotor, Adafruit_DCMotor, Adafruit_MotorHAT
  File "/usr/local/lib/python2.7/dist-packages/Adafruit_MotorHAT-1.3.0-py2.7.egg/Adafruit_MotorHAT/Adafruit_MotorHAT.py", line 3, in <module>
    from Adafruit_PWM_Servo_Driver import PWM
  File "/usr/local/lib/python2.7/dist-packages/Adafruit_MotorHAT-1.3.0-py2.7.egg/Adafruit_MotorHAT/Adafruit_PWM_Servo_Driver.py", line 11, in <module>
    class PWM :
  File "/usr/local/lib/python2.7/dist-packages/Adafruit_MotorHAT-1.3.0-py2.7.egg/Adafruit_MotorHAT/Adafruit_PWM_Servo_Driver.py", line 35, in PWM
    general_call_i2c = Adafruit_I2C(0x00)
  File "/usr/local/lib/python2.7/dist-packages/Adafruit_MotorHAT-1.3.0-py2.7.egg/Adafruit_MotorHAT/Adafruit_I2C.py", line 43, in __init__
    self.bus = smbus.SMBus(busnum if busnum >= 0 else Adafruit_I2C.getPiI2CBusNumber())
IOError: [Errno 2] No such file or directory


phaze3131
 
Posts: 15
Joined: Tue Jan 19, 2016 8:20 pm

Re: Can't Get Rpi Motor Hat To Work

Post by phaze3131 »

maybe it's just a faulty unit, I'll contact the RMA department and point them here so they can tell what the problem is.

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Can't Get Rpi Motor Hat To Work

Post by adafruit_support_mike »

They'll send you back here for confirmation that it's a hardware failure.

What do you get when you enter:

Code: Select all

sudo i2cdetect -y 1

phaze3131
 
Posts: 15
Joined: Tue Jan 19, 2016 8:20 pm

Re: Can't Get Rpi Motor Hat To Work

Post by phaze3131 »

pi@raspberrypi ~/Adafruit-Motor-HAT-Python-Library $ sudo i2cdetect -y 1
Error: Could not open file `/dev/i2c-1' or `/dev/i2c/1': No such file or directory

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Can't Get Rpi Motor Hat To Work

Post by adafruit_support_rick »

Right, so it's not a hardware problem. I2C has not been successfully enabled on your Pi.
Try the manual method of installing kernel support for I2C
https://learn.adafruit.com/adafruits-ra ... t-manually

phaze3131
 
Posts: 15
Joined: Tue Jan 19, 2016 8:20 pm

Re: Can't Get Rpi Motor Hat To Work

Post by phaze3131 »

First of all thank you for the help and I should of read the whole page and I could have understood my problem, I'm sorry, I am learning.

I installed manually and now I get this output:

Code: Select all

pi@raspberrypi ~/Adafruit-Motor-HAT-Python-Library/examples $ 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: 60 -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: 70 -- -- -- -- -- -- --
However when I run my code my motor still will not turn. I am checking the voltage readings on my meter and I am not getting any reading when I am connecting to either of the pairs.

I know the pairs, green and black are pairs, then red and blue are pairs (M1 or M2). I tested this twice with Ohm testings and manually spinning the motor to light an LED.

Is there a way I can test to see if If the board is good by itself with meter readings, or maybe my soldering wasn't successful.

I should be getting voltage readings on the terminals M1 and M2 right? (+ - on M1 terminals and then again testing + - on M2)

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Can't Get Rpi Motor Hat To Work

Post by adafruit_support_mike »

You should see voltage between each of the motor outputs and GND. You should also see voltage between the M+ and M- terminals, but that will be harder to measure accurately. It changes faster than a multimeter can follow.

Post a photo showing your hardware and connections and we'll make sure those are okay. 800x600 images usually work best. Also post the code you're using, and we'll see what we can find there.

Locked
Please be positive and constructive with your questions and comments.

Return to “General Project help”