Notifications
Clear all

Stepper and load cell

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

@rob42101 Please send me what you think will help. I was looking at python but like you say there are so much. C++ s another one but same story.


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

@the-apprentice Not geniuses, but there is a certain skill involved. BTW, when someone says 'codes' I know they are not a coder. It is always code, there is no plural.

Yes, time, many studies for all sorts of human endeavours have shown that 10,000 hours is to achieve world class, about 5,000 for expert class and 2,000 for competency.

Copy and paste will not work here for a couple reasons.

Fist this is TWO projects so you will not find any libraries or samples that have sample code. Secondly, the UNO is not capable of running the eventual solution. The third issue is you have not even determined if this will take two controllers, or maybe an ESP32-S3 using both cores via either RTOS or simple milli tasking.

If you were at the stage of learning around 1 year (2,000 hrs) I would ask you to just make a working load cell code and profile it. Ideally with a real profiler, I imagine the GCC suite has one but at the very least by using the microsecond function. My HUNCH is the load cell calls are super slow.

What that means is you need a stepper library that can take a command and run by itself while you read the load cell if you don't go the two processor or two cores or tasking via micros or RTOS route.

I really think you are waaaaaaay over your head, but if you are prepared to listen, answer questions when asked then maybe there is a hope.

First listen to @will, he is our resident stepper expert. What you need to learn from him is what library (NOT FlexyStepper) can be used that will allow you to do some setup then a very few commands to the stepper to have it run at the set speed in the background. ONLY after that is working and debugged do you attempt the next step which is.

Write a totally new sketch and using the library source code that you will have to read choose the most relevant function to use. I see average type functions which sound more relevant but maybe not. Mechanically you will need a fairly large mechanical buffer usually done with loops to allow the stepper to be brought to the correct speed. This is all a part of being a programmer. (at this stage the motors should be driven by a pot with a special testing sketch)

Once you have the load cell feedback working, modify (I know you will need help and I am happy to help at this point) the code to convert it to a function that returns a speed factor. values GT 0 are increase speed by X, values LT 0 are decrease speed by X. A value of 0 means maintain the current speed.

This is where you may want to add a speed adjust pot. I haven't given this a lot of thought so the design may change, but lets assume it goes after the load cell value is retrieved. If the load cell increase by 5 and you used the pot to go slower, then the load cell value would be modified to say 4.

You can do this but you need to listen.

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
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2042
 

@the-apprentice

Posted by: @the-apprentice

@zander ... I never wrote the codes. Copy and paste it works...

If I understand you correctly. Coding is for geniuses and it takes time?

Copy and paste doesn't work if you need to modify the code and/or understand what the code is doing.

Programming the Arduino development system is not hard to learn there are plenty of tutorials about.

But understanding how to write code is not the same as knowing the programming environment (simple for the Arduino) or understanding (or inventing) the algorithm you are implementing.  Knowing "how to program" doesn't mean you can program anything. 

 

 


   
Ron reacted
ReplyQuote
Marvin
(@rob42101)
The Paranoid Android
Joined: 2 months ago
Posts: 32
 

Posted by: @the-apprentice

Please send me what you think will help.

There are (of course) many, many sites that cover, not only Python, but also MicroPython and it's all too easy to have so many bookmarked that it becomes overwhelming, so my advice is to pick just a few sites that explain things in a way that you like working with.

Real Python has some excellent content, most of which you can view without the paywall restrictions, but there is that barrier to be aware of. You don't need to pay; simply find another site that offers the information without a paywall.

It's an old format for a website, but none the less, Full Circle Magazine has some very good content. You'll find a series of articles called Micro This Micro That (written by Greg Walters). They start at FCM167 and there's 26 in total, to date. The issue numbers are:

167 to 179,
181, 182, 185, 188,
193 to 201

That should be enough to keep you busy for a while.

Myself, I like to gather resources and study the theory before I embark on any practical work. I also need to setup my work area, before I get going, which will be a very small area, as I live in a small first floor apartment. A disused 'computer desk' (they were popular years ago, when one had a mini tower, a screen and a keyboard, rather then a 'laptop' computer) will be converted into my 'electronics lab' over the coming weeks.

I hope the links that I've provided will be of help. I'll also be able to offer some MicroPython coding help, once I know what I'm doing with that code base.

It does not matter how slowly you go as long as you do not stop:~ Confucius

The only thing necessary for the triumph of evil is for good men to do nothing.


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

Posted by: @the-apprentice

@rob42101 Please send me what you think will help. I was looking at python but like you say there are so much. C++ s another one but same story.

If I wasn't clear, let me try again. First you need to learn how to code in C so you know the syntax of the language like where () are used, where commas are used, and where semi-colons are used. There is a bit more, but that's a start. Then you need to learn the Arduino environment, be at least familiar with general concepts and know how to use the tools provided. Now you need to learn to code in Arduino IDE style, which means using libraries but also some other concepts.

