Topic: Arduino input

Hey all

I'm new to chumby (just turned it on!)
I want to use it in a project which needs a few extra methods of user input (rotary encoder, flip switches)
I was planning on using an arduino to interface these with Chumby
I found this post on getting serial drivers setup: http://forum.chumby.com/viewtopic.php?id=1207
but not sure if there's any way to get serial data into flash widgets
any ideas/experiences/broken dreams?

thanks!
elliot

Re: Arduino input

The "usual" mechanism to talk to the outside world is to set up a local web server and grab XML data from that.  The iPod support uses this mechanism.

Another option is to use Pipe Open to open up a driver file, and talk to it that way.

PipeOpen is discussed here: http://forum.chumby.com/viewtopic.php?id=3125

And I have an example of how to use it here: http://forum.chumby.com/viewtopic.php?id=3623

Re: Arduino input

Note that the "pipe" functionality is available to local movies, such at the Control Panel, but not widgets, which are considered network untrusted.

The HTTP mechanism that ChumbyLurker mentioned will work for widgets.

4 (edited by elliotwoods 2009-08-10 05:26:13)

Re: Arduino input

ok
i've had this working now using the following code:

pipeArduino = _pipeOpen( "cat /dev/ttyUSB0", "r" );

function fnArduinoRead()
{
    s = _pipeRead( pipeArduino );
    if (s != undefined && s != "")
    {
       sarr = s.split("\n");
       status.text="";
       for (i in sarr)
       {
           status.text += "[" + i + "]=" + sarr[i] + "\n";
           if (Number(sarr[i])>0)
           {
               fInput = (Number(sarr[i])/1023.0 - 0.2)/0.4;
               mcBG._alpha=100*fInput;           
               trace(fInput);
           }
       }

    }
}

setInterval(this, "fnArduinoRead", 40);

there's a seperate as file with all the asnative links:

_pipeRead = ASnative(5,193);
_pipeOpen = ASnative(5,191);
_pipeClose = ASnative(5,195);
_PlayAudio = ASnative(5,151);

this worked fantasitcally (i had one variable coming in over from arduino as a decimal)
but after rebooting chumby
i'm not getting anything on /dev/ttyUSB0 anymore
when i run

cat /dev/ttyusb0

i get no response
if arduino isn't plugged in then i get told that it doesn't exist
if i do

cat /dev/ttyusb0 | less

then i get loads of '@'s, constantly coming in
also, i notice that when cat is running, the lights on arduino spark up showing that transmission is happening
but nothing when cat is closed

any idea why i wouldn't get anything out of cat anymore?
when i connect arduino to my laptop i still get data coming out
i think maybe i need to set the baud rate etc on the chumby?

Re: Arduino input

one other thing is
when i used to run cat (when transmission was working)
if i started typing into the chumby terminal window whilst cat was running
the 'rx' light would flash up on the arduino
that doesn't happen anymore

Re: Arduino input

hmm, seems that (at the moment) if i dont have arduino plugged in when i start up then it's ok
if i have it plugged in on startup, and replug it in, then same problem
so.. any idea what's up?

Re: Arduino input

It looks like inittab in /etc runs gettywrap on /dev/ttyUSB0 on startup.  I'm guessing that's trying to connect to the USB serial port, then timing out, and respawning.  After five tries inittab will give up and go to sleep for a minute.  This is so that people can plug in a USB serial port like yours and get a serial console on it without needing to open up the Chumby.

Try doing this, which should close off the process listening to the serial port and make sure it doesn't come back:

touch /tmp/ttyUSB0.nogetty
killall gettywrap getty

Re: Arduino input

hmm, after that i still have gettywrap running when i check ps
and cat /dev/ttyUSB0 doesn't give anything
/etc/inittab is read only
is there a way of modifying that?

Re: Arduino input

ahh, spotted that getty sets the baud rate to 115200
which seems to stick after the app is closed
so changing my arduino app to run at 115200 and closing getty seems to work a bit
but isn't very stable
any advancements on the above method to disable getty on my precious usb serial?

Re: Arduino input

If you didn't mind also having a USB dongle plugged in at boot, you could put the following in a file at the root of the drive called "debugchumby" and leave it plugged in at boot:

#!/bin/sh
touch /tmp/ttyUSB0.nogetty

I believe (though haven't tested) that this will get executed before getty starts up.

Re: Arduino input

ah yeah that works
thanks lurker!