4

I want to create a simple Javascript program with a HTML interface. The program will run in Chrome. I will also use node-serialport and Node.js to comunicate with an Arduino. I have a HTML and JavaScript file done, but I have no clue how to run it, or how to implement Node.js or node-serialport, nor how to "start" the sever. Initially it will only be running locally, but eventually it may become a real sever. For now, how do I run all that locally?

EDIT: I'm using the sample code from http://brandontilley.com/2012/03/02/controlling-an-arduino-from-nodejs.html, with the CoffeeScript converted into JavaScript.

4
  • 2
    and how does the file look like? Commented Jun 17, 2012 at 4:20
  • 2
    you may want to look at node docs for info regarding installing and starting node.js Commented Jun 17, 2012 at 4:24
  • I have it installed in my system, I don't know how to implement it, and the Docs are foreign language to me Commented Jun 17, 2012 at 4:29
  • In case other programming languages are more familiar to you, you can build the gui in html/js and use flash or a java applet to provide socket connections. You can then connect to another program that listens on that socket(any programming language), and let that other program do the arduino interaction. getting node.js running sounds simpler though, unless you really want to control the arduino with something like c. Commented Jun 17, 2012 at 5:49

2 Answers 2

3

Lucas, glad you found the blog post useful; perhaps I should add this information to it.

Getting the sketch into your Arduino

Just fire up the Arduino application, paste in the sketch code, and hit "Upload." Should be all you need to do here.

Starting the Node.js Server

What operating system are you using this on? Finding out how to access your Arduino microcontroller via node-serialport will differ based on your OS.

In the source code, change the string value of port to be your Arduino's device (once you know it). Also, the script depends on Express and (of course) node-serialport from NPM, so run npm install express serialport in the directory where your JavaScript file is saved. Finally, run the file with node server.js (assuming server.js is the name of your file). Then you can access the server at http://localhost:8080.

Sign up to request clarification or add additional context in comments.

6 Comments

Great! Server started up and the script ran, but on going to localhost:8080 it only shows Cannot GET /
One other thing, how do I stop it?
Hmm, can you paste your translated JavaScript code on gist.github.com or something? It should send the index.html file. You can stop the server with Ctrl+C.
gist.github.com/2945632 EDIT: I think I might've found my problem, looking...
That definitely looks right; lines 38-40 should handle the root route.
|
1

You can use node.js to serve up HTML with Express. If your main Javascript file is called server.js, then run it by typing:

node server.js

at the command line.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.