Author Topic: Need code for Arduino project- help me  (Read 2457 times)

0 Members and 1 Guest are viewing this topic.

Offline ImnarnianTopic starter

  • Contributor
  • !
  • Posts: 13
  • Country: in
Need code for Arduino project- help me
« on: March 29, 2022, 04:38:33 am »
Hi guys. I want to make an abrasive polish with an Arduino . I already make designs (Reference Image 3) and have not yet bought all the components. I just ordered components today except the Arduino and Stepper motor. Arduino prices have gone higher because of the Atmega 328p shortage. I will buy it ASAP. Before that I would like to prepare other things.

Hereby I attached some reference Images. I'm not very good at Arduino coding. I watch some Youtube videos and make notes, not code. If there are any wrong or mis-combinations (Reference image 1) please teach me, friends.

Here are the components:

1. Nema 17 stepper motor with A4988 Driver

OR

28BJY-48 Stepper motor with ULN2003 Driver

2. LCD 1602

3. 6mm Tactile switches (4)

4. Arduino UNO

{Nema 17 Stepper motor is quite expensive. But the 28BJY-48 Stepper motor is a cheap one. In performance comparison Nema 17 wins. So I decided to put both motor mounts in my design to use both of them. I thought both are load only difference is Amps. So the only thing I change is to change pins in the Arduino. Correct me please if I’m wrong. If using Only motor is possible, no problem.}

Features that I needed:

1. Using Arduino UNO and 1602 LCD

2. Those 4 Tactile switches for Forward, Backward, Zero, Go to Zero (Reference Image 2).

3. The LCD display should show Forward movement in the unit of "mm". For example This stepper motor gives 200 steps/ revolution. We are using a 2mm Trapezoidal pitch threaded rod, So it can able to give the forward or backward movement of 0.01mm. So we can easily calculate how much it moves using steps moved in the Stepper motor. The example of a LCD display as shown in the document (Reference Image 2)

4. Every Single press of Tactile switch, stepper motor gives only one step movement. Long press of the Tactile switch gives continuous rotation, of a certain speed. That speed should be fixed in Coding.



Can anyone please write code for this for me.



THANKS IN ADVANCE !!!

I also post this problem in reddit too.
 

Offline matb

  • Regular Contributor
  • *
  • Posts: 68
  • Country: fr
Re: Need code for Arduino project- help me
« Reply #1 on: March 29, 2022, 06:33:30 am »
Hi, first some informations missing :
  • What is the LCD type, I2C driven ?
  • How are you going to power your system ?

You could first start with a button. Ground on one side and an analog input with pull-up (check INPUT_PULLUP) on the other side. Watching the state changing on the console.
Then you can add the other buttons.
Then you add an LCD and start just printing the state of your 4 buttons, then text, then numbers.
And finally your motor driver.

We can help you with debugging but not write the code from scratch as there are lots of exemple on internet (and in Arduino Exemples)
 
The following users thanked this post: Imnarnian

Offline Brumby

  • Supporter
  • ****
  • Posts: 12380
  • Country: au
Re: Need code for Arduino project- help me
« Reply #2 on: March 29, 2022, 07:28:15 am »
Can anyone please write code for this for me.

We are not a programming service.  Someone might feel sorry for you - but don't expect this.

We are the sort of crowd that will help you build such projects.  Hints, tips, examples of this kind or the other.  Electronics being the main strength here, but coding experience is around as well.

We like people to learn.  You make the effort and you will quite often find a few members who are more than willing to help you get there - and you will be better prepared for your next project.
« Last Edit: March 29, 2022, 07:31:35 am by Brumby »
 
The following users thanked this post: Ed.Kloonk, madires, tooki, Jacon, RJSV, Microdoser, Imnarnian

Offline tooki

  • Super Contributor
  • ***
  • Posts: 12577
  • Country: ch
Re: Need code for Arduino project- help me
« Reply #3 on: March 29, 2022, 09:26:03 am »
Hi guys. I want to make an abrasive polish with an Arduino . I already make designs (Reference Image 3) and have not yet bought all the components. I just ordered components today except the Arduino and Stepper motor. Arduino prices have gone higher because of the Atmega 328p shortage. I will buy it ASAP. Before that I would like to prepare other things.

