I'm attempting to send data to my Arduino over my USB cable from the OSX terminal. My understanding was that I should be able just do something like echo b > /dev/tty.usbmodem1411 or echo b > /dev/cu.usbmodem1411 but neither of those are working. I also tried an explicit newline by doing echo "b\r\n" > /dev/tty.usbmodem1411 and echo "b\r\n" > /dev/cu.usbmodem1411 but neither worked. I don't really have any idea what's going on, what the difference between the cu and tty is (when I write data with the Serial Monitor in the Arduino IDE I use the cu version, and that works)
It is not as easy as echoing :)
Here is great tutorial with everything you need to know about Serial Communication -- Serial Terminal Basics
I'd be happy to answer more of your questions if needed.
EDIT:
for the shell script something like that:
#!/bin/bsh
screen /dev/tty.usbmodem* 9600
# and everything you need to do
I found this blog post: http://todbot.com/blog/2006/12/06/arduino-serial-c-code-to-talk-to-arduino/
And this code: https://github.com/todbot/arduino-serial
Which solve the problem.
Related
I created a bash script to randomize some number, then send it to > /dev/ttyUSB0. This is a converter (USB to serial, RS-232) that is plugged through the notebook USB.
Right now, my only wish is to see these random numbers (sent from one terminal) on some other terminal (same PC). I've already tried using screen, cat, minicom, and other internet-favorites, but with no success.
Right now, when I run the random-number script (while other terminal is trying to read the output from the port), the "best" answer is saying that the ttyUSB0 is unavailable at the moment.
Appreciate your help,
Regards;
#!/bin/bash
while true;
do
number=$RANDOM
echo $number >/dev/ttyUSB0
echo $number
sleep 4
done
I expected to see the random numbers through other terminal. Instead, I'm reading different kind of errors.
I could do it quite simply with minicom now. After resetting parameters, I reconfigured minicom (minicom -s). After starting the minicom (to /dev/ttyUSB0) in one terminal, I ran my script in another terminal (that echos random numbers to /dev/ttyUSB0) and could finally receive all data.
Problem:
I'm using Terminator but I think this question is relevant to any terminal.
To be more precise let me please explain my problem on concrete example.
I'm running Android cts tests, so I need to use cts-tradef script. This is how it looks like:
The script just runs jar (which I don't want to modify), however I would like to change color of cts-tf, so it looks like on a picture below:
My unsuccessful attempts to solve the problem:
For now I've tried doing something like this:
echo -e "\033[01;32m" && ./cts-tradefed
However it will color everything (as on below picture) while I want to color only cts-tf string (as above):
I also tried using sed, however although it works and replace some strings it also finishes cts-tradefed, so it's useless to me. Same thing (cts-tradefed finishes) happens when piping it through grep:
./cts-tradefed | grep --color "cts-tf\|$"
Another try was with grc tool mentioned by Anthony Geoghegan. Running it without config file doesn't do anything but cts-tradefed doesn't finish but when I run it with config file cts-tradefed finishes the same as with grep or sed. My config file was ok, since it works good with cat or similar commands.
I haven’t used it myself but Radovan Garabík’s Generic Colouriser looks like it should do what you want. It’s written in Python “for beautifying your logfiles or output of commands”.
Packages are available for Debian-based operating systems but I imagine it should not be too hard to install if you are familiar with Python.
GitHub repository
I'm running exercise 14 of Learn Ruby the Hard Way. If I run the script in cmd it works fine, but I've been using Cygwin because it's nicer. When I run it in cygwin using this command:
ruby ex14.rb Devon
I get the following output
test
one
two
Hi Devon, I'm the ex14.rb script.
I'd like to ask you a few questions.
Do you like me Devon?
> Where do you live Devon?
> What kind of computer do you have?
> Alright, so you said test about liking me.
You live in one. Not sure where that is.
And you have a two computer. Nice.
That is to say, the program starts and immediately runs the three STDIN.gets.chomp() commands, and once it gets through those it puts and prints everything at once.
Is there a way to fix this behaviour? I would obviously want to have the lines run in the order they are written. I was unsure what to google for this type of error - combinations of "cygwin", "ruby", "puts output delayed" and "gets out of order" returned nothing relevant. Those search terms seem to vague anyway.
What exactly is going on, and is there a solution?
I think it is all to do with the CR LF differences between dos and unix.
try this...
set -o igncr
before running your script.
I am attempting to read the contents of an RFID card with a bash script using a RFID reader I got from sparkfun, however the most promising piece of code I have found for it is:
#!/bin/sh
while :
do
rfid=`screen /dev/cu.usbserial-A600JNHR 9600`
echo "RFID #: $rfid"
sleep 1
done
which does what it is supposed to, only it never exits screen, so the variable cannot be checked against a known tag to perform an action.
My question: what do I need to do to get the tag in a variable so that I can use it to check and perform an action? Is this piece of code going about it all wrong, or do I just need to add an extra line or two to process the data?
This may work for you
#!/bin/bash
while read -r rfid; do
echo "RFID #: $rfid"
sleep 1
done < /dev/cu.usbserial-A600JNHR
I got it thank you SiegeX I double checked and had used tty instead of cu for the code, here I had given the default that I had found and when I changed it I grabbed the tty.
I have some long running scripts with breaks requiring input/interaction to continue but when I switch to another window I'd like to be notified (by sound) that a task is complete and now awaiting input.
I would prefer to be able to play an audio clip (*.mp3, *.ogg, etc.) but wouldn't care if the only solution is to make the PC Speaker beep noise.
Any ideas? I'm open to any CLI utilities I can install that play sounds that in turn I can execute when needed.
FYI: My System is running WinXP Pro.
UPDATE: Doh! My Windows > Control Panel > Sounds > Default Beep: was set to (none). Grrr...
Problem solved.
This will make a beep from within bash
echo -en "\007"
Try this:
echo ^G
(^G is obtained by ctrl+G).
Note: you can't copy and paste this code in a batch file, it won't work. To obtain a ^G character in a file, type in a cmd window:
echo ^G > beep.txt
(again, ^G is obtained by ctrl+G).
Then you'll have a file named beep.txt, open it with notepad, there will be a square character. This is our ^G once it is saved in a file.
You can then copy and paste it in a batch file to make a sound (don't forget to put "echo" in front of it).
spd-say
sleep 2; spd-say 'get back to work'
Infinite loop with -w if you need extra motivation:
sleep 2; while true; do spd-say -w 'get back to work'; done
or if you prefer the carrot:
sleep 2; while true; do spd-say -t female1 -w "I'm done, come back to me, darling"; done
Pre-installed on Ubuntu 14.04 via the package speech-dispatcher: http://releases.ubuntu.com/trusty/ubuntu-14.04.4-desktop-amd64.manifest for blind people I suppose?
See also: https://askubuntu.com/questions/277215/how-to-make-a-sound-once-a-process-is-complete
Also add a popup
This combo is a life saver, b stands for beep:
b() ( spd-say 'done'; zenity --info --text "$(date);$(pwd)" & )
and then:
super-slow-command;b
If I'm somewhere in the room, I'll hear it and know that the long job is done.
Otherwise, I'll see the popup when I get back to my computer.
Related:
How to show a GUI message box from a bash script in linux?
https://superuser.com/questions/345447/how-can-i-trigger-a-notification-when-a-job-process-ends
https://askubuntu.com/questions/409611/desktop-notification-when-long-running-commands-complete
Listen to your cooler
I'm joking of course, but for compilation I noticed that I use often use this queue subconsciously. When the cooler stops humming for a while, it means that the compilation is over!
I know your question was for Window but just putting this here for any Mac OSX users who come across this article. OSX 10+ comes with the say command:
say "I'm done"
For example:
sleep 5 && say "I'm done waiting 5 seconds"
By setting this variable as follows
PROMPT_COMMAND="echo -en '\a'"
then bash will beep every time it shows the prompt. When you do not need it anymore,
unset PROMPT_COMMAND
To play the system sound from Windows command line you can run:
rundll32 user32.dll,MessageBeep
It should work on all version of Windows.
copy con beep.bat [Enter]
#echo off [Enter]
echo [Ctrl+G] [Enter]
[Ctrl+Z] [Enter]
beep.bat [Enter]
Simple answer without ^G
echo -en "\007"
In my bash profile I've added a BEEP to the script using #GregReynolds solution above then added this to PS1:
GREEN="\[\033[0;32m\]"
BEEP=$(echo -en "\007")
export PS1="$GREEN : ${BEEP}"
source ~/.bash_profile - you should hear the beep after the command prompt returns
I have git-autocomplete on usually so I've provided a much simplified version above