loading

In this example, I will show you how to communicate one micro controller to another micro controller BOTH WAYS via serial with cc2541 (BLE-HM-10). https://www.youtube.com/watch?v=6zXYH9arHMI For board design and code please download BLE_Duplex

Introduction

HM-10 is a BLE module for embedded system to get BLE wireless communication with BLE capable devices (e.g. iPhone and iPad). It is fully configurable by a rich and well documented AT command-set and allows transparent data communication via serial UART (default baudrate 9600bps). The Bluetooth 4.0 HM-10 is basically a breakout board for cc2541, it broke out the LED pins, RX/TX and also adding the voltage regulator that regular 5v to 3.3 v. sjineesprulbfdgd_zpsewhckphz-1

Bluetooth 4.0 HM-10 Master Slave Module

Bluetooth V4.0 BLE 2540 Hm-10

Step 1: Setup With FTDI + Arduino Serial Monitor + AT Command

Setup with FTDI + Arduino Serial Monitor + AT Command

There are so many things that you can do with Bluetooth 4.0 HM-10, but first you need to setup with FTDI cable to understand what and how it's doing.

You will need a FTDI cable and 4 female to male wires to hook up to Bluetooth 4.0 HM-10 / BLE

  bluetooth     On your computer, open Arduino. Make sure you select the correct usb serial port. Open Serial Monitor and make sure the baud rate is 9600, this is the default baud rate. Screen Shot 2015-11-17 at 11.37.35 AM Type in AT+NAME?     (NO SPACES IN AT COMMAND) you should get OK+NAME:HMSoftScreen Shot 2015-11-17 at 11.40.58 AM If it says nothing, check your connections. Now we can talk to BLE with AT command and the rest is simple. See more AT Commands at the very end of the post.  

Step 2: Sending & Receiving (Both Ways ) Setting the Master-Slave Mode

With this method, you can turn the device on and have them talk to each other right away, without pairing, without initializing ... it is wonderful. The data goes both ways.

First you will need to Query the native MAC address using AT Command AT+ADDR?

You will get something like this 20C38FF61DA1, each BLE has a unique MAC address.

Use AT+CON[param1] and AT+ROLE[param1] to pair to another device.

Example

BLE A has Mac Address 11C11FF11DA1, I used AT+ADDR? to figure it out BLE B has Mac Address 22C22FF22DA2, I used AT+ADDR? to figure it out

Send AT+CON22C22FF22DA2 to BLE A Send AT+CON11C11FF11DA1 to BLE B (Send the B address to A, A address to B)

