Hitechnic sensors

Hey, does anybody know if it is possible to use Hitechnic sensors? And if so, how can I use them with BrickPi?

Hey blackbird, it should be. I think most of their sensors if not all of their sensors are i2c based, and that’s definitely supported with the BrickPi. It should be possible to use them, but we need someone who has them to help us write libraries.

Hey! Thanks for the quick response :).

First I searched for a datasheet but I could not find one (I have a Gyro sensor).

Then I tried to find the i2c address with i2cdetect but no luck on that either…

pi@raspberrypi ~ $ sudo i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --  

Is there another way to detect on which i2c address the sensor is?
Maybe it won’t show up on i2cdetect because it is connected to the BrickPi (Port 1) and not directly to the Pi, if that makes sense (I’m just guessing).

But when I ran General-Analog_Sensor_Test.py I did see an output and it was responding to movement. So that gave me some hope haha.

So now I’m trying to connect it with i2c but I need an address…
So do you have any tips for me or advice?

Thanks

From the website: "The Gyro Sensor connects to an NXT sensor port using a standard NXT wire and utilizes the analog sensor interface. " So you’re probably not going to see an I2C response with the Gyro.

Best advice is to download the RobotC or NXC libraries to see how they handle the data and the math. Probably the easiest way to do this is to have a look at BotBench’s 3rd party drivers for the NXT. They have the HT accelerometer in there and I think if you adapt the formatting, you can easily copy most of it over (be sure to attribute correctly!).

I’m not at home with my HW, but last week I was successful in using the HT accelerometer on sensor port 5 (HW I2C). I’m quite certain I can (time permitting) add drivers for several of the HT sensors, but it won’t be right away.

Since the HT Gyro is analog, it can be used on sensor ports 1-4, but not 5. To read it, you can set the sensor type to TYPE_SENSOR_RAW. Subtract the stationary value to get the rotation speed in degrees per second.

Hey Matt,

Thanks for the advice! I am going to give it a try.

Hey Matt, I’d like to see your code for the HT accelerometer on sensor port 5 because I haven’t been able to get it working.

You need to be sure you have the latest version of BrickPi.h, which you can get here. You can find out more about using HW I2C sensor port 5 from this post. Note however that the HW I2C sensor port 5 support is new , and likely to change (I’m contemplating making some changes to the API).

/*
*  Matthew Richardson
*  matthewrichardson37<at>gmail.com
*  http://mattallen37.wordpress.com/
*  Initial date: Nov. 22, 2013
*  Last updated: Dec. 17, 2013
*
*  You may use this code as you wish, provided you give credit where it's due.
*
*  This is a program for testing the RPi BrickPi drivers.
*/

#include "tick.h"
#include "BrickPi.h"

// Compile:
//   gcc -o program "Test BrickPi HW I2C HT Accel.c" -lrt
// Run:
//   sudo ./program

int result;

unsigned char I2C_Array_Out[1];
unsigned char I2C_Array_In[6];
int Accel_Values[3];

int main() {
  ClearTick();

  BrickPi.Address[0] = 1;
  BrickPi.Address[1] = 2;
  
  BrickPi.Timeout = 500;                       // Communication timeout (how long in ms since the last valid communication before floating the motors). 0 disables the timeout.

  result = BrickPiSetup();
  printf("BrickPiSetup: %dn", result);
  if(result)
    return 0;
 
  if(!result){
    I2C_Array_Out[0] = 0x42;
    while(1){
      result = I2C_WriteReadArray(0x02, 1, I2C_Array_Out, 6, I2C_Array_In);
      printf("I2C_WriteReadArray: %dn", result);
      if(!result){
        unsigned char i;
        for(i = 0; i < 3; i++){
          Accel_Values[i] = (I2C_Array_In[i] << 2) + (I2C_Array_In[i + 3] & 0x03);
          if(Accel_Values[i] >= 512){
            Accel_Values[i] = Accel_Values[i] - 1024;
          }
        }
        printf("X: %d   Y: %d   Z: %dn", Accel_Values[0], Accel_Values[1], Accel_Values[2]);
      }
      usleep(50000);
    }
  }
  return 0;
}

Cool! Thanks!

Hey, happy new year to all!

I am trying to run your program with your drivers, and I get this strange errors:

BrickPi.h:98:1: error: stray '240' in program
BrickPi.h:98:1: error: stray '240' in program
BrickPi.h:100:1: error: stray '240' in program
BrickPi.h:100:1: error: stray '240' in program
BrickPi.h:101:1: error: stray '240' in program
BrickPi.h:101:1: error: stray '240' in program
BrickPi.h:104:1: error: stray '240' in program
BrickPi.h:104:1: error: stray '240' in program
......
BrickPi.h:1058:1: error: stray '240' in program
BrickPi.h:13:0: error: unterminated #ifndef
Acel.c:60:1: error: expected declaration or statement at end of input