cc3000 prints line to client and resets arduino

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
davidbroadbent
 
Posts: 25
Joined: Thu Aug 06, 2015 5:42 pm

cc3000 prints line to client and resets arduino

Post by davidbroadbent »

hi guys ive been trying alot of fixes for this but nothing seems to work. im sure its something simple im overlooking but anyway i have a mega R3 board an adafruit datalogger shield and an adafruit cc3000 wifi shield when i run the program everything works well it listens for a client it prints to my SD and serial and lcd but when i connect to cc3000 as a client it prints the first line of data no problem... just right, and then resets my arduino which then works well untill i connect to cc3000 as a client again. ive tried stack overflow ive tried modifying socket.cpp for non blocking, ive tried delays after every print. ive looked online for solutions as well but nothing helps. i really appreciate any input you guys might have.

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

Re: cc3000 prints line to client and resets arduino

Post by Franklin97355 »

How are you powering the Arduino? If it isn't a memory it's probably power.

User avatar
davidbroadbent
 
Posts: 25
Joined: Thu Aug 06, 2015 5:42 pm

Re: cc3000 prints line to client and resets arduino

Post by davidbroadbent »

I tried it with 9v adapter, same thing happens. tried it without USB, same thing. connected through my phone (telnet) with module independant of serial connection and same thing. in all of these instances the info is saved to the SD so i know what and when it happens. always after it prints the 1st data line to putty or telnet client.

Thanks for your help,

User avatar
adafruit2
 
Posts: 22144
Joined: Fri Mar 11, 2005 7:36 pm

Re: cc3000 prints line to client and resets arduino

Post by adafruit2 »

can you remvoe the SD card code, does it work with the default code for the cc3k?

User avatar
davidbroadbent
 
Posts: 25
Joined: Thu Aug 06, 2015 5:42 pm

Re: cc3000 prints line to client and resets arduino

Post by davidbroadbent »

i removed the sd card and loaded the chatserver sketch only. it hangs at initializing..... ????? my combined sketch runs well even connects ????..... okay im back so when i installed the logger shield i had to cut the cs trace to pin 10 and jumper to 9 so that the cc3k could use 10 anywho when the original chatserver sketch was hanging on initializing i changed the cs pin back to 10 and it works now.! sooooo conflict with cs pins? how do i designate the loggershield cs from the cc3k cs in the sketch? i assume that is the next step.? thank you for your help.

User avatar
adafruit2
 
Posts: 22144
Joined: Fri Mar 11, 2005 7:36 pm

Re: cc3000 prints line to client and resets arduino

Post by adafruit2 »

remove the datalogger shield completely. do just the most basic tests with the wifi shield.

User avatar
davidbroadbent
 
Posts: 25
Joined: Thu Aug 06, 2015 5:42 pm

Re: cc3000 prints line to client and resets arduino

Post by davidbroadbent »

nevermind i already did that. the cc3k hangs when cs pin is changed from pin 10 though. i changed the logger to cs pin 9 and already deignated the changes in the sketch so it still resets after client gets first data dump. hmmmmm. think, think, think,

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: cc3000 prints line to client and resets arduino

Post by adafruit_support_rick »

Can you post your code?

User avatar
davidbroadbent
 
Posts: 25
Joined: Thu Aug 06, 2015 5:42 pm

Re: cc3000 prints line to client and resets arduino

Post by davidbroadbent »

you can see ive played around with this alot ive rearranged it as many ways as possible but the mega resets after every dump to server.




Code: Select all

/*By David Broadbent E:[email protected]*/

#include <SD.h>
#include <LiquidCrystal_I2C.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>  // Comes with Arduino IDE
#include <SPI.h> //ethernetcode >
#include "RTClib.h"
#include <Adafruit_CC3000.h>
#include <SPI.h>
#include "utility/debug.h"
#include "utility/socket.h"
// These are the interrupt and control pins
#define ADAFRUIT_CC3000_IRQ   3  // MUST be an interrupt pin!
// These can be any two pins
#define ADAFRUIT_CC3000_VBAT  5
#define ADAFRUIT_CC3000_CS    10
// Use hardware SPI for the remaining pins
Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT,
                                         SPI_CLOCK_DIVIDER); // you can change this clock speed

#define WLAN_SSID       "SSID"           // cannot be longer than 32 characters!
#define WLAN_PASS       "PASS"
// Security can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2
#define WLAN_SECURITY   WLAN_SEC_WPA2

#define LISTEN_PORT           23    // What TCP port to listen on for connections.
Adafruit_CC3000_Server chatServer(LISTEN_PORT);


LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

#define ONE_WIRE_BUS_PIN A8
const int alarmPin = 30; //db
const int solenoidPin1 = 31; //db 
const int buzzerPin = 32; //db
const int ledPin = 33; //db
const int chipSelect = 9;
File dataFile;
OneWire oneWire(ONE_WIRE_BUS_PIN);
DallasTemperature sensors(&oneWire);
DeviceAddress Probe01 = { 0x28, 0xD7, 0x4A, 0x09, 0x06, 0x00, 0x00, 0x49 };
DeviceAddress Probe02 = { 0x28, 0xFF, 0x00, 0xF0, 0x02, 0x15, 0x03, 0x87 }; 
DeviceAddress Probe03 = { 0x28, 0xFF, 0x80, 0x47, 0x51, 0x15, 0x03, 0xC4 };
DeviceAddress Probe04 = { 0x28, 0xFF, 0x60, 0x77, 0x51, 0x15, 0x03, 0x56 };
DeviceAddress Probe05 = { 0x28, 0xFF, 0x2C, 0x4E, 0x51, 0x15, 0x03, 0x45 };
DeviceAddress Probe06 = { 0x28, 0xFF, 0xCE, 0xEF, 0x02, 0x15, 0x03, 0xA5 };
DeviceAddress Probe07 = { 0x28, 0xFF, 0x37, 0xE2, 0x01, 0x15, 0x02, 0xD7 };
RTC_DS1307 rtc;
void setup() 
{
  Serial.begin(9600);
  Serial.println(F("Hello, CC3000!")); 
  delay (500);
  
  SD.begin(chipSelect); 
  
  
  Serial.println("card initialized.");
  
  
  Serial.print("Free RAM: "); Serial.println(getFreeRam(), DEC);
  delay (500);
  
  Serial.println(F("Initializing..."));
  cc3000.begin();
  delay(1000);
  
  
  
  
  Serial.print(F("Attempting to connect to ")); Serial.println(WLAN_SSID);
  
  cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY, 2);

  
  Serial.println(F("Request DHCP"));
  cc3000.checkDHCP();
  
    delay(10000); // ToDo: Insert a DHCP timeout!
    

  
  uint32_t ipAddress, netmask, gateway, dhcpserv, dnsserv;
  
  cc3000.getIPAddress(&ipAddress, &netmask, &gateway, &dhcpserv, &dnsserv);
 
    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();

  chatServer.begin();
  
  
    delay(1000);
 
  


  
  Serial.println(F("Listening for connections..."));
 
 lcd.begin(20,4);         // initialize the lcd for 20 chars 4 lines, turn on backlight
 lcd.backlight();  

//-------- Write characters on the display ------------------
  // NOTE: Cursor Position: Lines and Characters start at 0  
  lcd.setCursor(1,0); //Start at character 4 on line 0
  lcd.print("");
  delay(2000);
  lcd.setCursor(1,1);
  lcd.print("");
  delay(2000);  
  lcd.setCursor(0,2);
  lcd.print("");
  delay(2000);
  lcd.setCursor(4,3);
  lcd.print("Initializing");
  delay(7000);
  lcd.clear ();
  delay (1000);
  
  lcd.setCursor(1,0); //Start at character 0 on line 0
  lcd.print("");
  delay (2000);
  lcd.setCursor(1,1);
  lcd.print("");  
  delay(1000);  
  lcd.setCursor(4,2);
  lcd.print("");
  //delay(1000);
  //lcd.setCursor(0,3);
  //lcd.print("");
  delay (7000);
   
  dataFile = SD.open("datalog.txt", FILE_WRITE);
    rtc.begin();  
 
    Serial.println("RTC is running!");
   
  sensors.begin(); 
    

  // set the resolution to 10 bit (Can be 9 to 12 bits .. lower is faster)
  sensors.setResolution(Probe01, 10);
  sensors.setResolution(Probe02, 10);
  sensors.setResolution(Probe03, 10);
  sensors.setResolution(Probe04, 10);
  sensors.setResolution(Probe05, 10);
  sensors.setResolution(Probe06, 10);
  sensors.setResolution(Probe07, 10);
  
lcd.clear();  // Reset the display  
lcd.setCursor(0,0); //Start at character 0 on line 0
lcd.print("Devices on Bus = ");  
lcd.print(sensors.getDeviceCount()); 
lcd.setCursor(0,2); 
delay(1000);
lcd.println("Getting temperatures");
delay(5000); 

  Serial.println();
  Serial.print("Number of Devices found on bus = ");  
  Serial.println(sensors.getDeviceCount());   
  Serial.print("Getting temperatures... ");  
  Serial.println();
  
  pinMode (ledPin, OUTPUT);
  pinMode(53, OUTPUT);
  pinMode(A8,INPUT);
  pinMode (alarmPin, OUTPUT); 
  pinMode (solenoidPin1, OUTPUT); 
  pinMode (buzzerPin, OUTPUT); 
 
 
    }

