PDA

Επιστροφή στο Forum : AZIMUT AND ELEVATION με ΑtMega 328P



jimnaf
10-11-12, 01:37
Ήθελα να κατασκευάσω έναν ροτορα για την κεραία μου.
Είχα κολλήσει με την ένδειξη.

Έμπλεξα με αναλογικά όργανα και αρκετά εξαρτήματα μέχρι που είπα να δω αν
υπάρχει τίποτα σε μικροελεγκτή αλλα τζιφος .

Μια και πρόσφατα είχα πάρει το arduino Uno χωρίς να έχω ασχοληθεί μαζί του, εκτός από το led
που το έκανα να ανάβει και να σβήνει, ανακάτεψα κάτι προσράμματα που βρήκα για ποτενσιόμετρα ,
διάφορα άλλα και δικά μου …… νομίζω ότι κάτι κατάφερα.
Επειδή όσο και να έψαξα δεν βρήκα κάτι που να είναι σχετικά απλό κάποιοι εδώ μέσα πιο ειδικοί μπορεί να το κάνουν καλύτερο.
38873
Αντιγράψτε και επικολλήστε μέσα στην εφαρμογή του ARDUINO



/* hey, this is a simple code to make your arduino read
the value of a potentiometer and display it in percentage form on
a 16 X 2 LCD screen. I am pretty new at this so sorry if this code
is terrible or if i have no idea what i'm talking about in the
comments.

the circuit(pasted from examples):

* LCD RS pin to digital pin 12
* LCD Enable pin to digital pin 11
* LCD D4 pin to digital pin 5
* LCD D5 pin to digital pin 4
* LCD D6 pin to digital pin 3
* LCD D7 pin to digital pin 2
* LCD R/W pin to ground
* 10K resistor:
* ends to +5V and ground
* wiper to LCD VO pin (pin 3)
* Potentiometer attached to analog input 0
* Potentiometer attached to analog input 1

* center pin of the potentiometer to the analog pin
* one side pin (either one) to ground
* the other side pin to +5V

*/
#include <LiquidCrystal.h> // include the LCD library
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

int potPin = A0; //Potentiometer input pin
int potValue1 = 0;
int potValue2 = 0; // final display variable
int poLPin = A1; //Potentiometer input pin
int poLValue3 = 0;
int poLValue4 = 0; // final display variable
void setup() {
lcd.begin(16, 2); // lcd rows and columns
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("Rotor Controller");
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print(" NAME ");
delay(5500);
lcd.clear();
}

void loop() {
// read then divide the input(max 1020 in this case) by 10
potValue1 = analogRead(potPin) / 1.87;
// divide by 1.02 to get percentage
potValue2 = potValue1 / 1;
// set cursor to second row, first column
lcd.setCursor(0, 0);
//display final percentage
lcd.print(potValue2);
//print the percent symbol at the end
lcd.print((char)223);
lcd.print(" Azimuth");

// read then divide the input(max 1020 in this case) by 10
poLValue3 = analogRead(poLPin) / 7.48;
// divide by 1.02 to get percentage
poLValue4 = poLValue3 / 1;
// set cursor to second row, first column
lcd.setCursor(0, 1);
//display final percentage
lcd.print(poLValue4);
//print the percent symbol at the end
lcd.print((char)223);
lcd.print(" Elevation");
//wait 0.1 seconds
delay(100);
//wipe the extra characters
lcd.print(" ");
delay(1);
}

nikknikk4
16-11-12, 00:38
πρόσθεση trimer & πυκνωτών

39036

jimnaf
17-11-12, 00:44
Δεν είναι απαραίτητα τα τριμερ γιατί στις γραμμές που έχω με ΧΧΧΧ φορτώνεις το πρόγραμμα και βάζεις όχι αυτό που έχω εγώ,
αλλά την μονάδα 1 (potValue1 = analogRead(potPin) / 1; )
Τρέχεις το πρόγραμμα και περιστρέφεις πλήρως το ποτενσιόμετρο από την αρχή αριστερά μέχρι τέρμα δεξιά.

Αυτό σημαίνει ότι το ποτενσιόμετρο θα σου δώσει μια ένδειξη ας πούμε από 0 έως 650 στο lcd.
Αυτό το διαιρείς με τις μοίρες EL που θες πχ 650/360= 1,805
Οπότε στην γραμμή βάζεις potValue1 = analogRead(potPin) / 1.805;

