Go Down

Topic: Using JavaScript to program arduino uno robotics project (Read 2675 times) previous topic - next topic

ApacheOmega

Feb 09, 2013, 01:52 pm Last Edit: Feb 09, 2013, 03:12 pm by ApacheOmega Reason: 1
I want to create a robotics project using JavaScript and HTML5 along with the Arduino Uno. My goal is to program the robotics platform with JavaScript because I want to be able to control the robot on either my cell phone, tablet or laptop  through a wireless Bluetooth connection.

If the Bluetooth connection isn't feasible I also have a mini tp-link usb router I can use also. The reason I want to use JavaScript is because I want to control via a web page/web connection through multiple platforms (what I mean is I want to be able to control the robot on android, IOS, windows or mac) and I know JavaScript and HTML5 is the only option to go multi platform.

What I wanna know is, A) is this possible and B)what resources or examples are out there for me to learn off of in order to get an idea for what to do. I've heard of people using Node.js somehow to achieve this.

IF ANYBODY OUT THERE KNOWS WHAT I'M TALKING ABOUT PLEASE POINT ME IN THE RIGHT DIRECTION.

Thank You!!!

PaulS

Quote
If anyone out there knows what I'm talking about could you please point me in the right direction.

Proper use of capital letters might help. Breaking that narrative into paragraphs might help.

Your assumptions that the only way to be able to access the robot from multiple platforms is to use Java is flawed. The Arduino would have to serve up the web page in order to be accessed from anywhere. That web page does NOT have to have any Java scripting on it.

The only role that I can see HTML5 or Java performing is to create visual representations of sliders. The Java script part does not have to be served by the Arduino. The page served by the Arduino would simply include a link to the Java script that was served from somewhere else. The resulting GET request made to the Arduino doesn't look any different because Java scripting was involved.

Regardless of which way you go, the Arduino must be programmed with C++.

ApacheOmega

#2
Feb 09, 2013, 02:58 pm Last Edit: Feb 09, 2013, 03:09 pm by ApacheOmega Reason: 1
Thanks for the reply Paul

