Pages: [1]   Go Down
Author Topic: Linux Digital I/O ( Serial without processing / openframeworks )?  (Read 1515 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi all,

Ok, so some brief background on the project:
Overall trying to send images over a LASER.  This is similar to data transmission over fiber optics but through air.  Two of my major objectives are develop a program to grab a frame from the webcam, decompress that jpeg image, and then send the raw RGB data to a receiving computer via pulses on a LASER. 

What I have done:
Currently I'm working in Ubuntu Linux with Eclipse IDE and I have a C program written to use the libjpeg library and grab a frame, decompress it, and I have an array of RGB values ready to be transmitted. 

The problem:
At this point I'm looking for a form of digital I/O from Linux.  I just need a ground output and a digital pin to pulse high and low to transmit binary data hopefully at a rate of 1MHz. 

Various Solutions:
- Parallel port: Apparently this port is relatively easy to use and would work well for what I want however this port isn't used anymore.  My desktop that I'm developing on doesn't have a parallel port and hopefully when I port this project to a laptop that won't have this port either so this solution doesn't seem very likely at this point which is why i'm looking for an alternative.

- USB-to-Serial Breakout boards: I've looked at http://www.sparkfun.com/products/718 from spark fun, but I've never used one and would like some feed back on how easy those are to use.

- Using Arduino + Firmata: So this solution is the main reason I'm posting this.  I would like to be able to write to the usb connection from my C program in Eclipse in a Firmata format that Arduino can process to directly control any of the digital pins.  Now this is where I am kind of confused about what Firmata does.  Almost every resource I have previously found says to use Processing or OpenFrameworks to send the serial data, I don't believe I can use either of these because I'm developing my own program with the libjpeg decompression and stuff and I need the serial part to work with this.  I would have to save all my data to a file from my C program then open back up from a processing script and then send it and I don't want to do that.  I would like all this ability to be contained within my C program in Eclipse. From my understanding Firmata is just like a standard format for serial data that arduino can understand so technically if i knew what bytes needed to be sent I could send the same data which would be sent through Processing with my own code.

Another strict consideration is that I need this digital pin to be pulsed at very very consistent intervals so if sending firmata signals is inconsistent maybe that whole idea won't work. 

Direct Questions:
1. Would going with a USB-to-Serial breakout board be simpler than messing with Firmata / Arduino.  If so why?  Maybe higher frequency?
2. Is my understanding of Firmata correct, can I send commands to control Arduino within a generic C program without Processing/Openframeworks libraries?
3. Would there be any advantage to using a Windows environment for image decompression and digital output?  ( I don't think libjpeg can be installed in windows but idk )
4. Is there a better solution to achieving digital output from Linux than those I have proposed?

Any help is appreciated,
- Matt

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 32
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If your Arduino is one with a USB connector, you don't need to run Firmata, and you don't need to use a separate USB-to-serial converter -- you can just use the USB connection that's already there -- addressed as "Serial" from the code running on the Arduino and probably /dev/ttyUSB0 or /dev/ttyACM0 from Linux.

Just keep in mind that Linux likes to raise/lower DTR whenever a process opens or closes the serial device, which will make the Arduino reset unless you open the reset circuit.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok, I do have an Arduino Duemilanove with as USB port so that's good.  http://www.arduino.cc/en/Main/ArduinoBoardDuemilanove.

I think I am still confused about Firmata.  I tried looking on their Wiki but it seems a lot of the links are broken.  I thought Firmata just defined a set of serial instructions Arduino could understand and was not a separate program so when you say "run Firmata" that makes me unsure.  Perhaps I need to understand what exactly Firmata's purpose is to better explain my situation.

Just to be clear.  I'm hoping to send a signal from my C program in Eclipse through the USB which would directly tell Arduino to toggle a digital pin.  I was under the assumption Firmata was the only way to do this and I would need to include the Firmata classes / headers in my C program somehow so that when I call digitalPin( PIN_NUM, HIGH ) on my computer the compiler will call the underlying function which translate that in to the corresponding serial command.

I've used Processing before to pass Red Green and Blue PWM values to Arduino for an RGB LED strip so I'm familiar with parsing serial bytes received by the Arduino but I was hoping to avoid that.  For instance, instead of me sending the bytes, then having Arduino determine what those bytes mean, I could have just wrote something like arduino.analogWrite( Rpin, PWMvalue ) for each color and the Firmata would have interpreted that behind the scenes and accomplished the same result.

I hope I'm making sense,  smiley-confuse .
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 549
Posts: 46090
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I think I am still confused about Firmata.

I'm familiar with parsing serial bytes received by the Arduino but I was hoping to avoid that.  For instance, instead of me sending the bytes, then having Arduino determine what those bytes mean, I could have just wrote something like arduino.analogWrite( Rpin, PWMvalue ) for each color and the Firmata would have interpreted that behind the scenes and accomplished the same result.
That's what Firmata does. What are you confused about?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm really sorry if I'm frustrating you guys, I really appreciate the help.

Ok, so in Processing you can setup an Arduino object and call functions on that object as if you were programming directly in the Arduino environment,  I would like to recreate this effect in my generic C program.  I was expecting to have to download some C-style Firmata library for linux, add that to my project, include something like Firmata.h, open up a serial port and linux and somehow tell the Firmata/Arduino object to use the linux special file pointing to the serial port.  On arduino I would only have to load the Firmata scketch and let it wait for commands.  On my program I would just have some timer on a microsecond interval and then every event it would send the current bit in the RGB sequence and increment the pointer to the next bit. ( I still have to figure out a method to send binary data since you can only go down to characters but I assume this can be done )  In summary this option puts all the complexity on the linux side and simple passing of values to ports on Arduino.

The other option is to open up a UBS port in linux regularly and write characters to it without any fancy Firmata commands. Then on the Arduino side I could just parse these commands and toggle the digital pin based on the received character in Arduino.  I don't think this option would work because I was thinking there would be an inconsistent pulse width between each serial read command that I won't be able to adjust for.  In summary this option makes the linux side very simple and puts a lot of complexity on the Arduino side which I assumed would be unreliable.

Again, if there is another solution to get digital pin output from linux/windows that will get rid of all this Firmata/Arduino nonsense I am open to it.  I'm ideally looking for the solution that offers the most consistent pulsewidth and the highest frequency, whatever that may be.

I hope that makes more sense.
- Matt
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 549
Posts: 46090
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Firmata is going to be sent something that says "Yo, Arduino, set digital pin 7 HIGH", or "Yo, Arduino, what is the reading of analog pin 3".

You can have your PC application send similar commands, and program the Arduino to parse the statements to figure out what to do, and return appropriate responses.

If you are going to use a different protocol (which I always recommend, so YOU understand what is being sent and received), you might want to use something that is a bit easier to parse than my flippant examples above.

<R:D:1> ==> Read digital pin 1, and return the value
<S:2:0> ==> Set pin 2 to 0
<S:9:135> ==> Set pin 9 to 135, using analogWrite
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 32
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

But the question remains -- why do it at all? Don't have the PC send commands to change this pin or change that pin. Have the PC send the *data* that you want to transmit, and have the Arduino listen on the serial port for data and run the code that actually manipulates the pins. Trying to bit-bang across USB is just silly and unnecessary.
Logged

Australia
Offline Offline
Full Member
***
Karma: 6
Posts: 161
You dont have to touch powerlines for them to kill you, even looking at them for too long will make them angry.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I gather you have researched Free Space Optics? there are some big commercial uses of this technology you can look at for ideas as well as a fair amount of open source based stuff.
Logged

"Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent di

Pages: [1]   Go Up
Jump to: