View: 12438|Reply: 15

rs232 to ethernet , nmea router orange pi zero

[Copy link]

2

threads

5

posts

26

credits

Novice

Rank: 1

credits
26
Published in 2018-3-4 05:32:48 | Show all floors |Read mode
Edited by afric at 2018-3-4 06:51

buy MAX3232 RS232 Serial Port To TTL and i Connected to uart 2- ttyS2 (pin4-5V,pin6-GND,pin11-UART2 RX,pin13-UART2 TX)

I use Armbian_5.35_Orangepizero_Debian_jessie_default_3.4.113

install  python

  1. sudo apt-get install python-serial python3-serial
Copy code
write the script
  1. sudo nano read_serial.py
Copy code
  1. #!/usr/bin/env python
  2. import time
  3. import serial

  4. ser = serial.Serial(
  5. port='/dev/ttyS2',
  6. baudrate = 38400,
  7. parity=serial.PARITY_NONE,
  8. stopbits=serial.STOPBITS_ONE,
  9. bytesize=serial.EIGHTBITS,
  10. timeout=1
  11. )
  12. counter=0


  13. while 1:
  14. x=ser.readline()
  15. print x
Copy code

and i run
  1. sudo python read_serial.py
Copy code
to see if ti works
after that i write onether script (i find it ready)
  1. sudo nano serial_to_udp.py
Copy code
  1. # Python script for serial to UDP communication
  2. # Alex Olwal, 2012 03 24
  3. # www.olwal.com
  4. #

  5. import serial
  6. import sys

  7. from socket import *

  8. def send(msg, ip, port):
  9.     socket(AF_INET,SOCK_DGRAM).sendto(msg, (ip, port))

  10. baud_rate = 38400

  11. if ( len(sys.argv) == 1 ):
  12.         print "Serial-to-UDP utility | Alex Olwal, 2012, www.olwal.com"
  13.         print "Syntax: " + sys.argv[0] + " serial_port udp_ip(= 127.0.0.1) udp_port(= 5000)"
  14.         print "Example: " + sys.argv[0] + " COM20 127.0.0.1 5000"
  15.         quit()

  16. serial_port = sys.argv[1]

  17. if ( len(sys.argv) >= 3 ):
  18.         udp_ip = sys.argv[2]
  19. else:
  20.         udp_ip = "127.0.0.1"

  21. if ( len(sys.argv) >= 4 ):
  22.         udp_port = sys.argv[3]
  23. else:
  24.         udp_port = "5000"
  25.                
  26. if ( len(sys.argv) >= 5):
  27.         printing = 1
  28. else:
  29.                 printing = 0

  30. print "Reading from serial port: " + serial_port
  31. print "Sending to " + udp_ip + ":" + udp_port

  32. udp_port = int(udp_port)

  33. s = serial.Serial( serial_port, baud_rate, timeout=1 )

  34. while (1):
  35.         line = s.readline()

  36.         if (line != ''):
  37.                         if (printing):
  38.                                 print line[:-1]
  39.             
  40.                         send( line, udp_ip, udp_port )

  41.         else:
  42.             if (printing):
  43.                 print "."

  44. s.close()
Copy code
now if you run
  1. sudo python serial_to_udp.py
Copy code
you will take
  1. Serial-to-UDP utility | Alex Olwal, 2012, www.olwal.com
  2. Syntax: serial_to_udp.py serial_port udp_ip(= 127.0.0.1) udp_port(= 5000)
  3. Example: serial_to_udp.py COM20 127.0.0.1 5000
Copy code
so  run
  1. python serial_to_udp.py  /dev/ttyS2 192.168.1.100 13000 &
Copy code
and take serial data from ttyS2 and  sent it to pc at port 13000

there are 2 ways to auto start on boot
the fisrt is direct config rc.local but put inside 1minute wait to find the ethernet
  1. sudo nano /etc/rc.local
