0

This seems so simple but I can't solve it. (I'm new to Programming) I do not want to use EEPROM. Just store it and do the math. I strip the Azmuth and Elevation values from a satellite tracker program and need to calculate the difference the satellite has moved to turn the rotors. Here's my efforts so far as requested ...Thanks

/* Sketch for WXtrack satellite tracking software
 * VE3COJ Burlington, Ontario, Canada 
 * Requires COM port and Max 232 from PC
 * to Serial in on Arduino (Rx)
 * 
 * Download URL: http://www.satsignal.eu/software/wxtrack.htm
 * 
 * Setup in WXtrack: Go to <Tracker menu> <Options> <Select EGIS COM port> <check box XY mode>
 * Select a Satellite using Manual in Timeframe box. 
 * Highlight Satellite icon, Use seconds box (third box from left side) to increment satellite.
 * Use the Sketch Monitor to see Elevation and azimuth reading from Serial port. 
 * Alternatly, one can use an array to simulate Elevation and Azimuth increments in degrees.
 */
 #include <Stepper.h>
 #include <avr/pgmspace.h>
 #define STEP 50
 #define motorSteps 600 // Number of steps to turn the motor
 #define motorPin1 8
 #define motorPin2 9
 #define motorPin3 10
 #define motorPin4 11
 // 2 EasyDriver boards will be used in final project //
 String readString, read_az, read_el;
 int el_current_store_0; // elevation ... global value ??
 int el_current_store_1;
 int el_position; // final value in degrees to move rotor
 int az_current_store_1; // azimuth ..... global value ??
 void setup() {
 Serial.begin(9600);
 Serial.println(" AZ & EL "); // so I can keep track of elevation and Azimuth
 Serial.println (" =========");
 Serial.print("");
 }
 void loop() {
 while (Serial.available()) {
 delay(3); //delay to allow buffer to fill
 if (Serial.available() >0) { 
 char c = Serial.read(); //gets one byte from serial buffer
 readString += c; //makes the string readString
 }
 }
 if (readString.length() >0) {
 //Serial.println(readString); //see what was received from Serial input
 // pull out the number values required... parse the serial output
 // On WXtrack menu, select "Tracker" > "Options" > "EGIS COM" & "XY mode"
 read_az = readString.substring(3, 7); //get the first 3 to the 6th integers (azmuth)
 read_el = readString.substring(10, 13); //get the next 10 to thee 13th integers (elevation)
 int el_current_store = read_el.toInt(); // Change String el to Integer 
 int az_current_store = read_az.toInt(); // Change String Az to integer
 /* This is an attemp to calculate the difference in degrees the satellite moves. */
 int n1 = el_current_store_0; // first elevation reading ... store it ... how?
 int n2 = el_current_store_1; // second elevation reading ... 
 int el_position = (n2 - n1); // Subtract first from second ... equals how many degrees to turn the rotor
 // if result is negative, rotor changes direction
 /* Can't be done as is because the reading gets put in all variables
 * I cannot figure out how to store the number of degrees in memory (Not EEPROM)
 * EEPROM will burn out eventually, FLASH cannot change values it appears... in docs.
 * 
 * From here:
 * Store first reading from Serial port into memory. 
 * Rotor moves to degrees probably 3 degrees ... read second position (if 4 degrees)
 * Subtract 3 degrees from 4 degrees equals 1 and multiply by variable STEP (200 STEP = 1 degree motor rotation)
 * Get next elevation reading and repeat subtraction... 
 */
 // Print to serial monitor to see results of all values //
 Serial.print(" Elevation = ");
 Serial.println(read_el);
 Serial.print(" Azimuth = ");
 Serial.println(read_az); 
 //Serial.println(el_position);
 Serial.println (" --------next-------");
 Serial.print("");
 readString="";
 }
 }
 /* 1. ========= Send Antenna to 0 degrees / Check for interrup at 0 degrees & Stop ========= 
 ========= Wait for Serial input then goto 2. ========= 
 2. ========= Get Az and El from Serial Port and Start Tracking ========== 
 3. ========= Store (first, second, etc. ) El and AZ ========= 
 4. ========= Get Next El and Az / Subtract from one before El & Az ========= 
 5. ========= Move Antenna to Next Position ======= 
 6. ======== Goto 3. ========= 
 7. ======== If El Equals 0, Goto 1.
 When El = 90 degrees, (Satellite overhead) Az rotates 180 degrees and 
 El decreases, coming down to the horizon.
 When Satellite is off to E or W, elevation does not reach 90 degrees!
 */ 
