bharath.s
Published © LGPL

Android Guided Vehicle

A customizable vehicle which makes path decisions based on the commands given using an Android app for material movement in industries.

AdvancedWork in progress7 hours9,411
Android Guided Vehicle

Things used in this project

Hardware components

Kinetis Freedom Board with FlexIO
NXP Kinetis Freedom Board with FlexIO
×1
Arduino UNO
Arduino UNO
×1
wheels (generic)
any pair of wheels which will fit in the chassis and the motor
×1
Dual H-Bridge motor drivers L298
SparkFun Dual H-Bridge motor drivers L298
×1
DC motor (generic)
×1
HC-SR04 Ultrasonic Distance Measuring Sensor Module
×1
Jumper wires (generic)
Jumper wires (generic)
×20
Digital IR transceiver module
×1

Software apps and online services

MIT App Inventor 2
MIT App Inventor 2

Hand tools and fabrication machines

Hot glue gun (generic)
Hot glue gun (generic)
Soldering iron (generic)
Soldering iron (generic)
plier and screwdriver

Story

Read more

Schematics

Power Supply

Input to the freedom board is given via P5-9V_VIN pin
and the IR sensors are powered from the pin P5V_USB ( Nominal 5 V supplied to the I/O headers (J3 pin10) )

When 3.3 V power is supplied directly through the Freedom platform
compatibility header J3, please enable protection diode D7 by opening J18 shorting header.

Bluetooth

An optional header (J24) on the FRDM-K82F supports communication with an add-on Bluetooth interface over a UART.

Overall Interface

make the connections accordingly

Code

work_in_progress

C/C++
code to receive data via uart and send command to motor driver using GPIO
#include "board.h"
#include "fsl_flexio_uart_driver.h"
#include "fsl_clock_manager.h"
#include "fsl_lpuart_driver.h"
#include "fsl_debug_console.h"
// Standard C Included Files
#include <stdio.h>
// SDK Included Files
#include "board.h"
#include "gpio_pins.h"
#include "fsl_debug_console.h"


//GPIO

// Variables


volatile bool isButtonPress = false;

// Code

/*
 * Uses a switch to run a motor
 *
 * This function toogles motor when press the switch.
 */
int main(void)
{
    // Define gpio input pin config structure SW.
    gpio_input_pin_user_config_t inputPin[] = {
        {
            .pinName                       = BOARD_SW_GPIO,
            .config.isPullEnable           = true,
#if FSL_FEATURE_PORT_HAS_PULL_SELECTION
            .config.pullSelect             = kPortPullUp,
#endif
#if FSL_FEATURE_PORT_HAS_PASSIVE_FILTER
            .config.isPassiveFilterEnabled = false,
#endif
#if FSL_FEATURE_PORT_HAS_DIGITAL_FILTER
            .config.isDigitalFilterEnabled = false,
#endif
            .config.interrupt              = kPortIntFallingEdge,
        },
        {
            .pinName = GPIO_PINS_OUT_OF_RANGE,
        }
    };

    // Define gpio output pin config structure LED1.
    gpio_output_pin_user_config_t outputPin[] = {
        {
            .pinName              = kGpioM1,
            .config.outputLogic   = 0,
#if FSL_FEATURE_PORT_HAS_SLEW_RATE
            .config.slewRate      = kPortFastSlewRate,
#endif
#if FSL_FEATURE_PORT_HAS_DRIVE_STRENGTH
            .config.driveStrength = kPortHighDriveStrength,
#endif
        },
        {
            .pinName = GPIO_PINS_OUT_OF_RANGE,
        }
    };

    // Init hardware
    hardware_init();

    // Print a note to terminal.
    PRINTF("\r\n Press %s to turn on/off a motor\r\n",BOARD_SW_NAME);

    // Init motor, Switch.
    GPIO_DRV_Init(inputPin, outputPin);
    // Turn motor on.
    GPIO_DRV_ClearPinOutput(kGpioM1);

    while(1)
    {
        if(isButtonPress)
        {
            PRINTF(" %s is pressed \r\n",BOARD_SW_NAME);
            // Reset state of button.
            isButtonPress=false;
        }
    }
}

