Ashok R
Published © CC BY-NC-ND

Secured STEM Library with Tracking

Securing the STEM library in smart way with tracking and tech things.

BeginnerShowcase (no instructions)Over 1 day100

Things used in this project

Hardware components

Infineon PSoC™ 6 BLE Prototyping Kit
×1
Full Color OLED Display
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1

Software apps and online services

Android Studio
Android Studio
Bluetooth Application

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

Schematic

Code

main code

C/C++
/*******************************************************************************
* File Name:   main.c
*
*******************************************************************************
/*******************************************************************************
* Header Files
*******************************************************************************/
#include "cybsp.h"
#include "cy_retarget_io.h"
#include <FreeRTOS.h>
#include <task.h>
#include "queue.h"
#include "wiced_bt_stack.h"
#include "cybsp_bt_config.h"
#include "cycfg_bt_settings.h"
#include "cybt_platform_config.h"
#include "cyhal.h"
#include "bt_app.h"
#include "rgb_oled.h"
#include "servo.h"

/*******************************************************************************
* Macros
*******************************************************************************/
#define DOOR_TASK_PRIORITY             (2u)
#define DOOR_TASK_STACK_SIZE           (512u)

/*******************************************************************************
* Global Variables
*******************************************************************************/


/*******************************************************************************
* Function Prototypes
*******************************************************************************/

void handle_error(uint32_t status)
{

    if(CY_RSLT_SUCCESS != status)
    {
        CY_ASSERT(0);
    }
}

/*******************************************************************************
* Function Definitions
*******************************************************************************/

/*******************************************************************************
* Function Name: main
********************************************************************************
* Summary:
* The main function.
*   1. Initializes the board, retarget-io and led
*   2. Configures the SPI Master to send command packet to the slave
*
* Parameters:
*  void
*
* Return:
*  int
*
*******************************************************************************/
int main(void)
{
    cy_rslt_t result;
    wiced_result_t btresult = WICED_BT_SUCCESS;
    BaseType_t rtos_result;


    /* Initialize the device and board peripherals */
    result = cybsp_init();
    /* Board init failed. Stop program execution */
    handle_error(result);

    /* Initialize retarget-io for uart logs */
    result = cy_retarget_io_init(CYBSP_DEBUG_UART_TX, CYBSP_DEBUG_UART_RX,
                                  CY_RETARGET_IO_BAUDRATE);
    /* Retarget-io init failed. Stop program execution */
    handle_error(result);


    /* Enable interrupts */
    __enable_irq();


    /* \x1b[2J\x1b[;H - ANSI ESC sequence for clear screen */
    printf("\x1b[2J\x1b[;H");

    printf("Secured STEM Lib Access!\r\n");

#if 1
	/* Configure platform specific settings for the BT device */
	cybt_platform_config_init(&cybsp_bt_platform_cfg);

	/* Register call back and configuration with stack */
	btresult = wiced_bt_stack_init(bt_app_management_cb, &wiced_bt_cfg_settings);

	/* Check if stack initialization was successful */
	if( WICED_BT_SUCCESS == btresult)
	{
	   printf("Bluetooth stack initialization successful!\r\n");
	}
	else
	{
	   printf("Bluetooth stack initialization failed!\r\n");
	   CY_ASSERT(0);
	}
#endif

    /* Create Button Task for processing board events */
    rtos_result = xTaskCreate(door_task,"EPD Task", DOOR_TASK_STACK_SIZE,
                            NULL, DOOR_TASK_PRIORITY, NULL);


    /* Start the FreeRTOS scheduler */
    vTaskStartScheduler();

    /* Should never get here */
    CY_ASSERT(0) ;
}


/* [] END OF FILE */

display code

C/C++
/*
 * rgb_oled.c
 *
 *  Created on: 19-Apr-2023
 *      Author: Ashok
 */

/*******************************************************************************
* Header Files
*******************************************************************************/
#include "cyhal.h"
#include "cybsp.h"
#include "cy_retarget_io.h"
#include "rgb_oled.h"
#include "images.h"

/*******************************************************************************
* Macros
*******************************************************************************/

/* SPI baud rate in Hz */
#define SPI_FREQ_HZ                (16000000UL)
/* Delay of 1000ms between commands */
#define CMD_TO_CMD_DELAY           (1000UL)
/* SPI transfer bits per frame */
#define BITS_PER_FRAME             (9)

#define OLED_RST				  P6_2

