🛠 Faire clignoter la LED embarquée et lire la batterie

Arduino MKR GSM 1400 · debutant · Schéma : IMG-mkr-gsm-1400-debutant-1-mkrgsm-led-clignotant.svg — Vue de dessus de la carte MKR GSM 1400 avec la LED embarquée (broche D6) et les pads batterie LiPo mis en évidence.

Objectives

Get started with the Arduino MKR GSM 1400 without using the cellular module: blink the onboard LED (pin D6, LED_BUILTIN) and read the LiPo battery voltage via the analog channel ADC_BATTERY (channel 32, 12-bit ADC). This tutorial validates the USB port, the SAM-BA bootloader, and the serial console before any GSM manipulation, where power supply issues are frequent.

Hardware

Complete code

// LED embarquee D6 + lecture brute de la batterie (module GSM inutilise)
void setup {
  pinMode(LED_BUILTIN, OUTPUT);   // LED_BUILTIN = broche 6 (variant.h du core)
  Serial.begin(9600);             // Sur SAMD21, Serial == SerialUSB (CDC)
}

void loop {
  digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));  // bascule a chaque tour
  int raw = analogRead(ADC_BATTERY);  // canal 32, ADC 12 bits
  Serial.print("VBAT raw: ");
  Serial.println(raw);
  delay(500);
}

Expected verification

After double-clicking the RST button and then uploading (using the bossac tool), the onboard LED blinks approximately every 500 ms and the USB console (9600 baud) displays a raw value that follows the battery charge. Without a battery, the reading changes or falls to a fixed value: this is normal, as the voltage sensor (ADC_BATTERY) depends on the actual board power supply.

Common errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials