LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware
User Name
Password
Linux - Hardware This forum is for Hardware issues.
Having trouble installing a piece of hardware? Want to know if that peripheral is compatible with Linux?

Notices


Reply
  Search this Thread
Old 05-01-2019, 07:22 AM   #1
edcasati
LQ Newbie
 
Registered: May 2019
Posts: 5

Rep: Reputation: Disabled
Serial port receiving request to run a shell script


(New to Linux, first post here)
I am trying to get an Arduino to communicate with a Raspberry Pi through a USB cable.

The Raspberry PI is being used as a CNC controller, and runs a small web server that an be queried for status. I intend to do the query on demand by the Arduino.

I have installed HTTPie on the Pi, which is a lightweight HTTP client.

If, from a local Linux terminal window I type: "http http://localhost:8080/getSystemStatus"
I get a JSON formatted response as expected. No problem there.

But I can't figure out how to send the command through the serial port from the Arduino so it runs on the Linux box when requested

If I open a terminal window on the Linux box, I can see the command being sent by the Arduino, but it just sits there as plain text, without executing.

So my question is, if I send data to a Linux box via the serial port, how can it be processed so that it is treated as a terminal command and gets processed so that it triggers the script? I assume that I need a script of some kind constantly running on the Linux box monitoring the serial port and parsing the incoming data. Is there a function that does that readily available in Linux or any examples to look at?
 
Old 05-01-2019, 12:25 PM   #2
hoes
Member
 
Registered: Sep 2005
Distribution: debian, linux from scratch
Posts: 190

Rep: Reputation: 51
Maybe this link is helpful https://unix.stackexchange.com/quest...e-as-using-ssh
 
Old 05-01-2019, 02:53 PM   #3
michaelk
Moderator
 
Registered: Aug 2002
Posts: 26,730

Rep: Reputation: 6314Reputation: 6314Reputation: 6314Reputation: 6314Reputation: 6314Reputation: 6314Reputation: 6314Reputation: 6314Reputation: 6314Reputation: 6314Reputation: 6314
Are you using a USB serial adapter or the Pi's built in serial port? The built in port should be configured as a console so how are you sending the command from the arduino?
 
Old 05-01-2019, 04:12 PM   #4
edcasati
LQ Newbie
 
Registered: May 2019
Posts: 5

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by michaelk View Post
Are you using a USB serial adapter or the Pi's built in serial port? The built in port should be configured as a console so how are you sending the command from the arduino?
I am using an Arduino pro micro, aka 'Leonardo' which uses a different chip than the regular Arduino. This gives you built in USB capabilities, and allows you to emulate a standard HID keyboard.

The Arduino 'types' in a command (right now every 10 seconds as a test) and prints it to the Serial port, where it is received by the Raspberry Pi. I can see it on the Raspberry if I monitor the port using "Putty', but it does nothing with the info. Basically I can't figure out how to get Putty, or Screen, to treat it as a command when the CR/LF is sent finishing the command.

If the command was sent to a true console session, wouldn't it be seen by a command prompt instead of just a blank line where it end up being echoed?

Last edited by edcasati; 05-01-2019 at 04:37 PM.
 
Old 05-01-2019, 06:31 PM   #5
blue_z
Member
 
Registered: Jul 2015
Location: USA
Distribution: Ubuntu, Lubuntu, Mint, custom embedded
Posts: 105

Rep: Reputation: Disabled
Quote:
Originally Posted by edcasati View Post
I am trying to get an Arduino to communicate with a Raspberry Pi through a USB cable.
That's an ambiguous description. USB is a bus that supports many different type of devices.
Presumably the RPi is the USB host, and the Arduino is the USB device.
The simplest way of describing the USB connection is identifying the device node that you use on the USB host.
On the RPi you are probably accessing /dev/ttyACM0, which is a serial terminal that uses a USB CDC ACM device.


Quote:
Originally Posted by edcasati View Post
So my question is, if I send data to a Linux box via the serial port, how can it be processed so that it is treated as a terminal command and gets processed so that it triggers the script?
Hardware is useless without (proper) software.
Putty and screen are terminal emulator programs that allow a human to send and receive text with the connected/remote device. They are not programs that allow a remote device to access the Linux host without human interaction.

There are two basic approaches:

1. A login terminal
The device /dev/ttyACM0 can be setup as a terminal so that the connected device (the Arduino) can log into the Linux host (by providing a username and password that getty or agetty would process), and then have access using a shell.
The burden is on the connected device (the Arduino) to be Linux-aware by sending valid shell commands, and be able to deal with all possible results.
This type of connection by a non-human "user" (even when terminal echo is suppressed) is atypical.

2. A dedicated application
You write/build and execute an application program that opens /dev/ttyACM0, and then "forever" reads and proceseses the input sent by the Arduino.
This is the conventional/traditional configuration for connecting industrial/comercial devices using a proprietary communication protocol.
You can devise any level of complexity for exchanging information between the two devices.


Regards

Last edited by blue_z; 05-01-2019 at 06:58 PM.
 
2 members found this post helpful.
Old 05-01-2019, 07:53 PM   #6
edcasati
LQ Newbie
 
