O'Reilly logo

Raspberry Pi For Dummies by Mike Cook, Sean McManus

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Making a Curve Tracer

You are going to make a curve tracer; that is, a device outputs a varying voltage, applies it to a simple circuit, and reads back a measurement. When using the analog output, the analog input A0 is not functional and must be left unconnected. The analog input A1 has a high-value pull-down resistor to stabilize the readings when no voltage is applied. This resistor doesn’t affect the measurements. In Listing 17-3, the voltage across the LED is measured by analog channel A1 and printed out along with the analog output voltage. Look at how the voltage “sticks” at close to the LED’s turn-on voltage. When the LED is on, the voltage across it does not rise by much despite the voltage applied to the whole thing increasing. This sticking voltage depends on the LED’s color and type.

Listing 17-3 LED Curve Tracer

# LED_trace1 - Buf --resistor -- A1 -- LED -- Gnd

# Print the voltage across an LED a voltage applied to LED and resistor

from smbus import SMBus

from time import sleep

# comment out the one that does not apply to your board

bus = SMBus(0) # for revision 1 boards

# bus = SMBus(1) # for revision 2 boards

address = 74

control = 1<<6 | 1 # enable analogue output and set to read A1

Vref = 4.44

convert = Vref / 256

print(“Output a ramp on the D/A”)

print(“Ctrl C to stop”)

while(True): # do forever

for v in range(28,256): # start close to 0.7V

bus.write_byte_data(address, control, v) # trigger last value to D/A

bus.write_byte_data(address, control, v) # trigger ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required