Arduino uno and CC3000 with RGB LCD screen wont upload

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
sniperdude
 
Posts: 8
Joined: Tue Apr 01, 2014 3:19 pm

Arduino uno and CC3000 with RGB LCD screen wont upload

Post by sniperdude »

Hi, Im trying to build the temperature and humidity DHT22 sensor into my project to update my xively account and put the temp and humidity on the RGB LCD shield.


When I put "Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();" into my sketch the sketch stops uploading to xively, if I remove that line and upload it again it starts working again. I need this line to declare my LCD screen. Below is what I get out of the serial monitor.


Initializing...


Started AP/SSID scan




Connecting to myhome...Waiting to connect...Connected!
Request DHCP
api.xively.com -> 216.52.233.120Data length128

PUT /v2/feeds/1667445499.json HTTP/1.0
Host: api.xively.com
X-ApiKey: H1DDRMSfyhEEL2JuQz8KV4R9UVA0ZpvgR3hhQckNeeWwoIeq
Content-Length: 128
Connection: close

{"version":"1.0.0","datastreams" : [ {"id" : "Temperature","current_value" : "75"},{"id" : "Humidity","current_value" : "42"}]}


Connect to 216.52.233.120:80
Connected!
-------------------------------------
HTTP/1.1 400 Bad Request
Date: Tue, 08 Apr 2014 23:00:30 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 121
Connection: close
X-Request-Id: 0f2babed928a71a987f7b7967e6c2676995bce27

{"title":"JSON Parser Error","errors":"lexical error: invalid char in json text. ity\",\"current_value\":\"42\"}]\u0012"}-------------------------------------


Disconnecting
Started AP/SSID scan



I dont know what to do, as I have almost no coding knowledge. Any help would be appreciated.

User avatar
sniperdude
 
Posts: 8
Joined: Tue Apr 01, 2014 3:19 pm

Re: Arduino uno and CC3000 with RGB LCD screen wont upload

Post by sniperdude »

When I remove that line this is the serial output


Initializing...
Started AP/SSID scan




Connecting to myhome...Waiting to connect...Connected!
Request DHCP
api.xively.com -> 216.52.233.120Data length128

PUT /v2/feeds/1667445499.json HTTP/1.0
Host: api.xively.com
X-ApiKey: H1DDRMSfyhEEL2JuQz8KV4R9UVA0ZpvgR3hhQckNeeWwoIeq
Content-Length: 128
Connection: close

{"version":"1.0.0","datastreams" : [ {"id" : "Temperature","current_value" : "68"},{"id" : "Humidity","current_value" : "45"}]}


Connect to 216.52.233.120:80
Connected!
-------------------------------------
HTTP/1.1 200 OK
Date: Wed, 09 Apr 2014 16:46:14 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 0
Connection: close
X-Request-Id: 080dd8a9815d939647addd17818925dc3e38af7c
Cache-Control: max-age=0
Vary: Accept-Encoding

-------------------------------------


Disconnecting
Started AP/SSID scan


The bold text is what i noticed was different. I don't know what it means.

User avatar
sniperdude
 
Posts: 8
Joined: Tue Apr 01, 2014 3:19 pm

Re: Arduino uno and CC3000 with RGB LCD screen wont upload

Post by sniperdude »

I'm assuming I'm not giving the right information. I am trying to do the Xively project with a DHT22 sensor. I have the CC3000 wifi shield for my arduino uno. I also have the RGB LCD shield on top of that. Are they compatable? Can I send updates to my xively account and put the output on the 16x2 lcd screen?

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Arduino uno and CC3000 with RGB LCD screen wont upload

Post by adafruit_support_mike »

The two should be compatible.. they use different pins and protocols.

The "HTTP/1.1 200 OK" message from the second connection is the server's way of saying the message went through. The one that didn't work is saying an unexpected Unicode character got into the request string, which is frankly strange.

