I'm new to the arduino and need help. I understand what I am looking at, but I have a hard time understanding how different lines of code relate to one another. Below is my code for an arduino + ethernet shield + a one wire temp sensor. I have placed numbers like this: -------1------- in the code that relate to questions below. If you are kind enough to answer, assume I know nothing (because I don't). For more info on pachube visit www.pachube.com.
/* ==============================
* This code, which assumes you're using the official Arduino Ethernet shield,
* updates a Pachube feed with your analog-in values and grabs values from a Pachube
* feed - basically it enables you to have both "local" and "remote" sensors.
*
* Tested with Arduino 14
*
* Pachube is www.pachube.com - connect, tag and share real time sensor data
* code by usman (www.haque.co.uk), may 2009
* copy, distribute, whatever, as you like.
*
* v1.1 - added User-Agent & fixed HTTP parser for new Pachube headers
* and check millis() for when it wraps around
*
* =============================== */
#include <Ethernet.h>
#include <string.h>
#undef int() // needed by arduino 0011 to allow use of stdio
#include <stdio.h> // for function sprintf
#define SHARE_FEED_ID 2970 // this is your Pachube feed ID that you want to share to
#define REMOTE_FEED_ID 310 // this is the ID of the remote Pachube feed that you want to connect to
#define REMOTE_FEED_DATASTREAMS 4 // make sure that remoteSensor array is big enough to fit all the remote data streams -------1-------
#define UPDATE_INTERVAL 10000 // if the connection is good wait 10 seconds before updating again - should not be less than 5
#define RESET_INTERVAL 10000 // if connection fails/resets wait 10 seconds before trying again - should not be less than 5
#define PACHUBE_API_KEY ***// fill in your API key -> I know to fill mine in here
byte mac[] = { 0xAA, 0xAB, 0xBB, 0xBC, 0xCC, 0x99 }; // make sure this is unique on your network -------2-------
byte ip[] = { 192, 168, 0, 144 }; // no DHCP so we set our own IP address -------3-------
byte remoteServer[] = { 209,40,205,190 }; // pachube.com
float remoteSensor[REMOTE_FEED_DATASTREAMS]; // we know that feed 256 has floats - this might need changing for feeds without floats
void setup()
{
Serial.begin(57600);
setupEthernet();
pinMode(3, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
}
void loop()
{
// call 'pachube_in_out' at the beginning of the loop, handles timing, requesting
// and reading. use serial monitor to view debug messages
pachube_in_out();
// then put your code here, you can access remote sensor values
// by using the remoteSensor float array, e.g.: -------4-------
analogWrite(3, (int)remoteSensor[3] * 10); // remoteSensor is a float // -------5a-------
analogWrite(5, (int)remoteSensor[1]);
//my code starts here:
//TMP36 Pin Variables
int sensorPin = 0; //the analog pin the TMP36's Vout (sense) pin is connected to -------5b-------
//the resolution is 10 mV / degree centigrade with a
//500 mV offset to allow for negative temperatures
/*
* setup() - this function runs once when you turn your Arduino on
* We initialize the serial connection with the computer
*/
void setup()
{
Serial.begin(9600); //Start the serial connection with the computer
//to view the result open the serial monitor
}
void loop() // run over and over again
{
//getting the voltage reading from the temperature sensor
int reading = analogRead(sensorPin);
// converting that reading to voltage, for 3.3v arduino use 3.3
float voltage = reading * 5.0 / 1024;
// print out the voltage
Serial.print(voltage); Serial.println(" volts");
// now print out the temperature
float temperatureC = (voltage - 0.5) * 100 ; //converting from 10 mv per degree wit 500 mV offset
//to degrees ((volatge - 500mV) times 100)
Serial.print(temperatureC); Serial.println(" degress C");
// now convert to Fahrenheight
float temperatureF = (temperatureC * 9 / 5) + 32;
Serial.print(temperatureF); Serial.println(" degress F");
delay(1000); //waiting a second
}
//my code ends here.
// you can have code that is time sensitive (e.g. using 'delay'), but
// be aware that it will be affected by a short pause during connecting
// to and reading from ethernet (approx. 0.5 to 1 sec).
// e.g. this code should carry on flashing regularly, with brief pauses
// every few seconds during Pachube update.
digitalWrite(6, HIGH);
delay(100);
digitalWrite(6, LOW);
delay(100);
}
- How do i know the number of datastreams? Is it just how many sensors you have?
- Can the mac address be anything or is there a for this must conform to?
- Do you have to set your own IP? Or was the example saying they don't have dhcp so they had to assign one?
- Do I put my code there or does it go where I put it? See comments //my code starts here and //my code ends here.
5a/b Do I need to change any of this so that it reads the correct sensor and if so what do I change. - What else do I need to know/do.
I just want to get a working feed onto pachube. Any help is appreciated. I hope that I could eventually put together a step-by-step tutorial that is a little more detailed than those available from the pachube site. Thanks in advance.