Plotting real-time graph using HC-06, MPU6050 and Arduino Nano

324 views
Skip to first unread message

Sonia Cristina

unread,
May 7, 2018, 3:18:38 PM5/7/18
to mitappinv...@googlegroups.com
Hello!

I am using a MPU 6050 module (Accelerometer, Gyroscope, Temperature) to send data to the Arduino Nano using a Bluetooth Module (HC-06) to transmit data to Android. The project purpose is to create an application using App Inventor 2 which should plot a real-time graph as soon as it receives data from the Bluetooth Module.  

This is the app so far. I managed to connect it to the Bluetooth Module, but it won't plot anything. Any ideas what am I doing wrong? I've started using App Inventor 2 two days ago so I am pretty sure I am missing something. 

Attached you will find the .aia file and the Arduino code (in case you need it). 

Thanks!
TestGrafic7mai.aia
test1.ino
blocks.png

Abraham Getzler

unread,
May 7, 2018, 5:06:22 PM5/7/18
to MIT App Inventor Forum
You were very close.

See attachments.

You needed to set a BlueTooth Delimiter of 10 to receive just one complete message at a time.
You needed to only process text input if BytesAvailable > 0.
You also needed to request -1 bytes, to just get 1 complete message at a time.
Your .ino file was set up right, with a println() at the end of the message.


You were sending boiler plate text with each reading, which had to be split away from
the corresponding number for the graphing.  It turned out to be easier to not split at '|',
but instead to keep the input message and pull each code one at a time as needed, using the included code procedure.

I adjusted your line draw procedure calls to receive proper values,
and eliminated all reference to the no longer needed list variable.

It's up to you to test.

ABG

prints with boiler plate.PNG
Clock enabled at 100 ms.PNG
blocks.png
TestGrafic7mai_ABG.aia
GraphicClock.PNG
DelimiterByte should be 10.PNG
code.PNG

Sonia Cristina

unread,
May 7, 2018, 5:37:44 PM5/7/18
to MIT App Inventor Forum
It still won't plot anything :( 

Abraham Getzler

unread,
May 7, 2018, 5:45:56 PM5/7/18
to MIT App Inventor Forum
I guess it's Debugging Time.

I would start with adding an InputLabel to show the global input variable.
Assign it in the inner IF statement in the Clock Timer,
so you can see if you are receiving data.

Also add a BytesAvailableLabel, to show the Bytes Available
value each cycle, to let you know the backlog size.

Let us know what you see.

ABG

Abraham Getzler

unread,
May 7, 2018, 5:54:34 PM5/7/18
to MIT App Inventor Forum
Look at what you are doing with the variable AxisTime.

You are using it as your x value everywhere,
incrementing it at the bottom of the inner Clock Timer section,
but also resetting it to 0 at the top of that same section.

So all your points are at the left edge of the canvas.

Remove that resetting it to 0, and instead, where you increment the x value,
check if it is past the Width of the Canvas, then reset it to 1.

ABG

Sonia Cristina

unread,
May 8, 2018, 4:53:01 AM5/8/18
to MIT App Inventor Forum
It still doesn't work. I don't know what else to do. 

Abraham Getzler

unread,
May 8, 2018, 11:49:21 AM5/8/18
to MIT App Inventor Forum
Also, post your new Downloaded Blocks Image
and your new screenshots.

ABG

Sonia Cristina

unread,
May 8, 2018, 12:03:27 PM5/8/18
to MIT App Inventor Forum
I added those two labels and I took a screenshot of what I'm receiving. So I am receiving data but it still won't plot. 
TestGrafic7mai_ABG_1_1.aia
32191903_10213145639297549_7067523192721506304_n.png
Blocks_graf.png

Abraham Getzler

unread,
May 8, 2018, 12:35:08 PM5/8/18
to MIT App Inventor Forum
See attached.

You had 1 block in the wrong place
  (displaying a value before it was calculated),

and three blocks that should not be repeatedly done in the Clock Timer loop,
but should be elsewhere in a Start button.

ABG

Blocks_graf.png

Sonia Cristina

unread,
May 8, 2018, 2:54:35 PM5/8/18
to MIT App Inventor Forum
It's working! 
Thank you very much for your help!!! 
31960182_10213146359795561_4353343546594426880_n (1).png
Reply all
Reply to author
Forward
0 new messages