0
Offline
Newbie
Karma: 0
Posts: 42
Arduino rocks
|
 |
« Reply #15 on: January 13, 2009, 01:22:42 pm » |
Oh duh! I'm kicking myself for this right now: You'll need to replace /dev/ttyUSB0 with the serial port your arduino is attached to, dmesg will show the port used by the arduino shortly after you plug it in It really helped for me to try again - with it plugged in. No errors are show, so my guess is that it works, but I'll report back after adding a new sketch to the Arduino. Thanks so much, computer_freak_8
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 42
Arduino rocks
|
 |
« Reply #16 on: January 14, 2009, 03:05:17 pm » |
Hmm... Somehow, I managed to make a program that freezes the Arduino software when I switch to the Serial Monitor. Now, a few seconds after plugging the Arduino into the computer, the "TX" light starts slowly blinking, and my Serial Monitor shows the number 4 being spit out time and time again, just flooding it. Here's the code I used on the Arduino: /* * * Trial sketch for handling button presses (converting to serial output) * */
int button4 = LOW; int button5 = LOW; int button6 = LOW;
void setup() { pinMode(4, INPUT); pinMode(5, INPUT); pinMode(6, INPUT); Serial.begin(9600); }
void loop() { button4 = digitalRead(4); button5 = digitalRead(5); button6 = digitalRead(6); if (button4 == HIGH) {Serial.print("4");} if (button5 == HIGH) {Serial.print("5");} if (button6 == HIGH) {Serial.print("6");} }
I had started my Perl script, and had not pressed any buttons yet. There is nothing connecting pin 4; it did this even when it was dangling by the cord, with nothing touching it. Any ideas?
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Sr. Member
Karma: 0
Posts: 375
|
 |
« Reply #17 on: January 14, 2009, 07:34:49 pm » |
That's because the input is floating and will randomly switch between high and low. If you connect your button you should be fine. Otherwise comment out that line until you get it hooked up and you should be fine.
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 42
Arduino rocks
|
 |
« Reply #18 on: January 16, 2009, 02:23:05 pm » |
That's because the input is floating and will randomly switch between high and low. Thanks for that. But if the switch is "off", then what's the difference? Anyways, I think I've discovered two things: 1. I can't get it to work. 2. The Arduino will only transmit to the computer if the Serial Monitor is open. It must not like the Perl script. Also, the Perl script releases the terminal, and it does not show up in the list of processes. Here is the code I have for it: #!/usr/bin/perl -w
use Device::SerialPort;
my $port = Device::SerialPort->new("/dev/ttyUSB0"); $port->databits(8); $port->baudrate(9600); $port->parity("none"); $port->stopbits(1);
$number_of_chars_to_read=1;
$command4="/home/jaredtbrees/Scripts/Linux/wake-up_alarm.sh";
$command5="/home/jaredtbrees/Scripts/Linux/start_elisa.sh";
# $time="1";
while(my $code=$port->read($number_of_chars_to_read)) {
print "$code";
system("$command4") if($code eq "a"); system("$command5") if($code eq "b");
}
Ideas? Thanks again, computer_freak_8
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Sr. Member
Karma: 0
Posts: 430
Arduino rocks
|
 |
« Reply #19 on: January 16, 2009, 02:47:36 pm » |
You may need to adjust a few other statements a little sleep(1); will sleep for 1sec that may be too long, in which case you can sleep for 100 or 200ms using Time::HiRes #!/usr/bin/perl -w
use Device::SerialPort;
my $port = Device::SerialPort->new("/dev/ttyUSB0"); $port->databits(8); $port->baudrate(9600); $port->parity("none"); $port->stopbits(1);
$number_of_chars_to_read=1;
$command4="/home/jaredtbrees/Scripts/Linux/wake-up_alarm.sh";
$command5="/home/jaredtbrees/Scripts/Linux/start_elisa.sh";
# $time="1";
while(1) {
my $code=$port->read($number_of_chars_to_read);
print "$code";
system("$command4") if($code eq "a"); system("$command5") if($code eq "b");
sleep(1); }

