Trinket servo problems

USB AVR Programmer and SPI interface. Adafruit's USBtinyISP.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
flsteam
 
Posts: 12
Joined: Tue Dec 15, 2015 5:03 pm

Trinket servo problems

Post by flsteam »

I am having trouble getting code to compile without getting errors.
I have copied and pasted several sample programs listed as "For the trinket" No Luck
Does the Adafruit_Servo also require code to run an interrupt?

I think my sketch is pretty simple: check if one of the two binary inputs is on.
Depending on which is on, drive the servo to one of 3 possible positions.

John B.
Central Florida

User avatar
Franklin97355
 
Posts: 23911
Joined: Mon Apr 21, 2008 2:33 pm

Re: Trinket servo problems

Post by Franklin97355 »

No Luck
What examples are you running and what error messages are you getting?

User avatar
flsteam
 
Posts: 12
Joined: Tue Dec 15, 2015 5:03 pm

Re: Trinket servo problems

Post by flsteam »

I am running "Blink" copy and pasted into Arduino 1.6.6
I keep getting the error "expected unqualified -id before numeric constant.

User avatar
flsteam
 
Posts: 12
Joined: Tue Dec 15, 2015 5:03 pm

Re: Trinket servo problems

Post by flsteam »

I get the same error when compiling "Pulse" also cut and pasted.

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

Re: Trinket servo problems

Post by adafruit_support_bill »

IDE 1.6.6 has been quite buggy and puts out a lot of strange compiler errors. We recommend using 1.6.5 for now.

User avatar
flsteam
 
Posts: 12
Joined: Tue Dec 15, 2015 5:03 pm

Re: Trinket servo problems

Post by flsteam »

Thanks. I will be back for the servo problems once the compile is solved.

John B.

User avatar
flsteam
 
Posts: 12
Joined: Tue Dec 15, 2015 5:03 pm

Re: Trinket servo problems

Post by flsteam »

Ok, back again....I have installed 1.6.5 and is working fine. Trying to get the servo example going on the trinket. can't get by the following code.

// We'll take advantage of the built in millis() timer that goes off
54.// to keep track of time, and refresh the servo every 20 milliseconds
55.// The SIGNAL(TIMER0_COMPA_vect) function is the interrupt that will be
56.// Called by the microcontroller every 2 milliseconds
57.volatile uint8_t counter = 0;
58.SIGNAL(TIMER0_COMPA_vect) {
59. // this gets called every 2 milliseconds
60. counter += 2;
61. // every 20 milliseconds, refresh the servos!
62. if (counter >= 20) {
63. counter = 0;
64. myServo1

John b.

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

Re: Trinket servo problems

Post by adafruit_support_bill »

can't get by the following code.
What exactly is the problem with it? If there are error messages, please post them.

User avatar
flsteam
 
Posts: 12
Joined: Tue Dec 15, 2015 5:03 pm

Re: Trinket servo problems

Post by flsteam »

The code:

Code: Select all

/*
 Pulse
 Pulses the internal LED to demonstrate the analogWrite function
 
 This example code is in the public domain.
 
 To upload to your Gemma or Trinket:
 1) Select the proper board from the Tools->Board Menu
 2) Select USBtinyISP from the Tools->Programmer
 3) Plug in the Gemma/Trinket, make sure you see the green LED lit
 4) For windows, install the USBtiny drivers
 5) Press the button on the Gemma/Trinket - verify you see
 the red LED pulse. This means it is ready to receive data
 6) Click the upload button above within 10 seconds
*/
 
int led = 1; // pulse 'digital' pin 1 - AKA the built in red LED
 
// the setup routine runs once when you press reset:
void setup() {
 // initialize the digital pin as an output.
 pinMode(led, OUTPUT);
}
 
// the loop routine runs over and over again forever:
void loop() {
 for (int i=0; i<256; i++) {
 analogWrite(led, i); // PWM the LED from 0 to 255 (max)
 delay(5);
 }
 for (int i=255; i>=0; i--) {
 analogWrite(led, i); // PWM the LED from 255 (max) to 0
 delay(5);
 }
}
The first of many errors: Expected unqualified -id before numeric constant

John B.
Last edited by Franklin97355 on Thu Dec 17, 2015 1:57 pm, edited 1 time in total.
Reason: Added missing code tags and removed line numbers

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

Re: Trinket servo problems

Post by adafruit_support_bill »

Please post the full text of the error message. It will tell you the precise line and column numbers where the error was detected.

User avatar
flsteam
 
Posts: 12
Joined: Tue Dec 15, 2015 5:03 pm

Re: Trinket servo problems

Post by flsteam »

First I just installed Windows 10 and for some reason I can't always cut/paste. So before I hand write all the messages let me ask a question. What do I need to have in a sketch to drive a standard hobby servo from a Trinket? I know softservo but do I also to use software interrupts?

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

Re: Trinket servo problems

Post by adafruit_support_bill »

You just need the Adafruit Software Servo library: https://learn.adafruit.com/trinket-gemm ... ntrol/code

User avatar
flsteam
 
Posts: 12
Joined: Tue Dec 15, 2015 5:03 pm

Re: Trinket servo problems

Post by flsteam »

I have it and it is installed and called in the first line.
Here is the code:

The error message is the same as before: Expected unqualified -id before numeric constant @ line 43

#include <Adafruit_SoftServo.h>

27. int SERVO1PIN 0 // Servo control line (orange) on Trinket Pin #0
28.
29. int POTPIN 1 // Potentiometer sweep (center) on Trinket Pin #2 (Analog 1)
30.
31. Adafruit_SoftServo myServo1; //create servo objects
32.
33. void setup() {
34. // Set up the interrupt that will refresh the servo for us automagically
35. OCR0A = 0xAF; // any number is OK
36. TIMSK |= _BV(OCIE0A); // Turn on the compare interrupt (below!)
37.
38. myServo1.attach(SERVO1PIN); // Attach the servo to pin 0 on Trinket
39. myServo1.write(90); // Tell servo to go to position per quirk
40. delay(15); // Wait 15ms for the servo to reach the position
41.
}

43. void loop()
{
44. int potValue; // variable to read potentiometer
45. int servoPos; // variable to convert voltage on pot to servo position
46. potValue = analogRead(POTPIN); // Read voltage on potentiometer
47. servoPos = map(potValue, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180)
48. analogWrite(myServo1, servoPos); // tell servo to go to position
50. delay(15); // waits 15ms for the servo to reach the position
}

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

Re: Trinket servo problems

Post by adafruit_support_bill »

Where are those line numbers coming from? Why do they start at 27? The code you posted earlier is only 35 lines long.

User avatar
Franklin97355
 
Posts: 23911
Joined: Mon Apr 21, 2008 2:33 pm

Re: Trinket servo problems

Post by Franklin97355 »

You can turn off the line numbers in the preferences and then use our

Code: Select all

 button </> when pasting your code.

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

Return to “USBtinyISP”