1 (edited by dployed 2010-01-02 16:59:50)

Topic: Trigger for Arduino from Flash widget

I would like to trigger an action with the Arduino from my Flash widget. (p.e. if i press a button on the Chumby, the arduino lights an LED for 5 seconds..).

As I only need one trigger and I have zero knowledge in linux programming I try to avaoid a "real" serial communication between the chumby and the arduino as described in other posts here.

To give you an example, I used the headphone jack and my Flash widget played a sound, the arduino read its analog input and started the action. This worked perfectly well as long as the Arduino used another power source, but as soon as I powered the arduino from the chumby via USB it made some strange noises and the trigger did't work anymore. (I think it has sth. to do with a kind of interference between the sound and the power loop..?).

Can anyone think of a way to avoid the above mentioned interference?
Or another way to send a signal to the arduino (somehow via usb)?

2 (edited by unwiredben 2010-01-04 10:25:57)

Re: Trigger for Arduino from Flash widget

You could use an Ethernet shield on the Arduino with the Webduino library to put the device on your network, then have the flash widget on the Chumby do a XML request to the Arduino to trigger the action.

Re: Trigger for Arduino from Flash widget

Thats a good idea,
but there must be some other (simpler) hack to this..

i'll keep searching..

4 (edited by inio 2010-01-03 22:24:00)

Re: Trigger for Arduino from Flash widget

It seems like there should be a way to get at the serial pins on the corner of the board as a regular TTY instead of a console.  That would let you do simple things from flash (file IO) to talk to the arduino, little/no linux programming required.

Re: Trigger for Arduino from Flash widget

wow, that would be perfect, if someone could tell me how to use one of those as digital out from flash!

Thank you inio

Re: Trigger for Arduino from Flash widget

Using the TTL-level serial lines would be ideal.  You'd need to have a cable that either ignored the DTR signal or allowed you to switch it off, since current boards use that as a reset signal, something you'd not want to assert while sending useful data to the device.

Re: Trigger for Arduino from Flash widget

Did you want serial-out or a managed GPIO?  Conveniently enough, the two pins that are used for the serial port can also be used as PWMs, and you can also treat them as GPIOs.

Currently, flash widgets communicate to the hardware through a variety of hooks, ranging from ASnative() calls that require we patch the flashplayer, to http servers that you simply connect to and pull data from.

I think that for your purposes, a simple shell script that lives in the cgi-bin directory might be the easiest way to do it.  What would you like it to do?

Re: Trigger for Arduino from Flash widget

All I need is a digital out (on or off).

If i push a button in the flash widget its on if i push again it is off - no more than that (no data transfer, no input).
Thats why i look for the simplest possible hack.

Re: Trigger for Arduino from Flash widget

We should be able to throw together a cgi-bin you could use.  It should be really simple, and use regutil.  Unfortunately, I won't be in a position to come up with such a script until Monday.

The pins can drive anywhere from 4mA to 16mA.  Does it matter how much current, or will pretty much any binary signal do?  In any case, it really should be a matter of only a few lines of shell script.  The pins you're interested in are, I believe, bank 1, pins 26 and 27.

I think the script will be something like:

pins_on.sh:

#!/bin/sh
regutil -w HW_PINCTRL_MUXSEL3_SET=0x00f00000
regutil -w HW_PINCTRL_DOUT1_SET=0x0c000000
regutil -w HW_PINCTRL_DOE1_SET=0x0c000000

pins_off.sh:

#!/bin/sh
regutil -w HW_PINCTRL_MUXSEL3_SET=0x00f00000
regutil -w HW_PINCTRL_DOUT1_SET=0x0c000000
regutil -w HW_PINCTRL_DOE1_CLR=0x0c000000

To change only the rx pin, change 0x0c000000 to 0x04000000, and to change only the tx pin, change it to 0x08000000.

Re: Trigger for Arduino from Flash widget

The current doesn't matter, any binary signal will do.

How do I run shell scripts from within a flash widget?

Thank you!

Re: Trigger for Arduino from Flash widget

Put them into /psp/cgi-bin, make sure they're executable (chmod a+x /psp/cgi-bin/pins_off.sh /psp/cgi-bin/pins_on.sh), then from flash use an XML connection to access http://localhost/cgi-bin/custom/pins_off.sh.

