Hackster is hosting Hackster Holidays, Ep. 4: Livestream & Giveaway Drawing. Start streaming on Wednesday!Stream Hackster Holidays, Ep. 4 on Wednesday!
Guillermo Perez Guillen
Published © CC BY-ND

Robotic Arm Controlled with Capsense

Robotic arm tasks such as pick and place products, material handling, welding & inspection with Infineon PSoC™ 62S2 Wi-Fi BT Pioneer Kit

IntermediateFull instructions provided20 hours307
Robotic Arm Controlled with Capsense

Things used in this project

Hardware components

PSoC™ 62S2 Wi-Fi BT Pioneer Kit
Infineon PSoC™ 62S2 Wi-Fi BT Pioneer Kit
×2
evive Robotic Arm Kit [Add-on]
STEMpedia evive Robotic Arm Kit [Add-on]
×1
Grommet, Gripper
Grommet, Gripper
×1
Rechargeable Battery, 4.8 V
Rechargeable Battery, 4.8 V
×2

Software apps and online services

ModusToolbox™ Software
Infineon ModusToolbox™ Software

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Desoldering Pump, Deluxe SOLDAPULLT®
Desoldering Pump, Deluxe SOLDAPULLT®

Story

Read more

Custom parts and enclosures

BOM Cost

Bill of materials cost in excel file

Schematics

How to Solder Components Using Capsense

Schematic diagram

How to Unsolder Components Using Capsense

Schematic diagram

Code

soldering_components_using_capsense.c

C/C++
Soldering Components Using Capsense Project
Requires ModusToolbox 3.0
The Full Project you can get in the added github repository link
// AUTHOR: Guillermo Perez Guillen

/*******************************************************************************
* Header files includes
*******************************************************************************/
#include "cybsp.h"
#include "cyhal.h"
#include "led.h"
#include <stdio.h> // added
#include <math.h>

/*******************************************************************************
* Global constants
*******************************************************************************/
#define PWM_LED_FREQ_HZ    (1000000lu)  /* in Hz */
#define GET_DUTY_CYCLE(x)    (100 - x)


/******************************************************************************
 * Servo Macros - added
 *****************************************************************************/

/* PWM Frequency */
#define PWM_FREQUENCY (50u)

/* PWM Duty-cycle */
#define PWM_DUTY_CYCLE_1 (4.58f) //  30 degrees

/*******************************************************************************
* Global constants
*******************************************************************************/
led_state_t led_state_cur = LED_OFF;
cyhal_pwm_t pwm_led;
cyhal_pwm_t servo_1; // added

/*******************************************************************************
* Function Name: update_led_state
********************************************************************************
* Summary:
*  This function updates the LED state, based on the touch input.
*
* Parameter:
*  ledData: the pointer to the LED data structure
*
*******************************************************************************/
void update_led_state(led_data_t *ledData)
{
    if ((led_state_cur == LED_OFF) && (ledData->state == LED_ON))
    {
        cyhal_pwm_start(&pwm_led);
        led_state_cur = LED_ON;
        ledData->brightness = LED_MAX_BRIGHTNESS;
        //printf("brightness high!!!\r\n\n");
    }
    else if ((led_state_cur == LED_ON) && (ledData->state == LED_OFF))
    {
        cyhal_pwm_stop(&pwm_led);
        led_state_cur = LED_OFF;
        ledData->brightness = 0;
        //printf("brightness low!!!\r\n\n");
    }
    else
    {
    }

    if ((LED_ON == led_state_cur) || ((LED_OFF == led_state_cur) && (ledData->brightness > 0)))
    {
        cyhal_pwm_start(&pwm_led);
        uint32_t brightness = (ledData->brightness < LED_MIN_BRIGHTNESS) ? LED_MIN_BRIGHTNESS : ledData->brightness;

        uint32_t servo_control_gripper_1 = brightness;
        uint32_t PWM_DUTY_CYCLE_GRIPPER_1 = 0.00003 * pow(servo_control_gripper_1, 2) + 0.0472 * servo_control_gripper_1 + 3;

        /* Drive the LED with brightness */
        cyhal_pwm_set_duty_cycle(&pwm_led, GET_DUTY_CYCLE(brightness),
                                 PWM_LED_FREQ_HZ);
        cyhal_pwm_set_duty_cycle(&servo_1, PWM_DUTY_CYCLE_GRIPPER_1, PWM_FREQUENCY); // robot gripper
        cyhal_pwm_start(&servo_1); // robot gripper

        led_state_cur = LED_ON;
    }
}