Post the code you're using (between CODE tags please.. it preserves the formatting) and a photo of your LCD Shield. I'd like to see the pins and solder joints near Arduino pins 10-13. Those are the ones the CC3000 uses for communication.

User avatar
sniperdude
 
Posts: 8
Joined: Tue Apr 01, 2014 3:19 pm

Re: Arduino uno and CC3000 with RGB LCD screen wont upload

Post by sniperdude »

Code: Select all

/*************************************************** 
  This is a sketch to use the CC3000 WiFi chip & Xively
  
  Written by Marco Schwartz for Open Home Automation
 ****************************************************/

// Libraries
#include <Adafruit_CC3000.h>
#include <ccspi.h>
#include <SPI.h>
#include <string.h>
#include "utility/debug.h"
#include "DHT.h"
#include<stdlib.h>
#include <Wire.h>
#include <Adafruit_MCP23017.h>
#include <Adafruit_RGBLCDShield.h>

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

// DHT sensor
#define DHTPIN 2
#define DHTTYPE DHT22

// Create CC3000 instances
Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT,
                                         SPI_CLOCK_DIV2); // you can change this clock speed
Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();
                                         
// DHT instance
DHT dht(DHTPIN, DHTTYPE);

// WLAN parameters
#define WLAN_SSID       "myhome"
#define WLAN_PASS       "mighty2000"
// Security can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2
#define WLAN_SECURITY   WLAN_SEC_WPA2

// Xively parameters
#define WEBSITE  "api.xively.com"
#define API_key  "H1DDRMSfyhEEL2JuQz8KV4R9UVA0ZpvgR3hhQckNeeWwoIeq"
#define feedID  "1667445499"

uint32_t ip;

void setup(void)
{
  // Initialize
  Serial.begin(115200);
  lcd.begin(16, 2);
  Serial.println(F("\nInitializing..."));
  if (!cc3000.begin())
  {
    Serial.println(F("Couldn't begin()! Check your wiring?"));
    while(1);
  }
 
}

void loop(void)
{
  // Connect to WiFi network
  cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY);
  Serial.println(F("Connected!"));
  
  /* Wait for DHCP to complete */
  Serial.println(F("Request DHCP"));
  while (!cc3000.checkDHCP())
  {
    delay(100);
  }  

  // Get the website IP & print it
  ip = 0;
  Serial.print(WEBSITE); Serial.print(F(" -> "));
  while (ip == 0) {
    if (! cc3000.getHostByName(WEBSITE, &ip)) {
      Serial.println(F("Couldn't resolve!"));
    }
    delay(500);
  }
  cc3000.printIPdotsRev(ip);
  
  // Get data & transform to integers
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  
  int temperature = (int) t;
  int humidity = (int) h;
  
  // Prepare JSON for Xively & get length
  int length = 0;

  String data = "";
  data = data + "\n" + "{\"version\":\"1.0.0\",\"datastreams\" : [ {\"id\" : \"Temperature\",\"current_value\" : \"" + String(temperature*9/5+32) + "\"}," 
  + "{\"id\" : \"Humidity\",\"current_value\" : \"" + String(humidity) + "\"}]}";
  
  length = data.length();
  Serial.print("Data length");
  Serial.println(length);
  Serial.println();
  
  // Print request for debug purposes
  Serial.print("PUT /v2/feeds/");
  Serial.print(feedID);
  Serial.println(".json HTTP/1.0");
  Serial.println("Host: api.xively.com");
  Serial.print("X-ApiKey: ");
  Serial.println(API_key);
  Serial.print("Content-Length: ");
  Serial.println(length, DEC);
  Serial.print("Connection: close");
  Serial.println();
  Serial.print(data);
  Serial.println();
  
  
  
   lcd.setCursor(0, 0);
 lcd.print("humidity  ");
 lcd.print(  h);
 lcd.print("%");
  lcd.setCursor(0, 1);
  lcd.print("temp      ");
  lcd.print(t*9 / 5 +32);
  lcd.print("F");
  
  
  
  // Send request
  Adafruit_CC3000_Client client = cc3000.connectTCP(ip, 80);
  if (client.connected()) {
    Serial.println("Connected!");
    client.println("PUT /v2/feeds/" + String(feedID) + ".json HTTP/1.0");
    client.println("Host: api.xively.com");
    client.println("X-ApiKey: " + String(API_key));
    client.println("Content-Length: " + String(length));
    client.print("Connection: close");
    client.println();
    client.print(data);
    client.println();
  } else {
    Serial.println(F("Connection failed"));    
    return;
  }
  
  Serial.println(F("-------------------------------------"));
  while (client.connected()) {
    while (client.available()) {
      char c = client.read();
      Serial.print(c);
    }
  }
  client.close();
  Serial.println(F("-------------------------------------"));
  
  Serial.println(F("\n\nDisconnecting"));
  cc3000.disconnect();
  
  // Wait 10 seconds until next update
  delay(5000);
  
}
Ill try and post pictures of the LCD shield later. The shield does work though. the solder joints are decent, cant say they are the best but I do know how to solder a bit.


