ALR32XX Python Library- Documentation EN
  • elc Annecy
  • Changelog
  • FAQ
  • ALR32XX sur Python
    • Installing the library
    • ALR3203
    • ALR3220
    • ALR3206D
    • ALR3206T
  • Exemples
    • Changing voltages and parameters
    • Generation of a sine and graphic display
    • F(t) generation and SQL recording
Powered by GitBook
On this page
  1. Exemples

Generation of a sine and graphic display

2nd example: https://github.com/elc-construction-electronique/Librairie-Python-ALR32XX/blob/main/Exemples/Exemple_2.py

PreviousChanging voltages and parametersNextF(t) generation and SQL recording

Last updated 3 years ago

The purpose of this is to control the supply voltage of the ALR3203 to create a low frequency sine wave. Once the voltage is sine, a load will be connected and the power supply will measure the current generated and display it graphically.

Adding the library and initializing

As in the previous example, the development libraries are added and the power supply variable is created.

import sys 
import math
import matplotlib.pyplot as plt   
sys.path.insert(0, "..")
from ALR32XX import*

The sys and math libraries do not require additional installation. Concerning matplotlib, it is most often included in the Python distributions, if not it can be downloaded by the pip.

To complete the initialization of the procedure, we need to declare a variable for our feed:

X=ALR32XX('ALR3203')

Here, the variable X will be linked to the ALR3203 connected via USB or RS232 to the computer. X therefore inherits functions from the library, for example X.Meesure_tension() to measure the voltage on the power supply channel.

Creating the sine and storing the values in lists

The idea for this development is to send to the power supply the calculated values of a sine evolving between 0 and 32V. To do this, we use a for loop with i between 0 and 360 (i represents the degree) and we send to the power supply 16*sin(i)+16.

for i in range (0,  360):
    temp=math.sin(i*3.14/180)
    temp_=(temp*16)+16
    alim.Ecrire_tension(temp_)

The power supply therefore receives a voltage value at each loop turn.

As the power supply has its values for drawing the sine, we record the values of i, time and current measured throughout the loop so that we can display a graph. Our three lists are previously declared. Everything happens in the previous for loop:

for i in range (0,  360):
    X.append(i)                  # Adding the index to the list of abcissa
    
    temp=math.sin(i*3.14/180)
    temp_=(temp*16)+16
    alim.Ecrire_tension(temp_)   # Sending the voltage value to the power supply
    
    Y1.append(temp)              # Add the value to the ordinate list 1

    valeur=alim.Mesure_courant() # Power supply current measurement
    Y2.append(valeur)            # Add the value to the ordinate list 2

On the power supply side, we observe our sine curve on an oscilloscope:

Display as a graph

The last step is to display the previously measured current values. The matplotlib library can be used to display a list of values in graphical form.

plt.plot(X, Y1,"b:o", label="voltage U")
plt.plot(X, Y2, label="current I")
plt.title("Sinus function")
plt.xlabel("t(s)")
plt.ylabel("f(t)")
plt.legend()
plt.show()

The figure you find is then similar to the one below.

2nd example