久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 9082|回復: 9
打印 上一主題 下一主題
收起左側

arduino 多路I2C設備(MLX90614 )地址修改

[復制鏈接]
跳轉到指定樓層
#
ID:209158 發表于 2019-6-7 17:51 | 只看該作者 回帖獎勵 |正序瀏覽 |閱讀模式
紅外溫度傳感器    MLX90614
// remap_mlx90614.ino
#include "i2cmaster.h"
// New slave address, purposefully left shifted
byte NewMLXAddr = 0x39;                                //傳感器新I2C地址;傳感器1,2,3,4,5依次為0x1A,0x2A,0x3A,0x4A,0x5A
// 0x5A is the default address - uncomment this to set it back
// byte NewMLXAddr = 0x5A;
  
void setup(){
   Serial.begin(9600);
   Serial.println("Setup...");
   // Initialise the i2c bus, enable pullups and then wait
   i2c_init();
   PORTC = (1 << PORTC4) | (1 << PORTC5);
   delay(5000);
   // Read current address bytes
   ReadAddr(0);
   // Change address to new value (NewMLXAddr);
   ChangeAddr(NewMLXAddr, 0x00);
   // Read address bytes
   ReadAddr(0);
   Serial.print("> Cycle power NOW to set address to: ");
   Serial.print(NewMLXAddr, HEX);
   Serial.println(" - you have 10 seconds");
   // Cycle power to MLX during this 10 second pause
   delay(10000);
   // Read temperature using default address
   ReadTemp(0);
   // Read temperature using new address (note left bit shift for reading)
   ReadTemp(NewMLXAddr<<1);
   Serial.println("**---DONE---**");
}
void loop(){
     delay(5000);
     ReadTemp(NewMLXAddr<<1);
}
word ChangeAddr(byte NewAddr1, byte NewAddr2) {
   Serial.println("> Change address");
   // Send start condition and write bit
   i2c_start_wait(0 + I2C_WRITE);
   // Send command for device to return address
   i2c_write(0x2E);
   // Send low byte zero to erase
   i2c_write(0x00);
   // Send high byte zero to erase
   i2c_write(0x00);
   if (i2c_write(0x6F) == 0) {
     // Release bus, end transaction
     i2c_stop();
     Serial.println("> Data erased.");
   }
   else {
     // Release bus, end transaction
     i2c_stop();
     Serial.println("> Failed to erase data");
     return -1;
   }
   Serial.print("> Writing data: ");
   Serial.print(NewAddr1, HEX);
   Serial.print(", ");
   Serial.println(NewAddr2, HEX);
   for (int a = 0; a != 256; a++) {
     // Send start condition and write bit
     i2c_start_wait(0 + I2C_WRITE);
     // Send command for device to return address
     i2c_write(0x2E);
     // Send low byte zero to erase
     i2c_write(NewAddr1);
     // Send high byte zero to erase
     i2c_write(NewAddr2);
     if (i2c_write(a) == 0) {
       // Release bus, end transaction then wait 10ms
       i2c_stop();
       delay(100);
       Serial.print("> Found correct CRC: 0x");
       Serial.println(a, HEX);
       return a;
     }
   }
   // Release bus, end transaction
   i2c_stop();
   Serial.println("> Correct CRC not found");
   return -1;
}
void ReadAddr(byte Address) {
   Serial.println("> Read address");
   // Inform the user
   Serial.print("  MLX address: ");
   Serial.print(Address, HEX);
   Serial.print(", Data: ");
   // Send start condition and write bit
   i2c_start_wait(Address + I2C_WRITE);
   // Send command for device to return address
   i2c_write(0x2E);
   i2c_rep_start(Address + I2C_READ);
   // Read 1 byte and then send ack (x2)
   Serial.print(i2c_readAck(), HEX);
   Serial.print(", ");
   Serial.print(i2c_readAck(), HEX);
   Serial.print(", ");
   Serial.println(i2c_readNak(), HEX);
   i2c_stop();
}
float ReadTemp(byte Address) {
   int data_low = 0;
   int data_high = 0;
   int pec = 0;
   Serial.println("> Read temperature");
   // Inform the user
   Serial.print("  MLX address: ");
   Serial.print(Address, HEX);
   Serial.print(", ");
   i2c_start_wait(Address + I2C_WRITE);
   // Address of temp bytes
   i2c_write(0x07);
   // Read - the famous repeat start
   i2c_rep_start(Address + I2C_READ);
   // Read 1 byte and then send ack (x2)
   data_low = i2c_readAck();
   data_high = i2c_readAck();
   pec = i2c_readNak();
   i2c_stop();
   // This converts high and low bytes together and processes the temperature
   // MSB is a error bit and is ignored for temperatures
   // Zero out the data
   float temp = 0x0000;
   // This masks off the error bit of the high byte, then moves it left
   // 8 bits and adds the low byte.
   temp = (float)(((data_high & 0x007F) << 8) + data_low);
   temp = (temp * 0.02) - 273.16;
   Serial.print(temp);
   Serial.println(" C");
   return temp;
}

