Stepper motor control with app via bluetooth problem

hello ,
i'm in project , that controlling stepper motor (linear slide ) via Bluetooth .

i have my Owen code that i uploaded to arduino , the code is working perfect with bluetooth terminal app , but when i make app with mit inventor , when i press the button in the app that contain the code to move stepper motor steps, the motor don't move and don't get any response ,
but when i use the bluetooth treminal app it works very well ,,
i don't know where is the error

my code work when i send (x0) x is the axis and zero the steps of moving
it work well in bluetooth terminal app when i send (x0 ,x200,x300) any code i send it work well with bluetooth terminal app but the app i made with mit inventor that i make buttons when i click the buttons to move x0 or x200 or x300 not responding i don't know why ??
(upload://oPpdW4OKdsq4BiFkk5DD3MIGxJj.png)


attached the code i used and the blocks in the mit app )
any help please
thanks ,

Hello Mohamed

I see your working on a CNC mill or 3D Printer project?

Remove the Clock Timer, that is not helping at all! You can check if Bluetooth Is Connected in your Button Click Events.

It's all but impossible to navigate your script on the forum, could you please just post the Main Loop that receives data from the App, with the variable assignments?

thank you so much for interesting , yes my project like that "cnc mill " but i used for control gearbox , oh i'm sorry for that i remove the script
main loop.txt (1.6 KB)

i attached the main loop
and i removed the clock timer , but i don't understand what do you mean by button click events ?
variable is "x" then number of steps
ex : x0 , x122 ... and so on

Try with \n

bluetooth_cambio

1 Like

Hi Mohamed

Erm, that isn't the main loop :upside_down_face:

Arduino's main loop is literally: void loop().

Within it will be code to handle the arrival of the commands sent by the App - so that's what we want to see, since the App and the Arduino need to agree on the format of their communication. I'm expecting the Sketch to use Serial.read to collect the commands from the App and then apply to the gearbox.

(?)
Is it the code5?

1 Like

thank you for interesting , i will try and inform you the result

i'm sorry for that mistake Chris .

main loop i attached :+1:
main loop.txt (788 Bytes)

hi Juan ,

no it is code1
thank you very much for interesting
i hope you help me

Hi Mohamed

Lots of errors just in the loop. I can fix the basics. At this point, sending the data back to confirm receipt can be omitted - not sure it's even necessary.

#include "GantryXYZ.h"

GantryXYZClasses gantryXYZ;

//vars
unsigned int igUpdateTime;
char gVal[];

void setup()
{
// put your setup code here, to run once:
Serial.begin(9600); // open comms
gantryXYZ.setFeedrate(1000); // set default speed
igUpdateTime = millis();
}

void loop()
{

     if(millis() - igUpdateTime > 500)  //Loop approx every 1/2 second
     {
           igUpdateTime = millis();

           if (Serial.available() > 0)
           {
                    //Read Data From App
                    gVal = Serial.read();

                    gantryXYZ.storeBuffer(gVal);
                    gantryXYZ.processCommand();
                    gantryXYZ.move();
           }
     }   

}

Thank you for your interesting Chris
But how there is alot of error you found ..
But i can use any bluetooth terminal app and control the stepper work very normal ... i see the blocks in mit app there is error in it i don't know it ???

I will try that loop , Chris
And inform you the result

By the way - the button clicks in the App, I think the text should be sent without \n, but the best way to know is to try with and without :grin:

...also, in the Sketch, I can't see the gantry classes so I have assumed that part of the code is already correct.

thank you so much for your time Charis ,
by the way i will try with it and without it :grin: :grin: it and tell you about that ,
and for the sketch i use this code

and only upload this code to arduino , it works with Bluetooth terminal app in play store ,
But i want to make custom app for my project
thank you very mush for your help again :blush: :blush:

Looking at that sample from the :open_mouth:Sketch, there are errors such as how a char variable is declared - which makes me wonder how bad the rest of the code could be.

thank you Juan , it works with \n
thanks alot for your support and help

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.