Beginners: please read this post and this post before posting to the forum.
0 Members and 1 Guest are viewing this topic.
#ifdef _GETCOMPASSB_ #ifndef _GETCOMPASSB_EXISTS_ #define _GETCOMPASSB_EXISTS_ #include <jmkernel.h> #include "I2C_Soft.h" #ifndef _COMPASS_ #define _COMPASS_ unsigned long #endif unsigned int GetCompassB(_COMPASS_ which){ struct select *information=&which; unsigned char ddr1=portarray[1][information->group1]; unsigned char ddr2=portarray[1][information->group2]; unsigned char port1=portarray[2][information->group1]; unsigned char port2=portarray[2][information->group2]; unsigned char pin1=portarray[0][information->group1]; unsigned char pin2=portarray[0][information->group2]; unsigned char bit1=information->bit1; unsigned char bit2=information->bit2; SDA_DDR=ddr2; SDA_PORT=port2; SDA_PIN=pin2; SDA_BIT=bit2; SCL_DDR=ddr1; SCL_PORT=port1; SCL_BIT=bit1; unsigned char low; unsigned char high; unsigned int angle; Soft_I2C_Start(); Soft_I2C_Write(0x76); Soft_I2C_Write(0x01); Soft_I2C_Start(); Soft_I2C_Write(0x77); high=Soft_I2C_Read(0); low=Soft_I2C_Read(1); Soft_I2C_Stop(); if(high==1) angle=256+low; else if(high==0) angle=low; else angle=9999; return angle; } #endif#endif
#include <Wire.h>#include <SoftwareSerial.h>void setup(){ Wire.begin(); // Conects I2C Serial.begin(9600);} void loop(){ char high, low; int bearing; Wire.begin(); Wire.write(0x76); Wire.write(0x01); //Wire.endTransmission(); Wire.begin(); Wire.write(0x77); high = Wire.read(); low = Wire.read(); if(high==1) { bearing=256+low; } if(high==0) { bearing=low; } Serial.println(bearing);}
re you properly pulling the I2C lines (A4/A5) up to VCC with 2.2 kOhm resistors?
Do you have an oscilloscope or logic analyzer available so you can look at the signals?
Hook the oscilloscope to the clock and data lines when using the working controller, and look at the signals. Measure timing (how fast does it run?)Then, hook the oscilloscope to the Arduino set-up to the clock and data lines, and look at the signals. Are they different? Too fast? Different voltage? Different rise/fall times?