GithubHelp home page GithubHelp logo

Comments (3)

colesnicov avatar colesnicov commented on June 8, 2024

Hello fellow. This way I use i2c on esp8266 with esp-iot:

Routine for initialize I2C bus:

 
#define OLED_IIC_NUM        I2C_NUM_0
#define OLED_IIC_SCL_NUM    4
#define OLED_IIC_SDA_NUM    5

static void i2cBusInit() {
	m_i2c_bus = new CI2CBus((i2c_port_t) OLED_IIC_NUM,
			(gpio_num_t) OLED_IIC_SCL_NUM, (gpio_num_t) OLED_IIC_SDA_NUM,
			100000);
}

Routinne for scanning I2C addresses:

void i2cScanner(i2c_port_t i2c_port) {
	uint8_t address;
	printf("     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f\r\n");
	for (int i = 0; i < 128; i += 16) {
		printf("%02x: ", i);
		for (int j = 0; j < 16; j++) {
			fflush(stdout);
			address = i + j;
			i2c_cmd_handle_t cmd = i2c_cmd_link_create();
			i2c_master_start(cmd);
			i2c_master_write_byte(cmd, (address << 1) | I2C_MASTER_WRITE,
			true);
			i2c_master_stop(cmd);
			esp_err_t ret = i2c_master_cmd_begin(i2c_port, cmd,
					(TickType_t) (50 / portTICK_RATE_MS));
			i2c_cmd_link_delete(cmd);
			if (ret == ESP_OK) {
				printf("%02x ", address);
			} else if (ret == ESP_ERR_TIMEOUT) {
				printf("UU ");
			} else {
				printf("-- ");
			}
		}
		printf("\r\n");
	}
}

And this is the mr. Task what can do it:

void task_i2c_scanner(void *ignore) {
    i2c_bus_t* i2c_bus = (i2c_bus_t*) bus;
    i2cScanner(i2c_bus->i2c_port); // Simillar to => i2cScanner(I2C_NUM_0);
    vTaskDelete(NULL);
}

And sequence to start:

 i2cBusInit() ;
vTaskCreate(&task_i2c_scanner, ...);
vTaskCreate(&task_ssd1306, ...);
vTaskCreate( ... );
...

For now, I can to use APDS-9960 and ssd1306.
BME280 so far (although successfully initialize) does not display the value but I plan to solve it. However, I had to rewrite something somewhat to make it work for ESP8266 with ESP8266_RTOS_SDK.

But now I think how best to make I2CBUS thread safe...

P.S. Sorry for my bad language.. ;)

from esp-iot-solution.

colesnicov avatar colesnicov commented on June 8, 2024

If you are interesting about I2C or SPI thread-safe, see

from esp-iot-solution.

ChristosPalisidis avatar ChristosPalisidis commented on June 8, 2024

Thank you @colesnicov for you reply.
I managed to reach the solution, being more carefull, reading the datasheets, and creating the I2C inteface with the right way, as far as the pins and the adresses concern. I used the Wire Library.

from esp-iot-solution.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.