Show Posts
Pages: 1 ... 15 16 [17] 18 19
241  Using Arduino / Project Guidance / Re: Trouble using analogRead when ethernet shield is plugged into the arduino on: July 19, 2012, 05:31:16 am
I tried it on two of the pins and it happened on both of them.  I have the divider set up, with a 100K resistor from the arduino 5V pin to A1, and a thermistor connected from A1 to the arduino ground pin.  When I connect it this way directly to the arduino without the shield I measure 4.97 volts across the 5V and ground pins, 330mv across the 100K resistor and 4.64V across the thermistor.  When I use the exact same configuration, except I connect it to the arduino through the ethernet shield I get 4.97V across the 5V and ground pins, 30mv across the 100K resistor and 4.94V across the thermistor.  So it's not really the ADC that is the problem.
242  Using Arduino / Project Guidance / Trouble using analogRead when ethernet shield is plugged into the arduino on: July 17, 2012, 08:31:13 pm
Is there something about the ethernet shield that would cause a problem with the ADC on the mega328?  I made a small voltage divider that incorporates a 100K resister and a thermistor and when it is plugged into the arduino directly it works fine but when it is plugged into the arduino through the ethernet shield I get values that are completely off.  Can anyone shed any light on this for me? Sketch is below.

Code:


/*
 * BBQControl.c
 *
 * Created: 8/7/2011 12:34:32 PM
 *  Author: Saleem and Leslie
 */

 

#define LCD_Command_A 0x7C
#define LCD_Command_B 0xFE
#define LCD_Clear_Screen 0x01
#define LCD_Cursor_Position(a) {Serial.print(LCD_Command_B,BYTE); Serial.print(a+128,BYTE);}
#define chipSelect 10
#define thermPin A1

#include <math.h>
#include <stdint.h>
#include <PID_v1.h>
#include <stdio.h>
#include <string.h>

//PID Variables
double Input = 0;  //Our Current Temperature
double Output = 0;  //Our Control Variable
double Setpoint = 0;  //Our Setpoint
double Kp = 10;      //Proportional
double Ki = .1;      //Integral
double Kd = 50;      //Derivative

PID myPID(&Input, &Output, &Setpoint, Kp, Ki, Kd, DIRECT);
 
void setup()
{
pinMode(thermPin,INPUT);  //Thermistor is connected to A1
Serial.begin(9600);
        myPID.SetMode(AUTOMATIC);  //start PID
}       



void loop()
{
    uint16_t ADCVal;
    uint16_t temperature;
   
    //String dataString = "";
   
    //ADCVal = analogRead(thermPin);
   
    //temperature = (get_temperature(ADCVal));  //get temperature conversion
   
    for(int i = 0;i<100;i++)
    {
      ADCVal = analogRead(thermPin);
      temperature += (get_temperature(ADCVal));  //add 99 more conversions
    }
   
    temperature = temperature/100;  //average them
    Input = (double)temperature;    //load new temperature into our PID Algorithm
    myPID.Compute();                //compute new output value
    //Serial.println(Input);          //print output to out monitor
    //Serial.println(Output);
   
   if(Serial.available())   //check to see if the user has sent
                                   //any new parameters
    {
      char myString[40];   //buffer to hold my received string
      char *str;           //pointer for strtok function
      receive_serial(&myString[0]);  //get serial data
      //Serial.println(myString);      //debugging
      double PID_Params[4];          //array to hold my new parameters
      double *my_params = PID_Params;
      str = strtok (myString,",");   //split mystring into 4 pieces using comma delimiter, reference:
      while (str != NULL)            //http://www.cplusplus.com/reference/clibrary/cstring/strtok/
      {
        *my_params = atof(str);    //convert strings segments to doubles
        my_params++;
        //Serial.println(str);
        str = strtok (NULL, ",");  //strtok expects a NULL pointer for all
      }                            //subsequent calls after the first call
      Setpoint = PID_Params[0];
      myPID.SetTunings(PID_Params[1],PID_Params[2],PID_Params[3]);
     
     
    }
   
    //Send all of the data to our monitor in comma delimited format
    Serial.print(temperature);   
    Serial.print(",");
    Serial.print(ADCVal);
    Serial.print(",");
    Serial.print(Setpoint,0);
    Serial.print(",");
    Serial.print(myPID.GetKp(),4);
    Serial.print(",");
    Serial.print(myPID.GetKi(),4);
    Serial.print(",");
    Serial.println(myPID.GetKd(),4);
   
    delay(100);
}