void loop()
{ 
  sensors.requestTemperatures(); 
  DateTime now = rtc.now();  // Read data from the RTC Chip
   Adafruit_CC3000_ClientRef client = chatServer.available();
client.available();
 chatServer.print(F("Number of Devices found on bus = "));  
 chatServer.println(sensors.getDeviceCount());   
 chatServer.println(F("Getting temperatures... "));
 chatServer.println ();
chatServer.print(F("Oven 1 Probe 1 temp")); 
dataFile.print(F("Oven 1 Probe 1 temp")); 

 lcd.clear();    
 lcd.home();
 lcd.setCursor(0,0); 
 lcd.print(F("Oven 1 Probe 1 temp"));   

 
 
  Serial.print(F("Oven 1 Probe 1 temperature is:   "));
  printTemperature(Probe01);
  Serial.println();
  

   
chatServer.print(F("Oven 1 Probe 2 temp")); 

dataFile.print(F("Oven 1 Probe 2 temp"));
 
 lcd.clear();  // Reset the display   
 lcd.setCursor(0,0);
 lcd.print(F("Oven 1 Probe 2 temp"));
 
  Serial.print(F("Oven 1 Probe 02 temperature is:   "));
  printTemperature(Probe02);
  Serial.println();
  

  
  chatServer.print(F("Oven 1 Probe 3 temp"));
  //client.println (sensors.getTempC(Probe03));
  dataFile.print(F("Oven 1 Probe 3 temp"));
  
 lcd.clear();  // Reset the display   
 lcd.setCursor(0,0);
 lcd.print(F("Oven 1 Probe 3 temp"));
 
  Serial.print(F("oven 1 Probe 3 temperature is:   "));
  printTemperature(Probe03);
  Serial.println();
  

  
  chatServer.print(F("Oven 1 Probe 4 temp"));
  
  dataFile.print(F("Oven 1 Probe 4 temp"));
  
  
  lcd.clear();  // Reset the display   
  lcd.setCursor(0,0);
  lcd.print(F("Oven 1 Probe 4 temp"));
   
  Serial.print(F("Oven 1 Probe 4 temperature is:   "));
  printTemperature(Probe04);
  Serial.println();
  
  
  chatServer.print(F("Oven 1 Probe 5 temp"));
  
  dataFile.print(F("Oven 1 Probe 5 temp"));
  
  
  lcd.clear();  // Reset the display   
  lcd.setCursor(0,0);
  lcd.print(F("Oven 1 Probe 5 temp is"));
  
  Serial.print(F("Oven 1 Probe 5 temperature is:   "));
  printTemperature(Probe05);
  Serial.println();
  
  
  chatServer.print(F("Oven 1 Probe 6 temp"));
  
  dataFile.print(F("Oven 1 Probe 6 temp"));
  
  
  lcd.clear();  // Reset the display   
  lcd.setCursor(0,0);
  lcd.print(F("Oven 1 Probe 6 temp"));
  
  Serial.print(F("Oven 1 Probe 6 temperature is:   "));
  printTemperature(Probe06);
  Serial.println();
  
  
   chatServer.print(F("Oven 1 Probe 7 temp"));
   
   dataFile.print(F("Oven 1 Probe 7 temp"));
  
  
  lcd.clear();  // Reset the display   
  lcd.setCursor(0,0);
  lcd.print(F("Oven 1 Probe 7 temp"));
  
  Serial.print(F("Oven 1 Probe 7 temperature is:   "));
  printTemperature(Probe07);
  Serial.println();

  
}
  