And sadly my computer restarted on its own last night so I had to redo the code as I remember it.

I also have the wing shield between the wifi shield and the LCD shield.

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Arduino uno and CC3000 with RGB LCD screen wont upload

Post by adafruit_support_mike »

I don't see anything out of the ordinary in the code, which leads me to think there might be some kind of unwanted connection in the wiring.

darth253
 
Posts: 7
Joined: Fri Jan 04, 2013 4:58 pm

Re: Arduino uno and CC3000 with RGB LCD screen wont upload

Post by darth253 »

Hi guys, did this ever get resolved? I am having the same problem of sorts: For some reason when I add the LCD I2c library and put in a lcd.print request in the code, xively no longer receives the data. It appears to me as though the cc3000 is skipping over certain characters when it tries to upload the data, causing the data uploaded to xively to corrupt. For example, although my data string has the value

{"version":"1.0.0","datastreams" : [ {"id" : "pH","current_value" : "6.11"},{"id" : "Temperature","current_value" : "2.27"}]}

It is shown as


{"version":"1.0.0","datastreams" : [ {"id" : "pH","current_value" : "6.11"},{"id" : "Temperature","current_value" : "2.27 NOTICE THERE'S NO BRACKETS/BRACES HERE

Or sometimes:

{"version":"1.0.0","datastreams" : [ {"id" : "pH","current_value" : "6.11"},{"id" : "Temp

Little snippets of the data are left out, leading me to believe this is a clock/baud rate issue with the cc3000, so that somehow when a Serial.print or lcd.print command is added, the cc3000 will upload false data. Any idea why this could be? I don't understand how only adding a serial.print command in the code could cause the upload to fail. I don't think it could be a soldering or connection issue, as my LCD is connected to pins A4-A5 using i2c, which has nothing to do with the cc3000 pins...

darth253
 
Posts: 7
Joined: Fri Jan 04, 2013 4:58 pm

Re: Arduino uno and CC3000 with RGB LCD screen wont upload

Post by darth253 »

I'm also wondering whether there could also be a difficulty coming from using the String type to hold the data: because of the small memory limit of the MCU, could using dynamic memory be screwing stuff up?

darth253
 
Posts: 7
Joined: Fri Jan 04, 2013 4:58 pm

Re: Arduino uno and CC3000 with RGB LCD screen wont upload

Post by darth253 »

SOLUTION: Using this function, monitor the free memory available on the Arduino.


http://playground.arduino.cc/Code/AvailableMemory

because a String dynamically allocates memory, it clogs up the amount of memory that is available, causing memory leaks and corrupting the String of data that is to be sent to xively.com. The solution is to use char arrays instead of Strings. Here is a great article that helps to explain it:

http://critical.eschertech.com/2010/07/ ... d-systems/

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

Return to “General Project help”