Anyone ever get the Hitachi H48C working with Arduino? I've read all the docs and old posts but can't seem to get things working and Yes I looked at the parallax website as I orginally used it with the BS2, and had it working. ![]()
I am getting values and the numbers do change but not the right scale/they don't make sense.
int CS_pin = 9;
int CLK_pin = 10;
int DIO_pin = 11;
int aXÂ = 0;
int aYÂ = 1;
int aZÂ = 2;
int Vref = 3;
int counter = 0;
//byte axis = 0;
word GetValue(int axis) { // x = B11000, y = B11001, z = B11010 Vref = B11011
 word Result = 0;
 pinMode(DIO_pin,OUTPUT);
 pinMode(CLK_pin,OUTPUT);
 digitalWrite(CS_pin, LOW);
 shiftOut(DIO_pin,CLK_pin,MSBFIRST,0X18+axis);
//now get the input
 pinMode(DIO_pin,INPUT);
 //Serial.print("\n");
 Result=shiftIn(DIO_pin,CLK_pin,MSBFIRST);
 Result <<=8;
 Result |= shiftIn(DIO_pin,CLK_pin,MSBFIRST);
 //Serial.print("&&&&&&&&&&&&&&&&& RESULT=");Serial.print(Result,BIN);Serial.print(" &&&&&&&&&&&&&&\n");
 digitalWrite(CS_pin, HIGH);
 digitalWrite(CLK_pin, HIGH);
 return Result;
 }
//// SETUP
void setup() {
 Serial.begin(4800);
 pinMode(CS_pin, OUTPUT);
 pinMode(CLK_pin, OUTPUT);
 pinMode(DIO_pin, OUTPUT);
 // initialize device & reset
 digitalWrite(CS_pin,LOW);
 digitalWrite(CLK_pin,LOW);
 delayMicroseconds(1);
 digitalWrite(CS_pin, HIGH);
 digitalWrite(CLK_pin,HIGH);
}
//// LOOP
void loop() {
Â
 Serial.print("\n\n\n**************************Counter = ");
 Serial.print(counter);
 Serial.print("\n");
 Vref = GetValue(B11011);
 aX = GetValue(B11000);
 Serial.print("Xforce=");
 if(aX >= Vref) {
  Serial.print((aX-Vref)*.22);
 } else {
  Serial.print(-(Vref-aX)*.22);
 }
 Serial.print(" aX=");Serial.print(aX);
 Serial.print(" Vref=");Serial.print(Vref);Serial.print("\n");
 Serial.print("\n");
Â
 Vref = GetValue(B11011);
 aY = GetValue(B11001);
 Serial.print("Yforce=");
 if(aY >= Vref) {
  Serial.print((aY-Vref)*.22);
 } else {
  Serial.print(-(Vref-aY)*.22);
 }
 Serial.print(" aY=");Serial.print(aY);Serial.print(" Vref=");
 Serial.print(Vref);Serial.print("\n");Serial.print("\n");
Â
 Vref = GetValue(B11011);
 aZ = GetValue(B11010);
 Serial.print("Zforce=");
 if(aZ >= Vref) {
  Serial.print((aZ-Vref)*.22);
 } else {
  Serial.print(-(Vref-aZ)*.22);
 }
 Serial.print(" aZ=");Serial.print(aZ);Serial.print(" Vref=");
 Serial.print(Vref);Serial.print("\n");Serial.print("\n");
 Vref = GetValue(B11011);
 counter += 1;
 //Serial.print("\n#####################");
 delay(10); // loop every 10 times per sec.
}