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

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 9136|回復(fù): 9
打印 上一主題 下一主題
收起左側(cè)

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

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:209158 發(fā)表于 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, 下載次數(shù): 39, 下載積分: 黑幣 -5

評分

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

查看全部評分

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

使用道具 舉報

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

使用道具 舉報

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

使用道具 舉報

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

使用道具 舉報

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

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

使用道具 舉報

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

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

使用道具 舉報

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

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

使用道具 舉報

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

使用道具 舉報

9#
ID:1146133 發(fā)表于 2025-3-23 17:39 | 只看該作者
arduino 多路I2C設(shè)備,esp8266 OK??
回復(fù)

使用道具 舉報

10#
ID:1146133 發(fā)表于 2025-3-23 17:40 | 只看該作者
arduino 多路I2C設(shè)備, esp8266 可以嗎?
回復(fù)

使用道具 舉報

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

本版積分規(guī)則

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

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表
主站蜘蛛池模板: 亚洲成人一区 | 国产午夜精品久久久 | www.日韩 | 99久久精品免费看国产免费软件 | 91久久精品国产 | 中文字幕一二三区 | 国产一区欧美一区 | 国产成人精品一区二区三区视频 | www.97国产 | 日韩中文字幕在线 | 国产精品日韩一区二区 | 午夜精品一区二区三区在线观看 | 天天综合国产 | 日韩在线视频网址 | 久久久久久久国产精品 | 欧美爱爱视频 | 2018国产大陆天天弄 | 欧美激情综合五月色丁香小说 | 高清免费在线 | 国产在线观看一区二区三区 | 午夜影院中文字幕 | 三级黄色大片网站 | 一级毛片高清 | 国产一区二区欧美 | 欧美一区不卡 | 国产免费a | 精品国模一区二区三区欧美 | 天堂资源 | 中文字幕av色| 人人做人人澡人人爽欧美 | 久久亚洲高清 | 久久久久国产一区二区三区四区 | 日韩午夜一区二区三区 | 一级欧美| 亚洲精品国产精品国自产在线 | 国产69久久精品成人看动漫 | 成人福利在线观看 | 欧美成人免费在线视频 | 国产成人一区在线 | 欧美一区二区精品 | 亚洲成人免费在线观看 |