Use the following code to identify any slave device’s address present on the I2C bus. Luckily, Arduino offers a scanner library that simplifies the process of identifying slave addresses, eliminating the need to sift through lengthy sensor data sheets and confusing online documentation. To read values from components added to an I2C bus in such a project, it is important that you include the correct slave address when coding. These should normally sit high at whatever voltage your system is running at ie 5V or 3V3. 1,553 1 1 gold badge 12 12 silver badges 17 17 bronze badges. You can customize this code to suit whichever sensors you may have in your project, or even display the sensor values on a display module to make your own room thermometer and humidity meter. The i2c (Inter-IC Communication) Bus consists of 2 wires (hence often called Two-Wire Interface aka TWI when you want to avoid using the i2c licensed term) the Data (SDA) and Clock (SCL). write(temperature) // Send temperature data to master readTemperature() // Read temperature from DHT sensor For the I2C the Wire library from Arduino is required and for SD card the SD library is. # define DHTTYPE DHT11 // DHT sensor typeĭelay( 2000) // Wait for 2 seconds for DHT to stabilize some of those Arduino libraries are just so darn convenient. Hence, it is sometimes also known as TWI (Two Wire Interface). # define DHTPIN 4 // Pin connected to DHT sensor Wire Library Functions What is I2C I2C or I C is short for Inter-Integrated Circuit, a synchronous serial communication protocol developed by Phillips for communication between a fast Microcontroller and relatively slow peripherals (like Memory or Sensors) using just two wires. read() // Read temperature data from slaveĭelay( 2000) // Wait for 2 seconds before requesting temperature again requestFrom( 8, 1) // Request temperature data from slaveīyte temperature = Wire. The master board can then read the value we sent, then display it on the serial monitor. Let's modify the code we wrote earlier to include the temperature measurement which we will then send to the master board over the I2C bus.
0 Comments
Leave a Reply. |