Serial Communication and Interrupts

I have an accelerometer connected to an UNO that is streaming serial data (gravity values) to a GUI I've written in Processing. I'm using Processing to determine a tilt angle.
I want to be able to interrupt the flow of serial information from the Arduino, so that I can send the Arduino board threshold values, that I set in Processing, to trigger a motor to turn clockwise, counterclockwise, and off.

I only need to interrupt so that I can send the arduino threshold values so that it can do an analogWrite to an H bridge to turn a motor. I want to resume streaming data into Processing from the accelerometer, when I'm done setting threshold tilt values.

Any thoughts? This is not really a hardware interrupt. The "interrupt" needs to come from Processing after I click a button called "Program Arduino with new trigger angles!"

AliH:
Any thoughts?

Post what you have so far.

AliH:
I want to be able to interrupt the flow of serial information from the Arduino, so that I can send the Arduino board threshold values

I don't really see how this 'interrupts' the flow from the Arduino, since what you're describing would be sending data TO the Arduino, and the serial connection is duplex (can transmit data both ways simultaneously) so there's no need to suspend/interrupt/disrupt the serial stream from the Arduino.

The only potential issue I can see would be that your Processing application would need to enable you to enter values to be sent to the Arduino while also continuing to receive serial data from the Arduino, but that's just a Processing design issue.

AliH:

Congrats getting from the Arduino to your Processing sketch on the host. This link will overview the Arduino listening to the PC for commands:
http://learning.codasign.com/index.php?title=Communicating_with_an_Arduino_Over_Serial

The key to making this happen is to ensure that your loop() does not have any delay() commands (or other commands that would significantly hinder the loop() from rapidly cycling. Then it is simply a matter of using if (Serial.available() > 0) to process your incoming ASCII messages from the PC. You'll need to work out a messaging format (schema) which "understands" or parses out your desired variables. After setting up your hardware, the sketch should ensure the serial buffer is empty and then continue in the loop().

IF you are a little uncertain of how to parse incoming data from the PC, then you can look over one of my sketches... very simple.
http://forum.arduino.cc/index.php?topic=147550.0

Ray

PeterH:

AliH:
I want to be able to interrupt the flow of serial information from the Arduino, so that I can send the Arduino board threshold values

I don't really see how this 'interrupts' the flow from the Arduino, since what you're describing would be sending data TO the Arduino, and the serial connection is duplex (can transmit data both ways simultaneously) so there's no need to suspend/interrupt/disrupt the serial stream from the Arduino.

The only potential issue I can see would be that your Processing application would need to enable you to enter values to be sent to the Arduino while also continuing to receive serial data from the Arduino, but that's just a Processing design issue.

Peter, at the moment I have serial data coming through from arduino to processing. I can view this on Arduino's serial monitor. I send "0.21X-0.98Y1.01Z" every line, which I parse and load into 3 gravity variables inside of Processing. That's my live feed from the accelerometer. My GUI allows the user to enter values that I save (in Processing). These entered values are what I need to send back to the arduino so that it can update some of its variables. I essentially need to stop the arduino board from streaming the accelerometer values to processing, send values from processing to the arduino board, and then resume reading the accelerometer values from the arduino board.

I am unsure of the commands to halt the the arduino, send my values to it, and then have it resume. I wasn't sure if I could tell the arduino to stop what its doing, through a processing issued command (while the arduino is sending me data)

Would it be as simple as updating processing code to say, if this button is clicked then:
myPort.write('values');

and then on the arduino side I have a statement at the start that says, if something is coming in over serial, stop what your doing and listen for it. not sure how to implement this arduino code. Any tips?

And I do not want to implement an I2C bus.

AliH:
I essentially need to stop the arduino board from streaming the accelerometer values to processing, send values from processing to the arduino board, and then resume reading the accelerometer values from the arduino board.

This is the part that doesn't make sense. You don't need to stop the Arduino from sending data, in order to send data to it.

PeterH:

AliH:
I essentially need to stop the arduino board from streaming the accelerometer values to processing, send values from processing to the arduino board, and then resume reading the accelerometer values from the arduino board.

This is the part that doesn't make sense. You don't need to stop the Arduino from sending data, in order to send data to it.

Okay, I got it to work. You were right. However, when I do a write on the serial to send a line of data to the Arduino, it seems the program pauses for half a second, is that normal? I don't have any delays that would cause this.
I thought I would try to right a serialevent handler, like the void serialEvent() in processing, but for the Arduino side. perhaps that would reduce the pause in the program. I can see the pause because the accelerometer values stop for about half a second.

AliH:
when I do a write on the serial to send a line of data to the Arduino, it seems the program pauses for half a second, is that normal?

Is 'the program' your Processing application? What are the symptoms of it pausing? I don't see any inherent reason for serial output to make the Processing application pause, although it could certainly be coded in a way that made that happen. I also don't see any inherent reason why receiving serial input would cause an Arduino sketch to stop generating serial output, although it would certainly be possible to code it in a way that made that happen.

I suggest you try to simplify the Processing application and Arduino sketch down to the minimal code necessary to demonstrate the problem, and then post both sets of code and a description of how to reproduce the problem.

I figured it out, the long delay was due to the way I wrote a button click routine. I essentially had implemented something akin to a software debounce for a gui button and it tied up the program. Resolved.