void printTemperature(DeviceAddress deviceAddress)
{  
DateTime now = rtc.now(); 
float tempC = sensors.getTempC(deviceAddress);


   if (tempC == -127.00) 
{
   Serial.println(F("Error getting temperature"));
   dataFile.println(F("Error getting temperature")); 
 lcd.setCursor(0,1); //Start at character 0 on line 1
   lcd.println(F(" Error getting Temp "));
   chatServer.println(F("Error getting Temp"));
   chatServer.println();
   } 
   else
   {
  Serial.print(" C: ");
  Serial.print(tempC);
  Serial.print(" F: ");
  Serial.println(DallasTemperature::toFahrenheit(tempC) );
  Serial.print(now.year(), DEC); //
  Serial.print('/');
  Serial.print(now.month(), DEC);
  Serial.print('/');
  Serial.print(now.day(), DEC);
  Serial.print(' ');
  Serial.print(now.hour(), DEC);
  Serial.print(':');
  Serial.print(now.minute(), DEC);
  Serial.print(':');
  Serial.print(now.second(), DEC);
  Serial.println(); 
   
 
 lcd.setCursor(0,2); //Start at character 1 on line 1
 lcd.print("  C: ");
 lcd.print(tempC);
 lcd.print(" F: ");
 lcd.println(DallasTemperature::toFahrenheit(tempC) );
   
chatServer.print ("C: " );  
chatServer.print (tempC ); 
chatServer.print (" F: ");   
chatServer.println (DallasTemperature::toFahrenheit(tempC)  );   
chatServer.print(now.year(), DEC); //
chatServer.print('/');
chatServer.print(now.month(), DEC);
chatServer.print('/');
chatServer.print(now.day(), DEC);
chatServer.print(' ');
chatServer.print(now.hour(), DEC);
chatServer.print(':');
chatServer.print(now.minute(), DEC);
chatServer.print(':');
chatServer.print(now.second(), DEC);
chatServer.println(); 
  
dataFile.print ("C: " );  
dataFile.print (tempC );  
dataFile.print (" F: ");  
dataFile.println (DallasTemperature::toFahrenheit(tempC)  );  
dataFile.print(now.year(), DEC); //
dataFile.print('/');
dataFile.print(now.month(), DEC);
dataFile.print('/');
dataFile.print(now.day(), DEC);
dataFile.print(' ');
dataFile.print(now.hour(), DEC);
dataFile.print(':');
dataFile.print(now.minute(), DEC);
dataFile.print(':');
dataFile.print(now.second(), DEC);
dataFile.println();
   
   
   
if ( DallasTemperature::toFahrenheit(tempC) <= 195.00 )//db
{
 
  Serial.println ( " LOW TEMP ALARM" ); //db
  
 lcd.setCursor(0,3); //Start at character 0 on line 3
  lcd.println ( "   LOW TEMP ALARM   " ); //db
 chatServer.println ( "LOW TEMP ALARM" ); //db ethernet
chatServer.println ( "" ); //db ethernet

dataFile.println ( "LOW TEMP ALARM" ); //db ethernet
dataFile.println ( "" ); //db ethernet

//digitalWrite (alarmPin, HIGH);//db
//digitalWrite (solenoidPin1, HIGH); // db if solenoid is NO
//digitalWrite (buzzerPin, HIGH); //db
//digitalWrite (ledPin, HIGH); //db 
}

if (DallasTemperature::toFahrenheit(tempC) >= 290.00 )//db
   {
  Serial.println (" HIGH TEMP ALARM"); //db
 lcd.setCursor(0,3); //Start at character 0 on line 3
  lcd.println ("  HIGH TEMP ALARM   "); //db
  chatServer.println ( "HIGH TEMP ALARM" ); //db ethernet
chatServer.println ( "" ); //db ethernet

dataFile.println ( "HIGH TEMP ALARM" ); //db ethernet
dataFile.println ( "" ); //db ethernet
  
//digitalWrite (alarmPin, HIGH); //db
//digitalWrite (solenoidPin1, LOW); // db if solenoid is NC
//digitalWrite (buzzerPin, HIGH); //db
//digitalWrite (ledPin, HIGH); //db
   }



if ((DallasTemperature::toFahrenheit(tempC) >195.00 ) && (DallasTemperature::toFahrenheit(tempC) <290.00))
{
  Serial.println ( " NORMAL OPERATING TEMP" );

 lcd.setCursor(0,3); //Start at character 0 on line 3
  lcd.println ( " NORMAL OPERATING TEMP" );
  chatServer.println ( "NORMAL OPERATING TEMP" ); //db ethernet
chatServer.println ( "" ); //db ethernet

dataFile.println ( "NORMAL OPERATING TEMP" ); //db ethernet
dataFile.println ( "" ); //db ethernet

//digitalWrite (alarmPin, LOW);//db
//digitalWrite (solenoidPin1, LOW); // db if solenoid is NC
//digitalWrite (buzzerPin, LOW); //db
//digitalWrite (ledPin, LOW); //db

  
}
//{
//dataFile.flush();  
//dataFile.close(); 
//}
  delay(10000); // temp sample rate.adjust as needed
   }

 
 


  
      // when characters arrive over the serial port...
 // if (Serial.available()) {
      // wait a bit for the entire message to arrive
 // delay(100);
      // clear the screen
 // lcd.clear();
      // read all the available characters
 // while (Serial.available() > 0) {
        // display each character to the LCD
 // lcd.write(Serial.read());
}

    
    

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: cc3000 prints line to client and resets arduino

