Page 1 of 1

How to read and write on a pin ?

Posted: Fri May 15, 2015 2:26 pm
by coyote-mania

I'm a student and i have a project to do for my baccalaureate.
My issue is to detect a person in a room with an ultrasonic sensor and return a value if there is someone to the RaspberryPi 2, to detect with an infrared sensor the position of a shutter, if there is in high, middle or low position and return a value to the microcontroller, and the mount or get down the shutter according to the value of another sensor, but this sensor is not my part.
My problem is with WiringPi, the Raspberry can't compile my program.

This is my program :
Capture.PNG (31.33 KiB) Viewed 798 times
The variable IN1 and IN2 are to run the motor in one direction or the other. The variable infrared is for the infrared sensor and is the GPIO 11 of the Raspberry. lux is a variable whose is not in my issue.
To run my ultrasonic sensor need a pulse of 10uS by my microcontroller. Before the sensor if there is an object, send the GPIO 13 at 1.
The ultrasonic sensor and the infrared sensor are in bang-bang control.

This is the screenshot of my problem :
Capture1.png (57.81 KiB) Viewed 798 times
Can you help me please ?

Thanks for reading.

Re: How to read and write on a pin ?

Posted: Fri May 15, 2015 5:46 pm
by FTrevorGowen
There are at least two (syntax) errors in your code and your indentation style does not make it easy reading. When posting code (snippits) it's best to copy and paste it with "Code" tags (5th. tab above) rather than post a "screen capture" image.
Doing that allows us to re-post corrections easily.
The two things I've spotted which led to the gcc compiler complaining are:
1) You should have:

Code: Select all

int main(int argc, char **argv)
2) and an else if line appears to have an extra semi-colon - perhaps it should read like this:

Code: Select all

else if (lux >= 1500)
   /* some other code here */
Also I think wiringPiSetup(); may need to be called before pinMode(.. . There may well be other bugs since it's not clear from your included comments what you're trying to do (ie. program errors, rather than syntax errors)

Re: How to read and write on a pin ?

Posted: Fri May 15, 2015 6:24 pm
by MarkHaysHarris777
Your errors are classic C compile time errors when the compiler finds missing semi colons ;

Your code has several obvious missing semi colons ;

The structure (style) you have chosen is difficult to read, and has probably led to coding errors and logic errors.