Dimiter Kendri
Published

ESP32 Pico D4 Coin IMU for AI gesture

An IMU coupled with an ESP32 PICO D4 BLE WiFi chipset in coin form for AI gesture recognition

IntermediateFull instructions providedOver 3 days329

Things used in this project

Hardware components

ESP32 picoD4
×1
Pocket Solder- 60/40 Rosin Core 0.031" diameter
Pocket Solder- 60/40 Rosin Core 0.031" diameter
×1

Software apps and online services

Eagle

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

ESP32 pico D4 IMU coin

ESP32 tracker schematics

Code

I2C scanner.

C/C++
Scanning I2C bus 0 for the IMU.
#include <driver/i2c.h>
#include <esp_log.h>
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include <stdio.h>
#include "sdkconfig.h"

#include "freertos/FreeRTOS.h"
#include "esp_system.h"
#include "esp_event.h"
#include "esp_event_loop.h"
#include "nvs_flash.h"
#include "driver/gpio.h"

#define SDA_PIN 21
#define SCL_PIN 22

static char tag[] = "i2cscanner";

void I2C_setup(void) 
{
	i2c_config_t conf;
	conf.mode = I2C_MODE_MASTER;
	conf.sda_io_num = SDA_PIN;
	conf.scl_io_num = SCL_PIN;
	conf.sda_pullup_en = GPIO_PULLUP_ENABLE;
	conf.scl_pullup_en = GPIO_PULLUP_ENABLE;
	conf.master.clk_speed = 100000;
	i2c_param_config(I2C_NUM_0, &conf);
	i2c_driver_install(I2C_NUM_0, I2C_MODE_MASTER, 0, 0, 0);
}


void task_i2cscanner(void *ignore) {
	ESP_LOGD(tag, ">> i2cScanner");
	int i;
	esp_err_t espRc;
	printf("     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f\n");
	printf("00:         ");
	for (i=3; i< 0x78; i++) {
		i2c_cmd_handle_t cmd = i2c_cmd_link_create();
		i2c_master_start(cmd);
		i2c_master_write_byte(cmd, (i << 1) | I2C_MASTER_WRITE, 1 /* expect ack */);
		i2c_master_stop(cmd);

		espRc = i2c_master_cmd_begin(I2C_NUM_0, cmd, 10/portTICK_PERIOD_MS);
		if (i%16 == 0) {
			printf("\n%.2x:", i);
		}
		if (espRc == 0) {
			printf(" %.2x", i);
		} else {
			printf(" --");
		}
		//ESP_LOGD(tag, "i=%d, rc=%d (0x%x)", i, espRc, espRc);
		i2c_cmd_link_delete(cmd);
	}
	printf("\n");
	vTaskDelete(NULL);
}




esp_err_t event_handler(void *ctx, system_event_t *event)
{
    return ESP_OK;
}

void app_main(void)
{
    nvs_flash_init();

	I2C_setup();
    ESP_ERROR_CHECK( esp_event_loop_init(event_handler, NULL) );
	
    gpio_set_direction(GPIO_NUM_2, GPIO_MODE_OUTPUT);
    int level = 0;
	
    while (true) {
        gpio_set_level(GPIO_NUM_2, level);
        level = !level;
        vTaskDelay(4000 / portTICK_PERIOD_MS);

		xTaskCreate(task_i2cscanner, "task_i2cscanner", 4096, NULL, 5, NULL);

		
    }
}

Credits

Dimiter Kendri

Dimiter Kendri

19 projects • 85 followers
Embedded systems developer with a focus on PCB design, FPGA and embedded C. Need a product prototype, get in touch!

Comments