Post by adafruit_support_rick »

What are all those arguments to the LIquidCrystal_I2C constructor? Are those pin numbers?

Code: Select all

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

Try checking for a client before writing to chatServer:

Code: Select all

   Adafruit_CC3000_ClientRef client = chatServer.available();
  if (client) {
    chatServer.print(F("Number of Devices found on bus = "));  
    chatServer.println(sensors.getDeviceCount());   
    chatServer.println(F("Getting temperatures... "));
    chatServer.println ();
    chatServer.print(F("Oven 1 Probe 1 temp")); 
    dataFile.print(F("Oven 1 Probe 1 temp")); 
    . . . etc . . .

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

Re: cc3000 prints line to client and resets arduino

Post by Franklin97355 »

According to the library the LiquidCrystal_i2c only takes 4 arguments.

Code: Select all

LiquidCrystal_I2C::LiquidCrystal_I2C(uint8_t lcd_addr, uint8_t lcd_cols, uint8_t lcd_rows, uint8_t charsize)

User avatar
davidbroadbent
 
Posts: 25
Joined: Thu Aug 06, 2015 5:42 pm

Re: cc3000 prints line to client and resets arduino

Post by davidbroadbent »

ive removed the lcd portion from sketch (used from arduino site) and it does the same thing. i have also placed the server call at the top of the loop with same results with the if line in place it hangs just before the loop starts.





Serial.println();
delay(500);
Serial.print("#of Devices on bus = ");
delay(500);
Serial.println(sensors.getDeviceCount());
delay(500);
Serial.print("Getting Temps... "); hangs on this line
delay(500);
Serial.println();
delay(1000);

pinMode (ledPin, OUTPUT);
pinMode(53, OUTPUT);
pinMode(A8,INPUT);
pinMode (alarmPin, OUTPUT);
pinMode (solenoidPin1, OUTPUT);
pinMode (buzzerPin, OUTPUT);


}

void loop()
{
sensors.requestTemperatures();
DateTime now = rtc.now(); // Read data from the RTC Chip
// Try to get a client which is connected.
//Adafruit_CC3000_ClientRef client = server.available();
//server.read();
// if (client) {
//}
// Check if there is data available to read.
//if ( > 0) {
// Read a byte and write it to all clients.
// uint8_t ch = client.read();
// chatServer.write(ch);
Adafruit_CC3000_ClientRef client = server.available();
if (client) {
server.print(F("# of Devices on bus = "));
delay(500);
server.println(sensors.getDeviceCount());
delay(500);
server.println(F("Getting Temps... "));
delay(500);
server.println ();
server.print(F("Ovn 1 Prb 1 Tmp"));
delay(500);
dataFile.print(F("Ovn 1 Prb 1 Tmp"));
delay(500);

User avatar
davidbroadbent
 
Posts: 25
Joined: Thu Aug 06, 2015 5:42 pm

Re: cc3000 prints line to client and resets arduino

Post by davidbroadbent »

remove the if statement and it no longer hangs before the loop but resets after dump to server still ??? ive updated the firmware ive added the define non blocking in socket cpp, ive added all the delays between prints for stack overflow, its externally powered....... the thing is ive been running this program with a W5100 ethernet shield for about a year with no problems i just thought i would like my future projects to be wireless and retrofit other projects but i cant get over this hump.

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: cc3000 prints line to client and resets arduino

Post by adafruit_support_rick »

Does "Getting Temps" get transmitted? Does the result of sensors.getDeviceCount() get transmitted?

User avatar
davidbroadbent
 
Posts: 25
Joined: Thu Aug 06, 2015 5:42 pm

Re: cc3000 prints line to client and resets arduino

Post by davidbroadbent »

yes . just right, no lag (exept what i program) it all comes through and if i connect in the middle of the sketch say for probe 5 it gets transmitted same way in all instances. it just resets the board after it transmitts the info for that section. ive tried it on other r3 boards same results. i tried a uno but the sketch is way to big, so i guess its either code or something on the r3 im overlooking . ill try disabling the reset on monday JIC. i dont have a 110 ohm resistor here. i do have an edison at work maybe ill try that to. if anyone comes up with anything in the meantime let me know and ill try it.

Thanks for all the help.

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

Return to “Arduino Shields from Adafruit”