DEC to HEX from Bluetooth connection to create a live graph

troubleshhot.aia (380.2 KB)

Hello, MIT community. I have a robot sending me lots of data, and I want to use some and graph it. Currently, the data I receive is in decimals, and I try to transform it in HEX to combine it then since I am receiving it in a 1byte ID - 2-bytes data structure. Overall I received 48 bytes. The issue is in Screen2 of the .aia file.

An example of the data is shown at the bottom of the screen.

My negative numbers are transformed correctly but my positive numbers are not when using the function convertnumberbase10tohex.

0x05 comes as decimal 5 determines first data
the next 2 bytes if negative correct transformation, if positive wrong transformation

I haven't set up the graph yet.

After awhile the app slows down and the data listed becomes disorganized


The 2 bytes after 5 is the timestamp sent by the robot.

Once I get the conversion correct I can then store the values in their own lists and graph them separately.

Any help is greatly appreciated.

Warm thanks

Can you post the code that sends the 5 and the timestamp?
That's needed to know how to reassemble them.

P.S. Your idea of the ^ operator differs from AI2's idea of the ^ operator.
Use the tooltips.
This is trickier than I expected - ABG

Post the robot code.
You might be transmitting faster than AI2 can receive and process.
The robot code is needed also to see how data formats match up on the transmitting and receiving ends of the link.

If that's the case, convert the positive numbers to negative, then remove the minus sign from the hex.

The after 5 - I mean the first column is the data ID, which is constant until there is the shift after about 5 seconds. Each row is a different type of data that comes in two bites (decimals) that I have to convert in HEX and then join to reconvert into decimal.

As mentioned the negative conversion code I have works.
The positive using only convert number base 10 to hex doesn't. For example, if I have a decimal 162 I should get A2, but I get A3 instead similar goes with the second digit where I would get a correct conversion with a added 1infront of it. Weird things like this.

Anyways, I really do appreciate your input.

It could be..What is the max speed I can read in AI2? Unfortunately, I cannot post the code for reference. In the picgui in Matlab my baudrate is at 115200.

Props for the picture is about what I am doing :slight_smile:

Do you mean adding an if statement that says if the number is higher than 0, multiply by -1?
Honestly, I think it is genius, and it should solve the issue in the short term. Although I still wonder why the convert number base 10 to hex does not work correctly.

I will try it @SHUBHAMR69 . Thank you

1 Like

The AI2 hex conversion block in question only understands positive numbers.

Consider sending unsigned bytes instead of signed bytes to simplify conversion of multi-byte integers.

The 115200 baud rate is irrelevant to your backlog problem. I was thinking more of a Lucy and Ethel on the Chocolate Assembly Line problem.

Without knowing the data type of the 16 bit datum being sent in those two bytes, it is impossible to know the right conversion technique.

1Mbit/s (1000000bit/s), 8N1, No HW-Flow Control
The main node sends at 100Hz.
The message contains 16 signals separated by a signal ID.
Each signal is sent as UINT16 (after being converted accordingly), and the LSB is sent first.

Here is my take on receiving mixed UInt8 and UInt16 data ...




troubleshhotABGScreen2.aia (375.1 KB)

P.S. These blocks can be dragged directly into your Blocks Editor workspace.

See A way to group projects by theme - #10 by ABG
for a demo.

Note how I switched to Unsigned bytes, and I eliminated the double list-text conversion you had on the way into the Data list. (ReceiveUnsignedBytes returns a list).

At first it goes well but the data conversion is off. "183" "112" = B870 = 46960 instead it shows 28855

It gets a little messier once it gets too much data (which I have to figure out), but the conversion is still off.

Sorry for the late reply and thank you for all the help @ABG .

P.S. the first number I am receiving is time. Do you think there is a way to store the first value I receive and subtracted from it. Such as I receive 200 and I desplay it as a 1. Number - First received number? This way I use it as my X value for the graph

P.S.S. I am not using BLE

Let's do this two ways, to verify that the LSB (Least Significant Byte) indeed precedes the MSB (Most Significant Byte) ...

Your conversion technique requires the MSB first followed by the LSB:
183 * 256 = 46848
46848 + 112 = 46960

My conversion technique matches the spec you posted in DEC to HEX from Bluetooth connection to create a live graph - #9 by cvignola (LSB is sent first.)

112 * 256 = 28672
28672 + 183 = 28855

So we have your interpretation, and your spec.
Could it be that you interpret "LSB" as Left Side Byte ?

You are correct; I was doing the conversion in reverse. Because as the data moves, the first byte changes fast but the second changes once the first value makes a complete revolution.

I do have a complication with this system.

After the ID, each value I am receiving needs to be converted following its specific conversion. For example, the value in row 1 needs to be divided by 1000 before storing it, whereas the value in row 2 is multiplied by 3.7 and so on for each row.

Using global pairs, how do I achieve this without indexing as I was doing before?

Considering that I want to store the values and plot them singularly

I haven't seen any usage of that column 1 value (5,21,37,...(n*16 - 11),...,245) in this thread, other than their constancy.

Do you expect any other values than those 16 values?

If not, you might as well just accumulate your 16 bit values in a 16 column table (list of lists), one row per 48 byte packet.

On the other hand, this is getting ahead of yourself. You have no packet wrappers to stay in sync.

The alternative is to add your (id, value) pairs to a long two column log table as they arrive, and filter the table by column 1 value later when you want to graph your data by arrival order.

Regarding your normalization problem, I suggest keeping a constant lookup table of multiplication factors
(5, 0.001),
(21, 3.7),
...

to be used in conjunction with the LOOKUP IN PAIRS list block.

Sample filter routines: