How to use servo click library in pic16f1526 microcontroller to control the servo motor using PCA9685 module

General discussion on mikroC PRO for PIC.
Author
Message
kumar123
Posts: 68
Joined: 17 Oct 2023 07:32

How to use servo click library in pic16f1526 microcontroller to control the servo motor using PCA9685 module

#1 Post by kumar123 » 13 Nov 2023 10:00

Hi,

I want to control servo motor using micro-controller (PIC16F1526). The micro-controllar is connected to PCA9685 module via I2C.
I have used servo library in mikroC pro for PIC compiler but it is not working to control the servo motor. I don't want to use mikrobus and development board an all things.
The below code I trying to compile but it is not working for PIC16F1526 miro-controller using PCA9685 module in mikroC for PIC compiler.
[url]https://https://github.com/MikroElektro ... ck.git[url]

Thank you

kumar123
Posts: 68
Joined: 17 Oct 2023 07:32

How to use servo click library in pic16f1526 microcontroller to control the servo motor using PCA9685 module

#2 Post by kumar123 » 14 Nov 2023 05:12

Hi,
I want to control servo motor using micro-controller (PIC16F1526). The micro-controllar is connected to PCA9685 module via I2C.
I have used servo library in mikroC pro for PIC compiler but it is not working to control the servo motor. I don't want to use mikrobus and development board an all things.
I am using PIC16F1526 micro-controller. RC3,RC4 and GND pins of PIC16F1526 is connected to SCL, SDA, and GND pins of PCA9685 module.
The below code I trying to compile but it is not working for PIC16F1526 miro-controller using PCA9685 module in mikroC for PIC compiler.
Servo_click-master.zip
(4.28 MiB) Downloaded 32 times
Thank you

kumar123
Posts: 68
Joined: 17 Oct 2023 07:32

Re: How to work with servo click library in pic16f1526 microcontroller to control the servo motor using PCA9685 module

#3 Post by kumar123 » 14 Nov 2023 06:26

Hi,
I want to control servo motor using micro-controller (PIC16F1526). The micro-controllar is connected to PCA9685 module via I2C.
I have used servo library in mikroC pro for PIC compiler but it is not working to control the servo motor. I don't want to use mikrobus and development board an all things.
I am using PIC16F1526 micro-controller. RC3,RC4 and GND pins of PIC16F1526 is connected to SCL, SDA, and GND pins of PCA9685 module.
The below code I trying to compile but it is not working for PIC16F1526 miro-controller using PCA9685 module in mikroC for PIC compiler.
We want to work on pic16f1526 with Servo click library so when I trying to built the program I got error like
err2.png
err2.png (40.24 KiB) Viewed 896 times
err1.png
err1.png (193.6 KiB) Viewed 896 times
so please any one help us to clear this issue.

Best regards,
Himanshu Kumar

User avatar
IvanJeremic
mikroElektronika team
Posts: 316
Joined: 05 Sep 2022 14:32

Re: How to use servo click library in pic16f1526 microcontroller to control the servo motor using PCA9685 module

#4 Post by IvanJeremic » 14 Nov 2023 07:57

Hi,

You do not have to use the MikroBUS, but there is no example written for it without the use of the MikroBUS library.

Basically you will have to rewrite the code to not use the MikroBUS library, so just define the pins that you are using.

Regards,

Ivan.

kumar123
Posts: 68
Joined: 17 Oct 2023 07:32

Re: How to use servo click library in pic16f1526 microcontroller to control the servo motor using PCA9685 module

#5 Post by kumar123 » 14 Nov 2023 08:16

Hi,
Could you explain it in more details, where i need to define the pins
I am using RC4,RC3 pins of micro-controller connected to sda, scl of of PCA9685 respectively.

Regards,
Himanshu Kumar

User avatar
IvanJeremic
mikroElektronika team
Posts: 316
Joined: 05 Sep 2022 14:32

Re: How to use servo click library in pic16f1526 microcontroller to control the servo motor using PCA9685 module

#6 Post by IvanJeremic » 15 Nov 2023 08:37

Hi,

Basically you just need to use TRIS register on the pins you are using, you can see LED blinking examples in the compiler and the datasheet of the MCU you are using for more information.

https://ww1.microchip.com/downloads/en/ ... 01458D.pdf

For I2C and LOG, look into I2C and UART libraries in the help section there are detailed explanations on how to use these libraries there.

Regards,

Ivan.

kumar123
Posts: 68
Joined: 17 Oct 2023 07:32

Re: How to use servo click library in pic16f1526 microcontroller to control the servo motor using PCA9685 module

#7 Post by kumar123 » 15 Nov 2023 13:44

Hi,
I want to use this function "servo_i2cDriverInit()" for PIC16F1526 micro-controller to configure the the pins RC3, RC4 is connected to scl, sda of PCA9685 module.
I don't know how to configure RC3, RC4 pins of micro-controller in "servo_i2cDriverInit()" function. This is the code I am trying.
cop.png
cop.png (199.21 KiB) Viewed 866 times
Regards,
Himanshu Kumar

User avatar
IvanJeremic
mikroElektronika team
Posts: 316
Joined: 05 Sep 2022 14:32

Re: How to use servo click library in pic16f1526 microcontroller to control the servo motor using PCA9685 module

#8 Post by IvanJeremic » 16 Nov 2023 08:41

Hi,

Can you send me your project so i can try it out for myself?

Regards,

Ivan.

kumar123
Posts: 68
Joined: 17 Oct 2023 07:32

Re: How to use servo click library in pic16f1526 microcontroller to control the servo motor using PCA9685 module

#9 Post by kumar123 » 16 Nov 2023 09:26

Hi,
I am sending my code which I have tried on PIC16F1526 micro-controller and PCA9685 module on mikroC pro for PIC compiler. RC3, RC4 pins of micro-controller is connected to SCL, SDA pin of PCA9685 module respectively.
I don't want to use any development board mikroBus. I only want to configure my own pins. I am attaching my code.
SMC.rar
(57.31 KiB) Downloaded 22 times
Regards,
Himanshu Kumar

kumar123
Posts: 68
Joined: 17 Oct 2023 07:32

Re: How to configure servo click library for pic16f1526 micro-controller

#10 Post by kumar123 » 18 Nov 2023 11:23

Hi,
I am not able to configure this library for pic16f1526 micro-controller. I don't want to use microbus and development board. I want to configure my one gpio pins and i2c pins.
servo_i2cDriverInit((T_SERVO_P)&_MIKROBUS1_GPIO, (T_SERVO_P)&_MIKROBUS1_I2C,0x40, 0x14 );


Regards,
Himanshu Kumar

User avatar
IvanJeremic
mikroElektronika team
Posts: 316
Joined: 05 Sep 2022 14:32

Re: How to use servo click library in pic16f1526 microcontroller to control the servo motor using PCA9685 module

#11 Post by IvanJeremic » 20 Nov 2023 08:55

Hi,

I looked at your code, i don't have the MCU that you are using to try it out, but i can tell you that you do not need all of the stuff you placed in the code, to initialize I2C you just need to use the I2C library.

Connect your SERVO click to the I2C 1 pins and in the code use the I2C1_Init, and of course enable the I2 library in the library manager.

As for the OE pin, use TRIS on the SS pin.

Regards,

Ivan.

kumar123
Posts: 68
Joined: 17 Oct 2023 07:32

Re: How to use servo click library in pic16f1526 microcontroller to control the servo motor using PCA9685 module

#12 Post by kumar123 » 20 Nov 2023 11:05

Hi,
I did whatever you told. The code is compiling and not giving any error but the problem is PCA9685 module channel is not getting any voltage or current.
code1.png
code1.png (210.34 KiB) Viewed 714 times
In the above code. I have used this function
servo_i2cDriverInit((T_SERVO_P)&_MIKROBUS1_GPIO,(T_SERVO_P)&_MIKROBUS1_I2C,0x40, 0x14 );

In this function library proved these variables _MIKROBUS1_GPIO, _MIKROBUS1_I2C, what should be the values to initialize the pins.

Regards,
Himanshu Kumar

User avatar
IvanJeremic
mikroElektronika team
Posts: 316
Joined: 05 Sep 2022 14:32

Re: How to use servo click library in pic16f1526 microcontroller to control the servo motor using PCA9685 module

#13 Post by IvanJeremic » 21 Nov 2023 15:25

Hi,

The _MIKROBUS1_GPIO is the SS pin and the _MIKROBUS1_I2C is the SDA and SCL pins of I2C.

0x40 and 0x14 are slave addresses of the two modules the click uses PCA9685 and LTC2497.

The code seems fine, are you certain that the clock scheme for your MCU is ok?

Regards,

Ivan.

kumar123
Posts: 68
Joined: 17 Oct 2023 07:32

How to use own pins instead of mikrobus1_i2c

#14 Post by kumar123 » 28 Nov 2023 08:36

Hi,
I am using this piece of code .
code3.png
code3.png (198.97 KiB) Viewed 600 times
code2.png
code2.png (210.2 KiB) Viewed 601 times
In this code they are using mikrobus_i2c for configuring i2c pins, but I don't want to use mikrobus_i2c, I want to use my pins to configure SDA, SCL pins.
They are using mikrobus_i2c from this github
https://github.com/MikroElektronika/mik ... _generic.h

I don't know how to use my own pins instead of mirkobus_i2c.

Regards,
Himanshu kumar

User avatar
IvanJeremic
mikroElektronika team
Posts: 316
Joined: 05 Sep 2022 14:32

Re: How to use servo click library in pic16f1526 microcontroller to control the servo motor using PCA9685 module

#15 Post by IvanJeremic » 29 Nov 2023 10:29

Hi,

You can change what pins are used inside the MikroBUS definition files.

You can find the definitions by selecting one of the pins and clicking Ctrl+D.
Untitled.png
Untitled.png (10.64 KiB) Viewed 575 times
Select one of the pins in this file and again click Ctrl+D.
Untitled1.png
Untitled1.png (6.91 KiB) Viewed 575 times
And here you can change the pin mapping to the ones you are using.
Untitled3.png
Untitled3.png (43.57 KiB) Viewed 575 times
Regards,

Ivan.

Post Reply

Return to “mikroC PRO for PIC General”