Hi there,
I currently have a project I’m working on with my Arduino Nano connected to a HM-10 via AltSoftSerial.
The nano is plugged into my PC and would be using hardware serial.
Things work fine in terms of figuring out how to communicate back and forth with characters or integers, but one thing I’d like to get working is being able to send AT commands to the HM-10 via the AI2 Android app and have the HM-10’s response to those commands print in a text box in the app for debug.
So far I haven’t figured out how to achieve this. In this video, it seems you are able to sendbytes to run AT commands, but I’d like to be able to view the response to for query commands like AT+NAME?
https://www.youtube.com/watch?v=PINCucGRhA8
I have this simple arduino code from martyncurrey.com in order to print things to both directions and that works fine for ints and characters. Incoming data is printed in the serial monitor in the arduino IDE, and if I type an AT command in the serial monitor it makes it’s way to the HM10 and I get a response.
However when I sendbytes in AI2 as suggested by that video, I dont get a printout of the HM-10s response.
If anyone has any idea’s on how this is done, I’d greatly appreciate it.
Here’s the Arduino side code:
// SerialIn_SerialOut_HM-10_01
//
// Uses hardware serial to talk to the host computer and AltSoftSerial for communication with the bluetooth module
//
// What ever is entered in the serial monitor is sent to the connected device
// Anything received from the connected device is copied to the serial monitor
// Does not send line endings to the HM-10
//
// Pins
// BT VCC to Arduino 5V out.
// BT GND to GND
// Arduino D8 (SS RX) - BT TX no need voltage divider
// Arduino D9 (SS TX) - BT RX through a voltage divider (5v to 3.3v)
//
#include <AltSoftSerial.h>
AltSoftSerial BTserial;
char c = ’ ';
boolean NL = false;
void setup()
{
Serial.begin(9600);
Serial.print("Sketch: "); Serial.println(FILE);
Serial.print("Uploaded: “); Serial.println(DATE);
Serial.println(” ");
BTserial.begin(9600);
Serial.println(“BTserial started at 9600”);
}
void loop()
{
// Read from the Bluetooth module and send to the Arduino Serial Monitor
if (BTserial.available() )
{
c = BTserial.read();
Serial.write©;
}
// Read from the Serial Monitor and send to the Bluetooth module
if (Serial.available())
{
c = Serial.read();
// do not send line end characters to the HM-10
if (c != 10 & c != 13 )
{
BTserial.print(c);
}
// Echo the user input to the main window.
// If there is a new line print the ">" character.
if (NL) {
Serial.print("\r\n>");
NL = false;
}
Serial.write(c);
if (c == 10) {
NL = true;
}
}
}