Το ίδιο και πιο κάτω AZ (ανάλογα το ποτενσιόμετρο, τα δικά μου είναι 5ΚΩ 10στροφων)
Βάζεις 650/90= 7,22 poLValue3 = analogRead(poLPin) / 7.22;
Δεν χάνεις βέβαια τίποτα να τα βάλεις αφού θα σε γλυτώσεις από επαναπρογραμματισμό σε περίπτωση που αλλάξει
κάτι στα ποτενσιόμετρα ( κρύο, ζέστη , υγρασία)!!!!!!!

Ένα προβληματάκι που έχω είναι ότι όταν ο αριθμός AZ γίνει 3ψηφιος πχ από 95 μοίρες πάει 110 μετακινεί την
λέξη Azimuthμια θέση δεξιά, υπάρχει κάποιο κολπάκι για σταθεροποίηση;

void loop() {
// read then divide the input(max 1020 in this case) by 10
potValue1 = analogRead(potPin) / 1.87; XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// divide by 1.02 to get percentage
potValue2 = potValue1 / 1;
// set cursor to second row, first column
lcd.setCursor(0, 0);
//display final percentage
lcd.print(potValue2);
//print the percent symbol at the end
lcd.print((char)223);
lcd.print(" Azimuth");

// read then divide the input(max 1020 in this case) by 10
poLValue3 = analogRead(poLPin) / 7.48; XXXXXXXXXXXXXXXXXXXXXXXXXX
// divide by 1.02 to get percentage
poLValue4 = poLValue3 / 1;
// set cursor to second row, first column
lcd.setCursor(0, 1);
//display final percentage
lcd.print(poLValue4);
//print the percent symbol at the end
lcd.print((char)223);
lcd.print(" Elevation");
//wait 0.1 seconds
delay(100);
//wipe the extra characters
lcd.print(" ");
delay(1);
}

manolena
17-11-12, 01:18
Ένα προβληματάκι που έχω είναι ότι όταν ο αριθμός AZγίνει 3ψηφιος πχ από 95 μοίρες πάει 110 μετακινεί την
λέξη Azimuthμια θέση δεξιά, υπάρχει κάποιο κολπάκι για σταθεροποίηση;



Για να λύσεις αυτό το πρόβλημα, απλά κάνε το εξής (σου γράφω δίπλα απο τον κώδικά σου):


