Go Down

Topic: JavaScript -> ? -> arduino (Read 2 times) previous topic - next topic

cman

I have a mega and a tl wr703n on the way.
I'd like to pull up a page hosted on the 703 and use JavaScript (ajax) to control the mega which will generate PWM.
I'm a web guy so this seems like a reasonable undertaking to me.
I have no experience with arduino though.  I am goin to run openwrt on the 703.

My question is this...
Can the arduino interface with JavaScript natively, or is there some kind of translator that has to sit between the js and the arduino? If so is that open source?
I feel like if I could find one example of say turning on a led with js then I would understand a bit better.

Any suggestions where to start?
I'm eager to start understanding.

Goofballtech

Arduino is built on c++. No javascript that i know of.

How do you plan to get the data from your router to the arduino? Perhaps UDP or TCP and a networking shield?

You can have the javascript output a packet\ that contains the information you need then have the arduino recieve that packet and use it to control whatever needs the PWM signal.

holmes4

You need to send/get data from the Arduino to and from the PC. You can do this in lots of ways. Via the comms port over e-net, WiFi and many others.

So the question is can you get javascript to talk over any of these things. Now if you had said java that would be easy.

@goffballtech - What the Arduino uses C/C++ does not matter at all!.

Mark

Goofballtech



@goffballtech - What the Arduino uses C/C++ does not matter at all!.

Mark


It matters very much if the OP's question was aimed at using
Quote
JavaScript (ajax) to control the mega which will generate PWM.


Javascript will not "control" the mega. Javascript will send a set of data that will be received by the mega and interpreted to produce the proper command. These are very different things. This is what the remaining portion of my reply was addressing.

cman

Hmm. I guess I need to be a little more clear, sorry about that. A pc won't be involved other than to use a browser to acces the webpage and manipulate a variable value.
The router will host the web page. The router will connect to the mega via USB. I would like the webpage to use JavaScript to trigger the arduino to generate pwm to speed up or slow down a motor based on values from the JavaScript.  So I guess my question may be how to I pass these variables from JavaScript to the arduino ... I've seen some custom stuff ... Like node.js.

I'm just wondering what is the standard way to get data from js to arduino?

Thanks for your help. I hate I don't know enough yet to even phrase the question correctly.

PeterH


I'm a web guy so this seems like a reasonable undertaking to me.


I haven't quite figured out what architecture you're imagining. Are you going to use the tl wr703n as a web server? Are you running a client (browser) on some remote system somewhere? Are you envisaging the JavaScript running at the web server or the client? How is the Arduino connected to this lot? If you're planning to access it via its USB port, what's it plugged into? If not, how is it to be connected?

I only provide help via the forum - please do not contact me for private consultancy.

holmes4

There are a number of threads on using xml/html to talk to Arduino's may be they willl help?

But I'd just use a java applet.

Mark

cman

#7
Sep 17, 2012, 01:33 am Last Edit: Sep 17, 2012, 02:08 am by cman Reason: 1
XML huh? Well that's something I understand! I was hoping there was a way to pass straight into the c/c++ from js without having to write it out to a file to be read back in.

Just to clarify the architecture.
The router will accept wifi connections.. From a pc or such. It will also have a web server running on it. So there will be a web page on the webserver that allows you to manipulate a variable. For the sake of argument let's say you are changing a number from 1-10. Each time the user changes the number the info will be relayed to the webserver using Ajax.

The router will be connected to the mega via USB. I'd like to take that number that has just been received from the web and pass it into the mega to be used to adjust a PWM output being used by a motor

Docedison

I've never seen a router with a usb port for Ethernet connectivity. I've seen a lot of Arduino's with Ethernet shields, Wi-Fi shields, X-Bee shields but never Ethernet across A USB port.

Doc
--> WA7EMS <--
"The solution of every problem is another problem." -Johann Wolfgang von Goethe
I do answer technical questions PM'd to me with whatever is in my clipboard

PeterH


Just to clarify the architecture.
The router will accept wifi connections.. From a pc or such. It will also have a web server running on it. So there will be a web page on the webserver that allows you to manipulate a variable. For the sake of argument let's say you are changing a number from 1-10. Each time the user changes the number the info will be relayed to the webserver using Ajax.

The router will be connected to the mega via USB. I'd like to take that number that has just been received from the web and pass it into the mega to be used to adjust a PWM output being used by a motor


You've described how the change gets as far as the web server. How does it get from there to the Arduino? Will your router have the Arduino USB drivers installed, and provide support for server-side scripting or web apps etc that would enable you to run code on the web server that received the updates (via your Ajax framework) and write it to the Arduino's serial port? PHP seems to work OK at this, but I don't know and wouldn't assume that a router supports it. Or does the Arduino have its own NIC?
I only provide help via the forum - please do not contact me for private consultancy.

fenix8k

i do what u whant exept for the part of the router xD i don t remember what is the name but i have a arduino mega and there is and sketch and code for it that display data and let u control it from a SWF xD using javascrip is very nice but i get boring and go to another thing if i remember the name of the project or something i post it here :P

Look in google arduino and javascrip or something like that

danb35

Is your keyboard missing the punctuation keys?

fenix8k


Is your keyboard missing the punctuation keys?


yes sorry my keyboard work very bad and some keys work really bad and doesn't write fine, i'm at work xD

rockwallaby

Hi cman and others,

Cman, your idea of using the router with Open-WRT is valid and I have looked into this recently, although I have a Cisco/Linksys WRT-54GS with DD-WRT firmware.
My current project building web access to my Arduino based hardware for my home solar/micro-hydro SCADA system, so that I can check in while I am else where on the globe.

Now I did come across a blog where I guy was using some other router, maybe a TP-Link with dd-wrt/open-wrt configured as a server and talking to an Arduino via USB I recall.
I don't have the link for that article it seems, but it can be found on the forums of dd-wrt I think if you're interested.
But I ran into problems with installing a SD card into the router for storage of files, namely web pages for serving.
So I started to re-think how I could do this....

I am using a Mega, though mine is the Freetronics Mega, which has ethernet and SD all on it.
So after thinking about how best to set this up, initially like you, I was going to use the router as my web server, but concluded that for this project I will use the Arduino as the web server.
My aim is making the Arduino the web sever to serve up pages. The project will use JQuery for AJAX functionality and PHP and some other libraries for history trending.
Now I wanted to also make it mobile friendly, so I am also looking at JQuery-mobile and have started building the user interface mock up.

My question for you is, is this concept of how I am doing it make any sense for your idea?
Would it not be easier to do away with the router as server and have your Mega be the server, thus potentially simplifying your work in terms of code?
There are a number of good articles on having your Arduino playing web server.

Just for your interest, a lot of my ideas are coming from this project, the hydrobot - http://www.cs.helsinki.fi/u/ljlukkar/hydrobot/
Check out his web interface, I really like it http://www.cs.helsinki.fi/u/ljlukkar/hydrobot/dummyui/#

I will be posting soon a new thread on my project as I am needing some advice in various aspects.

rockwallaby ... le printemps est là   :smiley-mr-green:

Go Up