/*******************************************************************************
* Function Name: initialize_led
********************************************************************************
* Summary:
*  Initializes a PWM resource for driving an LED.
*
*******************************************************************************/
cy_rslt_t initialize_led(void)
{
    cy_rslt_t rslt;

    rslt = cyhal_pwm_init(&pwm_led, CYBSP_USER_LED, NULL);
    rslt = cyhal_pwm_init(&servo_1, P7_5, NULL); // added


    if (CY_RSLT_SUCCESS == rslt)
    {
        rslt = cyhal_pwm_set_duty_cycle(&pwm_led,
                                        GET_DUTY_CYCLE(LED_MAX_BRIGHTNESS),
                                        PWM_LED_FREQ_HZ);
        if (CY_RSLT_SUCCESS == rslt)
        {
            rslt = cyhal_pwm_start(&pwm_led);
        }
    }

    if (CY_RSLT_SUCCESS == rslt)
    {
        led_state_cur = LED_ON;
    }
    return rslt;
}

unsoldering_components_using_capsense.c

C/C++
Unsoldering Components Using Capsense Project
Requires ModusToolbox 3.0
The Full Project you can get in the added github repository link
// AUTHOR: Guillermo Perez Guillen

/*******************************************************************************
* Header files includes
*******************************************************************************/
#include "cybsp.h"
#include "cyhal.h"
#include "led.h"
#include <stdio.h> // added
#include <math.h>

/*******************************************************************************
* Global constants
*******************************************************************************/
#define PWM_LED_FREQ_HZ    (1000000lu)  /* in Hz */
#define GET_DUTY_CYCLE(x)    (100 - x)

/*******************************************************************************
* Global constants
*******************************************************************************/
led_state_t led_state_cur = LED_OFF;
cyhal_pwm_t pwm_led;
cyhal_pwm_t servo_1; // robot arm
cyhal_pwm_t servo_2;
cyhal_pwm_t servo_3;
cyhal_pwm_t servo_4;
cyhal_pwm_t servo_5; // robot gripper-2

/******************************************************************************
 * Servo Macros - added
 *****************************************************************************/

/* PWM Frequency */
#define PWM_FREQUENCY (50u)

/* PWM Duty-cycle */
#define PWM_DUTY_CYCLE_1 (4.44f) //  30 degrees
#define PWM_DUTY_CYCLE_2 (8.02f) //  100 degrees
#define PWM_DUTY_CYCLE_3 (10.76f) // 150 degrees
#define PWM_DUTY_CYCLE_4 (8.02f) //  100 degrees
#define PWM_DUTY_CYCLE_5 (3.48f) //  10 degrees - robot gripper-2

