diff --git a/README.md b/README.md index f509275..24f4675 100755 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ -# NMEA Monitor 1 -A small portable NMEA0183 comunications monitor. +# NMEA Simulator 1 +A small portable NMEA0183 comunications simulator. diff --git a/firmware/v01/v01.ino b/firmware/v01/v01.ino index b8ae96d..39f3c72 100644 --- a/firmware/v01/v01.ino +++ b/firmware/v01/v01.ino @@ -1,15 +1,15 @@ /********************************************************************* NMM-1 -NMEA0183 serial monitor. +NMEA0183 serial simulator. By Jony Silva Wed 24 Jan 23:11:25 GMT 2018 *********************************************************************/ // Libraries to be included -//#include -//#include +#include +#include #include #include #include @@ -40,10 +40,9 @@ Adafruit_SSD1306 display(OLED_RESET); void one(); // Menu one void two(); // Menu two void three(); // Menu three -void four(); // Menu four void read_serial(); // Menu that reads the serial void write_serial(); // Menu that writes to serial -void config(); // Configuration menu +void config_nmm(); // Configuration menu void batt_icon(); // Draws the battery icon acording to value @@ -55,6 +54,13 @@ int OK_state = OFF; // Holds state for OK, either ON or OFF int DOWN_state = OFF; // Holds state for DOWN, either ON or OFF int CANCEL_state = OFF; // Holds state for CANCEL, either ON or OFF int batt_val = 0; // Holds the value of battery voltage +int incomingByte; // Serial incoming byte buffer +int lines = 0; +int chars = 0; +char sentence[68]; +String s; +int i; +int read_s = 0; // Create SoftwareSerial object and designate pins @@ -62,7 +68,7 @@ int batt_val = 0; // Holds the value of battery voltage void setup() { // BEGIN SETUP ------------------------------------ - // Configure buttons and led's has inputs or outputs + pinMode(led1, OUTPUT); // Led 1 is an output pinMode(led2, OUTPUT); // Led 2 is an output pinMode(UP, INPUT); // Switch 1 is an input @@ -70,13 +76,14 @@ void setup() { // BEGIN SETUP ------------------------------------ pinMode(DOWN, INPUT); // Switch 3 is an input pinMode(CANCEL, INPUT); // Switch 4 is an input - // Define the starting state of the led's digitalWrite(led1,HIGH); // Turn off led 1 digitalWrite(led2,HIGH); // Turn off led 2 // set the data rate for the SoftwareSerial port - mySerial.begin(9600); + + // set the data rate for the Serial port + Serial.begin(4800); // by default, we'll generate the high voltage from the 3.3v line internally! (neat!) display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 128x32) @@ -104,7 +111,7 @@ void setup() { // BEGIN SETUP ------------------------------------ display.setTextSize(2); display.setTextColor(WHITE); - display.setCursor(36,12); + display.setCursor(36,22); display.println("NMM-1"); display.display(); delay(3000); @@ -126,10 +133,7 @@ ISR(TIMER1_COMPA_vect) // menuState = 1; } else if (menuState == 3) { - menuState = 4; - } - else if (menuState == 4) { - menuState = 1; + menuState = 2; } while (!rUP); // Check if button is still pressed do nothing } @@ -145,9 +149,6 @@ ISR(TIMER1_COMPA_vect) // else if (menuState == 3) { menuState = 3; } - else if (menuState == 4) { - menuState = 3; - } while (!rDOWN); // Check if button is still pressed do nothing } @@ -165,10 +166,6 @@ ISR(TIMER1_COMPA_vect) // menuState = 12; prevMenu = 3; } - else if (menuState == 4) { - menuState = 11; - prevMenu = 4; - } while (!rOK); // Check if button is still pressed do nothing } @@ -183,9 +180,6 @@ ISR(TIMER1_COMPA_vect) // else if (prevMenu == 3) { menuState = 3; } - else if (prevMenu == 4) { - menuState = 4; - } while (!rCANCEL); // Check if button is still pressed do nothing } } @@ -197,42 +191,59 @@ void loop() { batt_val = analogRead(batt); -// Routine to check the battery analog value for calibration -/* display.drawRect(0, 8, 168, 24, BLACK); - display.display(); - display.clearDisplay(); - display.setTextSize(1); - display.setTextColor(WHITE); - display.setCursor(50,18); - display.println(batt_val); - batt_icon(); - display.display();*/ - - - if (menuState == 1) { one(); + mySerial.end(); + read_s = 0; } else if (menuState == 2) { two(); + mySerial.end(); + read_s = 0; } else if (menuState == 3) { three(); - } - else if (menuState == 4) { - four(); + mySerial.end(); + read_s = 0; } else if (menuState == 10) { + if (read_s == 0) { + mySerial.begin(4800); + read_s = 1; + display.clearDisplay(); + display.setTextSize(1); + display.setTextColor(WHITE); + display.setCursor(1,17); + display.println("RS-422 to USB"); + display.println("Sending..."); + batt_icon(); + display.display(); + } read_serial(); } else if (menuState == 11) { - write_serial(); + if (read_s == 0) { + mySerial.begin(4800); + read_s = 1; + display.clearDisplay(); + display.setTextSize(1); + display.setTextColor(WHITE); + display.setCursor(1,17); + display.println("Sending GPS....."); + batt_icon(); + display.display(); + } + write_serial(); } else if (menuState == 12) { - config(); + config_nmm(); + mySerial.end(); + read_s = 0; } else { one(); + mySerial.end(); + read_s = 0; } } @@ -295,100 +306,64 @@ void batt_icon (void) { void one (void) { - display.drawRect(0, 8, 168, 24, BLACK); - display.display(); - display.clearDisplay(); - display.setTextSize(1); - display.setTextColor(WHITE); - display.setCursor(1,12); - display.println("Read NMEA0183 <--"); - display.setCursor(1,22); - display.println("Write NMEA0183"); - batt_icon(); - display.display(); - + display.clearDisplay(); + display.setTextSize(1); + display.setTextColor(WHITE); + display.setCursor(1,12); + display.println("RS422 ==> USB <--"); + display.setCursor(1,22); + display.println("Send NMEA0183"); + display.setCursor(1,32); + display.println("Config NMEA0183"); + batt_icon(); + display.display(); } void two (void) { - display.drawRect(0, 8, 168, 24, BLACK); - display.display(); - display.clearDisplay(); - display.setTextSize(1); - display.setTextColor(WHITE); - display.setCursor(1,12); - display.println("Read NMEA0183"); - display.setCursor(1,22); - display.println("Write NMEA0183 <--"); - batt_icon(); - display.display(); - + display.clearDisplay(); + display.setTextSize(1); + display.setTextColor(WHITE); + display.setCursor(1,12); + display.println("RS422 ==> USB"); + display.setCursor(1,22); + display.println("Send NMEA0183 <--"); + display.setCursor(1,32); + display.println("Config NMEA0183"); + batt_icon(); + display.display(); } void three (void) { - display.drawRect(0, 8, 168, 24, BLACK); - display.display(); - display.clearDisplay(); - display.setTextSize(1); - display.setTextColor(WHITE); - display.setCursor(1,12); - display.println("Write NMEA0183"); - display.setCursor(1,22); - display.println("Config NMEA0183 <--"); - batt_icon(); - display.display(); - -} - -void four (void) { - - display.drawRect(0, 8, 168, 24, BLACK); - display.display(); - display.clearDisplay(); - display.setTextSize(1); - display.setTextColor(WHITE); - display.setCursor(1,12); - display.println("Write NMEA0183 <--"); - display.setCursor(1,22); - display.println("Config NMEA0183"); - batt_icon(); - display.display(); - + display.clearDisplay(); + display.setTextSize(1); + display.setTextColor(WHITE); + display.setCursor(1,12); + display.println("RS422 ==> USB"); + display.setCursor(1,22); + display.println("Send NMEA0183"); + display.setCursor(1,32); + display.println("Config NMEA0183 <--"); + batt_icon(); + display.display(); } void read_serial (void) { - display.drawRect(0, 8, 168, 24, BLACK); - display.display(); - display.clearDisplay(); - display.setTextSize(1); - display.setTextColor(WHITE); - display.setCursor(1,17); - display.println("Lets Read :)"); - batt_icon(); - display.display(); - + if (mySerial.available()) { + Serial.write(mySerial.read()); + } } void write_serial (void) { - display.drawRect(0, 8, 168, 24, BLACK); - display.display(); - display.clearDisplay(); - display.setTextSize(1); - display.setTextColor(WHITE); - display.setCursor(1,17); - display.println("Lets Write :)"); - batt_icon(); - display.display(); - + mySerial.print("$GPGGA,090000.10,6350.37829338,N,02225.18272240,W,1,05,2.87,160.00,M,-21.3213,M,,*64"); + mySerial.println(); } -void config (void) { +void config_nmm (void) { - display.drawRect(0, 8, 168, 24, BLACK); - display.display(); display.clearDisplay(); display.setTextSize(1); display.setTextColor(WHITE); @@ -396,5 +371,4 @@ void config (void) { display.println("BLOCKED"); batt_icon(); display.display(); - }