Hi, i'm using the HM-10 Bluetooth module (HM-10 CC2541 v540), the module works perfectly with arduino uno, but with arduino nano ATmega368, with some specific commands, arduino stops working and it connects to another port, something like reset.
The code:
#include <SoftwareSerial.h>
SoftwareSerial BT(7, 8);
unsigned char buffer[64]; // buffer array for data recieve over serial port
int count = 0; // counter for buffer array
void setup()
{
BT.begin(9600); // the BT baud rate
Serial.begin(9600); // the Serial port of Arduino baud rate.
}
void loop()
{
if (BT.available()) // if date is comming from softwareserial port ==> data is comming from gprs shield
{
while(BT.available()) // reading data into char array
{
buffer[count++] = BT.read(); // writing data into array
if(count == 64)
break;
}
Serial.write(buffer,count); // if no data transmission ends, write buffer to hardware serial port
clearBufferArray(); // call clearBufferArray function to clear the storaged data from the array
count = 0; // set counter of while loop to zero
}
if (Serial.available()) // if data is available on hardwareserial port ==> data is comming from PC or notebook
BT.write(Serial.read()); // write it to the BT shield
}
void clearBufferArray() // function to clear buffer array
{
for (int i=0; i<count;i++)
buffer[i]=NULL; // clear all index of array with command NULL
}
The error:
Error inside Serial.serialEvent()
java.io.IOException: Input/output error in nativeavailable
at gnu.io.RXTXPort.nativeavailable(Native Method)
at gnu.io.RXTXPort$SerialInputStream.available(RXTXPort.java:1598)
at processing.app.Serial.serialEvent(Serial.java:258)
at gnu.io.RXTXPort.sendEvent(RXTXPort.java:774)
at gnu.io.RXTXPort.eventLoop(Native Method)
at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1644)
commands that i have use:
AT+DISC?
AT+DISI?
first command is to find bluetooth devices, the second to find ibeacons.
Thank you