Show Posts
Pages: 1 [2] 3 4 ... 10
16  Using Arduino / Networking, Protocols, and Devices / Re: I2C read problems on: February 16, 2012, 05:51:01 pm
The master

asks for data

Code:
void Read_Data()
{
  Wire.beginTransmission(2);
  Wire.write('H');
  Wire.endTransmission();

  delay(200);

  Wire.beginTransmission(2);
  Wire.requestFrom(2,127);
  Wire.endTransmission();
  for ( int i=0; i<128; i++ ) Serial.write(Wire.read());
  Serial.println("");
}

and on the slave

Code:
 Wire.begin(I2C_Address);  
  Wire.onRequest(requestEvent);
  Wire.onReceive(ReceiveCommand);

Code:
void ReceiveCommand(int howMany)
{
  command = Wire.read();
}

Code:
void loop()
{
  if (command == 'H')
  {
    Capture_OS4000();
    command = 'N';
  }
}

Code:
void  Capture_OS4000()
{
  //Serial.println("mpika capture"); // debug
  //Serial.flush();
  while ( Serial.read () != '$' );
  //Serial.flush();
  while( Serial.available() < 127 );
  OS4000Data[0] = '$';
  for(Position=1; Position<128; Position++){
    buf = Serial.read();
    if ( buf == '*' ) EOL = Position + 2;
    if ( Position <= EOL ) OS4000Data[Position] = buf;
    else OS4000Data[Position] = B0;
  }
}

Code:
void requestEvent()
{
  //Wire.write (OS4000Data, 127);
   Wire.write ("AbcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789000987654321");
}

but i am receiving

AbcdefghijklmnopqrstuvwxyzABCDEFÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ

thanks

17  Using Arduino / Networking, Protocols, and Devices / Re: I2C read problems on: February 16, 2012, 04:00:34 pm
wire.h and twi.h into the library folder
18  Using Arduino / Networking, Protocols, and Devices / Re: Serial.available() buffer reduced ?? on: February 16, 2012, 01:23:05 pm
thanks a lot it worked
19  Using Arduino / Networking, Protocols, and Devices / Re: I2C read problems on: February 16, 2012, 01:17:51 pm
hallo again
i also tried to change the values in anrduino 1.0

but it didn't worked

???
20  Using Arduino / Networking, Protocols, and Devices / Serial.available() buffer reduced ?? on: February 16, 2012, 12:58:24 pm
i was using in arduino 022

while( Serial.available() < 127 );

but now the programm stalls at this point

but if i use

while( Serial.available() < 63 );

it continiues normanly

can we make it work again with 127???


thanks a lot
21  Using Arduino / Networking, Protocols, and Devices / Re: I2C read problems on: July 30, 2011, 05:29:49 am
thanks it worked

for some reason the buffer size into the wire.h was 32 and not 128
22  Using Arduino / Networking, Protocols, and Devices / Re: I2C read problems on: July 29, 2011, 06:26:16 pm
Code:
#include <Wire.h>

#define I2C_Address 2
#define UartBaudRate 57600

int Position;

byte OS4000Data [128];

char command;

void setup()
{
  Serial.begin(UartBaudRate);  
  Wire.begin(I2C_Address);  
  Wire.onRequest(requestEvent);
  Wire.onReceive(ReceiveCommand);
}

void loop()
{
  if(command == 'C')
  {
    Capture_OS4000();
    command = 'N';
  }
}


void ReceiveCommand(int howMany)
{
  while(!Wire.available());
  command = Wire.receive();
}

void requestEvent()
{
    Wire.send ("kffkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkdd");
    //Wire.send (OS4000Data, 127);
}

void  Capture_OS4000()
{
  Serial.flush();
  while ( Serial.read () != '$' );
  Serial.flush();
  while( Serial.available() < 127 );
  OS4000Data[Position] = Serial.read();
}

Code:
#include <Wire.h>
#define requestdelay 25


void setup(){
  Wire.begin();
  Serial.begin(9600);
}