/*!
 * @brief Interrupt service fuction of switch.
 *
 * This function toogles motor
 */
void BOARD_SW_IRQ_HANDLER(void)
{
    // Clear external interrupt flag.
    GPIO_DRV_ClearPinIntFlag(BOARD_SW_GPIO);
    // Change state of button.
    isButtonPress = true;
    // Toggle motor
    GPIO_DRV_TogglePinOutput(kGpioM1);
}


//  Variables

static uint32_t s_flexioInstance;
flexio_uart_state_t uartState;
#define DATA_LENGTH         65
const uint8_t txBuff[] = "This data to transfer between FlexIO simulated UART and LPUART";
uint8_t rxBuff[DATA_LENGTH] = {0};
#if defined TWR_K80F150M || defined TWR_K81F150M || defined FRDM_K82F
#define COMM_UART_INSTANCE    0
#else
#define COMM_UART_INSTANCE    1
#endif

//  Codes


bool flexio_uart_compare(uint8_t *txBuff, uint8_t *rxBuff, uint32_t count)
{
    uint32_t i;
    /* Comapre source and sink data*/
    for (i = 0; i < count ; i++)
    {
        if (txBuff[i] != rxBuff[i])
        {
            return false;
        }
    }
    return true;
}
/*!
 * @brief reset a buffer.
 * @param source The pointer to the buffer
 * @param size of the buffer
 */
void flexio_uart_reset_buffer(uint8_t *txBuff, uint32_t count)
{
    uint32_t i;
    /* Comapre source and sink data*/
    for (i = 0; i < count ; i++)
    {
        txBuff[i] = 0;
    }
}
/*!
 * @brief Check send/receive blocking functionality
 *
 */
int main(void)
{
    lpuart_state_t lpuartStatePtr;
    s_flexioInstance = 0;
    /* Fill in FlexIO config data */
    flexio_user_config_t userConfig =
    {
        .useInt = true,
        .onDozeEnable = false,
        .onDebugEnable = true,
        .fastAccessEnable = false
    };

    // Enable clock for PORTs, setup board clock source, config pin
    hardware_init();

    // Call OSA_Init to setup LP Timer for timeout
    OSA_Init();

    FLEXIO_DRV_Init(s_flexioInstance,&userConfig);
    FLEXIO_DRV_Start(s_flexioInstance);

    /* Fill in FlexIO UART config data */
    flexio_uart_userconfig_t uartConfig;
    uartConfig.bitCounter = kFlexIOUart8BitsPerChar;
    uartConfig.baudRate = 115200;
    uartConfig.uartMode = flexioUART_TxRx;
    uartConfig.txConfig.pinIdx = 5;
    uartConfig.txConfig.shifterIdx = 0;
    uartConfig.txConfig.timerIdx = 0;
    uartConfig.rxConfig.pinIdx = 4;
    uartConfig.rxConfig.shifterIdx = 1;
    uartConfig.rxConfig.timerIdx = 1;

    // Fill in lpuart config data
    lpuart_user_config_t lpuartConfig = {
        .clockSource     = BOARD_LPUART_CLOCK_SOURCE,
        .bitCountPerChar = kLpuart8BitsPerChar,
        .parityMode      = kLpuartParityDisabled,
        .stopBitCount    = kLpuartOneStopBit,
        .baudRate        = 115200
    };

    /* init the FlexIO simulated UART module with base address and config structure*/
    FLEXIO_UART_DRV_Init(s_flexioInstance, &uartState, &uartConfig);
    // Initialize the lpuart module with instance number and config structure
    LPUART_DRV_Init(COMM_UART_INSTANCE, &lpuartStatePtr, &lpuartConfig);
    // Inform to start blocking example
    PRINTF("\r\n++++++++++++++++ FLEXIO UART Send/Receive Example Start +++++++++++++++++\r\n");
    PRINTF("\r\n1. FlexIO simulated UART send a buffer \
            \r\n2. LPUART receives data from FlexIO simulated UART.\
            \r\n3. Compare rxBuff and txBuff to see result.\
            \r\n4. LPUART send a buffer\
            \r\n5. FlexIO simulated UART receives data from LPUART.\
            \r\n6. Compare rxBuff and txBuff to see result.\r\n");
    PRINTF("\r\n============================================================\r\n");
    PRINTF("\r\nPress any key to start transfer:\r\n\r\n");
    while(true)
    {
        GETCHAR();
       // FlexIO UART sends data to LPUART

        FLEXIO_UART_DRV_SendData(&uartState, txBuff, DATA_LENGTH);
        LPUART_DRV_ReceiveDataBlocking(COMM_UART_INSTANCE, rxBuff, DATA_LENGTH, 1000U);
        if(flexio_uart_compare((uint8_t*)txBuff, rxBuff, DATA_LENGTH) != true)
        {
            PRINTF("\r\nFailure transfer from FlexIO simualted UART to LPUART");
            break;
        }
        PRINTF("Transfer from FlexIO simulated UART to LPUART successfully\r\n");

        flexio_uart_reset_buffer(rxBuff,DATA_LENGTH);
        // FlexIO UART receives data from LPUART
        LPUART_DRV_SendData(COMM_UART_INSTANCE, txBuff, DATA_LENGTH);
        FLEXIO_UART_DRV_ReceiveDataBlocking(&uartState, rxBuff, DATA_LENGTH,1000U);
        if(flexio_uart_compare((uint8_t*)txBuff, rxBuff, DATA_LENGTH) != true)
        {
            PRINTF("\r\nFailure FlexIO simulated UART receive from FlexIO LPUART");
            break;
        }
        PRINTF("FlexIO simulated UART receive from FlexIO LPUART successfully\r\n");
    }

    return 0;
}

