Notifications
Clear all

Stepper and load cell

150 Posts
8 Users
31 Likes
3,600 Views
The apprentice
(@the-apprentice)
Member
Joined: 4 months ago
Posts: 61
Topic starter  

I'm now changing the Leonardo to an Uno. Then I will change the driver to a TB6560. Not sure if this will do any good. I'm afraid I have damaged one of them with all my fiddling. 


   
ReplyQuote
The apprentice
(@the-apprentice)
Member
Joined: 4 months ago
Posts: 61
Topic starter  

I'm now changing the Leonardo to an Uno. Then I will change the driver to a TB6560. Not sure if this will do any good. I'm afraid I have damaged one of them with all my fiddling. 


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7008
 

@the-apprentice Changing the Leonardo to a UNO will change nothing. Also changing to the TB6560 is ill advised for a beginner. Stick with either the ULN2003 (good learning board) or the L298N or A4988. Bill has a video/article using all those driver boards, here are the two links VIDEO Article

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.


   
ReplyQuote
The apprentice
(@the-apprentice)
Member
Joined: 4 months ago
Posts: 61
Topic starter  

@zander It was just to make sure the boards are still working correctly. I would need the TB6560 for the end project as the stepper will be drawing about 2 amps.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7008
 

@the-apprentice Ok, but the venerable old L298N will handle that albeit it will run hot. Also the A4988 will handle 2A. You have choices.

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.


   
ReplyQuote
The apprentice
(@the-apprentice)
Member
Joined: 4 months ago
Posts: 61
Topic starter  

@zander That is something for when I have the program running. If I ever get this to work. LOL


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7008
 

@the-apprentice Just curious, are you following my instructions? It worked for me the first time.

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.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7008
 

@the-apprentice Black and blue wires on a black background is pointless. I assume you can follow Bills instructions for wiring up a stepper. Add the load cell after the stepper works with a pot, then replace the pot with 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.


   
ReplyQuote
The apprentice
(@the-apprentice)
Member
Joined: 4 months ago
Posts: 61
Topic starter  

@zander I have done it separate. Then everything works. The load cell prints to the serial monitor. Not sure how to get the reading to the potentiometer. And the speed to adjust accordingly.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7008
 

@the-apprentice I think that is two different things. One is using the load cell to control the stepper speed, and the second is to provide either an initial speed and/or a fine tune of the speed when in the main loop. WHICH IS IT?

The following makes no sense. Do you know ohms law?

Not sure how to get the reading to the potentiometer.

This is a serious problem, do you understand why?

The following is a bit of a concern

And the speed to adjust accordingly.

Isn't that the purpose of the load cell code?

Do I need to tell you how to do this again?

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.


   
ReplyQuote
Inst-Tech
(@inst-tech)
Member
Joined: 2 years ago
Posts: 554
 

@the-apprentice ..Hi, I have been monitoring your post with some interest, so I decided to run your problem through one of the circuit simulators I use for circuit design and troubleshooting. and here's what I came up with:

/*
  Source:  https://www.electroschematics.com/pressure-sensor-guide/ 
*/
#include <HX711.h>
#include <LiquidCrystal_I2C.h>
#include <AccelStepper.h>

const int dirPin = 2;
const int stepPin = 3;
const byte dout_pin = A1;
const byte sck_pin = A0;
unsigned long prevTime = 0;
float motorSpeed = 0;
float sensorReading = 0;

HX711 scale; //  define object called scale
LiquidCrystal_I2C lcd(0x27, 16, 2);

