Getting Started in C


#1

HELP!!!

I recently purchased my kit to do a final project for class, and I have to use c. I installed geany on my pi but when I run motor test it gives me an error of brickpi.h and tick.h not found. I ran the setup.sh file for c but, no luck in fixing that error. If someone could provide me with a list of steps to take, that would be wonderful.

thanks guys.


#2

Hey icortez, take a deep breath! We’re here to help!

It would be helpful to know about your image; did you purchase the SD card from us, install our image, or are you using NOOBS?

Have you been able to use any of the c examples that we have in our github site? They should compile, do they?

If you’re seeing this error, does copying the files brickpi.h and tick.h into the directories the c program you’re writing help?


#3

Also, just to be sure, you’re compiling from the command line, right? You’re not trying to run the program from Geany are you?


#4

I did purchase the sd card from you guys, and I have done multiple clean installs of the same image. My current image is currently is similar to this as i followed the steps.

https://github.com/DexterInd/BrickPi_C/tree/master/Scripts

I just recently got it to compile the motor test.c but, after I created a new file on the desktop renamed it to “test.c” and as well as creating new files for both BrickPi.h and Tick.h but, I keep getting a return result of -1 although my motors are plugged in. though before that I could not get them to compile. Making those files in the same directory (Desktop) it did seem to have a good effect. although it did not do anything with the motors. I was compiling and building within geany and it was giving an error message of “Permission
Denied”. So because of that it would not let me execute.
I did get python to run on a previous install of the image but not c, and my project has to be written in c.

also on a side note, I really wanted to use nxcEditor thinking it would help me as well but i could not get it to install correctly.

I hope this helps, and Thanks for the reply
I hope you can help save me from this fiasco


#5

Are you using “sudo” to compile, and “sudo” to run the C code?

Are you compiling our test program or one you wrote yourself?

Here’s what I would try:
1). copy this file (https://github.com/DexterInd/BrickPi_C/blob/master/Sensor_Examples/LEGO%20-%20Motor%20Test.c) and make sure you have brickpi.h and tick.h into the same directory.
2). Compile Using:
sudo gcc -o program “LEGO - Motor Test.c” -lrt -lm
3). Run the compiled program using:
sudo ./program

I would double check:


#6

John my friend you are a life saver!!!

But i have some questions
creating my project i would make a new file and name it along the lines of = “FinalProject.c”(without the qoutes of course)

Could i make a folder on the desktop named project and include BrickPi.h, tick.h and myProject.c and have it work essentially?


#7
John my friend you are a life saver!!!
Glad we could help. Which part worked?
But i have some questions creating my project i would make a new file and name it along the lines of = “FinalProject.c”(without the qoutes of course)

Could i make a folder on the desktop named project and include BrickPi.h, tick.h and myProject.c and have it work essentially?


Yes, I think that should work. Copy the .h files into your new folder, name your new .c file whatever you like. Just be sure to use the new .c file name when you compile. once yuo’ve compiled, you can move this program to wherever you need to.

#8

What worked was making sure that the files were all in the same directory. I also changed my working directory to the Sensor_Examples, then typed in what you told me and the motors were music to my ears.

Thank you very much for the help
-Isaiah


#9

Hello,
sadly i am back again, so i tried to run code from a folder on the desktop with my project file along with both .h files but no luck. i ran the motor test from the sensor folder and it worked fine. i then copied all the text from the motor test file into a new file into the desktop folder where my project file is stored and it gave me an error.(error1)
i am unable to drag my project file to the sensors folder to see if that will help as well but i get another error(error2)


#10

I think the problem might be with your program. If you copy the motor file into your directory and try to compile it, it should work.

I just did this to make sure I wasn’t taking crazy pills, and it compiled fine on a folder i made on the desktop. In the command line I made a folder called “Final” then I went into the BrickPi_C/Sensor_Examples directory and copied each file to the new folder:

`cp filename.c ~/Desktop/Final’

Then compiled. I attached a screenshot. No errors. I did this on the latest version of Raspbian for robots. If you get permission errors, just use “sudo” when you cp.


#11

thanks john for the help.
i got it to work again on a fresh install of the latest image, so it was probably the code that i was trying to write as well. so my question now is there some type of documentation i can use to understand how the functions are used and well how to use the c library for the brickPi. I tried going through the BrickPi.h file to see if i could gain a grasp on it but, i didnt get much.