I2c register reading

hello all.

I'm trying to read I2c information from a Raspberry pi via I2c. The catch is, the Pi thinks its sending information to a PCA9685, 16 channel servo driver : Downloads | Adafruit PCA9685 16-Channel Servo Driver | Adafruit Learning System

The Pi is sending servo positional information that I am latter going to map to 0-255 PWM outputs for two DC motors, hopefully

I know the max/min values its going to send, I can't seem to isolate them in the Arduino with Wire.read() in a usable format?

I2c example, slave_ receiver.ino has this sort of serial output from Wire.read()

0
0
200

0

If I could isolate the 200 line then I could work with it.

Any suggestions?

Thanks

Is the output from the Pi always in the same format ?

I'd start with if I don't want 0's to be received, not sending 0's.

of course you could change the few of lines of your code right there between those 2 other lines and add in a parsing routine. to separate out the values.

Thanks,
@UKHeliBob its always the same format.

Once received by the board I'm trying to emulate, It outputs a foward/reverse, Left/right PWM for an ESC

@Idahowalker parsing routine sounds like it will work! Is that similar to bit masking?

A parsing routine would understand the incoming message format, take the message apart to access its individual components, and send/distribute the components.

Here is a routine I use to receive Serial:

void fReceiveSerial_LIDAR( void * parameters  )
{
  bool BeginSentence = false;
  char OneChar;
  char *str;
  str = (char *)ps_calloc(300, sizeof(char) ); // put str buffer into PSRAM
  // log_i("Free PSRAM before String: %d", ESP.getFreePsram());
  for ( ;; )
  {
    EventBits_t xbit = xEventGroupWaitBits (eg, evtReceiveSerial_LIDAR, pdTRUE, pdTRUE, portMAX_DELAY);
    if ( LIDARSerial.available() >= 1 )
    {
      while ( LIDARSerial.available() )
      {
        OneChar = LIDARSerial.read();
        if ( BeginSentence )
        {
          if ( OneChar == '>')
          {
            if ( xSemaphoreTake( sema_ParseLIDAR_ReceivedSerial, xSemaphoreTicksToWait10 ) == pdTRUE )
            {
               xQueueOverwrite( xQ_LIDAR_Display_INFO, ( void * ) &str );
              xEventGroupSetBits( eg, evtParseLIDAR_ReceivedSerial );
              //
            }
            BeginSentence = false;
            break;
          }
          strncat( str, &OneChar, 1 );
        }
        else
        {
          if ( OneChar == '<' )
          {
            strcpy( str, ""); // clear string buffer
            BeginSentence = true; // found beginning of sentence
          }
        }
      } //  while ( LIDARSerial.available() )
    } //if ( LIDARSerial.available() >= 1 )
    xSemaphoreGive( sema_ReceiveSerial_LIDAR );
    //        log_i( "fReceiveSerial_LIDAR " );
    //        log_i(uxTaskGetStackHighWaterMark( NULL ));
  }
  free(str);
  vTaskDelete( NULL );
} //void fParseSerial( void * parameters  )

The routine is only concerned with the processing of the received data and passing that data onto a parsing routine.

Here is the parsing routine:

void fParseLIDAR_ReceivedSerial ( void * parameters )
{
  // distribute received LIDAR info
  String sTmp = "";
  sTmp.reserve ( 20 );
  String sMessage = "";
  sMessage.reserve ( StringBufferSize300 );
  for ( ;; )
  {
    EventBits_t xbit = xEventGroupWaitBits (eg, evtParseLIDAR_ReceivedSerial, pdTRUE, pdTRUE, portMAX_DELAY) ;
    xQueueReceive ( xQ_LIDAR_Display_INFO, &sMessage, QueueReceiveDelayTime );
    int commaIndex = sMessage.indexOf(',');
    sTmp.concat ( sMessage.substring(0, commaIndex) );
    sMessage.remove( 0, (commaIndex + 1) ); // chop off begining of message
    if ( sTmp == "!" )
    {
      xSemaphoreGive ( sema_LIDAR_OK );
      //  Display info from LIDAR
      sLIDAR_Display_Info = sMessage;
    }
    if ( sTmp == "$" )
    {
      xEventGroupSetBits( eg1, evtResetWatchDogVariables );
    }
    if ( sTmp == "#")
    {
      xSemaphoreTake( sema_LIDAR_Alarm, xSemaphoreTicksToWait );
      sLIDAR_Alarm_info = sMessage;
      xSemaphoreGive( sema_LIDAR_Alarm );
      xEventGroupSetBits( eg, evtfLIDAR_Alarm );
    }
    sTmp = "";
    sMessage = "";
    xSemaphoreGive( sema_ParseLIDAR_ReceivedSerial );
  }
  vTaskDelete( NULL );
} // void fParseReceivedSerial ( void * parameters )

The parsing routine is only concerned with deconstructing the received message and passing the deconstructed message to the various other concerned tasks.

What you may find useful is to load up into the IDE a library for a I2C device, there by looking into the .cpp file you can see how I2C is parsed and, perhaps, apply what is learned to your project.