|
| 1 | +/* |
| 2 | + September 1st, 2020 |
| 3 | + SparkFun Electronics |
| 4 | + Nathan Seidle |
| 5 | +
|
| 6 | +*/ |
| 7 | + |
| 8 | +#include <Wire.h> //Needed for I2C to GPS |
| 9 | + |
| 10 | + |
| 11 | +// setting PWM properties |
| 12 | +const int freq = 5000; |
| 13 | +const int ledRedChannel = 0; |
| 14 | +const int ledGreenChannel = 1; |
| 15 | +const int resolution = 8; |
| 16 | +//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= |
| 17 | + |
| 18 | +//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= |
| 19 | +//Setup hardware serial and BT buffers |
| 20 | +#include "BluetoothSerial.h" |
| 21 | +BluetoothSerial SerialBT; |
| 22 | + |
| 23 | +HardwareSerial GPS(2); |
| 24 | +#define RXD2 16 |
| 25 | +#define TXD2 17 |
| 26 | + |
| 27 | +#define SERIAL_SIZE_RX 1024 * 16 //Using a large buffer. This might be much bigger than needed but the ESP32 has enough RAM |
| 28 | +uint8_t rBuffer[SERIAL_SIZE_RX]; //Buffer for reading F9P |
| 29 | +uint8_t wBuffer[SERIAL_SIZE_RX]; //Buffer for writing to F9P |
| 30 | +//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= |
| 31 | + |
| 32 | +//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= |
| 33 | +//Hardware connections v11 |
| 34 | +const int positionAccuracyLED_1cm = 2; |
| 35 | +const int baseStatusLED = 4; |
| 36 | +const int baseSwitch = 5; |
| 37 | +const int bluetoothStatusLED = 12; |
| 38 | +const int positionAccuracyLED_100cm = 13; |
| 39 | +const int positionAccuracyLED_10cm = 15; |
| 40 | +const int sd_cs = 25; |
| 41 | +const int zed_tx_ready = 26; |
| 42 | +const int zed_reset = 27; |
| 43 | +const int batteryLevelLED_Red = 32; |
| 44 | +const int batteryLevelLED_Green = 33; |
| 45 | +const int batteryLevel_alert = 36; |
| 46 | +//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= |
| 47 | + |
| 48 | +void setup() |
| 49 | +{ |
| 50 | + Serial.begin(115200); //UART0 for programming and debugging |
| 51 | + Serial.setRxBufferSize(SERIAL_SIZE_RX); |
| 52 | + Serial.setTimeout(1); |
| 53 | + |
| 54 | + GPS.begin(115200); //UART2 on pins 16/17 for SPP. The ZED-F9P will be configured to output NMEA over its UART1 at 115200bps. |
| 55 | + GPS.setRxBufferSize(SERIAL_SIZE_RX); |
| 56 | + GPS.setTimeout(1); |
| 57 | + |
| 58 | + Wire.begin(); |
| 59 | + |
| 60 | + Serial.println("SparkFun RTK Surveyor v1.0"); |
| 61 | + |
| 62 | + pinMode(positionAccuracyLED_1cm, OUTPUT); |
| 63 | + pinMode(positionAccuracyLED_10cm, OUTPUT); |
| 64 | + pinMode(positionAccuracyLED_100cm, OUTPUT); |
| 65 | + pinMode(baseStatusLED, OUTPUT); |
| 66 | + pinMode(bluetoothStatusLED, OUTPUT); |
| 67 | + pinMode(baseSwitch, INPUT_PULLUP); //HIGH = rover, LOW = base |
| 68 | + |
| 69 | + digitalWrite(positionAccuracyLED_1cm, LOW); |
| 70 | + digitalWrite(positionAccuracyLED_10cm, LOW); |
| 71 | + digitalWrite(positionAccuracyLED_100cm, LOW); |
| 72 | + digitalWrite(baseStatusLED, LOW); |
| 73 | + digitalWrite(bluetoothStatusLED, LOW); |
| 74 | + |
| 75 | + //SerialBT.register_callback(btCallback); |
| 76 | + if (startBluetooth() == false) |
| 77 | + { |
| 78 | + Serial.println("An error occurred initializing Bluetooth"); |
| 79 | + digitalWrite(bluetoothStatusLED, LOW); |
| 80 | + } |
| 81 | + else |
| 82 | + { |
| 83 | + digitalWrite(bluetoothStatusLED, HIGH); |
| 84 | + } |
| 85 | + |
| 86 | + //myGPS.enableDebugging(); //Enable debug messages over Serial (default) |
| 87 | +} |
| 88 | + |
| 89 | +void loop() |
| 90 | +{ |
| 91 | + |
| 92 | + delay(10); //Required if no other I2C or functions are called |
| 93 | + |
| 94 | +} |
0 commit comments