softi2c master library error

Hi there,

In Arduino 022 I am trying to compile the code below with todbot's softi2c master library (GitHub - todbot/SoftI2CMaster: Software I2C / TWI library for Arduino allows any two pins to be SDA & SCL). It is my intention to get data from a uBlox GPS receiver using softi2c with an atmega32u2 (Teensy 1.0 compatible) with DFU bootloader. Codes like blink.hex can be compiled and run easily on this atmega.

However I get the following errors (and some more) compiling the code below: "DigitalPinToPort was not declared in this scope and "PortInputRegister" was not declared in this scope.

What might be wrong here?

#include "SoftI2CMaster.h"
const byte sdaPin = 0;
const byte sclPin = 1;
SoftI2CMaster i2c = SoftI2CMaster( sdaPin,sclPin );
 
#define BUFFER_LENGTH 10//buffer size
 
int GPSAddress = 0x42;//GPS address
 
double Datatransfer(char *data_buf,char num)//transfer?char to float
 
{                                           //*data_buf?char need to be converted?num?scalar
 
  double temp=0.0;
 
  unsigned char i,j;
 
  if(data_buf[0]=='-')//negative number
 
  {
 
    i=1;
 
    //char to int and accumulation
    while(data_buf[i]!='.')
 
      temp=temp*10+(data_buf[i++]-0x30);
 
    for(j=0;j<num;j++)
 
      temp=temp*10+(data_buf[++i]-0x30);
 
    //int to float
    for(j=0;j<num;j++)
 
      temp=temp/10;
 
    //convert to negetive number
    temp=0-temp;
 
  }
 
  else//positive number
 
  {
 
    i=0;
 
    while(data_buf[i]!='.')
 
      temp=temp*10+(data_buf[i++]-0x30);
 
    for(j=0;j<num;j++)
 
      temp=temp*10+(data_buf[++i]-0x30);
 
    for(j=0;j<num;j++)
 
      temp=temp/10 ;
 
  }
 
  return temp;
 
}
 
void rec_init()//receive initialization
 
{
 
  i2c.beginTransmission(GPSAddress);
 
  i2c.send(0xff);//load address of the bytes    
 
  i2c.endTransmission();
 
  i2c.beginTransmission(GPSAddress);
 
  i2c.requestFrom(GPSAddress);//require 10 byte from GPA
 
}
 
char ID()//info ID
 
{
 
  char i = 0;
 
  char value[7]={
 
    '

,'G','P','G','G','A',','      };//the info ID

char buff[7]={

'0','0','0','0','0','0','0'      };

while(1)

{

rec_init();//receive initialize

// while(i2c.available())

// {

buff[i] = i2c.receive();//get I2C data

if(buff[i]==value[i])//compare

{

i++;

if(i==7)

{

i2c.endTransmission();//end of transmission

return 1;//if end return 1

}

}

else

i=0;

// }

i2c.endTransmission();//end of transmission

}

}

void UTC()//get time info

{

char i = 0,flag=0;

char value[7]={

'


,'G','P','G','G','A',','   };
 
  char buff[7]={
 
    '0','0','0','0','0','0','0'       };
 
  char time[9]={
 
    '0','0','0','0','0','0','0','0','0'    };//time buffer
 
  double t=0.0;
 
  while(1)
 
  {
 
    rec_init();  
 
   //  while(i2c.available()) 
 
   // {
 
      if(!flag)
 
      {
 
        buff[i] = i2c.receive();
 
        if(buff[i]==value[i])
 
        {
 
          i++;
 
          if(i==7)
 
          {
 
            i=0;
 
            flag=1;
 
          }
 
        }
 
        else
 
          i=0;
 
      }
 
      else
 
      {
 
        time[i] = i2c.receive();
 
        i++;
 
        if(i==9)
 
        {
 
          t=Datatransfer(time,2);//convert to float
 
          t=t+80000.00;//change to BeiJing time
 
          Serial.println(t);//print time
 
          i2c.endTransmission();
 
          return;
 
        }
 
      }
 
   // }
 
    i2c.endTransmission();
 
  }
 
}
 
