Ardunio Class 101 chapter 7, Lab's 3 & 4, Controlling servos

This forum is dedicated to the author Joe Pardue as he teaches you about AVR C Programming in his workshop series.

Moderator: joepardue

Post Reply
frank_fg
Posts: 41
Joined: Tue Apr 29, 2008 9:07 am
Contact:

Ardunio Class 101 chapter 7, Lab's 3 & 4, Controlling servos

Post by frank_fg » Tue Jul 01, 2014 9:52 am

:smile:

Hi!

Ardunio Classroom 101 chapter 7 Lab's 3 and 4.

I have the same error on both of them.

1) Missing closing curly brace, fixed.

2) Right after the closing curly brace, there is a delay of 1 sec., which is outside of it.
should it not be in side? I put it inside the last curly brace, same error.

3) following the delay command towards the end of the program, there is the closing brace,
without the opening one. is this not also an error? I put an opening curly brace, before the delay,
still did not work.

Q - Is there a way to find the errors and there meaning?

Thanks
Frank fg

User avatar
joepardue
Posts: 51
Joined: Sun Jul 31, 2011 7:44 am
Contact:

Re: Ardunio Class 101 chapter 7, Lab's 3 & 4, Controlling se

Post by joepardue » Wed Jul 02, 2014 11:21 am

I suspect this is typo? I just copied and pasted the file into Arduino and it compiled okay.

One problem is that I didn't submit the correct zip file to Nuts&Volts for this code. I just resubmitted it so it should be attached to the article in the next day or so. In the meantime try the following - copy and paste only one module at at time and see if they work.

// A101_ch7_pot_angle 5/7/14 Joe Pardue

#include <Servo.h>

Servo myservo; // create servo object to control a servo

int sensorPin = A0; // analog input pin
int sensorValue = 0; // store the analog input value
int zero = 0; // calibration reading for 0 degree
int oneeighty = 0; // calibrartion reading for 180 degree

void setup() {
// attaches the servo on pin 9 to the servo
myservo.attach(9);

Serial.begin(57600);
Serial.println("Measure potentiometer angle rev 1.0");
}

void loop() {

if(Serial.available())
{
char c = Serial.read();
if(c == 'a') // get the zero degree calibration value
{
// read the value from the sensor:
zero = analogRead(sensorPin);

Serial.print("You set 0 degree to: ");
Serial.println(zero);
}
if(c == 'b') // get the 180 degree calibration value
{
// read the value from the sensor:
oneeighty = analogRead(sensorPin);

Serial.print("You set 180 degree to: ");
Serial.println(oneeighty);
}

}

delay(1000);
int val = sensorValue;
val = map(val,zero,oneeighty,0,180);

// the dial is reversed for what we want so we
// reverse the value to get the angle
//val = 180 - val;
myservo.write(val); // use converted angle
Serial.println(val);
}




// A101_ch7_pot_motion_control 5/7/14 Joe Pardue

#include <Servo.h>

Servo myservo; // create servo object to control a servo
int sensorPin = A0; // analog input pin
int zero = 0; // calibration reading for 0 degree
int oneeighty = 0; // calibrartion reading for 180 degree

void setup() {
// attaches the servo on pin 9 to the servo
myservo.attach(9);

Serial.begin(57600);
Serial.println("Pot motion control rev 1.0");
}

void loop() {
int val;

if(Serial.available())
{
char c = Serial.read();

if(c == 'a') // get the zero degree calibration value
{
// read the value from the sensor:
zero = analogRead(sensorPin);
Serial.print("You set 0 degree to: ");
Serial.println(zero);
}
if(c == 'b') // get the 180 degree calibration value
{
// read the value from the sensor:
oneeighty = analogRead(sensorPin);
Serial.print("You set 180 degree to: ");
Serial.println(oneeighty);
}
}
delay(100);
val = analogRead(sensorPin);;
val = map(val,zero,oneeighty,0,180);

// the dial is reversed for what we want so we
// reverse the value to get the angle
val = 180 - val;
myservo.write(val); // use converted angle
}