void loop(){

  Wire.beginTransmission(2);
  Wire.send('C');
  Wire.endTransmission();
delay(200);

Wire.beginTransmission(2);
  
  Wire.requestFrom(2,40);
  for ( int i=0; i<40; i++ ) Serial.print(Wire.receive());
  Serial.println();
}

not working with the above code

i am reading kffkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
and not         kffkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkdd
23  Using Arduino / Networking, Protocols, and Devices / Re: I2C read problems on: July 29, 2011, 05:12:27 pm
it gives me an error if i used your code in the compliler

is it gone work if i change the


#define BUFFER_LENGTH 32

from the wire.h?

and the TWI_BUFFER_LENGTH 32

from twi.h

?
24  Using Arduino / Networking, Protocols, and Devices / Re: I2C read problems on: July 29, 2011, 01:15:13 am
can we increse it?

i want to capture 128 bytes from serial and then send them throught the i2c

but Wire.send (OS4000Data1, i);

but if the i>32 then does not work

thanks
25  Using Arduino / Networking, Protocols, and Devices / Re: I2C read problems on: July 28, 2011, 09:12:53 am
Quote
Wire.send (OS4000Data1, 32);

why anything bigger than 32 does not work?

*the OS4000Data1 is a byte array
26  Using Arduino / Networking, Protocols, and Devices / Re: I2C read problems on: June 20, 2011, 04:22:11 am
this seems to work

Code:
Wire.beginTransmission(2);
  Wire.send('P');
  Wire.endTransmission();
  delay(requestdelay);
  Wire.requestFrom(2,2);
  if ( Wire.available() > 1 )
  {
    pitchMSB = Wire.receive();
    pitchLSB = Wire.receive();
    pitch = ( ( pitchMSB<<8 ) | ( pitchLSB ) );
    Serial.print("P: ");
    Serial.print(pitch);
    Serial.print("  ");
  }

with requestdelay at 25ms

thanks a lot for you replies

--------------------------------------------------------------

i am not sure how to use atof and atoi

this is my uart input:

Quote
$OHPR,346.2,1.0,1.8,30.6,0.0000,168.01,-163.19,-39.50,-5.94,1.011,0.019,0.033,1.010,0.00,-0.01,-0.01,48145S0*59

$OHPR,346.2,1.0,1.8,30.6,0.0000,168.00,-163.18,-39.50,-5.95,1.011,0.018,0.033,1.010,0.00,-0.01,-0.01,48146S0*5A

$OHPR,346.2,1.0,1.8,30.6,0.0000,168.02,-163.20,-39.50,-5.98,1.011,0.019,0.033,1.010,0.00,-0.01,-0.01,48147S0*5E

$OHPR,heading,pitch,roll,temp,depth, ..... .......,gyroX*
27  Using Arduino / Networking, Protocols, and Devices / Re: I2C read problems on: June 19, 2011, 06:29:27 pm
first if all thanks for you replies

the second code is just to test the first code

the i2c readout it will be done by an FPGA

--------

thats why i dont have the

Quote
#define SLAVE_ADDRESS 2

as i have on the first one

Quote
#define I2C_Address 2

and everything is on a loop


------------------------------

Now 200ms i think its enought
it is working and on 100ms

I also have tested at 500ms and i have the same issues

when you send the C "Capture-Convert" command

1- the programm listens the Uart and seeking for the '$'
2- after he finds it - fills in the Uart buffer
3-  resets to 0 the heading
4- updates the heading
5- resets to  0 the pitch
6 - udates the pitch
7- resets to  0 the roll
8 - udates the roll
9- resets to  0 the temp
10 - udates the temp

then if you just send again the C command it will do the same
or if you send another command it has to reply back with some data

i might have to use that

Code:
Wire.endTransmission();
  delay(requestdelay);
  Wire.requestFrom(2,2);

as you suggest me

because the programm might not have the time to do that :

Code:
void ReceiveCommand(int howMany)
{
  while(!Wire.available());
  command = Wire.receive();
}

tanks again