Hereby I attached some reference Images. I'm not very good at Arduino coding.

[…]

Can anyone please write code for this for me.
Sure. That’ll be $195/h.

In all seriousness, none of us were any good at coding in the beginning. It’s why you start at the beginning and practice. Figure out and understand the “blink” sketch. Figure out how to use buttons to turn the LED off and on. Figure out how to write to an LCD. Figure out how to get each piece working. Then you start combining.
 
The following users thanked this post: Imnarnian

Offline ImnarnianTopic starter

  • Contributor
  • !
  • Posts: 13
  • Country: in
Re: Need code for Arduino project- help me
« Reply #4 on: March 29, 2022, 10:07:18 am »
Hi sir Thanks for your reply.
It's a I2C driven sir. I powered it with 12V SMPS.

Yeah sir. The problem is I dont know how to write or edit codes. I will study some basics and let you know sir. Thanks for your reply.
 

Offline ImnarnianTopic starter

  • Contributor
  • !
  • Posts: 13
  • Country: in
Re: Need code for Arduino project- help me
« Reply #5 on: March 29, 2022, 10:09:04 am »
Thanks for your reply sir.

Sorry putting post like this. I will learn Arduino and try some codes and post for your review sir.
 

Offline ImnarnianTopic starter

  • Contributor
  • !
  • Posts: 13
  • Country: in
Re: Need code for Arduino project- help me
« Reply #6 on: March 29, 2022, 10:11:10 am »
Thanks for reply sir.

This induce me in Arduino coding and understanding how it works.  I will learn codes and edit existing codes and post here for your reply sir.  :)
 

Offline Zipdox

  • Regular Contributor
  • *
  • Posts: 193
  • Country: nl
Re: Need code for Arduino project- help me
« Reply #7 on: March 29, 2022, 11:14:22 am »
You have example sketches and stackoverflow. Use them.
 
The following users thanked this post: Imnarnian

Offline ImnarnianTopic starter

  • Contributor
  • !
  • Posts: 13
  • Country: in
Re: Need code for Arduino project- help me
« Reply #8 on: March 29, 2022, 11:55:04 am »
Thanks for your help Zipdox
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9933
  • Country: us
Re: Need code for Arduino project- help me
« Reply #9 on: March 29, 2022, 03:14:05 pm »
In the IDE select File->Examples->Stepper or File->Examples->Liquid Crystal or File->Examples->Digital->Button

It's all right there in the IDE but if you have something specific, just Google for 'Arduino <whatever>'

Literally, EVERYTHING that can be done with an Arduino has already been done and it's all on the Internet.  That's why people select the Arduino in the first place.  Most of the work has already been done.

Google for 'Arduino CNC' and one of the replies is:

https://howtomechatronics.com/tutorials/how-to-setup-grbl-control-cnc-machine-with-arduino/

It's all out there, all you have to do is look.
 
The following users thanked this post: Imnarnian

Offline SL4P

  • Super Contributor
  • ***
  • Posts: 2318
  • Country: au
  • There's more value if you figure it out yourself!
Re: Need code for Arduino project- help me
« Reply #10 on: March 29, 2022, 10:50:29 pm »
You could do a lot worse than visiting the Arduino Forum
https://forum.arduino.cc/

If you go in well prepared, and put some effort in for yourself, I guarantee you can solve your requirements.
Don't ask a question if you aren't willing to listen to the answer.
 
The following users thanked this post: Imnarnian

Offline Brumby

  • Supporter
  • ****
  • Posts: 12380
  • Country: au
Re: Need code for Arduino project- help me
« Reply #11 on: March 30, 2022, 12:39:28 am »
The key is to start with something simple - like making an LED flash.

This is actually a very important achievement!  By getting that to happen, you have set up the development environment - which is the most important first step - and you have a few "simple to understand" lines of code.

