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
Trinket servo problems
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- Franklin97355
- Posts: 23911
- Joined: Mon Apr 21, 2008 2:33 pm
Re: Trinket servo problems
What examples are you running and what error messages are you getting?No Luck
- flsteam
- Posts: 12
- Joined: Tue Dec 15, 2015 5:03 pm
Re: Trinket servo problems
I am running "Blink" copy and pasted into Arduino 1.6.6
I keep getting the error "expected unqualified -id before numeric constant.
I keep getting the error "expected unqualified -id before numeric constant.
- flsteam
- Posts: 12
- Joined: Tue Dec 15, 2015 5:03 pm
Re: Trinket servo problems
I get the same error when compiling "Pulse" also cut and pasted.
- adafruit_support_bill
- Posts: 88093
- Joined: Sat Feb 07, 2009 10:11 am
Re: Trinket servo problems
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.
- flsteam
- Posts: 12
- Joined: Tue Dec 15, 2015 5:03 pm
Re: Trinket servo problems
Thanks. I will be back for the servo problems once the compile is solved.
John B.
John B.
- flsteam
- Posts: 12
- Joined: Tue Dec 15, 2015 5:03 pm
Re: Trinket servo problems
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.
// 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.
- adafruit_support_bill
- Posts: 88093
- Joined: Sat Feb 07, 2009 10:11 am
Re: Trinket servo problems
What exactly is the problem with it? If there are error messages, please post them.can't get by the following code.
- flsteam
- Posts: 12
- Joined: Tue Dec 15, 2015 5:03 pm
Re: Trinket servo problems
The code:
The first of many errors: Expected unqualified -id before numeric constant
John B.
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);
}
}
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
Reason: Added missing code tags and removed line numbers
- adafruit_support_bill
- Posts: 88093
- Joined: Sat Feb 07, 2009 10:11 am
Re: Trinket servo problems
Please post the full text of the error message. It will tell you the precise line and column numbers where the error was detected.
- flsteam
- Posts: 12
- Joined: Tue Dec 15, 2015 5:03 pm
Re: Trinket servo problems
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?
- adafruit_support_bill
- Posts: 88093
- Joined: Sat Feb 07, 2009 10:11 am
Re: Trinket servo problems
You just need the Adafruit Software Servo library: https://learn.adafruit.com/trinket-gemm ... ntrol/code
- flsteam
- Posts: 12
- Joined: Tue Dec 15, 2015 5:03 pm
Re: Trinket servo problems
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
}
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
}
- adafruit_support_bill
- Posts: 88093
- Joined: Sat Feb 07, 2009 10:11 am
Re: Trinket servo problems
Where are those line numbers coming from? Why do they start at 27? The code you posted earlier is only 35 lines long.
- Franklin97355
- Posts: 23911
- Joined: Mon Apr 21, 2008 2:33 pm
Re: Trinket servo problems
You can turn off the line numbers in the preferences and then use our
Code: Select all
button </> when pasting your code.
Please be positive and constructive with your questions and comments.