📬❄️📦Adafruit Holiday Shipping Deadlines 2019: Please place all UPS 3 Day orders by 11am ET Friday December 13 📬❄️📦
0

Serial Communication to turn on LED...why won't this work?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Serial Communication to turn on LED...why won't this work?

by Tekkaman Blade on Wed Oct 29, 2008 8:20 pm

I'm trying to do a project that will involve a processing program gathering weather data from xml and visualizing it in LEDs. I found what looked like a simple and very useful tutorial.
I did the tutorial found here:
http://everybody.is-a-cyb.org/project/21
My code is pretty much identical. Here it is:
Processing
Code: Select all | TOGGLE FULL SIZE
import processing.serial.*;

// The serial port:
Serial port;
//List all available serial ports:
println(Serial.list());
port = new Serial(this, Serial.list()[1], 9600);
//Send a Capital A out of the serial port
port.write(65);


Arduino
Code: Select all | TOGGLE FULL SIZE
int ledPin = 13; //LED connected to digital pin 13
int val = 0;

void setup()
{
  pinMode(ledPin, OUTPUT);//digital pin set as output
  Serial.begin(9600);
}

void loop()

{
  val = Serial.read();
  if (val == 'A'){
   
    digitalWrite(ledPin, HIGH); //LED turns on
  }

}


Now, that being said, the LED does not turn on. When i first activate the Processing program, it blinks, but I've found that this happens even when I remove the write command altogether. I have no idea why this isn't working, and I've been tearing my hair out in frustration at such an early stumbling block. Is there an alternate way I can get the Arduino to recognize it receiving the ASCII code? To trick it into working? I honestly have no idea what to do.

I'm using the right port, but I've found that no matter how many USB cables I plug into the various ports on my laptop the only thing that displays in the device manager is COM4, even though the processing program also detects a COM3. Even when I set the Processing program to use COM3 (which my Arduino is not) the LED still blinks when it initially activates. Help!
Tekkaman Blade
 
Posts: 8
Joined: Wed Oct 29, 2008 8:14 pm

Re: Serial Communication to turn on LED...why won't this work?

by westfw on Wed Oct 29, 2008 8:36 pm

When i first activate the Processing program, it blinks

Perhaps you are running into the "auto-reset" "problem." The automatic reset in the diecimila is triggered from the serial port signals, and a side effect is that when you open the serial port from a program other than the arudino environment, it also resets the arduino. This would mean (I think) that the processing app is sending the "A" while the Arduino is doing its reset processing, rather than when it is running your sketch.

Try inserting a delay (a couple seconds) after the "new Serial ..." statement and before the "port.write" statement...
westfw
 
Posts: 1585
Joined: Fri Apr 27, 2007 1:01 pm
Location: SF Bay area

Re: Serial Communication to turn on LED...why won't this work?

by Tekkaman Blade on Wed Oct 29, 2008 8:55 pm

I tried that just now, but just to be sure this is how it would be, right?
Code: Select all | TOGGLE FULL SIZE
port = new Serial(this, Serial.list()[1], 9600);
//Send a Capital A out of the serial port
delay(10000);
port.write(65);

It wasn't working before when I tried so I went all the way up to 10 seconds. Nothing.
It seems to blink more now though, for some reason, even after I took out the delay.
Tekkaman Blade
 
Posts: 8
Joined: Wed Oct 29, 2008 8:14 pm

Re: Serial Communication to turn on LED...why won't this work?

by westfw on Thu Oct 30, 2008 3:09 am

FWIW, it works fine for me (MacOS 10.5, Processing 0148, Arduino 0011, MDC Bare Bones Board.)
Note that the BBB does not include the auto-reset capability.
(My "real" arduino seems to be having problems at the moment...)
westfw
 
Posts: 1585
Joined: Fri Apr 27, 2007 1:01 pm
Location: SF Bay area

Re: Serial Communication to turn on LED...why won't this work?

by Tekkaman Blade on Thu Oct 30, 2008 10:15 am

I should point out that I have a PC running Windows Vista with an Arduino Diecimilia, Processing 154, and Arduino 0011.
Tekkaman Blade
 
Posts: 8
Joined: Wed Oct 29, 2008 8:14 pm

Re: Serial Communication to turn on LED...why won't this work?

