Show Posts
Pages: [1] 2 3
1  Using Arduino / Networking, Protocols, and Devices / Re: Sending data from DHT11 to Xively using Xbees [SOLVED] on: May 21, 2014, 10:02:40 pm
I am very pleased to say that I have changed the reciever sketch and can now send  temperature and humidity readings to Xively via Xbees (Pro S1) .

The code below is my latest version of the reciever code and although very clumsy it works for the moment.  Using Serial.parse() and making sure my coding syntax, particularly the placement of curly brackets was correct seemed to help. However I have learned much and hope to write a more efficient version soon. 

Next step is to test the range of the XBees.  Am hoping to get about 500 metres, line of sight, outdoors.





Code:
#include <SPI.h>
#include <Ethernet.h>
#include <HttpClient.h>
#include <Xively.h>

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


// MAC address for your Ethernet shield
byte mac[] = {
  XXXXXXXXXXX };

char inData[24]; // for reading serial from tx
byte index;  // for reading serial from tx
boolean started = false; // for reading serial from tx
boolean ended  = false; // for reading serial from tx

// Your Xively key to let you upload data
char xivelyKey[] = "XXXXXXXXXXXXXXXXXXX";



// Define the strings for our datastream IDs

char dht11temp[] = "temperature";
char dht11hum[] = "humidity";

const int bufferSize = 140;
char bufferValue[bufferSize]; // enough space to store the string we're going to send
XivelyDatastream datastreams[] = {
  XivelyDatastream(dht11temp, strlen(dht11temp), DATASTREAM_FLOAT),
 XivelyDatastream(dht11hum, strlen(dht11hum), DATASTREAM_FLOAT),
 
 
};

XivelyFeed feed(XXXXXXXX, datastreams, 2 /* number of datastreams */);

EthernetClient client;
XivelyClient xivelyclient(client);


void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);

  Serial.println("Starting multiple datastream upload to Xively...");
  Serial.println();

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

void loop()
{
  // main program loop
if (millis() - lastConnectionTime > connectionInterval)
{
  Serial.flush();
 
  while (Serial.available() == 0);
{
  char ch = Serial.read();
  if(ch == 'T') // Wait for the capital T. 
{

long t = Serial.parseInt(); //Temperature

datastreams[0].setFloat(t); // The maths is there to convert mV into V.
Serial.print("Read Temperature ");
Serial.println(datastreams[0].getFloat());



   Serial.println("Uploading it to Xively");
   int ret = xivelyclient.put(feed, xivelyKey);
   Serial.print("xivelyclient.put returned ");
   Serial.println(ret);


   
   
Serial.println();

lastConnectionTime = millis();
  }
  else if (ch == 'H')
  {
  long h = Serial.parseInt(); //Humidity

datastreams[1].setFloat(h); // The maths is there to convert mV into V.
Serial.print("Read Humidity ");
Serial.println(datastreams[1].getFloat());



   Serial.println("Uploading it to Xively");
   int ret = xivelyclient.put(feed, xivelyKey);
   Serial.print("xivelyclient.put returned ");
   Serial.println(ret);
   
   Serial.println();

lastConnectionTime = millis();
  }
}
}
}
2  Using Arduino / Networking, Protocols, and Devices / Re: Sending data from DHT11 to Xively using Xbees on: May 13, 2014, 07:54:35 pm
Thanks for those suggestions and questions Paul, I will follow them through as I still haven't solved the problem but am determined to sort it out.

3  Using Arduino / Networking, Protocols, and Devices / Re: Sending data from DHT11 to Xively using Xbees on: May 12, 2014, 04:54:22 pm
Thanks again Rob,  I will follow up on your suggestions and will post my results.
4  Using Arduino / Networking, Protocols, and Devices / Re: Sending data from DHT11 to Xively using Xbees on: May 12, 2014, 06:32:54 am
Hi Rob and others.

I have modified the code as you suggested however still no luck.  I cannot seem to get the temperature and humidity values to be read into the datastreams  for Xively.  Here is the code I am now using. 

Code:
#include <SPI.h>
#include <Ethernet.h>
#include <HttpClient.h>
#include <Xively.h>



