I downloaded the i2c libraries from Gerhard and having problems... I think Im down to only one problem, maybe 2...
I cannot find IoDrvArduino, 1.1.0.0
I try to download missing library and download fails.
I do have the IoDrvArduinoUNO... but I 16 Library Manager errors with lots of placeholder errors.
Anyone (Gerhard?) have an idea? can I just change the name and delete UNO from the end?
The second problem is my raspberry pi says it is missing the device description (3.5.4.10) and I have a newer description... If I click on update device, I lose the Arduino I2c....
Im sure my question shows Im a newb hahaha sorry and thanks in advance
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I do not pretend to know the answer to your problem. I managed to make a project with the library (attached) but found it to be very very unstable.
In fact all the project does is to toggle the LED at pin 13 of an Arduino Uno r3. This project compiles and runs at RPi model B and an Arduino Uno r3. It toggles the LED a few times and then synchronization is apparently lost, that is the program when monitored keeps on running but the LED doesn't blink anymore.
When I try the same using the PCF8574 library the communications seems to be far more stable.
Can somebody please clarify why the Arduino Uno library or solution seems to be so unstable?
I found that in the Arduino sketch packed with the original example project is assuming that on a Arduino Wire receiveEvent the complete packet of 12 bytes is readily available (i.e. received). Since this is not always the case the sketch looses synchronization, resulting in unpredictable behavior. I modified the code so that it waits for the packet to complete before processing the received data.
I included the new sketch below.
constintI2C_ADDRESS=4;
\#include<Wire.h>volatileintpinConfig;volatileintPWMConfig;volatileintdigitalIn;volatileintanalogIn[4];volatileintdigitalOut;volatileintPWMOut[6];volatilebytereceiveBuffer[12];volatilebytecnt=0;voidsetup() {
 Wire.begin(I2C_ADDRESS);  Â
 Wire.onReceive(receiveEvent);
 Wire.onRequest(requestEvent);
 Serial.begin(9600);Â
 Serial.println("Ready to accept I2C data ...");
}
voidloop() {
 for(inti=0; i<14; i++) {
  boolmode=bitRead(pinConfig, i);
  boolpwm=bitRead(PWMConfig, i);
  bytepwmvalue;
  if(mode) {
   pinMode(i, OUTPUT);
  Â
   if(pwm) {
    switch(i) {
    case3:
     pwmvalue=PWMOut[0];
     break;
    case5:
     pwmvalue=PWMOut[1];
     break;
    case6:
     pwmvalue=PWMOut[2];
     break;
    case9:
     pwmvalue=PWMOut[3];
     break;
    case10:
     pwmvalue=PWMOut[4];
     break;
    case11:
     pwmvalue=PWMOut[5];
     break;
    }
    analogWrite(i,pwmvalue);
   } else {
    digitalWrite(i, bitRead(digitalOut,i));
   }
  } else {
   pinMode(i,INPUT);
  }
 }
Â
 for(inti=0; i<14; i++) {
  if(!bitRead(pinConfig, i))bitWrite(digitalIn, i, digitalRead(i));
 }
 for(inti=0; i<4; i++) {
  analogIn[i] =analogRead(i);
 }
}
voidreceiveEvent(inthowMany) {
 while(Wire.available()) {
  receiveBuffer[cnt] =Wire.read();
  cnt++;
 }
 if(cnt<12)return;
 cnt=0;
 pinConfig=receiveBuffer[1]*256+receiveBuffer[0];
 PWMConfig=receiveBuffer[3]*256+receiveBuffer[2];
 digitalOut=receiveBuffer[5]*256+receiveBuffer[4];
 for(intj=0;j<6;j++) {
  PWMOut[j] =receiveBuffer[6+j];
 }
}
voidrequestEvent() {
 intsendBuffer[5];
 sendBuffer[0] =digitalIn;
 for(inti=0; i<4; i++) {
  sendBuffer[1+i] =analogIn[i];
 }
 Wire.write((uint8_t*)&sendBuffer,10);
}
voidrequestEvent() {
 intsendBuffer[5];
 sendBuffer[0] =digitalIn;
 for(inti=0; i<4; i++) {
  sendBuffer[1+i] =analogIn[i];
 }
 Wire.write((uint8_t*)sendBuffer,10);Â
}
So you should remove the & before sendBuffer in the Wire.write() call (Compiled with Arduino 1.6.3 on Windows 7 64bit)
With these corrections everything works fine!
Thanks,
Hi,
I was very happy to be able to use Arduino I2C with CoDeSys but I have instability problems !!
By the time I compiled with ide 1.8 and Arduino, with your example, it is very unstable.
The LED flashes for a while then stops to continue maybe or maybe not.
Now they will try to compile with 1.6.3 as you did, but I wonder how it is possible to have a stable according to the compiler !!
Another thing: I do not understand your last comment snippet.
Zitat:
So you should remove the & before sendBuffer in the Wire.write() call (Compiled with Arduino 1.6.3 on Windows 7 64bit)
With these corrections everything works fine!
Thanks,
Where is the '&' in the old code ?
Greetings, Alberto
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I downloaded the i2c libraries from Gerhard and having problems... I think Im down to only one problem, maybe 2...
I cannot find IoDrvArduino, 1.1.0.0
I try to download missing library and download fails.
I do have the IoDrvArduinoUNO... but I 16 Library Manager errors with lots of placeholder errors.
Anyone (Gerhard?) have an idea? can I just change the name and delete UNO from the end?
The second problem is my raspberry pi says it is missing the device description (3.5.4.10) and I have a newer description... If I click on update device, I lose the Arduino I2c....
Im sure my question shows Im a newb hahaha sorry and thanks in advance
Hi,
I do not pretend to know the answer to your problem. I managed to make a project with the library (attached) but found it to be very very unstable.
In fact all the project does is to toggle the LED at pin 13 of an Arduino Uno r3. This project compiles and runs at RPi model B and an Arduino Uno r3. It toggles the LED a few times and then synchronization is apparently lost, that is the program when monitored keeps on running but the LED doesn't blink anymore.
When I try the same using the PCF8574 library the communications seems to be far more stable.
Can somebody please clarify why the Arduino Uno library or solution seems to be so unstable?
KK
FischerTechnicMetVellemanIOShield.project [138.82 KiB]
what sketch do you have loaded on the arduino?
Hi again,
I found that in the Arduino sketch packed with the original example project is assuming that on a Arduino Wire receiveEvent the complete packet of 12 bytes is readily available (i.e. received). Since this is not always the case the sketch looses synchronization, resulting in unpredictable behavior. I modified the code so that it waits for the packet to complete before processing the received data.
I included the new sketch below.
Hope this helps someone,
Koen.
Related
Talk.ru: 1
Talk.ru: 2
Talk.ru: 3
Talk.ru: 5
For future reference ...
The Arduino slave code in the requestEvent reads:
So you should remove the & before sendBuffer in the Wire.write() call (Compiled with Arduino 1.6.3 on Windows 7 64bit)
With these corrections everything works fine!
Thanks,
Related
Talk.ru: 5
Hi,
I was very happy to be able to use Arduino I2C with CoDeSys but I have instability problems !!
By the time I compiled with ide 1.8 and Arduino, with your example, it is very unstable.
The LED flashes for a while then stops to continue maybe or maybe not.
Now they will try to compile with 1.6.3 as you did, but I wonder how it is possible to have a stable according to the compiler !!
Another thing: I do not understand your last comment snippet.
Where is the '&' in the old code ?
Greetings, Alberto
Do you know that you are right KKempeneers?
Compiling with 1.6.3 works which is a wonder !!
Thanks