by josheeg on Thu Oct 30, 2008 10:44 am

I have had problems with the reset also.
But on the topic of processing I would try serial IO stuff that comes with processing under open libraries com port stuff
their are examples with example arduino code.
coppy paste and learn maby you could notice something their thats different showing you something from a different angle.
check out the processing webpage.

I think a processing tutorial would be nice on adafruit I am surprised nowone wrote a data logger yet or a arduino logic analiser kit from the blog post a avr mega 168 logic analiser that would be great in a box with clips.
josheeg
 
Posts: 213
Joined: Wed Jan 16, 2008 8:38 am

Re: Serial Communication to turn on LED...why won't this work?

by Tekkaman Blade on Thu Oct 30, 2008 10:56 am

The code in Processing is actually practically taken practically verbatim from the Processing website. If there's another way of sending info through serial with Processing, I don't know it.
Tekkaman Blade
 
Posts: 8
Joined: Wed Oct 29, 2008 8:14 pm

Re: Serial Communication to turn on LED...why won't this work?

by josheeg on Thu Oct 30, 2008 11:10 am

so why not load both of them from what the processing gui says when you open the example then work from their if it works?
The reason why I say that is it is easy to make a mistake at least for me that could take a wile to catch.
josheeg
 
Posts: 213
Joined: Wed Jan 16, 2008 8:38 am

Re: Serial Communication to turn on LED...why won't this work?

by Tekkaman Blade on Thu Oct 30, 2008 11:24 am

How would I even do that? I'm not really sure what you mean.
Tekkaman Blade
 
Posts: 8
Joined: Wed Oct 29, 2008 8:14 pm

Re: Serial Communication to turn on LED...why won't this work?

by westfw on Thu Oct 30, 2008 11:35 am

Code: Select all | TOGGLE FULL SIZE
//List all available serial ports:
println(Serial.list());
port = new Serial(this, Serial.list()[1], 9600);

So the first port listed in the list IS the port you have the arduino on, right? When I ran it on the mac, I notice it found several "serial ports" (a couple of bluetooth ports as well as usb), and I was only "lucky" that the correct USB port happened to be first...
westfw
 
Posts: 1585
Joined: Fri Apr 27, 2007 1:01 pm
Location: SF Bay area

Re: Serial Communication to turn on LED...why won't this work?

by Tekkaman Blade on Thu Oct 30, 2008 11:51 am

Yes, it absolutely is. It's the port I have the Arduino code sending to, and I've tried sending other things to the Arduino like a basic light blinking program with no problem. The port I declare does not seem to be the issue.
Tekkaman Blade
 
Posts: 8
Joined: Wed Oct 29, 2008 8:14 pm

Re: Serial Communication to turn on LED...why won't this work?

by westfw on Thu Oct 30, 2008 6:35 pm

Can you get the LED to turn on sending "A" on the serial using the arduino environment "serial monitor"?

Are you exiting the arduino environment before you run the processing app? I'm not sure what will happen in processing if the port is in use by another app...
westfw
 
Posts: 1585
Joined: Fri Apr 27, 2007 1:01 pm
Location: SF Bay area

Re: Serial Communication to turn on LED...why won't this work?

by Tekkaman Blade on Thu Oct 30, 2008 11:20 pm

The Processing program will not in fact work when Serial Monitor is on. I've tried this as well :( .
Tekkaman Blade
 
Posts: 8
Joined: Wed Oct 29, 2008 8:14 pm

Re: Serial Communication to turn on LED...why won't this work?

by Tekkaman Blade on Tue Nov 04, 2008 12:44 am

I GOT IT TO WORK!
Okay folks, in case you're interested, I went to the unbelievably helpful page
http://itp.nyu.edu/physcomp/Labs/SerialOut and changed my code accordingly. And it now works. Here is my new Processing program code:
Code: Select all | TOGGLE FULL SIZE
import processing.serial.*;

// The serial port:
Serial myPort;

void setup() {
//List all available serial ports:
println(Serial.list());
myPort = new Serial(this, Serial.list()[1], 9600);
}

void draw() {
myPort.write(65);
}


All I had to do was organize everything better, and put the write function in a draw loop!
Tekkaman Blade
 
Posts: 8
Joined: Wed Oct 29, 2008 8:14 pm

Please be positive and constructive with your questions and comments.