Skip to content

Output devices

Group assignment:

  • Measure the power consumption of an output device.

Let’s measure the power consumption of a DC motor using an output card.

Siglent Oscilloscope

Siglent oscilloscopes are a range of electronic test equipment produced by the Chinese company Siglent Technologies. These oscilloscopes are widely used in various industries, including electronics, telecommunications, automotive, medical and education.

Measure

The picture below shows the wiring of the board used and the motor. We’ve used an L298N module to control the motor. Power, voltage and current variations will be read on the oscilloscope.

The code for ordering the motor is shown below:

import machine
import utime

# Définition des broches
borneENA = machine.PWM(machine.Pin(26))
borneIN1 = machine.Pin(27, machine.Pin.OUT)
borneIN2 = machine.Pin(28, machine.Pin.OUT)
borneIN3 = machine.Pin(29, machine.Pin.OUT)
borneIN4 = machine.Pin(6, machine.Pin.OUT)
borneENB = machine.PWM(machine.Pin(5))

# Constantes du programme
delaiChangementVitesse = 20
vitesseMinimale = 60
vitesseMaximale = 255

# Sens de rotation
MARCHE_AVANT = 'V'
MARCHE_ARRIERE = 'R'

# Fonction de configuration du sens de rotation
def configurerSensDeRotationPontA(sensDeRotation):
    if sensDeRotation == MARCHE_AVANT:
        borneIN1.value(1)
        borneIN2.value(0)
    elif sensDeRotation == MARCHE_ARRIERE:
        borneIN1.value(0)
        borneIN2.value(1)

# Fonction de changement de vitesse du moteur
def changeVitesseMoteurPontA(nouvelleVitesse):
    borneENA.duty_u16(nouvelleVitesse * 256)  # Le RP2040 utilise une résolution de 16 bits pour le PWM

# Configuration des broches en sortie
borneENA.freq(1000)  # Fréquence du signal PWM
borneENB.freq(1000)
borneIN1.value(0)
borneIN2.value(0)
borneIN3.value(0)
borneIN4.value(0)

# Boucle principale
while True:
    # MARCHE AVANT
    configurerSensDeRotationPontA(MARCHE_AVANT)
    for vitesse in range(vitesseMinimale, vitesseMaximale):
        changeVitesseMoteurPontA(vitesse)
        utime.sleep_ms(delaiChangementVitesse)

    for vitesse in range(vitesseMaximale, vitesseMinimale, -1):
        changeVitesseMoteurPontA(vitesse)
        utime.sleep_ms(delaiChangementVitesse)

    # Pause
    changeVitesseMoteurPontA(0)
    utime.sleep(1)

    # MARCHE ARRIERE
    configurerSensDeRotationPontA(MARCHE_ARRIERE)
    for vitesse in range(vitesseMinimale, vitesseMaximale):
        changeVitesseMoteurPontA(vitesse)
        utime.sleep_ms(delaiChangementVitesse)

    for vitesse in range(vitesseMaximale, vitesseMinimale, -1):
        changeVitesseMoteurPontA(vitesse)
        utime.sleep_ms(delaiChangementVitesse)

    # Pause
    changeVitesseMoteurPontA(0)
    utime.sleep(1)

Let’s watch the video!