Questions: app receive the integer send by Bluetooth

I am using TM4C123 and using keil software to program. I have two reading value, the one is get from temperature senor and another s form CO2 sensor. the value of the temp reading i storage it in a 8 bit integer, and for CO2 reading i storage it in 16 bit integer, in order to send CO2 reading, I send them for 2 sperate 8 bit integer. I want to know how to receive this number in the MIT inventor and display it. this is what i have so far.

Is there a print command on your hardware/software platform?
That would make this much easier.

i think there is print command, but i have no idea how to use that. Can u show me on that ? thanks

The print and println() commands allow you to send text.
Here is standard advice for receiving text messages...

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:

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.

thanks you for helping me on that, i was check with my instructor, he said we do have that command in keil, because he do not no library to call that. And we are using TM4C123 controller Can u give me some idea how to send integer?

From the Label names in your app, I see you want to send temperature and CO2 in the same data stream?

Sending low level codes like integers is a problem, since there is no way to tell from an incoming integer if it represents a temperature versus a CO2 level.

If you could find a print stream library, you could compose messages like

  • T:35
  • CO2:.04

that carry labels describing their numbers.
(This is called YAML format.)

i do not know is that correct or not. i my opinion, in my coding, i send 3 8 bit integer for each time. so in the MIT, can i just storage those 3 8bit integer to three variable follow the order, and display them?

Check this and give feedback:

1 Like

thank you for giving me the idea, I have one more issue with my coding. for Temp reading, it is an 8-bit integer, but for CO2 reading, it actually is a 16-bit integer. As I show in the coding, I separate them into 2 8-bit integers in order to send them. so i think after i receive them i still need to combine them together. For this step how can I do that? this is my first time to creat this app, i have no idea to use them. thanks

Try it:

Send a single byte first, then two split bytes.

Show us what you get in the labels.

for this situation, do i need to initialize a variable and storage each 8-bit integer in them? and then do calculations to get them together

The blocks I gave you are test blocks. I am waiting for your reply whether it works and what you get in the labels, then there will be further help.

Set the data sending frequency lower than the component clock frequency.

ok , i will try on that

Yes, because in order to advise you more we need to see what you are getting and whether it is correct.

i have test on that there is nothing display on the label block

Are you sure anything is being sent over blueooth? Can you install app from play store, bluetooth terminal on your phone? Connect the terminal with your bt module and see if it receives anything.

You can set the label color to red when it detects 3 bytes.

yeah, i am considering if there is problem on Bluetooth library. Which app i can install on the play store? Are you familer with TM4C123, would you mind have a look on my code stuffs? And I am coming another question, co2_calculation = rx_data[3]*256+rx_data[4]; in order to get CO2 reading number , i need to do this calculation, after i sepreat this 16bit integer into 2 8bits integer, do i still need to do this calculation in the MIT app?

I use this one. It works flawlessly.

Maybe at the beginning try to send some constant bytes from the module. Not from sensors, only constant.

As for the calculation, we'll see what the app receives. Perhaps the block receive 2 bytes will merge the bytes automatically.