void receive_serial(char *String)
{
  int i = Serial.available(); //Serial.available returns number of bytes
  delay(10);                  //in the Serial buffer
 
  //wait to make sure that all bytes have been received
  while(i != Serial.available())  //if i does not equal Serial.available then
  {                              //that means we are still receiving bytes.
    i = Serial.available();
    delay(10);
  }
 
  //Read serial data into address pointed to by String
  while(Serial.available())
  {
    *String = Serial.read();
    String++;
    *String = '\0';
  }

}



void get_parameters(uint16_t ADCvalue, uint16_t *beta, float *r_infinity)
{

if      (ADCvalue < 15)   {*beta = 5191; *r_infinity=0.07028;}
else if (ADCvalue <= 39)  {*beta = 5085; *r_infinity=0.08597;}
else if (ADCvalue <= 158) {*beta = 4942; *r_infinity=0.11637;}
else if (ADCvalue <= 530) {*beta = 4767; *r_infinity=0.17766;}
else if (ADCvalue <= 577) {*beta = 4671; *r_infinity=0.23249;}
else if (ADCvalue <= 670) {*beta = 4641; *r_infinity=0.25289;}
else if (ADCvalue <= 757) {*beta = 4604; *r_infinity=0.28168;}
else if (ADCvalue <= 832) {*beta = 4566; *r_infinity=0.31618;}
else if (ADCvalue <= 892) {*beta = 4526; *r_infinity=0.35779;}
else if (ADCvalue <= 938) {*beta = 4485; *r_infinity=0.40755;}
else if (ADCvalue <= 1023){*beta = 4453; *r_infinity=0.45243;}
return;
}


//*************Hardware SetUp***************
//
//     ADC Input
//        |
//        Rpad    |  Rtherm
// Vcc--------/\/\/\------/\/\/\------ground
//
//******************************************


float get_temperature(uint16_t ADCVal){
//temperature in kelvin = beta/ln(R/Rinfinity)
uint16_t beta = 0;
        uint8_t servo_command;
float Ri = 0;
float Rpad = 100000;
float Rtherm = Rpad/(1-((float)ADCVal/1024.0)) - 100000;
float Temperature;
float t;
//Serial.println(Rtherm);
get_parameters(ADCVal, &beta, &Ri);

t=beta/log(Rtherm/Ri);
t = ((9.0/5.0)*(t-273))+32;
Temperature = t;


//Out to LCD
//LCD_Cursor_Position(72);
//Serial.print(ADCVal);
        //Serial.print("    ");
//LCD_Cursor_Position(28);
        //Serial.print(beta);
        //Serial.print("    ");
//LCD_Cursor_Position(8);
return Temperature;

}





243  Using Arduino / Installation & Troubleshooting / Re: .hex file path on: July 17, 2012, 08:19:31 pm
I had to "make visible" all folders and files to find the .hex file when I did what you are doing.  For some reason on my Mac it was putting the files in a hidden folder.
244  Using Arduino / Project Guidance / Re: Setting up Arduino Webserver for remote access on: July 05, 2012, 01:56:27 pm
Fantastic explanation PaulS!  I appreciate that!  So it sounds like I need to do two things.  First I need to take advantage of a service like dynDNS and second would be to enable port forwarding on my router.  I think my router should take care of updating dynDNS when the IP Address changes (I hope).
245  Using Arduino / Project Guidance / Setting up Arduino Webserver for remote access on: July 04, 2012, 09:46:14 pm
I have been googling all day for a comprehensive set of instructions that will allow an Arduino with Ethernet Shield to be visible to the whole world versus just being visible to my local area network.  I did this example:

http://bildr.org/2011/06/arduino-ethernet-pin-control/

but of course it only works with a local connection.  I would like to be able to access my arduino remotely from anywhere but there doesn't seem to be a lot on the web about it.  I have a cable internet modem connected to a linksys E1200 wireless router.  I have found a few things that I don't understand very well such as dynamic dns and port forwarding and I am sure that I have found some of the pieces, but I just don't know how to put them together.  Can someone help me out with this?
246  Using Arduino / Installation & Troubleshooting / Re: Solder bridges on ethernet shield purchased online.....suggestions? on: July 03, 2012, 06:47:56 am
Thanks!  I checked the datasheet and cross checked it against the schematic and all of those pins are grounded so it should be fine as is.  I am hopefully going to try out my first application with it tonight so we will see how it does.
247  Using Arduino / Installation & Troubleshooting / Solder bridges on ethernet shield purchased online.....suggestions? on: July 02, 2012, 02:13:26 pm
I purchased this ethernet shield from a Chinese distributor off of ebay.  Upon inspection it appears to have quite a few solder bridges on the WIZnet chip.  I know that most of the pins on that chip are grounded so it may not matter if there are bridges but I am not confident that I would be able to figure out which ones are okay and which aren't.  Is running a hot soldering iron across all of the pins the best way to resolve this?


