I've commented out the majority of my code but still get the same behaviour - permanent high without the gpio_set_direction(), working as intended with. Copy paste of my code below.
Code: Select all
#include <inttypes.h>
#include <stdio.h>
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include <sys/time.h>
//#include <hd44780.h>
#include <pcf8574.h>
#include <string.h>
#include <esp_idf_version.h>
#include <dirent.h>
#include "driver/gpio.h"
#include "freertos/queue.h"
#include "esp_timer.h"
#include <max7219.h>
#include <math.h>
#define LOG_LOCAL_LEVEL ESP_LOG_VERBOSE
#include "esp_log.h"
#ifndef APP_CPU_NUM
#define APP_CPU_NUM PRO_CPU_NUM
#endif
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(4, 0, 0)
#define HOST HSPI_HOST
#else
#define HOST SPI2_HOST
#endif
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//GLOBAL VARIABLES START
QueueHandle_t red_handler_queue;
QueueHandle_t blue_handler_queue;
QueueHandle_t red_box_queue;
QueueHandle_t blue_box_queue;
uint8_t expander_value;
uint8_t stop_flag;
char state[5];
int queue_time_rh;
int queue_time_bh;
int queue_time_rb;
int queue_time_bb;
int start_button_status;
uint64_t race_start_time = 5000000; //set the initial value to 5 seconds, means when we check in the interrupt later compare to race_start_time it will automatically flag an early start if it hasn't been updated with an accurate value
static i2c_dev_t pcf8574_expander;
//GLOBAL VARIABLES END
Code: Select all
void pin_setup()
{
/////////////////////////////////////////////////////////////////////
//Pin definition on ESP DOIT Devkit V1 and pin config
//D1/TXD0 - Red lane Dog 1 Fault button TX2
gpio_config_t io_conf1;
io_conf1.intr_type = GPIO_INTR_DISABLE;//disable interrupt
io_conf1.mode = GPIO_MODE_INPUT;
io_conf1.pin_bit_mask = (1ULL<<1);//bit mask of the pins that you want to set,e.g. GPIO 1
io_conf1.pull_down_en = GPIO_PULLDOWN_ENABLE;//enable pull-down mode
io_conf1.pull_up_en = GPIO_PULLUP_DISABLE;//disable pull-up mode
esp_err_t error1=gpio_config(&io_conf1);//configure GPIO with the given settings
if(error1!=ESP_OK){
printf("error configuring GPIO1 \n");
}
#define BUTTON_RED_DOG1 GPIO_NUM_1
//D2 - Red lane Dog 2 Fault button RX2
gpio_config_t io_conf2;
io_conf2.intr_type = GPIO_INTR_DISABLE;//disable interrupt
io_conf2.mode = GPIO_MODE_INPUT;
io_conf2.pin_bit_mask = (1ULL<<2);//bit mask of the pins that you want to set,e.g. GPIO 1
io_conf2.pull_down_en = GPIO_PULLDOWN_ENABLE;//enable pull-down mode
io_conf2.pull_up_en = GPIO_PULLUP_DISABLE;//disable pull-up mode
esp_err_t error2=gpio_config(&io_conf2);//configure GPIO with the given settings
if(error2!=ESP_OK){
printf("error configuring GPIO2 \n");
}
#define BUTTON_RED_DOG2 GPIO_NUM_2
//D3/RXD0 - Red lane Dog 3 Fault button
gpio_config_t io_conf3;
io_conf3.intr_type = GPIO_INTR_DISABLE;//disable interrupt
io_conf3.mode = GPIO_MODE_INPUT;
io_conf3.pin_bit_mask = (1ULL<<3);//bit mask of the pins that you want to set,e.g. GPIO 1
io_conf3.pull_down_en = GPIO_PULLDOWN_ENABLE;//enable pull-down mode
io_conf3.pull_up_en = GPIO_PULLUP_DISABLE;//disable pull-up mode
esp_err_t error3=gpio_config(&io_conf3);//configure GPIO with the given settings
if(error3!=ESP_OK){
printf("error configuring GPIO3 \n");
}
#define BUTTON_RED_DOG3 GPIO_NUM_3
//D4 - Red lane Dog 4 Fault button
gpio_config_t io_conf4;
io_conf4.intr_type = GPIO_INTR_DISABLE;//disable interrupt
io_conf4.mode = GPIO_MODE_INPUT;
io_conf4.pin_bit_mask = (1ULL<<4);//bit mask of the pins that you want to set,e.g. GPIO 1
io_conf4.pull_down_en = GPIO_PULLDOWN_ENABLE;//enable pull-down mode
io_conf4.pull_up_en = GPIO_PULLUP_DISABLE;//disable pull-up mode
esp_err_t error4=gpio_config(&io_conf4);//configure GPIO with the given settings
if(error4!=ESP_OK){
printf("error configuring GPIO4 \n");
}
#define BUTTON_RED_DOG4 GPIO_NUM_4
//D5 - Amber start light 1
gpio_config_t io_conf5;
io_conf5.intr_type = GPIO_INTR_DISABLE;//disable interrupt
io_conf5.mode = GPIO_MODE_OUTPUT;
io_conf5.pin_bit_mask = (1ULL<<5);//bit mask of the pins that you want to set,e.g. GPIO 1
io_conf5.pull_down_en = GPIO_PULLDOWN_ENABLE;//enable pull-down mode
io_conf5.pull_up_en = GPIO_PULLUP_DISABLE;//disable pull-up mode
esp_err_t error5=gpio_config(&io_conf5);//configure GPIO with the given settings
if(error5!=ESP_OK){
printf("error configuring GPIO5 \n");
}
#define LIGHT_AMBER1 GPIO_NUM_5
//D12 - Amber start light 2
gpio_config_t io_conf12;
io_conf12.intr_type = GPIO_INTR_DISABLE;//disable interrupt
io_conf12.mode = GPIO_MODE_OUTPUT;
io_conf12.pin_bit_mask = (1ULL<<12);//bit mask of the pins that you want to set,e.g. GPIO 1
io_conf12.pull_down_en = GPIO_PULLDOWN_ENABLE;//enable pull-down mode
io_conf12.pull_up_en = GPIO_PULLUP_DISABLE;//disable pull-up mode
esp_err_t error12=gpio_config(&io_conf12);//configure GPIO with the given settings
if(error12!=ESP_OK){
printf("error configuring GPIO12 \n");
}
#define LIGHT_AMBER2 GPIO_NUM_12
//D13 - Amber start light 3
gpio_config_t io_conf13;
io_conf13.intr_type = GPIO_INTR_DISABLE;//disable interrupt
io_conf13.mode = GPIO_MODE_OUTPUT;
io_conf13.pin_bit_mask = (1ULL<<13);//bit mask of the pins that you want to set,e.g. GPIO 1
io_conf13.pull_down_en = GPIO_PULLDOWN_ENABLE;//enable pull-down mode
io_conf13.pull_up_en = GPIO_PULLUP_DISABLE;//disable pull-up mode
esp_err_t error13=gpio_config(&io_conf13);//configure GPIO with the given settings
if(error13!=ESP_OK){
printf("error configuring GPIO13 \n");
}
#define LIGHT_AMBER3 GPIO_NUM_13
//D14 - Green start light
gpio_config_t io_conf14;
io_conf14.intr_type = GPIO_INTR_DISABLE;//disable interrupt
io_conf14.mode = GPIO_MODE_OUTPUT;
io_conf14.pin_bit_mask = (1ULL<<14);//bit mask of the pins that you want to set,e.g. GPIO 1
io_conf14.pull_down_en = GPIO_PULLDOWN_ENABLE;//enable pull-down mode
io_conf14.pull_up_en = GPIO_PULLUP_DISABLE;//disable pull-up mode
esp_err_t error14=gpio_config(&io_conf14);//configure GPIO with the given settings
if(error14!=ESP_OK){
printf("error configuring GPIO14 \n");
}
#define LIGHT_GREENSTART GPIO_NUM_14
//D15 - CS Pin for MAX7219 interface
//D16/RXD2 - 2min timer button
gpio_config_t io_conf16;
io_conf16.intr_type = GPIO_INTR_DISABLE;//disable interrupt
io_conf16.mode = GPIO_MODE_INPUT;
io_conf16.pin_bit_mask = (1ULL<<16);//bit mask of the pins that you want to set,e.g. GPIO 1
io_conf16.pull_down_en = GPIO_PULLDOWN_ENABLE;//enable pull-down mode
io_conf16.pull_up_en = GPIO_PULLUP_DISABLE;//disable pull-up mode
esp_err_t error16=gpio_config(&io_conf16);//configure GPIO with the given settings
if(error16!=ESP_OK){
printf("error configuring GPIO16 \n");
}
#define BUTTON_2MIN GPIO_NUM_16
//D17/TXD2 - START button
gpio_config_t io_conf17;
io_conf17.intr_type = GPIO_INTR_DISABLE;//no interrupt
io_conf17.mode = GPIO_MODE_INPUT;//set as input mode
io_conf17.pin_bit_mask = (1ULL<<17);//bit mask of the pins that you want to set,e.g. GPIO 1
io_conf17.pull_down_en = GPIO_PULLDOWN_ENABLE;//enable pull-down mode
io_conf17.pull_up_en = GPIO_PULLUP_DISABLE;//disable pull-up mode
esp_err_t error17=gpio_config(&io_conf17);//configure GPIO with the given settings
if(error17!=ESP_OK){
printf("error configuring GPIO17 \n");
}
#define BUTTON_START GPIO_NUM_17
//D21 - SDA Pin
//D19 - red fault light flash
gpio_config_t io_conf19;
io_conf19.intr_type = GPIO_INTR_DISABLE;//disable interrupt
io_conf19.mode = GPIO_MODE_OUTPUT;
io_conf19.pin_bit_mask = (1ULL<<19);//bit mask of the pins that you want to set,e.g. GPIO 1
io_conf19.pull_down_en = GPIO_PULLDOWN_ENABLE;//enable pull-down mode
io_conf19.pull_up_en = GPIO_PULLUP_DISABLE;//disable pull-up mode
esp_err_t error19=gpio_config(&io_conf19);//configure GPIO with the given settings
if(error19!=ESP_OK){
printf("error configuring GPIO19 \n");
}
#define LIGHT_RED_FAULT GPIO_NUM_19
//D18 - CLK
//D22 - SDL
//D23 - DIN to MAX7219
//D25 - Blue lane Dog 3 Fault button
gpio_config_t io_conf25;
io_conf25.intr_type = GPIO_INTR_DISABLE;//disable interrupt
io_conf25.mode = GPIO_MODE_INPUT;
io_conf25.pin_bit_mask = (1ULL<<25);//bit mask of the pins that you want to set,e.g. GPIO 1
io_conf25.pull_down_en = GPIO_PULLDOWN_ENABLE;//enable pull-down mode
io_conf25.pull_up_en = GPIO_PULLUP_DISABLE;//disable pull-up mode
esp_err_t error25=gpio_config(&io_conf25);//configure GPIO with the given settings
if(error25!=ESP_OK){
printf("error configuring GPIO25 \n");
}
#define BUTTON_BLUE_DOG3 GPIO_NUM_25
//D26 - Blue lane Dog 4 Fault button
gpio_config_t io_conf26;
io_conf26.intr_type = GPIO_INTR_DISABLE;//disable interrupt
io_conf26.mode = GPIO_MODE_INPUT;
io_conf26.pin_bit_mask = (1ULL<<26);//bit mask of the pins that you want to set,e.g. GPIO 1
io_conf26.pull_down_en = GPIO_PULLDOWN_ENABLE;//enable pull-down mode
io_conf26.pull_up_en = GPIO_PULLUP_DISABLE;//disable pull-up mode
esp_err_t error26=gpio_config(&io_conf26);//configure GPIO with the given settingsw
if(error26!=ESP_OK){
printf("error configuring GPIO26 \n");
}
#define BUTTON_BLUE_DOG4 GPIO_NUM_26
//D27 - Blue lane Fault light (white flash)
gpio_config_t io_conf27;
io_conf27.intr_type = GPIO_INTR_DISABLE;//disable interrupt
io_conf27.mode = GPIO_MODE_OUTPUT;//set as output mode
io_conf27.pin_bit_mask = (1ULL<<27);//bit mask of the pins that you want to set,e.g. GPIO 1
io_conf27.pull_down_en = GPIO_PULLDOWN_ENABLE;//enable pull-dwwown mode
io_conf27.pull_up_en = GPIO_PULLUP_DISABLE;//disable pull-up mode
esp_err_t error27=gpio_config(&io_conf27);//configure GPIO with the given settings
if(error27!=ESP_OK){
printf("error configuring GPIO27 \n");
}
#define LIGHT_BLUE_FAULT GPIO_NUM_27
//D32 -Blue lane Dog 1 Fault button
gpio_config_t io_conf32;
io_conf32.intr_type = GPIO_INTR_DISABLE;//disable interrupt
io_conf32.mode = GPIO_MODE_INPUT;
io_conf32.pin_bit_mask = (1ULL<<32);//bit mask of the pins that you want to set,e.g. GPIO 1
io_conf32.pull_down_en = GPIO_PULLDOWN_ENABLE;//enable pull-down mode
io_conf32.pull_up_en = GPIO_PULLUP_DISABLE;//disable pull-up mode
esp_err_t error32=gpio_config(&io_conf32);//configure GPIO with the given settings
if(error32!=ESP_OK){
printf("error configuring GPIO32 \n");
}
#define BUTTON_BLUE_DOG1 GPIO_NUM_32
//D33 -Blue lane Dog 2 Fault button
gpio_config_t io_conf33;
io_conf33.intr_type = GPIO_INTR_DISABLE;//disable interrupt
io_conf33.mode = GPIO_MODE_INPUT;
io_conf33.pin_bit_mask = (1ULL<<33);//bit mask of the pins that you want to set,e.g. GPIO 1
io_conf33.pull_down_en = GPIO_PULLDOWN_ENABLE;//enable pull-down mode
io_conf33.pull_up_en = GPIO_PULLUP_DISABLE;//disable pull-up mode
esp_err_t error33=gpio_config(&io_conf33);//configure GPIO with the given settings
if(error33!=ESP_OK){
printf("error configuring GPIO33 \n");
}
#define BUTTON_BLUE_DOG2 GPIO_NUM_33
//D34 - Red Handler Sensor
gpio_config_t io_conf34;
io_conf34.intr_type = GPIO_INTR_NEGEDGE;//falling edge interrupt
io_conf34.mode = GPIO_MODE_INPUT;//set as output mode
io_conf34.pin_bit_mask = (1ULL<<34);//bit mask of the pins that you want to set,e.g. GPIO 1
io_conf34.pull_down_en = GPIO_PULLDOWN_DISABLE;//disable pull-down mode
io_conf34.pull_up_en = GPIO_PULLUP_ENABLE;//enable pull-up mode
esp_err_t error34=gpio_config(&io_conf34);//configure GPIO with the given settings
if(error34!=ESP_OK){
printf("error configuring GPIO34 \n");
}
#define SENSOR_RED_HANDLER GPIO_NUM_34
//D35 - Red Box Sensor
gpio_config_t io_conf35;
io_conf35.intr_type = GPIO_INTR_NEGEDGE;//falling edge interrupt
io_conf35.mode = GPIO_MODE_INPUT;//set as output mode
io_conf35.pin_bit_mask = (1ULL<<35);//bit mask of the pins that you want to set,e.g. GPIO 1
io_conf35.pull_down_en = GPIO_PULLDOWN_DISABLE;//disable pull-down mode
io_conf35.pull_up_en = GPIO_PULLUP_ENABLE;//enable pull-up mode
esp_err_t error35=gpio_config(&io_conf35);//configure GPIO with the given settings
if(error35!=ESP_OK){
printf("error configuring GPIO35 \n");
}
#define SENSOR_RED_BOX GPIO_NUM_35
//D36/VP - Blue Handler Sensor
gpio_config_t io_conf36;
io_conf36.intr_type = GPIO_INTR_NEGEDGE;//falling edge interrupt
io_conf36.mode = GPIO_MODE_INPUT;//set as output mode
io_conf36.pin_bit_mask = (1ULL<<36);//bit mask of the pins that you want to set,e.g. GPIO 1
io_conf36.pull_down_en = GPIO_PULLDOWN_DISABLE;//disable pull-down mode
io_conf36.pull_up_en = GPIO_PULLUP_ENABLE;//enable pull-up modew
esp_err_t error36=gpio_config(&io_conf36);//configure GPIO with the given settings
if(error36!=ESP_OK){
printf("error configuring GPIO36 \n");
}
#define SENSOR_BLUE_HANDLER GPIO_NUM_36
//D39/VN - Blue Box Sensor
gpio_config_t io_conf39;
io_conf39.intr_type = GPIO_INTR_NEGEDGE;//falling edge interrupt
io_conf39.mode = GPIO_MODE_INPUT;//set as output mode
io_conf39.pin_bit_mask = (1ULL<<39);//bit mask of the pins that you want to set,e.g. GPIO 1
io_conf39.pull_down_en = GPIO_PULLDOWN_DISABLE;//disable pull-down mode
io_conf39.pull_up_en = GPIO_PULLUP_ENABLE;//enable pull-up mode
esp_err_t error39=gpio_config(&io_conf39);//configure GPIO with the given settings
if(error39!=ESP_OK){
printf("error configuring GPIO39 \n");
}
#define SENSOR_BLUE_BOX GPIO_NUM_39
}
Code: Select all
void app_main()
{
printf("about to enter while loop");
while (1)
{
gpio_set_level(LIGHT_AMBER1, 1);
printf("A1 light on\n");
vTaskDelay(pdMS_TO_TICKS(3000));
gpio_set_level(LIGHT_AMBER1, 0);
printf("A1 light off\n");
vTaskDelay(pdMS_TO_TICKS(3000));
}
}