USB cable detection

Hi teachers~!

I am using a Lipo battery connected to Artemis nano.

I know that Artemis nano cannot check if Lipo is connected.

So how do I know if the charger is connected to USB C or if the USB Cable is connected?

(Regardless of whether there is a battery or not)

Please help me with a detailed code example.

Benscoffee:
Hi teachers~!

I am using a Lipo battery connected to Artemis nano.

I know that Artemis nano cannot check if Lipo is connected.

So how do I know if the charger is connected to USB C or if the USB Cable is connected?

(Regardless of whether there is a battery or not)

Please help me with a detailed code example.

- So how can I know if the charger is connected to USB C port of the board or if the USB Cable is connected to use power?
  • Please help me with a detailed arduino code example.

The board has NO sense-wire between the Apollo3 processor and the power supply circuit. It will only get the 3v3 based on the input voltage from the Lipo or USB.

You could try to solder wires in the right place on the board (e.g. on the anode side of D3 + voltage divider) but you have to study the schematics for that. Also, it will impact the warranty on the board.

Thank you, Paul~!

condition : The LCD is connected to the Nano board

If the C Type cable is disconnected, the screen turns off, and when it is connected, the screen turns on is impossible, right?

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!

Thank you ReahaTaul!

I will check it ~!