How to show value received from HC-06 as a graph?

Hello:)

I'm using HC-06 + AD8232(ecg sensor) + app inventor.
I want to show the value received from hc-06 as a graph.
But I have some problem TT.

Could somebody help me?


--------------- This is my arduino code ------------------

#include <SoftwareSerial.h>

SoftwareSerial A(2, 3); //(Tx, Rx)

void setup() {
Serial.begin(9600); // 시리얼 통신 시작
A.begin(9600); // 블루투스 통신 시작
pinMode(10, INPUT);
pinMode(11, INPUT);
}

// #1

void loop() {
if((digitalRead(10) == 1) || (digitalRead(11) == 1)){
Serial.println('!');
}
else{
Serial.println(analogRead(A0));
A.println(analogRead(A0));
}

// delay(1100);
}

----- What is the problem -----
#1 When there is no delay();

#2 When there is delay(1100);

I really want to solve this problem but I cant :cry:
Please help me

1 Like

You are relying too much on timers. Use a Delimiter

Please see the Delimiter article in FAQ

Be sure to use println() at the end of each message to send from the sending device, to signal end of message. Do not rely on timing for this, which is unreliable.

In the AI2 Designer, set the Delimiter attribute of the BlueTooth Client component to 10 to recognize the End of Line character.

Also, return data is not immediately available after sending a request,
you have to start a Clock Timer repeating and watch for its arrival in the Clock Timer event. The repeat rate of the Clock Timer should be faster than the transmission rate in the sending device, to not flood the AI2 buffers.

In your Clock Timer, you should check

  Is the BlueTooth Client still Connected?
  Is Bytes Available > 0?
     IF Bytes Available > 0 THEN
       set message var  to BT.ReceiveText(-1) 

This takes advantage of a special case in the ReceiveText block:

ReceiveText(numberOfBytes)
Receive text from the connected Bluetooth device. If numberOfBytes is less than 0, read until a delimiter byte value is received.

If you are sending multiple data values per message separated by | or comma, have your message split into a local or global variable for inspection before trying to select list items from it. Test if (length of list(split list result) >= expected list length) before doing any select list item operations, to avoid taking a long walk on a short pier. This bulletproofing is necessary in case your sending device sneaks in some commentary messages with the data values.

2 Likes

I'm late.
Thx for the reply :slight_smile:

1 Like

Hi all,
this is the same old story... MIT Ai2 is not a Real Time tool. Let Arduino do the RT job, and MIT AI2 to do only the visualization. In other words, buffer as much as you can on Arduino memory, and transmit only seldom to MIT Ai2, and let it plot a series of data (i.e. 10 data at a time).
Please take a look to the topic Bluetooth client speed and buffering issue.
It is exactly the same ....
Cheers.

1 Like

Hello! Did you solve the probleme? I have the same probleme with that type of signal..

2 Likes

Did you solve the problem?

1 Like

If you solve problem, can u share us? pleaseee

For those who are asking "did you solve the problem": Please also read the answers in this thread...

Taifun