Wednesday 16 2020

Matplotlib Learning Notes - Part 9 (Creating voltage and current lists for plotting)

Matplotlib Learning Notes - Part 9 (Creating voltage and current lists for plotting)

Below is the python program to create the voltage and current lists for plotting the I-V curve.

The two lists created are:

  VoltageList     = [0.1, 0.2, 0.3, 0.4, 0.5, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 194.0, 206.0, 221.0, 241.0, 250.0, 271.0, 486.0, 488.0, 490.0, 492.0, 495.0, 498.0, 500.0]

  CurrentList     = [0.02, 0.02, 0.03, 0.05, 0.06, 0.11, 0.24, 0.34, 0.46, 0.57, 0.8, 0.78, 1.01, 1.11, 1.21, 1.32, 1.41, 1.51, 1.6, 1.7, 1.88, 1.88, 1.88, 1.88, 1.88, 1.88, 1.88, 1.95, 2.06, 2.32, 2.32, 2.49, 2.63]

Next step is to use the two lists to plot the I-V curve.

# diodeplot15.py tlfong01 2020dec16hkt2214

# Description of program

#   Part A - Background

#     1. This Rpi4B Thonny python 3.7.3 program is used for matplotlib newbies to learn how to use the very basic

#        the baisc plotting functions.  

#     2. The tunnel diode I-V measurement dictionary is a list of 33 pairs of I-V numbers, each pair corresponding to

#        a point in the two dimenionl graph, where Y-axia is current fn X-axis voltage of the diode under test.

#     3. Version 1 of the experiment uses a simple manual adjustable voltage source to power the diode, and two

#        multi-meters are used by hand to take the current and voltage readings and input to an Excel worksheet

#        for subsequent data analysis and graph plotting.

#     4. Version 2 of the same experiment is trying to use Rpi4B python to control a digital 12-bit DAC and two

#        12-bit ADC's to measure current through the diode and also voltage across it.

#     5. The test data used for this program is the raw data of one set of 33 pairs of numbers, with each pair

#        represents one measuremnt current and associated voltage.

#     6. For this feasibility test program, the Excel worksheet of 33 rows of data has already been manually copied

#        and pasted to a python dictionary.

#   Part B - Description of the Tunnel Diode I-V Curv Plotting Function diodePlot()

#     1. Convert the python dictionary data into two lists, one containg 33 current values, the ohter 33 voltage

#        values.

#     2. Use the matplotlib module to plot the current values vs the voltage values. 

# Description of function diodePlot()

# *** Diode Dictionariesy ***

diodeDataDictionary01 = {

  'Title'           : 'Diode Data Dictionary', 

  'Version'         : 'v0.8',

  'Date'            : '2020dec16hkt2109',

  'Author'          : 'tlfong01',

  'Description'     : 'Inputs a diode dictionary and plots the I-V curve',

  'Measurements'    :

  { '2BS4B-01'  : { 'DiodeName'      : '2SB4B',

                    'SampleNum'      : '1', 

    'I2cBusName'     : 'I2cBus0',

                    'DvBaseAddrName' : '0x20',

    'DataPoints' : {  '0'  : {'mV' :   0.10, 'mA': 0.02, 'Zone' : '1'},

          '1'  : {'mV' :   0.20, 'mA': 0.02, 'Zone' : '1'},

          '2'  : {'mV' :   0.30, 'mA': 0.03, 'Zone' : '1'},

          '3'  : {'mV' :   0.40, 'mA': 0.05, 'Zone' : '1'},

          '4'  : {'mV' :   0.50, 'mA': 0.06, 'Zone' : '1'},

          '5'  : {'mV' :   1.00, 'mA': 0.11, 'Zone' : '1'},

          '6'  : {'mV' :   2.00, 'mA': 0.24, 'Zone' : '1'},

          '7'  : {'mV' :   3.00, 'mA': 0.34, 'Zone' : '1'},

          '8'  : {'mV' :   4.00, 'mA': 0.46, 'Zone' : '1'},

          '9'  : {'mV' :   5.00, 'mA': 0.57, 'Zone' : '1'},

         '10'  : {'mV' :   6.00, 'mA': 0.80, 'Zone' : '1'},

         '11'  : {'mV' :   7.00, 'mA': 0.78, 'Zone' : '1'},

         '12'  : {'mV' :   9.00, 'mA': 1.01, 'Zone' : '1'},

         '13'  : {'mV' :  10.00, 'mA': 1.11, 'Zone' : '1'},

         '14'  : {'mV' :  11.00, 'mA': 1.21, 'Zone' : '1'},

         '15'  : {'mV' :  12.00, 'mA': 1.32, 'Zone' : '1'},

         '16'  : {'mV' :  13.00, 'mA': 1.41, 'Zone' : '1'},

         '17'  : {'mV' :  14.00, 'mA': 1.51, 'Zone' : '1'},

         '18'  : {'mV' :  15.00, 'mA': 1.60, 'Zone' : '1'},

         '19'  : {'mV' :  16.00, 'mA': 1.70, 'Zone' : '1'},

         '20'  : {'mV' : 194.00, 'mA': 1.88, 'Zone' : '2'},

         '21'  : {'mV' : 206.00, 'mA': 1.88, 'Zone' : '2'},

         '22'  : {'mV' : 221.00, 'mA': 1.88, 'Zone' : '2'},

         '23'  : {'mV' : 241.00, 'mA': 1.88, 'Zone' : '2'},

         '24'  : {'mV' : 250.00, 'mA': 1.88, 'Zone' : '2'},

         '25'  : {'mV' : 271.00, 'mA': 1.88, 'Zone' : '2'},

         '26'  : {'mV' : 486.00, 'mA': 1.88, 'Zone' : '3'},

         '27'  : {'mV' : 488.00, 'mA': 1.95, 'Zone' : '3'},

         '28'  : {'mV' : 490.00, 'mA': 2.06, 'Zone' : '3'},

         '29'  : {'mV' : 492.00, 'mA': 2.32, 'Zone' : '3'},

         '30'  : {'mV' : 495.00, 'mA': 2.32, 'Zone' : '3'}, 

         '31'  : {'mV' : 498.00, 'mA': 2.49, 'Zone' : '3'},

         '32'  : {'mV' : 500.00, 'mA': 2.63, 'Zone' : '3'},

},

                          },

           '2SB4B-02'  :  { 'DiodeName'  : '2SB4B'},

           '2SB4-01'   :  { 'DiodeName'  : '2SB4'},

           '2SB3-01'   :  { 'DiodeName'  : '2SB3'},

         }

    }

