Show Posts
|
|
Pages: 1 ... 16 17 [18] 19
|
|
257
|
Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Stepper motor using Arduino
|
on: January 20, 2011, 05:22:52 pm
|
|
I would suggest the easiest and fastest route to your goal would be an Easydriver board board available from Sparkfun. It is for small motors (.75A per coil) but it is well documented on various sites. Sparkfun also sells a small motor that works well with it. A larger motor would require a driver with more capacity like some inexpensive ones by Pololu. The Playground section of this site has plenty of info to get you started.
|
|
|
|
|
259
|
Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Never programmed before. Can Arduino be a hobby?
|
on: January 05, 2011, 03:26:34 pm
|
|
Welcome to the forum Pman! Yes, it can be a great hobby. I've had my Arduino for just a few months and came to it with practically no programming experience (just a little Basic back in the Commodore64 days). Just start with the easy blinking led stuff and work your way up. It can be a bit frustrating at first but once you're over the initial "hump" it starts making more sense and the learning comes more quickly. I got a lot from LadyAda's tutorials. To start I just got a breadboard some resistors and led's as well as a cheap multimeter and that kept me going for quite a while until I learned what else I needed. Good luck!
|
|
|
|
|
261
|
Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Hey im thinking of buying my first Arduino.
|
on: December 22, 2010, 09:41:55 pm
|
Welcome Darrion! To get started you will need an Arduino board, a computer and lots of time and patience unless you already have a strong programming background. You will also need a prototyping board, a few electronic components such as resistors and LED's. Once you feel comfortable with the basics of flashing LED's etc. you will want to obtain a motor control board and motors if you want to control cars. I would reccomend Adafruit Industries http://www.adafruit.com/ or Sparkfun http://www.sparkfun.comas a good source both for hardware and tutorials. Read all you can and ask questions on the forums. Just be aware that all this takes time and effort and your goal of using a Wiimote to control a car will be some ways in the future. I got into using the Arduino about 3 months ago with the goal of creating a simple linear positioning system and I'm now only about halfway there but I've learned a great deal in the process. The learning curve can be frustrating at times but when you get something working it feels really great! Good luck to you.
|
|
|
|
|
265
|
Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: How to enter numerical data?
|
on: October 29, 2010, 02:43:12 pm
|
Well, I worked hard all week and finally got my sketch to do what I want. Many thanks to Korman. I'm sure it could be done in a more elegant manner and would appreciate if any of you could take the time to look at it and critique it for me. /*This sketch reads a numbers from a 4x4 matrix keypad using either decimal or fractional entry and returns a value in thousandths of an inch. */
#include <Keypad.h>
const byte ROWS = 4; //four rows const byte COLS = 4; //four columns char keys[ROWS][COLS] = { {'7','8','9','A'}, {'4','5','6','B'}, {'1','2','3','C'}, {'0','.','e','/'}, }; byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad byte colPins[COLS] = {9, 8, 7, 6,}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS ); long value = 0; //value in thousandths of an inch int dec_switch = 0; //0=integer entry, 1=decimal entry, 2=fractional entry int dec_place = 0; //tracks decimal place int frac_switch = 0; //switches to fraction mode int numerator; //numerator value int denominator; //denominator value float frac_value; //calculated decimal value of fraction
void setup(){ Serial.begin(9600); }
void loop(){ char key = keypad.getKey(); //read keypad switch (key){ case NO_KEY: // No key read. Do nothing break;
case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': //Serial.print (key); if (frac_switch == 1){ //prints and evaluates numerator numerator = numerator * 10 + key - '0'; //prints and evaluates denominator Serial.print (key); } if (frac_switch == 2){ //prints and evaluates denominator denominator = denominator * 10 + key - '0'; Serial.print (key); } if ( dec_switch == 0 ){ //prints and evaluates integer value = value * 10 + key - '0'; Serial.print (key); } else if ( dec_switch == 1 && dec_place < 3){ //prints and evaluates decimal value = value * 10 + key - '0'; dec_place = dec_place + 1; Serial.print (key); } else if (dec_switch == 1 && dec_place == 3) { //prevents entering extra decimal places Serial.println (); Serial.print ("Entry complete. Press Enter"); } break;
case 'e': // Enter key if (frac_switch == 1){ //multiplier for fractional value value = value * 1000; }
if (frac_switch == 0 && dec_place == 0){ Serial.print (".000"); //prints decimal placeholder value = value * 1000; //multiplier for integer only decimal value } else if (frac_switch == 0 && dec_place == 1){ Serial.print ("00"); //prints decimal placeholder value = value * 100; //multiplier for decimal place } else if (frac_switch == 0 && dec_place == 2){ Serial.print ("0"); //prints decimal placeholder value = value * 10; //multiplier for decimal place } if (frac_switch == 2) { frac_value = (float)numerator/denominator; //calculates value of fraction value = (value + frac_value) * 1000; //multiplier for decimal place } Serial.println (); Serial.print ("The current value is: "); Serial.print (value); Serial.print (" thousandths."); Serial.println (); //Serial.println (numerator); //Serial.println (denominator); //Serial.print (frac_value); //Serial.println ();
// Reset values. The last number is done value = 0; dec_switch = 0; dec_place = 0; frac_switch = 0; numerator = 0; denominator = 0; frac_value = 0; break; case '.': dec_switch = 1; //switches to decimal mode Serial.print ("."); //prints decimal point break; case '/': if (frac_switch == 0){ Serial.print ("-"); frac_switch = 1; dec_switch = 2; } else if (frac_switch == 1){ Serial.print ("/"); frac_switch = 2; } break;
default: // All other keys Serial.println (); Serial.print ("Criminy! Don't press key '"); Serial.print (key); Serial.println ("'! Another "); Serial.print (value); Serial.println (" puppies died in China.");
// Reset value. The last number is done value = 0; } }
While I'm waiting for my LCD display to arrive I will work on some routines to prevent entry of invalid data but I would like to make sure I've got the basic sketch in its best form first. Thanks again. Greg
|
|
|
|
|
266
|
Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: How to enter numerical data?
|
on: October 25, 2010, 10:48:01 am
|
|
Thank you Korman. I'm not sure that completely answers my question but it gives me a new approach to the problem (I've never used the "case/break" function before). Now I will have to ponder this and move on to the next step which will be to add the decimal portion of the value.
Best regards, Greg
|
|
|
|
|
267
|
Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: How to enter numerical data?
|
on: October 24, 2010, 10:14:38 pm
|
|
I'm totally confounded! I keep looking at it but can't understand why "key" would not be a different value each time through the loop. If I describe how I see the logic perhaps someone could point out my erroneous thinking. Bear with me. When a key is hit the variable "key" is set to that key. The "if" statement tests to see that "key" is not an unpressed key nor an "e" We then serial.print "key" (up to this point everything works fine) let's say the first key entered is 2 1st loop: i=0, key=2 so value=value*2+key=0+2 2nd loop: i=1, key=3, so value=value*10+key=20+3=23 3rd loop: i=2, key=4, so value=value*10 +key=23+4=234 I hit "e" and and expect to print 234 but instead I print 11211.
Obviously I don't understand the logic. :-X
|
|
|
|
|
269
|
Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: How to enter numerical data?
|
on: October 24, 2010, 10:55:49 am
|
OK. I've finally found some time to play with this and here is what I have so far (using Korman's code snippet): #include <Keypad.h>
const byte ROWS = 4; //four rows const byte COLS = 4; //four columns char keys[ROWS][COLS] = { {'7','8','9','A'}, {'4','5','6','B'}, {'1','2','3','C'}, {'0','.','e','D'}, }; byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad byte colPins[COLS] = {9, 8, 7, 6,}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS ); int value = 0;
void setup(){ Serial.begin(9600); }
void loop(){ char key = keypad.getKey(); if (key != NO_KEY && key != 'e') Serial.print (key); //prints input digit { for (int i = 3; i != 0; i--) { //shifts digits to left value = value * 10 + key; } if (key == 'e'){ //prints value Serial.println (); Serial.print (value); Serial.println ();} } } It displays the digits as I type them but when I hit "e" I get a result of '11211' no matter what was entered previously.
|
|
|
|
|