Black Lives Matter - Action and Equality. ... Adafruit is open and shipping.
0

Trouble with MotorHAT and Adafruit IO on RPI3
Moderators: adafruit_support_bill, adafruit

Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
Please be positive and constructive with your questions and comments.

Trouble with MotorHAT and Adafruit IO on RPI3

by ACaldwell8814 on Wed May 27, 2020 6:39 pm

Hello all,

I'm very new to all of this and super excited to try to make some things that are useful. I had a concept of powering a couple of stepper motors with my Adafruit MotorHAT (on top of a Raspberry PI 3) and saw a project to control them wirelessly. I've followed a few guides and installed all of the libraries, and configured all of my settings a few times, but when I run the program and then go to click a go button on my dashboard, my stepper motor will start to work and then stop. I keep getting the following when I run my program, Adafruit_IO_steppers:

Traceback (most recent call last):
File "adafruit_io_steppers.py", line 104, in <module>
stepper_1_step_size = aio.receive(feed_step_1_step_size.key)
File "/usr/local/lib/python3.7/dist-packages/Adafruit_IO/client.py", line 216, in receive
return Data.from_dict(self._get(path))
File "/usr/local/lib/python3.7/dist-packages/Adafruit_IO/client.py", line 118, in _get
self._handle_error(response)
File "/usr/local/lib/python3.7/dist-packages/Adafruit_IO/client.py", line 108, in _handle_error
raise RequestError(response)
Adafruit_IO.errors.RequestError: Adafruit IO request failed: 404 Not Found - not found - API documentation can be found at https://io.adafruit.com/api/docs

Here is my code:

Code: Select all | TOGGLE FULL SIZE
"""
'adafruit_io_steppers.py'
==================================
Example of using CircuitPython and
Adafruit IO to control two stepper
motors over the internet.
 
Dependencies:
    - Adafruit_Blinka
        (https://github.com/adafruit/Adafruit_Blinka)
    - Adafruit_CircuitPython_MotorKit
        (https://github.com/adafruit/Adafruit_CircuitPython_MotorKit)
    - Adafruit_IO_Python
        (https://github.com/adafruit/Adafruit_IO_Python)
"""
# Import Python Libraries
import time
import atexit
import threading
 
# import Adafruit IO REST client.
from Adafruit_IO import Client, RequestError
 
# Import CircuitPython Libraries
from adafruit_motor import stepper as STEPPER
from adafruit_motorkit import MotorKit
 
# Set to your Adafruit IO key.
# Remember, your key is a secret,
# so make sure not to publish it when you publish this code!
ADAFRUIT_IO_KEY = '[deleted before posting]'
 
# Set to your Adafruit IO username.
# (go to https://accounts.adafruit.com to find your username)
ADAFRUIT_IO_USERNAME = '[deleted before posting]'
 
# Create an instance of the REST client.
aio = Client(ADAFRUIT_IO_USERNAME, ADAFRUIT_IO_KEY)
 
# Delay between checking for `go` button press on Adafruit IO, in seconds
ADAFRUIT_IO_DELAY = 1
 
# Stepper 1 Adafruit IO Feeds
feed_step_1_steps = aio.feeds('stepper1steps')
feed_step_1_direction = aio.feeds('stepper1direction')
feed_step_1_step_size = aio.feeds('stepper1stepsize')
# Stepper 2 Adafruit Feeds
feed_step_2_steps = aio.feeds('stepper2steps')
feed_step_2_direction = aio.feeds('stepper2direction')
feed_step_2_step_size = aio.feeds('stepper2stepsize')
# Steppers start button
feed_steppers_status = aio.feeds('stepperstart')
 
# create a default object, no changes to I2C address or frequency
kit = MotorKit()
 
# create empty threads (these will hold the stepper 1 and 2 threads)
# pylint: disable=bad-thread-instantiation
st1 = threading.Thread()
st2 = threading.Thread()
 
# recommended for auto-disabling motors on shutdown!
def turnOffMotors():
    kit.stepper1.release()
    kit.stepper2.release()
 
atexit.register(turnOffMotors)
stepstyles = [STEPPER.SINGLE, STEPPER.DOUBLE, STEPPER.INTERLEAVE, STEPPER.MICROSTEP]
 
