Skip to content

Instantly share code, notes, and snippets.

@vishalseshagiri
Forked from eraclitux/py-arduino.py
Last active September 20, 2015 17:05
Show Gist options
  • Select an option

  • Save vishalseshagiri/0057c3cea5859e5b0dad to your computer and use it in GitHub Desktop.

Select an option

Save vishalseshagiri/0057c3cea5859e5b0dad to your computer and use it in GitHub Desktop.

Revisions

  1. @eraclitux eraclitux revised this gist May 1, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion py-arduino.py
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    #!/usr/bin/python
    # -*- coding: utf-8 -*-
    """
    Simple code to test Arduino to Python serial communication
    Sample code to test Arduino to Python serial communication
    """

    import serial
  2. @eraclitux eraclitux revised this gist May 1, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion py-arduino.py
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    #!/usr/bin/python
    # -*- coding: utf-8 -*-
    """
    Simple code to test Arduino<--->Python serial communication
    Simple code to test Arduino to Python serial communication
    """

    import serial
  3. @eraclitux eraclitux revised this gist Apr 29, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion py-arduino.py
    Original file line number Diff line number Diff line change
    @@ -14,7 +14,7 @@ def mainloop():
    try:
    #Create a connection with Arduino board and set 1 sec timeout
    conn = serial.Serial('/dev/ttyUSB0', timeout=1)
    tbytes = raw_input('Write something (exit does what youthink): ') + '\n'
    tbytes = raw_input('Write something (exit does what you think): ') + '\n'
    if tbytes == 'exit\n' :
    break
    conn.write(tbytes)
  4. @eraclitux eraclitux revised this gist Apr 29, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion py-arduino.py
    Original file line number Diff line number Diff line change
    @@ -12,8 +12,8 @@ def mainloop():
    while True:
    try:
    try:
    conn = serial.Serial('/dev/ttyUSB0', timeout=1)
    #Create a connection with Arduino board and set 1 sec timeout
    conn = serial.Serial('/dev/ttyUSB0', timeout=1)
    tbytes = raw_input('Write something (exit does what youthink): ') + '\n'
    if tbytes == 'exit\n' :
    break
  5. @eraclitux eraclitux revised this gist Apr 29, 2014. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions py-arduino.py
    Original file line number Diff line number Diff line change
    @@ -14,11 +14,11 @@ def mainloop():
    try:
    conn = serial.Serial('/dev/ttyUSB0', timeout=1)
    #Create a connection with Arduino board and set 1 sec timeout
    tbytes = raw_input('Scrivi qualcosa (exit per terminare): ') + '\n'
    tbytes = raw_input('Write something (exit does what youthink): ') + '\n'
    if tbytes == 'exit\n' :
    break
    conn.write(tbytes)
    print '\n' + 'Arduino ha ricevuto i seguenti caratteri: ' + conn.readline()
    print '\n' + 'Arduino received: ' + conn.readline()
    except serial.SerialException:
    raw_input(error_message)
    break
  6. @eraclitux eraclitux created this gist Apr 29, 2014.
    30 changes: 30 additions & 0 deletions py-arduino.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    #!/usr/bin/python
    # -*- coding: utf-8 -*-
    """
    Simple code to test Arduino<--->Python serial communication
    """

    import serial

    error_message="################ !!! Communication Error !!! ################\n"

    def mainloop():
    while True:
    try:
    try:
    conn = serial.Serial('/dev/ttyUSB0', timeout=1)
    #Create a connection with Arduino board and set 1 sec timeout
    tbytes = raw_input('Scrivi qualcosa (exit per terminare): ') + '\n'
    if tbytes == 'exit\n' :
    break
    conn.write(tbytes)
    print '\n' + 'Arduino ha ricevuto i seguenti caratteri: ' + conn.readline()
    except serial.SerialException:
    raw_input(error_message)
    break
    except KeyboardInterrupt:
    conn.close()
    break

    if __name__ == '__main__':
    mainloop()