Hi Karan!
I thought that’s the solution, but I think there is still a general problem:
The output of my code is always “I2C-Address: 0.000” but it should be “8”. What is the I2C-baudrate of the GoPiGo because i read in the firmware that it is reduced – do you think that can be the problem?
CODE OUTPUT:
pi@raspberrypi ~/wiringPi gcc Test.cpp -o test -l wiringPi
pi@raspberrypi ~/wiringPi sudo ./test
I2C-Adresse: 0.000000
Cmd:v
I2C Befehl
Address00: %b
Address01 %b
I2C Befehl
Address00: -nan
Address01 -0.000007
I tried so many different things with my code. But nothing helps:
#include <stdio.h>
#include <wiringPi.h>
#include <wiringPiI2C.h>
#define volt_cmd 118 // Read the voltage of the batteries
int main(int argc, char *argv [])
{
char a;
int test, b1, b2, ver, ver1;
int address=0x08;
test = wiringPiI2CSetup(address);
printf(“n I2C-Adresse: %f n”,test);
printf(“Cmd:”);
a=getchar();
if(a==‘v’)
{
wiringPiI2CWriteReg16(118,0,0);
printf(“n I2C Befehl”);
delay(100);
ver=wiringPiI2CReadReg16(118,0);
ver1=wiringPiI2CReadReg16(118,0);
printf(“n Address00: %f”,ver);
printf(“n Address01 %f n”,ver1);
printf(“n ********************** n”);
wiringPiI2CWriteReg8(118,0,0);
printf(“n I2C Befehl”);
delay(100);
b1=wiringPiI2CReadReg8(118,0);
b2=wiringPiI2CReadReg8(118,0);
printf(“n Address00: %f”,ver);
printf(“n Address01 %f n”,ver1);
printf(“n ********************** n”);
}
if(a=='f')
{
wiringPiI2CWriteReg16(test,20,0);
printf("n I2C Befehl");
delay(100);
ver=wiringPiI2CReadReg16(test,20);
ver1=wiringPiI2CReadReg16(test,20);
printf("n Address00: %f",ver);
printf("n Address01 %f n",ver1);
printf("n ********************** n");
wiringPiI2CWriteReg8(test,0x14,0);
printf("n I2C Befehl");
delay(100);
b1=wiringPiI2CReadReg8(test,0x14);
b2=wiringPiI2CReadReg8(test,0x14);
printf("n Address00: %f",ver);
printf("n Address01 %f n",ver1);
printf("n ********************** n");
wiringPiI2CWriteReg8(address,20,0);
printf("n I2C Befehl");
delay(100);
b1=wiringPiI2CReadReg8(address,20);
b2=wiringPiI2CReadReg8(address,20);
printf("n Address00: %f",ver);
printf("n Address01 %f n",ver1);
printf("n ********************** n");
wiringPiI2CWriteReg16(address,20,0);
printf("n I2C Befehl");
delay(100);
b1=wiringPiI2CReadReg16(address,20);
b2=wiringPiI2CReadReg16(address,20);
printf("n Address00: %f",ver);
printf("n Address01 %f n",ver1);
}
else
printf("Error");
return 0;
}
Best regards!
Gerhard