LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-05-2007, 02:45 PM   #1
Tlaloc888
LQ Newbie
 
Registered: Jun 2007
Posts: 4

Rep: Reputation: 0
Programming LED's with C


Hello

I am new to actually doing hardware programming and I do need some advice.
I need let's say 10 LED's to flash on and off at a given frequency controlled by the written program, usually aroun 5-13 Hz.

What programming language is best suited for this task? I was thinking of C since that is a language I worked with before.

What port is the easiest to use? Parallel port? USB port? If it is USB, how will I "tie" the LEDs to an USB cable?

If parallel port is a viable option, can it support such quick flashing speeds?

Thanks in advance.
 
Old 06-05-2007, 03:05 PM   #2
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Assuming your target architecture is X86 Linux, the most appropriate (high level) language for this kind of thing is probably C. You will need to use either '/dev/port' or 'ioperm()' to gain access to the hardware registers. By far the simplest, most ubiquitous hardware for this would be the parallel port. It will not, however, have enough power to drive a bunch of LEDs. You will need to suck some power out of another interface: game ports are good for this. Unless you write your access routines as kernel modules, you will have to run as root to make it work.
--- rod.
 
Old 06-05-2007, 03:24 PM   #3
Tlaloc888
LQ Newbie
 
Registered: Jun 2007
Posts: 4

Original Poster
Rep: Reputation: 0
Thanks for the info.
Yes, I use linux and C.
What about USB? I presume it is more complicated to use in a technical way than the parallel port right?
 
Old 06-05-2007, 05:18 PM   #4
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
While I have never bit-banged anything attached to a USB port, I do know that a lot of what makes USB friendly to end-users is the result of a lot of complexity in the underlying hardware and software. I would guess that USB would be somewhere near the last of the likely candidates for IO hacking.

--- rod.
 
Old 06-06-2007, 03:21 AM   #5
Tlaloc888
LQ Newbie
 
Registered: Jun 2007
Posts: 4

Original Poster
Rep: Reputation: 0
Well, basicly I just want 8 leds to flash on and off in a certain sequence. If you say that the parallel port does not have enought power to soup up the leds, what should I use then? Gameport?
I would presume buying a second-hand joystick, cutting loose the wires and attach them to my leds then.
 
Old 06-06-2007, 05:34 AM   #6
cyborg_jt
Member
 
Registered: Jan 2004
Location: New Zealand
Distribution: 2.6.11-gentoo-r3
Posts: 120

Rep: Reputation: 15
Try looking into the PIC16 microcontroller. I hear its pretty normal from jobs like that, but requires assembly.

I worked on a AT91SAM7 from amtel. We made a basic alarm system with IR, leds, and a keypad. Its written in C which makes it so easy, but a low level initialization has to be done which is why I hate assembly.
 
Old 06-06-2007, 06:25 AM   #7
veroaimeca
LQ Newbie
 
Registered: Jun 2007
Posts: 5

Rep: Reputation: 0
http://www.pink-martini.org/missions...rMeOJ7Lhf6Vu5L
 
Old 06-06-2007, 07:43 AM   #8
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,699

Rep: Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895
It is possible to drive LEDs with the parallel port. Have you googled for information?

School project or just for fun?
 
Old 06-06-2007, 10:54 AM   #9
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Technically, you can drive LEDs with the output bits on a parallel port, however their ability to source current is quite limited. However, a game port has a 5V output, used as excitation for joystick pot's, and if this is used in combination with the output bits greater current sinking capability, you can get greater brightness combined with less risk of releasing the magic smoke, and greater portability across different hardware. The digital logic used for almost all parallel ports is pretty consistent. The electrical characteristic varies significantly.
The parallel port is dead simple to use in an application such as this. Simply writing a byte to a single output register controls the 8 data bits of the data output register.
--- rod.
 
Old 06-07-2007, 12:26 AM   #10
The_Nerd
Member
 
