Error on DFRobot sample code for sensor Gravity: I2C Waterproof SEN0562

userHead Jean Marc.CHAPUIS 2025-10-01 00:36:25 82 Views1 Replies

Hello,

Just for testing the sensor, I just copy and put the sample code delivery on the Wiki Page.

But I have a error message :

 

error: stray '\302' in program Wire.write(®, 1);

 

I don't understand where is the problem, it seam's to be in the character ®?

If I avoid this line the compilation is OK and it is possible to put the program in the card, but without registry address, the result is always 0.00 Lux.

Please can someone help me.

Regards.

 

The code is :

#include "Wire.h"
#define address 0x23                 //I2C address 0x23
void setup()
{
 Serial.begin(9600);
 Wire.begin();
}
uint8_t buf[4] = {0};
uint16_t data, data1;
float Lux;
void loop()
{
 readReg(0x10, buf, 2);              //Register address 0x10
 data = buf[0] << 8 | buf[1];
 Lux = (((float)data )/1.2);
 Serial.print("LUX:");
 Serial.print(Lux);
 Serial.print("lx");
 Serial.print("\n");
 delay(500);
}
uint8_t readReg(uint8_t reg, const void* pBuf, size_t size)
{
 if (pBuf == NULL) {
   Serial.println("pBuf ERROR!! : null pointer");
 }
 uint8_t * _pBuf = (uint8_t *)pBuf;
 Wire.beginTransmission(address);
 Wire.write(®, 1);
 if ( Wire.endTransmission() != 0) {
   return 0;
 }
 delay(20);
 Wire.requestFrom(address, (uint8_t) size);
 for (uint16_t i = 0; i < size; i++) {
   _pBuf[i] = Wire.read();
 }
 return size;
};
}
 

2025-10-01 16:12:46

Hello, after looking for other informations, I found my mistake :

The code providing on the web site is “Wire.write(®, 1);” but the good code is :  Wire.write(@reg, 1);

I think the html translate “@reg” in “®”, or something like that.

Regards.

userHeadPic Jean Marc.CHAPUIS