help! hello world CC3000 turn on a led

For other supported Arduino products from Adafruit: Shields, accessories, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
Rho
 
Posts: 3
Joined: Mon Nov 18, 2013 11:01 pm

help! hello world CC3000 turn on a led

Post by Rho »

Hello I just bought a adafruit cc3000, I want it to implement wifi to my home projects, but the thing is its kind of hard to understand from the first time, I am no new to microcontrollers I used to program microchips but now i am trying arduino. I need some guidance or tutorial from where to start to turn on a led from a distance in my same network. I don't quite understand how to config all the micro to make this work(the connection to wifi, and sending data from my pc for example).

I feel like the libraries don't explain a hole lot they just throw raw info. I someone could help me i would appreciate it very very much!

User avatar
Franklin97355
 
Posts: 23910
Joined: Mon Apr 21, 2008 2:33 pm

Re: help! hello world CC3000 turn on a led

Post by Franklin97355 »

First, have you tried any of the examples and did they work?

Second, can you describe in exacting detail what you want to do for your first program? Don't get too wild just a simple program to get you started.

Rho
 
Posts: 3
Joined: Mon Nov 18, 2013 11:01 pm

Re: help! hello world CC3000 turn on a led

Post by Rho »

First thank you franklin97355 for answering me, I do need help.

FIRST reply
I have tried all the examples on the ardruino, buildtest works perfect, I have been checking the code on the others to see if i could figure out how to transmit data, but no luck so far.

Second reply
switch), so for the first program I want to be able to turn on and off a LED from the arduino that has the CC3000, basically a wireless switch, all this should be activated from my computer running a python script in my same network that will send a command (some sort of char of byte the arduino will recognize) to the arduino. That is what I want to do so far.

Thanks again :)

User avatar
fmbfla
 
Posts: 110
Joined: Fri Jun 08, 2012 6:48 pm

Re: help! hello world CC3000 turn on a led

Post by fmbfla »


Rho
 
Posts: 3
Joined: Mon Nov 18, 2013 11:01 pm

Re: help! hello world CC3000 turn on a led

Post by Rho »

Looks great fmbfla, I'll try this out when i get back home tonight. If there is anything else that could help I would appreciate it thanks.

User avatar
fmbfla
 
Posts: 110
Joined: Fri Jun 08, 2012 6:48 pm

Re: help! hello world CC3000 turn on a led

Post by fmbfla »

Here is a start, http://forums.adafruit.com/viewtopic.php?f=22&t=46303.
I got a few sketches with buttons an whut not that use the wired ethernet and I'll spend some time wrighting sumthin up on them tomorrow.
Not much mem on the lil bugger but If i try and use the SD card and save the page to it and serve the page off of it, it might jus werk. but I can see it might be a lil slow sending out data. 8)

User avatar
fmbfla
 
Posts: 110
Joined: Fri Jun 08, 2012 6:48 pm

Re: help! hello world CC3000 turn on a led

Post by fmbfla »

Rho-
Try this out, The original is zoomkat'z I just moved some stuff around abit. The CC3000 server lib is almost the same as the arduino ether lib you just need to change a few things.(this should werk for you right outta da box)

Code: Select all

//zoomkat 8-04-12
//simple button GET server code to control arduino pins
//for use with IDE 1.0 or later
//open serial monitor to see what the arduino receives
//use ' instead of " in the html 
//address will look like http://192.168.1.102:84 when submited
//for use with W5100 based ethernet shields
///note that the below bug fix may be required
// http://code.google.com/p/arduino/issues/detail?id=605 
// fmbfla 11/26/12 
//************Now werks with ADAFRUIT BOB http://www.adafruit.com/products/1469 **********
//ZoomKat'z post with the posted code http://forum.arduino.cc/index.php?topic=199315.0 **************
#include <Adafruit_CC3000.h>
#include <Adafruit_CC3000_Server.h>//make sure its in you folder
#include <ccspi.h>
#include <SPI.h>
#include <string.h>
#include "utility/debug.h"
#include<stdlib.h>

// Define CC3000 chip pins
#define ADAFRUIT_CC3000_IRQ   3
#define ADAFRUIT_CC3000_VBAT  5
#define ADAFRUIT_CC3000_CS    10
//#define CC3000_TINY_DRIVER
// WiFi network (change with your settings !)
#define WLAN_SSID       "Yo mama"        // cannot be longer than 32 characters!
#define WLAN_PASS       "Yo daddy"
#define WLAN_SECURITY   WLAN_SEC_WPA2 // This can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2
Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT,
SPI_CLOCK_DIV2);

