duanbohan2015 2013-08-29 04:47
浏览 422

在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.

  • 写回答

1条回答 默认 最新

  • douchao5864 2013-08-29 07:26
    关注

    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()
    
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。