Notifications
Clear all

Stepper and load cell

150 Posts
8 Users
31 Reactions
6,929 Views
Inst-Tech
(@inst-tech)
Member
Joined: 3 years ago
Posts: 554
 

Posted by: @the-apprentice

@inst-tech Was thinking of using a STM 32 Nucleo. It can multi task. Do any one know of this processor?

As I said in my last reply to you, The Arduino Uno can easily do what you are asking it to do..However, you can use almost any MPU/MCU for the task. Your problem is getting the code correct so that it can do the task required. This, however, requires alot of research and trial & error on your part to see how the code actually works. Remember, if it was easy, everyone would be doing it!...lol

Obviously, it's not easy, and can be the cause of a lot of frustration and angst, but in the end, your reward will be the satisfaction of building, or designing something that works the way you intended it to. I have many decades of experience in making things work that weren't designed correctly in the first place...lol .. That's what technicians do, besides installing, trouble-shooting, and  repairing system components, Working in an industrial environment also gives one an exposure to many different types of processes and control schemes.

Your on the right track, just keep at it, and it'll all come together..I'm still waiting on my NEMA17 motor to arrive so I can finish my testing on the hardware part...The coding is mostly done, and when I'm done testing...I'll turn it into a 10kg scale..lol

regards,

LouisR

 

LouisR


   
Ron reacted
ReplyQuote
The apprentice
(@the-apprentice)
Member
Joined: 10 months ago
Posts: 75
Topic starter  

This will help. 


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

@the-apprentice Nope.

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.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


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

@zander LOL


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

@the-apprentice One thing that just occurred to me looking at your device, is the motor turning the take up spool will need to vary it's speed as the diameter of material on the spool increases. Maybe measuring the tension will do that, I am not sure. At some point it's a math and specsheet exercise that will need to be translated into code.

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.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


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

@the-apprentice The reason I said nope, is I had already grokked it from an earlier picture you posted at https://forum.dronebotworkshop.com/postid/46056/

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.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


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

@zander The load cell is actually there to slightly tension the string. If it tensions to much the main motor will break the plastics string being puled.


   
Inst-Tech reacted
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 4 years ago
Posts: 7664
 

@the-apprentice Sorry, no idea what you are replying to.

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.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


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

I'm a blank now. Just cant get it to work not even with 2 Arduino's. 


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

@the-apprentice Nowhere near enough info for starters. You do NOT need 2 arduinos. I had it working but since deleted the sketch. In a nutshell here are the general steps.

1. Use the kitchen_scale example form the HX711 library.

2. From whatever (recommend AccelStepper) stepper library you are using, look for a basic example like constant _speed (3 lines of operational code)

3. In your sketch, create a setup that has any common code like setting up the Serial monitor, then call a procedure called stepper_Setup that you create from the sample setup leaving out the common stuff. Do the same for scale and call it scale_setup. You MAY need to add calibration and tare routines.

In your loop, copy in the scale sample then copy the one line stepper loop code and place it at the top or bottom of your loop whatever seems correct.

All you need to do now is add a routine to read a speed controller like a potentiometer (linear or log?)

do the usual map operation and you are done.

 

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.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


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

@the-apprentice One minor point you may not be familiar with, you will need to find out (from datasheet) what the resolution is of the analogue pins. It will either be expressed as number of bits or a decimal range. The low end will be 0 so the map instruction is something like.

I always assume anybody using the forum knows how to do binary math so converting from 4 bits resolution to 0 to 15 is a given.

int newSpeed = map(analogueRead(pinSpeed), 0, max from spec sheet, 0 unless you want something else for a minimum speed, whatever you want for a max speed);

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.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


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

Thanks I will try it. 


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

Nope my skills are not able to get it to work. Busy learning Python. Maybe in 10 years I will do it. 


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

@the-apprentice What exactly didn't work? Did the scale give a result from get _units? Did the stepper move in response to the set_speed and run_speed?