#define OLED_RST_ON				cyhal_gpio_write(OLED_RST, CYBSP_LED_STATE_ON);
#define OLED_RST_OFF			cyhal_gpio_write(OLED_RST, CYBSP_LED_STATE_OFF);

cyhal_spi_t mSPI;

void rgb_oled_init_hw()
{
	cy_rslt_t result;

 /* Init SPI master */
	result = cyhal_spi_init(&mSPI,CYBSP_SPI_MOSI,CYBSP_SPI_MISO,CYBSP_SPI_CLK,
							CYBSP_SPI_CS,NULL,BITS_PER_FRAME,
							CYHAL_SPI_MODE_11_MSB,false);
	handle_error(result);

	 printf("SPI init done\r\n");
	/* Set the SPI baud rate */
	result = cyhal_spi_set_frequency(&mSPI, SPI_FREQ_HZ);
	handle_error(result);

	/* Initialize the user LED */
	result = cyhal_gpio_init(OLED_RST, CYHAL_GPIO_DIR_OUTPUT,
					CYHAL_GPIO_DRIVE_STRONG, 1);
	/* User LED init failed. Stop program execution */
	handle_error(result);
}


void rgb_oled_init()
{
	uint16_t i,j;

	OLED_RST_ON;
	cyhal_system_delay_ms(500);
	OLED_RST_OFF;
	cyhal_system_delay_ms(500);

	rgb_oled_write_cmd(0xFD);
	rgb_oled_write_data(0x12);

	rgb_oled_write_cmd(0xFD);
	rgb_oled_write_data(0xB1);

	rgb_oled_write_cmd(0xAE);

	rgb_oled_write_cmd(0xB3); //Clock & Frequency
	rgb_oled_write_data(0xF1); // div=1, freq= 0xf

	rgb_oled_write_cmd(0xCA);
	rgb_oled_write_data(0x7F);

	rgb_oled_write_cmd(0xA2);
	rgb_oled_write_data(0x00);

	rgb_oled_write_cmd(0xA1);
	rgb_oled_write_data(0x00);

	rgb_oled_write_cmd(0xA0);
	rgb_oled_write_data(0xA0);

	rgb_oled_write_cmd(0xB5);
	rgb_oled_write_data(0x00);

	rgb_oled_write_cmd(0xAB);
	rgb_oled_write_data(0x01);

	rgb_oled_write_cmd(0xB4);
	rgb_oled_write_data(0xA0);
	rgb_oled_write_data(0xB5);
	rgb_oled_write_data(0x55);

	rgb_oled_write_cmd(0xC1);  //Set color contrast
	rgb_oled_write_data(0x8A);
	rgb_oled_write_data(0x51);
	rgb_oled_write_data(0x8A);

	rgb_oled_write_cmd(0xC7);  // set master contrast
	rgb_oled_write_data(0x0F);

	rgb_oled_write_cmd(0xB9);

	rgb_oled_write_cmd(0xB8);

	rgb_oled_write_data(0x02);
	rgb_oled_write_data(0x03);
	rgb_oled_write_data(0x04);
	rgb_oled_write_data(0x05);
	rgb_oled_write_data(0x06);
	rgb_oled_write_data(0x07);
	rgb_oled_write_data(0x08);
	rgb_oled_write_data(0x09);
	rgb_oled_write_data(0x0a);
	rgb_oled_write_data(0x0b);
	rgb_oled_write_data(0x0c);
	rgb_oled_write_data(0x0d);
	rgb_oled_write_data(0x0e);
	rgb_oled_write_data(0x0f);
	rgb_oled_write_data(0x10);
	rgb_oled_write_data(0x11);
	rgb_oled_write_data(0x12);
	rgb_oled_write_data(0x13);
	rgb_oled_write_data(0x15);
	rgb_oled_write_data(0x17);
	rgb_oled_write_data(0x19);
	rgb_oled_write_data(0x1b);
	rgb_oled_write_data(0x1d);
	rgb_oled_write_data(0x1f);
	rgb_oled_write_data(0x21);
	rgb_oled_write_data(0x23);
	rgb_oled_write_data(0x25);
	rgb_oled_write_data(0x27);
	rgb_oled_write_data(0x2a);
	rgb_oled_write_data(0x2d);
	rgb_oled_write_data(0x30);
	rgb_oled_write_data(0x33);
	rgb_oled_write_data(0x36);
	rgb_oled_write_data(0x39);
	rgb_oled_write_data(0x3c);
	rgb_oled_write_data(0x3f);
	rgb_oled_write_data(0x42);
	rgb_oled_write_data(0x45);
	rgb_oled_write_data(0x48);
	rgb_oled_write_data(0x4c);
	rgb_oled_write_data(0x50);
	rgb_oled_write_data(0x54);
	rgb_oled_write_data(0x58);
	rgb_oled_write_data(0x5c);
	rgb_oled_write_data(0x60);
	rgb_oled_write_data(0x64);
	rgb_oled_write_data(0x68);
	rgb_oled_write_data(0x6c);
	rgb_oled_write_data(0x70);
	rgb_oled_write_data(0x74);
	rgb_oled_write_data(0x78);
	rgb_oled_write_data(0x7d);
	rgb_oled_write_data(0x82);
	rgb_oled_write_data(0x87);
	rgb_oled_write_data(0x8c);
	rgb_oled_write_data(0x91);
	rgb_oled_write_data(0x96);
	rgb_oled_write_data(0x9b);
	rgb_oled_write_data(0xa0);
	rgb_oled_write_data(0xa5);
	rgb_oled_write_data(0xaa);
	rgb_oled_write_data(0xaf);
	rgb_oled_write_data(0xb4);

	rgb_oled_write_cmd(0xB1);
	rgb_oled_write_data(0x32);

	rgb_oled_write_cmd(0xBB);
	rgb_oled_write_data(0x07);

	rgb_oled_write_cmd(0xB2);
	rgb_oled_write_data(0xA4);
	rgb_oled_write_data(0x00);
	rgb_oled_write_data(0x00);

	rgb_oled_write_cmd(0xB6);
	rgb_oled_write_data(0x01);

	rgb_oled_write_cmd(0xBE);
	rgb_oled_write_data(0x07);

	rgb_oled_write_cmd(0xA6);

	rgb_oled_write_cmd(0x15); // Set Column start & end address
	rgb_oled_write_data(0x00);
	rgb_oled_write_data(0x7F);

	rgb_oled_write_cmd(0x75); // Set Row start & end address
	rgb_oled_write_data(0x00);
	rgb_oled_write_data(0x7F);

	rgb_oled_write_cmd(0x5C);

	for(i=0;i<128;i++)
	{
		for(j=0;j<128;j++)
		{
			rgb_oled_write_data(0x00);
		}
	}

	rgb_oled_write_cmd(0xAF);  // Display ON
}


