Show Posts
Pages: 1 ... 16 17 [18] 19 20
256  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).
257  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?
258  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.
259  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
260  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!
261  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()];
262  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.
263  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;

}
264  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);
}
265  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.
266  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--;
}

267  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!
268  Using Arduino / Programming Questions / Re: Writing to SD Card causes MCU to restart after 12 iterations of the loop on: September 03, 2011, 05:42:22 pm
First off, Nick and Wildbill, your suggestions worked great.  However, I ran into another problem.  Is there any difference between:

Code:
sprintf (buff, "%u,%u", count++, temperature);

and

Code:
sprintf (buff, "%u,%u", temperature, count++);

The reason I ask is that the first method doesn't work.  It adds count++ to the buffer but temperature always gets written to buff as zero such as:

Code:
0,0
1,0
2,0
3,0

The second method works great printing:

Code:
74,0
74,1
74,2
74,3

Here is the whole code segment:

Code:
uint32_t count;
void loop()
{
    uint16_t ADCVal;
   
    uint16_t temperature;
    //String dataString = "";
    char buff[15];
    ADCVal = analogRead(A0);
    temperature = (get_temperature(ADCVal));
    sprintf (buff, "%u,%u", temperature, count++);

It wouldn't be the end of the world to have:

Code:
temperature, count

printed to the SD card but it bugs me as to why one way works and the other doesn't.
269  Using Arduino / Programming Questions / Re: Writing to SD Card causes MCU to restart after 12 iterations of the loop on: September 02, 2011, 08:35:09 am


Yes it does, but the String class uses dynamic memory allocation. This is prone to fragmentation. Especially if you are making counters and things which get larger, it is going to be allocating different sized pieces of memory.

Without checking your code in detail, you are probably better off using a static buffer, eg.

Code:
char buf [20];  // or whatever size you think you need

sprintf (buf, "%i,%i", a, b);  // print two numbers to buf

So would I just do it with:

Code:
sprintf(buf, "%i,%i", count++, temperature);
dataFile.println(buf); //out to sd card
270  Using Arduino / Programming Questions / Re: Writing to SD Card causes MCU to restart after 12 iterations of the loop on: September 02, 2011, 08:23:59 am
Quote
So you said if you replace the SD card writes with Serial prints, it doesnt happen?
When you say reset, does the whole arduino actually reset, or just the count variable?

No, I commented out a few serial prints in order to use less RAM thinking that may be the problem.  If I comment out all references to a "count" variable and just write the temperature to the SD card without a count  I don't have the problem.  Likewise if I don't have the SD card inserted at all (the program skips the code segment dealing with writing to the SD Card) I don't have the problem.

The whole arduino resets.  I thought maybe the writes to the SD card were pulling too much current so I put a check at the beginning of the program to see if the brownout flag was set but that doesn't seem to be the problem.
Pages: 1 ... 16 17 [18] 19 20