Posts: 15
Joined: Wed Jun 20, 2012 8:41 pm

How to read and write on a pin ?

Fri May 15, 2015 2:26 pm


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 810 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 810 times
Can you help me please ?

Thanks for reading.

User avatar
Forum Moderator
Forum Moderator
Posts: 5799
Joined: Mon Mar 04, 2013 6:12 pm
Location: Bristol, U.K.
Contact: Website

Re: How to read and write on a pin ?

Fri May 15, 2015 5:46 pm

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)
Still running Raspbian Jessie or Stretch on some older Pi's (an A, B1, 2xB2, B+, P2B, 3xP0, P0W, 2xP3A+, P3B+, P3B, B+, and a A+) but Buster on the P4B's. See:

User avatar
Posts: 1820
Joined: Mon Mar 23, 2015 7:39 am
Location: Rochester, MN
Contact: Website

Re: How to read and write on a pin ?

Fri May 15, 2015 6:24 pm

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.

Return to “C/C++”