2016. 2. 8. 03:39
무선 송수신기 + GPS + LCD 작품/무선 GPS 송수신2016. 2. 8. 03:39
다수의 receiver들이 사방에 있으면서 자신의 gps값을 공중으로 전송시킵니다.
또한 center에는 데이터를 받는 하나의 수신 모듈이 있습니다.
center는 receiver의 gps값을 읽어드립니다.
이 모듈을 컴퓨터와 연결 되어있으며 이 데이터를 컴퓨터가 받은 후 컴퓨터 화면 창에 위치를 찍어줍니다.
receiver는 아두이노에 GPS, LCD, RH447이 연결되어 있습니다.
center는 오로지 RH447과 아두이노로만 구성되어 있으며 단순이 값을 읽어들이는 일만 처리합니다.
receiver의 코드
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | #include "SoftwareSerial.h" //wireless trans #include "TinyGPS.h" //GPS #include <LiquidCrystal.h> //LCD #define HEMISPHERE_PIN 13 #define GPS_RX_PIN 5 #define GPS_TX_PIN 6 #define USERID 333333 SoftwareSerial mySerial(5,6); //wireless trans TinyGPS gps;//GPS SoftwareSerial ss(GPS_RX_PIN, GPS_TX_PIN); LiquidCrystal lcd(12,11,10,9,8,7); //LCD //wireless trans & GPS long lat, lon; char buffer_id[7], buffer_lat[13], buffer_lon[13]; int count_trans = 0; //LCD long display_lat=0, display_lon = 0; int i = 1; int count; // ... int check_gps = 0; // ! void setup() { Serial.begin(9600); mySerial.begin(9600); ss.begin(9600); lcd.begin(16,2); pinMode(HEMISPHERE_PIN, OUTPUT); digitalWrite(HEMISPHERE_PIN, LOW); } void loop() { read_GPS(); //make lat and lon to three num display_lat = lat%1000; display_lon = lon%1000; //converting number to string ltoa(USERID, buffer_id, 10); ltoa(lat, buffer_lat, 10); ltoa(lon, buffer_lon, 10); //send GPS value to center if(count_trans > 30){ //sending speed mySerial.print(buffer_id); mySerial.print("i"); mySerial.print(buffer_lat); mySerial.print("t"); mySerial.print(buffer_lon); mySerial.print("n"); count_trans = 0; delay(10); //because of multiple serial comunication } //count_trans++ count_trans++; //-----------------------------LCD if(display_lat == 0 && display_lon == 0) loading(); else { print_3num(display_lat, 0, 0);//first line if(check_gps > 200) // ! time print_text('!', 3, 0); else print_text('.', 3, 0); print_3num(display_lon, 4, 0); print_text('/', 7, 0); print_3num(4, 0, 1);//second line print_text('.', 3, 1); print_3num(5, 4, 1); } print_3num(3, 8, 0); print_text('/', 7, 1); print_3num(6, 8, 1); delay(10); //count looop count++; check_gps++; if(count == 25) {i++; //the number of dot, that is increased by count count =0;} } void print_3num(int n, int p1, int p2) { if(n>99) { lcd.setCursor(p1, p2); lcd.print(n); } else if(n>9) { lcd.setCursor(p1, p2); lcd.print("0"); lcd.setCursor(p1+1, p2); lcd.print(n); } else if(n>=0) { lcd.setCursor(p1, p2); lcd.print("00"); lcd.setCursor(p1+2, p2); lcd.print(n); } } void print_text(char a, int p1, int p2) { lcd.setCursor(p1, p2); lcd.write(a); } void loading(void) { //first line lcd.setCursor(0,0); lcd.print("Loading"); print_text('/', 7, 0); //second line lcd.setCursor(0, 1); lcd.print("."); lcd.setCursor(0, 1); print_text('/', 7, 1); print_3num(6, 8, 1); if(i==7)//reset { lcd.setCursor(0, 1); lcd.print(". "); i=1; } lcd.setCursor(i, 1);//... lcd.print("."); } void read_GPS(void) { while (ss.available()) { int c = ss.read(); Serial.write(c); if (gps.encode(c)) { unsigned long fix_age; gps.get_position(&lat, &lon, &fix_age); if (fix_age == TinyGPS::GPS_INVALID_AGE ) Serial.println("No fix ever detected!"); else if (fix_age > 2000) Serial.println("Data is getting STALE!"); else Serial.println("Latitude and longitude valid!"); Serial.print("Lat: "); Serial.print(lat); Serial.print(" Lon: "); Serial.println(lon); if (lat < 0) digitalWrite(HEMISPHERE_PIN, HIGH); else digitalWrite(HEMISPHERE_PIN, LOW); check_gps=0; break; } } } | cs |
center의 코드
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | //receive #include <SoftwareSerial.h> SoftwareSerial mySerial(5,6); char char_value = 0, pre_char = 0; long long_value = 0; long id_val = 0, lon_val = 0, lat_val = 0; char lon_char[13] = {'0'}, lat_char[13] = {'0'}; int nullLoc = 0; const char id = 'i', lat = 't', lon = 'n'; void setup() { Serial.begin(9600); mySerial.begin(9600); } void loop() // 반복 { if (mySerial.available()) { char_value = mySerial.read(); if(isDigit(char_value)) { long_value = (long_value*10)+(char_value - '0'); } else if(char_value == id) { id_val = long_value; long_value = 0; Serial.print("<"); Serial.print(id_val); delay(5); } else if(char_value == lat) { lat_val = long_value; long_value = 0; //debugging //Serial.print(" , origin lat: "); Serial.print(lat_val); //converint num to string ltoa(lat_val, lat_char, 10); //NULL location NULL_location(&nullLoc, lat_char); //input dot inputDOT(nullLoc, lat_char); Serial.print(","); Serial.print(lat_char); delay(5); } else if(char_value == lon) { if(pre_char != 'o'){ lon_val = long_value; long_value = 0; //debugging //Serial.print(" , origin lon: "); Serial.print(lon_val); //converint num to string ltoa(lon_val, lon_char, 10); //NULL location NULL_location(&nullLoc, lon_char); //input dot inputDOT(nullLoc, lon_char); Serial.print(","); Serial.print(lon_char); Serial.println(">"); delay(5); } pre_char = 0; } else if(char_value == 'o' || char_value == 'O') { pre_char = char_value; id_val = long_value; long_value = 0; Serial.print("<"); Serial.println(id_val); delay(5); } } } void NULL_location(int * val, char * charPtr) { int count = 0; while(charPtr[count] != NULL) count = count+1; *val = count; } void inputDOT(int val, char * charPtr) { int count = 0; while(count<6) { charPtr[val+1-count] = charPtr[val-count]; count++; } charPtr[val - 5] = '.'; } | cs |
'작품 > 무선 GPS 송수신' 카테고리의 다른 글
무선송수신모듈 RH447 (0) | 2016.02.08 |
---|---|
GPS 값을 받아서 LCD제어 (0) | 2016.02.08 |