/*******************************************************************************
* Function Name: update_led_state
********************************************************************************
* Summary:
*  This function updates the LED state, based on the touch input.
*
* Parameter:
*  ledData: the pointer to the LED data structure
*
*******************************************************************************/
void update_led_state(led_data_t *ledData)
{

    if ((led_state_cur == LED_OFF) && (ledData->state == LED_ON))
    {
        cyhal_pwm_start(&pwm_led);
        led_state_cur = LED_ON;
        ledData->brightness = LED_MAX_BRIGHTNESS;

        for (int i = 65; i <= 90; i++){ // servo_2 ***
        float PWM_DUTY_CYCLE_S2 = 0.00003 * pow(i, 2) + 0.0472 * i + 3;
        cyhal_pwm_set_duty_cycle(&servo_2, PWM_DUTY_CYCLE_S2, PWM_FREQUENCY);
        cyhal_pwm_start(&servo_2);
        cyhal_system_delay_ms(20);
        }
        cyhal_system_delay_ms(50);

        for (int i = 100; i >= 30; i--){ // servo_1 ***
        float PWM_DUTY_CYCLE_S1 = 0.00003 * pow(i, 2) + 0.0472 * i + 3;
        cyhal_pwm_set_duty_cycle(&servo_1, PWM_DUTY_CYCLE_S1, PWM_FREQUENCY);
        cyhal_pwm_start(&servo_1);
        cyhal_system_delay_ms(20);
        }
        cyhal_system_delay_ms(50);

        for (int i = 90; i >= 65; i--){ // servo_2 ***
        float PWM_DUTY_CYCLE_S2 = 0.00003 * pow(i, 2) + 0.0472 * i + 3;
        cyhal_pwm_set_duty_cycle(&servo_2, PWM_DUTY_CYCLE_S2, PWM_FREQUENCY);
        cyhal_pwm_start(&servo_2);
        cyhal_system_delay_ms(20);
        }
        cyhal_system_delay_ms(50);

        for (int i = 8; i <= 60; i++){ // servo_5 *** robot gripper-2 opened
        float PWM_DUTY_CYCLE_S5 = 0.00003 * pow(i, 2) + 0.0472 * i + 3;
        cyhal_pwm_set_duty_cycle(&servo_5, PWM_DUTY_CYCLE_S5, PWM_FREQUENCY);
        cyhal_pwm_start(&servo_5);
        cyhal_system_delay_ms(20);
        }
        cyhal_system_delay_ms(500);

        for (int i = 65; i <= 90; i++){ // servo_2 ***
        float PWM_DUTY_CYCLE_S2 = 0.00003 * pow(i, 2) + 0.0472 * i + 3;
        cyhal_pwm_set_duty_cycle(&servo_2, PWM_DUTY_CYCLE_S2, PWM_FREQUENCY);
        cyhal_pwm_start(&servo_2);
        cyhal_system_delay_ms(20);
        }
        cyhal_system_delay_ms(250);

        for (int i = 60; i >= 10; i--){ // servo_5 *** robot gripper-2 closesd
        float PWM_DUTY_CYCLE_S5 = 0.00003 * pow(i, 2) + 0.0472 * i + 3;
        cyhal_pwm_set_duty_cycle(&servo_5, PWM_DUTY_CYCLE_S5, PWM_FREQUENCY);
        cyhal_pwm_start(&servo_5);
        cyhal_system_delay_ms(20);
        }
        cyhal_system_delay_ms(50);

    }
    else if ((led_state_cur == LED_ON) && (ledData->state == LED_OFF))
    {
        cyhal_pwm_stop(&pwm_led);
        led_state_cur = LED_OFF;
        ledData->brightness = 0;

        for (int i = 30; i <= 165; i++){ // servo_1 ***
        float PWM_DUTY_CYCLE_S1 = 0.00003 * pow(i, 2) + 0.0472 * i + 3;
        cyhal_pwm_set_duty_cycle(&servo_1, PWM_DUTY_CYCLE_S1, PWM_FREQUENCY);
        cyhal_pwm_start(&servo_1);
        cyhal_system_delay_ms(20);
        }
        cyhal_system_delay_ms(250);

        for (int i = 10; i <= 60; i++){ // servo_5 *** robor gripper-2 opened
        float PWM_DUTY_CYCLE_S5 = 0.00003 * pow(i, 2) + 0.0472 * i + 3;
        cyhal_pwm_set_duty_cycle(&servo_5, PWM_DUTY_CYCLE_S5, PWM_FREQUENCY);
        cyhal_pwm_start(&servo_5);
        cyhal_system_delay_ms(20);
        }
        cyhal_system_delay_ms(50);

        for (int i = 90; i >= 65; i--){ // servo_2 ***
        float PWM_DUTY_CYCLE_S2 = 0.00003 * pow(i, 2) + 0.0472 * i + 3;
        cyhal_pwm_set_duty_cycle(&servo_2, PWM_DUTY_CYCLE_S2, PWM_FREQUENCY);
        cyhal_pwm_start(&servo_2);
        cyhal_system_delay_ms(20);
        }
        cyhal_system_delay_ms(500);

        for (int i = 60; i >= 8; i--){ // servo_5 *** robot gripper-2 closed
        float PWM_DUTY_CYCLE_S5 = 0.00003 * pow(i, 2) + 0.0472 * i + 3;
        cyhal_pwm_set_duty_cycle(&servo_5, PWM_DUTY_CYCLE_S5, PWM_FREQUENCY);
        cyhal_pwm_start(&servo_5);
        cyhal_system_delay_ms(20);
        }
        cyhal_system_delay_ms(250);

        for (int i = 65; i <= 90; i++){ // servo_2 ***
        float PWM_DUTY_CYCLE_S2 = 0.00003 * pow(i, 2) + 0.0472 * i + 3;
        cyhal_pwm_set_duty_cycle(&servo_2, PWM_DUTY_CYCLE_S2, PWM_FREQUENCY);
        cyhal_pwm_start(&servo_2);
        cyhal_system_delay_ms(20);
        }
        cyhal_system_delay_ms(50);

        for (int i = 165; i >= 100; i--){ // servo_1 ***
        float PWM_DUTY_CYCLE_S1 = 0.00003 * pow(i, 2) + 0.0472 * i + 3;
        cyhal_pwm_set_duty_cycle(&servo_1, PWM_DUTY_CYCLE_S1, PWM_FREQUENCY);
        cyhal_pwm_start(&servo_1);
        cyhal_system_delay_ms(20);
        }
        cyhal_system_delay_ms(250);

        for (int i = 90; i >= 65; i--){ // servo_2 ***
        float PWM_DUTY_CYCLE_S2 = 0.00003 * pow(i, 2) + 0.0472 * i + 3;
        cyhal_pwm_set_duty_cycle(&servo_2, PWM_DUTY_CYCLE_S2, PWM_FREQUENCY);
        cyhal_pwm_start(&servo_2);
        cyhal_system_delay_ms(20);
        }
        cyhal_system_delay_ms(50);
    }
    else
    {
    }

    if ((LED_ON == led_state_cur) || ((LED_OFF == led_state_cur) && (ledData->brightness > 0)))
    {
        cyhal_pwm_start(&pwm_led);
        uint32_t brightness = (ledData->brightness < LED_MIN_BRIGHTNESS) ? LED_MIN_BRIGHTNESS : ledData->brightness;

        uint32_t servo_control_gripper_2 = brightness;
        uint32_t PWM_DUTY_CYCLE_GRIPPER_2 = 0.00003 * pow(servo_control_gripper_2, 2) + 0.0472 * servo_control_gripper_2 + 3;


                /* Drive the LED with brightness */
        cyhal_pwm_set_duty_cycle(&pwm_led, GET_DUTY_CYCLE(brightness), PWM_LED_FREQ_HZ);
        cyhal_pwm_set_duty_cycle(&servo_4, PWM_DUTY_CYCLE_GRIPPER_2, PWM_FREQUENCY); // servo 4
        cyhal_pwm_start(&servo_4);

        led_state_cur = LED_ON;
    }
}