Re: Trigger for Arduino from Flash widget

first of all thank you for helping me out with this.
I was only able to try it today, but without success.

It would be very kind if someone could help me narrow down the possible source of the error.

I put the scripts ChumbyLurker posted into the psp/cgi-bin/ folder and made them executable.

from the button in my flash widget i call the following code

myButton.onRelease = function() {
   arduino_xml = new XML(); 
   arduino.ignoreWhite = true;
    arduino_xml.load("http://localhost/cgi-bin/custom/pins_off.sh");
}

but if i run it nothing happens (if i read the TX pin it has a constant 3v output - executing the pins_off.sh should switch the TX output off, right?).

There was sth that made me wonder. I tried to execute the script in the terminal via

sh pins_off.sh

(don't know if that should be working)
then I get the following error:
-sh: regutil: not found

Re: Trigger for Arduino from Flash widget

Yeah, it's best to try out the CGI scripts from your own browser first to verify that they work before trying from Flash, since Flash also has this crossdomain.xml security mechanism you'll need to handle.

regutil should be in /usr/bin which is in the standard path.  If you try running "regutil" by itself on the command line, what do you see?

14 (edited by dployed 2010-01-15 08:13:05)

Re: Trigger for Arduino from Flash widget

standard path you mean on the chumby?

I i enter it in the terminal shell I get the same error:
-sh: regutil: not found

Re: Trigger for Arduino from Flash widget

@dployed - which chumby are you doing this on? regutil is only in chumby one, not the classic.

Re: Trigger for Arduino from Flash widget

ahh.. ok
I have a chumby classic 3.8

I hope there is an alternative to regutil?

Re: Trigger for Arduino from Flash widget

I'm not very familiar with the multifuction pin controller on the Classic, but in looking at the datasheet, it looks like the UART is connected to pins PE13 and PE12.

I'd guess (but haven't checked) that you'd need to set bits 12 and 13 in PTE_DDIR to make them outputs, and do the same for PTE_GIUS to make it a GPIO and not a serial port.  If you need a pullup, set the corresponding bit in PTE_PUEN.  It looks like you might also need to make it a GPIO pin rather than a serial port by setting bits 0x0f000000 in PTE_OCR1, but I'm not sure about that.

Then, to set the pin high, set either bit 12 or 13 (depending on which pin) in PTE_DR.

So a modified script for the Classic to turn both on might look like:

regutil -w PTE_DDIR=0x00003000
regutil -w PTE_GIUS=0x00003000
regutil -w PTE_OCR1=PTE_0x0f000000
regutil -w PTE_PUEN=0x00003000
regutil -w PTE_DR=0x00003000

And to turn both back off, just clear out PTE_DR.

Re: Trigger for Arduino from Flash widget

Thank you and sorry it took me so long to get back, but I didn't have time until today to try it.

What exactly do you mean by clear out PTE_DR?
This ?:

/psp/cgi-bin/regutil -w PTE_DR=0x00000000

The regutil command seems to work now as i get the following feedback when I call pins_on.sh / pins_off.sh in the terminal:

chumby:/psp/cgi-bin# sh pins_off.sh
Setting 0x10015400: 0x00000000 -> 0x00003000 ok
Setting 0x10015420: 0x00000000 -> 0x00003000 ok
Setting 0x10015404: 0x00000000 -> 0x00000000 ok
Setting 0x10015440: 0x00000000 -> 0x00003000 ok
Setting 0x1001541c: 0x00000000 -> 0x00000000 ok

chumby:/psp/cgi-bin# sh pins_on.sh
Setting 0x10015400: 0x00000000 -> 0x00003000 ok
Setting 0x10015420: 0x00000000 -> 0x00003000 ok
Setting 0x10015404: 0x00000000 -> 0x00000000 ok
Setting 0x10015440: 0x00000000 -> 0x00003000 ok
Setting 0x1001541c: 0x00000000 -> 0x00003000 ok

but the voltage on the tx pin stays the same.

I used the following scripts:

pins_on.sh

#!/bin/sh
/psp/cgi-bin/regutil -w PTE_DDIR=0x00003000
/psp/cgi-bin/regutil -w PTE_GIUS=0x00003000
/psp/cgi-bin/regutil -w PTE_OCR1=PTE_0x0f000000
/psp/cgi-bin/regutil -w PTE_PUEN=0x00003000
/psp/cgi-bin/regutil -w PTE_DR=0x00003000

