Components and supplies
1
Arduino Nano R3
1
Small Signal Diode, Switching
2
SG90 Micro-servo motor
Tools and machines
1
Soldering iron (generic)
1
Hot glue gun (generic)
Apps and platforms
1
Arduino IDE
Project description
Code
servos_easycom2_apr2021
arduino
AZ/EL Rotator toy controller for Arduino with servos Uses EasyComm2 protocol for computer - Tracking Software Two servomotors to move the antenna in Az (360 deg) and El (90 deg)
1/* AZ/EL Rotator toy controller for Arduino with servos 2 * ======================================================== 3 * Uses EasyComm2 protocol for computer - Tracking Software 4 * servomotors to move the antenna in Az (360 deg) and El (90 deg) 5 * 6 * Viorel Racoviteannu 7 * https://www.youtube.com/channel/UCiRLZX0bV9rS04BGAyUf-fA 8 * https://racov.ro 9 * YO3RAK@gmail.com 10 * 11 * I cannot take any responsibility for missuse of this code 12 * or any kind of damage it may occur from using this code. 13 * 14 */ 15#include <Wire.h> 16/* 17#include <Adafruit_GFX.h> 18#include <Adafruit_SSD1306.h> 19#include <Fonts/FreeSans18pt7b.h> 20#include <Fonts/FreeSans12pt7b.h> 21Adafruit_SSD1306 display(4); 22*/ 23#include <Servo.h> 24Servo AzServo; // create servo object to control the azimuth servo 25Servo ElServo; // create servo object to control the elevation servo 26 27 String Azimuth = ""; 28 String Elevation = ""; 29 String ComputerRead = ""; 30 String ComputerWrite = ""; 31 int ComAzim = 0; 32 int ComElev = 0; 33 34void setup() { 35 Serial.begin(9600); 36 Serial.setTimeout(50); // miliseconds to wait for USB sata. Default 1000 37/* 38 display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 128x32) 39 display.display(); 40 display.setTextColor(WHITE); 41 display.setFont(&FreeSans12pt7b); 42 delay(2000); 43 display.clearDisplay(); // Clear the buffer 44 45 display.setCursor(-3,24); 46 display.println("EasyComm2"); 47 display.display(); 48 delay (1000); 49 display.setFont(&FreeSans18pt7b); 50*/ 51 AzServo.attach(5); // connect Az servo to pin 5 52 ElServo.attach(6); // connect Az servo to pin 6 53 54 55 /********************** make a short movement *************************/ 56 ComAzim = 0; 57 ComElev = 40; 58 Rotate(); // center the servos 59 delay(100); 60 for (ComAzim = 0; ComAzim <= 45; ComAzim += 1) { // goes from 0 degrees to 45 degrees 61 // in steps of 1 degree 62 Rotate(); // tell servo to go to position 63 delay(20); // waits 20ms for the servo to reach the position 64 } 65 for (ComElev = 20; ComElev <= 75; ComElev += 1) { 66 Rotate(); 67 delay(20); 68 } 69 ComAzim = 0; 70 ComElev = 35; 71 Rotate(); 72 DisplayPosition(); 73 74} 75 76void loop() { 77 78 if (Serial.available()){ 79 SerComm(); 80 Rotate(); 81 DisplayPosition(); 82 delay (100); 83 } 84 85} 86 87void SerComm() { 88 // initialize readings 89 ComputerRead = ""; 90 Azimuth = ""; 91 Elevation = ""; 92 93 while(Serial.available()) { 94 ComputerRead= Serial.readString(); // read the incoming data as string 95// Serial.println(ComputerRead); // echo the reception for testing purposes 96 } 97 98// looking for command <AZxxx.x> 99 for (int i = 0; i <= ComputerRead.length(); i++) { 100 if ((ComputerRead.charAt(i) == 'A')&&(ComputerRead.charAt(i+1) == 'Z')){ // if read AZ 101 for (int j = i+2; j <= ComputerRead.length(); j++) { 102 if (isDigit(ComputerRead.charAt(j))) { // if the character is number 103 Azimuth = Azimuth + ComputerRead.charAt(j); 104 } 105 else {break;} 106 } 107 } 108 } 109 110// looking for command <ELxxx.x> 111 for (int i = 0; i <= (ComputerRead.length()-2); i++) { 112 if ((ComputerRead.charAt(i) == 'E')&&(ComputerRead.charAt(i+1) == 'L')){ // if read EL 113 if ((ComputerRead.charAt(i+2)) == '-') { 114 ComElev = 0; // if elevation negative 115 break; 116 } 117 for (int j = i+2; j <= ComputerRead.length(); j++) { 118 if (isDigit(ComputerRead.charAt(j))) { // if the character is number 119 Elevation = Elevation + ComputerRead.charAt(j); 120 } 121 else {break;} 122 } 123 } 124 } 125 126// if <AZxx> received 127 if (Azimuth != ""){ 128 ComAzim = Azimuth.toInt(); 129 ComAzim = ComAzim%360; // keeping values between limits(for trackers with more than 360 deg. rotation) 130 } 131 132// if <ELxx> received 133 if (Elevation != ""){ 134 ComElev = Elevation.toInt(); 135 if (ComElev>180) { ComElev = 0;} 136 if (ComElev>90) { //if received more than 90deg. (for trackers with 180deg. elevation) 137 ComElev = 180-ComElev; //keep below 90deg. 138 ComAzim = (ComAzim+180)%360; //and rotate the antenna on the back 139 } 140 } 141 142// looking for <AZ EL> interogation for antenna position 143 for (int i = 0; i <= (ComputerRead.length()-4); i++) { 144 if ((ComputerRead.charAt(i) == 'A')&&(ComputerRead.charAt(i+1) == 'Z')&&(ComputerRead.charAt(i+3) == 'E')&&(ComputerRead.charAt(i+4) == 'L')){ 145 // send back the antenna position <+xxx.x xx.x> 146 ComputerWrite = "+"+String(ComAzim)+".0 "+String(ComElev)+".0"; 147 Serial.println(ComputerWrite); 148 } 149 } 150} 151 152void Rotate() { 153 // rotate the servos to the coordinates received thru serial 154 // because the servo rotates in the oposite direction, we have to reverse the movement 155 if (ComElev >90){ // if received elevation more than 90 deg 156 ComElev = 180-ComElev; // keep it below 90 157 ComAzim = (180+ComAzim)%360; // and flip the antenna 158 } 159 if (ComAzim > 180) { // if azim more than 180 deg 160 AzServo.write(360-ComAzim); // flip the antenna 161 ElServo.write(180-ComElev); 162 } 163 else { 164 AzServo.write(180-ComAzim); 165 ElServo.write(ComElev); 166 } 167} 168 169void DisplayPosition() { 170 // display values 171/* 172 display.clearDisplay(); 173 display.setCursor(0,28); 174 display.print(ComAzim); 175 display.print(" / "); 176 display.print(ComElev); 177 display.display(); 178*/ 179}
servos_easycom2_apr2021
arduino
AZ/EL Rotator toy controller for Arduino with servos Uses EasyComm2 protocol for computer - Tracking Software Two servomotors to move the antenna in Az (360 deg) and El (90 deg)
1/* AZ/EL Rotator toy controller for Arduino with servos 2 * ======================================================== 3 4 * Uses EasyComm2 protocol for computer - Tracking Software 5 * servomotors to 6 move the antenna in Az (360 deg) and El (90 deg) 7 * 8 * Viorel Racoviteannu 9 10 * https://www.youtube.com/channel/UCiRLZX0bV9rS04BGAyUf-fA 11 * https://racov.ro 12 13 * YO3RAK@gmail.com 14 * 15 * I cannot take any responsibility for missuse of 16 this code 17 * or any kind of damage it may occur from using this code. 18 * 19 20 */ 21#include <Wire.h> 22/* 23#include <Adafruit_GFX.h> 24#include <Adafruit_SSD1306.h> 25#include 26 <Fonts/FreeSans18pt7b.h> 27#include <Fonts/FreeSans12pt7b.h> 28Adafruit_SSD1306 29 display(4); 30*/ 31#include <Servo.h> 32Servo AzServo; // create servo object 33 to control the azimuth servo 34Servo ElServo; // create servo object to control 35 the elevation servo 36 37 String Azimuth = ""; 38 String Elevation = ""; 39 40 String ComputerRead = ""; 41 String ComputerWrite = ""; 42 int ComAzim 43 = 0; 44 int ComElev = 0; 45 46void setup() { 47 Serial.begin(9600); 48 49 Serial.setTimeout(50); // miliseconds to wait for USB sata. Default 50 1000 51/* 52 display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the 53 I2C addr 0x3C (for the 128x32) 54 display.display(); 55 display.setTextColor(WHITE); 56 57 display.setFont(&FreeSans12pt7b); 58 delay(2000); 59 display.clearDisplay(); 60 // Clear the buffer 61 62 display.setCursor(-3,24); 63 64 display.println("EasyComm2"); 65 display.display(); 66 delay (1000); 67 68 display.setFont(&FreeSans18pt7b); 69*/ 70 AzServo.attach(5); // connect 71 Az servo to pin 5 72 ElServo.attach(6); // connect Az servo to pin 6 73 74 75 76 /********************** make a short movement *************************/ 77 78 ComAzim = 0; 79 ComElev = 40; 80 Rotate(); // center the servos 81 82 delay(100); 83 for (ComAzim = 0; ComAzim <= 45; ComAzim += 1) { // goes from 84 0 degrees to 45 degrees 85 // in steps of 1 degree 86 Rotate(); // 87 tell servo to go to position 88 delay(20); // waits 20ms for the 89 servo to reach the position 90 } 91 for (ComElev = 20; ComElev <= 75; ComElev 92 += 1) { 93 Rotate(); 94 delay(20); 95 } 96 ComAzim = 0; 97 ComElev 98 = 35; 99 Rotate(); 100 DisplayPosition(); 101 102} 103 104void loop() { 105 106 107 if (Serial.available()){ 108 SerComm(); 109 Rotate(); 110 DisplayPosition(); 111 112 delay (100); 113 } 114 115} 116 117void SerComm() { 118 // initialize 119 readings 120 ComputerRead = ""; 121 Azimuth = ""; 122 Elevation = ""; 123 124 125 while(Serial.available()) { 126 ComputerRead= Serial.readString(); // read 127 the incoming data as string 128// Serial.println(ComputerRead); // echo the 129 reception for testing purposes 130 } 131 132// looking for command <AZxxx.x> 133 134 for (int i = 0; i <= ComputerRead.length(); i++) { 135 if ((ComputerRead.charAt(i) 136 == 'A')&&(ComputerRead.charAt(i+1) == 'Z')){ // if read AZ 137 for (int j = 138 i+2; j <= ComputerRead.length(); j++) { 139 if (isDigit(ComputerRead.charAt(j))) 140 { // if the character is number 141 Azimuth 142 = Azimuth + ComputerRead.charAt(j); 143 } 144 else {break;} 145 } 146 147 } 148 } 149 150// looking for command <ELxxx.x> 151 for (int i = 152 0; i <= (ComputerRead.length()-2); i++) { 153 if ((ComputerRead.charAt(i) == 154 'E')&&(ComputerRead.charAt(i+1) == 'L')){ // if read EL 155 if ((ComputerRead.charAt(i+2)) 156 == '-') { 157 ComElev = 0; // if elevation negative 158 159 break; 160 } 161 for (int j = i+2; j <= ComputerRead.length(); 162 j++) { 163 if (isDigit(ComputerRead.charAt(j))) { // 164 if the character is number 165 Elevation = Elevation + ComputerRead.charAt(j); 166 167 } 168 else {break;} 169 } 170 } 171 } 172 173// 174 if <AZxx> received 175 if (Azimuth != ""){ 176 ComAzim = Azimuth.toInt(); 177 178 ComAzim = ComAzim%360; // keeping values between limits(for trackers 179 with more than 360 deg. rotation) 180 } 181 182// if <ELxx> received 183 if 184 (Elevation != ""){ 185 ComElev = Elevation.toInt(); 186 if (ComElev>180) 187 { ComElev = 0;} 188 if (ComElev>90) { //if received more than 189 90deg. (for trackers with 180deg. elevation) 190 ComElev = 180-ComElev; //keep 191 below 90deg. 192 ComAzim = (ComAzim+180)%360; //and rotate the antenna on 193 the back 194 } 195 } 196 197// looking for <AZ EL> interogation for antenna 198 position 199 for (int i = 0; i <= (ComputerRead.length()-4); i++) { 200 if ((ComputerRead.charAt(i) 201 == 'A')&&(ComputerRead.charAt(i+1) == 'Z')&&(ComputerRead.charAt(i+3) == 'E')&&(ComputerRead.charAt(i+4) 202 == 'L')){ 203 // send back the antenna position <+xxx.x xx.x> 204 ComputerWrite 205 = "+"+String(ComAzim)+".0 "+String(ComElev)+".0"; 206 Serial.println(ComputerWrite); 207 208 } 209 } 210} 211 212void Rotate() { 213 // rotate the servos to the coordinates 214 received thru serial 215 // because the servo rotates in the oposite direction, 216 we have to reverse the movement 217 if (ComElev >90){ // if received 218 elevation more than 90 deg 219 ComElev = 180-ComElev; // keep it below 220 90 221 ComAzim = (180+ComAzim)%360; // and flip the antenna 222 } 223 if 224 (ComAzim > 180) { // if azim more than 180 deg 225 AzServo.write(360-ComAzim); 226 // flip the antenna 227 ElServo.write(180-ComElev); 228 } 229 else 230 { 231 AzServo.write(180-ComAzim); 232 ElServo.write(ComElev); 233 } 234} 235 236void 237 DisplayPosition() { 238 // display values 239/* 240 display.clearDisplay(); 241 242 display.setCursor(0,28); 243 display.print(ComAzim); 244 display.print(" / 245 "); 246 display.print(ComElev); 247 display.display(); 248*/ 249}
Downloadable files
Electric Diagram
Servos and board connections
Electric Diagram

Comments
Only logged in users can leave comments