Firefly Open Source Community

   Login   |   Register   |
New_Topic
Print Previous Topic Next Topic

python serial on firefly

2442

Credits

0

Prestige

0

Contribution

vip

Rank: 6Rank: 6

Credits
2442

python serial on firefly

Posted at 1/19/2015 16:58:08      View:3802 | Replies:0        Print      Only Author   [Copy Link] 1#

1.prepare on PC
Flash  Ubuntu 14.04 system on Firefly-RK3288 (hereinafter referred to as FR) , uart1  connected to PC by USB to TTL serial port module,set serial rate to 9600 when use C-Kermit(or other serial communication software)

2.enable uart1 on FR
--- a/kernel/arch/arm/boot/dts/firefly-rk3288.dts
+++ b/kernel/arch/arm/boot/dts/firefly-rk3288.dts
@@ -404,6 +404,13 @@
pinctrl-0 = <&uart0_xfer &uart0_cts>;
};

+&uart_bb {
+        status = "okay";
+        dma-names = "!tx", "!rx";
+        pinctrl-0 = <&uart1_xfer &uart1_cts>;
+};
+
+
&i2c0 {
status = "okay";
rk808: rk808@1b {

compile kernel and flash resource.img, reboot then you will find /dev/ttyS1 on FR

3. install python-serial on FR
sudo apt-get install python-serial


4.test it on FR:
firefly@firefly:~/test$ sudo python
Python 2.7.6 (default, Mar 22 2014, 23:30:12)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import serial
>>> ser = serial.Serial("/dev/ttyS1", 9600)
>>> count = ser.inWaiting()
>>> count
32
>>> ser.read(count)        #read date from PC
'firefly python serial read test\n'
>>> ser.write("firefly python serial write test")   #send date to PC
32
everything is going well.


5.the whole code uart_fr.py:
# -*- coding: utf-8 -*
import serial
import time
# open uart1
ser = serial.Serial("/dev/ttyS1", 9600)
ser.write("***********firefly python serial************\r\n")
def main():
while True:
# receive
count = ser.inWaiting()
if count != 0:
#  read buff and echo
recv = ser.read(count)
ser.write(recv)
ser.flushInput()
# just delay
time.sleep(0.1)

if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
if ser != None:
ser.close()

6.run it on FR:sudo python uart_fr.py

Reply

Use props Report

You need to log in before you can reply Login | Register

This forum Credits Rules

Quick Reply Back to top Back to list