当前位置:网站首页>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();
边栏推荐
- Linkage between esp8266 and stc8h8k single chip microcomputer - Weather Clock
- Go 学习笔记整合
- [C language] simple implementation of mine sweeping game
- Let every developer use machine learning technology
- 如何使用MITMPROXy
- Stc8h8k series assembly and C51 actual combat - keys allow key counting (using falling edge interrupt control)
- The difference between session and cookies
- Web components series (VIII) -- custom component style settings
- Zabbix Server trapper 命令注入漏洞 (CVE-2017-2824)
- BGP routing optimization rules and notification principles
猜你喜欢
LeetCode 78. 子集
ROS2----LifecycleNode生命周期节点总结
日期时间API详解
LeetCode 90. 子集 II
Singleton mode compilation
BGP报文详细解释
Redis key value database [primary]
Invalid operation: Load into table ‘sources_ orderdata‘ failed. Check ‘stl_ load_ errors‘ system table
Detailed explanation of BGP message
Zhuanzhuanben - LAN construction - Notes
随机推荐
Shenji Bailian 3.53-kruskal
External interrupts cannot be accessed. Just delete the code and restore it Record this unexpected bug
Sumo tutorial Hello World
Brain and cognitive neuroscience matlab psychoolbox cognitive science experimental design - experimental design 4
Reading classic literature -- Suma++
Ti millimeter wave radar learning (I)
Memcached installation
BGP报文详细解释
I/o multiplexing & event driven yyds dry inventory
ROS2----LifecycleNode生命周期节点总结
Contest3147 - game 38 of 2021 Freshmen's personal training match_ A: chicken
51 single chip microcomputer - ADC explanation (a/d conversion, d/a conversion)
Stc8h8k series assembly and C51 actual combat - digital display ADC, key serial port reply key number and ADC value
LeetCode 47. 全排列 II
线性dp(拆分篇)
Lucene Basics
Stc8h8k series assembly and C51 actual combat - serial port sending menu interface to select different functions
神机百炼3.54-染色法判定二分图
Servlet web XML configuration details (3.0)
神机百炼3.52-Prim