查看: 2922|回复: 0

[Micropython TPYBoard ] ADC的使用方法

[复制链接]
  • TA的每日心情
    慵懒
    2018-1-6 09:01
  • 签到天数: 7 天

    连续签到: 1 天

    [LV.3]偶尔看看II

    发表于 2018-5-24 10:41:51 | 显示全部楼层 |阅读模式
    分享到:
    基本用法
    import pyb
    adc = pyb.ADC(Pin('Y11')) # create an analog object from a pin
    adc = pyb.ADC(pyb.Pin.board.Y11)
    val = adc.read() # read an analog value
    adc = pyb.ADCAll(resolution) # creale an ADCAll object
    val = adc.read_channel(channel) # read the given channel
    val = adc.read_core_temp() # read MCU temperature
    val = adc.read_core_vbat() # read MCU VBAT
    val = adc.read_core_vref() # read MCU VREF
    pyb.ADC(pin)
    通过GPIO定义一个ADC
    pyb.ADCAll(resolution)
    定义ADC的分辨率,可以设置为8/10/12
    adc.read()
    读取adc的值,返回值与adc分辨率有关,8位最大255,10位最大1023,12位最大4095
    adc.read_channel(channel)
    读取指定adc通道的值
    adc.read_core_temp()
    读取内部温度传感器
    adc.read_core_vbat()
    读取vbat电压
    vback = adc.read_core_vbat() * 1.21 / adc.read_core_vref()
    adc.read_core_vref()
    读取vref电压(1.21V参考)
    3V3 = 3.3 * 1.21 / adc.read_core_vref()
    adc.read_timed(buf, timer)
    以指定频率读取adc参数到buf
    buf,缓冲区
    timer,频率(Hz)
    使用这个函数会将ADC的结果限制到8位
    adc = pyb.ADC(pyb.Pin.board.X19) # create an ADC on pin X19
    buf = bytearray(100) # create a buffer of 100 bytes
    adc.read_timed(buf, 10) # read analog values into buf at 10Hz
    #this will take 10 seconds to finish
    for val in buf: # loop over all values
    print(val) # print the value out

    回复

    使用道具 举报

    您需要登录后才可以回帖 注册/登录

    本版积分规则

    关闭

    站长推荐上一条 /4 下一条



    手机版|小黑屋|与非网

    GMT+8, 2024-11-24 21:28 , Processed in 0.108449 second(s), 15 queries , MemCache On.

    ICP经营许可证 苏B2-20140176  苏ICP备14012660号-2   苏州灵动帧格网络科技有限公司 版权所有.

    苏公网安备 32059002001037号

    Powered by Discuz! X3.4

    Copyright © 2001-2024, Tencent Cloud.