asked Jul 2, 2018 at 14:08
1
  • When you say you want to "store" the values, but not use EEPROM, what is the time frame you are meaning? Do you want to store it so it is not lost when the microcontroller resets (power cycles)? Or do you just mean to store it within the program for use in subsequent statements? Commented Jul 2, 2018 at 14:43

1 Answer 1

3

You have the following global variables declared:

int el_current_store_0; // elevation ... global value ??
int el_current_store_1;
int el_position; // final value in degrees to move rotor
int az_current_store_1; // azimuth ..... global value ??

But you never put anything into these variables.

Here is your relevant code that attempts to work with these values:

// pull out the number values required... parse the serial output
// On WXtrack menu, select "Tracker" > "Options" > "EGIS COM" & "XY mode"
read_az = readString.substring(3, 7); //get the first 3 to the 6th integers (azmuth)
read_el = readString.substring(10, 13); //get the next 10 to thee 13th integers (elevation)
int el_current_store = read_el.toInt(); // Change String el to Integer 
int az_current_store = read_az.toInt(); // Change String Az to integer

Above, you are declaring new variables el_current_store and az_current_store and giving them integer values converted from your input string. When you prefix a variable name with int (or any other type) you are declaring a new variable within that scope. In this case, the scope is the if (readString.length() >0) {} block. Once that block ends, those variables don't exist anymore, and every time that block runs, new variables are created there, and destroyed at the end of the block.

/* This is an attemp to calculate the difference in degrees the satellite moves. */
int n1 = el_current_store_0; // first elevation reading ... store it ... how?
int n2 = el_current_store_1; // second elevation reading ... 
int el_position = (n2 - n1); // Subtract first from second ... equals how many degrees to turn the rotor

Above, you declare new variables n1, n2, and el_position. However, you give n1 and n2 whatever was in el_current_store_0 and el_current_store_1, but you have never put any value into those variables, and so they have nothing.

Once that is solved, you also need to take a look at declaring a new variable by the command:

int el_position = (n2 - n1); // Subtract first from second ... equals how many degrees to turn the rotor

which, because it's in a nearer scope than the global variable of the same name, is used instead of the global. And when the scope block ends, it is destroyed.

You should instead assign the computed value to el_position without making a new variable:

el_position = (n2 - n1); // Subtract first from second ... equals how many degrees to turn the rotor

(Note, no int in front...)

**EDIT: To actually keep the values for the next loop(), you do have to store them in global (or static) variables. Something like this appears to be what you were going for:

 int el_current_store = read_el.toInt(); // Change String el to Integer 
 int az_current_store = read_az.toInt(); // Change String Az to integer
 /* This is an attemp to calculate the difference in degrees the satellite moves. */
 // Added code below keeps the older value in *_1
 // Puts the newer value in *_0
 el_current_store_1 = el_current_store_0;
 el_current_store_0 = el_current_store;
 az_current_store_1 = az_current_store_0;
 az_current_store_0 = az_current_store;
 int n1 = el_current_store_0; // first elevation reading ... store it ... how?
 int n2 = el_current_store_1; // second elevation reading ... 
 int el_position = (n2 - n1); // Subtract first from second ... equals how many degrees to turn the rotor
answered Jul 2, 2018 at 14:53
7
  • Hi Jose... Yes there re some variables not used yet... Commented Jul 2, 2018 at 16:14
  • It's not necessarily a problem to have unused variables. But what you have are uninitialized variables that you are trying to use. Commented Jul 2, 2018 at 16:19
  • Sorry... The program works... getting the AZ and EL I need. Once I get the two values, I need to stuff them somewhere so they do not get overwritten on the next loop around. When I have the next Az and El I want to get the previous Az and El and subtract the difference. Then I know the satellite has moved x degrees. This will then turn the stepper motors. I can't figure out how to temporarily hold the Az & El values. Commented Jul 2, 2018 at 16:22
  • @jeff: You need two pairs of variables; one for the current values and one for the previous values. You have to declare the pair for the previous values "static", which means they get permanent memory assignments and will not be overwritten when your loop() function exits and gets called again. Those declaration would look like: "int az, el;" and "static int prevAz, prevEl". On each loop, once you've calculated the 'az' and 'el' differences and moved the rotors, copy 'az' and 'el' to 'prevAz' and 'prevEl', respectively. Commented Jul 2, 2018 at 18:27
  • @JRobert. Thank you for your suggestions. I will see what I can do to get this to work using static memory. It will be a new learning curve. Commented Jul 3, 2018 at 3:54

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.