2688 views|2 replies

424

Posts

8

Resources
The OP
 

【Micropython DIY】 Make a voltmeter using adc and uart [Copy link]

 
This post was last edited by lehuijie on 2018-7-25 00:17 Now that I have free time, I'll come and post, otherwise D will think I've run away Here is the program, which mainly uses uart to output the voltage value read from ADC
  1. >>> from pyb import UART >>> from array import array >>> from pyb import ADC >>> from pyb import DAC >>> from pyb import Pin >>> v=ADC(Pin.cpu.A0) >>> u=v.read() >>> x=3.3*u/4096 >>> x=x*10 >>> x1=x/10 >>> x2=x%10 >>> u1=UART(1,9600) >>> u1.writechar(int(x1)+48) >>> u1.writechar(int(x2)+48)
复制代码
u1.writechar() Send, the data read from the adc must be int() to int type before sending, otherwise an error message will be prompted. Of course, you can also use while to loop to read the adc, or you can judge the adc and measure the waveform frequency and peak value This content is originally created by EEWORLD forum user lehuijie. If you need to reprint or use it for commercial purposes, you must obtain the author's consent and indicate the source

Latest reply

UART can directly send bytearray type, which is equivalent to the array in C and is more efficient than writechar.  Details Published on 2018-7-25 09:32
 
 

1w

Posts

25

Resources
2
 
UART can directly send bytearray type, which is equivalent to the array in C and is more efficient than writechar.
 
 
 

424

Posts

8

Resources
3
 
(x1)+48) >>> a.append(int(x2)+48) >>> u1.write(a) 16 [code] [code] import math >>> from pyb import UART >>> from array import array >>> from pyb import ADC >>> from pyb import DAC >>> from pyb import Pin >>> v=ADC(Pin.cpu.A0) >>> u=v.read() >>> x=3.3*u/4096 >>> x=x*10 >>> x1=x/10 >>> x2=x%10 >>> a=array('i') >>> a.append(int(x1)) >>> a.append(int(x2)) >>> u1=UART(1,9600) >>> a.append(int(x1)+48) >>> a.append(int(x2)+48) >>> u1.write(a) 16 [code] I forgot to convert the ASCII code before
 
 
 

Guess Your Favourite
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list