frank_fg
Posts: 41
Joined: Tue Apr 29, 2008 9:07 am
Contact:

Re: Ardunio Class 101 chapter 7, Lab's 3 & 4, Controlling se

Post by frank_fg » Thu Jul 03, 2014 10:31 am

:smile:

Am at a lost!

Ardunio cloassroom 101 chpter 7 Lab 2,3,4

Lab 2 works fine

Labs 2 and 4 don't.
Just copyed and pasted the files you sent in.

I got the same error's as before.

Nothing is highlighted as an error yet at the bottom window all kinds of errors.

what is happening her?

error reads as follows:

Adunio/Libraries/Servo/Servo.cpp:
In function 'void handle_interrupts(timer16_Sequnce_t, volatile uint16t*, volatile uint16_t*:
81: error'LOW' was not declard in this scope
81: error 'digitalWrite' was not declard in this scope

And it goes on and on.


Thanks
Frank G.

User avatar
joepardue
Posts: 51
Joined: Sun Jul 31, 2011 7:44 am
Contact:

Re: Ardunio Class 101 chapter 7, Lab's 3 & 4, Controlling se

Post by joepardue » Thu Jul 03, 2014 12:12 pm

This indicates that there is a problem with the servo library, not the program I've shown. That likely means that the servo library has not been installed properly or there is some sort of change in the way it is used between Arduino IDE editions. I'm using 1.0.5 so if you are using an earlier version please install this version and see if it works. Also I saw a forum comment where somebody had to remove the #include <Servo.h> to get it working. You might try that. If neither of these work then please post the first 10 lines of the error output and I'll see what I can figure out.

Joe

frank_fg
Posts: 41
Joined: Tue Apr 29, 2008 9:07 am
Contact:

Re: Ardunio Class 101 chapter 7, Lab's 3 & 4, Controlling se

Post by frank_fg » Thu Jul 03, 2014 4:36 pm

:smile:

Hi!

I believe you may be right on, I am currently having big problems with libraries from Adafruit-Ardunio.

I have Ver 1.0.5-r2

I have run servos from your programs and mind with no problems.
But I'll do as you suggested.

Thanks
Frank G.

frank_fg
Posts: 41
Joined: Tue Apr 29, 2008 9:07 am
Contact:

Re: Ardunio Class 101 chapter 7, Lab's 3 & 4, Controlling se

Post by frank_fg » Thu Jul 03, 2014 4:56 pm

:smile:

Hi!

I just compiled chapter 7 Lab 3 Pot Angle again,

this is what I got

if(c == 'b')
{
//read the value from the sensor
oneeighty = analogRead(sensorPin);
volatileuint16_t** ** this pop up???


this is a clue

Thank
Frank G.

User avatar
joepardue
Posts: 51
Joined: Sun Jul 31, 2011 7:44 am
Contact:

Re: Ardunio Class 101 chapter 7, Lab's 3 & 4, Controlling se

Post by joepardue » Thu Jul 03, 2014 8:15 pm

Well that is puzzling. The code:
volatileuint16_t** **
Isn't in my stuff so it is probably something from the Servo library that isn't being used properly somewhere deep under the hood.

Maybe you can get an earlier version of the Arduino IDE like 1.0.1 and see if it runs on that?

I know this is frustrating, but I can't duplicate the problem on this end so I can only offer guesses.

Joe

frank_fg
Posts: 41
Joined: Tue Apr 29, 2008 9:07 am
Contact:

Re: Ardunio Class 101 chapter 7, Lab's 3 & 4, Controlling se

Post by frank_fg » Fri Jul 04, 2014 4:25 pm

:smile:

Hi! Joe

Ardunio Classrom 101 chapter 7 Lab3

I had to switch computers, it seems that the one I was using was corrupt.

Now Lab's 2,3,and 4 are compiling good. angle rev 1.0

Sorry but there is a But in what I going to say.

Lab3 works to a point/;

On the serial monitor I get the following:

Measure potentiometer angle rev 1.0
is
1) then I enter 'a' after setting the pot to zero
my reading: you set 0 degree to:
0
********************************
I am missing the reading on the right of to:
a
2) then I enter 'b' after setting the pot to max pos.
my reading: you set 180 degree to:
-1
*****************************************
again I am missing the reading on the right.
***********************************

