I have set up my Arduino so when I send a "0" via the serial monitor, a stepper motor turns a given amount.
I want to include this in a bash script, but I can only get this to work when the arduino serial monitor is open and entering echo 0 > /dev/tty.usbserial641 in bash. I assume this is because serial monitor is opening the connection for me.
In my struggle to open the connection in bash (without serial monitor open) I have tried all manner of options with stty -f /dev/tty.usbserial641 and have also tried connecting reset to ground with a 10uF capacitor.
Can any help me open the connection in bash without the use of arduino serial monitor?
System:
Arduino Uno rev3
OS X 10.8.4
Many thanks,
hcaw
Do the commands below work for you.
# stty -F /dev/ttyUSB0 9600 cs8 -cstopb
# sleep 0.1
# echo "0" > /dev/ttyUSB0
There is a difference between the value 0 and the ascii char 0 (48). Which one you trying to send, and which one are you trying to receive?
If you want to read the port from the terminal you can do it like this
head -n 1 /dev/ttyUSB0 //the number after n is how many lines you want to read
As a last note, I am a fan of pySerial. I would much rather write an interface in python than shell scripts.
I found a great binary written in C that solves my problem called Arduino-serial. Here's the link.
I hope this helps people with similar problems!
Related
I was trying to figure out sending file via serial port on windows, as the below picture
I know on linux we could do
cat [file] > /dev/ttyS0
or vice verse
cat [file] < /dev/ttyS0
I also know on windows type operates samely as cat, so combined together, I modified baud rate and hope get the file transfered ...
type [file] > comport:
but as shown in picture, I was stuck in waiting forever, any idea to checkout if the file started transfering (like some verbose printout)?
after long wait ...
like one hour and a half, I got the process done (prompted with E:\scp in this case), but I did not find where the file locates in my com3 device, still need some help ...
I am newbie in Linux, sorry if the question sounds too easy.
I have some communication with the board.
what i do first is:
enable the usb and gsm driver and cat "/dev/ttyUSB0 &"
afterwards, I send some AT commands and automatically get replies like "OK" and so on.
What I want is to able to READ this output using bash scripts, or any other possible ways
Thx
You can use screen command to read and write to the GSM. for eg. execute the command sudo screen /dev/ttyUSB0 , it will open a new screen their you can send data and see received data.
I'm working on an i/o project where I have a microcontroller that communicates with my mac through a serial terminal using the screen command in Terminal.app
For example, to open the connection I type "screen /dev/tty.usbserial-number 115200" and then can type commands/data that are sent to the microcontroller
I would like to write a shell script, applescript, c program, or something simple like that that initiates the connection, sends the number "16" and then closes the connection
Thanks
Why do you need to use 'screen'? Can't you just do something like "stty -F 115200 /dev/ttyS0 ; echo '16' >/dev/ttyS0" ? Is there something specific about the setup?
This is in relation to resetting an Arduino, and then start pushing data to it from my usb xbee.
I've tried using screen, with no luck.
screen -S Xbee -d -m /dev/tty.usbserial-A900fra9 115200 *reset
I don't know how to close this session, not sure whether the args are correct, either.
to send anything to devices on /dev, you can use the > >> 2> 2>&1, etc.
Try this example from tty1 (ctrl+alt+F1):
echo "my string" > /dev/tty2
now go to tty2 (alt+F2) and you gonna see your string. It should work with any device.
and to sleep, use:
sleep 1
your problem could be also with permissions. Try it with root! ;)
Is it possible to set the baud rate for Macs in a terminal? If yes, how to set the baud rate in terminal through the terminal?
I am trying to talk to the Mac using an Arduino (open source microcontroller), an XBee (wireless communicator) to type in the terminal through the serial monitor. The only problem I am having is the baud rate of the serial monitor and terminal are different. I can easily change the baud rate for the serial monitor in the Arduino, but I do not know what the baud rate is for the terminal in Mac.
On Mac OS, stty seemingly can only change terminal settings for an ongoing access.
It works to either:
Access the serial interface, e.g. cat /dev/cu.usbserial, the default settings will be used at first. On a different terminal use stty, e.g. stty -f /dev/cu.usbserial 230400 to set the baud rate, the settings of the terminal accessed before will change.
There is a small time window after executing stty, in which the access can be performed with the desired parameters, e.g. stty -f /dev/cu.usbserial 230400 & cat /dev/cu.usbserial executes stty, detaches it and then immediately performs the access to the serial device.
For one line command logging serial port /dev/tty.usbserial-X's output to cat.out and terminating the logging by pressing Ctrl+C, here is the solution: trap 'kill $(jobs -p)' SIGINT ; cat /dev/tty.usbserial-X | tee cat.out & stty -f /dev/tty.usbserial-X 115200. You can type Ctrl+C to terminate logging to cat.out. (edited)
This only seems to work for the /dev/cu.* device files. I don't know the difference from /dev/tty.* files.
Minicom is an excellent tool that does exactly what you're asking for. You can get it using apt on ubuntu but should check this Tutorial out for Mac.
Keep the serial reset issue in mind if you plan on sending data to the Arduino. see http://arduino.cc/playground/Main/DisablingAutoResetOnSerialConnection
stty 19200 or so.
Check man stty, you can set stop bits, speed, etc.
Surprised that no one mentioned picocom which could set higher bard rate up to 4000000.