Hi everyone! Arduinoob here.
I'm working with an Arduino nano clone (ATmega328P microprocessor, TI CC2540 BLE 2.4G BLE component) that has pretty good documentation, but I've gotten stuck.
Specifically, I'm having trouble programmatically interacting with the Bluetooth Low Energy (BLE) component it came pre-installed with. I followed the documentation and successfully interacted with the BLE chip by issuing AT commands via the IDE serial monitor. The test case is as follows:
- Open the serial monitor
- Set line endings to "Both NL & CR"
- Enter "AT" as a message payload
- Click "Send"
- Result: receive "+OK" from the BLE component
I have successfully performed that test and other AT commands via the IDE serial monitor, but whenever I try to interact with the BLE chip via the program code I have no such luck.
I started with this rudimentary attempt at posting the "AT" test:
void setup() {
Serial.begin(9600);
Serial.write("OPENED SERIAL\n");
Serial.write("AT\r\n");
}
void loop() {
while(Serial.available() > 0){
Serial.write(Serial.read());
}
}
However that code simply resulted in posting the "AT" to the serial monitor output, not interacting with the BLE chip. I concluded that I was passing data from the microprocessor straight off of the hardware, and maybe needed to send data to the serial monitor from a different source.
Here was my next attempt, using a software serial to write "AT" to the main onboard serial:
#include <SoftwareSerial.h>
#define BLUETOOTH_RX 0
#define BLUETOOTH_TX 7
SoftwareSerial BTIN = SoftwareSerial(BLUETOOTH_RX, BLUETOOTH_TX);
void setup() {
pinMode(BLUETOOTH_RX, INPUT);
pinMode(BLUETOOTH_TX, OUTPUT);
Serial.begin(9600);
while(! Serial);
BTIN.begin(9600);
while(! BTIN);
Serial.write("OPENED SERIAL\n");
BTIN.write("AT\r\n");
}
void loop() {
while(Serial.available() > 0){
Serial.write(Serial.read());
}
}
}
However, this code similarly just posted out "AT" to the IDE monitor. I tried every permutation of write and print commands with \r\n, \r, \n, etc., all to no avail.
Is there something I'm missing or haven't tried regarding how data is transferred from IDE serial monitor to the onboard serial compared to writing/printing programmatically to the serial? I'm at a loss of how to proceed any further, since the documentation provides no insight into how data flows from microprocessor to BLE chip aside from the IDE serial monitor, which is not acceptable for my project.
Thank you very much for your time!
-Iconn