def stepper_worker(stepper, numsteps, direction, stepper_name, style, show_steps=False):
    print("Steppin!")
    stepper_steps = numsteps
    print(stepper_steps)
    for _ in range(numsteps):
        stepper.onestep(direction=direction, style=style)
        if show_steps: # print out the steps and send to IO stepper slider
            stepper_steps -= 1
            print('Steps: ', stepper_steps)
            aio.send(feed_step_1_steps.key, stepper_steps)
            time.sleep(0.5)
    print("{0} Done Stepping".format(stepper_name))
    # Reset slider on dashboard
    if stepper_name == "Stepper 1":
        aio.send(feed_step_1_steps.key, 0)
    elif stepper_name == "Stepper 2":
        aio.send(feed_step_2_steps.key, 0)
 
 
while True:
    try: # attempt to poll the stepper status feed
        print('checking for GO button press...')
        stepper_start = aio.receive(feed_steppers_status.key)
    except RequestError.ThrottlingError:
        print('Exceeded the limit of Adafruit IO requests, delaying 30 seconds...')
        time.sleep(30)
 
    # Stepper 1
    if not st1.isAlive() and int(stepper_start.value):
        stepper_1_steps = aio.receive(feed_step_1_steps.key)
        stepper_1_steps = int(stepper_1_steps.value)
        if stepper_1_steps > 0: # stepper slider is set
            # Get stepper configuration from io feeds
            stepper_1_direction = aio.receive(feed_step_1_direction.key)
            stepper_1_step_size = aio.receive(feed_step_1_step_size.key)
            print('Stepper 1 Configuration')
            print('\t%d steps' % stepper_1_steps)
            print('\tStep Size: ', stepper_1_step_size.value)
            print('\tStepper Direction: ', stepper_1_direction.value)
 
            # Set Stepper Direction
            if stepper_1_direction.value == 'Forward':
                move_dir = STEPPER.FORWARD
            elif stepper_1_direction.value == 'Backward':
                move_dir = STEPPER.BACKWARD
            # Stepper 1 Thread
            st1 = threading.Thread(target=stepper_worker, args=(kit.stepper1,
                                                                stepper_1_steps,
                                                                move_dir,
                                                                "Stepper 1",
                                                                stepstyles[STEPPER.SINGLE],))
            st1.start()
 
    # Stepper 2
    if not st2.isAlive() and int(stepper_start.value):
        stepper_2_steps = aio.receive(feed_step_2_steps.key)
        stepper_2_steps = int(stepper_2_steps.value)
        if stepper_2_steps > 0: # stepper slider is set
            # Get stepper configuration from io feeds
            stepper_2_direction = aio.receive(feed_step_2_direction.key)
            stepper_2_step_size = aio.receive(feed_step_2_step_size.key)
            print('Stepper 2 Configuration')
            print('\t%d steps' % stepper_2_steps)
            print('\tStep Size: ', stepper_2_step_size.value)
            print('\tStepper Direction: ', stepper_2_direction.value)
            # Set Stepper Direction
            if stepper_2_direction.value == 'Forward':
                move_dir = STEPPER.FORWARD
            elif stepper_2_direction.value == 'Backward':
                move_dir = STEPPER.BACKWARD
            # Stepper 2 Thread
            st2 = threading.Thread(target=stepper_worker, args=(kit.stepper2,
                                                                stepper_2_steps,
                                                                move_dir,
                                                                "Stepper 2",
                                                                stepstyles[STEPPER.SINGLE],))
            st2.start()
 
    # delay polling the `go button` to avoid Adafruit IO timeouts
    print('Delaying for {0} seconds...'.format(ADAFRUIT_IO_DELAY))
    time.sleep(ADAFRUIT_IO_DELAY)


I'm very inexperienced with most of this software, but I could use some help if anyone out there might be gracious enough to provide it.

Cheers!
-Aaron

ACaldwell8814
 
Posts: 8
Joined: Wed May 27, 2020 6:23 pm

Re: Trouble with MotorHAT and Adafruit IO on RPI3

by adafruit_support_carter on Wed May 27, 2020 7:47 pm

