Difference between revisions of "Listen to arduino from linux"

From cod3v
(Created page with "== Introduction == == Theory == Arduino using USB cable is either * /dev/ttyUSBx * /dev/ttyACMx <pre> > ls -l /dev/ttyACM* crw-rw---- 1 root uucp 166, 0 Mar 25 20:16 /dev/ttyACM0 </pre> Set the permissions: * sudo usermod -a -G uucp '''Screen''' command: * Ctrl+a and k will kill a screen session")
 
 
(One intermediate revision by the same user not shown)
Line 17: Line 17:




'''Screen''' command:
'''Screen''' command: Install screen and use it it:
<pre>
screen /dev/ttyACM0 9600
</pre>
* Ctrl+a and k will kill a screen session
* Ctrl+a and k will kill a screen session
'''Python'''.
<syntaxhighlight lang="python">
import time
import serial
ardu=serial.Serial('/dev/ttyACM0',9600, timeout=.1)
time.sleep(1)
while True:
    line = ardu.readline()
    if len( line ) > 1:
        print( line )
</syntaxhighlight>

Latest revision as of 12:17, 25 March 2023

Introduction

Theory

Arduino using USB cable is either

  • /dev/ttyUSBx
  • /dev/ttyACMx
> ls -l /dev/ttyACM*

crw-rw---- 1 root uucp 166, 0 Mar 25 20:16 /dev/ttyACM0

Set the permissions:

  • sudo usermod -a -G uucp


Screen command: Install screen and use it it:

screen /dev/ttyACM0 9600
  • Ctrl+a and k will kill a screen session

Python.

import time
import serial

ardu=serial.Serial('/dev/ttyACM0',9600, timeout=.1)
time.sleep(1)
while True:
    line = ardu.readline()
    if len( line ) > 1:
        print( line )