//DHT dht(DHTPIN, DHTTYPE);
// Initialize the Ethernet server library
// with the IP address and port you want to use 
// (port 80 is default for HTTP):
Adafruit_CC3000_Server server(80);//<----bacon
String readString; 

uint32_t ip;
void setup() {
  //MAKE SURE YOU KNOW WHAT PINS TO USE! the BOB/shield uses some of the pins in Zoomkat'z sketch.
  pinMode(2, OUTPUT); //pin selected to control
  // pinMode(4, OUTPUT); //pin selected to control
  // pinMode(6, OUTPUT); //pin selected to control
  // pinMode(8, OUTPUT); //pin selected to control
  // Open serial communications and wait for port to open:
  Serial.begin(115200);
  //dht.begin();
  //Serial.println(F("Hello, CC3000 Web Server TEST!\n")); 

  displayDriverMode();
  Serial.print("Free RAM: "); 
  Serial.println(getFreeRam(), DEC);
  /* Initialise the module */
  Serial.println(F("\nInitializing..."));
  if (!cc3000.begin())
  {
    Serial.println(F("Couldn't begin()! Check your wiring?"));
    while(1);
  }

  // Optional SSID scan
  //  listSSIDResults();//<==who else can a skim from ?

  if (!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) {
    Serial.println(F("Failed!"));
    while(1);
  }

  Serial.println(F("Connected!"));

  /* Wait for DHCP to complete */
  Serial.println(F("Request DHCP"));
  while (!cc3000.checkDHCP())
  {
    delay(100); // ToDo: Insert a DHCP timeout!
  }  

  /* Display the IP address DNS, Gateway, etc. */
  while (! displayConnectionDetails()) {
    delay(1000);
  }


  // start the Ethernet connection and the server:

  server.begin();

}// end void setup


void loop(){
  // Create a client connection
  Adafruit_CC3000_ClientRef 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("<center><H1>Zoomkat's simple Arduino button</H1></center>");
          client.println("<center><H2>Tweeked to werk with the Adafruit CC3000</H2></center>");
          client.println("<center><font size =\"5\" color=\"red\">\"26. Nov, 2013</H3></center>");

          // mousedown buttons, here are buttons, The chip cant handle alot of html(yet) even in TINYmode so i cut out all the other examples
          client.println("<center><input type=button value='2 ON' onmousedown=location.href='/?on2;'></center>"); 
          client.println("<center><input type=button value= '2 OFF' onmousedown=location.href='/?off3;'></center>");        
          //client.println(" <input type=button value='ALL OFF' onmousedown=location.href='/?off2468;'><br><br>");        
      
          client.println("</BODY>");
          client.println("</HTML>");

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

          ///////////////////// control arduino pin
          if(readString.indexOf('2') >0)//checks for 2
          {
            digitalWrite(2, HIGH);    // set pin 5 high
            Serial.println("Led 2 On");
          }
          if(readString.indexOf('3') >0)//checks for 3
          {
            digitalWrite(2, LOW);    // set pin 5 low
            Serial.println("Led 2 Off");
          }
         

          //clearing string for next read
          readString="";

        }
      }
    }
  }
}
void displayDriverMode(void)
{
#ifdef CC3000_TINY_DRIVER
  Serial.println(F("CC3000 is configure in 'Tiny' mode"));
#else
  Serial.print(F("RX Buffer : "));
  Serial.print(CC3000_RX_BUFFER_SIZE);
  Serial.println(F(" bytes"));
  Serial.print(F("TX Buffer : "));
  Serial.print(CC3000_TX_BUFFER_SIZE);
  Serial.println(F(" bytes"));
#endif
}

/**************************************************************************/
/*!
 @brief  Tries to read the CC3000's internal firmware patch ID
 */