Arduino code

C/C++
Initially for setting the delay, calibrating the IR sensors and for connecting the DC motors in right polarity I made use of Arduino since its user friendly and easier to Debug
int M1T1= 5;
int M1T2 =6;
int M2T1= 9;
int M2T2 = 10;
void setup() 
{
  Serial.begin(9600);
  pinMode(M1T1, OUTPUT);
  pinMode(M1T2, OUTPUT);
  pinMode(M2T1, OUTPUT);
  pinMode(M2T2, OUTPUT);
 
}
void loop() 
{
  int S1 = digitalRead(A0);
  int S2 = digitalRead(A1);
  int S3 = digitalRead(A2);
  int S4 = digitalRead(A3);
  int S5 = digitalRead(A4);
  

  if(S1==HIGH && S5== HIGH)
  {

    if(S2==HIGH && S3==LOW && S4==HIGH) // FRONT
    {
      analogWrite(M1T1,220);
      analogWrite(M1T2,0);
      analogWrite(M2T1,22
      );
      analogWrite(M2T2,0);
      delay(15);   }
      
      if(S2==LOW && S3==LOW && S4==LOW) // FRONT
    {
      analogWrite(M1T1,220);
      analogWrite(M1T2,0);
      analogWrite(M2T1,220);
      analogWrite(M2T2,0);
      delay(20);   }
      
      
    if(S2==LOW && S3==LOW && S4==HIGH) // Slight Left 
    {
      analogWrite(M1T1,130); 
      analogWrite(M1T2,0);
      analogWrite(M2T1,170);
      analogWrite(M2T2,0);
      delay(25);
    }
    if(S2==HIGH && S3==LOW && S4==LOW) // Slight Right
    {
      analogWrite(M1T1,170); 
      analogWrite(M1T2,0);
      analogWrite(M2T1,130); 
      analogWrite(M2T2,0);
      delay(25);
    } 

  }

  else if(S1==LOW && S5== HIGH) //Full LEFT
  {
    analogWrite(M1T1,180);
    analogWrite(M1T2,0);
    analogWrite(M2T1,0);
    analogWrite(M2T2,140);
    delay(30);
  }

  else if(S1==HIGH && S5== LOW) //Full Right
  {
    analogWrite(M1T1,0);
    analogWrite(M1T2,140);
    analogWrite(M2T1,180);
    analogWrite(M2T2,0);
    delay(30);
  }


}

App,flow,code

It contains Android-Guided-Vehicle(.aia and .apk), flow diagram of the Uart and GPIO code

Credits

bharath.s

bharath.s

2 projects • 10 followers

Comments