HiTechnic Compass Sensor


#1

Should the brickpi detect it when i run i2cdetect -y 1? and other question, shouldnt the example program dCompass from Dexter industries work with HiTechnic right?


#2

Is the sensor on Port 5? If you place the sensor on Port 5, I think it should be detected by the i2cdetect command. Just to be sure: do you know if the HiTechnic compass is digital or analog? It won’t work if it’s analog, but if it’s a digital compass and uses the I2C protocol, you should be able to poll it direectly from the Raspberry Pi through Port 5.

The Dexter Industries dCompass sensor program won’t work for the HiTechnic compass. They are two completely different products, protocol wise.


#3

I want to do a simple program which show the orientation degrees, but I dont know how to do it with HiTechnic sensor. My idea was show the 0x42 bit like u can see in the code, but it only show me 66 all the time.

while(1){
  result = BrickPiUpdateValues();
    if(!result){
        printf("Results: %dn", BrickPi.SensorI2COut   [HT_COMPASS_SENSOR_I2C_PORT][HT_COMPASS_SENSOR_I2C_DEVICE][0]);

   }
   usleep(100000);
 }
 return 0;
}

#4

@neixeronyate what does your setup look like? Can you post your entire program? How you configure the sensor port is absolutely critical. BTW, BrickPi.SensorI2COut is the write buffer (data to be written to the I2C device). BrickPi.SensorI2CIn is the read buffer (data that has been read from the I2C device), which is most likely what you intended to use. 0×42 and 66 are the same thing (you’re printing the data in the output buffer).


#5

Hi everybody,

after some try and error I found out, with the help of the Hitechnic Compass product page (https://www.hitechnic.com/cgi-bin/commerce.cgi?preadd=action&key=NMC1034) that you can read the values of the compass sensor like you would do with the ultrasonic sensor from lego. The only thing you have to do is to multiply the values with 2, because the sensor is only able to return integer values from 0 to 250.

Here is a little example how to get the data from the Sensor on the BrickPi on sensor port 1 in python:


from BrickPi import *

BrickPiSetup()
BrickPi.SensorType[PORT_1] = TYPE_SENSOR_ULTRASONIC_CONT
BrickPiSetupSensors()

while True:
        result = BrickPiUpdateValues()
        if not result:
                print ( BrickPi.Sensor[PORT_1] * 2 )
        time.sleep(.01)

To configure this litthe beast is another story, which Iam currently struggle with ^^


#6

Did you get the calibration to work?

I am struggling with the same device, I have got some data back from it but can’t calibrate it at the moment.

Steve