void loop() {
// read then divide the input(max 1020 in this case) by 10
potValue1 = analogRead(potPin) / 1.87; XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// divide by 1.02 to get percentage
potValue2 = potValue1 / 1;

if(potValue2<10)
{
lcd.setCursor(0,0);
lcd.print("00");
lcd.print(potValue2);
}
else if((potValue2>9) && (potValue2<100))
{
lcd.setCursor(0,0);
lcd.print("0");
lcd.print(potValue2);
}
else if(potValue2>99)
{
lcd.setCursor(0,0);
lcd.print(potValue2);

//Ομοίως και για την επόμενη μεταβλητή στη δεύτερη γραμμή...

//print the percent symbol at the end
lcd.print((char)223);
lcd.print(" Azimuth");

// read then divide the input(max 1020 in this case) by 10
poLValue3 = analogRead(poLPin) / 7.48; XXXXXXXXXXXXXXXXXXXXXXXXXX
// divide by 1.02 to get percentage
poLValue4 = poLValue3 / 1;
// set cursor to second row, first column
lcd.setCursor(0, 1);
//display final percentage
lcd.print(poLValue4);
//print the percent symbol at the end
lcd.print((char)223);
lcd.print(" Elevation");
//wait 0.1 seconds
delay(100);
//wipe the extra characters
lcd.print(" ");
delay(1);
}

Αν δεν θες να φαίνονται τα μηδενικά των δεκάδων ή εκατοντάδων (001 ή 035 π.χ.), απλά στην εντολή
lcd.print("00"); βάλε lcd.print(" ");

και lcd.print("0"); ------> lcd.print(" ");

manolena
17-11-12, 01:32
Το επόμενο βήμα τώρα είναι, απο ό,τι φαντάζομαι, να δώσεις 2 PWM εξόδους σε κινητήρες με τις τιμές στις μεταβλητές ανύψωσης και αζιμουθίου...

jimnaf
17-11-12, 01:33
ΕΥΧΑΡΙΣΤΩ ΜΑΝΟ !!!! :ok:

jimnaf
17-11-12, 01:35
Το επόμενο βήμα τώρα είναι, απο ό,τι φαντάζομαι, να δώσεις 2 PWM εξόδους σε κινητήρες με τις τιμές στις μεταβλητές ανύψωσης και αζιμουθίου...

ΩΠΑ ΩΠΑ με το μαλακό καθωτι γέρος, για λεγε για λεγε !!!

manolena
17-11-12, 01:43
Λέω, οτι μπορείς να οδηγείς δύο σερβοκινητηράκια, ένα για ανύψωση και ένα για αζιμούθιο, που θα σου κινούν την κεραία ακριβώς εκεί
που θές, οδηγώντας τους με την τιμή στις δύο μεταβλητές σου. Ταυτόχρονα, θα έχεις και την ένδειξη των μοιρών στην οθόνη.
Μπορείς να να κατεβάσεις τη σχετική βιβλιοθήκη απο εδώ:

http://arduino.cc/playground/uploads/ComponentLib/SoftwareServo.zip

να διαβάσεις το παράδειγμα, να βρείς δυο μικρά servo απο κανένα παλιό R/C μοντέλο και να παίξεις.
Για να γίνει όμως αυτό σε κανονική κλίμακα, έχε υπ' όψιν σου οτι θέλει καλή μηχανική κατασκευή.

nikknikk4
17-11-12, 02:08
manolena (http://www.hlektronika.gr/forum/member.php?u=32718) μπορείς να ανεβάσεις ολο τον κώδικα μαζι με την δική σου διόρθωση γιατι μου βγάζει κάποιο λάθος ετσι οπως το κάνω εγω

manolena
17-11-12, 02:28
manolena (http://www.hlektronika.gr/forum/member.php?u=32718) μπορείς να ανεβάσεις ολο τον κώδικα μαζι με την δική σου διόρθωση γιατι μου βγάζει κάποιο λάθος ετσι οπως το κάνω εγω



/* hey, this is a simple code to make your arduino read
the value of a potentiometer and display it in percentage form on
a 16 X 2 LCD screen. I am pretty new at this so sorry if this code
is terrible or if i have no idea what i'm talking about in the
comments.

the circuit(pasted from examples):

* LCD RS pin to digital pin 12
* LCD Enable pin to digital pin 11
* LCD D4 pin to digital pin 5
* LCD D5 pin to digital pin 4
* LCD D6 pin to digital pin 3
* LCD D7 pin to digital pin 2
* LCD R/W pin to ground
* 10K resistor:
* ends to +5V and ground
* wiper to LCD VO pin (pin 3)
* Potentiometer attached to analog input 0
* Potentiometer attached to analog input 1

* center pin of the potentiometer to the analog pin
* one side pin (either one) to ground
* the other side pin to +5V

*/
#include <LiquidCrystal.h> // include the LCD library
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

int potPin = A0; //Potentiometer input pin
int potValue1 = 0;
int potValue2 = 0; // final display variable
int poLPin = A1; //Potentiometer input pin
int poLValue3 = 0;
int poLValue4 = 0; // final display variable
void setup() {
lcd.begin(16, 2); // lcd rows and columns
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);

// Print a message to the LCD.
lcd.print("Rotor Controller");
delay(5500);
lcd.clear();
}

void loop() {
// read then divide the input(max 1020 in this case) by 10
potValue1 = analogRead(potPin) / 1.87;
// divide by 1.02 to get percentage
potValue2 = potValue1 / 1;

if(potValue2<10)
{
lcd.setCursor(0,0);
lcd.print("00");
lcd.print(potValue2);
}
else if((potValue2>9) && (potValue2<100))
{
lcd.setCursor(0,0);
lcd.print("0");
lcd.print(potValue2);
}
else if(potValue2>99)
{
lcd.setCursor(0,0);
lcd.print(potValue2);

//print the percent symbol at the end
lcd.print((char)223);
lcd.print(" Azimuth");

// read then divide the input(max 1020 in this case) by 10
poLValue3 = analogRead(poLPin) / 7.48;
// divide by 1.02 to get percentage
poLValue4 = poLValue3 / 1;
// set cursor to second row, first column

if(potValue4<10)
{
lcd.setCursor(0,1);
lcd.print("00");
lcd.print(potValue4);
}
else if((potValue4>9) && (potValue4<100))
{
lcd.setCursor(0,1);
lcd.print("0");
lcd.print(potValue4);
}
else if(potValue4>99)
{
lcd.setCursor(0,1);
lcd.print(potValue4);

//print the percent symbol at the end
lcd.print((char)223);
lcd.print(" Elevation");
//wait 0.1 seconds
delay(100);
//wipe the extra characters
lcd.print(" ");
delay(1);
}

nikknikk4
17-11-12, 02:56
αμεση απάντηση αψογος:thumbup:
αλλα ισως κάτι δεν κάνω σωστά και μου βγάζει αυτό
39078

manolena
17-11-12, 03:01
Δεν το μελέτησα καθόλου για να είμαι ειλικρινής, διορθώνω, σε 5'

manolena
17-11-12, 03:14
/* hey, this is a simple code to make your arduino read
the value of a potentiometer and display it in percentage form on
a 16 X 2 LCD screen. I am pretty new at this so sorry if this code
is terrible or if i have no idea what i'm talking about in the
comments.


the circuit(pasted from examples):


* LCD RS pin to digital pin 12
* LCD Enable pin to digital pin 11
* LCD D4 pin to digital pin 5
* LCD D5 pin to digital pin 4
* LCD D6 pin to digital pin 3
* LCD D7 pin to digital pin 2
* LCD R/W pin to ground
* 10K resistor:
* ends to +5V and ground
* wiper to LCD VO pin (pin 3)
* Potentiometer attached to analog input 0
* Potentiometer attached to analog input 1


* center pin of the potentiometer to the analog pin
* one side pin (either one) to ground
* the other side pin to +5V


*/
//================================================== =====================INCLUDES
#include <LiquidCrystal.h> // include the LCD library


//================================================== =====================DEVICE SETUP
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
//================================================== =====================VARIABLES
int potPin = A0; //Potentiometer input pin
int potValue1 = 0;
int potValue2 = 0; // final display variable
int poLPin = A1; //Potentiometer input pin
int poLValue3 = 0;
int poLValue4 = 0; // final display variable


//================================================== =====================SETUP
void setup()
{
lcd.begin(16, 2); // lcd rows and columns
// set up the LCD's number of columns and rows:
// Print a message to the LCD.
lcd.print("Rotor Controller");
delay(5500);
lcd.clear();
}
//================================================== =====================MAIN LOOP
void loop()
{
// read then divide the input(max 1020 in this case) by 10
potValue1 = analogRead(potPin) / 1.87;
// divide by 1.02 to get percentage
potValue2 = potValue1 / 1;

if(potValue2<10)
{
lcd.setCursor(0,0);
lcd.print("00");
lcd.print(potValue2);
}
else if((potValue2>9) && (potValue2<100))
{
lcd.setCursor(0,0);
lcd.print("0");
lcd.print(potValue2);
}
else if(potValue2>99)
{
lcd.setCursor(0,0);
lcd.print(potValue2);
}
//print the percent symbol at the end
lcd.print((char)223);
lcd.print(" Azimuth");
//================================================== =====================
// read then divide the input(max 1020 in this case) by 10
poLValue3 = analogRead(poLPin) / 7.48;
// divide by 1.02 to get percentage
poLValue4 = poLValue3 / 1;
// set cursor to second row, first column

if(poLValue4<10)
{
lcd.setCursor(0,1);
lcd.print("00");
lcd.print(poLValue4);
}
else if((poLValue4>9) && (poLValue4<100))
{
lcd.setCursor(0,1);
lcd.print("0");
lcd.print(poLValue4);
}
else if(poLValue4>99)
{
lcd.setCursor(0,1);
lcd.print(poLValue4);
}
//print the percent symbol at the end
lcd.print((char)223);
lcd.print(" Elevation");
//wait 0.1 seconds
delay(100);
//wipe the extra characters
lcd.print(" ");
delay(1);
}


Τώρα είσαι ΟΚ, χτίζεται κανονικά.

nikknikk4
17-11-12, 03:36
. 39079.

nikknikk4
17-11-12, 03:49
αυτο με τα servo νομιζω οτι θα μπορούσε να γίνει και με τα ποτενσιόμετρα και τον ηδη υπάρχων κινητήρα (μοτέρ) τι λες