Oak

🌳 An outdoor LoRa-GPS tracker with an E-Ink display 🔑

power 18650
wireless LoRa,
sensor GPS, E-Ink
mcu SAMD21G18
bom items 82
bom cost USD $78.93
vendors 6
completed July 2022

Measure battery voltage

measure battery medium

Measure LiPo battery voltage


Steps

  1. Plug in the Oak PCB to the computer
  2. (Option A) Ensure the PCB can be detected with ls -al /dev/cu.usbmodem and arduino-cli board list. Run make to compile and upload the code to the board. (Option A) Ensure the PCB can be detected with <code>ls -al /dev/cu.usbmodem</code> and <code>arduino-cli board list</code>. Run <code>make</code> to compile and upload the code to the board.
  3. (Option B) Ensure the board can be detected with Arduino IDE. Compile and upload the code to the board. (Option B) Ensure the board can be detected with Arduino IDE. Compile and upload the code to the board.

Serial console

Serial output from the firmware.

Code

Download code
#define VBATPIN A0
#define LEDPIN 2

void setup() {
  pinMode(LEDPIN, OUTPUT);

  SerialUSB.begin(9600);
  delay(1000);

  SerialUSB.println("Start battery voltage measurement!");
}

void loop() {
  float measuredvbat = analogRead(VBATPIN);

  for (int i = 0; i < 10; i++) {
    measuredvbat += analogRead(VBATPIN);
    delay(10);
  }

  // Take the average of 10 analog values
  measuredvbat /= 10;

  SerialUSB.print("Analog read: ");
  SerialUSB.print(measuredvbat);

  // Potential divider of equal resistance
  measuredvbat *= 2;

  // Or the reference voltage E.g. 2.8V, 3.3V, 5V, 3.7V
  measuredvbat *= 3.3;

  // Measured digital value with multimeter (instead of 1024)
  // Convert to voltage
  measuredvbat /= 1125;


  SerialUSB.print("   VBat: ");
  SerialUSB.print(measuredvbat);
  SerialUSB.println("V");

  digitalWrite(LEDPIN, HIGH);
  SerialUSB.println("HIGH");
  delay(2000);

  digitalWrite(LEDPIN, LOW);
  SerialUSB.println("LOW");
  delay(2000);
}

Makefile

BOARD?=hutscape:samd:oak
PORT := $(shell ls /dev/cu.usbmodem*)
BUILD=build

.PHONY: default lint all flash clean

default: lint all flash clean

lint:
	cpplint --extensions=ino --filter=-legal/copyright,-whitespace/line_length,-readability/casting,-readability/todo *.ino

all:
	arduino-cli compile --fqbn $(BOARD) --output-dir $(BUILD) ./

flash:
	arduino-cli upload -p /dev/cu.usbmodem14101 --fqbn $(BOARD) --input-dir $(BUILD) --verbose

clean:
	rm -r build

References