hoiberg / HM10-BluetoothSerial-iOS

An iOS 10 app to communicate with a HM10 Bluetooth module
189 stars 74 forks source link

can you post an arduino code here? #1

Closed jemmychen closed 8 years ago

jemmychen commented 9 years ago

I tried to talk to my arduino with this app but failed. could u please show me ur arduino code???

hoiberg commented 9 years ago

Here is the code I used as a serial passtrough:

#include <SoftwareSerial.h>

SoftwareSerial softSerial(2, 3); // first RX, then TX

void setup() {

  Serial.begin(9600); // baudrate of the serial monitor
  while (!Serial) {}

  softSerial.begin(9600); // baudrate of the HM10

  Serial.println("I'm ready!");
  softSerial.write("AT\n");
}

void loop() {

  if (softSerial.available()) {
    Serial.write(softSerial.read());
  }

  if (Serial.available()) {
    softSerial.write(Serial.read());
  }

}

You problem could be caused by having the wrong preferences set. In the preferences (within the app), select 'Write with response' if you have a fake HM10, or select 'Write without response' if you have a legit HM10 or HM11. If you don't select the right option, the app won't be able to write data to the bluetooth module.

If it still doesn't work, you've got to provide more information about what is happening.