It's a very small sketch, main loop is around a dozen lines of code. 

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.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
byron
(@byron)
No Title
Joined: 5 years ago
Posts: 1177
 

@the-apprentice 

Out with my grass mower to dodge the next rain shower and I ran over a blasted bit of cut up chicken wire.   Horrible mechanical sound ensued and I can't easily get to see what damage has been done and the mower needs lifting up on a hoist to see what's going on below.  A phone call tomorrow to mower repair man will probably prove expensive. 🙄  So I came indoors, perused some stuff and now subject you to a verbose rambling.  But who knows maybe it helps. (probably not though)

Learning python I see.  It's certainly a good choice to get to learn about programming for sure, but learning about the fundamentals of programming is really the same for any programming language.  I mean things like using variables, program flow control structures such as loops, using functions, endeavoring not to repeat your code to accomplish similar tasks, using recursion, etc etc.  And not to forget how to go about debugging your code.    

Python is good for learning probably the main reason is because one does not have to compile it, just run the Python script and inevitably see on what line of code your program goes wobbly and issues an error.   Ah you say, that was a silly typo, you correct it and immediately run the program again.  Also there is the ability to run Python code in a REPL (Read Evaluate Print and Loop) where one can input a line of code and have it immediately run to test things out.   

So learning Python is a good way to get to grips with programming, but it will be a while before you get up to speed in any language and it will be a while before you are tackling the programming for your particular project.    I see you have mentioned using Arduino Uno and some other boards.   Python runs on computers with an operating system (widows, linux etc) but a version of Python, MicroPython, runs on microprocessor boards that do not have an operating system, but it only runs on some select microprocessor boards and Arduino Uno boards are not on that list.   Also to remember is that MicroPython is written in C so anything MP can do, you can of course do directly with your own C code with sufficient time and knowledge.

As to your project, I would comment that it seems you are almost at a solution.   As you probably appreciate, your little old microprocessor board has to keep giving a pulse to your stepper motor driver to keep it turning.  But at the same time you want to keep reading information from your load cell to see if the pulses given to your stepper should be increased or decreased.   Fine, and you were getting there as you indicated the stepper was turning (very slow but nevertheless turning) and you were reading the load cell values at the same time.   Now @will pointed out that this was because too much was going on in the loop that controlled the stepper.  In that loop you were both controlling the stepper, reading the load cell, printing some stuff, and (a real time killer for a loop) choosing to put in a bit of a delay thus suspending your cpu for a while.  So no wonder your instructions to the stepper to step again was taking rather a long time.    

Now one approach to consider is to think about 2 (or more) loops going on at the same time.  One loop controls the stepper but with a miniscule quick check to see if the load cell indicates a speed change is required.  Another loop continually checks on the status of the load cell reading and sets a flag, recording a value, if the load cell reading changes.   It is this flag and value the stepper loop will be checking to see if a speed adjustment is required.  For this approach of using two loops then maybe you could consider using the millis timer function to ensure each loop runs and does not hog too much of the cpu’s time giving each loop a chance to run.   Maybe a peruse of this article on using millis for multitasking on an Arduino will help.  https://www.baldengineer.com/millis-tutorial.html

To close off, good luck with your project,  and do make progress with Python if you wish to progress enough to enable future projects to be undertaken.  However I expect, should you choose to follow along with @zander, and taking little steps at a time and following along the good examples Ron and @will  provided you will actually get a working example up and running in C.  You will need to follow along taking simple steps and provide the feedback on each step you take to enable anyone assisting you provide further assistance if required.  You will of course need to take steps to learn a bit more C programming at the same time.

Of course a working example of working code does not mean it will translate into providing the necessary result for your project and I expect there are more mechanical hurdles to overcome too. 

Blooming heck, that was a verbose post, almost a @davee sermon.  Ron will not be pleased. 😎  




   
DaveE reacted
ReplyQuote
Page 9 / 10