/**************************************************************************/
uint16_t checkFirmwareVersion(void)
{
  uint8_t major, minor;
  uint16_t version;

#ifndef CC3000_TINY_DRIVER  
  if(!cc3000.getFirmwareVersion(&major, &minor))
  {
    Serial.println(F("Unable to retrieve the firmware version!\r\n"));
    version = 0;
  }
  else
  {
    Serial.print(F("Firmware V. : "));
    Serial.print(major); 
    Serial.print(F(".")); 
    Serial.println(minor);
    version = major; 
    version <<= 8; 
    version |= minor;
  }
#endif
  return version;
}

/**************************************************************************/
/*!
 @brief  Tries to read the 6-byte MAC address of the CC3000 module
 */
/**************************************************************************/
void displayMACAddress(void)
{
  uint8_t macAddress[6];

  if(!cc3000.getMacAddress(macAddress))
  {
    Serial.println(F("Unable to retrieve MAC Address!\r\n"));
  }
  else
  {
    Serial.print(F("MAC Address : "));
    cc3000.printHex((byte*)&macAddress, 6);
  }
}


/**************************************************************************/
/*!
 @brief  Tries to read the IP address and other connection details
 */
/**************************************************************************/
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;
  }
}

/**************************************************************************/
/*!
 @brief  Begins an SSID scan and prints out all the visible networks
 */
/**************************************************************************/

void listSSIDResults(void)
{
  uint8_t valid, rssi, sec, index;
  char ssidname[33]; 

  index = cc3000.startSSIDscan();

  Serial.print(F("Networks found: ")); 
  Serial.println(index);
  Serial.println(F("================================================"));

  while (index) {
    index--;

    valid = cc3000.getNextSSID(&rssi, &sec, ssidname);

    Serial.print(F("SSID Name    : ")); 
    Serial.print(ssidname);
    Serial.println();
    Serial.print(F("RSSI         : "));
    Serial.println(rssi);
    Serial.print(F("Security Mode: "));
    Serial.println(sec);
    Serial.println();
  }
  Serial.println(F("================================================"));

  cc3000.stopSSIDscan();
}


User avatar
fmbfla
 
Posts: 110
Joined: Fri Jun 08, 2012 6:48 pm

Re: help! hello world CC3000 turn on a led

Post by fmbfla »

And this Tonight I got this to werk with a single button a DHT22 and a TMP36 for reading environmental's.
The single button makes it a lil cleaner and you only need to read the button to know the state of the pin
Arduino UNO R3
Adafruite CC3000
Adafruite DHT22
Adafruit TMP36
Binary sketch size: 28,040 bytes (of a 32,256 byte maximum)

(Free RAM: 294)left

Code: Select all

//Originaly from zoomkat 8-04-12
//simple button GET server code to control arduino pins
//for use with IDE 1.0 or later
//open serial monitor to see what the arduino receives
//use ' instead of " in the html 
//address will look like http://192.168.1.102:84 when submited
//for use with W5100 based ethernet shields
///note that the below bug fix may be required
// http://code.google.com/p/arduino/issues/detail?id=605 
// fmbfla 11/26/12 
//Single ON/OFF button with Button text to show the state of the selected PIN
//Now werks with ADAFRUIT CC3000 BOB http://www.adafruit.com/products/1469 
//ZoomKat'z post with the posted code http://forum.arduino.cc/index.php?topic=199315.0 


#include <Adafruit_CC3000.h>
#include <Adafruit_CC3000_Server.h>//make sure its in you folder
#include <ccspi.h>
#include <SPI.h>
#include <string.h>
#include "utility/debug.h"
#include<stdlib.h>
#include "DHT.h"//tmp,hum
#define DHTPIN A2 //tmp,hum
#define DHTTYPE DHT22  //tmp,hum 
// Define CC3000 chip pins
#define ADAFRUIT_CC3000_IRQ   3
#define ADAFRUIT_CC3000_VBAT  5
#define ADAFRUIT_CC3000_CS    10
//#define CC3000_TINY_DRIVER
// WiFi network (change with your settings (or your neighbors) !)
#define WLAN_SSID       "bahzinga"        // cannot be longer than 32 characters!
#define WLAN_PASS       "sheldon"
#define WLAN_SECURITY   WLAN_SEC_WPA2 // This can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2
DHT dht(DHTPIN, DHTTYPE);
char* reload = ("Refresh: 15");// Wanna see the temp update right?
String readString; //Light gizmo stuff
int pin2 = 2;// The Turtle Light! or ,RELAY, LED....or what ever....
Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT,
SPI_CLOCK_DIV2);

// Initialize the Ethernet server library
// with the IP address and port you want to use 
// (port 80 is default for HTTP):
Adafruit_CC3000_Server server(80);//<----bacon

uint32_t ip;
void setup() {
  //MAKE SURE YOU KNOW WHAT PINS TO USE! the BOB/shield uses some of the pins in Zoomkat'z sketch.
  pinMode(2, OUTPUT); //pin selected to control
  digitalWrite(2,LOW);
  dht.begin();
  Serial.begin(115200);
  displayDriverMode();
  Serial.print("Free RAM: "); 
  Serial.println(getFreeRam(), DEC);
  /* Initialise the module */
  Serial.println(F("\nInitializing..."));
  if (!cc3000.begin())
  {
    Serial.println(F("Couldn't begin()! Check your wiring?"));
    while(1);
  }

  // Optional SSID scan
  //  listSSIDResults();//<==who else can a skim from ?

  if (!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) {
    Serial.println(F("Failed!"));
    while(1);
  }

  Serial.println(F("Connected!"));

  /* Wait for DHCP to complete */
  Serial.println(F("Request DHCP"));
  while (!cc3000.checkDHCP())
  {
    delay(100); // ToDo: Insert a DHCP timeout!
  }  

  /* Display the IP address DNS, Gateway, etc. */
  while (! displayConnectionDetails()) {
    delay(1000);
  }


  // start the Ethernet connection and the server:

  server.begin();//The bar is OPEN, "kamikaze" Please!

}// end void setup


void loop(){

  // Create a client connection
  Adafruit_CC3000_ClientRef 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) {//Light gizmo stuff

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

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

          ///////////////
          Serial.println(readString); //print to serial monitor for debuging (u that board?)
          client.println("HTTP/1.1 200 OK"); //send new page
          client.println("Content-Type: text/html");
          //client.println("Connection: close");  // makes poop!
          client.println(reload);  // refresh the page automatically every 15 sec (U Wanna see the temp update right?)
          client.println();// ?
          client.println("<HTML>");//html whats the diff?
          client.print("<center><font size=38>Hello World,</font></center>");
          client.println("<br />");
          client.print("<center>This is a TEST of the ADAFRUIT CC3000 BOB Web Server !</center>");
          client.println("<br />"); 
          client.print("<center>ENJOY!</center>");
          client.println("<br />");
          //Light gizmo stuff
          if(pin2 == LOW,readString.indexOf('2') >0)//checks for 2
          {
            digitalWrite(pin2, HIGH);    // set pin 5 high
            Serial.print("Led 2 On");
            client.print("<center><input type=button value= 'The Turtle Light ON' onmousedown=location.href='/?off3;'></center>");
          }
          else if(pin2 == HIGH,readString.indexOf('3') >0)//checks for 3
          {
            digitalWrite(pin2, LOW);    // set pin 5 low
            Serial.print("Led 2 Off");
            client.print("<center><input type=button value='The Turtle Light OFF' onmousedown=location.href='/?on2;'></center>");
          }
          else{
            client.print("<center><input type=button value= 'The Turtle Light OFF' onmousedown=location.href='/?on2;'></center>");
          }//Light gizmo stuff
          client.println("<br />");
          // ======--------sensor 1-----readings-----------======
          client.print("<left>Adafruit TMP36, DHT22</left>");
          client.println("<br />");
          client.print(" ");
          client.println("<br />");
          client.print(" TMP 36 Sensor ");
          client.println("<br />");
          client.print(" ");
          client.println("<br />");
          client.print(" Temperature :");
          client.print("<font size =\"5\" color=\"red\">");
          int sensorPin = A0;// TMP36
          int reading = analogRead(sensorPin);// TMP36
          float voltage = reading * 5.0;// TMP36
          voltage /= 1024.0; // TMP36
          float temperatureC = (voltage - 0.5) * 100 ;// TMP36  //converting from 10 mv per degree wit 500 mV offset
          float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;// TMP36 //converting the C to F
          client.print(temperatureF); // TMP36
          client.print("</font>");
          client.print(" *F");
          client.print("<br />");
          client.print(" ");
          client.println("<br />");
          client.print(" DHT22 Sensor");
          client.println("<br />");
          client.print(" ");
          client.println("<br />");
          float h = dht.readHumidity();//DHT
          float t = dht.readTemperature();//DHT
          client.print(" Humidity  :"); 
          client.print("<font size =\"5\" color=\"red\">");
          client.print(h);//DHT Humidity
          client.print("</font>");
          client.print(" %");
          client.println("<br />");
          client.print(" Temperature:");
          client.print("<font size =\"5\" color=\"red\">"); 
          client.print(t);//DHT Temperature
          client.print("</font>");
          client.print(" *F");
          client.println("</HTML>");
          delay(1);
          //stopping client
          client.close();
          //clearing string for next read
          readString="";//Light gizmo stuff

        }
      }
    }
  }
}
// ADAFruit stuff
void displayDriverMode(void)
{
#ifdef CC3000_TINY_DRIVER
  Serial.println(F("CC3000 is configure in 'Tiny' mode"));
#else
  Serial.print(F("RX Buffer : "));
  Serial.print(CC3000_RX_BUFFER_SIZE);
  Serial.println(F(" bytes"));
  Serial.print(F("TX Buffer : "));
  Serial.print(CC3000_TX_BUFFER_SIZE);
  Serial.println(F(" bytes"));
#endif
}

