Uwaga: Na forum proszę rejestrować się pełnym znakiem, inne nicki będą blokowane. Następnie należy się przedstawić pisząc kilka słów o sobie, swoich zainteresowaniach...

NOWE POSTY | NOWE TEMATY | POPULARNE | STAT | RSS | KONTAKT | REJESTRACJA | Login: Hasło: rss dla

HOME » ARDUINO » ARDUINO MEGA2560 BASED ANTENNA ROTATOR CONTROLLER

Przejdz do dołu stronyStrona: 1 / 1    strony: [1]

Arduino Mega2560 based Antenna Rotator Controller

  
SP2RXX
14.06.2016 07:25:24
poziom najwyższy i najjaśniejszy :-)



Grupa: Administrator 

Lokalizacja: Bydgoszcz JO83XC

Posty: 7669 #2295659
Od: 2011-6-25


TYLKO ZAREJESTROWANI I ZALOGOWANI UŻYTKOWNICY WIDZĄ ZDJĘCIA. DARMOWA REJESTRACJA





TYLKO ZAREJESTROWANI I ZALOGOWANI UŻYTKOWNICY WIDZĄ ZDJĘCIA. DARMOWA REJESTRACJA



Więcej na:

TYLKO ZAREJESTROWANI I ZALOGOWANI UŻYTKOWNICY WIDZĄ LINKI » DARMOWA REJESTRACJA






_________________
73! Maciej
  
Electra29.03.2024 09:24:16
poziom 5

oczka
  
sp3nyf
14.06.2016 08:16:42
poziom 5



Grupa: Użytkownik

Lokalizacja: Gorzów JO72pr

Posty: 513 #2295684
Od: 2011-7-20
No, nawet interesująca alternatywa do K3NG, tylko z takiej wielkości (a raczej małości) wyświetlaczem, to trochę kłopot...
_________________
Zbyszek SP3NYF
  
sp6ix
14.06.2016 09:58:45
poziom 6

Grupa: Użytkownik

Posty: 833 #2295748
Od: 2011-6-26
Dla mnie wystarczyło by i to w polu ,małe poręczne .Mam pytanie czy mały tablet KENTO by to mógł zastąpić?
  
SP7CKH
14.06.2016 13:23:33
poziom 5



Grupa: Użytkownik

Lokalizacja: JO92QF Kutno

Posty: 406 #2295841
Od: 2011-8-26
Ten program trzeba przepisać ?
Nie widzę możliwości pobrania.
Wyświetlacz jest znośny , tablet się nie nadje.

_________________
Kazik
  
sp6ix
14.06.2016 13:36:43
poziom 6

Grupa: Użytkownik

Posty: 833 #2295844
Od: 2011-6-26
Problem z głowy trzeba wozić sterownik i po bólu.W jakim języku prog. jest to napisane lub czym to skompilować.
  
sp2cnw
14.06.2016 19:44:48
poziom 4

Grupa: Użytkownik

Posty: 322 #2295939
Od: 2011-6-30
Witam!
Tak wygląda program rotora:

#include <Wire.h> //I2C Arduino Library
#include <UTFT.h> // UTFT Library from Henning Karlsen (http://www.rinkydinkelectronics.com/library.php)
#include <UTFT_Geometry.h> //UTFT Geometry Library from Henning Karlsen (http://www.rinkydinkelectronics.com/library.php)
#include <Keypad.h>
#include <EEPROM.h>

const int centreX = 320;
const int centreY = 160;
const int diameter = 130;
const int x_Offset = 30;
const int y_Offset = 128;
const int z_Offset = 0;
const byte rows = 4; // Four rows
const byte cols = 3; // Three columns
const int maxDegreeDigits = 3; //maximum allowed input length
const int fixedInflight = 5;
const long maxInflight = 25;

extern uint8_t BigFont[];
extern uint8_t SmallFont[];
extern uint8_t SevenSegmentFull[];

#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
#define ORANGE 0xFF00
#define address 0x1E //0011110b, I2C 7bit address of HMC5883
#define EEPROM_ModeStatus_Location 10 // The starting address of the EEPROM where the data is Stored (10.11.12.13)
#define EEPROMSetpointLocation 14
#define EEPROM_ScaleMax_Location 18
#define EEPROMInflightLocation 22

struct EEPROMValue //EEPROM Data Structure : Taken from G0MGX DDS VFO Code
{
union{
long Value;
struct
{
unsigned char Byte1;
unsigned char Byte2;
unsigned char Byte3;
unsigned char Byte4;
}
__attribute__((packed));
}
__attribute__((packed));
}
__attribute__((packed));

inline long ReadEEPROMValue(int16_t EEPROMStartAddress); //Reads the values from EEPROM Like Calibration , set Parameters, etc
inline void SaveEEPROMValue(int16_t EEPROMStartAddress, long Value); //Save the Value to EEPROM startingfrom the given StartAddress (4 Bytes of Data)
inline double ReadAngleFromAccelerometer(int x_Offset, int y_Offset);
inline void ResetInputBuffer(void);

// Define the Keymap
char keys[rows][cols] =
{
{
'1','2','3' }
,
{
'4','5','6' }
,
{
'7','8','9' }
,
{
'*','0','#' }
};

