Browse Source

added servo library and changed pins for GPS as it was causing problems

master
Luis Rodil-Fernandez 2 years ago
parent
commit
d7a104a404
  1. 3
      platformio.ini
  2. 56
      src/main.cpp

3
platformio.ini

@ -21,6 +21,7 @@ lib_deps =
Adafruit_GPS=https://github.com/adafruit/Adafruit_GPS/archive/refs/tags/1.7.0.zip 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 SoftwareSerial=https://github.com/plerup/espsoftwareserial/archive/refs/tags/6.16.1.zip
Time=paulstoffregen/Time@^1.6.1 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 ; NeoGPS=slashdevin/NeoGPS@^4.2.9
; SolarPosition=https://github.com/KenWillmott/SolarPosition.git

56
src/main.cpp

@ -1,5 +1,7 @@
#include <Arduino.h> #include <Arduino.h>
#include <ESP32Servo.h>
#include <SPI.h> #include <SPI.h>
#include <Wire.h> #include <Wire.h>
#include <Adafruit_GFX.h> #include <Adafruit_GFX.h>
@ -19,7 +21,10 @@
#define SCREEN_ADDRESS 0x3C #define SCREEN_ADDRESS 0x3C
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); 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); Adafruit_GPS GPS(&altserial);
uint32_t tstamp = millis(); uint32_t tstamp = millis();
@ -45,6 +50,7 @@ void init_display() {
} }
display.clearDisplay(); display.clearDisplay();
display.display();
} }
void init_gps() { void init_gps() {
@ -60,17 +66,27 @@ void init_gps() {
altserial.println(PMTK_Q_RELEASE); 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() { void setup() {
Serial.begin(115200); Serial.begin(115200);
// init_servo();
init_display(); init_display();
init_gps(); init_gps();
wmm_init(); wmm_init();
} }
void draw_sunpos() {
void ui_sunpos() {
display.clearDisplay(); display.clearDisplay();
display.setTextSize(1); display.setTextSize(1);
@ -103,6 +119,9 @@ void draw_sunpos() {
display.print(F("elevation .. ")); display.print(F("elevation .. "));
display.print((double)sun.elevation, 4); display.print((double)sun.elevation, 4);
display.println(); display.println();
display.print(F("zenith ..... "));
display.print((double)sun.zenith, 4);
display.println();
display.print(F("azimuth .... ")); display.print(F("azimuth .... "));
display.print((double)sun.azimuth, 4); display.print((double)sun.azimuth, 4);
display.println(); display.println();
@ -137,15 +156,29 @@ void debug_solar() {
// Serial.print("Antenna status: "); Serial.println((int)GPS.antenna); // 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() { 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 (c) Serial.write(c);
// if a sentence is received, we can check the checksum, parse it...
if (GPS.newNMEAreceived()) { 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 // approximately every 2 seconds or so, print out the current stats
@ -167,6 +200,7 @@ void loop() {
// calculate magnetic declination // calculate magnetic declination
E0000(GPS.latitudeDegrees, GPS.longitudeDegrees, wmmtime, &sun.declination); E0000(GPS.latitudeDegrees, GPS.longitudeDegrees, wmmtime, &sun.declination);
// prepare location and time data to call the sun position API
cLocation loc; cLocation loc;
loc.dLatitude = GPS.latitudeDegrees; loc.dLatitude = GPS.latitudeDegrees;
loc.dLongitude = GPS.longitudeDegrees; loc.dLongitude = GPS.longitudeDegrees;
@ -191,10 +225,14 @@ void loop() {
// sun.elevation = location.getSolarPosition(sun.epoch).elevation; // sun.elevation = location.getSolarPosition(sun.epoch).elevation;
// sun.azimuth = location.getSolarPosition(sun.epoch).azimuth; // sun.azimuth = location.getSolarPosition(sun.epoch).azimuth;
// servo.write( ceil(sun.elevation) );
// delay(20);
debug_solar(); debug_solar();
draw_sunpos();
//ui_sunpos();
} }
} }
// draw_sunpos();
ui_sunpos();
} // loop() } // loop()
Loading…
Cancel
Save