so your saying my approach should be to program the robot in C++ (cause I can only use that anyways) and that connects to its own server. Then I build the GUI in JavaScript (if I decide to do that) and connect that to its own page and server. then I build a Link between the two in order for communication between the two servers (I hope I'm reading you right) with something like node.js i think.

Am I close to describing this?

What do you suggest I research or read up on?
What are some good tutorials that touches on everything you just described?

I'm open to any all suggestions.

(I'm trying to think of some other things to ask you but at the same time I don't want to over do it)

Thank You!!!

P.S. keep the suggestions coming. I need any over all blue print or game plan to start from and it sounds like you just gave me one.
just please go a little more in depth.

oh yeah, also I wanna have a camera view from the controller

and what is a better wireless connection (Bluetooth or A small wireless router like the one I mentioned)????

PaulS

Quote
so your saying my approach should be to program the robot in C++ (cause I can only use that anyways)

Yes.

Quote
and that connects to its own server.

No. The Arduino must BE a server in order for clients to send it information. Think of it as clients GETting the Arduino to GET moving, GET stopped, GET turning left, GET turning right, etc.

Quote
Then I build the GUI in JavaScript (if I decide to do that) and connect that to its own page and server.

You would build the GUI in JavaScript and store that on a server. The GUI doesn't "connect that to its own page", whatever that means.

The Arduino would then simply server up a page that says "The GUI is over there" in a way (using href) that the client understands to mean "Go fetch another page from another server".

Quote
then I build a Link between the two in order for communication between the two servers (I hope I'm reading you right)

No, you didn't read that right. I think you have a lot to learn about how client/server communication works before you will be successful on this project.

Start with creating a page on one server that is static. It does nothing but display an image from another server. Get a client on the phone, on the PC, and on the tablet to fetch the page from server one that contains the link to the picture on server two.

When you get that to work, then change to image link to a different kind of link, to the GUI code.

When you understand how to do that, then change server one to be the Arduino with Ethernet shield, serving the page that links the picture on server two. When you get that to work, then change to image link to the GUI link.

When that works, you'll have a much better idea of how to communicate from the phone, PC, and tablet to the Arduino.

Only then should you introduce bluetooth into the picture. Or, a WiFi shield.

Only after you understand what role, if any, bluetooth is going to play. My personal opinion is going to be that bluetooth will not work for a robot because of its extremely short range. Think about what bluetooth was invented for - wireless mice, keyboards, headsets, etc. How far from the PC is a wireless mouse useful? Can you see what the mouse is doing if you take it 10 feet from the PC? How about a hundred feet? Does a headset need to operate 100 feet from the phone? How would you dial a number from that far away?

Bluetooth is meant for very short ranges. Most devices are class A, with a range of 10 meters or less. Is a robot that can't get that far away going to be useful? Maybe. Fun? No.

What is your robot to do? That would have a lot to do with how far from the device on the other end of the wireless (bluetooth/Wifi/XBee) connection you would want the robot to be able to go. The availability of a suitable host, range, volume of data, and risk of connection loss will have a lot to do with deciding on what wireless system you choose.


Denbo

One way you could do this is to mount an Android phone that controls an Arduino.  The phone could also run a web server app that serves up all the html5/javascript/whatever goodness he desires.   

There are tons of examples of Arduino's being controlled by Android phones  (MIT for example:   http://appinventor.mit.edu/explore/stories/my-droid-robot-controlled-app-inventor.html)

Not saying this is the best way, its just a possibility.

Denbo

Actually this was posted on Adafruit  recently  Arduino MK802 Based Mobile Web Server Robotic Platform Controlled via javascript with node.js http://www.adafruit.com/blog/2012/12/24/arduino-mk802-based-mobile-web-server-robotic-platform-controlled-via-javascript-with-node-js/

zoomkat

Sounds like you are interested in web control of the bot with a video feed from the bot. Below is some recent discussion that has example code serving .js files from an SD drive on an arduino ethernet board. The bottom link has some info on making a simple bot using an inexpensive router that can support an IP cam. bottom is some simple web page control code.

http://arduino.cc/forum/index.php/topic,144675.0.html

http://www.lynxmotion.net/viewtopic.php?f=20&t=6343

Code: [Select]
//zoomkat 4-1-12
//simple button GET for servo and pin 5
//for use with IDE 1.0
//open serial monitor to see what the arduino receives
//use the \ slash to escape the " in the html, or use ' instead of "
//address will look like http://192.168.1.102:84 when submited
//for use with W5100 based ethernet shields

#include <SPI.h>
#include <Ethernet.h>

#include <Servo.h>
Servo myservo;  // create servo object to control a servo

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 102 }; // ip in lan
byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(84); //server port

String readString;

//////////////////////

void setup(){

  pinMode(5, OUTPUT); //pin selected to control
  //start Ethernet
  Ethernet.begin(mac, ip, gateway, gateway, subnet);
  server.begin();

  myservo.write(90); //set initial servo position if desired
  myservo.attach(7);  //the pin for the servo control
  //enable serial data print
  Serial.begin(9600);
  Serial.println("server servo/pin 5 test 1.0"); // so I can keep track of what is loaded
}

void loop(){
  // Create a client connection
  EthernetClient client = server.available();
  if (client) {
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();

        //read char by char HTTP request
        if (readString.length() < 100) {

          //store characters to string
          readString += c;
          //Serial.print(c);
        }

        //if HTTP request has ended
        if (c == '\n') {

          ///////////////
          Serial.println(readString); //print to serial monitor for debuging

          client.println("HTTP/1.1 200 OK"); //send new page
          client.println("Content-Type: text/html");
          client.println();

          client.println("<HTML>");
          client.println("<HEAD>");
          client.println("<TITLE>Arduino GET test page</TITLE>");
          client.println("</HEAD>");
          client.println("<BODY>");

          client.println("<H1>Zoomkat's simple Arduino button</H1>");
         
          client.println("<a href=\"/?on\">ON</a>");
          client.println("<a href=\"/?off\">OFF</a>");

          client.println("</BODY>");
          client.println("</HTML>");

          delay(1);
          //stopping client
          client.stop();

          ///////////////////// control arduino pin
          if(readString.indexOf("on") >0)//checks for on
          {
            myservo.write(40);
            digitalWrite(5, HIGH);    // set pin 5 high
            Serial.println("Led On");
          }
          if(readString.indexOf("off") >0)//checks for off
          {
            myservo.write(140);
            digitalWrite(5, LOW);    // set pin 5 low
            Serial.println("Led Off");
          }
          //clearing string for next read
          readString="";

        }
      }
    }
  }
}

Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.

ApacheOmega

Hey Denbo And Z-Cat

Is the arduGate a good place to start?
This is the link I found on that subject: http://www.arduinodev.com/software/ardugate/

It says its a web gate for Arduino that enables the use of JavaScript.
It sounds pretty ideal for me.
The Arduino uno platform I'm considering to use is here: http://www.robotshop.com/dfrobotshop-rover-tracked-robot-xbee-kit-8.html
I just need to decide which wireless connection I plan on using (wifi, Bluetooth or Xbee - which ever has the furthest range and is compatible with a cell phone, tablet and laptop) I'm thinking the router.

I'm checking out your links as we speak
I really appreciate all the help you guys are providing

I know what I want to do as far as the GUI. I just need some guidance on the other parts but My programming skills are decent it shouldn't be to hard to figure out (hopefully).
Like i told Paul earlier I just need an actual blue print on which steps to take and what procedures to follow (whats the best path to follow basically)

Thank You!!!

rwaldron

Maybe this will help you get started? https://github.com/rwldrn/johnny-five

Go Up