# *** Plotting Functions ***

def printDiodeDataDictionary(diodeDataDict, diodeName): # Just printing out dictionary data for debugging - tlfong01  2020dec16hkt2040)

    print('Begin printDiodeDataDictionary(), ...')

    print('  Title           = ', diodeDataDict['Title'])

    print('  Diode Name      = ', diodeDataDict['Measurements'][diodeName]['DiodeName'])

    print('  I2cBusName      = ', diodeDataDict['Measurements'][diodeName]['I2cBusName'])

    print('  DvBaseAddrName  = ', diodeDataDict['Measurements'][diodeName]['DvBaseAddrName'])

    print('  DataPoints      =    Num       mV      mA')

    for dataPointNum in range(len(diodeDataDict['Measurements'][diodeName]['DataPoints'])):

        print('                      ', (str(dataPointNum)).rjust(3),  \

             ('{:.2f}'.format(diodeDataDict['Measurements'][diodeName]['DataPoints'][str(dataPointNum)]['mV'])).rjust(8), end = '')

        print(('{:.2f}'.format(diodeDataDict['Measurements'][diodeName]['DataPoints'][str(dataPointNum)]['mA'])).rjust(8), ' ')

    print('End   printDiodeDataDictionary().')

    return

def listDiodeDataDictionary(diodeDataDict, diodeName): # Just printing out dictionary data for debugging - tlfong01  2020dec16hkt2040)

    print('Begin listDiodeDataDictionary(), ...')

    print('  Title           = ', diodeDataDict['Title'])

    print('  Diode Name      = ', diodeDataDict['Measurements'][diodeName]['DiodeName'])       

    # ***Extract I-V values from device data dictionary and compile two lists for matplotlib to plot the I-V curve ***

    # *** Print voltage and current values (debugging only) ***

    '''

    # *** print voltage values ***

    print(' ', 'Voltage values   =  mV ')

    for dataPointNum in range(len(diodeDataDict['Measurements'][diodeName]['DataPoints'])):

        print('                    ', diodeDataDict['Measurements'][diodeName]['DataPoints'][str(dataPointNum)]['mV'], '  ',end = '')

        print('')        

    print(' ', 'Current values   =  mA ')       

    for dataPointNum in range(len(diodeDataDict['Measurements'][diodeName]['DataPoints'])):

        print('                    ', diodeDataDict['Measurements'][diodeName]['DataPoints'][str(dataPointNum)]['mA'], '  ',end = '')

        print('')

    '''

    # *** Creat voltage list and current list ***

    voltageList = []

    currentList = []    

    for dataPointNum in range(len(diodeDataDict['Measurements'][diodeName]['DataPoints'])):

        voltageList.append(diodeDataDict['Measurements'][diodeName]['DataPoints'][str(dataPointNum)]['mV'])

    for dataPointNum in range(len(diodeDataDict['Measurements'][diodeName]['DataPoints'])):

        currentList.append(diodeDataDict['Measurements'][diodeName]['DataPoints'][str(dataPointNum)]['mA'])       

    print('')

    print('  VoltageList     =', voltageList)

    print('')

    print('  CurrentList     =', currentList)        

    print('End   listDiodeDataDictionary().')    

    return

# *** Main Fnction ***

# *** 1. Print Tunnel Diode Data Dictionary ***

#printDiodeDataDictionary(diodeDataDictionary01, '2BS4B-01')

# *** 2. List Tunnel Diode DataDictionary ***

listDiodeDataDictionary(diodeDataDictionary01, '2BS4B-01')

# *** End of program ***

# Appendix B - Sample Output ***

# *** Begin sample output ***

'''

>>> %Run plotDiode14.py

Begin listDiodeDataDictionary(), ...

  Title           =  Diode Data Dictionary

  Diode Name      =  2SB4B

  VoltageList     = [0.1, 0.2, 0.3, 0.4, 0.5, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 194.0, 206.0, 221.0, 241.0, 250.0, 271.0, 486.0, 488.0, 490.0, 492.0, 495.0, 498.0, 500.0]

  CurrentList     = [0.02, 0.02, 0.03, 0.05, 0.06, 0.11, 0.24, 0.34, 0.46, 0.57, 0.8, 0.78, 1.01, 1.11, 1.21, 1.32, 1.41, 1.51, 1.6, 1.7, 1.88, 1.88, 1.88, 1.88, 1.88, 1.88, 1.88, 1.95, 2.06, 2.32, 2.32, 2.49, 2.63]

End   listDiodeDataDictionary().

>>> 

'''

# *** End  sample output ***

# *** End of program, appendices, and sample output ***


.END



No comments:

Post a Comment

Joe Biden

RCA Tunnel Diode Manual - RCA 1966

 RCA Tunnel Diode Manual - RCA 1966 https://www.yumpu.com/en/document/read/23901571/rca-tunnel-diode-manual