/*******************************************************************************
* Function Name: initialize_led
********************************************************************************
* Summary:
*  Initializes a PWM resource for driving an LED.
*
*******************************************************************************/
cy_rslt_t initialize_led(void)
{
    cy_rslt_t rslt;

    rslt = cyhal_pwm_init(&pwm_led, CYBSP_USER_LED, NULL);
    rslt = cyhal_pwm_init(&servo_1, P7_5, NULL); // pinout
    rslt = cyhal_pwm_init(&servo_2, P7_6, NULL);
    rslt = cyhal_pwm_init(&servo_3, P12_3, NULL);
    rslt = cyhal_pwm_init(&servo_4, P12_0, NULL);
    rslt = cyhal_pwm_init(&servo_5, P12_1, NULL);

    cyhal_pwm_set_duty_cycle(&servo_1, PWM_DUTY_CYCLE_1, PWM_FREQUENCY);
    cyhal_pwm_start(&servo_1);
    cyhal_pwm_set_duty_cycle(&servo_2, PWM_DUTY_CYCLE_2, PWM_FREQUENCY);
    cyhal_pwm_start(&servo_2);
    cyhal_pwm_set_duty_cycle(&servo_3, PWM_DUTY_CYCLE_3, PWM_FREQUENCY);
    cyhal_pwm_start(&servo_3);
    cyhal_pwm_set_duty_cycle(&servo_4, PWM_DUTY_CYCLE_4, PWM_FREQUENCY);
    cyhal_pwm_start(&servo_4);
    cyhal_pwm_set_duty_cycle(&servo_5, PWM_DUTY_CYCLE_5, PWM_FREQUENCY);
    cyhal_pwm_start(&servo_5);

    if (CY_RSLT_SUCCESS == rslt)
    {
        rslt = cyhal_pwm_set_duty_cycle(&pwm_led,
                                        GET_DUTY_CYCLE(LED_MAX_BRIGHTNESS),
                                        PWM_LED_FREQ_HZ);
        if (CY_RSLT_SUCCESS == rslt)
        {
            rslt = cyhal_pwm_start(&pwm_led);
        }
        
    }

    if (CY_RSLT_SUCCESS == rslt)
    {
        led_state_cur = LED_ON;
    }

    return rslt;
}

robotic-arm-controlled-with-capsense

github repository

Credits

Guillermo Perez Guillen

Guillermo Perez Guillen

57 projects • 63 followers
Electronics and Communications Engineer (ECE) & Renewable Energy: 14 prizes in Hackster / Hackaday Prize Finalist 2021-22-23

Comments