pins_off.sh

#!/bin/sh
/psp/cgi-bin/regutil -w PTE_DDIR=0x00003000
/psp/cgi-bin/regutil -w PTE_GIUS=0x00003000
/psp/cgi-bin/regutil -w PTE_OCR1=PTE_0x0f000000
/psp/cgi-bin/regutil -w PTE_PUEN=0x00003000
/psp/cgi-bin/regutil -w PTE_DR=0x00000000

I could imagine that the pins_off.sh script is wrong (as I didn't know how to clear the PTE_DR)

Re: Trigger for Arduino from Flash widget

Okay, I just got out the multimeter and cracked open a Classic.  Here's what I've found.

First, use this script to set the pins to GPIOs:

#!/bin/sh
# Enable GPIO for bits 12 and 13
/psp/cgi-bin/regutil -w PTE_GIUS=0x00183020

# Set bits 12 and 13 as outputs.
/psp/cgi-bin/regutil -w PTE_DDIR=0x00e07520

# Set bits 12 and 13 to use PTE_DR for their input
/psp/cgi-bin/regutil -w PTE_OCR1=0x0f000c00

Then, use this script to turn both pins on:

#!/bin/sh
/psp/cgi-bin/regutil -w PTE_DR=0x00003020

And use this script to turn both off:

#!/bin/sh
/psp/cgi-bin/regutil -w PTE_DR=0x00000020

I'm thinking it may be very, very useful to add a "set" and "clear" argument to regutil to be able to toggle individual bits, but for now you'll need to come up with your own scripts to turn individual pins on and off.

Re: Trigger for Arduino from Flash widget

thanks again for your efforts..
I don't need to toggle individual bits I only need on signal on or off i can read with the multimeter and thanks to you i feel I am really close to solve this, but when I execute this setGPIO.sh script via the terminal:

#!/bin/sh
# Enable GPIO for bits 12 and 13
/psp/cgi-bin/regutil -w PTE_GIUS=0x00183020

# Set bits 12 and 13 as outputs.
/psp/cgi-bin/regutil -w PTE_DDIR=0x00e07520

# Set bits 12 and 13 to use PTE_DR for their input
/psp/cgi-bin/regutil -w PTE_OCR1=0x0f000c00

i get the following response and my Chumby turns off !?!

chumby:/psp/cgi-bin# sh setGPIO.sh
Setting 0x10015420: 0x00000000 -> 0x00183020 ok
Setting 0x10015400: 0x00000000 -> 0x00e07520 ok
Setting 0x10015404: 0x00000000 -> 0x0f000c00 ok

Re: Trigger for Arduino from Flash widget

That seems really strange. Especially since all of the values for you seem to be defaulting to 0x00000000.  You've first loaded the enable_regutil.ko file before running regutil, correct?

Basically, the values that I put down in the setGPIO script were me first reading the registers, then manually setting bits 12 and 13, then setting the registers.

Re: Trigger for Arduino from Flash widget

Ok figured it out. I put insmod enable_regutil.ko in the debugchumby file to load it on startup.

So now everything works fine. EXCEPT:

I want to switch the pins on and off via the widget.
This works perfectly fine, from my computer, from chumby.com website, from another website, and via terminal.

But it's buggy when I use it from chumby directly.
So the first buttonpress works as it should (if I start with pins high it calls pins_off.sh and the voltage is set to 0.0 ; If I start with pins low it calls pins_on.sh and the voltage is 3.19).

But if I press the button again the voltage on my multimeter is jumping around.
That's really strange as this is only happening from the chumby itself. All above mentioned ways work perfectly.

Does anybody have any idea what's causing this bug?

Heres the flash code

myButton.onRelease = function() {
    if (pins){
        var arduino_xml:XML = new XML();
        arduino_xml.ignoreWhite = true;
        arduino_xml.load('http://localhost/cgi-bin/custom/pins_off.sh');
    } else {
        var arduino_xml2:XML = new XML();
        arduino_xml2.ignoreWhite = true;
        arduino_xml2.load('http://localhost/cgi-bin/custom/pins_on.sh');
    }
    pins = !pins;
}