AccelStepper myStepper(AccelStepper::DRIVER, stepPin, dirPin); //define object as myStepper
void setup() {
  Serial.begin(115200);

   pinMode(dirPin, OUTPUT);
   pinMode(stepPin, OUTPUT);
   pinMode(dout_pin, INPUT);
   pinMode(sck_pin, INPUT);

     //digitalWrite(dirPin, HIGH);
     
   lcd.begin(16,2);
   lcd.clear();
   lcd.setCursor(0,0);
   lcd.print("HX711 Demo with");
   lcd.setCursor(0,1);
   lcd.print("HX711 Library");
    delay(1500);
   lcd.clear();
   lcd.setCursor(0,0);
   lcd.print("Initializing");
   lcd.setCursor(0,1);
   lcd.print("the scale");
   delay (1500);
   lcd.clear();

  // parameter "gain" is ommited; the default value 128 is used by the library
  // HX711.DOUT   - pin #A1
  // HX711.PD_SCK - pin #A0

  scale.begin(dout_pin, sck_pin);

  Serial.println("Before setting up the scale:");
  Serial.print("read: \t\t");
  Serial.println(scale.read());                  // print a raw reading from the ADC
  Serial.print("read average: \t\t");
  Serial.println(scale.read_average(20));        // print the average of 20 readings from the ADC
  Serial.print("get value: \t\t");
  Serial.println(scale.get_value(5));            // print the average of 5 readings from the ADC minus the tare weight (not set yet)
  Serial.print("get units: \t\t");
  Serial.println(scale.get_units(5), 1);         // print the average of 5 readings from the ADC minus tare weight (not set) divided

  // by the SCALE parameter (not set yet)
  scale.set_scale(420.f);  //2280.f                     // this value is obtained by calibrating the scale with known weights; see the README for details
  scale.tare();                                  // reset the scale to 0

  Serial.println("After setting up the scale:");
  Serial.print("read: \t\t");
  Serial.println(scale.read());                  // print a raw reading from the ADC
  Serial.print("read average: \t\t");
  Serial.println(scale.read_average(20));        // print the average of 20 readings from the ADC
  Serial.print("get value: \t\t");
  Serial.println(scale.get_value(5));            // print the average of 5 readings from the ADC minus the tare weight, set with tare()
  Serial.print("get units: \t\t");
  Serial.println(scale.get_units(5), 1);         // print the average of 5 readings from the ADC minus tare weight, divided

  // by the SCALE parameter set with set_scale
  Serial.println("Readings:");
}

void loop() {
  
if (millis() >= prevTime+1000){ //read scale every 1 second

 float sensorReading = (scale.get_units());
 Serial.print(sensorReading);
 Serial.print("\t\t");
  prevTime=millis();
 motorSpeed = sensorReading*40; //update motorSpeed

  Serial.println(motorSpeed);
  
}
   
  // set the motor speed:
 
     myStepper.setAcceleration(35);
     myStepper.setMaxSpeed(1000);
     myStepper.setSpeed(motorSpeed);      
     myStepper.runSpeed();
  

  
}

 

I assume you have followed the instructions on how to wire up everything, as you did say you could get the motor and the loadcell to work separately, but not just together. 

The simulation uses AccelStepper.h library and a A4988 driver with a 5kg load cell., so you will have adjust your calibration constant accordingly, as well as how you define your object for your stepper motor as the struct for this library uses the format 

AccelStepper myStepper(AccelStepper::DRIVER, stepPin, dirPin);
that is used for a A4988 driver and a bi-polar stepper motor.

in your query, you said you wanted the motor to slow down then the pressure ( tension) increased, but I didn't do that in this simulation..I'll just leave that to you to figure out how to do it..lol

Good luck with your project..

regards,

LouisR

 

LouisR


   
ReplyQuote
The apprentice
(@the-apprentice)
Member
Joined: 4 months ago
Posts: 61
Topic starter  

@inst-tech Thanks for helping. I will try it again and go back to the first post to read them again.


   
Inst-Tech reacted
ReplyQuote
Inst-Tech
(@inst-tech)
Member
Joined: 2 years ago
Posts: 554
 

Posted by: @the-apprentice

@inst-tech Thanks for helping. I will try it again and go back to the first post to read them again.

Your quite welcome.. and please let me know how you progress.. The simulation should be very close to how the motor and loadcell actually work, so I'm somewhat curious as to how it all works out. Good luck, and keep us informed.

regards,

LouisR

 

LouisR


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7008
 

@the-apprentice As usual, Pololu has great documentation for the A4988. I HIGHLY recommend you read ALL of it to understand the caveats and rules for using this driver. All drivers have pros and cons and you need to understand them ALL to pick your best match.

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.


   
Inst-Tech reacted
ReplyQuote
The apprentice
(@the-apprentice)
Member
Joined: 4 months ago
Posts: 61
Topic starter  

@inst-tech I keep getting this error.

Compilation error: no matching function for call to 'HX711::HX711()'


   
ReplyQuote
Page 5 / 10