[SOLVED]Return a status message (PC <=> Arduino)

Hello,

I work on a project currently on Arduino Uno. My Arduino is connected to a PC thanks to Bluetooth Shield. The PC sends commands to my board and I would like to send a message from my Arduino to my PC like a Status message (for exemple if I send $STATUS;24.14;1; it means that my battery is a 24.14V and that the power is ON(1)).
I tried a timer which sends the message by Serial.print(...); every seconds but I had a conflict when I have to read a RFID via an RFID reader .. I read on a topic that it's impossible to execute Serial.print() into an interrupt because Serial.print() uses interrupt. Any idea ?

Thank you for your attention

I tried a timer which sends the message by Serial.print(...); every seconds

Use millis() to determine if now minus then (the last time you sent data) exceeds some threshold (the interval between sends). If true, update the last time sent and send the message.

First, thank you for your answer.

Nevertheless, I don’t know how to use this method in my code …
My project is to dose a mixture. So this is what I do :

LOOP :
1) I’m waiting the mode from the PC (mode 0 or mode 1)
2) I’m waiting an RFID address from the PC (like 0A39EFFF930F)
3) I need to put my container under the powder
4) If it’s the address send by the PC, I can continue
5) I’m waiting a quantity from the PC (like 250 grammes)
6) A motor puts 250 grammes on my container

So my main program is my loop … I can spend 30 seconds to make a dose so my main loop takes a long time. This is why the PC need to know continuously where I am in my dose … Do you think that the solution that your propose can solve the problem ?

PS : sorry for my bad english …

You need to post your program if we are to make sense of your problem.

The demo serial input basics illustrates how to use millis() to manage timing.

…R

Please find enclosed my entire code, I hope you will understand how it works :

LOOP :

  1. I'm waiting the mode from the PC (mode 0 or mode 1)
  2. I'm waiting an RFID address from the PC (like 0A39EFFF930F)
  3. I need to put my container under the powder
  4. If it's the address send by the PC, I can continue
  5. I'm waiting a quantity from the PC (like 250 grammes)
  6. A motor puts 250 grammes on my container

I try to use a timer which display my status every 2 seconds.
But if I don't comment the line "Serial.print(HBM());" on the displayStatus() function, my program stops at line 534 ... any idea ?

I think that it doesn't work because my function HBM() use the software serial Poids() and at line 534 I use the RFID software serial so it's a conflict ..

If you have solved your problem please share the solution with other readers.

...R