boolean UserEntryStarted = false;
boolean UserEntryFinished = true;
boolean InflightEntryStarted = false;
boolean InflightEntryFinished = true;
boolean stopFlag = true;
boolean modeValue = false; // modeValue = false (Manual Mode), modeValue = true (Auto Mode)
boolean inputSelection = false; // false = SetPoint Input , True = inflight input

char KeyEntries[3]; //3 characters to store 0 to 360 Degrees
char dataBuffer[60];
char formattedDataBuffer[3];

int dx;
int dy;
int last_dx;
int last_dy;
int bufPtr = 0;
int CWMotor = 10;
int CCWMotor = 11;
int Stop_ResumeSignal = 12;
int Manual_Auto_Mode = 13;
int ManualSpeedControl = 9;

long UserEntry = 0;
long DegreeInput = 0;
long Inflight = 0;
long storedModeValue = 0;
long scaleMax = 0;

double angle = 0;

//Normal Keyboard Connected To Arduino
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[rows] = {
8, 7, 6, 5 };
// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
byte colPins[cols] = {
4, 3, 2 };

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, rows, cols );

UTFT utftDisplay(ILI9481,38,39,40,41);

#define FormatData(x) strcpy_P(dataBuffer, PSTR(x))

void setup(){
Serial.begin(9600);
utftDisplay.InitLCD();
utftDisplay.InitLCD(LANDSCAPE);
utftDisplay.clrScr();
utftDisplay.setFont(BigFont);
utftDisplay.setColor(255, 0, 0);
utftDisplay.print("ANTENNA ROTATOR ", LEFT, 16);
utftDisplay.print("CONTROLLER ", 40, 40);
utftDisplay.drawLine(440, 160, 460, 160);
utftDisplay.drawLine(180, 160, 200, 160);
utftDisplay.drawLine(320, 20, 320, 40);
utftDisplay.drawLine(320, 280, 320, 300);
utftDisplay.setColor(255, 255, 0);
utftDisplay.print("BEAM DIR", LEFT, 87);
utftDisplay.setFont(SmallFont);
utftDisplay.setColor(255, 100, 100);
utftDisplay.print("SET DIR", LEFT, 210);
utftDisplay.print("INFLIGHT", LEFT, 230);
utftDisplay.setFont(BigFont);
utftDisplay.setColor(255, 0, 0);
utftDisplay.print("O", 95, 115);
utftDisplay.setColor(255, 255, 255);
utftDisplay.print("VU3ESV : VU2JLH",LEFT, 290);
// Initialize I2C communications
Wire.begin();
//Put the HMC5883 IC into the correct operating mode
Wire.beginTransmission(address); //open communication with HMC5883
Wire.write(0x02); //select mode register
Wire.write(0x00); //continuous measurement mode
Wire.endTransmission();
delay(300);
last_dx = centreX;
last_dy = centreY;

DegreeInput = ReadEEPROMValue(EEPROMSetpointLocation);
Inflight = ReadEEPROMValue(EEPROMInflightLocation);
if(Inflight<fixedInflight)
{
Inflight = fixedInflight;
}
storedModeValue = ReadEEPROMValue(EEPROM_ModeStatus_Location);
scaleMax = ReadEEPROMValue(EEPROM_ScaleMax_Location);
if (storedModeValue ==0)
{
modeValue = false; //Manual Mode
}
else if (storedModeValue == 1)
{
modeValue = true; // AutoMode
}
keypad.setDebounceTime(50);
keypad.setHoldTime(3000);
keypad.addEventListener(KeypadEventHandler); // Add an event listener for this keypad

pinMode(ManualSpeedControl, OUTPUT);
pinMode(CWMotor,OUTPUT);
digitalWrite(CWMotor,LOW);
pinMode(CCWMotor,OUTPUT);
digitalWrite(CCWMotor,LOW);
pinMode(Manual_Auto_Mode,INPUT);
pinMode(Stop_ResumeSignal,INPUT);
analogReference(DEFAULT);
}
double ReadAngleFromAccelerometer(int x_Offset, int y_Offset)
{
//Tell the HMC5883 where to begin reading data
Wire.beginTransmission(address);
Wire.write(0x03); //select register 3, X MSB register
Wire.endTransmission();
//Read data from each axis, 2 registers per axis
Wire.requestFrom(address, 6);
int x,y,z; //triple axis data
if(6<=Wire.available())
{
x = Wire.read() << 8 | Wire.read();
z = Wire.read() << 8 | Wire.read();
y = Wire.read() << 8 | Wire.read();
}
DrawRotatorPosition();
return atan2((double)y + y_Offset,(double)x + x_Offset)* (180 / 3.141592654) + 180;
}
void loop()
{
char key = keypad.getKey();
angle = ReadAngleFromAccelerometer(y_Offset, x_Offset);
if((digitalRead( Stop_ResumeSignal) == false)&& stopFlag == true)
{
stopFlag = false;
}
else if((digitalRead( Stop_ResumeSignal) == false)&& stopFlag == false)
{
stopFlag = true;
}
if (stopFlag == true)
{
digitalWrite(CWMotor,LOW);
digitalWrite(CCWMotor,LOW);
stopFlag = true;
utftDisplay.setColor(0, 0, 0);
utftDisplay.print(" ", RIGHT, 25);
}
else
{
if(((long)angle< DegreeInput )&& stopFlag == false)
{
digitalWrite(CWMotor,HIGH);
digitalWrite(CCWMotor,LOW);
utftDisplay.setColor(0, 255, 255);
utftDisplay.print(" CW ", RIGHT, 25);
}
if(((long)angle >DegreeInput)&& stopFlag == false)
{
digitalWrite(CWMotor,LOW);
digitalWrite(CCWMotor,HIGH);
utftDisplay.setColor(0, 255, 255);
utftDisplay.print(" CCW ", RIGHT, 25);
}
if(((long) angle == DegreeInput)||
((long) angle > DegreeInput-Inflight)&&
((long) angle < DegreeInput+ Inflight ))
{
digitalWrite(CWMotor,LOW);
digitalWrite(CCWMotor,LOW);
stopFlag = true;
utftDisplay.setColor(0, 0, 0);
utftDisplay.print(" ", RIGHT, 25);
}
}
if((digitalRead( Manual_Auto_Mode) == false) && modeValue == false )
{
modeValue = true;
SaveEEPROMValue(EEPROM_ModeStatus_Location, 1);
}
else if((digitalRead( Manual_Auto_Mode) == false) && modeValue == true )
{
modeValue = false;
SaveEEPROMValue(EEPROM_ModeStatus_Location, 0);
}
if (modeValue == false)
{
if(stopFlag == false)
{
int spdValue = analogRead(A0);
spdValue = map(spdValue, 0, 1023, 0 , 255);
analogWrite(ManualSpeedControl, spdValue);
}
else
{
analogWrite(ManualSpeedControl, 0);
}
utftDisplay.setColor(0, 255, 255);
utftDisplay.print("Manual ", RIGHT, 295);
}
else
{
if(stopFlag == false)
{
int rotationValue =abs( (int)(DegreeInput- (long) angle)); /* Irrespective of the Direction the difference in value needs to be considered for PWM
// , Stoping is based on Cw/CCW outputs*/
//Use Serial Print to check the value of rotationValue variable
int scaleRotationValue = rotationValue *4;
int scaleMaxValue = scaleMax *4;
int newSpeedValue = map(scaleRotationValue,0,scaleMaxValue, 0,255); //The Scaling needs to be fine tuned based on the Test.
analogWrite(ManualSpeedControl, newSpeedValue);
}
else
{
analogWrite(ManualSpeedControl, 0);
}
utftDisplay.setColor(0, 255, 255);
utftDisplay.print(" Auto ", RIGHT, 295);
}
dx = (diameter * cos((angle-90)*3.14/180)) + centreX; // calculate X position
dy = (diameter * sin((angle-90)*3.14/180)) + centreY; // calculate Y position
utftDisplay.setColor(BLACK);
DrawArrow(last_dx,last_dy, centreX, centreY, 8,cool; // Erase last arrow
utftDisplay.setColor(GREEN);
DrawArrow(dx,dy, centreX, centreY, 8,cool; // Draw arrow in new position
last_dx = dx;
last_dy = dy;
delay(25);
utftDisplay.setFont(SevenSegmentFull);
utftDisplay.setColor(255, 0, 127);
int a =(int)angle;
sprintf(formattedDataBuffer, FormatData("%03d"),a);
utftDisplay.print(formattedDataBuffer, LEFT, 135);
if(UserEntryFinished == true)
{
utftDisplay.setFont(BigFont);
utftDisplay.setColor(0, 255, 0);
utftDisplay.printNumI(DegreeInput,80,205);
}
if(InflightEntryFinished == true)
{
utftDisplay.setFont(BigFont);
utftDisplay.setColor(0, 255, 0);
utftDisplay.printNumI(Inflight,80,225);
}
utftDisplay.setFont(BigFont);
utftDisplay.setColor(0, 100, 255);
if((angle < 22.5) || (angle > 337.5 ))utftDisplay.print(" North", LEFT, 260);
if((angle > 22.5) && (angle < 67.5 )) utftDisplay.print("North-East", LEFT, 260);
if((angle > 67.5) && (angle < 112.5 ))utftDisplay.print(" East", LEFT, 260);
if((angle > 112.5) && (angle < 157.5 ))utftDisplay.print("South-East", LEFT, 260);
if((angle > 157.5) && (angle < 202.5 ))utftDisplay.print(" South", LEFT, 260);
if((angle > 202.5) && (angle < 247.5 ))utftDisplay.print("South-West", LEFT, 260);
if((angle > 247.5) && (angle < 292.5 ))utftDisplay.print(" West", LEFT, 260);
if((angle > 292.5) && (angle < 337.5 ))utftDisplay.print("North-West", LEFT, 260);
}

void KeypadEventHandler(KeypadEvent key)
{
if (key != NO_KEY)
{
switch (keypad.getState())
{
case IDLE:
case RELEASED:
break;
case HOLD:
switch (key)
{
case '*':
if (inputSelection == true)
{
utftDisplay.setFont(BigFont);
utftDisplay.setColor(255, 0, 127);
utftDisplay.print(" ",80,225);
ResetInputBuffer();
UserEntry = 0;
InflightEntryStarted = true;
InflightEntryFinished = false;
}
break;
}
break;
case PRESSED:
switch (key)
{
case '#':
if (inputSelection == false)
{
UserEntryFinished = true;
UserEntryStarted = false;
if((UserEntry < 360) )
{
//If the User SetPoint is less than Inflight then we can't accept the set point
if(UserEntry> Inflight)
{
DegreeInput = UserEntry;
SaveEEPROMValue(EEPROMSetpointLocation, DegreeInput);
scaleMax = abs( (int)(DegreeInput- (long) angle));
SaveEEPROMValue (EEPROM_ScaleMax_Location, scaleMax);
utftDisplay.setFont(BigFont);
utftDisplay.setColor(BLACK);
utftDisplay.print(" ",80,205);
stopFlag = false;
}
else
{
//Show Error in UI
}
}
else
{
utftDisplay.print(" ",80,205);
DegreeInput = ReadEEPROMValue(EEPROMSetpointLocation);
}
inputSelection = true;
}
else
{
InflightEntryFinished = true;
InflightEntryStarted = false;
if((UserEntry < maxInflight) )
{
Inflight = UserEntry;
SaveEEPROMValue(EEPROMInflightLocation, Inflight);
utftDisplay.setFont(BigFont);
utftDisplay.setColor(BLACK);
utftDisplay.print(" ",80,225);
stopFlag = false;
}
else
{
utftDisplay.print(" ",80,225);
Inflight = ReadEEPROMValue(EEPROMInflightLocation);
}
inputSelection = false;
}
break;
case '*':
if (inputSelection ==false)
{
utftDisplay.setFont(BigFont);
utftDisplay.setColor(255, 0, 127);
utftDisplay.print(" ",80,205);
ResetInputBuffer();
UserEntry = 0;
UserEntryStarted = true;
UserEntryFinished = false;
}
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
if (bufPtr < maxDegreeDigits)
{
KeyEntries[bufPtr] = key;
bufPtr++;
UserEntry = atol (KeyEntries);
utftDisplay.setFont(BigFont);
utftDisplay.setColor(255, 0, 127);
if (UserEntryStarted == true)
{
utftDisplay.printNumI(UserEntry,80,205);
}
if (InflightEntryStarted == true)
{
utftDisplay.printNumI(UserEntry,80,225);
}
}
break;
}
break;
}
}
}

void DisplayUserEntry(int x, int y, String userData)
{
utftDisplay.setColor(RED);
utftDisplay.setFont(BigFont);
utftDisplay.print(userData,x,y);
}

void DrawArrow(int x2, int y2, int x1, int y1, int arrowLength, int arrowWidth)
{
float distance;
int dx, dy, x2Outer,y2Outer,x3,y3,x4,y4,k;
distance = sqrt(pow((x1 - x2), 2) + pow((y1 - y2), 2));
dx = x2 + (x1 - x2) * arrowLength / distance;
dy = y2 + (y1 - y2) * arrowLength / distance;
k = arrowWidth / arrowLength;
x2Outer = x2 - dx;
y2Outer = dy - y2;
x3 = y2Outer * k + dx;
y3 = x2Outer * k + dy;
x4 = dx - y2Outer * k;
y4 = dy - x2Outer * k;
utftDisplay.drawLine(x1, y1, x2, y2);
utftDisplay.drawLine(x1, y1, dx, dy);
utftDisplay.drawLine(x3, y3, x4, y4);
utftDisplay.drawLine(x3, y3, x2, y2);
utftDisplay.drawLine(x2, y2, x4, y4);
}

void DrawRotatorPosition()
{
int dxOuter, dyOuter, dxi, dyi;
utftDisplay.setColor(255, 128, 0);
utftDisplay.drawCircle(centreX,centreY,diameter); // Draw compass circle
for (float i = 0; i <360; i = i + 22.5) {
utftDisplay.setColor(255, 128, 0);
dxOuter = diameter * cos((i-90)*3.14/180);
dyOuter = diameter * sin((i-90)*3.14/180);
dxi = dxOuter * 0.98;
dyi = dyOuter * 0.98;
utftDisplay.drawLine(dxi+centreX,dyi+centreY,dxOuter+centreX,dyOuter+centreY);
}
DisplayUserEntry((centreX-8),(centreY-157),"N");
DisplayUserEntry((centreX-8),(centreY+145),"S");
DisplayUserEntry((centreX+141),(centreY-7),"E");
DisplayUserEntry((centreX-160),(centreY-7),"W");
}

void ResetInputBuffer()
{
int length = sizeof(KeyEntries);
for (int i = 0; i < length; i++)
{
KeyEntries[i] = '\0';
}
bufPtr = 0;
}

//Reads and returns the stored value specified in the EEPROM Start Address
long ReadEEPROMValue(int16_t EEPROMStartAddress)
{
volatile EEPROMValue eepromVal;
eepromVal.Byte1 = EEPROM.read(EEPROMStartAddress);
eepromVal.Byte2 = EEPROM.read(EEPROMStartAddress+1);
eepromVal.Byte3 = EEPROM.read(EEPROMStartAddress+2);
eepromVal.Byte4 = EEPROM.read(EEPROMStartAddress+3);
return eepromVal.Value;
}
/*Stores the specified value in the EEPROM from Start Address
EEPROM Write will only happens when the stored value and new value are different.
This will save the number of Writes to the EEPROM.*/
void SaveEEPROMValue(int16_t EEPROMStartAddress, long Value)
{
volatile EEPROMValue eepromVal;
eepromVal.Value = ReadEEPROMValue(EEPROMStartAddress);
if(eepromVal.Value != Value)
{
eepromVal.Value = Value;
EEPROM.write(EEPROMStartAddress,eepromVal.Byte1);
EEPROM.write(EEPROMStartAddress+1,eepromVal.Byte2);
EEPROM.write(EEPROMStartAddress+2,eepromVal.Byte3);
EEPROM.write(EEPROMStartAddress+3,eepromVal.Byte4);
}
}
  
sp3tyf
14.06.2016 23:14:00
Grupa: Użytkownik

Lokalizacja: Opalenica JO82FH

Posty: 3 #2296009
Od: 2012-1-23
Trochę ponarzekam.
Bajerancki wyświetlacz ale niewiele praktycznych funkcji. Brak komunikacji z programami logującymi. Spróbujcie tym sterownikiem podążać za sygnałem, szukając najsilniejszego np. na UKF. Trzeba co chwila wpisywać całą sekwencje azymutu. Konstruktor zastosował potencjometr do regulacji prędkości rotora, przecież zawsze jest za wolno więc po co zmniejszać wesoły
Myślę, że autor ma potencjał konstrukcyjny i programistyczny ale zabrakło mu zupełnie praktycznej znajomości zagadnienia. Jeżeli ktoś potrafi ten pomysł sobie usprawnić to może powstać ciekawy projekt.
_________________
Sławek SP3TYF
  
sp2cnw
14.06.2016 23:29:52
poziom 4

Grupa: Użytkownik

Posty: 322 #2296017
Od: 2011-6-30
Witam !

Podałem bazę i można ją skopiować do edytora i popracować zgodnie z sugestiami Zbyszka jeśli
ma się trochę umiejętności, czasu i chęci.

Życzę powopdzenia !
  
sq9mts
15.06.2016 09:11:25
poziom 5

Grupa: Użytkownik

Lokalizacja: jn99mt

Posty: 722 #2296149
Od: 2011-6-26
podobny projekt


TYLKO ZAREJESTROWANI I ZALOGOWANI UŻYTKOWNICY WIDZĄ LINKI » DARMOWA REJESTRACJA

  
BUBUS
26.12.2017 22:29:27
Grupa: Użytkownik

Posty: 2 #2499238
Od: 2017-12-26



UŻYTKOWNIK ZABLOKOWANY
[quote=sp2cnw]Witam!
Tak wygląda program rotora:

#include <,Wire.h>, //I2C Arduino Library
#include <,UTFT.h>, // UTFT Library from Henning Karlsen (http://www.rinkydinkelectronics.com/library.php)
#include <,UTFT_Geometry.h>, //UTFT Geometry Library from Henning Karlsen (http://www.rinkydinkelectronics.com/library.php)
#include <,Keypad.h>,
#include <,EEPROM.h>,

const int centreX = 320,
const int centreY = 160,
const int diameter = 130,
const int x_Offset = 30,
const int y_Offset = 128,
const int z_Offset = 0,
const byte rows = 4, // Four rows
const byte cols = 3, // Three columns
const int maxDegreeDigits = 3, //maximum allowed input length
const int fixedInflight = 5,
const long maxInflight = 25,

extern uint8_t BigFont[],
extern uint8_t SmallFont[],
extern uint8_t SevenSegmentFull[],

#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
#define ORANGE 0xFF00
#define address 0x1E //0011110b, I2C 7bit address of HMC5883
#define EEPROM_ModeStatus_Location 10 // The starting address of the EEPROM where the data is Stored (10.11.12.13)
#define EEPROMSetpointLocation 14
#define EEPROM_ScaleMax_Location 18
#define EEPROMInflightLocation 22

struct EEPROMValue //EEPROM Data Structure : Taken from G0MGX DDS VFO Code

union
long Value,
struct

unsigned char Byte1,
unsigned char Byte2,
unsigned char Byte3,
unsigned char Byte4,

__attribute__((packed)),

__attribute__((packed)),

__attribute__((packed)),

inline long ReadEEPROMValue(int16_t EEPROMStartAddress), //Reads the values from EEPROM Like Calibration , set Parameters, etc
inline void SaveEEPROMValue(int16_t EEPROMStartAddress, long Value), //Save the Value to EEPROM startingfrom the given StartAddress (4 Bytes of Data)
inline double ReadAngleFromAccelerometer(int x_Offset, int y_Offset),
inline void ResetInputBuffer(void),

// Define the Keymap
char keys[rows][cols] =


'1','2','3'
,

'4','5','6'
,

'7','8','9'
,

'*','0','#'
,

boolean UserEntryStarted = false,
boolean UserEntryFinished = true,
boolean InflightEntryStarted = false,
boolean InflightEntryFinished = true,
boolean stopFlag = true,
boolean modeValue = false, // modeValue = false (Manual Mode), modeValue = true (Auto Mode)
boolean inputSelection = false, // false = SetPoint Input , True = inflight input

char KeyEntries[3], //3 characters to store 0 to 360 Degrees
char dataBuffer[60],
char formattedDataBuffer[3],

int dx,
int dy,
int last_dx,
int last_dy,
int bufPtr = 0,
int CWMotor = 10,
int CCWMotor = 11,
int Stop_ResumeSignal = 12,
int Manual_Auto_Mode = 13,
int ManualSpeedControl = 9,

long UserEntry = 0,
long DegreeInput = 0,
long Inflight = 0,
long storedModeValue = 0,
long scaleMax = 0,

double angle = 0,

//Normal Keyboard Connected To Arduino
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[rows] =
8, 7, 6, 5 ,
// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
byte colPins[cols] =
4, 3, 2 ,

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, rows, cols ),

UTFT utftDisplay(ILI9481,38,39,40,41),

#define FormatData(x) strcpy_P(dataBuffer, PSTR(x))

void setup()
Serial.begin(9600),
utftDisplay.InitLCD(),
utftDisplay.InitLCD(LANDSCAPE),
utftDisplay.clrScr(),
utftDisplay.setFont(BigFont),
utftDisplay.setColor(255, 0, 0),
utftDisplay.print("ANTENNA ROTATOR ", LEFT, 16),
utftDisplay.print("CONTROLLER ", 40, 40),
utftDisplay.drawLine(440, 160, 460, 160),
utftDisplay.drawLine(180, 160, 200, 160),
utftDisplay.drawLine(320, 20, 320, 40),
utftDisplay.drawLine(320, 280, 320, 300),
utftDisplay.setColor(255, 255, 0),
utftDisplay.print("BEAM DIR", LEFT, 87),
utftDisplay.setFont(SmallFont),
utftDisplay.setColor(255, 100, 100),
utftDisplay.print("SET DIR", LEFT, 210),
utftDisplay.print("INFLIGHT", LEFT, 230),
utftDisplay.setFont(BigFont),
utftDisplay.setColor(255, 0, 0),
utftDisplay.print("O", 95, 115),
utftDisplay.setColor(255, 255, 255),
utftDisplay.print("VU3ESV : VU2JLH",LEFT, 290),
// Initialize I2C communications
Wire.begin(),
//Put the HMC5883 IC into the correct operating mode
Wire.beginTransmission(address), //open communication with HMC5883
Wire.write(0x02), //select mode register
Wire.write(0x00), //continuous measurement mode
Wire.endTransmission(),
delay(300),
last_dx = centreX,
last_dy = centreY,

DegreeInput = ReadEEPROMValue(EEPROMSetpointLocation),
Inflight = ReadEEPROMValue(EEPROMInflightLocation),
if(Inflight<,fixedInflight)

Inflight = fixedInflight,

storedModeValue = ReadEEPROMValue(EEPROM_ModeStatus_Location),
scaleMax = ReadEEPROMValue(EEPROM_ScaleMax_Location),
if (storedModeValue ==0)

modeValue = false, //Manual Mode

else if (storedModeValue == 1)

modeValue = true, // AutoMode

keypad.setDebounceTime(50),
keypad.setHoldTime(3000),
keypad.addEventListener(KeypadEventHandler), // Add an event listener for this keypad

pinMode(ManualSpeedControl, OUTPUT),
pinMode(CWMotor,OUTPUT),
digitalWrite(CWMotor,LOW),
pinMode(CCWMotor,OUTPUT),
digitalWrite(CCWMotor,LOW),
pinMode(Manual_Auto_Mode,INPUT),
pinMode(Stop_ResumeSignal,INPUT),
analogReference(DEFAULT),

double ReadAngleFromAccelerometer(int x_Offset, int y_Offset)

//Tell the HMC5883 where to begin reading data
Wire.beginTransmission(address),
Wire.write(0x03), //select register 3, X MSB register
Wire.endTransmission(),
//Read data from each axis, 2 registers per axis
Wire.requestFrom(address, 6),
int x,y,z, //triple axis data
if(6<,=Wire.available())

x = Wire.read() <,<, 8 | Wire.read(),
z = Wire.read() <,<, 8 | Wire.read(),
y = Wire.read() <,<, 8 | Wire.read(),

DrawRotatorPosition(),
return atan2((double)y + y_Offset,(double)x + x_Offset)* (180 / 3.141592654) + 180,

void loop()

char key = keypad.getKey(),
angle = ReadAngleFromAccelerometer(y_Offset, x_Offset),
if((digitalRead( Stop_ResumeSignal) == false)&& stopFlag == true)

stopFlag = false,

else if((digitalRead( Stop_ResumeSignal) == false)&& stopFlag == false)

stopFlag = true,

if (stopFlag == true)

digitalWrite(CWMotor,LOW),
digitalWrite(CCWMotor,LOW),
stopFlag = true,
utftDisplay.setColor(0, 0, 0),
utftDisplay.print(" ", RIGHT, 25),

else

if(((long)angle<, DegreeInput )&& stopFlag == false)

digitalWrite(CWMotor,HIGH),
digitalWrite(CCWMotor,LOW),
utftDisplay.setColor(0, 255, 255),
utftDisplay.print(" CW ", RIGHT, 25),

if(((long)angle >,DegreeInput)&& stopFlag == false)

digitalWrite(CWMotor,LOW),
digitalWrite(CCWMotor,HIGH),
utftDisplay.setColor(0, 255, 255),
utftDisplay.print(" CCW ", RIGHT, 25),

if(((long) angle == DegreeInput)||
((long) angle >, DegreeInput-Inflight)&&
((long) angle <, DegreeInput+ Inflight ))

digitalWrite(CWMotor,LOW),
digitalWrite(CCWMotor,LOW),
stopFlag = true,
utftDisplay.setColor(0, 0, 0),
utftDisplay.print(" ", RIGHT, 25),


if((digitalRead( Manual_Auto_Mode) == false) && modeValue == false )

modeValue = true,
SaveEEPROMValue(EEPROM_ModeStatus_Location, 1),

else if((digitalRead( Manual_Auto_Mode) == false) && modeValue == true )

modeValue = false,
SaveEEPROMValue(EEPROM_ModeStatus_Location, 0),

if (modeValue == false)

if(stopFlag == false)

int spdValue = analogRead(A0),
spdValue = map(spdValue, 0, 1023, 0 , 255),
analogWrite(ManualSpeedControl, spdValue),

else

analogWrite(ManualSpeedControl, 0),

utftDisplay.setColor(0, 255, 255),
utftDisplay.print("Manual ", RIGHT, 295),

else

if(stopFlag == false)

int rotationValue =abs( (int)(DegreeInput- (long) angle)), /* Irrespective of the Direction the difference in value needs to be considered for PWM
// , Stoping is based on Cw/CCW outputs*/
//Use Serial Print to check the value of rotationValue variable
int scaleRotationValue = rotationValue *4,
int scaleMaxValue = scaleMax *4,
int newSpeedValue = map(scaleRotationValue,0,scaleMaxValue, 0,255), //The Scaling needs to be fine tuned based on the Test.
analogWrite(ManualSpeedControl, newSpeedValue),

else

analogWrite(ManualSpeedControl, 0),

utftDisplay.setColor(0, 255, 255),
utftDisplay.print(" Auto ", RIGHT, 295),

dx = (diameter * cos((angle-90)*3.14/180)) + centreX, // calculate X position
dy = (diameter * sin((angle-90)*3.14/180)) + centreY, // calculate Y position
utftDisplay.setColor(BLACK),
DrawArrow(last_dx,last_dy, centreX, centreY, 8,cool, // Erase last arrow
utftDisplay.setColor(GREEN),
DrawArrow(dx,dy, centreX, centreY, 8,cool, // Draw arrow in new position
last_dx = dx,
last_dy = dy,
delay(25),
utftDisplay.setFont(SevenSegmentFull),
utftDisplay.setColor(255, 0, 127),
int a =(int)angle,
sprintf(formattedDataBuffer, FormatData("%03d"),a),
utftDisplay.print(formattedDataBuffer, LEFT, 135),
if(UserEntryFinished == true)

utftDisplay.setFont(BigFont),
utftDisplay.setColor(0, 255, 0),
utftDisplay.printNumI(DegreeInput,80,205),

if(InflightEntryFinished == true)

utftDisplay.setFont(BigFont),
utftDisplay.setColor(0, 255, 0),
utftDisplay.printNumI(Inflight,80,225),

utftDisplay.setFont(BigFont),
utftDisplay.setColor(0, 100, 255),
if((angle <, 22.5) || (angle >, 337.5 ))utftDisplay.print(" North", LEFT, 260),
if((angle >, 22.5) && (angle <, 67.5 )) utftDisplay.print("North-East", LEFT, 260),
if((angle >, 67.5) && (angle <, 112.5 ))utftDisplay.print(" East", LEFT, 260),
if((angle >, 112.5) && (angle <, 157.5 ))utftDisplay.print("South-East", LEFT, 260),
if((angle >, 157.5) && (angle <, 202.5 ))utftDisplay.print(" South", LEFT, 260),
if((angle >, 202.5) && (angle <, 247.5 ))utftDisplay.print("South-West", LEFT, 260),
if((angle >, 247.5) && (angle <, 292.5 ))utftDisplay.print(" West", LEFT, 260),
if((angle >, 292.5) && (angle <, 337.5 ))utftDisplay.print("North-West", LEFT, 260),


void KeypadEventHandler(KeypadEvent key)

if (key != NO_KEY)

switch (keypad.getState())

case IDLE:
case RELEASED:
break,
case HOLD:
switch (key)

case '*':
if (inputSelection == true)

utftDisplay.setFont(BigFont),
utftDisplay.setColor(255, 0, 127),
utftDisplay.print(" ",80,225),
ResetInputBuffer(),
UserEntry = 0,
InflightEntryStarted = true,
InflightEntryFinished = false,

break,

break,
case PRESSED:
switch (key)

case '#':
if (inputSelection == false)

UserEntryFinished = true,
UserEntryStarted = false,
if((UserEntry <, 360) )

//If the User SetPoint is less than Inflight then we can't accept the set point
if(UserEntry>, Inflight)

DegreeInput = UserEntry,
SaveEEPROMValue(EEPROMSetpointLocation, DegreeInput),
scaleMax = abs( (int)(DegreeInput- (long) angle)),
SaveEEPROMValue (EEPROM_ScaleMax_Location, scaleMax),
utftDisplay.setFont(BigFont),
utftDisplay.setColor(BLACK),
utftDisplay.print(" ",80,205),
stopFlag = false,

else

//Show Error in UI


else

utftDisplay.print(" ",80,205),
DegreeInput = ReadEEPROMValue(EEPROMSetpointLocation),

inputSelection = true,

else

InflightEntryFinished = true,
InflightEntryStarted = false,
if((UserEntry <, maxInflight) )

Inflight = UserEntry,
SaveEEPROMValue(EEPROMInflightLocation, Inflight),
utftDisplay.setFont(BigFont),
utftDisplay.setColor(BLACK),
utftDisplay.print(" ",80,225),
stopFlag = false,

else

utftDisplay.print(" ",80,225),
Inflight = ReadEEPROMValue(EEPROMInflightLocation),

inputSelection = false,

break,
case '*':
if (inputSelection ==false)

utftDisplay.setFont(BigFont),
utftDisplay.setColor(255, 0, 127),
utftDisplay.print(" ",80,205),
ResetInputBuffer(),
UserEntry = 0,
UserEntryStarted = true,
UserEntryFinished = false,

break,
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
if (bufPtr <, maxDegreeDigits)

KeyEntries[bufPtr] = key,
bufPtr++,
UserEntry = atol (KeyEntries),
utftDisplay.setFont(BigFont),
utftDisplay.setColor(255, 0, 127),
if (UserEntryStarted == true)

utftDisplay.printNumI(UserEntry,80,205),

if (InflightEntryStarted == true)

utftDisplay.printNumI(UserEntry,80,225),


break,

break,




void DisplayUserEntry(int x, int y, String userData)

utftDisplay.setColor(RED),
utftDisplay.setFont(BigFont),
utftDisplay.print(userData,x,y),


void DrawArrow(int x2, int y2, int x1, int y1, int arrowLength, int arrowWidth)

float distance,
int dx, dy, x2Outer,y2Outer,x3,y3,x4,y4,k,
distance = sqrt(pow((x1 - x2), 2) + pow((y1 - y2), 2)),
dx = x2 + (x1 - x2) * arrowLength / distance,
dy = y2 + (y1 - y2) * arrowLength / distance,
k = arrowWidth / arrowLength,
x2Outer = x2 - dx,
y2Outer = dy - y2,
x3 = y2Outer * k + dx,
y3 = x2Outer * k + dy,
x4 = dx - y2Outer * k,
y4 = dy - x2Outer * k,
utftDisplay.drawLine(x1, y1, x2, y2),
utftDisplay.drawLine(x1, y1, dx, dy),
utftDisplay.drawLine(x3, y3, x4, y4),
utftDisplay.drawLine(x3, y3, x2, y2),
utftDisplay.drawLine(x2, y2, x4, y4),


void DrawRotatorPosition()

int dxOuter, dyOuter, dxi, dyi,
utftDisplay.setColor(255, 128, 0),
utftDisplay.drawCircle(centreX,centreY,diameter), // Draw compass circle
for (float i = 0, i <,360, i = i + 22.5)
utftDisplay.setColor(255, 128, 0),
dxOuter = diameter * cos((i-90)*3.14/180),
dyOuter = diameter * sin((i-90)*3.14/180),
dxi = dxOuter * 0.98,
dyi = dyOuter * 0.98,
utftDisplay.drawLine(dxi+centreX,dyi+centreY,dxOuter+centreX,dyOuter+centreY),

DisplayUserEntry((centreX-8),(centreY-157),"N"),
DisplayUserEntry((centreX-8),(centreY+145),"S"),
DisplayUserEntry((centreX+141),(centreY-7),"E"),
DisplayUserEntry((centreX-160),(centreY-7),"W"),


void ResetInputBuffer()

int length = sizeof(KeyEntries),
for (int i = 0, i <, length, i++)

KeyEntries[i] = '\0',

bufPtr = 0,


//Reads and returns the stored value specified in the EEPROM Start Address
long ReadEEPROMValue(int16_t EEPROMStartAddress)

volatile EEPROMValue eepromVal,
eepromVal.Byte1 = EEPROM.read(EEPROMStartAddress),
eepromVal.Byte2 = EEPROM.read(EEPROMStartAddress+1),
eepromVal.Byte3 = EEPROM.read(EEPROMStartAddress+2),
eepromVal.Byte4 = EEPROM.read(EEPROMStartAddress+3),
return eepromVal.Value,

/*Stores the specified value in the EEPROM from Start Address
EEPROM Write will only happens when the stored value and new value are different.
This will save the number of Writes to the EEPROM.*/
void SaveEEPROMValue(int16_t EEPROMStartAddress, long Value)

volatile EEPROMValue eepromVal,
eepromVal.Value = ReadEEPROMValue(EEPROMStartAddress),
if(eepromVal.Value != Value)

eepromVal.Value = Value,
EEPROM.write(EEPROMStartAddress,eepromVal.Byte1),
EEPROM.write(EEPROMStartAddress+1,eepromVal.Byte2),
EEPROM.write(EEPROMStartAddress+2,eepromVal.Byte3),
EEPROM.write(EEPROMStartAddress+3,eepromVal.Byte4),


[/quote]
  
BUBUS
26.12.2017 22:33:37
Grupa: Użytkownik

Posty: 2 #2499243
Od: 2017-12-26



UŻYTKOWNIK ZABLOKOWANY
Chciałbym spotkać człowieka który to wykonał.Przytoczony program bez ingerencji niemożliwy do kompilacji Pozdrawiam
  
Electra29.03.2024 09:24:16
poziom 5

oczka

Przejdz do góry stronyStrona: 1 / 1    strony: [1]

  << Pierwsza      < Poprzednia      Następna >     Ostatnia >>  

HOME » ARDUINO » ARDUINO MEGA2560 BASED ANTENNA ROTATOR CONTROLLER

Aby pisac na forum musisz sie zalogować !!!

TestHub.pl - opinie, testy, oceny