if ( !advertising ) {

      useCodeLines(LAME_JOKE);

   }

Route / Route / Route

dynamic_feed comment

3Dip

Bluetooth Controller

Bluetooth Controller

calendar_today 05/03/2020  |  today   1   |  visibility   15249

[Status]: Finished but re-building, sorry! 08/03/2020



In this project:
1. We'll be using App Inventor [Jump to..]
2. We'll send text data through bluetotth
3. We'll receive data through Arduino [Jump to..]
4. All just to turn ON a LED [Jump to..]

Summary

The base idea is to send a PWM signal to a LED , the signal will come from an app made with App inventor and the signal is bluetooth.

Here's the end goal (spoiler alert)

[damn, i have to build it again and take pictures and a video, just hold on]

As you can(will) see, you set a simple configuration in the app, save it and press play. Arduino will receive the incomming input and save it, then, request the data and send it to a analog write.

Note: This tutorial won't cover any graphical behavioral or anithing relative to the visual design

Building the App

Front Panel

[Here's all the front panel blocks]

Alright, start a new project and add a bluetooth client, a tinyDB, a listview, a button and a webviewer.


At the start of the app we will see the the bluetooth connections and a start button; the start button will only send us to the controller screen with the bluetooth device to be controlled.
 

Customization sreen

[Here's all the screen_custom blocks]

Here we store some variables to configure the controller. First, we need a lot of text, checkbox and button inputs and a tinyDB to store the configurations.


The button [Save] will store all of the variables in one instruction and exit to the front panel again
 

Controller screen

[Here's all the controller blocks]

The controller screen is where the magic happens, the manipulation of data and the bluetooth controlling. First, we need: tinyDB and BT Client.


The X,Y and Z values will be used always and the angle and magnitude are a derivate of X and Z.

Building the Arduino code

The code goes like this:
1. Cheks if there's incomming input. Input starts with a '{'
2. Receives the input and stores it. Input ends with a '}'
3. When you need a number value you ask with the key valueOf("Key");
4. When you need text value you ask with the key textOf("Key");
5. Repeats.

For applications where the use of the valueOf() or the textOf() must only happen once every seral read (such this case) we must test the newData as
if(newData == true){valueOf();}

When we want to call valueOf() or textOf() repeatedly every time possible we must test the recAtLeast1Time as
if(recAtLeast1Time == true){valueOf();}.




Until understanding what does the recvWithStartEndMarkers() function does (see HERE), the rest is quite simple.
For the function:

textOf() only returns the value as text.

In this line:
char* pivot = strstr (receivedChars,key);
the variable pivot stores the receivedChars string but cuts from the start to the position of key

In this line
result = strtok(pivot+strlen(key)+1, ",}");
the result (value) of the input key is equal to: FROM: the pivot string + the characters in "key" + the character ':' TO: the next ',' or '}'

Example when the receivedChars is "{Y:1.23,CUSTOM:2.34}":
pivot =  "Y:1.23,CUSTOM:2.34}"
result = FROM "1.23,CUSTOM:2.34}" TO "," = "1.23"
 
Finally, the valueOf() function only converts the string output of textOf() to a floating point variable. In this case, we assigned the value to a integrer variable so the conversion always results in a integrer number for the PWM.

Well, that's it for this tutorial. Watch more projects from Wireless Instrumentation for more projects like this or take a look on the projects cloud

Result

See the App in App Inventor
Download Project .aia



References

Serial Input Basics - updated
strcmp - C++ Reference
Online C Compiler - online editor

Comments



 
@ab-cb
@dip000


Este sitio web fue creado de forma gratuita con PaginaWebGratis.es. ¿Quieres también tu sitio web propio?
Registrarse gratis