Let's Make Robots!

Arduino Diecimila Questions

http://www.arduino.cc/en/Main/ArduinoBoardDiecimila

ArduinoDiecimila400.jpg

which ports can support servo control? and where are they located?

I'm getting one leter this week, and I have absolutely no idea how it works.

 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Benbo231's picture

it would be a lot easier to insert it wherever i needed. starting to get it now...

now all i need is the Arduino itself! gui mailed it to me a buncha days ago

Thanks for all your help!

TeleFox's picture

The curly brackets denote a block of code that is tied together, ie: everything inside the { stuff } brackets after void loop() is the block of code that will be executed every time the loop() function is called. The code inside { and } after the 'for' command is the code that will be executed every time the for loop is run.

Libraries are pieces of code that can be reused easily; adding a library is like copying and pasting that code into your own, but it's tidier and more convenient (like if you update the library, all the programs that use that library will automatically use the updated copy).
Libraries are often used to provide pre-built commands to do something like, say, perform a certain set of calculations, or to control a particular type of servo, or something like that.

Benbo231's picture

and the { and} specify a certain loop in the program right? like if i had a few of the above program, it would do one, then move on to the next, then...

the variable thing is the same deal in basic. sorta. you give it a type, bit, byte or word...

now what about libraries? what purpose do they serve?

ezekiel181's picture

Yeah {} circle loops and if statements plus some others, switch etc. I like to keep them on their own lines so I can match them in pairs easily.

I answered the libraries thing up further. Look inside the \arduino-0015\hardware\libraries directory for all the libraries that come with the default install. Look inside the servo library folder and open servo.h in a text editor. All those commands in "private" are only used inside the actual library, but the ones underneath "public" you can use in your program. If you open servo.cpp this is the guts of the library. All the actual code. 

TeleFox's picture

You don't use angles for a continuous rotation modded servo, what used to be the angle value now sets the speed of rotation. If you told the servo to go to 'angle' 180°, it would run maximum speed in one direction, while 'angle' 0° would make it run maximum speed in the other direction. 90° would make the servo stop completely, and all the other angles between 0° and 180° would make the servo run forward or backward at a speed less than maximum.
If you used the code you posted above for a modded servo, the servo would run one way at full speed, gradually slow down and eventually reverse until it was running full speed the opposite way (for one loop).

Benbo231's picture

void loop() {
  // cycle through every angle (rotate the servo 180 slowly)
  for (myAngle=0; myAngle<=180; myAngle++) { 
    servoPulse(9, myAngle);

}
  delay(1000);
}

 

What this does is...

for (myangle...) it tells a non continuous rotation servo what to do anglewise.

then it pulses the servo through that arc, pulsing once every second. but how would i apply these angles to a continuous rotation servo? stop pretending, cuz i am an idiot at this

ezekiel181's picture

That looks pretty good! You should put a delay inside the loop like below otherwise your for loop will go through as fast as the processor can manage a servo output command.

void loop()
{
  // cycle through every angle (rotate the servo 180 slowly)
  for (int myAngle=0; myAngle<=180; myAngle++)
  {
     servoPulse(9, myAngle);
     delay(10);
  }
  delay(1000);

In C you need to initialize variables before using them by giving them a type. int myAngle says myAngle is a new variable of integer type. for(int myAngle =0...) works fine and makes myAngle a local variable... local to only that specific for loop. That way when the for loop is finished, the variable is destroyed and that memory is free for somewhere else. You CAN make myAngle global though by putting int myAngle; right at the top of your program. That way it keeps its value even after the loop is done, but if you aren`t gonna use it outside the loop it`s a bit of a waste.

 

guibot's picture

If you have no idea how to work with Arduino, I suggest to take a look into these tutorials, I started with them and even today they are very usefull. You will have everything very well explained, starting by blinking an LED, to work with buttons, potenciometers, servos, motors, and so on   ;)

http://todbot.com/blog/bionicarduino/

http://todbot.com/blog/spookyarduino/

Benbo231's picture

i thought i could program the ard. straight out of the box! pretend im an idiot and explain this to me in moron terms

also, what do libraries do?

ezekiel181's picture

Yeah you can with the Arduino because it has a bootloader. Just plug in the USB cable and upload the program from the Arduino software.

But if you want to make something permanent, you can pull the chip out of the board and put it on your own diy board, then buy more blank chips for $4 each to put back in the Arduino board. With the above link you can turn the blank chip into an Arduino chip using only the arduino board and some cables. It`s the same principle as turning a plain PIC into a picaxe chip.

Oh, libraries are ways of sharing code easily. Also they tidy up programs by hiding the stuff you don`t need to see. For an ultrasound sensor, instead of putting 10 lines of code in the main program you could put it in a library. Then when you make your 2nd 3rd 4th etc bots with the same ultrasound sensor you can import the same library.