void rec_data(char *buff,char num1,char num2)//receive data
 
{                                            //*buff?receive buffer?num1?num of comma?num2?size of buff?
 
  char i=0,count=0;
 
  if(ID())
 
  {
 
    while(1)
 
    {
 
      rec_init();  
 
     // while(i2c.available()) 
 
     // {
 
        buff[i] = i2c.receive();
 
        if(count!=num1)
 
        {
 
          if(buff[i]==',')
 
            count++;
 
        }
 
        else
 
        {
 
          i++;
 
          if(i==num2)
 
          {
 
            i2c.endTransmission();
 
            return;
 
          }
 
        }
 
    //  }
 
      i2c.endTransmission();
 
    }
 
  }
 
}
 
void latitude()//get latitude info
 
{
 
  char lat[10]={
 
    '0','0','0','0','0','0','0','0','0','0' };//latitude buffer
 
  rec_data(lat,1 ,10);//get latitude data
 
  Serial.println(Datatransfer(lat,5),5);//convert to float
 
}
 
void lat_dir()//get latitude direction info
 
{
 
  char dir[1]={'0'};//latitude direction buffer
 
  rec_data(dir,2,1);//get direction data
 
  Serial.println(dir[0],BYTE);//print the data
 
}
 
void  longitude()//get longtitude info
 
{
 
  char lon[11]={
 
    '0','0','0','0','0','0','0','0','0','0','0' };//longtitude buffer
 
  rec_data(lon,3,11);//get longitude data
 
  Serial.println(Datatransfer(lon,5),5);//convert data to float
 
}
 
void lon_dir()//get longitude direction info
 
{
 
  char dir[1]={'0'};
 
  rec_data(dir,4,1);
 
  Serial.println(dir[0],BYTE);
 
}
 
void altitude()//get altitude info
 
{
 
  char i=0,count=0;
 
  char alt[8]={
 
    '0','0','0','0','0','0','0','0' };
 
  if(ID())
 
  {
 
    while(1)
 
    {
 
      rec_init();  
 
    //  while(i2c.available()) 
 
    //  {
 
        alt[i] = i2c.receive();
 
        if(count!=8)
 
        {
 
          if(alt[i]==',')
 
            count++;
 
        }
 
        else
 
        {
 
          if(alt[i]==',')
 
          {
 
            Serial.println(Datatransfer(alt,1),1);
 
            i2c.endTransmission();
 
            return;
 
          }
 
          else
 
            i++;
 
        }
 
    //  }
 
      i2c.endTransmission();
 
    }
 
  }
 
}
 
void setup()
 
{
 
 // i2c.begin();//I2C initialize
 
  Serial.begin(9600);//set baudrate
 
  Serial.println("GOF GPS Shield v1.0");
 
  Serial.println("$GPGGA statement information: ");
 
}
 
void loop()
 
{
 
  while(1)
 
  {
 
    Serial.print("UTC:");
 
    UTC();
 
    Serial.print("Lat:");
 
    latitude();
 
    Serial.print("Dir:");
 
    lat_dir();
 
    Serial.print("Lon:");
 
    longitude();
 
    Serial.print("Dir:");
 
    lon_dir();
 
    Serial.print("Alt:");
 
    altitude();
 
    Serial.println(' ');
 
    Serial.println(' ');
 
  }
 
}

What might be wrong here?

That library may not be compatible with 0023 or earlier.

Or, upgrade to 1.0.0+. It compiles fine using 1.0.1.

Hi,

Thanks for the answer.

It compiles now for me too with Arduino 1.03. I have made a mistake by naming the folder in which Arduino resides Arduino-103. Because of this, the code could not find Arduino.h, but after changing the folder's name from Arduino-103 into plain: Arduino, it worked :slight_smile:

Thanks,
3dotter

That's strange, because mine is called Arduino-1.0.3, and it has no problem finding include files.

Plain Arduino is where I store my sketches.