I am now up to my last tear drop on this.
Can anyone please try to wright a code for this to work. 😥
@the-apprentice Sorry, without a lot more information, it's not possible. I don't know your qualifications and how much time you have to devote, but learning to program can take quite a while. You would do better starting with a smaller, simpler kit to use first to assemble more and more complex projects before designing your own.
First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.
@the-apprentice Be sure to let us know, it's not that hard and I did give you the start of the solution. I did fail to mention one thing, merge the two pieces of start up code, not sure which should go first, but you can figure that out. Then just make the stepper loop into a function passing in a numeric representation of what you want the stepper to do.
I wonder though, if it doesn't make more sense to start with a simple stepper sample, just a pot controlling forward speed, no need to go backwards and then make the load cell a function to return the pressure and develop a simple algorithm to translate pressure delta to a stepper speed.
I think both will work and the code is fairly straightforward, but give it some thought, which approach seems to be better.
Good luck.
First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.
#include "HX711.h" // Defin pins int driverPUL = 6; // PUL- pin int driverDIR = 5; // DIR- pin int spd = A0; // Potentiometer // Variables int pd = 500; // Pulse Delay period boolean setdir = LOW; // Set Direction // Interrupt Handler void revmotor (){ setdir = !setdir; } HX711 scale(2, 3); //HX711 scale(6, 5); float calibration_factor = -1; float units; float Nm; void setup() { pinMode (driverPUL, OUTPUT); pinMode (driverDIR, OUTPUT); Serial.begin(9600); Serial.println("HX711 weighing"); scale.set_scale(calibration_factor); scale.tare(0); Serial.println("Readings:"); } void loop() { { pd = map((analogRead(spd)),0,1023,2000,50); digitalWrite(driverDIR,setdir); digitalWrite(driverPUL,HIGH); delayMicroseconds(pd); digitalWrite(driverPUL,LOW); delayMicroseconds(pd); } Serial.print("Reading:"); units = scale.get_units(),10; if (units < 0) { units = 0.00; } Nm = units * 0.035274; Serial.print(units); Serial.println(" Nm "); delay(3000); }
@the-apprentice First, fix the compile errors.
/private/var/folders/pg/mjb25hc97csf8q8j964tdfz80000gn/T/.arduinoIDE-unsaved2024028-20629-1n76nrj.thkz/sketch_jan28a/sketch_jan28a.ino:21:17: error: no matching function for call to 'HX711::HX711(int, int)'
HX711 scale(2, 3); //HX711 scale(6, 5);
^
In file included from /private/var/folders/pg/mjb25hc97csf8q8j964tdfz80000gn/T/.arduinoIDE-unsaved2024028-20629-1n76nrj.thkz/sketch_jan28a/sketch_jan28a.ino:1:
/Users/ronalexander/Documents/Electronics/SourceCode/Arduino/libraries/HX711/HX711.h:40:3: note: candidate: 'HX711::HX711()'
HX711();
^~~~~
/Users/ronalexander/Documents/Electronics/SourceCode/Arduino/libraries/HX711/HX711.h:40:3: note: candidate expects 0 arguments, 2 provided
/Users/ronalexander/Documents/Electronics/SourceCode/Arduino/libraries/HX711/HX711.h:37:7: note: candidate: 'constexpr HX711::HX711(const HX711&)'
class HX711
^~~~~
/Users/ronalexander/Documents/Electronics/SourceCode/Arduino/libraries/HX711/HX711.h:37:7: note: candidate expects 1 argument, 2 provided
/private/var/folders/pg/mjb25hc97csf8q8j964tdfz80000gn/T/.arduinoIDE-unsaved2024028-20629-1n76nrj.thkz/sketch_jan28a/sketch_jan28a.ino: In function 'void loop()':
/private/var/folders/pg/mjb25hc97csf8q8j964tdfz80000gn/T/.arduinoIDE-unsaved2024028-20629-1n76nrj.thkz/sketch_jan28a/sketch_jan28a.ino:49:31: error: right operand of comma operator has no effect [-Werror=unused-value]
units = scale.get_units(),10;
First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.
@the-apprentice I am in a good mood today, so I fixed your compile errors. File included at the end.
NOTE: This code is still missing a lot like motor setup and control, also the load cell code is incomplete. Use the example in the HX711 library that is the closest match to your situation and modify it if needed.
HINT: Read the library/class hdr file to understand what public members are exposed, then if needed, read the cpp file to understand how they work if not obvious.
Now include the appropriate stepper library for your stepper/controller setup. Again, find a supplied library example that most closely matches what you want to do.
Merge the setups, and convert either the load cell loop or stepper loop into a function/procedure and call that function/procedure at the appropriate place in the new main loop.
Voila c'est fait
First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.
Your motor may be moving but you just can't detect it.
In your loop you appear to calculate the pulse delay time from 50 to 2000 and apply that as a microsecond delay between stepper pulses.
That's good, but then you do a few prints and apply a 3 second delay at the end of the loop. So, the MINIMUM time spent between pulses is 3 seconds. Assuming a nominal 200 step per revolution stepper, that means one revolution will take at least 200*3 = 600 seconds. So the motor's max speed is 6 revs/hour.
Your setup will ultimately be limited by the time required to read the load cell,
Anything seems possible when you don't know what you're talking about.
Let me try and see. Thanks for helping.
@will You are corect. Motor turning but slow. I will try to get it to use the load cell output.
In a sense, it IS using the load cell output because that's the delay between pulses.
The problem is that everything else in the loop (reading the cell and your calculations, the print statements and that 3 second delay) are also occurring between pulses. That's why it runs so slowly.
What I meant above by "your setup will ultimately be limited by the time required to read the load cell" is that everything that occurs during the loop will effectively delay the pulses sent to the stepper. So the minimum case is where the loop only contains the stepper driver commands and the load cell sensing (and new speed calculation which uses negligible time). So, the fastest speed possible for the motor depends on the length of time it takes to get a reading from the load cell (which would happen if pd were set t zero).
Anything seems possible when you don't know what you're talking about.
@will @the-apprentice Looking back at the original requirement of
I would like for the motor to slow down when the pressure increase and speed up when it decreases.
then roughly what is needed is (pseudo code) in this block of code you posted
units = scale.get_units(),10;
if (units < 0)
{
units = 0.00;
}
add in a statement to save the previous units,
now check if the new units are more or less and increase or decrease speed appropriately.
This is a high level solution, I have not compiled and I am almost certain more code is needed to manage the motors and maybe even the load cell.
First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.
To implement the load cell, you'll have to change the line
Anything seems possible when you don't know what you're talking about.
@will @the-apprentice I think there are a few more errors, I didn't attempt to get the code to even compile let alone work, just the broad strokes.
I want to experiment with a load cell myself someday, any recommendations from either of you?
First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.