I would suggest it is important that you understand how that simple code flows in execution before you start looking at more complex programming - and when you move to more and more complex code, do so one step at a time.  By doing this, you will only be dealing with one new feature, so if there are problems, you can keep your investigations confined to that one area.  If you add five new features to your code and have problems, then sorting out where the problems have crept in can be really difficult, especially if you are just getting into programming.

First learn to crawl, then learn to walk before you want to get up and run.
« Last Edit: March 30, 2022, 12:41:06 am by Brumby »
 
The following users thanked this post: Imnarnian

Offline Brumby

  • Supporter
  • ****
  • Posts: 12380
  • Country: au
Re: Need code for Arduino project- help me
« Reply #12 on: March 30, 2022, 12:45:16 am »
This induce me in Arduino coding and understanding how it works.  I will learn codes and edit existing codes

Excellent!  This is the best way (in my opinion).

That's how I started with Arduino programming - and I started writing code professionally last century.
 
The following users thanked this post: Imnarnian

Offline RJSV

  • Super Contributor
  • ***
  • Posts: 2378
  • Country: us
Re: Need code for Arduino project- help me
« Reply #13 on: March 30, 2022, 10:30:28 am »
Those replies are good, and I could add a little:
   Just doing that first step, (read previous couple of posts, from several people).  That first step, I would probably have trouble, with how to type in one of the 'BIT' functions, those (exacting) things can be frustrating, but not so bad.
Like, for example, you might need something looking like:.   LED1_port2  EQU 04010h
            Blink_ON EQU (0001000b)
:
            SETB LED1 ; Blink_ON

...Stuff looking cryptic like that, where you know what to do; it's just to set the LED bit, in the processor system output port.  But, regardless of processor type, you have to focus, on getting exact, with those couple lines of your CODE.  A couple of lines, in my general example, do the defining, but, instead of thinking:
..." SETB 0XXXBXXX b ", you just translate, as you go, instead thinking the common sense way;
"That will turn on the one LED bit, in the PORT I want..."
  Once you get over a couple of those hurdles, you can turn attention to the flow of your code, maybe it loops, just endlessly, to start, (as others have described).
A person alone, might struggle a bit, but you, here, can just put the question onto your EEVblog thread.  As I said, often it's just a format/ typing issue, with the strange looking characters and numbers mixed.

   What does need to happen, you need, maybe, some good background, on the so-called Hexadecimal formats, and a little binary math.