I had used a 50 k pot, so I change it to 10 k

now I get the following:

you set 0 degree to: 10
-1
and
you set 180 degree to: 1023
-1
************************

what is happening?
The first thing I get is
Measure potentiometer angle rev 1.0 ;good
then after a long space I get
you set 0 degree to: ;good
I don't get: Potentiometer voltage:
and Angle

Thanks
Frank G.

frank_fg
Posts: 41
Joined: Tue Apr 29, 2008 9:07 am
Contact:

Re: Ardunio Class 101 chapter 7, Lab's 3 & 4, Controlling se

Post by frank_fg » Fri Jul 04, 2014 5:19 pm

:smile:
Hi! Joe

A little improvement on Lab3

The large spaces between Measure potentiometer angle rev 1.0 and you set 0 degree to: are gone.

But not getting 'Potentiometer voltage' yet
and the 'Angle = xx' is also missing.

Thanks
Frank G.

User avatar
joepardue
Posts: 51
Joined: Sun Jul 31, 2011 7:44 am
Contact:

Re: Ardunio Class 101 chapter 7, Lab's 3 & 4, Controlling se

Post by joepardue » Sat Jul 05, 2014 4:51 am

Did you copy this directly from the source code or did you input the code yourself?
If you input it yourself, could you post it here so I can have a look?

Joe

frank_fg
Posts: 41
Joined: Tue Apr 29, 2008 9:07 am
Contact:

Re: Ardunio Class 101 chapter 7, Lab's 3 & 4, Controlling se

Post by frank_fg » Sat Jul 05, 2014 4:52 pm

:smile:

Hi! Joe

I downloaded from Nuts & volts.

I have a question on the serial monitor.

On some of your programs it seems to work find and on others it won't.

By that I mean, its scroll down slowly and other time its scrolls fast.

Is there way to control it?

Thanks
Frank G.

User avatar
joepardue
Posts: 51
Joined: Sun Jul 31, 2011 7:44 am
Contact:

Re: Ardunio Class 101 chapter 7, Lab's 3 & 4, Controlling se

Post by joepardue » Sat Jul 05, 2014 8:13 pm

Its probably related to the delay() function or possibly your computer is running other processes in the background?

Which program runs slow and which fast?

Joe

frank_fg
Posts: 41
Joined: Tue Apr 29, 2008 9:07 am
Contact:

Re: Ardunio Class 101 chapter 7, Lab's 3 & 4, Controlling se

Post by frank_fg » Sun Jul 06, 2014 4:21 pm

:smile:

Hi!

A101_chp6_Lab 1 servo velocity is great, but backwards.
can it be made to run the right way, at some point?

A101_chp7_Lab3 Pot voltage is also great but backward and that is ok for now.

At some point could I bring it back to say normal?

I want to make a servo tester panel.

I assume that this will also run a 360 degree servo?


Joe! I would like to ask you a question.

I have done a lot of building and testing and some programming too, more like copying someone else
program.

I want to build something real nice, that will be useful and versatile, that will put all that we have learned.

Can you come up with something?

Thanks

Frank G.

User avatar
joepardue
Posts: 51
Joined: Sun Jul 31, 2011 7:44 am
Contact:

Re: Ardunio Class 101 chapter 7, Lab's 3 & 4, Controlling se

Post by joepardue » Sun Jul 06, 2014 5:26 pm

I commented out the reversing code in lab 3!

In lab 3 I have:
//val = 180 - val;
myservo.write(val); // use converted angle

Remove the // so that it reads:
val = 180 - val;
myservo.write(val); // use converted angle

As far as a nice project - how about that servo tester you mentioned? Wouldn't that be a useful project for folks using servos?

Joe

Post Reply

Who is online

Users browsing this forum: No registered users and 11 guests