Hello, I am working on a rocket motor test stand project.It consists of two parts: controller with five switches( arming, tank fill, fuel valve, ox valve, ignition), arduino and the test stand with a load cell, 3 servo operated valves, and ignition wired up through a mosfet. And i got a problem with sending switch states over software serial (hardware serial is needed to connect controller to a pc), it has a really long delay, around 5 seconds, i figured out that its on the sending/recieving part, not encoding/decoding.
I would apreciate if someone helps me figure it out.
controller code:
#include <SoftwareSerial.h>
// Define SoftwareSerial pins
SoftwareSerial mySerial(7, 8); // RX, TX (On Arduino 1, use pin 7 for RX and 8 for TX)
byte thrustBytes[4];
byte command;
bool arm;
bool fill;
bool ox;
bool fuel;
bool ignition;
float thrust;
void setup() {
Serial.begin(19200);
mySerial.begin(19200);
delay(500);
pinMode(2, INPUT_PULLUP); //ignition switch
pinMode(3, INPUT_PULLUP); //fuel valve switch
pinMode(4, INPUT_PULLUP); //ox valve switch
pinMode(5, INPUT_PULLUP); //arming switch
pinMode(6, INPUT_PULLUP); //tank fill valve switch
}
void loop() {
if (digitalRead(2) == 0){ //turn all switch signals into boolian
ignition = true;
}
else if (digitalRead(2) == 1){
ignition = false;
}
if (digitalRead(3) == 0){
fuel = true;
}
else if (digitalRead(3) == 1){
fuel = false;
}
if (digitalRead(4) == 0){
ox = true;
}
else if (digitalRead(4) == 1){
ox = false;
}
if (digitalRead(5) == 0){
arm = true;
}
else if (digitalRead(5) == 1){
arm = false;
}
if (digitalRead(6) == 0){
fill = true;
}
else if (digitalRead(6) == 1){
fill = false;
}
command = (arm << 4) | ( fill << 3) | (fuel << 2) | (ox << 1) | (ignition << 0); //combine all bits into a byte
mySerial.write(command);
delay(20);
}
and stand code:
#include <SoftwareSerial.h>
#include <HX711.h>
// Define SoftwareSerial pins
SoftwareSerial mySerial(7, 8); // RX, TX (On Arduino 2, use pin 7 for RX and 8 for TX)
HX711 scale;
uint8_t dataPin = 6;
uint8_t clockPin = 5;
float thrust;
byte command;
bool arm;
bool fill;
bool ox;
bool fuel;
bool ignition;
void setup() {
Serial.begin(19200);
mySerial.begin(19200);
scale.begin(dataPin, clockPin);
scale.set_scale(66.6);
scale.tare();
}
void loop() {
thrust = scale.get_units(1);
delay(50);
if (mySerial.available()) { //recieve and decode the command
command = mySerial.read();
arm = (command >> 4) & 1;
fill = (command >> 3) & 1;
fuel = (command >> 2) & 1;
ox = (command >> 1) & 1;
ignition = (command >> 0) & 1;
}
}
Thanks