Registered: Aug 2002
Distribution: Debian
Posts: 540

Rep: Reputation: 32
You would be wise to try to understand electricity and electronics a wee-bit before you started this project. If you want something simple, say just flashing LED's and doing nothing else, you can:

1) Buy a frequency generator, a transistor or two, make a simple circuit, and walla!

If you HAVE to use your computer:
2) COM port: Make the same circuit as above, but use the COM port to drive the transistor(s).

3) Parellel port, same as above

4) If you really don't want to make any circuit (which is crazy, since you are already making an LED grid... right?), then it would be best to use the USB port. The USB port supplies .1 AMP at +5 volts to every device attached. This would be plenty of power, since LEDs on the average use about 15-35mA, a .1 AMP supply should be sufficient to run about 5 LEDs simultaniously. Look here for more information: http://www.gizmology.net/LEDs.htm

I am fairly sure the USB is setup on any OS as a COM port. For example, USB port 1 might be COM 8. Also keep in mind that you can buy USB to COM (serial) adaptors, wich to the fancy conversion for you (they act exactly like a COM port). As far as I know (not a lot), you can open the COM port like you normally would, and read-write data. However, I do know that there are also low-level calls to get device headers, etc...

5) In most Linux distros, you can call a cool little command to set your keyboard LEDs, the command is called "setleds". You could write a quick C program that would call this command to make your keyboard lights dance.

6) You could use a micro-controller. Such as a pic, msp430 (an awsome controller), a basic-stamp controller, etc... But again, this would require a bit of electronic KNOW-HOW.

7) Buy something from the store that blinks

Last edited by The_Nerd; 06-07-2007 at 12:29 AM.
 
Old 06-07-2007, 07:05 AM   #11
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,699

Rep: Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895
Yes the parallel port is limited in current and one must be very careful since it can be damaged easily. Using the serial port for toggling status lines is a bit more complicated then the parallel port and therefore not as easy. For beginning electronics / programming it is much simpler to use the parallel port if one does not have access to microcontroller programmers etc etc.

You could use the USB port +5 VDC wiring for more power but interfacing is much more complicated and would not suggest using it for beginner simple circuits. USB is not the same thing as a serial port even though it uses a serial communication protocol.
 
Old 06-07-2007, 10:57 AM   #12
Tlaloc888
LQ Newbie
 
Registered: Jun 2007
Posts: 4

Original Poster
Rep: Reputation: 0
Thanks for all the info.
The_Nerd is absolutely right. I want to learn more about electrical stuff. Any good place to start in electrotehnics?
The leds are no school-project. Actually, I wanted to build myself some sort of "dream machine" based on some white papers I read in Brain Entertainment. And I want my own software to controll it. Basicly some leds that are flashing acording to a certain frenquency in tandem with sound. The leds would be tied to some opaque sun-glasses. Four leds for an eye, four leds for the other eye.
 
Old 06-07-2007, 11:29 AM   #13
vxc69
Member
 
Registered: Jul 2004
Distribution: Ubuntu
Posts: 387

Rep: Reputation: 33
Tlaloc888 your thread got me interested. I found some resources you might find useful.

This site will teach the basics of electronics in order to learn how to control devices using our own programs:
http://www.learn-c.com/

Here's a nice doc from the same site about building a test board that connects to an ISA port (though good luck finding a PC with one):
http://www.learn-c.com/buildit.doc

Although the doc is a little outdated, there are some good tips on creating circuits if you're new to all of this, like me.

Also Linux I/O programming mini-howto:
http://www.faqs.org/docs/Linux-mini/...ogramming.html

Hope you build your dream machine.


Cheers,
vxc
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Difference between Top Down programming & Bottom up programming minil Programming 1 06-17-2005 02:42 AM
got contact with AP - but no ping or led's t163r Linux - Wireless Networking 1 07-06-2004 03:08 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:31 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration