Error in plotting graph because when the transmission speed is high

33 views
Skip to first unread message

Jahangir Ziaul

unread,
May 6, 2018, 7:30:28 AM5/6/18
to MIT App Inventor Forum
Sir, I have been working on a project where I have to plot data received from an Arduino. The data received from the arduino is at 9600 baud. The problem there is, is a data loss in the process and the graph is not accurate.
blocks.png

SteveJG

unread,
May 6, 2018, 8:55:01 AM5/6/18
to MIT App Inventor Forum
Things to try:

1)  Decrease pr imcrease the ms of your Clock1.TimerInterval  by a factor of perhaps 10 and see what happens to your plot.  If no improvement, increase/decrease by a factor of 100

2)  Do NOT continually monitor the  y value on the screen.     Temporarily disable the          set Label2.Text to  get global y   blocks.   Why?  Screen graphics is App Inventor's worst feature; they are slow compared to graphics using scripting languages.  Eliminating the posting of the data value continuously could result in an improvement in the actual graphing.

3) consider making the graph using the chartmaker extension:    https://github.com/MillsCS215AppInventorProj/chartmaker   instead of graphing with the Canvas.

Regards,
Steve

Ghica

unread,
May 6, 2018, 10:55:35 AM5/6/18
to MIT App Inventor Forum
Another thing to try is to make sure you always get complete messages. Do your Arduino messages end with a println?
If yes, you could set the delimiter in the designer to 10 and read -1 bytes when you are reading. This will ensure that you get exactly one message.
The speed and frequency of what you receive does not only depend on baudrate though. More important is the delay between messages and you have to tune that. Your clock time interval should be less than the delay at you Arduino side. See the FAQ in this forum under Bluetooth for examples and explanations.
Cheers, Ghica

Jahangir Ziaul

unread,
May 6, 2018, 11:41:09 AM5/6/18
to MIT App Inventor Forum
Sir, can you please explain me how to increase or decrease Clock1.TimerInterval by a factor.

Ghica

unread,
May 6, 2018, 11:51:32 AM5/6/18
to MIT App Inventor Forum
You can set the timer interval to anything you want, either in the designer or by setting using a block set Clock.TimerInterval to ...
Default is 1000 milliseconds, but you could set it to 500 milliseconds for example, to see if you get less data loss. This very much depends how fast you are sending things from the Arduino side, and as already said, Baud rate has not much to do with it, because Android just buffers the messages if they are not read fast enough.
Cheers, Ghica.

SteveJG

unread,
May 6, 2018, 11:52:20 AM5/6/18
to MIT App Inventor Forum
I do not know what your TimerInterval is set to at present.  If you use the Clock default value, it is set at 1000 ms ( 1 second).     So if I change 1000 ms by a factor of 10, the new value would be set to perhaps 100ms if reduced by a factor of 10  or it would be set to 10000 (which would be certainly too much in your case).  If you set the Timer Interval to 1 in your app, set it perhaps by a factor of 10  to 10 ms.   What I mean is set the TimerInterval by significant amount of ms higher or lower.

You can do that with Blocks.      set Clock1.TimerInterval to  10      ms   or to 100 or 1000.   Just try a variety of values.   What I expect is you clock is changing either too fast or too slowly, depending on what value you are presently using.

Does that work?

Jahangir Ziaul

unread,
May 6, 2018, 12:20:30 PM5/6/18
to MIT App Inventor Forum
Sir, after numerous different attempts with Clock1.TimeInterval, I am facing problems like the one attached. This error is not continuous but are frequent. Please help.
Screenshot_20180506-214658.png

SteveJG

unread,
May 6, 2018, 12:32:07 PM5/6/18
to mitappinv...@googlegroups.com
Your error is somewhere here




The error probably happens whenever the global Y_before or global Y value are greater than  the Canvas Height .    Possible solution  an    IF statement     IF Y  < Canvas.Height then   display on the Canvas, if not then do not  In the example you seem to be subtracting  929 from the canvas height of 254.   Is that possible?


Jahangir Ziaul

unread,
May 6, 2018, 12:48:49 PM5/6/18
to MIT App Inventor Forum
,[254], [92
9]

Sir, this is not executable and I am not able to analyze why such kind of values are being received. It should rather be [254],[92]. I used an if statement, but there's no improvement.

SteveJG

unread,
May 6, 2018, 1:10:35 PM5/6/18
to MIT App Inventor Forum
1)  How did you use the IF statement?  We cannot see what you did Jangangir .

2) What you get ( ,[254], [929]  )   is a result of how you parse the received bits..      See Ghica's first post for a possible solution   or you could use the DoIt debugger to find out what is happening.  This link shows how to do that 





Abraham Getzler

unread,
May 6, 2018, 1:23:47 PM5/6/18
to MIT App Inventor Forum
I suggest you upload your current .ino file and
your Downloaded Blocks Image.

ABG

Reply all
Reply to author
Forward
0 new messages