Hello everyone
I am using Qt 5.3.2 and have also installed Qtcreator 3.2.1 in my Raspberry pi 2 running Linux.
I have a C code which continously toggles the GPIO pin no. 17. Here the code is
//it is saved as blink..c
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <errno.h>
#include <stdint.h>
static volatile uint32_t *gpio;
int main(int argc, char **argv)
{
int fd ;
//Obtain handle to physical memory
if ((fd = open ("/dev/mem", O_RDWR | O_SYNC) ) < 0) {
printf("Unable to open /dev/mem: %s\n", strerror(errno));
return -1;
}
//map a page of memory to gpio at offset 0x3F200000 which is where GPIO goodnessstarts
gpio = (uint32_t *)mmap(0, getpagesize(), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0x3F200000);
if ((int32_t)gpio < 0){
printf("Mmap failed: %s\n", strerror(errno));
return -1;
}
//set gpio17 as an output
//set the value through a little bit twiddling where we only modify the bits 21-23 in the register
*(gpio + 1) = (*(gpio + 1) & ~(7 << 21)) | (1 << 21);
//toggle gpio17 every second
while(1){
//set the pin high
//increment the pointer to 0x3F20001C
*(gpio + 7) = 1 << 17;
//sleep
// sleep(1);
//set the pin to low
//increment the pointer to 0x3F200028
*(gpio + 10) = 1 << 17;
//sleep(1);
}
}
//it is saved as blink..c
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <errno.h>
#include <stdint.h>
static volatile uint32_t *gpio;
int main(int argc, char **argv)
{
int fd ;
//Obtain handle to physical memory
if ((fd = open ("/dev/mem", O_RDWR | O_SYNC) ) < 0) {
printf("Unable to open /dev/mem: %s\n", strerror(errno));
return -1;
}
//map a page of memory to gpio at offset 0x3F200000 which is where GPIO goodnessstarts
gpio = (uint32_t *)mmap(0, getpagesize(), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0x3F200000);
if ((int32_t)gpio < 0){
printf("Mmap failed: %s\n", strerror(errno));
return -1;
}
//set gpio17 as an output
//set the value through a little bit twiddling where we only modify the bits 21-23 in the register
*(gpio + 1) = (*(gpio + 1) & ~(7 << 21)) | (1 << 21);
//toggle gpio17 every second
while(1){
//set the pin high
//increment the pointer to 0x3F20001C
*(gpio + 7) = 1 << 17;
//sleep
// sleep(1);
//set the pin to low
//increment the pointer to 0x3F200028
*(gpio + 10) = 1 << 17;
//sleep(1);
}
}
To copy to clipboard, switch view to plain text mode
this code is saved as blink.c
And I can compile it through following code in terminal (not in Qt)
gcc blink.c
gcc blink.c
To copy to clipboard, switch view to plain text mode
And it is executing through following code in terminal (not in Qt)
sudo ./a.out
sudo ./a.out
To copy to clipboard, switch view to plain text mode
The above compilation and execution I am doing is without Qt.
I want to execute the same code When I push the button created in QtCreator. I know how to create button as I had gonr through this linkhttp://http://www2.cs.uic.edu/~i340/...gner_Tutorial/
How should I move futher. I just want my file to execute when I press button.
A detailed help will be very useful.
Thanks
Bookmarks