[vc_row][vc_column][vc_column_text]When using python, some people may meet the situation that serial ports( GPIO0 and GPIO1) cannot send or receive data on pcduino, but without any problem on Arduino. And when back to python, the connection under python-serial is normal too. This is because the gpio0 and gpio1 on python didn’t set to UART mode. Now we are going to set UART mode on python. When setting mode on pcduino GPIO, we could use code to the folder below, generally, “0” for input mode, “1” for output mode. “3” can be used to set UART:
/sys/devices/virtual/misc/gpio/mode/
Install python-serial:
sudo apt-get instal python-serial
test code:
import serial with open("/sys/devices/virtual/misc/gpio/mode/gpio0",'w') as UART_RX: UART_RX.write('3') with open("/sys/devices/virtual/misc/gpio/mode/gpio1",'w') as UART_TX: UART_TX.write('3') myport = serial.Serial("/dev/ttyS1",9600,timeout=10) myport.open() myport.write('python serial test on pcduino\n') data = myport.readline() if len(data)>0: print(data) myport.close()
Save the test code above as “serial_test.py”, then run: sudo python ./serial_test.py ( circumscribe a USB to serial port module and pcduino serial port in order to connecting, or, use jumper to short connect RXD and TXD, and the terminal will print the data ” python serial test on pcduino”) :
use the serial debugging tools from PC send data to pcduino:
[/vc_column_text][/vc_column][/vc_row]
Leave a Reply
You must be logged in to post a comment.