[chronojump] Added ForceSensor firmware version 0.4
- From: Xavier Padullés <xpadulles src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] Added ForceSensor firmware version 0.4
- Date: Wed, 9 Mar 2022 15:45:36 +0000 (UTC)
commit f77d776551db53c05b4b2b85cfad8a20437091b2
Author: xpadulles <x padulles gmail com>
Date: Tue Mar 8 16:13:41 2022 +0100
Added ForceSensor firmware version 0.4
.../ForceSensor-0.4.ino} | 0
.../ForceSensor-0.5/ForceSensor-0.5.ino | 282 +++++++++++++++++++++
arduino/ForceSensor/Versions.txt | 21 ++
3 files changed, 303 insertions(+)
---
diff --git a/arduino/ForceSensor/ForceSensor.ino b/arduino/ForceSensor/ForceSensor-0.4/ForceSensor-0.4.ino
similarity index 100%
rename from arduino/ForceSensor/ForceSensor.ino
rename to arduino/ForceSensor/ForceSensor-0.4/ForceSensor-0.4.ino
diff --git a/arduino/ForceSensor/ForceSensor-0.5/ForceSensor-0.5.ino
b/arduino/ForceSensor/ForceSensor-0.5/ForceSensor-0.5.ino
new file mode 100644
index 000000000..7544fbc52
--- /dev/null
+++ b/arduino/ForceSensor/ForceSensor-0.5/ForceSensor-0.5.ino
@@ -0,0 +1,282 @@
+/*
+ #
+ # This file is part of ChronoJump
+ #
+ # ChronoJump is free software; you can redistribute it and/or modify
+ # it under the terms of the GNU General Public License as published by
+ # the Free Software Foundation; either version 2 of the License, or
+ # (at your option) any later version.
+ #
+ # ChronoJump is distributed in the hope that it will be useful,
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ # GNU General Public License for more details.
+ #
+ # You should have received a copy of the GNU General Public License
+ # along with this program; if not, write to the Free Software
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ #
+ # Copyright (C) 2017 Xavier Padullés <x padulles gmail com>
+ # Copyright (C) 2017 Xavier de Blas <xaviblas gmail com>
+
+
+*/
+
+#include <HX711.h>
+#include <EEPROM.h>
+
+#define DOUT 5
+#define CLK 4
+
+//Version number //it always need to start with: "Force_Sensor-"
+String version = "Force_Sensor-0.5";
+
+
+int tareAddress = 0;
+int calibrationAddress = 4;
+
+HX711 scale(DOUT, CLK);
+
+//Data comming from the cell after resting the offset weight
+float offsetted_data = 0;
+
+//Data resulting of appying the calibration_factor to the offsetted_data
+float scaled_data = 0;
+
+//The weight used to calibrate the cell
+float weight = 0.0;
+
+//Wether the sensor has to capture or not
+boolean capturing = false;
+
+//wether the tranmission is in binary format or not
+boolean binaryFormat = false;
+
+unsigned long lastTime = 0;
+unsigned long currentTime = 0;
+unsigned long elapsedTime = 0;
+unsigned long totalTime = 0;
+
+const int rcaPin = 3;
+
+unsigned long triggerTime = 0;
+bool rcaState = digitalRead(rcaPin);
+bool lastRcaState = rcaState;
+
+void setup() {
+ Serial.begin(115200);
+
+ long tare = 0;
+ EEPROM.get(tareAddress, tare);
+ if (tare == -151) {
+ scale.set_offset(10000);// Usual value in Chronojump strength gauge
+ EEPROM.put(tareAddress, 10000);
+ } else {
+ scale.set_offset(tare);
+ }
+
+
+ //The factor to convert the units coming from the cell to the units used in the calibration
+ float calibration_factor = 0.0f;
+ EEPROM.get(calibrationAddress, calibration_factor);
+ if (isnan(calibration_factor)) {
+ scale.set_scale(915.0);// Usual value in Chronojump strength gauge
+ EEPROM.put(calibrationAddress, 915.0);
+ } else {
+ scale.set_scale(calibration_factor);
+ }
+
+ attachInterrupt(digitalPinToInterrupt(rcaPin), changingRCA, CHANGE);
+}
+
+void loop() {
+
+ if (capturing)
+ {
+ if (rcaState != lastRcaState) { //Event generated by the RCA
+ checkTimeOverflow();
+ Serial.print(totalTime);
+ Serial.print(";");
+
+ if (rcaState) {
+ Serial.println("R");
+ } else {
+ Serial.println("r");
+ }
+ lastRcaState = rcaState;
+
+ } else { //If no RCA event, read the force as usual
+ currentTime = micros();
+
+ checkTimeOverflow();
+ Serial.print(totalTime);
+ Serial.print(";");
+ Serial.println(scale.get_units(), 2); //scale.get_units() returns a float
+ }
+ }
+
+ //Checking if there's incoming serial data
+ if (Serial.available()) {
+ processSerial();
+ }
+}
+
+void changingRCA() {
+ //TODO: Check the overflow of the lastTriggerTime
+ detachInterrupt(digitalPinToInterrupt(rcaPin));
+ currentTime = micros();
+
+ rcaState = digitalRead(rcaPin);
+
+ attachInterrupt(digitalPinToInterrupt(rcaPin), changingRCA, CHANGE);
+}
+
+//In old version SerialEvent() was used but the nano every don't support it
+void processSerial()
+{
+ String inputString = Serial.readString();
+ String commandString = inputString.substring(0, inputString.lastIndexOf(":"));
+ // while (Serial.available())
+ // {
+ // char inChar = (char)Serial.read();
+ // inputString += inChar;
+ // if (inChar == '\n') {
+ // commandString = inputString.substring(0, inputString.lastIndexOf(":"));
+ // }
+
+ if (commandString == "start_capture") {
+ start_capture();
+ } else if (commandString == "end_capture") {
+ end_capture();
+ } else if (commandString == "get_version") {
+ get_version();
+ } else if (commandString == "get_calibration_factor") {
+ get_calibration_factor();
+ } else if (commandString == "set_calibration_factor") {
+ set_calibration_factor(inputString);
+ } else if (commandString == "calibrate") {
+ calibrate(inputString);
+ } else if (commandString == "get_tare") {
+ get_tare();
+ } else if (commandString == "set_tare") {
+ set_tare(inputString);
+ } else if (commandString == "tare") {
+ tare();
+ } else if (commandString == "get_transmission_format") {
+ get_transmission_format();
+ } else {
+ Serial.println("Not a valid command");
+ }
+ inputString = "";
+ // }
+}
+
+void start_capture()
+{
+ Serial.println("Starting capture...");
+ totalTime = 0;
+ lastTime = micros();
+ capturing = true;
+}
+
+void end_capture()
+{
+ capturing = false;
+ Serial.print("Capture ended:");
+ Serial.println(scale.get_offset());
+}
+void get_version()
+{
+ Serial.println(version);
+}
+
+void get_calibration_factor()
+{
+ Serial.println(scale.get_scale());
+}
+
+void set_calibration_factor(String inputString)
+{
+ //Reading the argument of the command. Located within the ":" and the ";"
+ String calibration_factor = get_command_argument(inputString);
+ //Serial.println(calibration_factor.toFloat());
+ scale.set_scale(calibration_factor.toFloat());
+ float stored_calibration = 0.0f;
+ EEPROM.get(calibrationAddress, stored_calibration);
+ if (stored_calibration != calibration_factor.toFloat()) {
+ EEPROM.put(calibrationAddress, calibration_factor.toFloat());
+ }
+ Serial.println("Calibration factor set");
+}
+
+void calibrate(String inputString)
+{
+ //Reading the argument of the command. Located within the ":" and the ";"
+ String weightString = get_command_argument(inputString);
+ float weight = weightString.toFloat();
+ //mean of 255 values comming from the cell after resting the offset.
+ double offsetted_data = scale.get_value(50);
+
+ //offsetted_data / calibration_factor
+ float calibration_factor = offsetted_data / weight / 9.81; //We want to return Newtons.
+ scale.set_scale(calibration_factor);
+ EEPROM.put(calibrationAddress, calibration_factor);
+ Serial.print("Calibrating OK:");
+ Serial.println(calibration_factor);
+}
+
+void tare()
+{
+ scale.tare(50); //Reset the scale to 0 using the mean of 255 raw values
+ EEPROM.put(tareAddress, scale.get_offset());
+ Serial.print("Taring OK:");
+ Serial.println(scale.get_offset());
+}
+
+void get_tare()
+{
+ Serial.println(scale.get_offset());
+}
+
+void set_tare(String inputString)
+{
+ String tare = get_command_argument(inputString);
+ long value = tare.toInt();
+ scale.set_offset(value);
+ long stored_tare = 0;
+ EEPROM.get(tareAddress, stored_tare);
+ if (stored_tare != value) {
+ EEPROM.put(tareAddress, value);
+ Serial.println("updated");
+ }
+ Serial.println("Tare set");
+}
+
+String get_command_argument(String inputString)
+{
+ return (inputString.substring(inputString.lastIndexOf(":") + 1, inputString.lastIndexOf(";")));
+}
+
+void get_transmission_format()
+{
+ if (binaryFormat)
+ {
+ Serial.println("binary");
+ } else
+ {
+ Serial.println("text");
+ }
+}
+
+void checkTimeOverflow() {
+
+ //Managing the timer overflow
+ if (currentTime > lastTime) //No overflow
+ elapsedTime = currentTime - lastTime;
+ else if (currentTime <= lastTime) //Overflow
+ elapsedTime = (4294967295 - lastTime) + currentTime; //Time from the last measure to the overflow event
plus the currentTime
+
+ //calculations
+ totalTime += elapsedTime;
+ lastTime = currentTime;
+}
diff --git a/arduino/ForceSensor/Versions.txt b/arduino/ForceSensor/Versions.txt
new file mode 100644
index 000000000..2f14778b6
--- /dev/null
+++ b/arduino/ForceSensor/Versions.txt
@@ -0,0 +1,21 @@
+V0.4
+---------------------------------------------------
+
+Connections:
+DOUT --> D3
+CLK --> D2
+
+Using sparkfun HX711 module
+
+
+V0.5
+---------------------------------------------------
+
+Connections:
+DOUT --> D5
+CLK --> D4
+RCA --> D3
+
+HX711 integrated in the PCB assembly
+Added RCA trigger
+Smaller PCB
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]