clignotante.py

LattePanda 3 Delta (id: lattepanda-3) · File : clignotante.py · Language : Python · Use case : Faire clignoter une LED depuis Python (broche du MCU)

The LattePanda pattern: the Python script runs on the x86 PC, the physical pin lives on the ATmega32U4, and PinPong bridges them in one line. The Arduino world becomes a PC library.

Hardware required

A LattePanda 3 Delta (x86 Intel N5105, Windows 10/11 or Ubuntu) with its Arduino-compatible co-processor (ATmega32U4) wired to the two 50-pin headers. 1 LED + 330 Ω resistor on the 50-pin header (MCU pin D13).

Wiring

Anode on the header's D13 pin (see the schematic), 330 Ω resistor, GND on a GND pin of the same header.

How it works

Board().begin() opens the internal serial port to the MCU; Pin(D13).write_digital drives the pin Arduino-style. The PinPong firmware must be flashed on the 32U4 (shipped with the library). Host side: pip install pinpong then python3. MCU side: the ATmega32U4 shows up as a COM port — program it with the Arduino IDE (« Arduino Leonardo » board).

Going further

Modulate the period with a sensor, or drive two LEDs from two Python threads.

clignotante.py

#!/usr/bin/env python3
# Clignotement LED via PinPong : Python cote hote, GPIO sur l'ATmega32U4.
# Installation : pip install pinpong
from pinpong.board import Board, Pin
from pinpong.extension.unipiot import *   # chargement standard
import time

Board().begin()                    # detecte le MCU (port serie interne)
led = Pin(Pin.D13, Pin.OUT)

print("Clignotement D13 (Ctrl-C pour arreter)")
try:
    while True:
        led.write_digital(1)
        print("ON")
        time.sleep(1)
        led.write_digital(0)
        print("OFF")
        time.sleep(1)
except KeyboardInterrupt:
    led.write_digital(0)
    print("Arret propre")

← Back to the board