Pages: [1]   Go Down
Author Topic: Reading data from Monitor using interupts?  (Read 1733 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 250
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi i am working on a big project (led display)

The code is big and each cycle (void loop)sometimes keeps 2-5 minutes.

I want to send some data (parametres) via serial communication from arduino monitor (or my visual basic program) and store them to his eeprom.

The problem is that the program makes a big cycle before it reading the data from serial communication, so it will read only the buffer, and it will loose the rest.

is it posible to connect the interrupt pin with the rx pin so it when there is data on that pin to execute the "reading from serial" routine?

is it good idea? can be done? is there any other solution?

thanks in advance and sorry for my bad english


Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 613
Posts: 49271
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It is generally better to implement handshaking between the Arduino and the data sender. The Arduino sends a message when it is ready to receive data, and the sender only sends data when the Arduino is ready.

Quote
The code is big and each cycle (void loop)sometimes keeps 2-5 minutes.
What is the loop() function doing that takes so long? Not using delay, I hope.

There may be ways to perform the actions in pieces so that more iterations of loop occur.

Quote
is it posible to connect the interrupt pin with the rx pin so it when there is data on that pin to execute the "reading from serial" routine?
Buffering of serial data is already interrupt-driven. You are really better off either managing the delivery of data (hand-shaking) or managing the reading of data (getting to it quicker).
Logged

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 250
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

yes there are many delay on the loop() function.

 it is hard to me to make the sender (visual basic) to send data when the arduino is ready, i dont know how could i make it practically (on visual basic). it must works like that i suppose

1) MASTER: "hey slave i will send you data are you ready?"
2) SLAVE: "Hey, i was busy, yes i am ready, send me now"
3) MASTER: "Take them, data,data,data....data"
4) MASTER: "that's all the data, i'm finished!, go back  to your routine work now
5) SLAVE: ok, i got it, i have to go back on my work, bye!!"

can anyone help me on code on visual basic how to do that?




Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26278
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
yes there are many delay on the loop() function
...is the wrong answer!

Of course, as a first stab, you could wrap the delays up to give you a chance to break out early.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 217
Posts: 13705
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Please post your code so we can look at the details for a solution.
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 613
Posts: 49271
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

On the Arduino side, use Serial.print() to send "Ready" to the serial port, whenever you are ready to read data.

On the PC side, there is an event that needs to be handled whenever serial data arrives. In the event handler, set a variable to true when the incoming serial data is "Ready"

In the sending method, don't send data unless the flag is true. After sending data, set the flag to false.

And follow AWOL's advice to get rid of the delays. Consider a state machine, where the Arduino does stuff only when it is time to do stuff. The thing being done defines the state. When that thing is done, a new state is defined.

Each pass through loop, you see if it is time to do something, based on the current state and the next time to do something/last time something was done. Before doing that, of course, you see if there is any serial data to read, and read it if there is.
Logged

Pages: [1]   Go Up
Jump to: