Ok, I give in. Need help coding my robot

I am brand new to coding. I have looked at some tutorials on how to control LEDs, and had to kinda figure servo coding by myself. What I really want to do is control servos from my nvidia shield tablet through wifi but I have no clue how to do the code at all. Can anyone help me understand how to code for this?

The hardware I have:

Arduino Due
CC3000 WiFi Breakout board
Nvidia shield tablet
16 channel 12-bit servo driver
3 Tower Pro MG90S metal gear servos

I have all the hardware wired and everything has been tested successfully. If pictures or more information is needed, pls ask and I will post it.

I am brand new to coding.

Get a good book or online tutorial and study the basics of coding. You will save time that way, compared to the current fashion of writing random nonsense and hoping to get lucky.

As for the hardware, learn one thing at a time. Don't try to do everything at once. Learn how your servos work. Then learn how your servo driver works.

Hardware is not a problem for me, I understand the hardware side of things. I just need help in code of how to connect my tablet directly to the CC3000 board through wifi to control the servos that move the robot. The robot is using WiFi cause I need the range since the robot will cover a lot of ground in a short amount of time.

An example code would be nice.

Does your equipment have ethernet/internet capability?

Yes, I have successfully ran the buildtest code on the CC3000 and pinged the adafruit website. The tablet connects to the internet via wifi. I also made my tablet into a hotspot through its menu and tried the same buildtest code with different wifi credentials and it connected to the tablet successfully. I can connect to the internet with cc3000 using the build test, and i am able to connect to my nvidia shield tablet using the buildtest code but it doesn't connect to the internet cause the tablet is just the wifi version and not the LTE one.

What role is the Arduino to have? Is it going to be a server or a client?

What role is the tablet going to have? Is it going to be a server or a client?

You can't begin to write code until you have requirements. "Make it work" is a goal, not a requirement.

Sorry for the late reply. Just woke up. Thanks for the reply.

The host and client stuff is where my lack of knowledge of this sort of stuff begins. I don't know which is to be host or client. There is a tutorial from adafruit for a WiFi controlled robot that I have been trying to figure out for the last couple of days but I don't now how to get it working for my purposes.

OK, here is my attempt to understand what client and host is. The server, is the device that is being connected to and client is the device connecting to server. If I am correct in this, then the tablet is client and the arduino is server. I hope I didn't just make myself look like an idiot.

So you need to start with a working example server sketch for that WiFi breakout, and modify
it to control the servos.

I don't know which is to be host or client

Your PC is the client. The arduino.cc organization is running a server.

Your web browser is a client. google is running a server.

Does that help?

If you want to send data to something (Hey, google, help me with the terms xxx, yyy, and zzz), and get a response (Here's a list of sites that might be useful), then you want to be a client, talking to a server.

The tablet is to be used to send data ("Turn right") to the Arduino-as-server, with the expectation that the server will return the appropriate response, such as saying "Yes, I turned left". (Or maybe not exactly that response. 8)).

"Your PC is the client. The arduino.cc organization is running a server.

Your web browser is a client. google is running a server.

Does that help?"

Yes, that does make it easier to understand.

"If you want to send data to something (Hey, google, help me with the terms xxx, yyy, and zzz), and get a response (Here's a list of sites that might be useful), then you want to be a client, talking to a server."

Yup, my tablet is the client connecting to the arduino which is the server.

"The tablet is to be used to send data ("Turn right") to the Arduino-as-server, with the expectation that the server will return the appropriate response, such as saying "Yes, I turned left". (Or maybe not exactly that response. 8))."

That's the problem, I don't know how. I have been trying to merge my servo code with some WiFi code I got from a tutorial here Introduction | WiFi Controlled Mobile Robot | Adafruit Learning System but nothing works and I don't know what I am doing.

I have been trying to merge my servo code with some WiFi code...but nothing works and I don't know what I am doing.

Some things you are NOT doing are:

  1. Posting code
  2. Explaining what the code ACTUALLY does
  3. Explaining how that differs from what you want

here is the code i have been trying to understand

// Robot test via aREST + WiFi

#define NUMBER_VARIABLES 1
#define NUMBER_FUNCTIONS 5

// Libraries
#include <Adafruit_CC3000.h>
#include <SPI.h>
#include <aREST.h>
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>

Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();

uint8_t servonum1 = 0;
uint8_t servonum2 = 1;
uint8_t servonum3 = 2;

#define SERVOMIN  152
#define SERVOMAX  575

// CC3000 pins
#define ADAFRUIT_CC3000_IRQ   3
#define ADAFRUIT_CC3000_VBAT  5
#define ADAFRUIT_CC3000_CS    10

// CC3000 instance
Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT);

// Create aREST instance
aREST rest = aREST();

// The port to listen for incoming TCP connections 
#define LISTEN_PORT           80

// Server instance
Adafruit_CC3000_Server restServer(LISTEN_PORT);

#define WLAN_SSID       "HOME-8970"
#define WLAN_PASS       "lkasdfhvgjnajokvnasdvgp;oijash#"
#define WLAN_SECURITY   WLAN_SEC_WPA2

