Adding bluetooth (HC05) to Ramps 1.4 headache May 08, 2019 02:51PM |
Admin Registered: 11 years ago Posts: 3,096 |
Re: Adding bluetooth (HC05) to Ramps 1.4 headache May 08, 2019 09:28PM |
Admin Registered: 13 years ago Posts: 6,995 |
Re: Adding bluetooth (HC05) to Ramps 1.4 headache May 09, 2019 02:22AM |
Admin Registered: 11 years ago Posts: 3,096 |
Quote
Dust
The bluetooth module when being used is plugged into rx0/tx0 on the ramps (it just bypasses the usb/serial chip)
BUT
the configuration program expects the bluetooth module on the arduino rx2/tx2
On ramps this is Digital pin 17 (RX2) on aux4 and Digital pin 16 (TX2) on aux4
The setup program prompts for user input over usb so you need the serial monitor open at 57600 baud
Re: Adding bluetooth (HC05) to Ramps 1.4 headache May 09, 2019 04:05AM |
Admin Registered: 13 years ago Posts: 6,995 |
Re: Adding bluetooth (HC05) to Ramps 1.4 headache May 09, 2019 04:34AM |
Admin Registered: 11 years ago Posts: 3,096 |
Quote
Dust
I've done it before, but a long time ago... it is a very common arduino thing to do..
Did you get as far as the serial monitor saying "Device speed detected" ?
Are you trying to pair it with another HC05 module or something else like a pc?
Where does it fail... wont link, wont talk serial, wont power on?
Got something like a ftdi to serial converter?
If you have wire that to the HC05 and plug it into your pc (you will need the resistor voltage divider) and open up a terminal program (eg putty) with baud rate at 9600
If you tried changing the baud rate you might have to try a few baud rates to work out what it is now talking.
Send the device a "AT" does it reply?
Once you have it talking reset it and set a new baud rate
ie
AT+ORGL
AT+UART=115200
AT+RESET
Most useful AT commands are
AT : Ceck the connection.
AT+NAME : See default name
AT+ADDR : see default address
AT+VERSION : See version
AT+UART : See baudrate
AT+ROLE: See role of bt module(1=master/0=slave)
AT+RESET : Reset and exit AT mode
AT+ORGL : Restore factory settings
AT+PSWD: see default password
Re: Adding bluetooth (HC05) to Ramps 1.4 headache May 09, 2019 08:34AM |
Admin Registered: 13 years ago Posts: 6,995 |
Re: Adding bluetooth (HC05) to Ramps 1.4 headache May 10, 2019 03:13PM |
Admin Registered: 11 years ago Posts: 3,096 |
Re: Adding bluetooth (HC05) to Ramps 1.4 headache May 11, 2019 06:07AM |
Admin Registered: 13 years ago Posts: 6,995 |
void bauddetect( long x){//this solved baudrate Serial.print("baudrate:"); Serial.print(x); int byte1; int detect=0;//used to know if detected long time_keeper;//get start millseconds Serial2.begin(x);//starts at baudrate delay(600);//stabilizer time_keeper=millis(); //sink up serial Serial2.print('\n');//initialization command Serial2.println('\n');//initialization command //discard and garbage characters while(millis()-time_keeper<2000){ //while within if (Serial2.available() > 0) { byte1= Serial2.read(); };// conditions met for char sent }//while loop //real test time_keeper=millis(); Serial2.println("AT");//initialization command while(millis()-time_keeper<2000){ //while within if (Serial2.available() > 0) { byte1= Serial2.read(); Serial.print("[0x"); Serial.print(byte1,HEX); Serial.print(","); Serial.print(byte1); Serial.print("]"); if (byte1==79 | byte1==75){ Serial.print("."); detect++; //if o or k is sent then increment byte1=0; //clear } };// conditions met for char sent }//while loop Serial2.flush(); Serial2.end();//stops serial at baud rate delay(200);//stabilizer if (detect < 2) {x=0; Serial.println("_no");}//clears if result is not a valid responce from bt host else{ Serial.println("_yes");// if baud then final_baud=x;//store baud rate for use. } }
detecting device.... baudrate:1200_no baudrate:2400_no baudrate:4800_no baudrate:9600_no baudrate:19200_no baudrate:38400[0x4F,79].[0x4B,75].[0xD,13][0xA,10]_yes baudrate:57600_no baudrate:115200_no baudrate:230400
Re: Adding bluetooth (HC05) to Ramps 1.4 headache May 11, 2019 11:51AM |
Admin Registered: 11 years ago Posts: 3,096 |
Quote
Dust
Your circuit looks good
had more of a play
the code provided is badly flawed!
It send data to the module at the wrong baud rate, then looks for a reply. It doesnt get one. that is ok.
then it tries the correct baud rate, but the module input buffer is already full of crap data from before, so it errors (ideally the module needs reset every try...)
but since that not is possible...
I have changed their code.. replace the function void bauddetect( long x) with the code below.
I've left some debugging in stuff in [ ] brackets... doesn't hurt and shows there is signs of life.
You do still need to power up the module in slow blink mode
NB setting the baud rate will not change the rate detected, this is the data rate for the BT link not the command rate.
void bauddetect( long x){//this solved baudrate Serial.print("baudrate:"); Serial.print(x); int byte1; int detect=0;//used to know if detected long time_keeper;//get start millseconds Serial2.begin(x);//starts at baudrate delay(600);//stabilizer time_keeper=millis(); //sink up serial Serial2.print('\n');//initialization command Serial2.println('\n');//initialization command //discard and garbage characters while(millis()-time_keeper<2000){ //while within if (Serial2.available() > 0) { byte1= Serial2.read(); };// conditions met for char sent }//while loop //real test time_keeper=millis(); Serial2.println("AT");//initialization command while(millis()-time_keeper<2000){ //while within if (Serial2.available() > 0) { byte1= Serial2.read(); Serial.print("[0x"); Serial.print(byte1,HEX); Serial.print(","); Serial.print(byte1); Serial.print("]"); if (byte1==79 | byte1==75){ Serial.print("."); detect++; //if o or k is sent then increment byte1=0; //clear } };// conditions met for char sent }//while loop Serial2.flush(); Serial2.end();//stops serial at baud rate delay(200);//stabilizer if (detect < 2) {x=0; Serial.println("_no");}//clears if result is not a valid responce from bt host else{ Serial.println("_yes");// if baud then final_baud=x;//store baud rate for use. } }
output will look like
detecting device.... baudrate:1200_no baudrate:2400_no baudrate:4800_no baudrate:9600_no baudrate:19200_no baudrate:38400[0x4F,79].[0x4B,75].[0xD,13][0xA,10]_yes baudrate:57600_no baudrate:115200_no baudrate:230400
Device info: baudrate:38400 BT Module: password: idname: -------Commands:-------------- 1........setbaudrate 2.....renamedeviceid 3.........Change pin - choose above options 1,2,3 -
Re: Adding bluetooth (HC05) to Ramps 1.4 headache May 11, 2019 12:42PM |
Admin Registered: 13 years ago Posts: 6,995 |
Re: Adding bluetooth (HC05) to Ramps 1.4 headache May 11, 2019 02:31PM |
Admin Registered: 11 years ago Posts: 3,096 |
Quote
Dust
It seems like the author favored pretty graphics over functionally...
setting a new baud rate for data looks like it might work, but setting a name and pin... more broken code...