2215 views|9 replies

5

Posts

0

Resources
The OP
 

I'm a complete novice. Why can't I read data from the serial port? [Copy link]

 

import machine
chuankou=machine.UART(2,9600)
while Ture:
x=chuankou.read()
if x=='a':
print('cg')
else:
print('sb')

Latest reply

The serial port returns data type is bytes, not str, so it cannot be compared like this   Details Published on 2021-10-15 17:37
 
 

7462

Posts

2

Resources
2
 

Check the baud rate and txrx line

Personal signature

默认摸鱼,再摸鱼。2022、9、28

 
 
 

1942

Posts

2

Resources
3
 

Is this Arduino? Is it grounded? Check if the transmitter is sending data.

 
 
 

5

Posts

0

Resources
4
 
w494143467 posted on 2021-10-15 15:48 Is this Arduino? Is it grounded? Check if the transmitter sends data.

esp32

 
 
 

5

Posts

0

Resources
5
 
w494143467 posted on 2021-10-15 15:48 Is this Arduino? Is it grounded? Check if the transmitter sends data.

I am sending data manually in the serial port assistant

 
 
 

1942

Posts

2

Resources
6
 

Try printing the data of variable [x] directly!

 
 
 

5

Posts

0

Resources
7
 
w494143467 posted on 2021-10-15 16:21 Try printing the data of variable [x] directly!

is none

Comments

This kind of simple program should have routines. You can run the routines directly. If it doesn't work, it's probably because the hardware environment is not set up properly.  Details Published on 2021-10-15 17:17
 
 
 

1942

Posts

2

Resources
8
 

This kind of simple program should have routines. You can run the routines directly. If it doesn't work, it's probably because the hardware environment is not set up properly.

 
 
 

5

Posts

0

Resources
9
 
w494143467 posted on 2021-10-15 17:17 This kind of simple program should have routines. You can run the routines directly. If it doesn't work, it's probably because the hardware environment is not set up properly.

Thanks, I'll try again

 
 
 

1w

Posts

25

Resources
10
 

The serial port returns data type is bytes, not str, so it cannot be compared like this

 
 
 

Just looking around
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