IMAG0475 by jg1996business, on Flickr


IMAG0475-1 by jg1996business, on Flickr


IMAG0476 by jg1996business, on Flickr


IMAG0476-1 by jg1996business, on Flickr
248  Using Arduino / Programming Questions / Re: Writing from Serial to Char array and then Serial.print(array) not working on: January 01, 2012, 06:37:10 pm
All of these recommendations worked great!  Thank you PaulS and WizenedEE!
249  Using Arduino / Programming Questions / Re: Writing from Serial to Char array and then Serial.print(array) not working on: January 01, 2012, 08:48:32 am
The functions that operate on strings (lower case s) expect strings, not arrays of chars. The difference is that a string is an array of chars that is NULL terminated. Your array of chars is NOT a string, so you should not be passing the array to a function that expects a string, like Serial.print().

NULL terminate your array. Of course, that means that you need to make the array big enough to hold the NULL.

PaulS - Adding the NULL termination fixed it and it is echoing back the data perfectly!  Thank you for that fix.  To add the NULL I just added it manually via:

Code:
int j = 0;
  while(Serial.available())
  {
    
    myString[j] = Serial.read();
    ++j;
    
    
  }
  myString[j] = '\0';
  
  Serial.println(myString);

Is that the typical way to do it or did I characteristically do it the ugliest possible way?  Also WizenedEE brought up a good point that the compiler doesn't know how much space to allocate to myString at compile time so does the fact that it compiled and ran correctly mean that I am just getting lucky that I am not overwriting important stuff during the execution?  My code is still using this:

Code:
char myString[Serial.available()];
250  Using Arduino / Programming Questions / Re: Writing from Serial to Char array and then Serial.print(array) not working on: December 31, 2011, 11:52:33 pm
That makes sense that the compiler needs to know how much memory to allocate to myString but is there any way to do it on the fly?  I won't know before hand how many bytes are going to be sent.  It will be comma delimited data that I will need to break up into separate variables to update my Setpoint, Kp, Ki, and Kd variables.
251  Using Arduino / Programming Questions / Re: Writing from Serial to Char array and then Serial.print(array) not working on: December 31, 2011, 11:44:07 pm
Sorry....this is all of the code:

Code:
/*
 * BBQControl.c
 *
 * Created: 8/7/2011 12:34:32 PM
 *  Author: Saleem and Leslie
 */

 

#define LCD_Command_A 0x7C
#define LCD_Command_B 0xFE
#define LCD_Clear_Screen 0x01
#define LCD_Cursor_Position(a) {Serial.print(LCD_Command_B,BYTE); Serial.print(a+128,BYTE);}
#define chipSelect 10

#include <math.h>
#include <stdint.h>
#include <PID_v1.h>
#include <stdio.h>

//PID Variables
double Input = 0;  //Our Current Temperature
double Output = 0;  //Our Control Variable
double Setpoint = 0;  //Our Setpoint
double Kp = 10;      //Proportional
double Ki = .1;      //Integral
double Kd = 50;      //Derivative

PID myPID(&Input, &Output, &Setpoint, Kp, Ki, Kd, DIRECT);
 
void setup()
{
pinMode(A0,INPUT);
Serial.begin(9600);
        myPID.SetMode(AUTOMATIC);
}       

uint32_t count;


void loop()
{
    uint16_t ADCVal;
    uint16_t temperature;
    //String dataString = "";
   
    ADCVal = analogRead(A0);
   
    temperature = (get_temperature(ADCVal));
   
    for(int i = 0;i<98;i++)
    {
      ADCVal = analogRead(A0);
      temperature += (get_temperature(ADCVal));
    }
   
    temperature = temperature/100;
    Serial.println(temperature);
    Input = (double)temperature;
    myPID.Compute();
    Serial.println(Input);
    Serial.println(Output);
   
   if(Serial.available())
    {
      receive_serial();
    }
   
   
     
    delay(1000);
}

void receive_serial()
{
  int i = Serial.available();
  delay(10);
 
  //wait to make sure that all bytes have been received
  while(i != Serial.available())
  {
    i = Serial.available();
    delay(10);
  }
 
  char myString[Serial.available()];
 
 
  while(Serial.available())
  {
    int j = 0;
    myString[j] = Serial.read();
    ++j;
     
  }
 
  Serial.print(myString);
}

