Show Posts
Pages: [1]
1  Using Arduino / Project Guidance / Re: Arduino Ethernet resetting and stops looping on: May 11, 2013, 10:28:56 pm
Never mind, it was the Serial data from debugging overloading the RAM.
found the fix on this thread: http://forum.arduino.cc/index.php/topic,48577.0.html
2  Using Arduino / Project Guidance / Arduino Ethernet resetting and stops looping on: May 11, 2013, 10:15:44 pm
I have looked at if it was memory use and thats not it. I tried a 10uF cap from reset to ground, no difference.

I am trying to upload data to cosm but it only uploads a few times, restarting a few times and then pauses. Sometimes it pauses after a short time, others only after a couple of minutes.
I attached a text file with the output I am getting from the serial monitor and my code is below.

Code:
/**
 * Cosm Arduino sensor client example.
 *
 * This sketch demonstrates connecting an Arduino to Cosm (https://cosm.com),
 * using the new Arduino library to send and receive data.
 *
 * Requirements
 *   * Arduino with Ethernet shield or Arduino Ethernet (board must use the
 *     Wiznet Ethernet chipset)
 *   * Arduino software with version >= 1.0
 *   * An account at Cosm (https://cosm.com)
 *
 * Optional
 *   * An analog sensor connected to pin 2 (note we can still read a value from
 *     the pin without this)
 *
 * Created 8th January, 2013 using code written by Adrian McEwen with
 * modifications by Sam Mulube
 *
 * Full tutorial available here: https://cosm.com/docs/quickstart/arduino.html
 *
 * This code is in the public domain.
 */

#include <SPI.h>
#include <Ethernet.h>
#include <HttpClient.h>
#include <Time.h>
#include <Cosm.h>
#include <avr/pgmspace.h>

#define API_KEY "mZ3NPPNX1Nn9sLnoQ4Hz-mwt9MSSAKxHYnozMy80dENRQT0g" // your Cosm API key
#define FEED_ID 131247 // your Cosm feed ID

// MAC address for your Ethernet shield
byte mac[] = {
  0x90, 0xA2, 0xDA, 0x0D, 0xD7, 0xC3 };

unsigned long lastConnectionTime = 0;                // last time we connected to Cosm
const unsigned long connectionInterval = 5000;      // delay between connecting to Cosm in milliseconds

// Initialize the Cosm library
char sensor0Id[] = "Pascals";
char sensor1Id[] = "Degrees_Farengeight";
char sensor2Id[] = "Degrees_Celsius";
char sensor3Id[] = "Relative_Humidity";
char sensor4Id[] = "Light_Level";
CosmDatastream datastreams[] = {
  CosmDatastream(sensor0Id, strlen(sensor0Id), DATASTREAM_FLOAT),
  CosmDatastream(sensor1Id, strlen(sensor1Id), DATASTREAM_FLOAT),
  CosmDatastream(sensor2Id, strlen(sensor2Id), DATASTREAM_FLOAT),
  CosmDatastream(sensor3Id, strlen(sensor3Id), DATASTREAM_FLOAT),
  CosmDatastream(sensor4Id, strlen(sensor4Id), DATASTREAM_FLOAT)
  };

  // Wrap the datastream into a feed
  CosmFeed feed(FEED_ID, datastreams, 5 /* number of datastreams */);

EthernetClient client;
CosmClient cosmclient(client);


// receiver.pde
//
// Simple example of how to use VirtualWire to receive messages
// Implements a simplex (one-way) receiver with an Rx-B1 module
//
// See VirtualWire.h for detailed API docs
// Author: Mike McCauley (mikem@airspayce.com)
// Copyright (C) 2008 Mike McCauley
// $Id: receiver.pde,v 1.3 2009/03/30 00:07:24 mikem Exp $

#include <VirtualWire.h>
#include <Time.h>

float RH, Pa, LL, TC, TF, RF, WS, WD;
int rcvCounter = 0;

