Hoping for some direction, I have created an app to send g code commands via Bluetooth to an Arduino uno running GRBL with a cnc shield v3.
I can connect to the Bluetooth no problem but sending a command the stepper motor fails to move.
I can send the same command using a serial interface with my laptop connected via Bluetooth with no problem. I do have to select the com port to use when connecting with the laptop.
The Bluetooth device is a HC05, the baud rate is set the same as GRBL and the HC05 is set as a slave.
Any pointers would be great thanks. Ignore the other buttons such as stop and the slider as they will be worked on once I get the stepper to move.
This is my flow-
You wouldn't normally send individual g code commands, normally the device would run a GRBL file. So are you building a GRBL stream on the Arduino and then sending that to the shield?
In your AfterPicking block, you cannot verify if the Client actually connected with that code, there is a block for that, which you have used @ button1.
We can't really guide you without also seeing the Arduino Sketch as it must tally with the App code. What tests have you performed to prove the hardware has been correctly set up?
Depending on your Android version, you may need to include permissions in your App code (search the forum). You also need to check the basics - do both the Android device and the Arduino have Bluetooth switched on? Is the Arduino receiving an appropriate power supply? Is there anything that could physically prevent a Bluetooth signal from reaching it's destination?
If the ListPicker is listing your target hardware, that's good news - we often have to allow a small amount of extra time for that to happen.
Concerning buttons - with button click, it is possible to click more than once in a row inadvertently. Using a button-up block instead would avoid that calamity.
Dear @Graham_Manuel,
as @ChrisWard has already said, without having a look to your Ardiuno code is difficult to help you, anyway, the first step that I can suggest you is to verify if really the BT communication is OK.
Since you say that if you send the same command with your PC the CNC works, I would concentrate my attention to the communication.
Therefore, my hint is to modify your Arduino code in order to send back to the app the echo of what is received and to display it into a label. In such a way you'll be sure that the comm's has closed the loop.
Once (i.e.only after) you are done with that, you can go on with the rest of your project.
Be also aware that you send commands once as text and sometimes ad couple of bytes: does your Arduino correctly interpret texts & bytes ?
The g code commands are text, so sending an individual command or a string of commands would work.
I have made another app that controlled a led connected to the arduino and turned it on and off, with the same code blocks so the connection does work.
The sketch is GRBL 1.1h and as I said I can send the same command using a serial interface with my laptop connected via Bluetooth to the arduino with no problem. I do have to select the com port to use when connecting with the laptop.
I have made another app that controlled a led connected to the same arduino and turned it on and off, with the same code blocks so the connection does work.
You did say originally that the stepper fails to move. Also, we don't know exactly what your App should achieve - if actually CNC machining, sending individual commands will cause latency (dwell) - that could damage the workpiece and/or cutter.
Upload your Sketch.
...and check the basics as I prompted before. You need more power to drive a stepper than you do an LED.
The next line in my post I said that I can get the stepper to move using my laptop and now my tablet using a serial Bluetooth terminal app.
There is nothing wrong with the Arduino, power supply, Bluetooth module or sketch as everything works correctly when receiving the code from the Bluetooth terminal app or from a terminal program on my laptop.
It has to be something I'm missing in the app I have created. Does the app actually send clean text? or is it amending something?
When using the serial terminal app, I can see the response from the Arduino with an ok.
Using the serial monitor in IDE connected to the Arduino via usb I can see the ok acknowledgement when a command is sent from both my laptop and the Bluetooth serial app on my tablet. And the stepper moves.
When using the app I created there is nothing. So, it seems the app is the problem.
The app appears to be connected as the led on the Bluetooth module flashes the way it should when connected.
It looks like the app isn't sending anything at all. Any ideas I can try.
The app appears to be connected as the led on the Bluetooth module flashes the way it should when connected.
This does not mean that the BT client on your app is working fine; this means only that the BT shield (HC05) and the device has been paired.
To allow an app to exchange data via BT you shall have BT and Localization permissions granted.
The first time that your app starts after the installation the operating system asks for those permission to be granted, but if you don't grant them at the first enquiry, at every update of the app the enquiry is not asked again, therefore if not granted at the first time, your app will never have such permissions. One solution can be to uninstall completely your app and re-install it again, taking care of the enquiries. Another solution is to enter the "app authorizations" menu of Android and to grant from there the access to BT and geolocalization.
Why you don't try my hint to echo from Arduino to the app what it is really receiving ? Only after having seen that the "communication loop" is really closed, you are sure that the BT comm's works.
EDIT: if you don't want to send back to the app what the Arduino board has received, you can , as @ChrisWard has said, forward it to the Serial Monitor.
Try also the hint from @ABG : probably the CNC, to interpret the command, needs not only the \n (0x0A = LineFeed) but also the \r (0x0D = Carriage Return).
So, I guess the Bluetooth serial app I have used was automatically adding it.
Yes, most probably the app you used can configure the end of line with:
no terminators
only Line Feed (\n)
Line Feed + Carriage Return (typically for old fashioned communications like typewriters) .
Nice to read that it works !
(please set @abg response as the solution, so anyone else who should have the same problem can focus directly on that post ! )