Gilisymo LS53L0X i2c and Arduino Due Wire
In the last post, we have seen how to connect LS with Arduino with the serial interface; here I will show you how to connect Gilisymo plugin with Arduino using the i2c interface.
For more detail about the Gilisymo plugin, please visit https://gilisymo.com/.
The LS needs only four wires for this tests, +3v3, GND, SDA and SCL, connected as follow.
Note that the LS has problem in the serigraphy, the version actually available has the SDA and SCL inverted! Check the version you have before run the demo.
The sketch starts to search the LS plugin connected. When it founds the plugin, it saves the address in a global variable and a flag is set to avoid repeating the search.
For all the further loops, the sketch read the ranging data from LS and then wait for 100 milliseconds. The visual effect in the serial monitor is that we have a new data every 100 milliseconds indefinitely.
You can find the Source code on the following link:
Setup and I2C in Arduino
Here we use two interfaces: the serial port to output the data and the i2c interface called Wire in Arduino.
The Setup() function will initiate Serial to 115200 baud.
The Wire interface is a standard 100 khz.
Here we can see the function
int getRangingdata(uint8_t slaveaddress)
Inside this function, we found:
Wire.requestFrom(slaveaddress, 2, RangingAddress, 1, true);
This function initiates the read over i2c interface requesting 2 bytes from RangingAddres (defined to 0xA8).
The first byte is the MSB of the ranging data and the second byte is the LSB.
The value of the ranging is returned with a simple formula:
result = b0*256+b1;
The Loop() is very easy.
On the first pass, with the help of the ‘for loop’, the sketch search for the LS plugin.
On the second pass, the sketch get data from LS plugin and print it.
The Serial Monitor output
The Serial Plotter output
You can use more commands to customize the LS plugin, you can find them in the LS documentation:https://gilisymo.com/content/6-documentation