General > Jobs
PAID JOB -Arduino Library wanted for GUVB-C31SM I2C sensor
(1/1)
Enea:
Hi all,
I need an Arduino library for this I2C GUVB-C31SM UV sensor and I am happy to pay for it. This is the link of the datasheet:
http://www.eoc-inc.com/genicom/GUVB-C31SM%20digital%20uv%20detector.pdf
If anyone is interested, please contact me via this forum
Best regards,
Enea
ledtester:
The Arduino I2C API is not to hard to use.
If you look on page 13 and 14 of your datasheet, you'll see that there are basically four I2C operations:
- single write operation
- burst write operation
- single read operation
- burst read operation
Here is how they translate into Arduino C code. Refer to the Register Map on page 10 for the offsets of the device's registers.
Any improvements to the code are welcome. The multiple read routine was grabbed from this forum discussion:
https://forum.arduino.cc/index.php?topic=57390.0
--- Code: ---#include <Wire.h>
// I2C address of the GenUV device:
#define DEV_ADDR 0x30
// single write - write the MODE register
Wire.beginTransmission(DEV_ADDR);
Wire.write(0x01); // selects the MODE register
Wire.write(0x31); // data to write to the MODE register
Wire.endTransmission();
// burst write - write the MODE_CTL and the next register which is SOFT_RESET
Wire.beginTransmission(DEV_ADDR);
Wire.write(0x0A); // selects the MODE_CTL register
Wire.write(0xF0); // data to write to the MODE_CTL register
Wire.write(0x56); // data to write to the SOFT_RESET register
Wire.endTransmission();
// single read - read the MODE register
int value = -1; // -1 means no value has been read
Wire.requestFrom(DEV_ADDR, 1);
while (Wire.available()) {
value = (uint8_t) Wire.receive();
break;
}
// value contains -1 if device didn't reply; contains the MODE register otherwise
// burst read - read the NVM MSB and LSB bytes
// First write 0x0C to the NVM Read Control register
Wire.beginTransmission(DEV_ADDR);
Wire.write(0x30);
Wire.write(0x0C);
Wire.endTransmission();
// Then read the NVM_MSB and NVM_LSB bytes:
// a general purpose burst read routine to read multiple bytes
uint8_t data[16];
uint16_t bytes_received;
uint16_t remaining;
remaining = 2; // request 2 bytes
bytes_received = 0;
Wire.requestFrom(DEV_ADDR, remaining);
while (Wire.available() && remaining--) {
data[bytes_received] = Wire.receive();
bytes_received++;
}
// check remaining == 0; received bytes are returned in data[]
--- End code ---
Navigation
[0] Message Index
Go to full version