Copy code
  1. sleep 1m
  2. python /root/serial_to_udp.py  /dev/ttyS2 192.168.1.100 13000 &
Copy code
before exit0

and the other to create a script
  1. sudo nano /etc/init.d/serial_to_udp.sh
Copy code
  1. #!/bin/sh
  2. python  /root/serial_to_udp.py  /dev/ttyS2 192.168.1.100 13000 &
Copy code
i make it  executable with
  1. sudo chmod +x /etc/init.d/serial_to_udp.sh
Copy code
and after that run
  1. sudo update-rc.d serial_to_udp.sh defaults
Copy code
and after that modified the  rc.local
  1. sudo nano /etc/rc.local
Copy code
write
  1. /etc/init.d/serial_to_udp.sh
  2. sh '/etc/init.d/serial_to_udp.sh'
Copy code
before exit0

  1. sudo reboot
Copy code
and it worksssssssssss

0

threads

112

posts

322

credits

Intermediate member

Rank: 3Rank: 3

credits
322
Published in 2022-4-1 09:46:26 | Show all floors
That is the amazing piece of writing, Thanks a lot for the purpose of rendering everybody this. Have post.        Packers and Movers Faridabad

0

threads

28

posts

120

credits

Registered member

Rank: 2

credits
120
Published in 2023-8-16 18:08:47 | Show all floors
This blog post is awesome. The material on your website proved to be quite useful to us. After finishing this article, I would like to introduce to you the game retro bowl unblocked. You can have some leisure time with your loved ones.

1

threads

2

posts

11

credits

Novice

Rank: 1

credits
11
Published in 2023-9-5 15:04:18 | Show all floors
Crypto marketing involves promoting and fostering adoption of cryptocurrencies and blockchain technology. It employs strategic communication, online campaigns, and community engagement to educate and attract users, investors, and businesses to the crypto ecosystem. This includes highlighting benefits like decentralization, security, and financial freedom, while addressing potential risks. Effective crypto marketing requires a deep understanding of the technology, target audience, and compliance with regulations. It aims to build trust, showcase use cases, and drive interest, ultimately propelling the growth and mainstream acceptance of cryptocurrencies and their underlying technology.

https://themetawise.com/crypto-m ... f-crypto-marketing/
Published in 4 daybefore | Show all floors
I’ve recently started a web site, the information you offer on this site has helped me greatly. Thanks for all of your time & work.        stream XXX Việt
Published in 4 daybefore | Show all floors
It will be in addition a tremendous write-up i usually without a doubt liked inspecting. It's not actually inevitably day-to-day i usually build up the possibility to see all sorts of things.        nhóm chơi đồ
Published in 4 daybefore | Show all floors
I am impressed with this  site,  real  I am a fan .        nhà nghỉ kín Sài Gòn
Published in 4 daybefore | Show all floors
Good day I am so glad I found your web site, I really found you by mistake, while I was looking on Aol for something else, Regardless I am here now and would just like to say thank you for a fantastic post and a all round enjoyable blog (I also love the theme/design), I don’t have time to browse it all at the moment but I have book-marked it and also added your RSS feeds, so when I have time I will be back to read a great deal more, Please do keep up the awesome work.        Telegram chia sẻ clip nhạy cảm
Published in 4 daybefore | Show all floors
when it comes to beautiful smile and beautiful teeth, Rachel McAdams have it all::        thuê sugar baby
Published in 4 daybefore | Show all floors
hello there and thank you for your info – I’ve definitely picked up something new from right here. I did however expertise some technical points using this web site, as I experienced to reload the site a lot of times previous to I could get it to load correctly. I had been wondering if your hosting is OK? Not that I am complaining, but sluggish loading instances times will very frequently affect your placement in google and can damage your high quality score if ads and marketing with Adwords. Well I am adding this RSS to my e-mail and can look out for much more of your respective intriguing content. Ensure that you update this again soon..        nhóm kín 18+ zalo
You need to log in before you can reply login | Register

Points Rule

Quick reply Top Return list