Close

Getting bounding box coordinates transmitted to Arduino over I2C

A project log for Autonomous Agri-robot Control System

Controlling autonomous robots the size of a small tractor for planting, weeding and harvesting

capt-flatus-oflahertyCapt. Flatus O'Flaherty ☠ 10/17/2018 at 16:140 Comments

After a few days work, I finally managed to get data out of the Jetson TX2 through the I2C bus. I started off using a tutorial from JetsonHacks that runs a 4 digit LED display and then stripped out most of the code to keep only the few lines that transmit the data. It was a bit tricky to compile the code along with the main 'inference' program which is called detectnet-camera.cpp. This basic code can only transmit one byte at a time so an integer such as 463 cannot be transmitted as the upper limit is 254. We get something like 46 instead of 463. This is not an insolvable problem as there is already I2C code within the WEEDINATOR software repository for doing this between the Arduino Mega and the TC275 so it should be just a case of re-purposing it for this new I2C task. It's also a chance for me to try and understand what Slash Dev wrote !!!!

Here's some excerpts from my 'basic' I2C code:

void OpenI2C()
{
    int length;
    unsigned char buffer[60] = {0};

    
    //----- OPEN THE I2C BUS -----
    char *filename = (char*)"/dev/i2c-1";
    if ((kI2CFileDescriptor = open(filename, O_RDWR)) < 0)
    {
        //ERROR HANDLING: you can check errno to see what went wrong
        printf("*************** Failed to open the i2c bus ******************\n");
        //return;
    }
        if( ioctl( kI2CFileDescriptor, I2C_SLAVE, PADDYADDRESS ) < 0 )
        {
                fprintf( stderr, "Failed to set slave address: %m\n" );
                //return 2;
        }
}
int i2cwrite(int writeValue) 
{
    int toReturn = i2c_smbus_write_byte(kI2CFileDescriptor, writeValue);
    if (toReturn < 0) 
    {
        printf(" ************ Write error ************* \n") ;
        toReturn = -1 ;
    }
    return toReturn ;
}
                                writeValue = static_cast<int>(bb[0]);
                                printf(" writeValueZero   = %i \n",writeValue);
                                i2cwrite(writeValue);

                                writeValue = static_cast<int>(bb[1]);
                                printf(" writeValueOne    = %i \n",writeValue);
                                i2cwrite(writeValue);

                                writeValue = static_cast<int>(bb[2]);
                                printf(" writeValueTwo    = %i \n",writeValue);
                                i2cwrite(writeValue);

                                writeValue = static_cast<int>(bb[3]);
                                printf(" writeValueThree  = %i \n",writeValue);
                                i2cwrite(writeValue);
writeValue = static_cast<int>(bb[0]); 
printf(" writeValueZero   = %i \n",writeValue); 
i2cwrite(writeValue);
writeValue = static_cast<int>(bb[1]);           
printf(" writeValueOne    = %i \n",writeValue);                               
i2cwrite(writeValue);
writeValue = static_cast<int>(bb[2]);   
printf(" writeValueTwo    = %i \n",writeValue);                                
i2cwrite(writeValue);
writeValue = static_cast<int>(bb[3]);     
printf(" writeValueThree  = %i \n",writeValue);                                
i2cwrite(writeValue);

 Full code is on Github.

Discussions