void rgb_oled_displayImage()
{
	uint32_t i;
	rgb_oled_write_cmd(0x15); // Set Column start & end address
	rgb_oled_write_data(0x00);
	rgb_oled_write_data(0x7F);

	rgb_oled_write_cmd(0x75); // Set Row start & end address
	rgb_oled_write_data(0x00);
	rgb_oled_write_data(0x7F);

	rgb_oled_write_cmd(0x5C);

	for(i=0;i<49152;i++){
		rgb_oled_write_data(gImage_rgboled_splash_128x128[i]>>2);
	}

}


void rgb_oled_displays5()
{
	uint32_t i;
	rgb_oled_write_cmd(0x15); // Set Column start & end address
	rgb_oled_write_data(0x00);
	rgb_oled_write_data(0x7F);

	rgb_oled_write_cmd(0x75); // Set Row start & end address
	rgb_oled_write_data(0x00);
	rgb_oled_write_data(0x7F);

	rgb_oled_write_cmd(0x5C);

	for(i=0;i<49152;i++){
		rgb_oled_write_data(gImage_rgboled_s5_128x128[i]>>2);
	}

}


void door_task(void *param)
{

	rgb_oled_init_hw();

  servo_init();
  
  printf("HW init Done\r\n");
  
  rgb_oled_init();
  
  printf("OLED init Done\r\n");
  
  rgb_oled_displayImage();
  
  
  printf("OLED Image Displayed\r\n");
  
  
  servo_start();


    for(;;)
    {

		cyhal_system_delay_ms(2000);
		rgb_oled_displays1();

		cyhal_system_delay_ms(2000);
		rgb_oled_displays2();


		cyhal_system_delay_ms(2000);
		rgb_oled_displays3();

		cyhal_system_delay_ms(2000);
		rgb_oled_displays4();

		cyhal_system_delay_ms(2000);
		rgb_oled_displays5();

		cyhal_system_delay_ms(2000);
	    rgb_oled_displayqr();

		cyhal_system_delay_ms(5000);

    }

}

Credits

Ashok R

Ashok R

37 projects • 102 followers
Hobbyist/Engineer/Director/Animatior

Comments