void setup()
{
  Serial.begin(9600); // Debugging only
  Serial.println("start up");

  // Initialise the IO and ISR
  vw_set_ptt_inverted(true); // Required for DR3100
  vw_setup(2000); // Bits per sec
  vw_set_rx_pin(8);
  vw_rx_start();       // Start the receiver PLL running

  Serial.println("Weather Reciever Starting");
  Serial.println("=========================");

  Serial.println("Initializing network");
  while (Ethernet.begin(mac) != 1) {
    Serial.println("Error getting IP address via DHCP, trying again...");
    delay(5000);
  }

  Serial.println("Network initialized");
  Serial.println();
}

void loop()
{

  uint8_t buf[VW_MAX_MESSAGE_LEN];
  uint8_t buflen = VW_MAX_MESSAGE_LEN;

  //convert buffer of chars to a string
  if (vw_get_message(buf, &buflen)) // Non-blocking
  {
    rcvCounter++;
    Serial.println(rcvCounter);
    time_t time = now();
    //recieve data and translate back to useable data
    String rawData;
    int i;

    for (i = 0; i < buflen; i++)
    {
      rawData = rawData + (char)buf[i];
    }
    String data = rawData.substring(2);
    int type = rawData.charAt(0) - 48;
    logData(data, type, time);  

  }
  
  //upload data to COSM
  if (millis() - lastConnectionTime > connectionInterval) {
    Serial.println(availableMemory());
    rcvCounter = 0;
    
    // send to Cosm
    setData(Pa, 0);
    setData(TF, 1);
    setData(TC, 2);
    setData(RH, 3);
    setData(LL, 4);
    Serial.println("Set");

    // read the datastream back from Cosm
    sendData();

    // update connection time so we wait before connecting again
    lastConnectionTime = millis();
    Serial.println("*");

  }
}

int availableMemory()
{
   int size = 8192;
   byte *buf;
   while ((buf = (byte *) malloc(--size)) == NULL);
   free(buf);
   return size;
}

void logData(String data, int type, time_t time)
{
  // asign data to var acording to type
  switch (type)
  {
  case 0:
    //humidity
    RH = strToFloat(data);
    break;
  case 1:
    //air presure
    Pa = strToFloat(data);
    break;
  case 2:
    //light
    LL = strToFloat(data);
    break;
  case 3:
    //temp
    TC = strToFloat(data);
    TF = TC * 1.8 + 32;
    break;
  }
}

float strToFloat(String str)
{
  String integer = getValue(str, '.', 0);
  String decimal = getValue(str, '.', 1);
  float out = integer.toInt() + (decimal.toInt()/(decimal.length()*10.00));
  return out;

}

String getValue(String data, const char separator, int index)
{
  int found = 0;
  int strIndex[] = {
    0, -1  };
  int maxIndex = data.length()-1;

  for(int i=0; i<=maxIndex && found<=index; i++){
    if(data.charAt(i)==separator || i==maxIndex){
      found++;
      strIndex[0] = strIndex[1]+1;
      strIndex[1] = (i == maxIndex) ? i+1 : i;
    }
  }

  return found>index ? data.substring(strIndex[0], strIndex[1]) : "";
}

void setData(float sensorValue, int sensorNum) {
  Serial.print("Seting Datastream ");
  Serial.print(sensorNum);
  Serial.print(" To Value ");
  Serial.print(sensorValue);
  datastreams[sensorNum].setFloat(sensorValue);
  Serial.println(" - Set");
}

// send the supplied value to Cosm, printing some debug information as we go
void sendData() {
  Serial.println("Uploading to Cosm");
  int ret = cosmclient.put(feed, API_KEY);
  Serial.print("PUT return code: ");
  Serial.println(ret);

  Serial.println();
}

// get the value of the datastream from Cosm, printing out the value we received
void getData() {
  Serial.println("Reading data from Cosm");

  int ret = cosmclient.get(feed, API_KEY);
  Serial.print("GET return code: ");
  Serial.println(ret);

  if (ret > 0) {
    Serial.print("Datastream is: ");
    Serial.println(feed[0]);

    Serial.print("Sensor value is: ");
    Serial.println(feed[0].getFloat());
  }

  Serial.println();
}