So you know, for example, '00001000'b   That's a '4' in regular decimal.  Or, for hexadecimal address, an output port might be: '04000'h ...That defines the PORT location, memory mapped.
I couldn't even tell you, directly, what value is 'Four-Thousand, hex'... I think in decimal it's going to be some 16, 440 decimal. (Literally it's 16 X 1024).
   See what I mean ?  The little, pesky format details, that can really distract, when you have some bigger problem to analyze.
But don't let 'hex' numbers, and strange definitions deter you: You've got great access to folks all too willing to aid your efforts.  Writing code can be hard, but that's how you can earn some bucks, if you take effort to learn!
 
The following users thanked this post: Imnarnian

Offline tooki

  • Super Contributor
  • ***
  • Posts: 12577
  • Country: ch
Re: Need code for Arduino project- help me
« Reply #14 on: March 30, 2022, 12:51:03 pm »
RJHayward, do you honestly think that the OP, who’s befuddled by introductory Arduino coding and has said they’ve written no code yet, could even begin to make sense of your post?? And that’s if your writing were clear and coherent, which it sadly is not. You’ve got tons of strange, run-on sentence fragments joined with bizarre comma usage. (Is it supposed to be William Shatner-style pausing between words? :P )
 
The following users thanked this post: cgroen, james_s, Jacon

Offline RJSV

  • Super Contributor
  • ***
  • Posts: 2378
  • Country: us
Re: Need code for Arduino project- help me
« Reply #15 on: March 31, 2022, 04:26:41 pm »
Yeah, all correct, RE: my run-on sentences!
   But I bet, almost all of us felt that way, when first confronted by 'HEXADECIMAL' numbers, and especially the 'arcane' and highly specific language needed to enter a 'Bit function' character by character.
Heck, some newer programmers are always needed, and some encouraging words regarding the strange language needed, to enter CODE.
   I come from background where I always like to know what the OBJECT code output generates; a sort of LITERAL reading.  But that's a hardware vantage.

   So question, today, I'm wondering, do you have a development system / software package, for editing things, and for de-bug problems ?
That might be a whole 'nother set of questions and issues, somebody like me can learn, as others answer your questions.
I'm not SUPERMAN, just did 'some' coding...
 

Offline tooki

  • Super Contributor
  • ***
  • Posts: 12577
  • Country: ch
Re: Need code for Arduino project- help me
« Reply #16 on: March 31, 2022, 04:35:17 pm »
The OP says Arduino right in the thread title. Unless otherwise specified, this generally means an Arduino board (or clone), using the Arduino environment (i.e. C++ and the Arduino standard libraries), in the Arduino IDE, without any true debugger.
 

Offline ImnarnianTopic starter

  • Contributor
  • !
  • Posts: 13
  • Country: in
Re: Need code for Arduino project- help me
« Reply #17 on: April 09, 2022, 07:25:42 am »
Hi guys, In my previous post I asked for code.

What I did :



1. I found code for Stepper motor controlling with Arduino with LCD and rotary encoder in curious scientist. Link below : https://curiousscientist.tech/blog/stepper-motor-direct-control-rotary-encoder

2. I connect the parts as per the code and put it in Arduino. After I connect the power supply, it won't work.

3. I don't have a stepper motor. So I didn't connect the motor. I just want to know, Is LCD works or not. Motor side is not a problem It will work when I connect it to driver and Arduino. But at the same time, I have an another doubt. I use a rotary encoder and stepper motor. Is Arduino counts and check the feedback voltage of stepper motor Initially. maybe that's the reason for its not working.

4. Finally I check with youtube video. link below :

5. The code in youtube and the code in google is not same. So I change the google code to Youtube code. its not working.



Can anyone help me please.



I attached some reference images.


Code in Youtube video :



//AccelStepper

#include <AccelStepper.h>

AccelStepper stepper(1, 9, 8);// pulses Digital 9 (CLK); Direction Digital 8 (CCW)



//16x2 LCD

#include <LiquidCrystal_I2C.h> //SDA = A4, SCL = A5

LiquidCrystal_I2C lcd(0x27, 16, 2);





//Defining pins

const int RotaryCLK = 2; //CLK pin on the rotary encoder

const int RotaryDT = 4; //DT pin on the rotary encoder

const int RotarySW = 3; //SW pin on the rotary encoder (Button function)



//Defining variables

int ButtonCounter = 0;

int RotateCounter = 0;



//Statuses

int CLKNow;

int CLKPrevious;



int DTNow;

int DTPrevious;



// Time

float TimeNow1;

float TimeNow2;









void setup()

{



Serial.begin(9600);

//------------------------------------------------------

lcd.init(); //initialize the lcd

lcd.init();

lcd.backlight();

//------------------------------------------------------

lcd.setCursor(0,0); //Defining positon to write from first row,first column .

lcd.print("Rotary encoder");

lcd.setCursor(0,1);

lcd.print("Stepper stepping"); //You can write 16 Characters per line .

delay(5000); //wait 1 sec

//------------------------------------------------------



pinMode(2, INPUT_PULLUP);

pinMode(3, INPUT_PULLUP);

pinMode(4, INPUT_PULLUP);



//Store states

CLKPrevious = digitalRead(RotaryCLK);

DTPrevious = digitalRead(RotaryDT);

attachInterrupt(digitalPinToInterrupt(RotaryCLK), rotate, CHANGE);

attachInterrupt(digitalPinToInterrupt(RotarySW), buttonPressed, FALLING);



stepper.setMaxSpeed(1000); //SPEED = Steps / second

stepper.setAcceleration(5000); //ACCELERATION = Steps /(second)^2



TimeNow1 = millis(); //Start time

}





void loop()

{

printLCD();

RunTheMotor();

}



void buttonPressed()

{

TimeNow2 = millis();

if(TimeNow2 - TimeNow1 < 1000)

{

ButtonCounter++; //increase the counter

}

TimeNow1 = millis();

//You can add something here, like resetting the RotateCounter (e.g. redefine 0 position)

}



void rotate()

{

CLKNow = digitalRead(RotaryCLK); //Read the state of the CLK pin



// If last and current state of CLK are different, then a pulse occurred

if (CLKNow != CLKPrevious && CLKNow == 1){



// If the DT state is different than the CLK state then

// the encoder is rotating CCW so increase

if (digitalRead(RotaryDT) != CLKNow) {

RotateCounter++;

} else {

// Encoder is rotating CW so decrease

RotateCounter--;

}

}

CLKPrevious = CLKNow; // Store last CLK state

}





void printLCD()

{

//lcd.clear();

lcd.setCursor(0,0); // Defining positon to write from first row, first column .

lcd.print("Clicks: ");

lcd.setCursor(8,0);

lcd.print(" ");

lcd.setCursor(8,0);

lcd.print(ButtonCounter); //Print the number of button clicks

lcd.setCursor(0,1); // Defining positon to write from second row, first column .

lcd.print("Position: ");

lcd.setCursor(10,1);

lcd.print(" ");

lcd.setCursor(10,1);

lcd.print(RotateCounter); //Print the number of pulses

}



void RunTheMotor() //function for the motor

{

stepper.enableOutputs(); //enable pins

stepper.moveTo(-1*RotateCounter); //-1 is to match the rotation of the encoder with the rotation of the stepper

while(stepper.distanceToGo() != 0)

{

stepper.runToNewPosition(RotateCounter);

}

}

 

Offline tooki

  • Super Contributor
  • ***
  • Posts: 12577
  • Country: ch
Re: Need code for Arduino project- help me
« Reply #18 on: April 10, 2022, 01:38:24 am »
Multiple people have told you what you need to do: START AT THE BEGINNING. Don’t try to get a complex bit of code running until you can get simple stuff running and understand what it’s doing. Step by step.

P.S. fix that atrocious formatting on the code there — or just delete it altogether since it’s just copied from the linked page!
 
The following users thanked this post: Imnarnian

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9933
  • Country: us
Re: Need code for Arduino project- help me
« Reply #19 on: April 10, 2022, 11:13:50 am »
As tooki points out, it's best to start small.

My first order of priority is to get a "hello world" bit of code working.  That is vitally important because it proves that the standard libraries are present, the compiler works, the bootloader works and the USB serial port works.  That is significant progress!

For this project, I would then add the LCD display.  Since this will be based on a 3rd party library and specific components (yes,  you have to use the exact display that matches the library) I can expect to have to spend time getting this to work.  But it must be rock solid before moving to the next step.

I might work on pushbuttons next.  These are easy but I would still write test code and use serial output to the terminal to indicate a change in button state.

Finally, I would work on the stepper code.  I would write very simple functions to just run the motor.  The fancy position counting can wait until I know the motor steps.  I expect to spend quite a bit of time getting this phase to work.  Again, the library and components must match perfectly.

Finally, I would add all the fluff.  Position counting and such would be written near the end of the project, not at the beginning.

At every step in the process, I am going to be using serial output to keep track of what is going on.  I would leave any test output code in place until the very end of the coding process.

Anyway, that's the way I would approach it.  What I wouldn't do is download somebody else's code and blindly try to get it to work.


« Last Edit: April 10, 2022, 11:15:53 am by rstofer »
 
The following users thanked this post: Imnarnian

Offline ImnarnianTopic starter

  • Contributor
  • !
  • Posts: 13
  • Country: in
Re: Need code for Arduino project- help me
« Reply #20 on: April 11, 2022, 09:53:34 am »
Yeah ok sir,

Thanks for reply @tooki, @rstofer


I did hello world, servo tester, blink code, Also did some stepper motor controller with small changes. Then only I go to website and did like this. If this is not enough I will learn and do some fun activities with Arduino and understand how it works.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf