Servo Libraries... I'm Lost

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Virtuous70
 
Posts: 23
Joined: Sat Nov 04, 2017 7:46 pm

Servo Libraries... I'm Lost

Post by Virtuous70 »

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 260 times

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

Re: Servo Libraries... I'm Lost

Post by adafruit_support_mike »

[moved to the CircuitPython forum]

User avatar
tannewt
 
Posts: 3314
Joined: Thu Oct 06, 2016 8:48 pm

Re: Servo Libraries... I'm Lost

Post by tannewt »

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.

User avatar
Virtuous70
 
Posts: 23
Joined: Sat Nov 04, 2017 7:46 pm

Re: Servo Libraries... I'm Lost

Post by Virtuous70 »

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.

User avatar
XRAD
 
Posts: 754
Joined: Sat Nov 19, 2016 3:28 pm

Re: Servo Libraries... I'm Lost

Post by XRAD »

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


/* Sweep
 by BANNED <http://BANNED.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 
  } 
} 


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

Return to “Adafruit CircuitPython”