|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 42
Arduino rocks
|
 |
« Reply #20 on: January 16, 2009, 03:22:19 pm » |
Okay, thanks, gnu_linux. I got it to work - a little bit. Apparently, whenever the computer is listening, the Arduino sends out the number 4 continually - even with the switch attached. But hey, at least now it runs the specified command! It's just kind of hard to exit the script. (But I was able to.)
More ideas? Great job helping me so far! Thanks again.
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Sr. Member
Karma: 0
Posts: 430
Arduino rocks
|
 |
« Reply #21 on: January 16, 2009, 03:36:32 pm » |
You can CTRL + C the perl script ( inside the terminal / console / xterm ) at any time and you can also find its PID and kill it man ps man kill man killall 
|
|
|
|
« Last Edit: January 16, 2009, 03:40:48 pm by gnu_linux »
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 42
Arduino rocks
|
 |
« Reply #22 on: January 16, 2009, 03:39:56 pm » |
Yeah, I figured out that part okay.
But I'm still stumped on how to get this to work properly. Why does it just send one "4" after the other when the computer listens, but the switch is "off" and connected?
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Sr. Member
Karma: 0
Posts: 430
Arduino rocks
|
 |
« Reply #23 on: January 16, 2009, 03:42:07 pm » |
How do you have your switch wired up? Can you post some pictures and wiring diagrams for us? 
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 42
Arduino rocks
|
 |
« Reply #24 on: January 16, 2009, 04:03:49 pm » |
I can try. The short answer is that it is a SPST Momentary (NO) that goes between the 3.3V and digital 4 sockets on the Arduino. Pictures here in a couple of minutes...
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Sr. Member
Karma: 0
Posts: 430
Arduino rocks
|
 |
« Reply #25 on: January 16, 2009, 04:17:43 pm » |
Awesome  The pictures should help diagnose the problem 
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 42
Arduino rocks
|
 |
« Reply #26 on: January 16, 2009, 05:05:00 pm » |
Okay, sorry for the long delay. Keep in mind that it does the same thing, whether or not the switch is connected. It also doesn't matter which of my three surfaces I put it on (plastic, wood, semi-glossy paper). Here is the Arduino with the switch plugged in (on the plastic surface). Here you can see that the connection is not shorted where it goes into the switch. Here you can see that the underside of the Arduino is not shorted by something stuck to it. Here is the wooden surface (the computer cart). Here is the semi-glossy paper surface (a calendar).
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Sr. Member
Karma: 0
Posts: 430
Arduino rocks
|
 |
« Reply #27 on: January 16, 2009, 05:17:10 pm » |
A piece of cardboard should provide good insulation Which pins did you connect the switch to? Also have you tried button 5 or just 4? Hopefully someone with better wiring skills than myself can chime in 
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 42
Arduino rocks
|
 |
« Reply #28 on: January 16, 2009, 06:48:51 pm » |
Hmm... I have a feeling that something is wrong with my Arduino code (which was previously posted). Here's part that I caught from my serial monitor while the switch was off, but connected to the 3.3V and digital pin 5: 4444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555554545454544444445454545454444444545454545454444545454545454544454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454544445454545454544444454545454544444445454545454444444545454545444444445454545444444444545454544444444454545454444444445454545444444444545454544444444454545454444444445454545444444444545454544444444454545454444444445454545444444444545454544444444454545454444444445454545444444444545454544444444445454545444444444545454544444444454545454444444445454545444444444545454544 Maybe I need to utilize the ground pin somehow? Don't know if, and definitely don't know how.
|
|
|
|
« Last Edit: January 16, 2009, 06:50:20 pm by computer_freak_8 »
|
Logged
|
|
|
|
|
0
Offline
Sr. Member
Karma: 0
Posts: 430
Arduino rocks
|
 |
« Reply #29 on: January 16, 2009, 07:25:05 pm » |
Yes that doen't look right the pins seem to be floating If I am not mistaken you may need pull down resistors on your pins but I am not an expert in that area so hopefully someone more knowledgeable can jump in 
|
|
|
|
|
Logged
|
|
|
|
|
|