nano-g2.cpp 946 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include <Arduino.h>
  2. #include "nano-g2.h"
  3. #ifdef NANO_G2_ULTRA
  4. #include <Wire.h>
  5. void NanoG2Ultra::begin()
  6. {
  7. NRF52Board::begin();
  8. // set user button
  9. pinMode(PIN_BUTTON1, INPUT);
  10. // the external notification circuit is shared for both buzzer and led
  11. pinMode(EXT_NOTIFY_OUT, OUTPUT);
  12. digitalWrite(EXT_NOTIFY_OUT, LOW);
  13. pinMode(GPS_EN, OUTPUT); // Initialize GPS power pin
  14. Wire.begin();
  15. pinMode(SX126X_POWER_EN, OUTPUT);
  16. digitalWrite(SX126X_POWER_EN, HIGH);
  17. delay(10);
  18. }
  19. uint16_t NanoG2Ultra::getBattMilliVolts()
  20. {
  21. int adcvalue = 0;
  22. analogReference(AR_INTERNAL_3_0);
  23. analogReadResolution(12);
  24. delay(10);
  25. // ADC range is 0..3000mV and resolution is 12-bit (0..4095)
  26. adcvalue = analogRead(PIN_VBAT_READ);
  27. // Convert the raw value to compensated mv, taking the resistor-
  28. // divider into account (providing the actual LIPO voltage)
  29. return (uint16_t)((float)adcvalue * REAL_VBAT_MV_PER_LSB);
  30. }
  31. #endif