Servo rotation and 315Mhz T/R help
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- adafruit_support_bill
- Posts: 88093
- Joined: Sat Feb 07, 2009 10:11 am
Re: Servo rotation and 315Mhz T/R help
The Gemma code should work on the Trinket as well.
- jc27
- Posts: 185
- Joined: Sun Nov 24, 2013 5:05 am
Re: Servo rotation and 315Mhz T/R help
Ok, I will try a mash up of the two and see what happens.
- jc27
- Posts: 185
- Joined: Sun Nov 24, 2013 5:05 am
Re: Servo rotation and 315Mhz T/R help
Code: Select all
#include <Adafruit_SoftServo.h>
int button1 = 0;
int press1 = 0;
int button2 = 0;
int press2= 0;
Adafruit_SoftServo servo1;
int pos = 0;
void setup()
{
OCR0A = 0xAF; // copied from the gemma tutorial
TIMSK |= _BV(OCIE0A); // copied from gemma tutorial and what is this symbol "|"
pinMode (button1, INPUT);
pinMode (button2, INPUT);
servo1.attach (9);
servo1.write (0);
}
void loop()
{
if ((digitalRead(button1)) == HIGH && (pos == 0))
{
for (int i = 0; i < 90; i++)
{
pos ++;
servo1.write(pos);
delay (30);
}
}
if ((digitalRead(button2)) == HIGH && (pos == 90))
{
for (int i = 90; i > 0; i--)
{
pos --;
servo1.write(pos);
delay (30);
}
}
}
volatile uint8_t counter = 0;
SIGNAL(TIMER0_COMPA_vect)
{
counter += 2;
if (counter >= 20)
{
counter = 0;
servo1.refresh();
}
}
Could I connect the trinket output pin to an oscilliscope it see if I am even getting a wave form?
And like I mentioned earlier, could I use one of the prebootloaded atmel chips I got from you without having to add any extra components (filtering caps, resistors, ect)? And since it would probably work at 8Mhz, I could get away with not using an external crystal correct?
- adafruit_support_bill
- Posts: 88093
- Joined: Sat Feb 07, 2009 10:11 am
Re: Servo rotation and 315Mhz T/R help
Code: Select all
servo1.attach (9);
- jc27
- Posts: 185
- Joined: Sun Nov 24, 2013 5:05 am
Re: Servo rotation and 315Mhz T/R help
Well that could be a problem lol. I will change it and see what happens.
- jc27
- Posts: 185
- Joined: Sun Nov 24, 2013 5:05 am
Re: Servo rotation and 315Mhz T/R help
Code: Select all
#include <Adafruit_SoftServo.h>
int button1 = 0;
int press1 = 0;
int button2 = 2;
int press2= 0;
Adafruit_SoftServo servo1;
int pos = 0;
void setup()
{
OCR0A = 0xAF; // copied from the gemma tutorial
TIMSK |= _BV(OCIE0A); // copied from gemma tutorial and what is this symbol "|"
pinMode (button1, INPUT);
pinMode (button2, INPUT);
servo1.attach (1);
servo1.write (0);
}
void loop()
{
if ((digitalRead(button1)) == HIGH && (pos == 0))
{
for (int i = 0; i < 90; i++)
{
pos ++;
servo1.write(pos);
delay (12);
}
}
if ((digitalRead(button2)) == HIGH && (pos == 90))
{
for (int i = 90; i > 0; i--)
{
pos --;
servo1.write(pos);
delay (5);
}
}
}
volatile uint8_t counter = 0;
SIGNAL(TIMER0_COMPA_vect)
{
counter += 2;
if (counter >= 20)
{
counter = 0;
servo1.refresh();
}
}
The code seems to work, but the servo only rotates 45 degrees rather than the full 90. I am powering the servo with a separate power source (5v 10a) and I am running the receiver off of the 5v pin on the trinket (which is running off the USB from my laptop).
Does the counter have anything to do with the rotation of the servo, or is that contained in the "if, for" statements of the code?
- adafruit_support_bill
- Posts: 88093
- Joined: Sat Feb 07, 2009 10:11 am
Re: Servo rotation and 315Mhz T/R help
The loop variable in the 'for' loops is what should be controlling the servo angle:
If you increase the 90 to a larger value does that affect the servo angle?
Code: Select all
for (int i = 0; i < 90; i++)
- jc27
- Posts: 185
- Joined: Sun Nov 24, 2013 5:05 am
Re: Servo rotation and 315Mhz T/R help
Code: Select all
#include <Adafruit_SoftServo.h>
int button1 = 0;
int press1 = 0;
int button2 = 2;
int press2= 0;
Adafruit_SoftServo servo1;
int pos = 0;
void setup()
{
OCR0A = 0xAF; // copied from the gemma tutorial
TIMSK |= _BV(OCIE0A); // copied from gemma tutorial and what is this symbol "|"
pinMode (button1, INPUT);
pinMode (button2, INPUT);
servo1.attach (1);
servo1.write (0);
}
void loop()
{
if ((digitalRead(button1)) == HIGH && (pos == 0))
{
for (int i = 0; i < 165; i++)
{
pos ++;
servo1.write(pos);
delay (7);
}
}
if ((digitalRead(button2)) == HIGH && (pos == 165))
{
for (int i = 165; i > 0; i--)
{
pos --;
servo1.write(pos);
delay (10);
}
}
}
volatile uint8_t counter = 0;
SIGNAL(TIMER0_COMPA_vect)
{
counter += 2;
if (counter >= 10)
{
counter = 0;
servo1.refresh();
}
}
I also changed the refresh time a little. I am hoping that it will keep the servo from humming, when it stops rotating. I am thinking once I have the proper lifting power and the refresh, that the servo will move a little more smoothly as well as not hum. I think it is humming because it is constantly trying to maintain the servo position, and since the servo ay not be strong enough the shaft tends to drift a little.
The rotation works (once I increased the degree value), but why did I need to do that? As you can see in the code I had to increase it to around 165 (instead of 90) to get the servo to rotate the desired 90 degrees.
I am still using the laptop USB for trinket and receiver power and a powered breadboard for the servo. Tomorrow I will try to see if everything will run off of either a 9v or 4 AA batteries. Once I get the power situated, I can start looking at making a PC board to mount everything to.
Side note, do you sell perf board or etching supplies? I want to make a few before I send any final designs to get made to make sure that the layout will work.
Also, does the orientation of the receiver board (horizontal rather than vertical) make a difference in how it can receive the RF signals from the transmitter fob?
- adafruit_support_bill
- Posts: 88093
- Joined: Sat Feb 07, 2009 10:11 am
Re: Servo rotation and 315Mhz T/R help
A little humming is normal as the servo actively maintains position. But it gets worse with load. A more powerful servo, or some counterbalancing for your load should help.
I haven't used the servo library on the Trinket. One possibility is that the timing on your 5v Trinket is different than the timing on the Gemma, since they have different clock speeds (8MHz vs 16MHz).
The orientation of the receiver board itself should not make much difference. But the antenna should be vertical for best reception.
I haven't used the servo library on the Trinket. One possibility is that the timing on your 5v Trinket is different than the timing on the Gemma, since they have different clock speeds (8MHz vs 16MHz).
The orientation of the receiver board itself should not make much difference. But the antenna should be vertical for best reception.
- jc27
- Posts: 185
- Joined: Sun Nov 24, 2013 5:05 am
Re: Servo rotation and 315Mhz T/R help
I may try changing the trinket to 16mhz to see what happens. Thanks for the help with this, I probably wouldn't have figured it out without it.
I'm going to try different ways to power it to see how small I can make everything, then try designing the board.
I'm going to try different ways to power it to see how small I can make everything, then try designing the board.
- jc27
- Posts: 185
- Joined: Sun Nov 24, 2013 5:05 am
Re: Servo rotation and 315Mhz T/R help
I did some tweaking with the code a couple of days ago and I think I have it the way I want it. I played around with the timing as well as the angles and rotation speed. One thing I was a little surprised about was the supply power. Once I had the code the way I wanted it, the servo was still a bit jerky. I was using the 6v supply from my powered breadboard to run the trinket and receiver, but I decided to try an A23 12v battery to power the trinket and receiver and it seemed to smooth everything out.
Noemi working on designing a custom PC board to mount everything to and I was wondering if there was a CAD drawing that shows the exact dimensions of the trinket and the location and size of the I/O pin holes. I plan on horizontally mounting the trinket and receiver to a small board that will fit in a container about 2.5" square.
Noemi working on designing a custom PC board to mount everything to and I was wondering if there was a CAD drawing that shows the exact dimensions of the trinket and the location and size of the I/O pin holes. I plan on horizontally mounting the trinket and receiver to a small board that will fit in a container about 2.5" square.
- adafruit_support_bill
- Posts: 88093
- Joined: Sat Feb 07, 2009 10:11 am
Re: Servo rotation and 315Mhz T/R help
The Eagle files we use for manufacture are here: https://github.com/adafruit/Adafruit-Trinket-PCB
These are 2D files & show the location of all components & holes on the boards.
EagleCad is a free download, available here: http://www.cadsoftusa.com/download-eagle/?language=en
These are 2D files & show the location of all components & holes on the boards.
EagleCad is a free download, available here: http://www.cadsoftusa.com/download-eagle/?language=en
- jc27
- Posts: 185
- Joined: Sun Nov 24, 2013 5:05 am
Re: Servo rotation and 315Mhz T/R help
Awesome thank you.
- jc27
- Posts: 185
- Joined: Sun Nov 24, 2013 5:05 am
Re: Servo rotation and 315Mhz T/R help
I have to say that everyone at adafruit is super helpful. Thank you for all your help with the code. You guys are awesome and make fantastic parts.
- adafruit_support_bill
- Posts: 88093
- Joined: Sat Feb 07, 2009 10:11 am
Re: Servo rotation and 315Mhz T/R help
Thanks for the good words. We are glad to help!
Please be positive and constructive with your questions and comments.