激光測距傳感器    ATK-VL53l0X
#include "Adafruit_VL53L0X.h"

Adafruit_VL53L0X lox=Adafruit_VL53L0X();
void setup() {
  // put your setup code here, to run once:
lox.begin(0x29);
}
void loop() {
  // put your main code here, to run repeatedly:
}

I2C地址修改.zip

5.58 KB, 下載次數: 39, 下載積分: 黑幣 -5

評分

參與人數 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎勵!

查看全部評分

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏2 分享淘帖 頂1 踩
回復

使用道具 舉報

9#
ID:1146133 發表于 2025-3-23 17:40 | 只看該作者
arduino 多路I2C設備, esp8266 可以嗎?
回復

使用道具 舉報

8#
ID:1146133 發表于 2025-3-23 17:39 | 只看該作者
arduino 多路I2C設備,esp8266 OK??
回復

使用道具 舉報

7#
ID:881733 發表于 2021-1-30 21:26 | 只看該作者
關于changeaddr那部分代碼,我看到樓主你用到了NewAddr1和2,但是沒有看到具體哪一步改動的地址那,NewAddr1時OX39,NewAddr2時ox00,是怎么修改5個設備的地址的那?還有一個HEX的變量也沒有看到在哪里引用的那?"i2cmaster.h"里面也沒有找到
回復

使用道具 舉報

6#
ID:209158 發表于 2020-3-23 19:34 | 只看該作者
碌碌無為 發表于 2020-1-14 23:11
若能任意修改I2C地址,那在設計中絕對是非常有意義的,感謝樓主分享。

這個需要對具體的設備來論,不同的IIC設備會有一個地址范圍,范圍內均可以,這方面可根據數據手冊查找
回復

使用道具 舉報

5#
ID:209158 發表于 2020-3-23 19:33 | 只看該作者
SuperCat995 發表于 2019-12-21 02:54
你好,請問可以用在其他傳感器上嘛?

這個抱歉,我不清楚   但是那個查詢IIC地址的可以,修改的那個程序如果有條件的話可以一試   
還有一個辦法就是不同的設備例如MPU6050和OLED可采用不同對的普通引腳設置為SCL、SDA,從而避免對默認地址的修改
回復

使用道具 舉報

地板
ID:209158 發表于 2020-3-23 19:30 | 只看該作者
Euler271828 發表于 2019-12-10 17:36
你好,這個i2cmaster.h的庫文件哪里可以下載呀

這個在arduinoIDE里面管理庫里面就有  搜索一下
回復

使用道具 舉報

板凳
ID:234938 發表于 2020-1-14 23:11 | 只看該作者
若能任意修改I2C地址,那在設計中絕對是非常有意義的,感謝樓主分享。
回復

使用道具 舉報

沙發
ID:669584 發表于 2019-12-21 02:54 | 只看該作者
你好,請問可以用在其他傳感器上嘛?
回復

使用道具 舉報

樓主
ID:652725 發表于 2019-12-10 17:36 | 只看該作者
你好,這個i2cmaster.h的庫文件哪里可以下載呀
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 亚洲久在线 | 国产偷录视频叫床高潮对白 | 久久精品 | 久久一及片| 日韩精品成人 | 欧美日韩久久久 | 日韩欧美在线观看视频网站 | 国产丝袜一区二区三区免费视频 | 欧美性另类 | 911影院| 国产精品99久久久久久宅男 | 欧产日产国产精品视频 | 天天操网| 久久久久1 | 男女搞网站 | 亚洲最大成人综合 | 日韩精品在线观看免费 | 欧美日韩一区在线播放 | 91精品久久久久久久久 | 91成人| 午夜一级做a爰片久久毛片 精品综合 | a级在线免费| 亚洲视频欧美视频 | 亚洲精品一区二区三区中文字幕 | 日本天天操 | 一区二区三区四区国产精品 | 国产日韩精品一区二区 | 欧美激情欧美激情在线五月 | 国产日韩在线观看一区 | 五月激情婷婷网 | 欧美亚洲一区二区三区 | 亚洲精品自在在线观看 | 国产中的精品av涩差av | 亚洲成a人片| 久色视频在线 | 欧美日韩一区二区三区视频 | 91精品久久久久久久久久 | 国产成人麻豆免费观看 | 国产精品国产a | 天天夜夜人人 | 成人高清在线视频 |