Listen to arduino from linux

From cod3v

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 )