0

Servo Libraries... I'm Lost
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Servo Libraries... I'm Lost

by Virtuous70 on Wed Jun 05, 2019 8:29 pm

Hello all,
I'm really inexperienced here, so you won't insult me by dumbing it down. I've got a trinket M0 and I'm trying to get it to control a servo. Ultimately, I'd like the code to toggle one pin as the input, when I hit a button it rotates 90 degrees (by sending an RF signal to a toggle switch), and when I hit the button again it returns to the original position (0 degrees.)
At this point, I have not been successful getting the servo to move at all using the sample sweep code from maker.makecode.com. That's the only way I've been successful getting a program on a Trinket M0, and I've done it a couple times before.

This is my first time working with a servo. I was able to install the latest (4.0) Circuit Python, and I downloaded the libraries and found the adafruit_motor folder. I placed that in the lib folder I created on the Trinket M0. But from what I can tell, there are a couple other libraries/bundles? called time, board and pulseio that need to be present and I don't know where to find them or how to install them.
Currently, when I mount the Trinket M0, I get the TRINKETBOOT disk on my desktop (I'm on a Mac). At one point, I was able to get the CIRCUIT_PYTHON volume to load instead of the TRINKETBOOT, and that was how I created the lib folder and placed the adafruit_motor folder inside.
My questions are:
1. Assuming I copied the makecode program for the sample sweep onto TRINKETBOOT, why is it not working? There servo does not move at all.
2. Is there anything else I need to do library-wise to prepare the Trinket M0?
3. Even if I could figure out the code, how do I get the CURCUIT_PYTHON image to mount so I can upload the program?

Thanks in advance,
-Chris
(Although not shown in the photo, the breadboard has power and the Trinket M0 is able to power up.)
Attachments
Servo.png
Servo.png (728.87 KiB) Viewed 184 times

Virtuous70
 
Posts: 22
Joined: Sat Nov 04, 2017 7:46 pm

Re: Servo Libraries... I'm Lost

by adafruit_support_mike on Thu Jun 06, 2019 1:45 am

[moved to the CircuitPython forum]

adafruit_support_mike
 
Posts: 59156
Joined: Thu Feb 11, 2010 2:51 pm

Re: Servo Libraries... I'm Lost

by tannewt2 on Thu Jun 06, 2019 1:35 pm

MakeCode and CircuitPython are two different things. Copying a file over from MakeCode will overwrite CircuitPython and make it so the CIRCUITPY drive doesn't appear.

So, to get CircuitPython back you'll need to copy a CircuitPython UF2 over onto the boot drive.

time, board and pulseio are built into CircuitPython and won't show up on the drive.

Let me know if you want to get it working with MakeCode instead of CircuitPython and I'll snag someone else to help with that.

tannewt2
 
Posts: 1313
Joined: Thu Oct 06, 2016 8:48 pm

Re: Servo Libraries... I'm Lost

by Virtuous70 on Sat Jun 08, 2019 9:36 am

That's very helpful, thank you. I will try to proceed with Circuit Python, but if I get in over my head, I will need to switch to MakeCode.

Virtuous70
 
Posts: 22
Joined: Sat Nov 04, 2017 7:46 pm

Re: Servo Libraries... I'm Lost

by XRAD on Mon Jun 10, 2019 10:19 am

And if you get frustrated of makecode/Python, we can help you with some very easy adafruit servo examples in C++ using the arduino IDE (Adafruit makes servo control uncomplicated, and you will have good control of whatever servo movement you need).....

for example, this is a simple code to make a servo go back and forth 180 degrees right out of the Arduino IDE Servo library:

Code: Select all | TOGGLE FULL SIZE

/* Sweep
 by BARRAGAN <http://barraganstudio.com>
 This example code is in the public domain.

 modified 8 Nov 2013
 by Scott Fitzgerald
 http://arduino.cc/en/Tutorial/Sweep
*/

#include <Servo.h>
 
Servo myservo;  // create servo object to control a servo
                // twelve servo objects can be created on most boards
 
int pos = 0;    // variable to store the servo position
 
void setup()
{
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}
 
void loop()
{
  for(pos = 0; pos <= 180; pos += 1) // goes from 0 degrees to 180 degrees
  {                                  // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for(pos = 180; pos>=0; pos-=1)     // goes from 180 degrees to 0 degrees
  {                               
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
}


XRAD
 
Posts: 532
Joined: Sat Nov 19, 2016 3:28 pm

Please be positive and constructive with your questions and comments.