Hello so I have a lcd, 100g load cell, a nema 17 motor, and dvr8825 stepper to control it. So I first got the motor to work and turn with a library I download of and tweaked it a lil and then I got the load cell to work I’m only +-5mg which is perfect for my situation. Now I just don’t know how to combine everything. What I want to do is make the motor spin the auger I have till the load cell reaches the designated weight say 200mg and once it does to shut it off. And wait for me to put in another weight say 6g and then the motor to start and do the same thing. Please please help
You can move the motor and read the load cell so what if you moved the motor a little, read the load cell, moved the motor a little, read the load cell and so on until the load cell reading matches your target and stop moving the motor at that point.
Yeah but I’d feel that would lead to overages and not be so accurate. Will it not?? How would that look far as code?
Pseudo code for the main requirement
move motor to initial position
boolean variable finished = false
start of loop()
if finished is false
move motor a small amount
read load cell
if load at 200mg
finished = true //this will stop the motor
end if
end if
end of loop()
UKHeliBob:
Pseudo code for the main requirementmove motor to initial position
boolean variable finished = false
start of loop()
if finished is false
move motor a small amount
read load cell
if load at 200mg
finished = true //this will stop the motor
end if
end if
end of loop()
idk what you mean by that i should add im new to this. so far i have two codes separate one for load cell for for motor to move. should i include that to this so you see what i got?
#include <HX711_ADC.h> // https://github.com/olkal/HX711_ADC
#include <Wire.h>
#include <LiquidCrystal_I2C.h> // LiquidCrystal_I2C library
HX711_ADC LoadCell(3, 2); // parameters: dt pin, sck pin<span data-mce-type="bookmark" style="display: inline-block; width: 0px; overflow: hidden; line-height: 0;" class="mce_SELRES_start"></span>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // 0x27 is the i2c address of the LCM1602 IIC v1 module (might differ)
void setup() {
LoadCell.begin(); // start connection to HX711
LoadCell.start(2000); // load cells gets 2000ms of time to stabilize
LoadCell.setCalFactor(-6717); // calibration factor for load cell => strongly dependent on your individual setup
lcd.begin(16, 2); // begins connection to the LCD module
lcd.backlight(); // turns on the backlight
}
void loop() {
LoadCell.update(); // retrieves data from the load cell
float i = LoadCell.getData(); // get output value
lcd.setCursor(0, 0); // set cursor to first row
lcd.print("Weight[g]:"); // print out to LCD
lcd.setCursor(0, 1); // set cursor to secon row
lcd.print(i); // print out the retrieved value to the second row
}
thats for my lcd and load cell
#include <Arduino.h>
// Motor steps per revolution. Most steppers are 200 steps or 1.8 degrees/step
#define MOTOR_STEPS 200
// Microstepping mode. If you hardwired it to save pins, set to the same value here.
#define MICROSTEPS 8
#define DIR 8
#define STEP 9
#define ENABLE 13 // optional (just delete ENABLE from everywhere if not used)
#include "DRV8825.h"
#define MODE0 10
#define MODE1 11
#define MODE2 12
DRV8825 stepper(MOTOR_STEPS, DIR, STEP, ENABLE, MODE0, MODE1, MODE2);
void setup() {
/*
* Set target motor RPM=1
*/
stepper.begin(1, MICROSTEPS);
stepper.enable();
}
void loop() {
/*
* The easy way is just tell the motor to rotate 360 degrees at 1rpm
*/
stepper.rotate(360);
}
thats my stepper code
Seeing your code is helpful but do you understand how it works ?
In order to do what you want you need some/all of the code in the same sketch. Start a new sketch and copy the #includes, declarations and #defines from both of them into the new one.
Copy the code in both sketches into setup() in the new one. Create 2 new functions in the new sketch and copy the code from loop() in the old ones into the new functions. Leave loop() empty in the new sketch for now.
Does the code compile ? If not then why not ? Get that far then post the new sketch here with details of any errors. As written the new sketch will do nothing but it is important that it compiles.
What you need to do is set up a feedback loop.
- advance the stepper
- measure the pressure
- test for desired pressure
test 1) is the pressure still low? - advance stepper again
test 2) is the pressure too much? - reverse the steeper
test 3) is the pressure correct? - stop. - loop back to step 1.
If you know how many steps are needed to moven the auger into position, then you can speed things up by getting the auger into position before you start the feedback routine. You could also change the number of steps the motor turns depending on the pressure. As you get close to the set point, reduce the number of steps between pressure measurements.
Now if you want to get fancy, add push buttons to set the pressure you want.
While the able doesn't give you the code needed, it illustrates the program flow needed to perform the task you need to do.