// MAC address for your Ethernet shield
byte mac[] = { xxxxxx };

char inData[24]; // for reading serial from tx
byte index;  // for reading serial from tx
boolean started = false; // for reading serial from tx
boolean ended  = false; // for reading serial from tx

// Your Xively key to let you upload data
char xivelyKey[] = "xxxxx";

// Analog pin which we're monitoring (0 and 1 are used by the Ethernet shield)
//int sensorPin = 2;

// Define the strings for our datastream IDs
char sensorId[] = "humidity";
char sensorId2[] = "temperature";

const int bufferSize = 140;
char bufferValue[bufferSize]; // enough space to store the string we're going to send
XivelyDatastream datastreams[] = {
  XivelyDatastream(sensorId, strlen(sensorId), DATASTREAM_FLOAT),
  XivelyDatastream(sensorId2, strlen(sensorId2), DATASTREAM_FLOAT),

};
// Finally, wrap the datastreams into a feed
XivelyFeed feed(xxxxxx, datastreams, 2 /* number of datastreams */);

EthernetClient client;
XivelyClient xivelyclient(client);


void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);

  Serial.println("Starting multiple datastream upload to Xively...");
  Serial.println();

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


 void handleINcomingSerial()
{

//start of code to read from transmitter
while(Serial.available() > 0)
  {
    char aChar = Serial.read();
    if(aChar == '<')
    {
      started = true;
      index = 0;
      inData[index] = '\0';
    }
    else if(aChar == '>')
    {
      ended = true;
    }
    else if(started)
    {
      inData[index] = aChar;
      index++;
      inData[index] = ',';
    }
  } 
}

void printValues()
{
  // Use the value
  if(inData[0] == 'T')
  {
    inData[0] = ' ';
    int temp = atoi(inData);
    Serial.println(" ");
    Serial.print("Temp:");
    Serial.print(inData);
    Serial.print("C");
    Serial.println(" ");
  }
  else if(inData[0] == 'H')
  {
    inData[0] = ' ';
    int hum = atoi(inData);
    Serial.println(" ");
    Serial.print("Humidity:");
    Serial.print(inData);
    Serial.print("%");
    Serial.println(" ");
  }
}


void sendoToXively()
{
  float t = temp;  //already in tx code
  float h = hum;   // already in tx code

 
  datastreams[0].setFloat(temp);
  datastreams[1].setFloat(hum);
 
  Serial.print("Read sensor value temp ");
  Serial.println(datastreams[0].getFloat());
  Serial.print("Read sensor value hum ");
  Serial.println(datastreams[1].getFloat());


  Serial.println("Uploading it to Xively");
  int ret = xivelyclient.put(feed, xivelyKey);
  Serial.print("xivelyclient.put returned ");
  Serial.println(ret);

  Serial.println();
}


void loop()
{
  handleINcomingSerial();



  if(started && ended)
  {
    printValues();
   
    sendoToXively();

    started = false;
    ended = false;
    index = 0;
    inData[index] = '\0';
  }

  delay(15000);
}

When I compile this code I get a "temp is not definded in this scope" error message.  If I define "temp" and "hum" as global variables the sketch then compiles and runs ok but I get 0 as values for temperature and humidity so I suspect the values are not getting into the "sendoToXively" function.

I'm sure I am doing something wrong but I hope another set of eyes could spot my error!

Many thanks,

Steve
5  Using Arduino / Networking, Protocols, and Devices / Re: Sending data from DHT11 to Xively using Xbees on: May 10, 2014, 05:23:46 pm
Thank you Robtillaart!

I will try your suggestions later on today and will report back...

6  Using Arduino / Networking, Protocols, and Devices / Sending data from DHT11 to Xively using Xbees [SOLVED] on: May 10, 2014, 09:13:24 am
Hello,

I am trying to send temperature and humidity data from a DHT11 sensor between two Arduino Mega 2560's using Xbees.  The code for the transmitter is as follows


Code:
#include "DHT.h"
#define DHTPIN 2    
#define DHTTYPE DHT11  
DHT dht(DHTPIN, DHTTYPE);

void setup()
{
Serial.begin(9600);
}

void loop()
{

float h = dht.readHumidity();
float t = dht.readTemperature();

Serial.print("<T:");
Serial.print(t);
Serial.print(">");

delay(2000);

Serial.print("<H:");
Serial.print(h);
Serial.print(">");

delay(2000);
}

The code for the receiving Arduino is as follows:-
Code:
#include <SPI.h>
#include <Ethernet.h>
#include <HttpClient.h>
#include <Xively.h>


// MAC address for your Ethernet shield
byte mac[] = { mac address };
int hum;
int temp;
char inData[24]; // for reading serial from tx
byte index;  // for reading serial from tx
boolean started = false; // for reading serial from tx
boolean ended  = false; // for reading serial from tx

// Your Xively key to let you upload data
char xivelyKey[] = "xivelykey";

// Analog pin which we're monitoring (0 and 1 are used by the Ethernet shield)


// Define the strings for our datastream IDs
char sensorId[] = "humidity";
char sensorId2[] = "temperature";
const int bufferSize = 140;
char bufferValue[bufferSize]; // enough space to store the string we're going to send
XivelyDatastream datastreams[] = {
  XivelyDatastream(sensorId, strlen(sensorId), DATASTREAM_FLOAT),
  XivelyDatastream(sensorId2, strlen(sensorId2), DATASTREAM_FLOAT),
 
};
// Finally, wrap the datastreams into a feed
XivelyFeed feed(xxxxxx, datastreams, 2);/* number of datastreams */

EthernetClient client;
XivelyClient xivelyclient(client);


void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  
  Serial.println("Starting multiple datastream upload to Xively...");
  Serial.println();

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

void loop() {
 
 //start of code to read from transmitter
 while(Serial.available() > 0)
  {
char aChar = Serial.read();
if(aChar == '<')
{
   started = true;
   index = 0;
   inData[index] = '\0';
}
else if(aChar == '>')
{
   ended = true;
}
else if(started)
{
   inData[index] = aChar;
   index++;
   inData[index] = ',';
}
  }

  if(started && ended)
  {
// Use the value
if(inData[0] == 'T')
{
  inData[0] = ' ';
           int temp = atoi(inData);
           Serial.println(" ");
  Serial.print("Temp:");
           Serial.print(inData);
           Serial.print("C");
           Serial.println(" ");
        
}
else if(inData[0] == 'H')
     {
  inData[0] = ' ';
           int hum = atoi(inData);
  Serial.println(" ");
           Serial.print("Humidity:");
           Serial.print(inData);
           Serial.print("%");
           Serial.println(" ");
          
     }

started = false;
ended = false;

index = 0;
inData[index] = '\0';
  }
  
  //end of code to read from transmitter

  datastreams[0].setFloat(temp);
  datastreams[1].setFloat(hum);
 
 
 
  Serial.print("Read sensor value temp ");
  Serial.println(datastreams[0].getFloat());
  Serial.print("Read sensor value hum ");
  Serial.println(datastreams[1].getFloat());
 

  Serial.println("Uploading it to Xively");
  int ret = xivelyclient.put(feed, xivelyKey);
  Serial.print("xivelyclient.put returned ");
  Serial.println(ret);

  Serial.println();
    
  delay(15000);
}


I can send the data to Xively directly from an Arduino ok and I can send and receive the temperature and humidity data between the two Arduino's via the Xbees ok but I can't seem to integrate the serial communication between the Arduino's with Xively.  Whenever I try cannot get the temperature and humidity readings.  If someone could have a look at my code and suggest where I am going wrong that would be most appreciated.

Kind Regards
7  Using Arduino / Motors, Mechanics, and Power / Re: Simple sketch to drive a stepper motor with a RC transitter on: October 08, 2013, 03:39:59 pm
Thanks Robin. I will give that a go.  Cheers.
8  Using Arduino / Motors, Mechanics, and Power / Simple sketch to drive a stepper motor with a RC transitter on: October 06, 2013, 09:05:42 pm
Hello All,