It looks like you are having a basic connection issue with Adafruit IO
Adafruit_IO.errors.RequestError: Adafruit IO request failed: 404 Not Found - not found - API


Have you managed to get a basic Adafruit IO example to work yet? Something without the stepper. Just a basic hello world example.

adafruit_support_carter
 
Posts: 15963
Joined: Tue Nov 29, 2016 2:45 pm

Re: Trouble with MotorHAT and Adafruit IO on RPI3

by ACaldwell8814 on Thu May 28, 2020 10:53 am

Thank you for your reply!

No, I haven't tried any other examples. I downloaded the example repository yesterday. I'll have to see if I can find one to use. Thanks again!

ACaldwell8814
 
Posts: 8
Joined: Wed May 27, 2020 6:23 pm

Re: Trouble with MotorHAT and Adafruit IO on RPI3

by ACaldwell8814 on Fri May 29, 2020 9:15 am

I gave an example script a try and was successful. I also deleted my older feeds and created newer feeds in case I may have had typos. It is important to note, I only have one stepper motor attached to my motorHAT rather than 2. It is in the stepper1 slot. I created feeds for the second motor for continuity, and I assumed the code would work as long as I'm not trying to perform functions that require motor 2. I wonder if that might be part of the problem.

ACaldwell8814
 
Posts: 8
Joined: Wed May 27, 2020 6:23 pm

Re: Trouble with MotorHAT and Adafruit IO on RPI3

by brubell on Fri May 29, 2020 10:23 am

Did you set up all the feeds listed on this page?
https://learn.adafruit.com/wireless-ste ... -3019075-2

brubell
 
Posts: 946
Joined: Fri Jul 17, 2015 10:33 pm

Re: Trouble with MotorHAT and Adafruit IO on RPI3

by ACaldwell8814 on Fri May 29, 2020 11:01 am

Yes, I did. Those were the feeds I created, deleted, and then created again.

ACaldwell8814
 
Posts: 8
Joined: Wed May 27, 2020 6:23 pm

Re: Trouble with MotorHAT and Adafruit IO on RPI3

by ACaldwell8814 on Mon Jun 01, 2020 11:06 am

I tried running the temperature sample, and believe it worked normally. There was a new feed added, and data looked like it was being collected with action on the RPI. I think it was working. One thing I'm curious about is whether or not the RPI works out of the box to communicate to IO or if there are any settings I might have missed with the WiFi connection when setting everything up. When I press a button on the dashboard, nothing happens, but if I hold it, the stepper motor twitches, and then the error occurs.

ACaldwell8814
 
Posts: 8
Joined: Wed May 27, 2020 6:23 pm

Re: Trouble with MotorHAT and Adafruit IO on RPI3

by brubell on Mon Jun 01, 2020 11:08 am

One thing I'm curious about is whether or not the RPI works out of the box to communicate to IO or if there are any settings I might have missed with the WiFi connection when setting everything up. When I press a button on the dashboard, nothing happens, but if I hold it, the stepper motor twitches, and then the error occurs.


Do you see any errors on the io.adafruit.com/monitor page when you hold the button on the dashboard?

brubell
 
Posts: 946
Joined: Fri Jul 17, 2015 10:33 pm

Re: Trouble with MotorHAT and Adafruit IO on RPI3

by ACaldwell8814 on Mon Jun 01, 2020 11:35 am

I do not.

ACaldwell8814
 
Posts: 8
Joined: Wed May 27, 2020 6:23 pm

Re: Trouble with MotorHAT and Adafruit IO on RPI3

by ACaldwell8814 on Mon Jun 01, 2020 12:21 pm

I believe I might not be connected properly. I don't see any connections listed on the monitor page either.

ACaldwell8814
 
Posts: 8
Joined: Wed May 27, 2020 6:23 pm

Re: Trouble with MotorHAT and Adafruit IO on RPI3

by ACaldwell8814 on Thu Jun 04, 2020 2:16 pm

Are there any good guides I might use to double-check my setup beyond the project guide?

ACaldwell8814
 
Posts: 8
Joined: Wed May 27, 2020 6:23 pm

Please be positive and constructive with your questions and comments.