void get_parameters(uint16_t ADCvalue, uint16_t *beta, float *r_infinity)
{

if      (ADCvalue < 15)   {*beta = 5191; *r_infinity=0.07028;}
else if (ADCvalue <= 39)  {*beta = 5085; *r_infinity=0.08597;}
else if (ADCvalue <= 158) {*beta = 4942; *r_infinity=0.11637;}
else if (ADCvalue <= 530) {*beta = 4767; *r_infinity=0.17766;}
else if (ADCvalue <= 577) {*beta = 4671; *r_infinity=0.23249;}
else if (ADCvalue <= 670) {*beta = 4641; *r_infinity=0.25289;}
else if (ADCvalue <= 757) {*beta = 4604; *r_infinity=0.28168;}
else if (ADCvalue <= 832) {*beta = 4566; *r_infinity=0.31618;}
else if (ADCvalue <= 892) {*beta = 4526; *r_infinity=0.35779;}
else if (ADCvalue <= 938) {*beta = 4485; *r_infinity=0.40755;}
else if (ADCvalue <= 1023){*beta = 4453; *r_infinity=0.45243;}
return;
}


//*************Hardware SetUp***************
//
//     ADC Input
//        |
//        Rpad    |  Rtherm
// Vcc--------/\/\/\------/\/\/\------ground
//
//******************************************


float get_temperature(uint16_t ADCVal){
//temperature in kelvin = beta/ln(R/Rinfinity)
uint16_t beta = 0;
        uint8_t servo_command;
float Ri = 0;
float Rpad = 100000;
float Rtherm = Rpad/(1-((float)ADCVal/1024.0)) - 100000;
float Temperature;
float t;

get_parameters(ADCVal, &beta, &Ri);

t=beta/log(Rtherm/Ri);
t = ((9.0/5.0)*(t-273))+32;
Temperature = t;


//Out to LCD
//LCD_Cursor_Position(72);
//Serial.print(ADCVal);
        //Serial.print("    ");
//LCD_Cursor_Position(28);
        //Serial.print(beta);
        //Serial.print("    ");
//LCD_Cursor_Position(8);
return Temperature;

}
252  Using Arduino / Programming Questions / Writing from Serial to Char array and then Serial.print(array) not working on: December 31, 2011, 10:42:07 pm
I have written a routine that is executed when serial data is available.  First it waits to make sure all bytes have been received and then it writes those bytes to a character array.  For debugging I wanted to then serially print that data back to the serial monitor to make sure that the data was coming in correctly.  When I execute the code I just get junk back on the Serial monitor.  I hope someone can tell me what I might be doing wrong.  My code is below:

Code:
void receive_serial()
{
  int i = Serial.available();
  delay(10);
 
  //wait to make sure that all bytes have been received
  while(i != Serial.available())
  {
    i = Serial.available();
    delay(10);
  }
 
  char myString[Serial.available()];
 
 
  while(Serial.available())
  {
    int j = 0;
    myString[j] = Serial.read();
    ++j;
     
  }
 
  Serial.print(myString);
}
253  Using Arduino / Programming Questions / Re: simple question about variable creation and initialization in loop() on: October 08, 2011, 03:28:51 pm
Thanks for the replies.  I guess I have always tried to limit the use of global variables only because I had read somewhere that it is poor form to declare lots of global variables.  Of course that was programming a simple application in C# so perhaps that doesn't apply here.
254  Using Arduino / Programming Questions / simple question about variable creation and initialization in loop() on: October 08, 2011, 02:35:02 pm
I am very much an amateur with all things programming related so I am curious about the normal use of the static keyword when declaring a variable.  I have slightly more experience programming with avrstudio in C whereby in my main function I will first declare my variables and then use a 'while' loop to cycle through my code that actually has action items.  I notice that the equivalent process in arduino is to declare my variables all as static to avoid having the loop function create and initialize them on each iteration through my loop.  Is this pretty typical to declare all variables in loop as static if you don't want to reinitialize them every time?  For example it seems that:

Code:
void main()
{
int i = 0;
int j = 10;

while(1)
{
i++;
j--;
}
}

is not equivalent to:

Code:
void loop()
{
int i = 0;
int j = 10;

i++;
j--;

}

but is equivalent to:

Code:
void loop()
{
static int i = 0;
static int j = 10;

i++;
j--;
}

255  Using Arduino / Programming Questions / Re: Writing to SD Card causes MCU to restart after 12 iterations of the loop on: September 03, 2011, 06:25:28 pm
Once again that worked like a charm!  I really appreciate your help!
Pages: 1 ... 15 16 [17] 18 19