I thought I would share this simple sketch that I have cobbled together to operate a Leadshine 57HS22-C stepper motor using a Leadshine M325 driver and a Arduino Mega 2560 via remote control.  The radio transmitter is a Turnigy 9x and  a Turnigy reciever.  The Arduino is recieving the signals from Ch1 of the reciever via pin 6.  Pin 5 of the Arduino is going to the DIR (direction) pin of the stepper driver and Pin 4 is going to the PUL (pulse) pin of the stepper driver and 5V from the Arduino is going to the OPTO pin of the stepper driver.

When operating the stepper moves up to 180 degrees in one direction for a left or right movement of the transmitter control stick (in this case the aileron control of the mode 1 Turnigy 9x).  It seems to work reasonably well although there is some "chatter" when stationary.

I hope someone finds this of use but please feel free to offer suggestions or improvements.

Code:
#include <AccelStepper.h>
// Define a stepper and the pins it will use
AccelStepper stepper(1, 4, 5);

int steps;
int ch1; // Here's where we'll keep our channel values
void setup()

  Serial.begin(9600);
  pinMode(6, INPUT); // Set our input pins as such
  stepper.setMaxSpeed(3000);
  stepper.setAcceleration(3000);
}
void loop()
{
  if (stepper.distanceToGo() == 0)
  ch1 = pulseIn(6, HIGH, 25000); // Read the pulse width of
  steps=(map(ch1, 1065,1915,-100,100)); // center at 0
  stepper.moveTo(steps);
  stepper.run();
  Serial.println(ch1);
}
9  Using Arduino / Motors, Mechanics, and Power / Re: Wiring arduino mega to high current stepper motor control on: September 16, 2013, 05:24:24 pm
Thanks Mark.  Yes I have wired it up as shown in Figure 2.  I haven't used any resistors as the voltage from the Arduino is 5 v.  But it seems to be working ok.

Cheers
10  Using Arduino / Motors, Mechanics, and Power / Re: Wiring arduino mega to high current stepper motor control on: September 16, 2013, 08:52:50 am
Thanks db,

I have tried it with 5v from the arduino going to opto, pin 4 going to pul and pin 5 going to dir.  I tried a simple sketch and it seems to be working fine.

Thanks for your thoughts, i will keep them in mind as I continue to to learn about steppers.

Cheers,

Steve
11  Using Arduino / Motors, Mechanics, and Power / Wiring arduino mega to high current stepper motor control on: September 16, 2013, 01:13:32 am
Hello,

I would like to use an Arduino Mega to control a stepper motor via a Leadshine M325 or(or M422) stepper motor controller (http://oceancontrols.com.au/datasheet/lea/smc010_DM422Cm.pdf).  I have sorted out how to hook up the motor and 24v power supply to the M325 but I would like some clarification on how to wire the arduino into the opto, pul, dir and ena pins.

I think 5v from the arduino goes to the opto pin, any 2 digital pins go to the pul and dir pins and I don't necessarily need to use the enable pin?

Thankyou for your advice.
12  Using Arduino / Programming Questions / Re: Seeeduino NFC SPI library on: June 11, 2013, 08:34:13 am
Thanks for checking it out for me Paul.  I couldn't see the .h or .cpp files or examples folder when I was trying to download it earlier.  But when you confirmed that they were there I tried again and they turned up! Consequently I tried a couple of example sketches and have been able to read some NFC tags. 

Good result, many thanks!

Steve
13  Using Arduino / Programming Questions / Re: Seeeduino NFC SPI library on: June 11, 2013, 07:10:58 am
Good point Paul! From here:-

http://www.seeedstudio.com/wiki/File:PN532_SPI_V2.zip
14  Using Arduino / Programming Questions / Seeeduino NFC SPI library on: June 11, 2013, 05:59:03 am
Hello,

I have just received a Seeeduino NFC shield.  I have tried to download the Seeeduino NFC library however the library does not appear to be complete and despite unzipping the file to my arduino library file there are no examples appearing in the Arduino IDE.  Has anyone come across this problem and been able to use the library?  I am using an Arduino Mega 2560.

Kind regards.

15  Using Arduino / Motors, Mechanics, and Power / Re: What Arduino output signal is required for 12DC motor speed controller? on: May 06, 2013, 04:19:16 pm
Thanks for your time and advice Chargrin, I will keep looking.
Pages: [1] 2 3