Welcome! Log In Create A New Profile

Advanced

RAMPS 1.4 and HC05 Bluetooth communication

Posted by QyKiske 
RAMPS 1.4 and HC05 Bluetooth communication
June 05, 2018 09:11PM
Hello everyone, i'm fairly new to RAMPS 1.4. I'm currently working on a project and i need some advice. My project consists of using the Arduino MEGA + RAMPS 1.4 to control 4 stepper motors via bluetooth (HC-05). I found there are different ways to do this but i don't know which set up is easier or if i understand them correctly.

1. Serial1 on pins 19 (RX) and 18 (TX), (on ramps Z-Min and Z-Max endstops pins), which means that i have to use the voltage divider to regulate the 5v(from the RAMPS) to 3.3v(Rx pin on the bluetooth)
2. Serial0 on pins D0 and D1, saw in this tutorial
3. Hook up the HC05 to Arduino UNO and connect it to the MEGA

I'd appreciate any advice that you can give and i wish you all a good day
Re: RAMPS 1.4 and HC05 Bluetooth communication
June 05, 2018 10:34PM
The different options are there so you can avoid other hardware

there are 4 serial ports

2 RXD0 PE0 ( RXD0/PCINT8 ) Digital pin 0 (RX0) usb
3 TXD0 PE1 ( TXD0 ) Digital pin 1 (TX0) usb
45 RXD1 PD2 ( RXDI/INT2 ) Digital pin 19 (RX1) Z-MAX
46 TXD1 PD3 ( TXD1/INT3 ) Digital pin 18 (TX1) Z-MIN
12 RXD2 PH0 ( RXD2 ) Digital pin 17 (RX2) on aux4
13 TXD2 PH1 ( TXD2 ) Digital pin 16 (TX2) on aux4
63 RXD3 PJ0 ( RXD3/PCINT9 ) Digital pin 15 (RX3) Y-MAX
64 TXD3 PJ1 ( TXD3/PCINT10 ) Digital pin 14 (TX3) Y-MIN

It depends on what other hardware you have

If you have a lcd then serial 2 is blocked
if you have a mks touch screen then d0 d1 blocked

if you use the others, and you have endstops your going to have to move the endstops elsewhere..

using d0/d1 is fractionally easier as you don't have to modify the serial port in firmware or remap pins. Just remember you cant have the usb cable plugged in at the same time (is connected to same serial port)
Re: RAMPS 1.4 and HC05 Bluetooth communication
June 06, 2018 05:07AM
Hello Dust,

Thank you for your reply.
So i've started a simple test to see if i can get the set up correctly. I hook up my HC05 to AUX1 (pin D0 and D1) on the RAMPS. I wrote a test code that should allow me to communicate by bluetooth.
I've created an app that allows me to send a value to the HC05 and it worked nicely, so no problem on that end. For the testing, i only put one motor connected to the RAMPS. The value that i send by phone should be able to turn the motor if it can communicate with the HC05.

The problem when i run the code is that, the motor waits for the value even when i send it multiple times. So i'm guessing that the HC05 receives the value but it can't send it to the RAMPS.

SO this is the code that i wrote:


#include

SoftwareSerial BT(0,1); // define fin number D0 and D1 on the RAMPS
String state;// string to store incoming message from bluetooth

#define X_STEP_PIN 54 //define pin number
#define X_DIR_PIN 55
#define X_ENABLE_PIN 38
#define X_MIN_PIN 3
#define X_MAX_PIN 2

#define LED_PIN 13

#define PS_ON_PIN 12
#define KILL_PIN -1

void setup() {

pinMode(LED_PIN, OUTPUT);

pinMode(X_STEP_PIN, OUTPUT);
pinMode(X_DIR_PIN, OUTPUT);
pinMode(X_ENABLE_PIN, OUTPUT);

digitalWrite(X_ENABLE_PIN , LOW);

Serial.begin(9600);

while(!Serial);
}

void loop () {

while (BT.available()){ //Check if there is an available byte to read
delay(50); //Delay added to make thing stable

int X_POS_1 = BT.read(); //Read the number sent from the bluetooth

digitalWrite(X_DIR_PIN,HIGH); // Enables the motor to move in a particular direction

for(int x = 0; x < 200* X_POS_1; x++) { // Makes pulses for making one full cycle rotation
digitalWrite(X_STEP_PIN,HIGH);
delayMicroseconds(100); // faster speed of rotation
digitalWrite(X_STEP_PIN,LOW);
delayMicroseconds(100);
}
delay(1000); // One second delay

digitalWrite(X_DIR_PIN,LOW); //Changes the rotations direction

for(int x = 0; x < 400* X_POS_1; x++) { // Makes pulses for making two full cycle rotation
digitalWrite(X_STEP_PIN,HIGH);
delayMicroseconds(500); // slower speed of rotation
digitalWrite(X_STEP_PIN,LOW);
delayMicroseconds(500);
}
delay(1000);
}
}



if anyone can spend a little time, i'd be very grateful.

Thank you and have a nice day
Re: RAMPS 1.4 and HC05 Bluetooth communication
June 06, 2018 07:54AM
D0/D1 is real hardware serial tx0/rx0 no need for SoftwareSerial

So remove softserial and replace all BT references with serial

Also since your using tx0/rx0 you can unplug bluetooth and plug in usb and test via serial console in arduno ide. Make sure firmware is actuly doing correct stuff

The "while(!Serial);" also worries me Its not needed on a mega.
Re: RAMPS 1.4 and HC05 Bluetooth communication
June 06, 2018 09:29AM
Hello Dust,

Thank you very much, i've modified the code like you said and it worked just the way i wanted to.
Now to write the complete program for the 4 motors and my project should be up and running nicely.

Thank you again for you help.

Have a nice day.
Sorry, only registered users may post in this forum.

Click here to login