the reader does not receive the two bytes ( thats why it freezes with while command ) and it is not receiving two zero bytes

28  Using Arduino / Networking, Protocols, and Devices / Re: I2C read problems on: June 19, 2011, 04:47:16 am

Code:
#include <Wire.h>
#define requestdelay 10

int heading;
byte headingMSB;
byte headingLSB;

int pitch;
byte pitchMSB;
byte pitchLSB;

int roll;
byte rollMSB;
byte rollLSB;

int temp;
byte tempMSB;
byte tempLSB;

void setup(){
  Wire.begin();
  Serial.begin(9600);
}

void loop(){

  Wire.beginTransmission(2);
  Wire.send('C');
  Wire.endTransmission();
  delay(200);

  Wire.beginTransmission(2);
  Wire.send('H');
  Wire.endTransmission();
  Wire.requestFrom(2,2);
  delay(requestdelay);
  if ( Wire.available() > 1 )
  {
    headingMSB = Wire.receive();
    headingLSB = Wire.receive();
    heading = ( ( headingMSB<<8 ) | ( headingLSB ) );
    Serial.print("H: ");
    Serial.print(heading);
    Serial.print("  ");
  }

  Wire.beginTransmission(2);
  Wire.send('P');
  Wire.endTransmission();
  Wire.requestFrom(2,2);
  delay(requestdelay);
  if ( Wire.available() > 1 )
  {
    pitchMSB = Wire.receive();
    pitchLSB = Wire.receive();
    pitch = ( ( pitchMSB<<8 ) | ( pitchLSB ) );
    Serial.print("P: ");
    Serial.print(pitch);
    Serial.print("  ");
  }

  Wire.beginTransmission(2);
  Wire.send('R');
  Wire.endTransmission();
  Wire.requestFrom(2,2);
  delay(requestdelay);
  if ( Wire.available() > 1 )
  {
    rollMSB = Wire.receive();
    rollLSB = Wire.receive();
    roll = ( ( rollMSB<<8 ) | ( rollLSB ) );
    Serial.print("R: ");
    Serial.print(roll);
    Serial.print("  ");
  }

  Wire.beginTransmission(2);
  Wire.send('T');
  Wire.endTransmission();
  Wire.requestFrom(2,2);
  delay(requestdelay);
  if ( Wire.available() > 1 )
  {
    tempMSB = Wire.receive();
    tempLSB = Wire.receive();
    temp = ( ( tempMSB<<8 ) | ( tempLSB ) );
    Serial.print("T: ");
    Serial.print(temp);
    Serial.print("  ");
  }

  Serial.println();
}


My output:

Quote
H: 3478  P: 17  R: 17  T: 305
H: 3478  P: 17  R: 17  T: 304
H: 3478  P: 17  R: 17  T: 303
H: 3478  P: 17  R: 17  T: 303
H: 3478  P: 17  R: 17  T: 305
H: 3478  P: 17  R: 17  T: 306
H: 3478  P: 17  R: 17  T: 307
H: 3478  P: 17  R: 17  T: 307
H: 3478  P: 17  R: 17  T: 306
H: 0 P: 17  R: 17  T: 304
H: 3478  P: 17  R: 17  T: 304
H: 3478  P: 17  R: 17  T: 303
H: 3478  P: 17  R: 17  T: 303
H: 3478  P: 17  R: 17  T: 305
H: 3478  P: 17  R: 17  T: 306
H: 3478  P: 17  R: 17  T: 307
H: 3478  P: 17  R: 17  T: 308
H: 3478  P: 17  R: 17  T: 308
H: 3478  P: 17  R: 17  T: 308
H: 3478 P: 0  R: 17  T: 309
H: 3478  P: 17  R: 17  T: 309
H: 3478  P: 17  R: 17  T: 309
H: 3478  P: 17  R: 17  T: 309
H: 3478  P: 17  R: 17  T: 308
H: 3478  P: 17  R: 17  T: 308
H: 3478  P: 17  R: 17  T: 308
H: 3478  P: 17  R: 17  T: 308
H: 3478  P: 17  R: 17  T: 306
H: 3478  P: 17  R: 17  T: 305 

it is not periodic
and not always on the same output (heading,pitch,roll,temp)

its 0 because the receiver never gets two bytes

*this is checked becase if i use
Code:
while ( Wire.available() < 2 ){}

it frezzes

thanks a lot
29  Using Arduino / Networking, Protocols, and Devices / Re: I2C read problems on: June 19, 2011, 04:43:09 am
Code:
#include <Wire.h>

#define I2C_Address 2
#define UartBaudRate 57600

int Position;
int NextData;

boolean SentenceState = false;
char OS4000Data[128];

char command;

int Heading;
int Heading100;
int Heading10;
int Heading1;
int Heading01;

int Pitch;
int Pitch100;
int Pitch10;
int Pitch1;
int Pitch01;

int Roll;
int Roll100;
int Roll10;
int Roll1;
int Roll01;

int Temp;
int Temp100;
int Temp10;
int Temp1;
int Temp01;

int Depth;

int MagneticVector;

int MagneticX;

int MagneticY;

int MagneticZ;

int AccelarationVector;

int AccelarationX;

int AccelarationY;

int AccelarationZ;

int GyroX;

int GyroY;

void setup()
{
  Serial.begin(UartBaudRate);  
  Wire.begin(I2C_Address);  
  Wire.onRequest(requestEvent);
  Wire.onReceive(ReceiveCommand);
}

void loop()
{
  if(command == 'C')
  {
    Capture_OS4000();
    Check_Sentence();
    if ( SentenceState == true ) Extract_Info();
    command = 'N';
  }
}


void ReceiveCommand(int howMany)
{
  while(!Wire.available());
  command = Wire.receive();
}

void requestEvent()
{
  switch (command)
  {
  case 'A':
    WireSendAll();
    break;
  case 'H':
    WireSendInt(Heading);
    break;
  case 'P':
    WireSendInt(Pitch);
    break;
  case 'R':
    WireSendInt(Roll);
    break;
  case 'T':
    WireSendInt(Temp);
    break;
  case 'D':
    WireSendInt(Depth);
    break;
  case 'M':
    WireSendInt(MagneticVector);
    break;
  case 'X':
    WireSendInt(MagneticX);
    break;
  case 'Y':
    WireSendInt(MagneticY);
    break;
  case 'Z':
    WireSendInt(MagneticZ);
    break;
  case 'a':
    WireSendInt(AccelarationVector);
    break;
  case 'x':
    WireSendInt(AccelarationX);
    break;
  case 'y':
    WireSendInt(AccelarationY);
    break;
  case 'z':
    WireSendInt(AccelarationZ);
    break;
  case 'G':
    WireSendInt(GyroX);
    break;
  case 'g':
    WireSendInt(GyroY);
    break;
  default:  
    break;
  }
  command = 'N';
}

void  Capture_OS4000()
{
  Serial.flush();
  while ( Serial.read () != '$' );
  Serial.flush();
  while( Serial.available() < 127 );
  for ( Position = 0; Position < 126; Position++ ){
    OS4000Data[Position] = char( Serial.read());
  }
}

void Check_Sentence()
{
  if ( ( OS4000Data[0] == 'O' ) && ( OS4000Data[1] == 'H' ) && ( OS4000Data[2] == 'P' ) && ( OS4000Data[3] == 'R' ) && ( OS4000Data[4] == ',' ) )SentenceState = true;
  else SentenceState = false;
}

void Extract_Info()
{
  Heading100 = 0;
  Heading10 = 0;
  Heading1 = 0;
  Heading01 = 0;
  if ( OS4000Data[8] == '.' ){
    Heading100 = OS4000Data[5] - '0';
    Heading10 = OS4000Data[6] - '0';
    Heading1 = OS4000Data[7] - '0';
    Heading01 = OS4000Data[9] - '0';
    NextData = 10;
  }
  else if ( OS4000Data[7] == '.' ){
    Heading10 = OS4000Data[5] - '0';
    Heading1 = OS4000Data[6] - '0';
    Heading01 = OS4000Data[8] - '0';
    NextData = 9;
  }
  else if ( OS4000Data[6] == '.' ){
    Heading1 = OS4000Data[5] - '0';
    Heading01 = OS4000Data[7] - '0';
    NextData = 8;
  }
  Heading = 1000*Heading100 + 100*Heading10 + 10*Heading1 + Heading01;

  Pitch100 = 0;
  Pitch10 = 0;
  Pitch1 = 0;
  Pitch01 = 0;
  if ( OS4000Data[NextData+1] == '-' ){
    if ( OS4000Data[NextData+5] == '.' ){
      Pitch100 = OS4000Data[NextData+2] - '0';
      Pitch10 = OS4000Data[NextData+3] - '0';
      Pitch1 = OS4000Data[NextData+4] - '0';
      Pitch01 = OS4000Data[NextData+6] - '0';
      NextData += 7;
    }
    else if ( OS4000Data[NextData+4] == '.' ){
      Pitch10 = OS4000Data[NextData+2] - '0';
      Pitch1 = OS4000Data[NextData+3] - '0';
      Pitch01 = OS4000Data[NextData+5] - '0';
      NextData += 6;
    }
    else if ( OS4000Data[NextData+3] == '.' ){
      Pitch1 = OS4000Data[NextData+2] - '0';
      Pitch01 = OS4000Data[NextData+4] - '0';
      NextData += 5;
    }
    Pitch = - ( 1000*Pitch100 + 100*Pitch10 + 10*Pitch1 + Pitch01 );
  }
  else
  {
    if ( OS4000Data[NextData+4] == '.' ){
      Pitch100 = OS4000Data[NextData+1] - '0';
      Pitch10 = OS4000Data[NextData+2] - '0';
      Pitch1 = OS4000Data[NextData+3] - '0';
      Pitch01 = OS4000Data[NextData+5] - '0';
      NextData += 6;
    }
    else if ( OS4000Data[NextData+3] == '.' ){
      Pitch10 = OS4000Data[NextData+1] - '0';
      Pitch1 = OS4000Data[NextData+2] - '0';
      Pitch01 = OS4000Data[NextData+4] - '0';
      NextData += 5;
    }
    else if ( OS4000Data[NextData+2] == '.' ){
      Pitch1 = OS4000Data[NextData+1] - '0';
      Pitch01 = OS4000Data[NextData+3] - '0';
      NextData += 4;
    }
    Pitch = ( 1000*Pitch100 + 100*Pitch10 + 10*Pitch1 + Pitch01 );
  }

  Roll100 = 0;
  Roll10 = 0;
  Roll1 = 0;
  Roll01 = 0;
  if ( OS4000Data[NextData+1] == '-' ){
    if ( OS4000Data[NextData+5] == '.' ){
      Roll100 = OS4000Data[NextData+2] - '0';
      Roll10 = OS4000Data[NextData+3] - '0';
      Roll1 = OS4000Data[NextData+4] - '0';
      Roll01 = OS4000Data[NextData+6] - '0';
      NextData += 7;
    }
    else if ( OS4000Data[NextData+4] == '.' ){
      Roll10 = OS4000Data[NextData+2] - '0';
      Roll1 = OS4000Data[NextData+3] - '0';
      Roll01 = OS4000Data[NextData+5] - '0';
      NextData += 6;
    }
    else if ( OS4000Data[NextData+3] == '.' ){
      Roll1 = OS4000Data[NextData+2] - '0';
      Roll01 = OS4000Data[NextData+4] - '0';
      NextData += 5;
    }
    Roll = - ( 1000*Roll100 + 100*Roll10 + 10*Roll1 + Roll01 );
  }
  else
  {
    if ( OS4000Data[NextData+4] == '.' ){
      Roll100 = OS4000Data[NextData+1] - '0';
      Roll10 = OS4000Data[NextData+2] - '0';
      Roll1 = OS4000Data[NextData+3] - '0';
      Roll01 = OS4000Data[NextData+5] - '0';
      NextData += 6;
    }
    else if ( OS4000Data[NextData+3] == '.' ){
      Roll10 = OS4000Data[NextData+1] - '0';
      Roll1 = OS4000Data[NextData+2] - '0';
      Roll01 = OS4000Data[NextData+4] - '0';
      NextData += 5;
    }
    else if ( OS4000Data[NextData+2] == '.' ){
      Roll1 = OS4000Data[NextData+1] - '0';
      Roll01 = OS4000Data[NextData+3] - '0';
      NextData += 4;
    }
    Roll = ( 1000*Roll100 + 100*Roll10 + 10*Roll1 + Roll01 );
  }

  Temp100 = 0;
  Temp10 = 0;
  Temp1 = 0;
  Temp01 = 0;
  if ( OS4000Data[NextData+1] == '-' ){
    if ( OS4000Data[NextData+5] == '.' ){
      Temp100 = OS4000Data[NextData+2] - '0';
      Temp10 = OS4000Data[NextData+3] - '0';
      Temp1 = OS4000Data[NextData+4] - '0';
      Temp01 = OS4000Data[NextData+6] - '0';
      NextData += 7;
    }
    else if ( OS4000Data[NextData+4] == '.' ){
      Temp10 = OS4000Data[NextData+2] - '0';
      Temp1 = OS4000Data[NextData+3] - '0';
      Temp01 = OS4000Data[NextData+5] - '0';
      NextData += 6;
    }
    else if ( OS4000Data[NextData+3] == '.' ){
      Temp1 = OS4000Data[NextData+2] - '0';
      Temp01 = OS4000Data[NextData+4] - '0';
      NextData += 5;
    }
    Temp = - ( 1000*Temp100 + 100*Temp10 + 10*Temp1 + Temp01 );
  }
  else
  {
    if ( OS4000Data[NextData+4] == '.' ){
      Temp100 = OS4000Data[NextData+1] - '0';
      Temp10 = OS4000Data[NextData+2] - '0';
      Temp1 = OS4000Data[NextData+3] - '0';
      Temp01 = OS4000Data[NextData+5] - '0';
      NextData += 6;
    }
    else if ( OS4000Data[NextData+3] == '.' ){
      Temp10 = OS4000Data[NextData+1] - '0';
      Temp1 = OS4000Data[NextData+2] - '0';
      Temp01 = OS4000Data[NextData+4] - '0';
      NextData += 5;
    }
    else if ( OS4000Data[NextData+2] == '.' ){
      Temp1 = OS4000Data[NextData+1] - '0';
      Temp01 = OS4000Data[NextData+3] - '0';
      NextData += 4;
    }
    Temp = ( 1000*Temp100 + 100*Temp10 + 10*Temp1 + Temp01 );
  }
}

void WireSendInt (int val)
{
  byte buf [2];
  buf [0] = val >> 8;
  buf [1] = val & 0xFF;
  Wire.send (buf, 2);
}

void WireSendAll ()
{
  byte buf [8];
  buf [0] = Heading >> 8;
}


the Extract_Info() is totaly corect
it is always updates corectly the
Heading PItch Roll Temp
i have check it with uart output

also i have tried

Code:
void requestEvent()
{
  switch (command)
  {
  case 'A':
    WireSendAll();
    break;
  case 'H':
    WireSendInt(100);
    break;
  case 'P':
    WireSendInt(-214);
    break;
  case 'R':
    WireSendInt(5);
    break;
  case 'T':
    WireSendInt(-98);
    break;
30  Using Arduino / Networking, Protocols, and Devices / Re: I2C read problems on: June 18, 2011, 05:29:50 am
i am not using it it since the time you told me not to

then my output is 0
H: 0 P: 17  R: 17  T: 304 

so i wanted to know if i get two 0 bytes

or none byte

if it freeze it means that is not receiving 2 bytes

------------

but why its not receiving them?
Pages: 1 [2] 3 4 ... 10