Hello all,
I'm a rocket model enthousiast, and I want to share to the community my booster test bench.
This is the single unit version, i.e using only one Arduino between your computer and the scale.
Warning : this is a DIY project I did. I didn't hurt myself, but I can't guaranty you won't. I can't be held responsible for any harm you may cause by following these steps.
General idea :
- Put the booster on the bench (facing down)
- Use the relay as an ignition switch
- Start the countdown and run away (LCD shield's Select Button)
- Before the countdown ends, measurements start
- Countdown hits zero, ignition on
- When it's safe to come back, stop the measurements (LCD shield's Left button)
- Measurement are sent to your computer and received by a python code who save it to text
- Treat the data using excel
BOM :
- (1) Arduino Uno
- (1) LCD Keypad Shield
- (1) Red LED
- (1) 1k resistor
- (1) HX711 + 10KG load cell
- (n) Connectors
Connections (TODO : schematic)
- LED/resistor to pin A1
- HX711 SCK to pin A2
- HX711 DT to pin A3
- Relay IN to pin 2
- HX711 80Hz hack (unsolder 15 and connect to 16 - Google it in doubt)
Displays :
- Top right: SBY(Standby)/CDN(Countdown)/CDM(Countdown+measurements)/Mes(Measurements)
- Bottom left : scale reading
- Bottom right : Countdown
To be done :
Diagrams, photos, make the code more beautiful.
For safety, I want to use radio communication between two Arduinos.
One near the bench to read the data and send it to Arduino Two, connected to the computer.
Arduino Code (The code is ugly, I'll rework it when I have a valid radio solution):
#include "HX711.h"
#include <LiquidCrystal.h>
#define CDNDur 2000 //CountDown duration in ms
#define CDNStartMes 1000 //When CountDown reaches CDNStartMes, mesurement starts
#define pinLED A1 //Blinking LED pin
#define pinFire 2 //Relay pin
#define tInterFire 1000 //The firing pin will stay "on" for that amount of time in ms
#define tInterMesure 25 //The XH711 will be read every tInterMesure ms
#define floatLCCalibration 212.5 //HX711 calibration
//LCD pins configuration
#define pinLCDRS 8
#define pinLCDEN 9
#define pinLCDd4 4
#define pinLCDd5 5
#define pinLCDd6 6
#define pinLCDd7 7
#define pinLCDBL 10
#define pinLCDinp A0
LiquidCrystal lcd( pinLCDRS, pinLCDEN, pinLCDd4, pinLCDd5, pinLCDd6, pinLCDd7);
#define pinLoadDout A3
#define pinLoadSCK A2
HX711 scale;
long inWeight = 0;
int inButton = 0;
bool isSBY = true;
bool isCDN = false;
bool isMes = false;
#define tInterBlinkCntDwn 250 //Slow blink during the first part of countdown
#define tInterBlinkTest 50 // fast blink when measurements have started
#define tInterLCD 100 //LCD refreshes every tInterLCD ms
unsigned long tFire = 0;
unsigned long tStartMes = 0;
unsigned long tStartCDN = 0;
unsigned long tCurrent = 0;
unsigned long tLastMes = 0;
unsigned long tLastBlink = 0;
unsigned long tLastLCD = 0;
int ledState = LOW;
int dispCDNq = 0;
long dispMesq = 0;
int i = 0;
void setup() {
pinMode(pinFire, OUTPUT);
digitalWrite(pinFire,HIGH);
pinMode(pinLED, OUTPUT);
digitalWrite(pinLED,LOW);
pinMode(pinLCDBL, OUTPUT);
digitalWrite(pinLCDBL,HIGH);
lcd.begin(16, 2);
scale.begin(pinLoadSCK, pinLoadDout);
scale.set_scale(floatLCCalibration);
scale.tare();
lcd.setCursor(0,0);
lcd.print("Load Bench");
lcd.setCursor(13,0);
lcd.print("SBY");
}
void loop() {
tCurrent = millis();
inButton = analogRead(pinLCDinp);
if( (isCDN or isMes) and isLeft(inButton) ){
//Turn off LED
//Finalize measurements
//update LCD
ledState = LOW;
digitalWrite(pinLED,LOW);
isCDN = false;
if(isMes){
Serial.println("end");
serStop();
}
isMes = false;
lcd.setCursor(13,0);
lcd.print("SBY");
lcd.setCursor(12,1);
lcd.print(" ");
}else if( not(isCDN or isMes) and isSelect(inButton) ){
//Initialize Countdown
tStartCDN = tCurrent;
isCDN = true;
lcd.setCursor(13,0);
lcd.print("CDN");
tLastLCD = tCurrent-tInterLCD;
tLastBlink = tCurrent;
ledState = HIGH;
digitalWrite(pinLED,HIGH);
}else if(isCDN and not(isMes) ){
if( tCurrent>(tStartCDN+CDNDur-CDNStartMes) ){
//CountDown reached measurement starting time
//Initialize measurement
isMes = true;
lcd.setCursor(13,0);
lcd.print("CDM");
tLastLCD = tCurrent;
scale.tare();
serStart();
tCurrent = millis();
tStartMes = tCurrent;
tLastMes = tCurrent-tInterMesure;
Serial.println("new data");
}
}else if( isCDN and isMes ){
if(tCurrent > (tStartCDN+CDNDur)){
//CountDown is zero
//Finalize CountDown
//Fire
isCDN = false;
lcd.setCursor(13,0);
lcd.print("Mes");
lcd.setCursor(12,1);
lcd.print(" ");
tLastLCD = tCurrent;
tFire=tCurrent;
digitalWrite(pinFire,LOW);
}
}
tCurrent = millis();
if( isCDN ){
//During countdown
if(isMes){
//We have measurements : fast blink
if(tCurrent>(tLastBlink+tInterBlinkTest)){
if(ledState == HIGH){
ledState = LOW;
digitalWrite(pinLED,LOW);
}else{
ledState = HIGH;
digitalWrite(pinLED,HIGH);
}
tLastBlink += tInterBlinkTest;
}
}else{
//No measurements : slow blink
if(tCurrent>(tLastBlink+tInterBlinkCntDwn)){
if(ledState == HIGH){
ledState = LOW;
digitalWrite(pinLED,LOW);
}else{
ledState = HIGH;
digitalWrite(pinLED,HIGH);
}
tLastBlink += tInterBlinkCntDwn;
}
}
}
if( isMes ){
//Measurement : data acquisition / transmission
if(tCurrent>(tLastMes+tInterMesure)){
inWeight = scale.get_units();
Serial.print(tCurrent-tStartMes);
Serial.print("\t");
Serial.print(inWeight);
Serial.println();
tLastMes+=tInterMesure;
}
}
if(tFire>0){
if(tCurrent>tFire+tInterFire){
//ignition done
tFire = 0;
digitalWrite(pinFire, HIGH);
}
}
if(tCurrent>(tLastLCD+tInterLCD)){
//LCD refreshment
if(isCDN){
dispCDNq = (int)((tStartCDN+CDNDur-tCurrent)/100);
lcd.setCursor(15,1);
lcd.print(dispCDNq % 10);
dispCDNq = (int)(dispCDNq/10);
lcd.setCursor(14,1);
lcd.print(".");
lcd.setCursor(13,1);
lcd.print(dispCDNq % 10);
dispCDNq = (int)(dispCDNq/10);
lcd.setCursor(12,1);
lcd.print(dispCDNq % 10);
}
if(not(isMes)){
inWeight = scale.get_units();
}
lcd.setCursor(0,1);
lcd.print(" ' . g");
if(inWeight<0){
lcd.setCursor(0,1);
inWeight = -inWeight;
lcd.print("-");
}
dispMesq = (long)(inWeight*10);
i = 0;
while(i < 8){
lcd.setCursor(8-i,1);
lcd.print(dispMesq % 10);
dispMesq = (long)(dispMesq/10);
i += 1;
if( (i==1) or (i==5) ){
i+=1;
}
}
tLastLCD+=tInterLCD;
}
}
void serStart(){
Serial.begin(9600);
while(!Serial);
}
void serStop(){
Serial.end();
}
bool isSelect(int val){
return (val<=800) and (val >= 600);
}
bool isLeft(int val){
return (val<=599) and (val >= 400);
}
bool in(int val, int low, int high){
return (val<=high) and (val >= low);
}
Python script : Open a cmd terminal, run the script.
It tries to detect connected Arduinos (Arduino or CH340 in the name).
None found : exiting.
One found : selecting it automatically.
More than one found : I set the default to -COM6 because that's what my board reads.
You can also add "-com N" N being the port you want to select.
Otherwise, you'll be asked to manually select a port.
During standby phase, Space+Escape to stop the script.
The script creates a text file with the measurements.
import serial
import serial.tools.list_ports
import keyboard
import os.path
import sys
if ("-com" in sys.argv):
defaultCom = "COM"+sys.argv[sys.argv.index("-com")+1]
else:
defaultCom = "COM6"
fIndexName = "data_index.txt"
fDataName = "data_"
print("Starting ArdIO.")
print("Ctrl+Esc to quit.")
print("")
print("Scanning COM ports :")
comList = []
ports = serial.tools.list_ports.comports()
for port, desc, hwid in sorted(ports):
print("{}: {} [{}]".format(port, desc, hwid))
if not(desc.find("Arduino")==-1) or not(desc.find("CH340")==-1):
comList.append([port,desc])
print("")
nbrCom = len(comList)
if nbrCom == 1:
arduinoCom = comList[0][0]
print("Only one Arduino found.")
print("Listening to serial port : "+arduinoCom)
elif nbrCom == 0:
print("No device connected...")
print("Exiting.")
exit()
else:
defaultFound = False
for i in range(nbrCom):
print(str(i)+" : "+comList[i][1])
if (defaultCom.lower() == comList[i][0].lower()):
defaultFound = True
if defaultFound:
print("Default port identified : "+defaultCom)
arduinoCom = defaultCom
else:
print("Default port not found.")
validChoice = False
while not(validChoice):
choice=input("Chose a Com port : ")
if choice:
if int(choice) in range(nbrCom):
validChoice = True
arduinoCom = comList[int(choice)][0]
ard = serial.Serial(arduinoCom, 9600, timeout=.1)
print("Connected.")
print()
mode = 0
running = True
while running:
if (mode == 0):
print("Ready to record data")
print()
mode = 1
data = ard.readline()[:-2]
if (mode == 1) and (data.decode('ASCII')=="new data"):
if os.path.isfile(fIndexName):
f_index = open(fIndexName,"r+")
index = int(f_index.read())+1
f_index.seek(0)
f_index.write(str(index))
f_index.close()
else:
f_index = open(fIndexName,"w")
f_index.write("0")
f_index.close()
index = 0
f_data = open(fDataName+str(index)+".txt", "w")
print("Creating file : "+fDataName+str(index)+".txt")
print("Recording...")
mode = 2
elif (mode == 2) and (data):
if data.decode('ASCII')=="end":
print("Data feed saved to "+fDataName+str(index)+".txt")
print("")
f_data.close()
mode = 0
else:
f_data.write(data.decode('ASCII')+"\n")
elif (mode == 1) and (keyboard.is_pressed('space+escape')):
running = False
print("Terminating.")
ard.close()
@challyss,
Thanks for sharing a working non-trivial example.. People will learn from examples like this...
Typical model rocket engines run 1..2 seconds as I recall, so 80 Hz is useful. I notice some people say that the 80Hz is not accurate or consistent. Are you time stamping / checking time VS readings?
I haven't made my own engines for 40 years; Hmmm....
Since I don't "trust" it, and don't have control over the time it will take to treat/save/send the data, I do as follows :
Before hand
Define my sampling interval dt
Measurement starts
Take a measurement.
Save the time (millis) in a variable tLast
Treat/save/send the first point.
Measurement loop
If currentTime>tLast+dt (a measurement is due) then
Take a measurement.
Save the time (millis) in a variable tLast
Treat/save/send the first point.
Like this even if some points are late, the average interval is respected (as long as you can treat the data fast enough).
When I started this project, the HX711 was set to 10Hz, and the HX711 library I use is blocking.... so it was useless.
Switching to 80Hz gave me enough latitude.
For a 1.2s burn it'd be around a hundred points. Should be good enough to evaluate the thrust over time and total kick of the booster !
It's a WIP here because I am currently in China, and I don't think the law here the fabrication of sugar boosters !