Hello All-
I am new to this compiler and thanks to the amazing documentation and help, I am slowly learning it.
I am wanting to add Bluetooth to a project I had made years ago with a different compiler and want to upgrade it to HM-11 so I can control it with my iPhone.
I wanted the versatility of Master/Slave so I decided on the HM-11.
Anyone have any experience with this module?
-Regards
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have looked into this for a few days and read AT command sets.
With HM-11 I can easily see the modules and send AT commands and all seems to be fine.
My read question is if you do NOT have an iPhone of a serial terminal hooked to a target board and ALL you have is to microcontrollers (PICs) and how can you ensure that each time you power down, these two boards will connect to each other?
I get one as Master and other as slave, but it seems after the 1st transmit, they un-couple from each.
Must be something real simple I am missing.......
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
No sure. So, I clean up the code to understand. Try this.
A few points in the original code.
#option explicit was missing. But, I do not think this is the issue
ALLOC. Changed to a string. Alloc is essentially a lump of memory and using as a string may, or, may not work. The alloc would have created a reserved buffer ( I dont remember the default size of the alloc). Anyway, use a string.
HserPrint ( SendBTpacket, 1 ) would not output anything as USART1 is not setup, and there is not USART1 PPS.
I would check with an analyser that the strings are being sent on USART5. This will prove the comms are working and what you think you are sending, is actaully being sent.
#chip 18f67K40 #option explicitSubInitPPS'Module: EUSART1RX1PPS=0x0011'RC1 > RX1RC0PPS=0x000C'TX1 > RC0'Module: EUSART2RX2PPS=0x0031'RG1 > RX2RG0PPS=0x000E'TX2 > RG0'Module: EUSART3RB4PPS=0x0010'TX3 > RB4'Module: EUSART5RX5PPS=0x0032'RG2 > RX5RG7PPS=0x0014'TX5 > RG7EndSub//SetupBluetoothinteffaceDirPORTG.7Out'TX to Bluetooth module#define BT_TX PORTG.7 'Define TX for BT moduleDirPORTG.2In'RX from Bluetooth module#define BT_RX PORTG.2 'Define RX for BT moduleDirPORTF.2In'Connected status to proc#define BT_Connected PORTF.2 'Define the BT module is connected or notDirPORTF.3Out'Key or Enable: 1 for BT Command mode, 0 for Data mode#define BT_KEY PORTF.3 'Define for the command/data modeDirPORTF.7Out'3.3v subsystem power enable pin for Bluetooth#define BT_PWREN PORTF.7 'Power ENABLE for the Bluetooth module//InitialisevariablesDimSendBTpacketasString*32BT_PWREN=1'DISABLES THE POWER TO THE MODULEBT_KEY=0//USARTsettingsforUSART5whichisusedforBTmodule//SetPORTG.2RX5toinputDirPORTG.2In//SetPORTG.7pintooutputDirPORTG.7Out#define USART5_BAUD_RATE 9600#define USART5_BLOCKING#define USART5_DELAY 5 ms//BluetoothModele//ThefollowingsetstheBTmoduleinATmodeforsettingupwait1secBT_PWREN=0'APPLIES POWER TO BT MODULEwait10us//SetsuptheBTModuleSendBTpacket="AT+NAMERemote"HserPrint(SendBTpacket,5)'BT Module is now 'Master'SendBTpacket="AT+MODE2"'Both modules can send/receive data not include any AT command 'andperpackagemustlessthan20bytesHserPrint(SendBTpacket,5)
Last edit: Anobium 2023-09-03
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks Evan, I did not post all of the code as this is a learning code.
I have set up COM1 and it displays on the compiler's serial terminal what is supposed to go to the BT module.
I also changesd from ALLOC to STRING but no difference.
I did hook in my analyzer (should have already done that) and there does NOT seem to be any data going to the modules.
Will look closer into
SendBTpacket = "AT+RENEW"
HserPrint ( SendBTpacket, 5 ) 'RESETS BT Module
HserPrint ( SendBTpacket, 1 )
why HSerPrint works with com1 but not with com5.
I believe I have saet up com5 correctly:
startup InitPPS, 85
define PPSToolPart 18lf67k40
config MCLR=ON 'Uses the RESET pushbutton
SubInitPPS'Module: EUSART1RX1PPS=0x0011'RC1 > RX1RC0PPS=0x000C'TX1 > RC0'Module: EUSART2RX2PPS=0x0031'RG1 > RX2RG0PPS=0x000E'TX2 > RG0'Module: EUSART3RB4PPS=0x0010'TX3 > RB4'Module: EUSART5RX5PPS=0x0032'RG2 > RX5RG7PPS=0x0014'TX5 > RG7End Sub// Template comment at the end of the config fileThe direction has been checked for the BT module as well as the com5.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello All-
I have tested my code with a wired connection between the two boards and they work just fine.
Learned a few things along the way.
I plugged in the HM-11 modules one at a time and looked on my iPhone to see that they were advertising and they were - I can them on my iPhone one at a time.
Then, again one at a time, I pushed 1 of the 4 buttons on the board to see if my iPhone would see the number: button1 = 1, Button2 = 2, etc. and everytime I pushed a button I would see its number on my iPhone.
I see that both BT modules transmit as they should to my iPhone one at a time.
I then reset both boards and looked to see the indication LED on the modules was steady which means they are connected and they were. I also checked on my iPhone to ensure I did not see them advertising because they were 'linked' to each other - I did not see them on my iPhone.
When I press a button on either board, the other board does not display on the LCD display as it did with just the wired connection.
So, I think I am not understanding something in the setup for these modules to send and receive to each other however, the send and receive to my iPhone when connected one at a time.
Here are my 4 commands I send to the modules:
AT+RENEW - for both boards
AT+NAMEMain - for the Main board
AT+NAMERemote - for the Remote board
AT+ROLE1 - for the Main board
AT+ROLE0 - for the Remote board
AT+WORK - for both boards
Only difference between boards are the NAME and the ROLE.
Any suggestions?
-Stuck in Texas
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
He is no longer listed at that department.
I have read the white paper and it did not provide much help.
Most if not all are using these module to communicate to a cell phone or to a computer.
My goal is to have a micro talk back and fort to another micro without using a computer or cellphone.
Its easy to talk to a cellphone and a micro - not what I am looking to learn however.
Regards and thanks for the interest!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This has been solved - there is a resolvable issue which needs a new USART.h file.
Evan helped with this.
I am using a PIC18F67K40 and was using com5 for the bluetooth module.
Thanks Evan!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello All-
I am new to this compiler and thanks to the amazing documentation and help, I am slowly learning it.
I am wanting to add Bluetooth to a project I had made years ago with a different compiler and want to upgrade it to HM-11 so I can control it with my iPhone.
I wanted the versatility of Master/Slave so I decided on the HM-11.
Anyone have any experience with this module?
-Regards
This thread look interesting for these devices. https://sourceforge.net/p/gcbasic/discussion/579125/thread/1539e130db/
Send the author a private message to get his program ? This may help.
Thanks, will look further when back home.
Regards!
I have looked into this for a few days and read AT command sets.
With HM-11 I can easily see the modules and send AT commands and all seems to be fine.
My read question is if you do NOT have an iPhone of a serial terminal hooked to a target board and ALL you have is to microcontrollers (PICs) and how can you ensure that each time you power down, these two boards will connect to each other?
I get one as Master and other as slave, but it seems after the 1st transmit, they un-couple from each.
Must be something real simple I am missing.......
Here is what I have thus far for trying to alk to a HM-11 module:
Last edit: Anobium 2023-09-03
And I added this:
HserPrint ( SendBTpacket, 1 )
right after the line:
HserPrint ( SendBTpacket, 5 )
Just to ensure the data is going out and it was sent to the built-in terminal -good feature!
No sure. So, I clean up the code to understand. Try this.
A few points in the original code.
I would check with an analyser that the strings are being sent on USART5. This will prove the comms are working and what you think you are sending, is actaully being sent.
Last edit: Anobium 2023-09-03
Thanks Evan, I did not post all of the code as this is a learning code.
I have set up COM1 and it displays on the compiler's serial terminal what is supposed to go to the BT module.
I also changesd from ALLOC to STRING but no difference.
I did hook in my analyzer (should have already done that) and there does NOT seem to be any data going to the modules.
Will look closer into
SendBTpacket = "AT+RENEW"
HserPrint ( SendBTpacket, 5 ) 'RESETS BT Module
HserPrint ( SendBTpacket, 1 )
why HSerPrint works with com1 but not with com5.
I believe I have saet up com5 correctly:
startup InitPPS, 85
define PPSToolPart 18lf67k40
config MCLR=ON 'Uses the RESET pushbutton
Hello All-
I have tested my code with a wired connection between the two boards and they work just fine.
Learned a few things along the way.
I plugged in the HM-11 modules one at a time and looked on my iPhone to see that they were advertising and they were - I can them on my iPhone one at a time.
Then, again one at a time, I pushed 1 of the 4 buttons on the board to see if my iPhone would see the number: button1 = 1, Button2 = 2, etc. and everytime I pushed a button I would see its number on my iPhone.
I see that both BT modules transmit as they should to my iPhone one at a time.
I then reset both boards and looked to see the indication LED on the modules was steady which means they are connected and they were. I also checked on my iPhone to ensure I did not see them advertising because they were 'linked' to each other - I did not see them on my iPhone.
When I press a button on either board, the other board does not display on the LCD display as it did with just the wired connection.
So, I think I am not understanding something in the setup for these modules to send and receive to each other however, the send and receive to my iPhone when connected one at a time.
Here are my 4 commands I send to the modules:
AT+RENEW - for both boards
AT+NAMEMain - for the Main board
AT+NAMERemote - for the Remote board
AT+ROLE1 - for the Main board
AT+ROLE0 - for the Remote board
AT+WORK - for both boards
Only difference between boards are the NAME and the ROLE.
Any suggestions?
-Stuck in Texas
Oh, and I did reverse RXdata and TXdata on both just to be certain. When I did, I could not communicate to them via iPhone.
Any use? https://engineering.fresnostate.edu/research/bulldogmote/documents/11.%20HM10%20BLE_FTDI.pdf I would ping the author.
He is no longer listed at that department.
I have read the white paper and it did not provide much help.
Most if not all are using these module to communicate to a cell phone or to a computer.
My goal is to have a micro talk back and fort to another micro without using a computer or cellphone.
Its easy to talk to a cellphone and a micro - not what I am looking to learn however.
Regards and thanks for the interest!
Contact DS Tech. Companies are typically very helpful.
Thanks, will try that.
This has been solved - there is a resolvable issue which needs a new USART.h file.
Evan helped with this.
I am using a PIC18F67K40 and was using com5 for the bluetooth module.
Thanks Evan!