diff --git a/platformio.ini b/platformio.ini index 2eec753..1238fc1 100644 --- a/platformio.ini +++ b/platformio.ini @@ -21,6 +21,7 @@ lib_deps = Adafruit_GPS=https://github.com/adafruit/Adafruit_GPS/archive/refs/tags/1.7.0.zip SoftwareSerial=https://github.com/plerup/espsoftwareserial/archive/refs/tags/6.16.1.zip Time=paulstoffregen/Time@^1.6.1 - SolarPosition=https://github.com/KenWillmott/SolarPosition.git + ESP32Servo=https://github.com/madhephaestus/ESP32Servo/archive/refs/tags/0.10.0.zip ; NeoGPS=slashdevin/NeoGPS@^4.2.9 +; SolarPosition=https://github.com/KenWillmott/SolarPosition.git diff --git a/src/main.cpp b/src/main.cpp index b038daf..b28d733 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,5 +1,7 @@ #include +#include + #include #include #include @@ -19,7 +21,10 @@ #define SCREEN_ADDRESS 0x3C Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); -SoftwareSerial altserial(14, 12); +Servo servo; +int servoPin = 13; + +SoftwareSerial altserial(5, 4); // rx, tx Adafruit_GPS GPS(&altserial); uint32_t tstamp = millis(); @@ -45,6 +50,7 @@ void init_display() { } display.clearDisplay(); + display.display(); } void init_gps() { @@ -60,17 +66,27 @@ void init_gps() { altserial.println(PMTK_Q_RELEASE); } +// void init_servo() { +// ESP32PWM::allocateTimer(0); +// ESP32PWM::allocateTimer(1); +// ESP32PWM::allocateTimer(2); +// ESP32PWM::allocateTimer(3); +// servo.setPeriodHertz(50);// Standard 50hz servo +// servo.attach(servoPin, 500, 2400); +// } + // /////////////////////////////////////////////////////////////////////////////////////// // /////////////////////////////////////////////////////////////////////////////////////// // /////////////////////////////////////////////////////////////////////////////////////// void setup() { Serial.begin(115200); +// init_servo(); init_display(); init_gps(); wmm_init(); } -void draw_sunpos() { +void ui_sunpos() { display.clearDisplay(); display.setTextSize(1); @@ -103,6 +119,9 @@ void draw_sunpos() { display.print(F("elevation .. ")); display.print((double)sun.elevation, 4); display.println(); + display.print(F("zenith ..... ")); + display.print((double)sun.zenith, 4); + display.println(); display.print(F("azimuth .... ")); display.print((double)sun.azimuth, 4); display.println(); @@ -137,15 +156,29 @@ void debug_solar() { // Serial.print("Antenna status: "); Serial.println((int)GPS.antenna); } +void servo_sweep() { + int pos; + + for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees + // in steps of 1 degree + servo.write(pos); // tell servo to go to position in variable 'pos' + delay(15); // waits 15ms for the servo to reach the position + } + for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees + servo.write(pos); // tell servo to go to position in variable 'pos' + delay(15); // waits 15ms for the servo to reach the position + } +} + + void loop() { - char c = GPS.read(); - // // if you want to debug, this is a good time to do it! + //char c = GPS.read(); + // debug print //if (c) Serial.write(c); - // if a sentence is received, we can check the checksum, parse it... if (GPS.newNMEAreceived()) { - if (!GPS.parse(GPS.lastNMEA())) // this also sets the newNMEAreceived() flag to false - return; // we can fail to parse a sentence in which case we should just wait for another + if (!GPS.parse(GPS.lastNMEA())) + return; } // approximately every 2 seconds or so, print out the current stats @@ -167,6 +200,7 @@ void loop() { // calculate magnetic declination E0000(GPS.latitudeDegrees, GPS.longitudeDegrees, wmmtime, &sun.declination); + // prepare location and time data to call the sun position API cLocation loc; loc.dLatitude = GPS.latitudeDegrees; loc.dLongitude = GPS.longitudeDegrees; @@ -191,10 +225,14 @@ void loop() { // sun.elevation = location.getSolarPosition(sun.epoch).elevation; // sun.azimuth = location.getSolarPosition(sun.epoch).azimuth; + // servo.write( ceil(sun.elevation) ); + // delay(20); + debug_solar(); - draw_sunpos(); + //ui_sunpos(); } } - // draw_sunpos(); + ui_sunpos(); + } // loop()