在RPi的GPIO上读取温度传感器值。 脚步

I am beginner to Go language, please provide me steps to read temperature sensor values on gpio of rpi. and how to process the read analog signal in to digital values for displaying voltage.

From http://www.rpiblog.com/2012/11/reading-analog-values-from-digital-pins.html

"Unfortunately all the 17 pins of Raspberry Pi are digital which can either output HIGH or LOW. But by using a simple circuit (poor man's A/D converter) you can measure multiple level of values using a single GPIO pin."

You can either do something similar to that guide, or connect an AD converter to your Raspberry Pi.

The actual process of reading the values using Dave Cheney's gpio package consists of setting the pin to input mode (Example code is all from the package watch example)

To set a pin to input mode:

pin, err := gpio.OpenPin(gpio.GPIO22, gpio.ModeInput)
if err != nil {
    fmt.Printf("Error opening pin! %s
", err)
    return
}

You would then get the HIGH or LOW values by calling BeginWatch() on the input pin:

err = pin.BeginWatch(gpio.EdgeFalling, func() {
    fmt.Printf("Callback for %d triggered!

", gpio.GPIO22)
})
if err != nil {
    fmt.Printf("Unable to watch pin: %s
", err.Error())
    os.Exit(1)
}

The values would then be processed using the procedure outlined in the first link, and then you would have to create the correct output signal to drive the digital display (These can differ greatly depending on model, capability and many other things. You'll need to look up the reference for the display you're using).

To set a pin to output mode:

power, err := gpio.OpenPin(gpio.GPIO17, gpio.ModeOutput)
if err != nil {
    fmt.Printf("Error opening pin! %s
", err)
    return
}

You would write the values to the output pins using Set() for HIGH and Clear() for LOW:

power.Set()
power.Clear()

Don't forget to Close() the pins after use.

pin.Close()
power.Close()