Last active
February 9, 2017 11:25
-
-
Save behrooz-tahanzadeh/24616f98c208ff3e513c97c56e1a717e to your computer and use it in GitHub Desktop.
Python Interface For Arduino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
import serial | |
import thread | |
recv_ip = "" | |
recv_port = 9090 | |
forward_ip = "127.0.0.1" | |
forward_port = 9091 | |
com_port = "COM11" | |
ser = serial.Serial(com_port, 9600) | |
def serialReadThread(): | |
global forward_ip,forward_port,ser | |
sock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM) | |
while True: | |
data = str(ser.readline()) | |
print "send message:", data | |
sock.sendto(data, (forward_ip, forward_port)) | |
#eof | |
def serialWriteThread(): | |
global recv_ip,recv_port,ser | |
sock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM) | |
sock.bind((recv_ip, recv_port)) | |
while True: | |
data, addr = sock.recvfrom(1024) | |
print "received message:", data | |
ser.write(data) | |
#eof | |
thread.start_new_thread(serialReadThread,()) | |
serialWriteThread() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@behrooz-tahanzadeh
http://playground.arduino.cc/interfacing/python
https://github.com/yoelk/instrumentino
https://github.com/thearn/Python-Arduino-Command-API