Servo rotation and 315Mhz T/R help

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
adafruit_support_bill
 
Posts: 88090
Joined: Sat Feb 07, 2009 10:11 am

Re: Servo rotation and 315Mhz T/R help

Post by adafruit_support_bill »

The Gemma code should work on the Trinket as well.

User avatar
jc27
 
Posts: 185
Joined: Sun Nov 24, 2013 5:05 am

Re: Servo rotation and 315Mhz T/R help

Post by jc27 »

Ok, I will try a mash up of the two and see what happens.

User avatar
jc27
 
Posts: 185
Joined: Sun Nov 24, 2013 5:05 am

Re: Servo rotation and 315Mhz T/R help

Post by jc27 »

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();
  }
}
  
This is the new code. It compiles and uploads with no issues, but still nothing on the servo. What would happen if I define the pins on the trinket like in the gemma example and remove the pin assigning code from the void setup section? I also removed the code for the 16Mhz because it probably won't make a difference and it saves some power drain on the batteries.
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?

User avatar
adafruit_support_bill
 
Posts: 88090
Joined: Sat Feb 07, 2009 10:11 am

Re: Servo rotation and 315Mhz T/R help

Post by adafruit_support_bill »

Code: Select all

servo1.attach (9);
There is no pin 9 on a Trinket. What pin do you have the servo attached to?

User avatar
jc27
 
Posts: 185
Joined: Sun Nov 24, 2013 5:05 am

Re: Servo rotation and 315Mhz T/R help

Post by jc27 »

Well that could be a problem lol. I will change it and see what happens.

User avatar
jc27
 
Posts: 185
Joined: Sun Nov 24, 2013 5:05 am

Re: Servo rotation and 315Mhz T/R help

Post by jc27 »

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();
  }
}
  
Here is the newest code (sorry it took so long). I realized when I looked at the code that I didn't assign the trinket pins correctly, now the buttons and the output to the servo are set up right this time.
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?

User avatar
adafruit_support_bill
 
Posts: 88090
Joined: Sat Feb 07, 2009 10:11 am

Re: Servo rotation and 315Mhz T/R help

Post by adafruit_support_bill »

The loop variable in the 'for' loops is what should be controlling the servo angle:

Code: Select all

for (int i = 0; i < 90; i++)
If you increase the 90 to a larger value does that affect the servo angle?

User avatar
jc27
 
Posts: 185
Joined: Sun Nov 24, 2013 5:05 am

Re: Servo rotation and 315Mhz T/R help

Post by jc27 »

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();
  }
}
  
Newest version. I changed the angle like you recommended, as well as tweaked the delay time. I think the servo I have isn't strong enough to rotate it properly, since it tends to bounce as it moves. I am going to try to find a scale and weigh the parts and see how much servo lifting torque I should be using.
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?

User avatar
adafruit_support_bill
 
Posts: 88090
Joined: Sat Feb 07, 2009 10:11 am

Re: Servo rotation and 315Mhz T/R help

Post by adafruit_support_bill »

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.

User avatar
jc27
 
Posts: 185
Joined: Sun Nov 24, 2013 5:05 am

Re: Servo rotation and 315Mhz T/R help

Post by jc27 »

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.

User avatar
jc27
 
Posts: 185
Joined: Sun Nov 24, 2013 5:05 am

Re: Servo rotation and 315Mhz T/R help

Post by jc27 »

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.

User avatar
adafruit_support_bill
 
Posts: 88090
Joined: Sat Feb 07, 2009 10:11 am

Re: Servo rotation and 315Mhz T/R help

Post by adafruit_support_bill »

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

User avatar
jc27
 
Posts: 185
Joined: Sun Nov 24, 2013 5:05 am

Re: Servo rotation and 315Mhz T/R help

Post by jc27 »

Awesome thank you.

User avatar
jc27
 
Posts: 185
Joined: Sun Nov 24, 2013 5:05 am

Re: Servo rotation and 315Mhz T/R help

Post by jc27 »

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.

User avatar
adafruit_support_bill
 
Posts: 88090
Joined: Sat Feb 07, 2009 10:11 am

Re: Servo rotation and 315Mhz T/R help

Post by adafruit_support_bill »

Thanks for the good words. We are glad to help!

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

Return to “Arduino”