I am trying to run a PWM programm in geany (C language with a Raspberry 4B). I can compile and build the program; however, when I run it the next erro appears:
pinMode PWM: unable to do this when using /dev(gpiomem. Try sudo?
Does anyone have had experience something like this? How can I fix it?
My program is the following:
#include <wiringPi.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#define MFOR_MOTOR 25
#define MBACK_MOTOR 24
#define PWM_MOTOR 1
#define ENCODER_A 21
#define ENCODER_B 22
int main (void){
if (wiringPiSetup()==-1)
exit (1) ;
int pwm_user;
wiringPiSetup();
pinMode(MFOR_MOTOR, OUTPUT);
pinMode(MBACK_MOTOR, OUTPUT);
pinMode(PWM_MOTOR, PWM_OUTPUT);
pinMode(ENCODER_A, INPUT);
pinMode(ENCODER_B, INPUT);
printf ("Raspberry Pi wiringPi Motor PWM program\n") ;
printf("PWM from motor: ");
scanf("%d", &pwm_user);
pwmWrite(PWM_MOTOR, pwm_user);
digitalWrite(MFOR_MOTOR, HIGH);
while(1){
digitalRead(ENCODER_A);
}
digitalWrite(MFOR_MOTOR, LOW);
return 0;
}
Thanks #Craig Estey for your help. I "fixed" the problem running the program directly to the terminal in the RaspberryPi so I used the next format for running it
$ nano pwm_motor.c //for creating the programm
$ gcc -Waöö pwm_motor.c -lwiring -o pwm_motor // for compile the programm
$ chmod +x pwm_motor // for build the program
$ sudo ./pwm_motor //for running the program
Maybe is not the best way but it worked for me. if someone else knows another idea I love reading it.
Related
I've the following code:
#include <stdio.h>
#include <windows.h>
#include <process.h>
int main() {
/* DWORD WINAPI */void input(/* LPVOID */void* lpParam) {
Sleep(1000);
printf("hello mingw!\n");
// return 0;
}
_beginthread(input, 0, NULL);
getchar();
return 0;
}
I cross-compile from ubuntu 22.04.01 with mingw-w64 with:
...$ x86_64-w64-mingw32-gcc -o example.exe example.c
In a native Win7 box it works as expected:
...$ example.exe
hello mingw! (after 1 second)
a
...$
but in wine when entering 'a' from keyboard, the 'a' climbs up one line:
...$ example.exe
aello mingw!
...$
It seems as if printf output from a thread didn't update console cursor. This only happens when read code (getchar()) executes before the write code (printf), hence the Sleep.
Any pointers?
For an assignment I have we are to find vulnerabilities in a certain C program and exploit them using various buffer overflow attacks. However when I run the .out file in the terminal with it's input argument it just stalls and doesn't do anything.
Even when I run GDB, that just lags too. I'm not looking for a solution to the assignment, I'm just looking for reasons why it's not running?
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
void partialwin()
{
printf("Achieved 1/2!\n");
}
void fullwin(){
printf("Achieved 2/2\n");
}
void vuln(){
char buffer[36];
gets(buffer);
printf("Buffer contents are %s\n",buffer);
}
int main(int argc,char**argv){
vuln();
}
Providing your sourc file is called assignment1.c and you're using gcc this should work, $ being your command prompt (which could be different on your platform)
$ gcc assignment1.c
$ a.out
Hello
Buffer contents are Hello
$
I am using the Adafruit Ultimate GPS breakout module to interface with the beaglebone black using c code. I am using UART 4 for that, but while running after compile it won't show any output. I changed the port name to "dev/ttyO4" in serial.h file.
thank you!!!
git hub link for the library: https://github.com/joyalraju/libgps
#include <stdio.h>
#include <stdlib.h>
#include <gps.h>
int main(void) {
// Open
gps_init();
loc_t data;
while (1) {
gps_location(&data);
printf("%lf %lf\n", data.latitude, data.longitude);
}
return EXIT_SUCCESS;
}
Joyal If you add your code with question make it easy to find out the problem.
I am trying to read a GPIO port from a raspberry pi 2B with C. I am using the wiringPi module and I have written a little program to try it out but it just always prints 0, even if I directly connect the pin to 3.3 or 5V. I also tried pulling it up but then it just always says 1, even when I try connecting it directly to ground. When I tried to read the pin with python it worked correctly so I am at a loss as to what is wrong. The code is as below:
#include <stdio.h>
#include <stdlib.h>
#include <wiringPi.h>
void main(){
wiringPiSetup();
pinMode(4, INPUT);
pullUpDnControl(4, PUD_DOWN);
printf("%d", digitalRead(4));
}
I am running raspbian 7 (wheezy)
I have implemented the boundary fill algorithm in C language with the following code:--
/* WAP to fill the polygon using boundary fill 4 connected algo */
#include "stdio.h"
#include "conio.h"
#include "graphics.h"
#include "dos.h"
void main()
{
int gd = DETECT, gm;
clrscr();
detectgraph(&gd, &gm);
initgraph(&gd, &gm , "C:\\TC\\BGI");
rectangle(60,60,500,500);
boundary_fill(65,65,4,15);
getch();
closegraph();
}
boundary_fill(int x, int y, int fclr, int bclr)
{
if(getpixel(x,y)!= bclr && getpixel(x,y)!= fclr)
{
putpixel(x,y,fclr);
boundary_fill(x+1,y,fclr,bclr);
boundary_fill(x-1,y,fclr,bclr);
boundary_fill(x,y+1,fclr,bclr);
boundary_fill(x,y-1,fclr,bclr);
}
}
when i compile it no error come. But When i run the program the window closes and i get the following error:--
C:\TC\BIN\TC.EXE
The NTVDM CPU has encounterer an illegal instruction.. . . . . .
PLease help
stop using turboC. run your 16 bit programs(such as TurboC/C++) with DosBox instead. NTVDM error occurs because of 32bit COMMAND-PROMPT trying to run a 16 Bit Program.