Send AT+ROLE0 to BLE ASend AT+ROLE1 to BLE B (Doesn't matter which one)

Now it's ready to use on you ATMEGA 328P, Arduino or Attiny. The red light will stay solid after the connection has been made on both BLE. This should take less than a second.

Find out AT Command here

https://www.seeedstudio.com/wiki/images/c/cd/Bluetooth4_en.pdf

Step 3: Sending & Receiving Both Ways on ATMEGA 328P / Arduino

It's very easy to talk to ATMEGA 328P / Arduino with the BLE, you can just use the hardware serial. Software serial should work for Attiny 44 to talk to BLE.

The data can talk both ways! Just Serial.println(Whatever you want); In the code below, the ATMEGA 328Ps "analog reads" the potentiometer data and sends serial data via BLE to each other turn each other's servo.

Step 4: Example Board

I took out the FTDI cable pads and upload my program with ISP pins to save some space on my board. I want this board to be part of my wearable project, that is why it's ULTA compact.

I did not use any SMD male pins to save some vertical space, because this needs to be wearable.
Each micro controller below runs the same code! So as soon as the BLE is on, it starts to look for the assigned address, it takes less than a second. The solid RED LED indicator on the BLE means the connection has been establish.

To make this wearable and flat, I have flexible cable coming out of it.

The Arduino Code

//receiving
int led = 3; // the pin that the LED is attached to #include Servo myservo; // create servo object to control a servo

//sending int sensorValue = 0; int presensorValue = 0;

void setup() { pinMode(led, OUTPUT); myservo.attach(A2); // attaches the servo on pin 9 to the servo object myservo.write(90); // tell servo to go to position in variable 'pos' delay(500); myservo.write(80); // tell servo to go to position in variable 'pos' Serial.begin(9600);

}

void loop() {

//receiving while (Serial.available() > 0) { int pos = Serial.parseInt(); if (pos > 1 && pos < 180) { myservo.write(pos); // tell servo to go to position in variable 'pos' //Serial.println(pos); analogWrite(led, 255); } sender(); } sender();

analogWrite(led, 10);

}

void sender() {

// Sending // read the input on analog pin 0: //sensorValue = analogRead(A1); sensorValue = map(analogRead(A3), 0, 1024, 5, 175);

//with noise reduction if (sensorValue == presensorValue || sensorValue - 1 == presensorValue || sensorValue + 1 == presensorValue) { } else { Serial.println(sensorValue); } presensorValue = sensorValue;

delay(50);

}

<p>hello guys, i need a help to proceed with ble</p><p>I have BLE HM 10 module and FTDI module . when i start giving AT commands</p><p>it responds to following AT COMMANDS </p><p>COMMANDS RESPONSE</p><p>1. AT - OK</p><p>2. AT+ADDR? - 00:15:83:00:57:E2</p><p>3. AT+VERSION? - Firmware V3. 0. 6 Bluetooth V4 . 0 .LE</p><p>4.AT+NAME? - NO RESPONSE </p><p>Please let me know the further procedure (AT COMMANDS) to test and how to connect with android phone.</p><p>THANKS!!!</p>
Where did you buy your hm-10 modules. I had a horrible problem with getting fakes online. Also, the voltage level question....<br><br>You are using a FTDI cable that operates at 5 VOLTS. Do you need to use a voltage divider circuit (1k ohm/2k ohm) to bring down the voltage level to 3.3V at ftdi-TX/hm10-RX.<br><br>I have to ask because i had blown up several hm-10 modules (and a usb aerial module) before figuring this out
<p>Hey there, I need help!</p><p>I've a HM-10 and I need to connect to another BLE device that's suppose to supply my HM-10 with a bunch of data every few second.</p><p>My current condition is pairing with the device using AT+CON[mac] works and returns AT+CONNA and ends up with AT+CONNF.</p><p>I'm not sure what am I missing here. I've tried pairing it with my Android using a bluetooth terminal app and it works perfectly!</p><p>Is there any step that I'm missing like pairing or something?</p><p>Thanks!</p>
<p>There is an app for iOS that makes using the HM-10 easy to use. It is for a single pin output. There is also a link the sketch for it. I used it with Arduino Nano, HM-10, a Relay, junction box, and an outlet to turn my room light off at night without getting out of my bed. The app is FatBeard HM10 here https://itunes.apple.com/us/app/fatbeard-hm10/id1198432512?mt=8</p>
<p>Check out this android app:</p><p>https://play.google.com/store/apps/details?id=com.optimist.bleCentral&amp;hl=en</p>
<p>Hi,</p><p>If you are using the bare HM-10 module, make sure to cross connect RTS and CTS (pins 3 and 4, P1_4 and P1_5, UART_CTS and UART_RTS) otherwise the serial comms won't work. Note: Pins count from 1 top left, counter clock to 34 top right with the CC2541 chip facing you, antenna at the top. The manufacturers manual is confusing as it shows the antenna terminating on the right (Section 1.1 HM-10 Schematic), when it is in fact terminating on the left. Both diagrams in this instructable are correct.</p><p>Also note device is a DTE, so TX (pin 1, P1_6, UART_TX) is an output and RX (pin 2, P1_7, UART_RX) is an input.</p><p>The diagram in Step 1 eludes to this by cross coupling the TX and RX lines to an FTDI, effectively forming a NUL modem interconnection.</p><p>The AT command parser is poor quality (as you would expect), it requires all command strings be entered upper case (other than the name string). A command is considered entered once the interchar timer has been exceeded (for that given baud rate). ie no terminating character '\r'. There is no SReg support to set this via S3 (carriage return character). This means you will need to pre-store any commands and issue all in one go, back to back at your selected baud. This prevents the usual method of typing by hand and hitting enter as with all modem devices. Though to be fair the manual does mention this.</p><p>I found that the only consistent way to get activate changes was to either issue AT+RESET or power cycle the module.</p><p>Final note, changes are written to flash. ie they are permanent. Power cycling won't get rid of them.</p><p>Rgds</p><p>SQ</p>
<p>Thank you for these useful infos.</p><p>I succeeded thanks to you.</p>
<p>You're welcome</p>
<p>Dan,</p><p>Thanks for this instructable. Very informative. I hao 1tve an idea for a project that will aconnect 2 arduinos via bluetooth, but also be able to connect a phone 1 of the arduinos via bluetooth. The 2 arduinos will be connected together by default, using your method described above. But if I wanted the phone to connect, I would first need to disconnect them some how. Obviously, I want this to happen automatically. Do any modes support multiple connections in the HM-10. Do you have any idea how to make this work?</p><p>Thanks again for your work above. Fantastic!</p>
<p>I tried connecting two BLE modules by making one of them Master and the other Slave. The two pairs automatically. However if I try to discover the slave device using an iPhone the slave module is not shown on the device unless I disconnect the master. Is there any workaround for this ?</p>
<p>I also have the same problem - vajee</p>
Very nice tuts. I would like to connect my hm10 module to andruino ide. But ide doesnt recognize that. I connected gnd to black , vvc to red, tx to green and rx to remained led and have plugged that to usb port on my comp. <br>What is me doing wrong? Thank you.
<p>It would be possible to expand a usb hub with an HM-10 module on iOS devices?</p><div>For example not to use camera connection kit.</div>
How come you didn't have to create/use software serial?
<p>Is it possible to use a hm10 on an arduino uno to send commands to an hm12?</p>
<p>what is the difference between the two HM-10 modules you have links to? Since you used eagle, could also post an itemized BOM or if you already have can you tell me where to look? Looks like a cool project man, I can't wait to get to work! THanks again for your help.</p>
<p>Hi!</p><p>i see hm as Unnamed and when i try to connect print Connection Allert </p><p>The peripheral disconnected while being interrogated. Dismiss.</p><p>and i 'have anther problem i can't use AT from serial monitor what can i do?</p>
<p>Hello, on step 4 picture 2, I would like to ask a question about this picture. Which program did you use to design PCB circuit? May you give its name please? Thank you very much!</p>
<p>I used eagle to design my board. It's free.</p><p>I use their export as image feature to generate the trace image. </p><p>I then take the trace image to a milling machine to produce my pcb board </p>

About This Instructable

82,415views

140favorites

License:

More by Dan Chen:High Precision Cardboard CNC Drawing Machine  Wearable Loading Wheel - Motion Deactivated  Programable Motion Sensing Night Light  
Add instructable to: