Gerhard Schillhubers IO for Arduino

DDP
2015-06-08
2017-04-19
  • DDP - 2015-06-08

    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

     
  • KKempeneers - 2015-06-10

    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]

     
  • DDP - 2015-06-12

    what sketch do you have loaded on the arduino?

     
  • KKempeneers - 2015-06-12

    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.

    const int I2C_ADDRESS = 4;
    \#include <Wire.h>
    volatile int pinConfig;
    volatile int PWMConfig;
    volatile int digitalIn;
    volatile int analogIn[4];
    volatile int digitalOut;
    volatile int PWMOut[6];
    volatile byte receiveBuffer[12];
    volatile byte cnt = 0;
    void setup() {
      Wire.begin(I2C_ADDRESS);      
      Wire.onReceive(receiveEvent); 
      Wire.onRequest(requestEvent); 
      Serial.begin(9600);  
      Serial.println("Ready to accept I2C data ...");
    }
    void loop() {
      for (int i = 0; i<14; i++) {
        bool mode = bitRead(pinConfig, i);
        bool pwm = bitRead(PWMConfig, i);
        byte pwmvalue;
        if (mode) {
          pinMode(i, OUTPUT);
          
          if(pwm) {
            switch (i) {
            case 3:
              pwmvalue = PWMOut[0];
              break;
            case 5:
              pwmvalue = PWMOut[1];
              break;
            case 6:
              pwmvalue = PWMOut[2];
              break;
            case 9:
              pwmvalue = PWMOut[3];
              break;
            case 10:
              pwmvalue = PWMOut[4];
              break;
            case 11:
              pwmvalue = PWMOut[5];
              break;
            }
            analogWrite(i,pwmvalue);
          } else {
            digitalWrite(i, bitRead(digitalOut,i));
          }
        } else {
          pinMode(i,INPUT);
        }
      }
      
      for (int i = 0; i<14; i++) {
        if (!bitRead(pinConfig, i)) bitWrite(digitalIn, i, digitalRead(i));
      }
      for (int i = 0; i<4; i++) {
        analogIn[i] = analogRead(i);
      }
    }
    void receiveEvent(int howMany) {
      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 (int j=0;j<6;j++) {
        PWMOut[j] = receiveBuffer[6+j];
      }
    }
    void requestEvent() {
      int sendBuffer[5];
      sendBuffer[0] = digitalIn;
      for (int i = 0; i<4; i++) {
        sendBuffer[1+i] = analogIn[i];
      }
      Wire.write((uint8_t*) &sendBuffer,10); 
    }
    

    Hope this helps someone,

    Koen.

     

    Related

    Talk.ru: 1
    Talk.ru: 2
    Talk.ru: 3
    Talk.ru: 5

  • KKempeneers - 2015-06-16

    For future reference ...

    The Arduino slave code in the requestEvent reads:

    void requestEvent() {
      int sendBuffer[5];
      sendBuffer[0] = digitalIn;
      for (int i = 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,

     

    Related

    Talk.ru: 5

  • alverman - 2017-04-19

    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

     
  • alverman - 2017-04-19

    Do you know that you are right KKempeneers?
    Compiling with 1.6.3 works which is a wonder !!

    Thanks

     

Log in to post a comment.