What non-programmers don't know is that the actual act of writing code is maybe 20% of our time budget over the life of a project (I am speaking of a professional environment) The rest of the time is spent on researching, documenting, debugging, and learning about what it is we are trying to program. This forum is primarily for hobbyists who only do the 20% plus a little debugging and research. Most of them have some amount of experience but many do not. Those who do not mostly just build whatever Bill shows them how to build. You on the other hand are doing more of a research-style project. The things you need to learn are:

1. Complete C coding syntax. If you want a reference, I don't know anyone who didn't start learning C from the following book https://amz.run/8eie

2. A bit of C++ syntax. Only needed for Library creators. I am NOT C++ trained and only understand it at a very high level. If I have questions I know who to ask.

3. Stepper tutorial, Bill has several, you need to build several of them to completely understand them. Just search his YT for stepper. Watch the video to get a flavour, but then click the article link to get a document with more details. Also learn where to find datasheets and make use of them to understand both the motors, and the motor driver boards. You will need to know what kind of torque/amperage is needed so you can pick the right motor and driver. This is all a part of being a programmer, it's not just about coding.

4. Load cell tutorial. You will need to find one, I don't know of any. Reading the library source code might help when you can read code.

Same as above except you will need to learn how to do timing and performance analysis as I think these devices are slow.

I found that one of my favourite presenters has a load cell video. I have not watched it yet. Here is the link

Many on the forum know him as the 'Swiss Guy'

5. Program design concepts, like modularity, functional procedures and functions. Sorry, that is a college level course.

6. Perhaps some tasking tutorials unless you decide to use 2 boards, one running the motors, and one reading the load cell.

Lots of stuff on this, here are a few links to both real tasking and homemade (not in any order, just some random google hits)

https://bityl.co/OE7v

https://bityl.co/OE7w

https://bityl.co/OE7y

https://bityl.co/OE82

https://bityl.co/OE86

https://bityl.co/OE87

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.


   
ReplyQuote
Marvin
(@rob42101)
The Paranoid Android
Joined: 2 months ago
Posts: 32
 

Posted by: @zander

If I wasn't clear, let me try again. First you need to learn how to code in C

Coding with C is not a prerequisite for learning how to code in Python, which is what you seem to be implying here, unless I'm misunderstanding what you are saying.

The only thing necessary for the triumph of evil is for good men to do nothing.


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

@rob42101 You are misunderstanding 2 ways. Firstly, that post was not addressed to you and second this Topic has never mentioned Python until you did at https://forum.dronebotworkshop.com/postid/45933/

The OP doesn't even know how to program in procedural languages let alone OO. I have been programming for over 60 years and have never used OO in any serious way. It either didn't exist on the hardware I was working on at the time or at the very least no customers wanted another language to maintain.

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
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2506
 

Posted by: @rob42101

Coding with C is not a prerequisite for learning how to code in Python

Perfectly true and Python would certainly be a viable means for implementing the project.

However, it seems to me that discussing C, C++ and Python at this point is like arguing gasoline versus electric versus Diesel engines when the real problem is that the user doesn't know how to drive 🙂

 

Anything seems possible when you don't know what you're talking about.


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

@will I knew you would hit the nail on the head!

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
Marvin
(@rob42101)
The Paranoid Android
Joined: 2 months ago
Posts: 32
 

@the-apprentice

If you read nothing else, for now, read Why MicroPython?I believe that you'll get to grips with the coding side of your project, much quicker by using MicroPython. You can always learn C as well, and it would be no bad thing to do so, but it's a much steeper learning curve.

The only thing necessary for the triumph of evil is for good men to do nothing.


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

@rob42101 @the-apprentice I look forward to seeing a solution in another language.

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
byron
(@byron)
No Title
Joined: 5 years ago
Posts: 1118
 

Posted by: @zander

@rob42101 @the-apprentice I look forward to seeing a solution in another language.

Ron wanting to see another language, I think he's being jocular.   But hey, if you want then here's a video reading a load cell with a raspberry pi in python.   

Whats that,  you now want to control a stepper motor in python.  Well I would have to be convinced you were not just kidding me before you that good stuff. 😀  

 


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

@byron It's not for me, I couldn't care less. If you can make Python do it I will be impressed, I have difficulty seeing it done in C. If Python uses multi-tasking then it will be able to but otherwise keeping a stepper running while waiting a very long time for a load cell to respond is hard to see but like I said, surprise me.

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
byron
(@byron)
No Title
Joined: 5 years ago
Posts: 1118
 

@zander

I knew your expression of desire was a tad with a mocking tone, but of course python on a raspberry pi can multitask either with multithreading, multiprocessing or asynchronous programming.

Micropython also has the ability to run asyncio and can also use both cores of the rip pico.  Very easy to multitask. The rip pico also can be persuaded to control a stepper via its Programmable Input Output additional processing ability via its assembly routines called from micropython.

Sadly I’ve not got much time to contribute to a solution for the OP, so will have to leave it to the more than capable hands of @will 😎 (just make sure the coding malarkey is not for a commercial endeavour by the OP as Will will get mightily narked 🤨 )


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

@byron That sounds impressive.

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
Page 7 / 10