The sensor address/id is 0x2A and below is a code I tried writing and failed terribly at.
Any help/advice/guidance/suggestion is highly appreciated.
#include <Wire.h>
void setup() {
Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(9600); // start serial for output
}
void loop() {
Wire.requestFrom(0X2A, 6); // request 6 bytes from peripheral 0x2A
while (Wire.available()) { // peripheral may send less than requested
int c = Wire.read(); // receive a byte value (i am not sure if value is int or other)
Serial.println(c); // print the value
}
delay(500);
}
I know this should be a simple code to just read the values from the sensor (I want to observe the change in magnetic field and quantify it as any object enters the proximity radius of this system) but it is my first time using I2C and I am finding it very difficult to understand the concepts. I referred to the LDC library already but that code is throwing error.
The first thing to do is to run a I2C Scanner sketch. Does it find the 0x2A ?
If the chip cannot be found, you have to fix the I2C bus first.
The next thing is to read a ID from the chip. It has a manufacturer ID and a device ID.
Try to read those. You can use the "readRegister()" function from that library.
Then you could try to fix that library or find a other library.
Can you write what the result of a test is ? We like to know everything and all the specific details. If there is an error, you can copy the compiler output and put it in a code-field to show it to us.
more details can also be seen in the pdf which I have already attached above, if needed.
The code above doesn't show any changes in the reading and just prints 255 or 0. There is only one library re-linking it here which I could find for LDC1612, I will be truly grateful if you could help me with more.
I meant that you have to write a sketch that reads those IDs. If you can read those numbers then you know that you can communicate with chip. The function "readRegister()" from that library shows how to read two bytes from a register of the chip.
You may try the following sketch: (This program prints data bytes that are coming from the sensor.) Check Section-8.4 of data sheets if you need to configure the sensor and add necessary codes with the sketch.
#include <Wire.h>
void setup()
{
Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(9600); // start serial for output
Wire.beginTransmission(0x2A);
byte busStatus = Wire.endTransmission();
if (busStatus != 0)
{
Serial.print("Device/Sensor is not found!");
while(1); //wait for ever
}
Serial.print("Device/Sensor is found.");
}
void loop()
{
byte m = Wire.requestFrom(0x2A, 6); // request 6 bytes from peripheral 0x2A
for (int i = 0; i < m; i++)
{
byte y = Wire.read();
Serial.println(y, HEX);
}
delay(1000); //test interval
}
Thanks a lot! I finally have some values on screen. Attaching a screenshot below. Do you know why I have values like that(all "FF" or "0")? I was expecting them to be numbers that display strength of magnetic field or change of voltage or something of that type.