Help me , i dont know how to use gpio to move stepper motor

#1

If you are asking a question, please follow this template:

  1. to move stepper motor forward and backward

#include <stdio.h>
#include “mgos_gpio.h”

#define dirpin 4
#define steppin 3

enum mgos_app_init_result mgos_app_init(void) {

 mgos_gpio_set_mode(dirpin, MGOS_GPIO_MODE_OUTPUT);
 mgos_gpio_write (dirpin, 1);
 for(int x = 0; x < 200; x++) {
  mgos_gpio_set_mode(steppin, MGOS_GPIO_MODE_OUTPUT);
  mgos_gpio_write (steppin, 1);
  mgos_gpio_write (steppin, 0);
  }

  mgos_gpio_set_mode(dirpin, MGOS_GPIO_MODE_OUTPUT);
  mgos_gpio_write (dirpin, 0);
  for(int x = 0; x < 400; x++) {
    mgos_gpio_set_mode(steppin, MGOS_GPIO_MODE_OUTPUT);
    mgos_gpio_write (steppin, 1);
    mgos_gpio_write (steppin, 0);
    }

return MGOS_APP_INIT_SUCCESS;
}
3. i cant mos build this code, it alwasy failed. there was no error in my code but it cant build.

  1. whats wrong with my code, please help me. i am still new with mongoose os
0 Likes

#2

You have a file ._main.c in the src folder which is not a valid c file.

0 Likes

#3

oh ok, so what do i do?
do i need to make a new c file to put my code?

0 Likes

#4

main.c and ._main.c are different files. Notice the before main.c.
Run dir src in the application’s directory and show the output.
Ex:

C:\error>dir src
 Volume in drive C is xxx
 Volume Serial Number is yyy

 Directory of C:\error\src

09.04.2019  17:00    <DIR>          .
09.04.2019  17:00    <DIR>          ..
09.04.2019  17:00                 0 ._main.c
09.04.2019  16:57                 0 main.c
0 Likes

#5

04/09/2019 08:35 PM .
04/09/2019 08:35 PM …
04/09/2019 08:35 PM 2,191 main.c
1 File(s) 2,191 bytes

why there is no ._main.c in my src directory?

0 Likes

#6

Try with dir /ah src

0 Likes

#7

04/05/2019 09:29 AM 6,148 .DS_Store
04/05/2019 10:22 AM 4,096 ._.DS_Store
04/05/2019 10:22 AM 4,096 ._main.c
3 File(s) 14,340 bytes

0 Likes

#8

Files from a mac :slight_smile:
Delete all the dot files.

0 Likes

#9

so i delete this all?
04/05/2019 09:29 AM 6,148 .DS_Store
04/05/2019 10:22 AM 4,096 ._.DS_Store
04/05/2019 10:22 AM 4,096 ._main.c

0 Likes

#10

ok i already delete all the dot files.but i still failed to build

0 Likes

#11

Can’t help without the build log.

0 Likes

#12

enum mgos_app_init_result mgos_app_init(void) { << undeclared , return error with value

what is that mean?

0 Likes

#13

You have several C language errors which are not related to Mongoose OS:

  • error: return type is an incomplete type in line 57
  • ‘MGOS_APP_INIT_SUCCESS’ undeclared

That means that the header files defining them are not included in main.c

Add

#include "mgos.h"

at the top of your file and rebuild.

0 Likes

#14

oh my god, thanks sir
its finally can be builded , but im not yet test it with my stepper motor
but still thank you very much sir, have a nice day

0 Likes