/**************************************************************************/
/*!
 @brief  Tries to read the CC3000's internal firmware patch ID
 */
/**************************************************************************/
uint16_t checkFirmwareVersion(void)
{
  uint8_t major, minor;
  uint16_t version;

#ifndef CC3000_TINY_DRIVER  
  if(!cc3000.getFirmwareVersion(&major, &minor))
  {
    Serial.println(F("Unable to retrieve the firmware version!\r\n"));
    version = 0;
  }
  else
  {
    Serial.print(F("Firmware V. : "));
    Serial.print(major); 
    Serial.print(F(".")); 
    Serial.println(minor);
    version = major; 
    version <<= 8; 
    version |= minor;
  }
#endif
  return version;
}

/**************************************************************************/
/*!
 @brief  Tries to read the 6-byte MAC address of the CC3000 module
 */
/**************************************************************************/
void displayMACAddress(void)
{
  uint8_t macAddress[6];

  if(!cc3000.getMacAddress(macAddress))
  {
    Serial.println(F("Unable to retrieve MAC Address!\r\n"));
  }
  else
  {
    Serial.print(F("MAC Address : "));
    cc3000.printHex((byte*)&macAddress, 6);
  }
}


/**************************************************************************/
/*!
 @brief  Tries to read the IP address and other connection details
 */
/**************************************************************************/
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;
  }
}

/**************************************************************************/
/*!
 @brief  Begins an SSID scan and prints out all the visible networks
 */
/**************************************************************************/

void listSSIDResults(void)
{
  uint8_t valid, rssi, sec, index;
  char ssidname[33]; 

  index = cc3000.startSSIDscan();

  Serial.print(F("Networks found: ")); 
  Serial.println(index);
  Serial.println(F("================================================"));

  while (index) {
    index--;

    valid = cc3000.getNextSSID(&rssi, &sec, ssidname);

    Serial.print(F("SSID Name    : ")); 
    Serial.print(ssidname);
    Serial.println();
    Serial.print(F("RSSI         : "));
    Serial.println(rssi);
    Serial.print(F("Security Mode: "));
    Serial.println(sec);
    Serial.println();
  }
  Serial.println(F("================================================"));

  cc3000.stopSSIDscan();
}




User avatar
tdicola
 
Posts: 1074
Joined: Thu Oct 17, 2013 9:11 pm

Re: help! hello world CC3000 turn on a led

Post by tdicola »

You might check out this tutorial on building a wifi candy bowl monitor too: http://learn.adafruit.com/wifi-candy-bowl

Instead of using an IR LED and sensor, just hook up a normal LED and have it turn it on or off when a command is received over telnet. You'd want to change the loop function slightly so it doesn't try to pulse the LED and read the detector, instead it just toggles the LED on or off like this:

Code: Select all

// Handle a connected client.
  Adafruit_CC3000_ClientRef client = candyServer.available();
  if (client) {
     // Check if there is data available to read.
     if (client.available() > 0) {
       uint8_t ch = client.read();
       // Toggle the LED whenever ? is received
       if (ch == '?') {
         digitalWrite(IR_LED, !digitalRead(IR_LED));
       }
     }
  }

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Arduino products from Adafruit”