Go Down

Topic: Controlling (embedded) Linux with Arduino (Read 755 times) previous topic - next topic

Demoniac

Hello there, for a while I have been working on an embedded Linux system to play music all around my house. The only thing missing is an interface to control it and I think my Arduino would be perfect to get some buttons and an LCD connected. I have created a /dev/ttyUSB0 and it's possible to 'cat' the text the Arduino prints to the serial port, but I would like to have the Arduino log in on the system so it can execute commands, like start or stop music, or shut the system down.
I've searched the forum, but all topics I find are about pushing/pulling data to/from the Arduino. Has anybody ever tried to control a Linux system with an Arduino? (it would be possible to continuously pull data from ttyUSB0 and analyze if there are any commands in there, but that's a pretty dirty solution)

dan.2082

I don't know the proper way a daemon should run, but can you not have a python script run in a while loop waiting for a serial command? Have python parse it and do the appropriate linux command?
Code: [Select]

while 1:
  str = serialCXN.readline()
  if (str != ""):
    doCommand()

Demoniac

So I've put my project aside, but a few days ago, I had an idea that's as simple as effective.. Since I will primarily use my Arduino as an interface to Music Player Daemon, I'll use socat (netcat on steroids) as a bridge between /dev/ttyUSB0 and the (Unix or TCP) socket on which MPD listens. Use an interrupt to react on a button press and do a serial.println (send the command), use serialEvent to listen for the computer's reaction to the command I've sent and use the main loop to refresh my LCD screen a few times per second.
I think this is usable for connecting to any Linux service with a TCP or Unix socket interface..

Go Up