当前位置:网站首页>Use of Arduino wire Library
Use of Arduino wire Library
2022-07-02 06:14:00 【Xie Niang blue bridge】
1. Scan all IIC Slave device
// --------------------------------------
// i2c_scanner
//
// Version 1
// This program (or code that looks like it)
// can be found in many places.
// For example on the Arduino.cc forum.
// The original author is not known.
// Version 2, Juni 2012, Using Arduino 1.0.1
// Adapted to be as simple as possible by Arduino.cc user Krodal
// Version 3, Feb 26 2013
// V3 by louarnold
// Version 4, March 3, 2013, Using Arduino 1.0.3
// by Arduino.cc user Krodal.
// Changes by louarnold removed.
// Scanning addresses changed from 0...127 to 1...119,
// according to the i2c scanner by Nick Gammon
// https://www.gammon.com.au/forum/?id=10896
// Version 5, March 28, 2013
// As version 4, but address scans now to 127.
// A sensor seems to use address 120.
// Version 6, November 27, 2015.
// Added waiting for the Leonardo serial communication.
//
//
// This sketch tests the standard 7-bit addresses
// Devices with higher bit address might not be seen properly.
//
#include <Wire.h>
void setup() {
Wire.begin();
Serial.begin(9600);
while (!Serial); // Leonardo: wait for Serial Monitor
Serial.println("\nI2C Scanner");
}
void loop() {
int nDevices = 0;
Serial.println("Scanning...");
for (byte address = 1; address < 127; ++address) {
// The i2c_scanner uses the return value of
// the Wire.endTransmission to see if
// a device did acknowledge to the address.
Wire.beginTransmission(address);
byte error = Wire.endTransmission();
if (error == 0) {
Serial.print("I2C device found at address 0x");
if (address < 16) {
Serial.print("0");
}
Serial.print(address, HEX);
Serial.println(" !");
++nDevices;
} else if (error == 4) {
Serial.print("Unknown error at address 0x");
if (address < 16) {
Serial.print("0");
}
Serial.println(address, HEX);
}
}
if (nDevices == 0) {
Serial.println("No I2C devices found\n");
} else {
Serial.println("done\n");
}
delay(5000); // Wait 5 seconds for next scan
}
2. Writing data
Wire.beginTransmission(CLD_ADDR1);
Wire.write(&TAS6424_Write_data_1_4[i][0], 2);
Wire.endTransmission();3. Specifies to read data from the device register
//CLD_ADDR1 Slave device address
// Read a data ,
//reg data Slave device address
// Address bit width 1
//0 -- Do not send stop
Wire.requestFrom((uint8_t)CLD_ADDR1, 1,reg_addr,1,0);
while (Wire.available()) {
c = Wire.read(); // Accept and read a byte of data sent from the machine in the form of characters
}
Serial.println(c, HEX); // Serial port outputs this character
Wire.endTransmission();边栏推荐
- Contest3147 - game 38 of 2021 Freshmen's personal training match_ F: Polyhedral dice
- 复杂 json数据 js前台解析 详细步骤《案例:一》
- Contest3147 - game 38 of 2021 Freshmen's personal training match_ 1: Maximum palindromes
- Redis Key-Value数据库 【秒杀】
- 深入学习JVM底层(三):垃圾回收器与内存分配策略
- Redis key value database [primary]
- 格式校验js
- 深入学习JVM底层(二):HotSpot虚拟机对象
- Memcached installation
- Eco express micro engine system has supported one click deployment to cloud hosting
猜你喜欢

在uni-app中引入uView

Current situation analysis of Devops and noops

Zhuanzhuanben - LAN construction - Notes

Deep learning classification network -- vggnet

穀歌出海創業加速器報名倒計時 3 天,創業人闖關指南提前收藏!

ROS create workspace

Flutter 混合开发: 开发一个简单的快速启动框架 | 开发者说·DTalk

Ros2 --- lifecycle node summary

Google Play Academy 组队 PK 赛,正式开赛!

Data playback partner rviz+plotjuggler
随机推荐
Brain and cognitive neuroscience matlab psychoolbox cognitive science experimental design - experimental design 4
External interrupts cannot be accessed. Just delete the code and restore it Record this unexpected bug
Invalid operation: Load into table ‘sources_ orderdata‘ failed. Check ‘stl_ load_ errors‘ system table
深入了解JUC并发(二)并发理论
步骤详解 | 助您轻松提交 Google Play 数据安全表单
Database learning summary 5
Eco express micro engine system has supported one click deployment to cloud hosting
No subject alternative DNS name matching updates. jenkins. IO found, the reason for the error and how to solve it
Singleton mode compilation
Servlet web XML configuration details (3.0)
深入学习JVM底层(四):类文件结构
Classic literature reading -- deformable Detr
Support new and old imperial CMS collection and warehousing tutorials
Flutter 混合开发: 开发一个简单的快速启动框架 | 开发者说·DTalk
New version of dedecms collection and release plug-in tutorial tool
51 single chip microcomputer - ADC explanation (a/d conversion, d/a conversion)
Browser principle mind map
Sumo tutorial Hello World
Go learning notes integration
Pbootcms collection and warehousing tutorial quick collection release