Chart 2D to plot two variables received from Arduino via Bluetooth (HC-05)

Hi, does anybody know how to create a chart to dinamically plot two variables received from Arduino in a graphic X by Y?

You can use the chart block provided, you can also take a look at this post for an example using highcharts

1 Like

Be sure to use println() at the end of each message to send from the sending device, to signal end of message.

Only use print() in the middle of a message.

Be sure not to println() in the middle of a message, or you will break it into two short messages and mess up the item count after you split the message in AI2.

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.

Some people send temperature and humidity in separate messages with distinctive prefixes like "t:" (for temperature) and "h:" (for humidity).
(That's YAML format.)

The AI2 Charts component can recognize these and graph them. See Bluetooth Client Polling Rate - #12 by ABG

To receive YAML format messages, test if the incoming message contains ':' . If true, split it at ':' into a list variable, and find the prefix in item 1 and the value in item 2.

Hi @cavour.martinelli, welcome on board.
first of all: before trying to plot the data received by an Arduino board (and a HC05 shiled), is everything fine with the BT comm's between app and Arduino ?
In other words, are the data correctly received by the app (i.e do you show them in a label, and are they as you expect ?).
Once you're done with that, you could have a look here:

As a general hint, please remember to make one step at a time: for example split your project in two, one part relevant to the BT comm's, and the second relevant to the plot of data (that, for simulation, you can inject from a list into the plotting procedure). When both parts work well, you can glue them together :nerd_face:

If you need further details, do no ìt hesitate to ask more.
Cheers.

Hello @uskiara , thank you very much for you answer. Yes, the BT comm is working and I can show both values into labels. I just have to plot the graphic using the Chart tool. In the X axis I have to plot the voltage value and in the Y axis the electrical current value as soon as the app receives the values. That’s all.

Nice to read that, @cavour.martinelli. Now, have you already had a look to the post linked by @davidefa ? Most probably you wil find therein the solution you need. :+1:

In addition you can also have a look to an old .aia file of mine, here annexed:
Low_Pass_Filter.aia (123.0 KB) where I plot data generated by a low pass filter (I guess you can extract from it parts of code or simply some ideas).
Best wishes for your project.
Cheers.

1 Like

:+1: