Comments (3)
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.
If you are interesting about I2C or SPI thread-safe, see
from esp-iot-solution.
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)
- Build Error when fetching Component Dependencies for WS2812 LED Strips example (AEGHB-553) HOT 2
- 关于usb-dongle demo 中通过USB-CDC对esp32s3无法正确输入命令 (AEGHB-571) HOT 1
- led_indicator: Different indicator LEDs on same strip (AEGHB-576) HOT 1
- usb cdc 4g module issue (AEGHB-580) HOT 2
- ESP32S2使用USB_CDC_4G_MODULE时,连接WiFi芯片重启 (AEGHB-584) HOT 5
- 用USB CDC 4G Module时,卡在了Modem state STAGE_WAIT_IP步骤 (AEGHB-586) HOT 3
- usb hid device barcode scanner can not use (AEGHB-589) HOT 1
- esp32 S3 BOX 按键触发回调函数后,怎么实现触发任务的执行 (AEGHB-592) HOT 1
- knob processing accuracy is not enough for 1-pulse-1-positioning encoder (AEGHB-600) HOT 2
- fail to build usb cdc 4g module (AEGHB-609) HOT 4
- How to change usb host cdc baudrate? (AEGHB-610) HOT 4
- About examples/bluetooth/ble_conn_mgr/ble_spp/spp_server (AEGHB-611) HOT 9
- esp-tinyuf2: hal/usb_phy_hal.h and hal/usb_phy_ll.h are renamed in esp-idf (AEGHB-615) HOT 1
- Feature Request: Support for RNDIS/ECM Connectivity in AP Mode (AEGHB-618) HOT 1
- usb cdc 4g module Auxiliary AT port (AEGHB-623) HOT 5
- I had an error running the usb\device\usb_webcam> instance and I pulled down all the code. There will still be this error, I don't know what went wrong (AEGHB-631) HOT 4
- esp-tinyuf2 + power management: crash when cpu frequency dynamic scaling is enabled (AEGHB-632) HOT 1
- 如何集成到Eclipse中去? (AEGHB-637) HOT 1
- 其他功能正常,但是在网页修改wifi账号密码的时候,会无法设置 (AEGHB-640) HOT 9
- 关于pwm舵机控制的一些问题 (AEGHB-644) HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from esp-iot-solution.