I have a BeagleBone Blackboard and I’m using the below-mentioned image file.
https://debian.beagleboard.org/images/bone-debian-10.3-iot-armhf-2020-04-06-4gb.img.xz
I aim to operate GPIO pins of this board with the c programming language.
To do so, I’ve gone through this link: Robot Control Library: Installation & Checking Functionality
And after following all the steps according to this link the result I achieved is the same as mentioned in the checking functionality step [the last step] of this document.
Furthermore, I follow this document for c language setup:
/** \page project_template Project Template
We highly suggest using or at least studying the rc_project_template available at <https://github.com/StrawsonDesign/librobotcontrol/tree/master/rc_project_template>.
\section template_s1 Copying the Template
The project template source is also included as part of the librobotcontrol package and in installed to /usr/share/robotcontrol/rc_project_template so it can be easily copied and modified. We suggest copying the project and modifying as follows.
\subsection template_s1s1 Make a Copy
Make a copy of the project template, rename the folder to your desired project name, and cd to your new directory.
````
cp -r /usr/share/robotcontrol/rc_project_template ~/new_project_name
cd new_project_name
````
This file has been truncated. show original
and run this source code:
https://beagleboard.org/static/librobotcontrol/rc_test_leds_8c-example.html
All these processes were completed without any error.
Now I want to access the GPIO pins of the board. For that, I’ve prepared a basic code.
Let’s take a pin P8_10 / GPIO2[4] for an example. So for that my code will be:
#include <stdio.h>
#include <rc/led.h>
#include <rc/gpio.h>
#include <rc/time.h>
//#define WAIT_US 500000 // time to light each LED in microseconds
int main()
{
rc_gpio_init(2,4,GPIOHANDLE_REQUEST_OUTPUT); /* declare as output*/
rc_gpio_set_value(2,4,1); /* set high */
rc_gpio_cleanup(2,4);
return 0;
}
After executing this code I am not getting the expected output.
So have you any suggestions for me regarding this code.
Or is there any other way to do so?
Thank you.
Why are you using libRobotControl? Are you using the Robotic’s cape?
Otherwise, just use libgpiod, or /sys/class/gpio…
Regards,
I want to use i2c and UART communication as well. so can you help me with the example code with the library gpiod?
Hi Raj,
For i2c example check the following link.
/*
* BMAAccelerator.cpp
* Implementation of a class to interface with the Bosch BMA180 3 Axis Accelerometer
* over the I2C bus
*
* Copyright Derek Molloy, School of Electronic Engineering, Dublin City University
* www.eeng.dcu.ie/~molloyd/
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL I
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
This file has been truncated. show original
UART communication can be achieved by accessing the /dev/ttyO0-4 files.
The following are some reading materials.
https://www.cmrr.umn.edu/~strupp/serial.html
https://www.wikitechy.com/tutorials/linux/how-to-open-read-and-write-from-serial-port-in-c
Regards,
Aswin
For i2c examples check these as well.
https://fossies.org/linux/i2c-tools/lib/smbus.c
Regards,
Aswin