You’re right, the Artemis Nano itself can’t directly sense a Lipo battery. But, we can definitely check for USB connection using code. Here’s a quick example:
C++
#include <Arduino.h>
const int ledPin = // Replace with your LED pin number (e.g., 13)
void setup() {
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
// Check USB power status
bool isUsbConnected = !PIN_ERROR && PIN_GET(USB_VBUS);
if (isUsbConnected) {
Serial.println(“USB Connected!”);
digitalWrite(ledPin, HIGH); // Turn on LED if USB connected
} else {
Serial.println(“No USB Detected”);
digitalWrite(ledPin, LOW); // Turn off LED if no USB
}
delay(500);
}
Explanation:
Include Arduino.h for core functions.
Define an LED pin to use for visual indication (replace the number with your actual LED pin).
In setup(), initialize the LED pin as output and start serial communication for debugging.
In loop(), a variable isUsbConnected is created. The !PIN_ERROR && PIN_GET(USB_VBUS) part checks the USB power pin state. If there’s no error and the pin is high (indicating voltage), it means USB is connected.
An if statement checks isUsbConnected. If true (USB connected), a message is printed and the LED turns on. Otherwise, a message is printed and the LED turns off.
delay() adds a pause between checks.
Notes:
Replace ledPin with your actual LED pin number.
This code assumes your USB VBUS pin is connected to a digital pin. Check your Artemis Nano schematic for the correct pin.
This code won’t tell you if a charger is connected, only if USB power is present.
This should give you a good starting point for detecting USB connection on your Artemis Nano!