Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I'm working on connecting my computer to my RC car (cheap car) and found a tutorial of someone who got this working years ago. Well, the hardware is built and connected to my parallel printer port but, the code doesn't work. It's written in C (of which I am not knowledgeable) and presents me with some errors. I've manages to fix a couple by using Google but, have come to a stopping point.
I have emailed the dev but, don't expect to hear from him given the 6 yrs since the posting. Here is the source code. I'm using Ubuntu Jaunty.
Code:
/*
* rccar.c: lpt port control of a radio controlled car
*
* MORE INFO HERE: http://www.engr.uvic.ca/~sbowman/prog.php
*
* By: Shaun Bowman Sept. 2003, shaun_bowman@hotmail.com
*
* Notes: This program is unlikely to be ready-2-port because of the ioctl
method
* of changing terminal settings. This program was written so i could
* control a tiny 10$ remote control car (and to procrastinate homework).
* The lpt port pins (6,7,8,9) are used to control Forward, Reverse, Left
* and Right in the controller. In addition to this program, I had to build
* a simple circuit to bypass the buttons on the remote control. This is
* because even in the low state, the Control and Ground pins still form a
* complete circuit.
*
* Crude Diagram (1 for each button):
*
* GrndPin(18-25) PinX(5-9)
* | | T1: NPN transistor, i used 2N222
* | |
* | L---R1--R2--R3 R1-R3: Resistors, i didn't have
* | T1: | ones with high enough
* |--------|\ | resistance, so i had to use
* | | ------------------ 3. Total R ~= 100k ohm's
* | |---|/(<-collector pin)
* | |
* -ButtnLead +ButtnLead
*
* Compile with: gcc -O2 -o rccar rccar.c (must be root)
*
* Pin bits (numbered at female end)
* outb(8, x) = pin 5 UNUSED
* outb(16, x) = pin 6 Forward
* outb(32, x) = pin 7 Reverse
* outb(64, x) = pin 8 Left
* outb(128, x) = pin 9 Right
* outb(80, x) = pin 6 & 8 FORWARDLEFT
* outb(144, x) = pin 6 & 9 FORWARDRIGHT
* outb(96, x) = pin 7 & 8 REVERSELEFT
* outb(160, x) = pin 7 & 9 REVERSERIGHT
*/
#include <stdio.h>
#include <unistd.h>
#include <asm/io.h>
#include <string.h>
#include <libio.h>
#include <sys/ioctl.h>
#include <termios.h>
#include <unistd.h>
#define LPT1PORT 0x378 /* lpt1 */
int main()
{
struct termios oldT, newT; /* create our termios identifiers, uphere because C++ is retarted*/
void forward( char key ){
outb(16, LPT1PORT); /* Set pin 9 to high */
usleep(10000); /* Sleep for a while (100 ms) */
}
void reverse( char key ){
outb(32, LPT1PORT);
usleep(10000);
}
void left( char key ){
outb(64, LPT1PORT);
usleep(10000);
}
void right( char key ){
outb(128, LPT1PORT);
usleep(10000);
}
void forwardleft( char key ){
outb(80, LPT1PORT);
usleep(10000);
}
void forwardright( char key ){
outb(144, LPT1PORT);
usleep(10000);
}
void reverseleft( char key ){
outb(96, LPT1PORT);
usleep(10000);
}
void reverseright( char key ){
outb(160, LPT1PORT);
usleep(10000);
}
void stop( char key ){
outb(0, LPT1PORT); /* Set the data signals (D0-7) of the port to all low (0) */
usleep(10000);
}
void end () { /* The Beggining of the end.... */
outb(0, LPT1PORT);
usleep(10000);
if (ioperm(LPT1PORT, 3, 0)) {perror("ioperm"); exit(1);} /* We don't need the port anymore */
ioctl(0,TCSETS,&oldT); /* Better set the terminal back to normal... :-) */
exit(0); /* Buh bye */
}
if (ioperm(LPT1PORT, 3, 1)) {perror("ioperm"); exit(1);} /* Get access to the ports */
ioctl(0,TCGETS,&oldT); /* get current terminal mode */
newT=oldT; /* copy it into our new structure */
newT.c_lflag &= ~ECHO; /* toggle echo */
newT.c_lflag &= ~ICANON; /* toggle no line delimination */
ioctl(0,TCSETS,`"wT); /* initialize our new terminal mode */
char i[1];
while(1==1){
read(0,&i[0],1); /* read one char from the buffer */
printf("\nu pressed %c\n", i[0]);
if (i[0] == '8') { forward(i[0]); }
if (i[0] == '2') { reverse(i[0]); }
if (i[0] == '4') { left(i[0]); }
if (i[0] == '6') { right(i[0]); }
if (i[0] == '7') { forwardleft(i[0]); }
if (i[0] == '9') { forwardright(i[0]); }
if (i[0] == '1') { reverseleft(i[0]); }
if (i[0] == '3') { reverseright(i[0]); }
if (i[0] == '5') { stop(i[0]); }
if (i[0] == 'q') { end(); }
}
}
/* end of rccar.c */
Here are my errors.
Code:
shawn@shawn-desktop:~/Desktop$ sudo gcc -O2 -o rccar rccar.c
[sudo] password for shawn:
rccar.c:47:20: error: asm/io.h: No such file or directory
rccar.c: In function ‘main’:
rccar.c:124: error: stray ‘`’ in program
rccar.c:124:17: warning: missing terminating " character
rccar.c:124: error: missing terminating " character
rccar.c:125: error: expected expression before ‘char’
rccar.c:144: error: expected ‘;’ before ‘}’ token
changed #include <asm/io.h> to #include <io.h> and now get these errors.
Code:
shawn@shawn-desktop:~/Desktop$ sudo gcc -O2 -o rccar rccar.c
[sudo] password for shawn:
rccar.c:47:16: error: io.h: No such file or directory
rccar.c: In function ?main?:
rccar.c:124: error: stray ?`? in program
rccar.c:124:17: warning: missing terminating " character
rccar.c:124: error: missing terminating " character
rccar.c:125: error: expected expression before ?char?
rccar.c:144: error: expected ?;? before ?}? token
rccar.c:124: error: stray ‘`’ in program
rccar.c:124:17: warning: missing terminating " character
rccar.c:124: error: missing terminating " character
rccar.c:125: error: expected expression before ‘char’
change
ioctl(0,TCSETS,`"wT); to ioctl(0,TCSETS,"wT");
The <asm/io.h> error seems to be related to whether you have the kernel source package installed.
I'm assuming there's just a "Makefile" file in the source directory, and there's no autoconf "config" script.
If that's the case, you may need to modify the Makefile. However, you first have to knock that io.h problem out of the park.
1. Run the "updatedb" command as root (use "sudo updatedb" if you can).
This command should not return any output, but just give you back your shell prompt when it's done.
2. Run "locate io.h" and take note of every path the "io.h" file is found.
3. Make a quick backup of your "Makefile" ("cp -p Makefile Makefile.bak").
4. Check your "Makefile" for any "-I /path/to/some/directory" statements, correct any non-existing directories.
(NOTE: when you add a path, don't put "io.h" at the end of it.)
If that still doesn't work, let us know! (and be sure to mention what changes you made to the Makefile.
UPDATE: I just pulled down the source. No "Makefile", it's just a .c script. Nevermind!
Last edited by xeleema; 10-17-2009 at 12:45 AM.
Reason: I need to RTFS before posting. :)
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339
Rep:
Quote:
Originally Posted by xeleema
Greetingz!
I'm assuming there's just a "Makefile" file in the source directory, and there's no autoconf "config" script.
If that's the case, you may need to modify the Makefile. However, you first have to knock that io.h problem out of the park.
1. Run the "updatedb" command as root (use "sudo updatedb" if you can).
This command should not return any output, but just give you back your shell prompt when it's done.
2. Run "locate io.h" and take note of every path the "io.h" file is found.
3. Make a quick backup of your "Makefile" ("cp -p Makefile Makefile.bak").
4. Check your "Makefile" for any "-I /path/to/some/directory" statements, correct any non-existing directories.
(NOTE: when you add a path, don't put "io.h" at the end of it.)
If that still doesn't work, let us know! (and be sure to mention what changes you made to the Makefile.
UPDATE: I just pulled down the source. No "Makefile", it's just a .c script. Nevermind!
there is no makefile and io.h should not be required on linux
I commented out #include <io.h> and fixed the missing quote and got this.
Code:
shawn@shawn-desktop:~/Desktop$ sudo gcc -O2 -o rccar rccar.c
rccar.c: In function ‘main’:
rccar.c:124: error: stray ‘`’ in program
rccar.c:129: warning: ignoring return value of ‘read’, declared with attribute warn_unused_result
smeezekitty,
I noticed the lack of a Makefile. Updated my post to reflect that almost right after I chased down the sourcecode myself
Danteleo,
I'm getting a different error, and I've made the changes that everyone's mentioned. However, I'm not sure why the author put "must do as root", typically you should be able to compile things as a regular user....
I'm getting different errors myself. I've commented-out the Include for asm/io.h and corrected the ioctl line.
Code:
sysop$ gcc -O2 -o rccar rccar.c
rccar.c: In function 'end':
rccar.c:111: warning: incompatible implicit declaration of built-in function 'exit'
rccar.c:113: warning: incompatible implicit declaration of built-in function 'exit'
rccar.c: In function 'main':
rccar.c:117: warning: incompatible implicit declaration of built-in function 'exit'
/tmp/cccwFwJZ.o: In function `main':
rccar.c:(.text+0xd9): undefined reference to `outb'
rccar.c:(.text+0x10b): undefined reference to `outb'
rccar.c:(.text+0x13b): undefined reference to `outb'
rccar.c:(.text+0x16e): undefined reference to `outb'
rccar.c:(.text+0x19b): undefined reference to `outb'
/tmp/cccwFwJZ.o:rccar.c:(.text+0x1ce): more undefined references to `outb' follow
collect2: ld returned 1 exit status
sysop$
I also get the same errors when I try it as root;
Code:
root# gcc -O2 -o rccar rccar.c
rccar.c: In function 'end':
rccar.c:111: warning: incompatible implicit declaration of built-in function 'exit'
rccar.c:113: warning: incompatible implicit declaration of built-in function 'exit'
rccar.c: In function 'main':
rccar.c:117: warning: incompatible implicit declaration of built-in function 'exit'
/tmp/ccIVzpBr.o: In function `main':
rccar.c:(.text+0xd9): undefined reference to `outb'
rccar.c:(.text+0x10b): undefined reference to `outb'
rccar.c:(.text+0x13b): undefined reference to `outb'
rccar.c:(.text+0x16e): undefined reference to `outb'
rccar.c:(.text+0x19b): undefined reference to `outb'
/tmp/ccIVzpBr.o:rccar.c:(.text+0x1ce): more undefined references to `outb' follow
collect2: ld returned 1 exit status
Here is the current version (edited) that I am using.
Code:
/*
* rccar.c: lpt port control of a radio controlled car
*
* MORE INFO HERE: http://www.engr.uvic.ca/~sbowman/prog.php
*
* By: Shaun Bowman Sept. 2003, shaun_bowman@hotmail.com
*
* Notes: This program is unlikely to be ready-2-port because of the ioctl
method
* of changing terminal settings. This program was written so i could
* control a tiny 10$ remote control car (and to procrastinate homework).
* The lpt port pins (6,7,8,9) are used to control Forward, Reverse, Left
* and Right in the controller. In addition to this program, I had to build
* a simple circuit to bypass the buttons on the remote control. This is
* because even in the low state, the Control and Ground pins still form a
* complete circuit.
*
* Crude Diagram (1 for each button):
*
* GrndPin(18-25) PinX(5-9)
* | | T1: NPN transistor, i used 2N222
* | |
* | L---R1--R2--R3 R1-R3: Resistors, i didn't have
* | T1: | ones with high enough
* |--------|\ | resistance, so i had to use
* | | ------------------ 3. Total R ~= 100k ohm's
* | |---|/(<-collector pin)
* | |
* -ButtnLead +ButtnLead
*
* Compile with: gcc -O2 -o rccar rccar.c (must be root)
*
* Pin bits (numbered at female end)
* outb(8, x) = pin 5 UNUSED
* outb(16, x) = pin 6 Forward
* outb(32, x) = pin 7 Reverse
* outb(64, x) = pin 8 Left
* outb(128, x) = pin 9 Right
* outb(80, x) = pin 6 & 8 FORWARDLEFT
* outb(144, x) = pin 6 & 9 FORWARDRIGHT
* outb(96, x) = pin 7 & 8 REVERSELEFT
* outb(160, x) = pin 7 & 9 REVERSERIGHT
*/
#include <stdio.h>
#include <unistd.h>
/* #include <io.h> */
#include <string.h>
#include <libio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <termios.h>
#include <unistd.h>
#define LPT1PORT 0x378 /* lpt1 */
int main()
{
struct termios oldT, newT; /* create our termios identifiers, uphere because C++ is retarted*/
void forward( char key ){
outb(16, LPT1PORT); /* Set pin 9 to high */
usleep(10000); /* Sleep for a while (100 ms) */
}
void reverse( char key ){
outb(32, LPT1PORT);
usleep(10000);
}
void left( char key ){
outb(64, LPT1PORT);
usleep(10000);
}
void right( char key ){
outb(128, LPT1PORT);
usleep(10000);
}
void forwardleft( char key ){
outb(80, LPT1PORT);
usleep(10000);
}
void forwardright( char key ){
outb(144, LPT1PORT);
usleep(10000);
}
void reverseleft( char key ){
outb(96, LPT1PORT);
usleep(10000);
}
void reverseright( char key ){
outb(160, LPT1PORT);
usleep(10000);
}
void stop( char key ){
outb(0, LPT1PORT); /* Set the data signals (D0-7) of the port to all low (0) */
usleep(10000);
}
void end () { /* The Beggining of the end.... */
outb(0, LPT1PORT);
usleep(10000);
if (ioperm(LPT1PORT, 3, 0)) {perror("ioperm"); exit(1);} /* We don't need the port anymore */
ioctl(0,TCSETS,&oldT); /* Better set the terminal back to normal... :-) */
exit(0); /* Buh bye */
}
if (ioperm(LPT1PORT, 3, 1)) {perror("ioperm"); exit(1);} /* Get access to the ports */
ioctl(0,TCGETS,&oldT); /* get current terminal mode */
newT=oldT; /* copy it into our new structure */
newT.c_lflag &= ~ECHO; /* toggle echo */
newT.c_lflag &= ~ICANON; /* toggle no line delimination */
ioctl(0,TCSETS,`"wT"); /* initialize our new terminal mode */
char i[1];
while(1==1){
read(0,&i[0],1); /* read one char from the buffer */
printf("\nu pressed %c\n", i[0]);
if (i[0] == '8') { forward(i[0]); }
if (i[0] == '2') { reverse(i[0]); }
if (i[0] == '4') { left(i[0]); }
if (i[0] == '6') { right(i[0]); }
if (i[0] == '7') { forwardleft(i[0]); }
if (i[0] == '9') { forwardright(i[0]); }
if (i[0] == '1') { reverseleft(i[0]); }
if (i[0] == '3') { reverseright(i[0]); }
if (i[0] == '5') { stop(i[0]); }
if (i[0] == 'q') { end(); }
}
}
/* end of rccar.c */
and here are the remaining errors that I am getting.
Code:
shawn@shawn-desktop:~/Desktop$ sudo gcc -O2 -o rccar rccar.c
rccar.c: In function ‘main’:
rccar.c:124: error: stray ‘`’ in program
rccar.c:129: warning: ignoring return value of ‘read’, declared with attribute warn_unused_result
Not sure on why being root either, figured it was just in case.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339
Rep:
Quote:
Originally Posted by xeleema
I'm getting different errors myself. I've commented-out the Include for asm/io.h and corrected the ioctl line.
Code:
sysop$ gcc -O2 -o rccar rccar.c
rccar.c: In function 'end':
rccar.c:111: warning: incompatible implicit declaration of built-in function 'exit'
rccar.c:113: warning: incompatible implicit declaration of built-in function 'exit'
rccar.c: In function 'main':
rccar.c:117: warning: incompatible implicit declaration of built-in function 'exit'
/tmp/cccwFwJZ.o: In function `main':
rccar.c:(.text+0xd9): undefined reference to `outb'
rccar.c:(.text+0x10b): undefined reference to `outb'
rccar.c:(.text+0x13b): undefined reference to `outb'
rccar.c:(.text+0x16e): undefined reference to `outb'
rccar.c:(.text+0x19b): undefined reference to `outb'
/tmp/cccwFwJZ.o:rccar.c:(.text+0x1ce): more undefined references to `outb' follow
collect2: ld returned 1 exit status
sysop$
I also get the same errors when I try it as root;
Code:
root# gcc -O2 -o rccar rccar.c
rccar.c: In function 'end':
rccar.c:111: warning: incompatible implicit declaration of built-in function 'exit'
rccar.c:113: warning: incompatible implicit declaration of built-in function 'exit'
rccar.c: In function 'main':
rccar.c:117: warning: incompatible implicit declaration of built-in function 'exit'
/tmp/ccIVzpBr.o: In function `main':
rccar.c:(.text+0xd9): undefined reference to `outb'
rccar.c:(.text+0x10b): undefined reference to `outb'
rccar.c:(.text+0x13b): undefined reference to `outb'
rccar.c:(.text+0x16e): undefined reference to `outb'
rccar.c:(.text+0x19b): undefined reference to `outb'
/tmp/ccIVzpBr.o:rccar.c:(.text+0x1ce): more undefined references to `outb' follow
collect2: ld returned 1 exit status
thats odd i thought outb is a standard library function
@Danteleo
you must not have noticed there
is a junk ` symbol that needs to be removed
ioctl(0,TCSETS,`"wT"); the bold red part needs to be removed
shawn@shawn-desktop:~/Desktop$ sudo gcc -O2 -o rccar rccar.c
[sudo] password for shawn:
rccar.c: In function ‘main’:
rccar.c:129: warning: ignoring return value of ‘read’, declared with attribute warn_unused_result
/tmp/cc6lYHO9.o: In function `main':
rccar.c:(.text+0x11e): undefined reference to `outb'
rccar.c:(.text+0x150): undefined reference to `outb'
rccar.c:(.text+0x180): undefined reference to `outb'
rccar.c:(.text+0x1b0): undefined reference to `outb'
rccar.c:(.text+0x1e0): undefined reference to `outb'
/tmp/cc6lYHO9.o:rccar.c:(.text+0x210): more undefined references to `outb' follow
collect2: ld returned 1 exit status
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.