LED I-V Curve using Julia

Introduction

Topic: We will collect I-V data of a LED

Connection

Electrical Connections

AOUT0.CH0---.          .------------- AIN0.CH1
           |          |
AIN0.CH0 ------/\/\/\------|>|------- GND
                 R1        D1          

R1 = 320
D1 = [RED] LED
In [1]:
import Box0
import Gadfly

# allocate the appropriate resources
dev = Box0.Usb.open_supported()
ain0 = Box0.ain(dev)
aout0 = Box0.aout(dev)

# prepare AIN0
Box0.snapshot_prepare(ain0)
Box0.chan_seq_set(ain0, Array{Cuint}([0, 1]))
Box0.bitsize_speed_set(ain0, Cuint(12), Culong(100000))

# prepare AOUT0
Box0.snapshot_prepare(aout0)

# generate voltage, read voltage, calculate current and store the result
# AIN0.CH0 = AOUT0.CH0 = generated signal
# AIN0.CH1 = voltage across LED
# current  = (AIN0.CH0 - AIN0.CH1) / R1  (where R1 = 320)
const R1 = 320.0
const SAMPLES = 100
x = Array{Float32}(SAMPLES)
y = Array{Float32}(SAMPLES)

voltages = linspace(0.0, 3.3, SAMPLES)
aout0_running = false

for i in range(1, SAMPLES)
    if aout0_running
        Box0.snapshot_stop(aout0)
    end
    
    # output "v" value on AOUT0.CH0
    Box0.snapshot_start(aout0, Array(voltages[i:i]))
    aout0_running = true
    
    # read back AIN.CH0 and AIN0.CH1
    readed_data = Array{Float32}(SAMPLES)
    Box0.snapshot_start(ain0, readed_data)
    
    # do the calculation
    ch0 = mean(readed_data[1:2:length(readed_data)])
    ch1 = mean(readed_data[2:2:length(readed_data)]) # = voltage across LED
    current = (ch0 - ch1)/R1
    
    # store the result
    x[i] = ch1
    y[i] = current
end

# stop if AOUT0 running
if aout0_running
    Box0.snapshot_stop(aout0)
end

# close the resources
Box0.close(ain0)
Box0.close(aout0)
Box0.close(dev)

# now, plot the data
Gadfly.plot(x=x,y=y, Gadfly.Geom.line)
Out[1]:
x -3.5 -3.0 -2.5 -2.0 -1.5 -1.0 -0.5 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 -3.0 -2.9 -2.8 -2.7 -2.6 -2.5 -2.4 -2.3 -2.2 -2.1 -2.0 -1.9 -1.8 -1.7 -1.6 -1.5 -1.4 -1.3 -1.2 -1.1 -1.0 -0.9 -0.8 -0.7 -0.6 -0.5 -0.4 -0.3 -0.2 -0.1 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3.0 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 4.0 4.1 4.2 4.3 4.4 4.5 -5 0 5 -3.0 -2.8 -2.6 -2.4 -2.2 -2.0 -1.8 -1.6 -1.4 -1.2 -1.0 -0.8 -0.6 -0.4 -0.2 0.0 0.2 0.4 0.6 0.8 1.0 1.2 1.4 1.6 1.8 2.0 2.2 2.4 2.6 2.8 3.0 3.2 3.4 3.6 3.8 4.0 4.2 4.4 4.6 -0.004 -0.003 -0.002 -0.001 0.000 0.001 0.002 0.003 0.004 0.005 0.006 0.007 -0.0030 -0.0029 -0.0028 -0.0027 -0.0026 -0.0025 -0.0024 -0.0023 -0.0022 -0.0021 -0.0020 -0.0019 -0.0018 -0.0017 -0.0016 -0.0015 -0.0014 -0.0013 -0.0012 -0.0011 -0.0010 -0.0009 -0.0008 -0.0007 -0.0006 -0.0005 -0.0004 -0.0003 -0.0002 -0.0001 0.0000 0.0001 0.0002 0.0003 0.0004 0.0005 0.0006 0.0007 0.0008 0.0009 0.0010 0.0011 0.0012 0.0013 0.0014 0.0015 0.0016 0.0017 0.0018 0.0019 0.0020 0.0021 0.0022 0.0023 0.0024 0.0025 0.0026 0.0027 0.0028 0.0029 0.0030 0.0031 0.0032 0.0033 0.0034 0.0035 0.0036 0.0037 0.0038 0.0039 0.0040 0.0041 0.0042 0.0043 0.0044 0.0045 0.0046 0.0047 0.0048 0.0049 0.0050 0.0051 0.0052 0.0053 0.0054 0.0055 0.0056 0.0057 0.0058 0.0059 0.0060 -0.003 0.000 0.003 0.006 -0.0030 -0.0028 -0.0026 -0.0024 -0.0022 -0.0020 -0.0018 -0.0016 -0.0014 -0.0012 -0.0010 -0.0008 -0.0006 -0.0004 -0.0002 0.0000 0.0002 0.0004 0.0006 0.0008 0.0010 0.0012 0.0014 0.0016 0.0018 0.0020 0.0022 0.0024 0.0026 0.0028 0.0030 0.0032 0.0034 0.0036 0.0038 0.0040 0.0042 0.0044 0.0046 0.0048 0.0050 0.0052 0.0054 0.0056 0.0058 0.0060 y