// Variable to be exposed to the API
int distance;

void setup(void)
{  
  // Start Serial
  Serial.begin(9600);
  Serial.begin(115200);
  
  // Give name to robot
  rest.set_id("1");
  rest.set_name("robot");
  
  // Expose variables to REST API
  rest.variable("distance",&distance);
  
  // Expose functions
  rest.function("forward",forward);
  rest.function("backward",backward);
  rest.function("left",left);
  rest.function("right",right);
  rest.function("stop",stop);
  
  // Set up CC3000 and get connected to the wireless network.
  if (!cc3000.begin())
  {
    while(1);
  }
  
  if (!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) {
    while(1);
  }
  while (!cc3000.checkDHCP())
  {
    delay(100);
  }
   
  // Start server
  pwm.begin();
  restServer.begin();
  Serial.println(F("Listening for connections..."));
  pwm.setPWMFreq(60);
  
  displayConnectionDetails();
  
  // Init sensor
  //dht.begin();
  
}

void loop() {
  
  // Handle REST calls
  Adafruit_CC3000_ClientRef client = restServer.available();
  rest.handle(client);
  
  // Check connection
  if(!cc3000.checkConnected()){while(1){}}
}

// Forward
int forward(String command) {
  
  send_motor_command(servonum1, 0, map(0, 0, 180, SERVOMIN, SERVOMAX));
  send_motor_command(servonum1, 0, map(45, 0, 180, SERVOMIN, SERVOMAX));
  send_motor_command(servonum1, 0, map(90, 0, 180, SERVOMIN, SERVOMAX));
  send_motor_command(servonum1, 0, map(135, 0, 180, SERVOMIN, SERVOMAX));
  send_motor_command(servonum1, 0, map(180, 0, 180, SERVOMIN, SERVOMAX));
  send_motor_command(servonum2, 0, map(0, 0, 180, SERVOMIN, SERVOMAX));
  send_motor_command(servonum2, 0, map(45, 0, 180, SERVOMIN, SERVOMAX));
  send_motor_command(servonum2, 0, map(90, 0, 180, SERVOMIN, SERVOMAX));
  send_motor_command(servonum2, 0, map(135, 0, 180, SERVOMIN, SERVOMAX));
  send_motor_command(servonum2, 0, map(180, 0, 180, SERVOMIN, SERVOMAX));
  send_motor_command(servonum3, 0, map(0, 0, 180, SERVOMIN, SERVOMAX));
  send_motor_command(servonum3, 0, map(45, 0, 180, SERVOMIN, SERVOMAX));
  send_motor_command(servonum3, 0, map(90, 0, 180, SERVOMIN, SERVOMAX));
  send_motor_command(servonum3, 0, map(135, 0, 180, SERVOMIN, SERVOMAX));
  send_motor_command(servonum3, 0, map(180, 0, 180, SERVOMIN, SERVOMAX));
  return 1;
}

// Backward
int backward(String command) {
  
  send_motor_command(servonum1, 0, map(180, 0, 180, SERVOMIN, SERVOMAX));
  send_motor_command(servonum1, 0, map(135, 0, 180, SERVOMIN, SERVOMAX));
  send_motor_command(servonum1, 0, map(90, 0, 180, SERVOMIN, SERVOMAX));
  send_motor_command(servonum1, 0, map(45, 0, 180, SERVOMIN, SERVOMAX));
  send_motor_command(servonum1, 0, map(0, 0, 180, SERVOMIN, SERVOMAX));
  send_motor_command(servonum2, 0, map(180, 0, 180, SERVOMIN, SERVOMAX));
  send_motor_command(servonum2, 0, map(135, 0, 180, SERVOMIN, SERVOMAX));
  send_motor_command(servonum2, 0, map(90, 0, 180, SERVOMIN, SERVOMAX));
  send_motor_command(servonum2, 0, map(45, 0, 180, SERVOMIN, SERVOMAX));
  send_motor_command(servonum2, 0, map(0, 0, 180, SERVOMIN, SERVOMAX));
  send_motor_command(servonum3, 0, map(180, 0, 180, SERVOMIN, SERVOMAX));
  send_motor_command(servonum3, 0, map(135, 0, 180, SERVOMIN, SERVOMAX));
  send_motor_command(servonum3, 0, map(90, 0, 180, SERVOMIN, SERVOMAX));
  send_motor_command(servonum3, 0, map(45, 0, 180, SERVOMIN, SERVOMAX));
  send_motor_command(servonum3, 0, map(0, 0, 180, SERVOMIN, SERVOMAX));
  return 1;
}

// Left
int left(String command) {
  
  send_motor_command(servonum1, 0, map(0, 0, 180, SERVOMIN, SERVOMAX));
  send_motor_command(servonum2, 0, map(0, 0, 180, SERVOMIN, SERVOMAX));
  send_motor_command(servonum3, 0, map(0, 0, 180, SERVOMIN, SERVOMAX));
  return 1;
}

// Right
int right(String command) {
  
  send_motor_command(servonum1, 0, map(180, 0, 180, SERVOMIN, SERVOMAX));
  send_motor_command(servonum2, 0, map(180, 0, 180, SERVOMIN, SERVOMAX));
  send_motor_command(servonum3, 0, map(180, 0, 180, SERVOMIN, SERVOMAX));
  return 1;
}

// Stop
int stop(String command) {
  
  send_motor_command(servonum1, 0, map(90, 0, 180, SERVOMIN, SERVOMAX));
  send_motor_command(servonum2, 0, map(90, 0, 180, SERVOMIN, SERVOMAX));
  send_motor_command(servonum3, 0, map(90, 0, 180, SERVOMIN, SERVOMAX));
  return 1;
}

// Function to command a given motor of the robot
void send_motor_command(int speed_pin, int direction_pin, int pwm, boolean dir)
{
  analogWrite(speed_pin,pwm); // Set PWM control, 0 for stop, and 255 for maximum speed
  digitalWrite(direction_pin,dir);
}

}

// Print connection details of the CC3000 chip
bool displayConnectionDetails(void)
{
  uint32_t ipAddress, netmask, gateway, dhcpserv, dnsserv;
  
  if(!cc3000.getIPAddress(&ipAddress, &netmask, &gateway, &dhcpserv, &dnsserv))
  {
    Serial.println(F("Unable to retrieve the IP Address!\r\n"));
    return false;
  }
  else
  {
    Serial.print(F("\nIP Addr: ")); cc3000.printIPdotsRev(ipAddress);
    Serial.print(F("\nNetmask: ")); cc3000.printIPdotsRev(netmask);
    Serial.print(F("\nGateway: ")); cc3000.printIPdotsRev(gateway);
    Serial.print(F("\nDHCPsrv: ")); cc3000.printIPdotsRev(dhcpserv);
    Serial.print(F("\nDNSserv: ")); cc3000.printIPdotsRev(dnsserv);
    Serial.println();
    return true;
  }
}

The code above does not compile at the moment so i don't know how it interacts with the arduino and the tablet yet. An earlier version of the code above that i tampered with didn't print of details in the serial monitor,(yes it was on the correct baud 115200). The earlier code that i tampered with didn't connect to my tablet and did not move the servos at all when i typed the command that the tutorial instructed. here is the tutorial.

Here is the working code just for the servos,(only one servo is activated in the code since i was trying to learn how to change the speed of the servo movement).

#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>

Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();

uint8_t servonum3 = 2;

#define SERVOMIN  152
#define SERVOMAX  575

void setup() {
  Serial.begin(9600);
  pwm.begin();
  pwm.setPWMFreq(60);
}
void loop() {
  pwm.setPWM(servonum3, 0, map(0, 0, 180, SERVOMIN, SERVOMAX));
  delay(10000);
  pwm.setPWM(servonum3, 0, map(90, 0, 180, SERVOMIN, SERVOMAX));
  delay(10000);
  pwm.setPWM(servonum3, 0, map(180, 0, 180, SERVOMIN, SERVOMAX));
  delay(10000);
  pwm.setPWM(servonum3, 0, map(90, 0, 180, SERVOMIN, SERVOMAX));
  delay(10000);
}

What i want, is to be able to control the servos when a given input from the tablet is received by the arduino via wifi. I don't know of any apps that i can use with this but most of the input from the tablet will come from the ipega controller i have paired to the tablet. http://shop.brando.com/prod_img/zoom/SGAME000700_6.jpg

I just don't know how to translate any of what i want into code and need help.

You don't need any app to control the servos, just configure your arduino with cc3000 as a rest api server. Then when both devices are connected to the local network, you can open any browser and send an http command, like this:

192.168.x.xx:5555/led/13/high

I dont have a code example but there must be examples on internet.

Now, if you want to use a controller, then you would need to create an android or ios app to communicate with the controller and send wifi tcp sockets.

That's the problem, I don't know how. I have been trying to merge my servo code with some WiFi code I got from a tutorial here Introduction | WiFi Controlled Mobile Robot | Adafruit Learning System but nothing works and I don't know what I am doing.

Well, i don't know about your particular equipment, but making a simple wifi bot is fairly easy. Arduino, w5100 ethernet shield, wireless router, servos, and adequate power supplies is about all you need. Below is an old simple routerbot setup I tried that did what I wanted. The wfi shields are some what sketchy in operation, so a mini wireless router or a used/refurbished wireless router might be a simpler wireless option.

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

mart256:
You don't need any app to control the servos, just configure your arduino with cc3000 as a rest api server. Then when both devices are connected to the local network, you can open any browser and send an http command, like this:

192.168.x.xx:5555/led/13/high

I dont have a code example but there must be examples on internet.

Now, if you want to use a controller, then you would need to create an android or ios app to communicate with the controller and send wifi tcp sockets.

Brilliant idea! Maybe not for just this case but for me :o Thank you!
rest api for arduino