Unable to use stty in ubuntu to pass commands

I am trying to get a simple script working in Ubuntu to pass a single command to the Uno. Here is my script.

#!/bin/bash

# Port setting
stty -F /dev/ttyACM0 cs8 115200 ignbrk -brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke noflsh -ixon -crtscts

echo "power 1" > /dev/ttyACM0

This does nothing when executed on its own. For what ever reason, if minicom is open and connected in a separate terminal, the command gets passed through with the script fine. (mistakenly found this out).

I'm not sure what I m missing here, so any help is greatly appreciated.

When your code opens the serial port the Arduino resets and cannot listen for several seconds.

I don't know if you can put a delay (say 10secs) into your shell script - but that is a fairly crude approach.

This demo using Python illustrates how to wait for the Arduino to send a simple message from setup() when it has finished resetting.

...R

I tried placing a 10 second sleep, but it had no effect. The Uno still doesn't seem to be taking the command.

The Uno still doesn't seem to be taking the command.

Does the RX LED on the UNO flash?

Have you the correct serial port name?

Have you the same baudrate at both ends?

Can you write a short shell script that receives data from the Arduino?

Did you try my Python code?

...R

PaulS:

The Uno still doesn't seem to be taking the command.

Does the RX LED on the UNO flash?

Yes, the led flashes

I've been thinking a bit more about this.

It seems to me that by far the simplest thing would be to write a short Python (or whatever you prefer) program to talk to the Arduino and use your shell script to call the Python program, and possibly to send it parameters.

I have already given you a link to a Python example.

...R

I think it would help if you also showed the code you have in the UNO to receive the data. Without seeing this, we will make assumptions.

Some boards you can disable the DTR used to reset the Arduino. I do this on most of my systems so I can connect and disconnect the USB cable without resetting the Arduino device.


Paul

rockwallaby:
I think it would help if you also showed the code you have in the UNO to receive the data.
Without seeing this, we will make assumptions.

Some boards you can disable the DTR used to reset the Arduino.
I do this on most of my systems so I can connect and disconnect the USB cable without resetting the Arduino device.


Paul

The Arduino code is HERE

Did you read Reply #6 ?

...R

Your code looks mostly ok, and cleanly written which is good to see.

You say

if minicom is open and connected in a separate terminal, the command gets passed through with the script fine

Just to clarify my understanding of what you are saying, does that mean when you connect to the Arduino with minicom you get the prompt back from the Arduino and you can also send commands back to it fine?

Does it echo back the typed character? If you type a character that is out illegal, does it say so?

If that is the case, then it suggests that the Arduino code would be ok.

If that is not true, then you need to take a look at the Arduino code more closely. I have reservations about using the string class and never use it myself with Arduino code. I would, instead use a char array and do away with the string class all together, but I can see it is quite central to your code.


Paul

I don't really understand whats going on in your specific case but with mine and ubuntu I had permission issue's. Do you have all the right ports open and the right perms for these ports? It's pretty easy fix I just can seem to be able to remember the command right now.

3_141592_Co: I don't really understand whats going on in your specific case but with mine and ubuntu I had permission issue's. Do you have all the right ports open and the right perms for these ports? It's pretty easy fix I just can seem to be able to remember the command right now.

Hi

Permission issue ?

chmod 777 /dev/ttyACM0.

As this, you get full read write execute perm for port ttyACM0, assuming this s the correct port where your arduino is connected.