Hello, I’m trying to send and receive data from my laptop to arduino nano via hc05 Bluetooth for a rocket flight computer. For some reasons which I don’t know, I can send data from processing software using myPort.write() but cannot send a String back from arduino back to processing for telemetry purpose. At some point it was working, then stopped. I tried another code from HowToMechatronics.com and still it didn’t work. For some reasns, now its working but im getting junk data(although i can see some expected numbers in the junk data) I’m using the Serial.println function on Hardware serial
Baudrate is at 115200, stop bit 1, parity 0
Does the stop bit or parity bit have anything to do with it?
Pls help
In the processing code, I use all necessary libraries and functions e.g serialEvent(), myPort.bufferUntil(\n), myPort.readStringUntil(‘\n’)
Stripped down arduino code
type or paste code here[code]
void setup() {
digitalWrite(resetbutton, HIGH);
mode=0;
prevAltitude = 0;
Serial.begin(115200);
servo1.attach(servoOne);
//servo2.attach(servoTwo);
pinMode(BlueLed, OUTPUT);
pinMode(RedLed, OUTPUT);
pinMode(buzzer, OUTPUT);
pinMode(Startbutton, INPUT);
pinMode(readybutton , INPUT);
pinMode(resetbutton, OUTPUT);
pinMode(BtState, INPUT);
Initialization();
}
void loop() {
int startbutton = digitalRead(Startbutton);
int Readybutton = digitalRead(readybutton);
unsigned long currentMillis = millis();
if (Serial.available() > 0) { //Save incoming bluetooth data to variable 'state'
state = Serial.read(); //read what button is pressed on phone
}
if (state == 's'){
startup();
state = 0;
delay(200);
}
if ((state == 'r') || (Readybutton == HIGH)) { //if char r is received via bluetooth or Readybutton pressed
digitalWrite(RedLed, HIGH);
tone(buzzer, 1200, 1000);
mode = 1;
state = 0;
}
if (mode == 1) {
datalogging(); //Set datalogmging to start.
detectAndDeploy();
}
if (state== 'R'){
digitalWrite(resetbutton, LOW);
}
}
void Initialization() {
int delayPeriod = 500;
servo1.write(130); //Arm servo to hold the parachute door
Serial.println("Initializing SD card...");
if (!SD.begin(chipSelect)) { // see if the card is present and can be initialized:
Serial.println("Card failed,or not present");
digitalWrite(buzzer, HIGH); //if not initialized, Buzzer keeps buzzing
return; // stops the code from continuing
}
digitalWrite(buzzer, LOW); //Turn off buzzer if SDcard is initialized
for (i = 0; i < 4; i++) {
digitalWrite(BlueLed, HIGH);
digitalWrite(RedLed, HIGH);
tone(buzzer, 1000);
delay(delayPeriod);
noTone(buzzer);
}
Serial.println("Initialization ok");
delay(15);
}
[/code]
Processing code
import processing.serial.*;
Serial myPort;
String stateStatus=" ";;
void setup() {
size(450, 500);
myPort= new Serial(this, "COM8", 115200);
myPort.bufferUntil('\n');
}
void serialEvent (Serial myPort) {
stateStatus= myPort.readStringUntil('\n');
}
void draw() {
background(237, 240, 241);
textSize(24);
fill(33);
text("Status:", 80, 280);
text(stateStatus, 20, 300);
}