3  Using Arduino / Microcontrollers / Re: Atmega328p error burning bootloader on: May 04, 2013, 02:06:19 pm
YAY, Blink.
It was the cap on reset and having to select upload with programer.
Thanks all of you for your help!
4  Using Arduino / Microcontrollers / Re: Atmega328p error burning bootloader on: May 04, 2013, 10:21:35 am
ok, when I removed the cap on reset, the IDE did not fail when burning the bootloader.(verbose output in Arduino-output-bootload.txt)
I then tried to upload blink and got "avrdude: stk500_getsync(): not in sync: resp=0x00".(verbose output in Arduino-output-upload.txt)
5  Using Arduino / Microcontrollers / Re: Atmega328p error burning bootloader on: May 03, 2013, 02:32:19 pm
and two more.
my programer works in arduino with tiny 85s on port 1!
6  Using Arduino / Microcontrollers / Re: Atmega328p error burning bootloader on: May 03, 2013, 02:28:14 pm
here are some images of my circuit
7  Using Arduino / Microcontrollers / Re: Atmega328p error burning bootloader on: May 02, 2013, 06:17:15 pm
I have tried:
burning the bootloader with the Sparkfun tiny avr programer and arduino as isp
successfully tested the tiny avr programer on a attiny85(bootloading and uploading blink)
burn the bootloader in arduino
using avrdude in command line to bootload with the tiny avr programer following this:
https://www.sparkfun.com/tutorials/247
bootloading with and without 16MHz crystal and 22pF caps to ground on xtal 1 and 2
8  Using Arduino / Microcontrollers / Re: Atmega328p error burning bootloader on: May 02, 2013, 05:58:56 pm
I have 22 pF caps
9  Using Arduino / Microcontrollers / Re: Atmega328p error burning bootloader on: May 02, 2013, 01:33:34 pm
Oh sorry I forgot to add those wires in the diagram, I have updated it now!
10  Using Arduino / Microcontrollers / Atmega328p error burning bootloader on: May 02, 2013, 09:43:51 am
I have been trying for a while now to burn the bootloader to this chip and another of the same. I keep getting an error and I have not found a solution on google.
I am running the most recent arduino IDE and using sparkfun's tiny programer. I am running windows seven.
I have the right programer and serial port selected and I have arduino uno selected as the board.
I attached a picture of how I have it wired.
This is my errors verbose output:
Code:
C:\Program Files\Arduino\arduino-1.0.3\hardware/tools/avr/bin/avrdude -CC:\Program Files\Arduino\arduino-1.0.3\hardware/tools/avr/etc/avrdude.conf -v -v -v -v -patmega328p -cusbtiny -e -Ulock:w:0x3F:m -Uefuse:w:0x05:m -Uhfuse:w:0xde:m -Ulfuse:w:0xff:m

avrdude: Version 5.11, compiled on Sep  2 2011 at 19:38:36
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "C:\Program Files\Arduino\arduino-1.0.3\hardware/tools/avr/etc/avrdude.conf"

         Using Port                    : lpt1
         Using Programmer              : usbtiny
avrdude: usbdev_open(): Found USBtinyISP, bus:device: bus-0:\\.\libusb0-0001--0x1781-0x0c9f
         AVR Part                      : ATMEGA328P
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PC2
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65    20     4    0 no       1024    4      0  3600  3600 0xff 0xff
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : USBtiny
         Description     : USBtiny simple USB programmer, http://www.ladyada.net/make/usbtinyisp/
avrdude: programmer operation not supported

avrdude: Using SCK period of 10 usec
CMD: [ac 53 00 00] [00 00 00 00]
CMD: [ac 53 00 00] [00 00 00 00]
avrdude: initialization failed, rc=-1
         Double check connections and try again, or use -F to override
         this check.


avrdude done.  Thank you.
Pages: [1]