View: 9134|Reply: 6

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

29

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

3

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 2024-3-16 02:08:03 | Show all floors
The next time I learn a weblog, I hope that it doesnt disappoint me as much as this one. I imply, I know it was my choice to read, but I really thought youd have one thing attention-grabbing to say. All I hear is a bunch of whining about one thing that you would fix in the event you werent too busy looking for attention.        topcer88 slot
Published in 2024-3-21 18:10:58 | Show all floors
Hi there, simply become aware of your blog thru Google, and found that it is truly informative. I’m gonna be careful for brussels. I will be grateful should you continue this in future. Lots of other folks can be benefited out of your writing. Cheers!        https://betvisa.ac/
Published in 2024-3-28 03:22:54 | Show all floors
You will find on our sites exclusive no deposit bonuses,no deposit casino , no deposit poker , no deposit bingo , no deposit forex and all the very best deposit bonuses        login topcer88
You need to log in before you can reply login | Register

Points Rule

Quick reply Top Return list