Registered: May 2019
Posts: 5

Original Poster
Rep: Reputation: Disabled
Thank you Blue_Z for your excellent answer. I suspected that the 'terminal' option was not the correct solution, and that having the two devices handshake through a dedicated process was the right choice. it will be a great learning experience getting this to work.
Sending commands to the main app that runs on the Raspberry is not too much of a problem, since it can work with keyboard shortcuts, and the Arduino Leonardo works well for that. It is querying and getting data back to be displayed by the Arduino that is the challenge; and mixing both 'modes' could be another issue.

Thanks again!
 
Old 05-01-2019, 08:35 PM   #7
michaelk
Moderator
 
Registered: Aug 2002
Posts: 26,730

Rep: Reputation: 6314Reputation: 6314Reputation: 6314Reputation: 6314Reputation: 6314Reputation: 6314Reputation: 6314Reputation: 6314Reputation: 6314Reputation: 6314Reputation: 6314
On a normal system keyboard input would be sent to the terminal or desktop application that is currently in focus and as you have posted seen by a command prompt. I suspect there is a program running to echo characters entered by the Arduino to the serial port.

It should be possible to do what you want without the Arduino but as posted your description is bit ambiguous.
 
Old 05-01-2019, 09:37 PM   #8
edcasati
LQ Newbie
 
Registered: May 2019
Posts: 5

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by michaelk View Post
On a normal system keyboard input would be sent to the terminal or desktop application that is currently in focus and as you have posted seen by a command prompt. I suspect there is a program running to echo characters entered by the Arduino to the serial port.

It should be possible to do what you want without the Arduino but as posted your description is bit ambiguous.
Here is the scenario. The main program ("BCNC") is run interactively on the Raspberry Pi, using a normal keyboard and mouse. Since it is running a larger piece of mechanical equipment (the CNC), operators often use a dedicated keypad (commonly known as a pendant) that they can have next to where they are working, and which has dedicated buttons assigned specific tasks. This is a typical wired CNC pendant.
Click image for larger version

Name:	pendant.jpg
Views:	20
Size:	84.5 KB
ID:	30448

In my project, the Arduino is the heart of the pendant, translating the button presses to commands, translating the encoder pulses to steps, and providing a status display.
Like I said, sending commands is not much of an issue, since the Arduino Leonardo acts as a USB keyboard. Asking for and receiving positional information for the display, when needed, is the problem that I'm trying to figure out.
 
Old 05-02-2019, 10:21 AM   #9
michaelk
Moderator
 
Registered: Aug 2002
Posts: 26,730

Rep: Reputation: 6314Reputation: 6314Reputation: 6314Reputation: 6314Reputation: 6314Reputation: 6314Reputation: 6314Reputation: 6314Reputation: 6314Reputation: 6314Reputation: 6314
Ok, had to do some basic research and just for my understanding bCNC is a python GUI program. It has a builtin web server/Pendant feature where you you can remotely control the machine.

You are wanting to use the web server/pendant feature using the Arduino to send keyboard commands via a command line using the httpie web browser.

As far as I know without running any additional programs to accept keyboard commands a terminal needs to be running and be in focus. You did mention you are using keyboard shortcuts so it seems reasonable that you can also create a bash script to run your http commands and execute them using a keyboard shortcut.
 
Old 05-02-2019, 11:35 AM   #10
edcasati
LQ Newbie
 
Registered: May 2019
Posts: 5

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by michaelk View Post
As far as I know without running any additional programs to accept keyboard commands a terminal needs to be running and be in focus. You did mention you are using keyboard shortcuts so it seems reasonable that you can also create a bash script to run your http commands and execute them using a keyboard shortcut.
Thanks Michael for looking into this and helping out!

I have built many projects using the Arduino tools (microcontrollers and programming tools) but never tried to interface them to a separate computer. Lots of interfaces to the cloud, but never to local computers.

Your help here, specially your last comment, and the comments of other people in this thread has got me thinking that I am approaching this wrong, and that it is not really an interface to Linux problem. "bCNC" is cross platform, so to make this project really useful it really should be made cross platform also, which probably means a plugin to bCNC itself, and not an OS specific solution. I guess that I have to look into learning Python! Being more of a hardware guy, this may take a while...

Thanks again for your time and help! I hope that I can close this thread by showing off a working solution eventually!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Communicate Virtual Serial Port on Host(windows) to Communicate with Virtual Serial Port on Guest System(Linux) aquamarine Linux - Newbie 2 09-16-2016 02:48 PM
[SOLVED] C/C++ - Serial Port Communication - Other Side Not Receiving Anything golmschenk Programming 7 12-08-2011 11:09 PM
Is a USBtty (USB serial port) treated the same as tty (normal serial port) in C? spudgunner Programming 1 11-12-2010 01:19 PM
Sending and receiving data to through Serial Port kalyan.penujeevi Programming 1 08-07-2006 07:55 AM
trouble receiving serial port data mtPete Linux - General 1 08-20-2003 04:27 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware

All times are GMT -5. The time now is 08:46 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration