Show Posts
Pages: [1] 2 3
1  Using Arduino / Programming Questions / Strategizing an Arduino to Web Code & Learning on: March 05, 2013, 07:50:56 am
Hi guys,

I've learned about lots of stuff since getting my first arduino just a couple of months ago. Now that I have a working project, I would like to upgrade by allowing some interaction happen from and to internet. I do know some HTML but nothing about PHP so if you could bear with me and point me to the right direction, I'll try my best to learn everything I can to make the rest of the project work out.

My USERS:
  • They interact with Smart Cards that hold info such as Balance & user info (including email add)
  • If user has enough Balance, he/she can activate a Motor Shield and deduct Credit Balance
  • Interaction is then logged in the Smart Card and on a microSD

While this all works great. I'm now updating some string variables to accurately log the actions on the sketch and reloading it (the sketch) to the Arduino every 8 hours or so. I would love to do the following but don't know where to start:

  • Be able to update sketch's variables from a webpage and/or read them from a MySQL online.
  • Connect to COSM/Pachube to log user interaction.
  • Send an automate email with the recent activity on the account.

I'm not trying to get the code from you... Just looking for Advice and perhaps some resources such as Tutorials, Similar Projects, or other that will help me get there. All comments are welcomed!

PS: I'm already retrieving a time-stamp using the "Udp NTP Client" via an official Arduino Ethernet Shield R3, but tell you the truth I'm not really sure how this works (although it works fine jajaja).
2  Using Arduino / Programming Questions / Re: Easier way to convert float to char array on: February 13, 2013, 06:35:13 pm
The Arduino is used to interface motors and SmartCards EEPROM (reads and re-writes exactly those 5 bytes). Each Card will have a Time Balance (rechargeable at the end of each month). Each User that owns a SC is allowed some "xx.xx" time (mm.ss) of the interface with the motors each month. Hence, I read from the Cards the "Time Balance", then if time is available Arduino will allow the user to interface with the motors and subtract the "time of usage" to the Balance and (Re-Write the Time Balance on the Card).

Few considerations:
A user can accumulate Time Balance for the next month.
There will be more than 1 Arduino/Motor devices (so each SC should be able to interact with any one device).
3  Using Arduino / Programming Questions / Re: Easier way to convert float to char array on: February 13, 2013, 05:42:08 pm
There is nothing wrong with it, I'm printing the line to confirm that my code is right.
The main goal is to save the float as an array of chars i.e.: float number 71.53 to Array[]={'7','1','.','5','3'}
4  Using Arduino / Programming Questions / Easier way to convert float to char array on: February 13, 2013, 05:35:23 pm
Hi guys, this time I actually worked my way around the problem, but I was wondering if you could share some ideas about how to improve the following code. I'm reading an array of chars from an eeprom, I later transform this array via atof() and do some mathematical operations and the last thing to do is write back to the memory the new floating number in the form of an array of chars (lucky me that I only have 4 significant figures i.e.: 71.53).

Just wondering if "I discovered the wheel" (Spanish expression meaning that this was done before) and that It was much easier that I thought. If so, could you point me in that direction. If not, then this is my workaround.

PS: I'm trying to reduce the basic sketch size as much as possible.

Code:
//Number 71.53 to convert to FArray{ 7, 1, ., 5, 3}
float F = 71.53;
char FArray[6];

//Temporal Variables that hold figures (i.e.: F10 = tens, F1 = ones)
int Fint, F10, F1, F01, F001;

//Temporal variable that holds Modulo
int Mod1, Mod01;


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

void loop(){
floatToArray();
        delay(20000);
}

void floatToArray(){
Serial.println(F);  //Float to convert
        F = F * 100;
        Fint = (int)F;
        Mod1 = Fint % 1000;
        F10 = (Fint - Mod1)/1000;
Serial.println(F10); // Tens
        F1 = (Fint - (F10*1000));
        Mod01 = F1 % 100;
        F1 = (F1 - Mod01)/100;
        Serial.println(F1); // Ones
        Serial.println('.'); // just printing the dot
        F01 = (Mod01 - (Mod01%10))/10;
        Serial.println(F01); // 1st decimal figure
        F001 = (Mod01 - (F01*10));
        Serial.println(F001); //2nd decimal figure
FArray[0] = F10+48; //converting number to ascii
FArray[1] = F1+48; //converting number to ascii
FArray[2] = '.';
FArray[3] = F01+48; //converting number to ascii
FArray[4] = F001+48; //converting number to ascii
Serial.println(FArray);
}
5  Using Arduino / Programming Questions / Re: String or Char Arrays Length Definition on: February 06, 2013, 02:40:40 pm
I'm trying to do so, English is my second language and I'm not fluent in C++ either.

I don't know what to do with this phrase:
Quote
"and with what end of packet marker"

I understand the logic of stopping reading but don't know how... I tried using a Serial Reset as soon as it enters the if(index>smiley-cool [Serial.end() & Serial.begin()] with no luck. I just changed in the Serial Monitor the option beside the baud rate from 'No line ending' to 'Carriage return'.

I'm not being lazy I sometimes don't get everything 'I'm supposed to'...
6  Using Arduino / Programming Questions / Re: String or Char Arrays Length Definition on: February 06, 2013, 02:14:59 pm
I thought it was clear from before:

Code:
char Name[9] = ""; // My Data array
char inChar; // Where to store the character read
byte index = 0; // Index into array; where to store the character


void setup(){

Serial.begin(9600);

}

void loop(){
  if (Serial.available()>0){
     inChar = Serial.read();
     Name[index] = inChar; // Store it
     if (index>8){
         Serial.println("Invalid Input, please enter 3 to 8 characters");
         index = -1;
         Name[9] = '\0';
         memset(Name, 0, sizeof(Name));
     }
     else if (int(Name[index])==13){  //If Carriage return has been reached
         Serial.println(Name);   
         index = -1; 
         Name[9] = '\0';
         memset(Name, 0, sizeof(Name));         
     }
   index++; // Increment where to write next
  }
}

The inputs are introduced via Serial Monitor. The Outputs are printed lines in the Serial Monitor as well.
7  Using Arduino / Programming Questions / Re: String or Char Arrays Length Definition on: February 06, 2013, 12:58:50 pm
  • INPUT: "1" ; OUTPUT: "1"
  • INPUT: "12345" ; OUTPUT: "12345"
  • INPUT: "12345678" ; OUTPUT: "12345678"
  • INPUT: "123456789" ; OUTPUT: "Invalid Input, please enter 3 to 8 characters"
  • INPUT: "12345678901" ; OUTPUT: Blank line, "Invalid Input, please enter 3 to 8 characters" & line with "1"
  • INPUT: "123456789012" ; OUTPUT: Blank line, "Invalid Input, please enter 3 to 8 characters" & line with "12"
  • INPUT: "012345678901234567890123" ; OUTPUT: "Invalid Input, please enter 3 to 8 characters" twice& line with "0123"

I would love to have just the ERROR ONCE. Any ideas, please!!!!
8  Using Arduino / Programming Questions / Re: String or Char Arrays Length Definition on: February 06, 2013, 12:09:12 pm
array of 9 elements = 8 valid values. right?

No. The first element is array[0]. Count up to nine elements and see which index values you used.

According to your explanation, there would be 10. But according to http://arduino.cc/en/Reference/Array
Quote
int mySensVals[6] = {2, 4, -8, 3, 2};
char message[6] = "hello";

so there are 5 values in the first and 5 letters in the second. I still don't get your point?... with my code loaded... press a key and hold until 20 or more chars have appeared in the dialog and then press enter... the error message appears several times and sometimes other chars bellow...
9  Using Arduino / Programming Questions / Re: String or Char Arrays Length Definition on: February 06, 2013, 11:54:16 am
Code:
         Name[9] = '\0';
For an array of 9 elements, what are the valid index values? Hint: 9 is not one of them.

array of 9 elements = 8 valid values. right? I don't really get what you're suggesting?
10  Using Arduino / Programming Questions / Re: String or Char Arrays Length Definition on: February 06, 2013, 11:27:47 am
Back to the original problem... I almost got it. I still have a couple of questions (below!);

Here's the code:
Code:
char Name[9] = ""; // My Data array
char inChar; // Where to store the character read
byte index = 0; // Index into array; where to store the character


void setup(){

Serial.begin(9600);

}

void loop(){
  if (Serial.available()>0){
     inChar = Serial.read();
     Name[index] = inChar; // Store it
     if (index>8){
         Serial.println("Invalid Input, please enter 3 to 8 characters");
         index=-1;
         memset(Name, 0, sizeof(Name));
     }
   else if (int(Name[index])==13){  //If Carriage return has been reached
            Serial.println(Name);   
         index=-1;
         Name[9] = '\0';
         memset(Name, 0, sizeof(Name));         
   }
   index++; // Increment where to write next
  }
}

If I insert any string from 1 to 8 chars it works perfectly, else:
  • 9 chars - println the error message - GREAT!
  • >9 chars - sometimes prints error message twice (more than 20 chars) or error message + modulos 10 (that is the 11th, 12th, 13th... chars) - I don't get why? or how to avoid?

Thanks for your help so far!!
11  Using Arduino / Programming Questions / Re: String or Char Arrays Length Definition on: February 06, 2013, 09:31:11 am
Quote
EUREKA!!!
Keep in mind that you need to provide a large enough array to hold what the user typed, and that that may be more than 8 bytes.


jajaja I found out about this already  the hard way, with this code if I enter 123456789 I receive back two lines, 1st: 12345678 and 2nd: 92345678 so it overwrites the array.

Code:
char Name[9]; // My Data array

void setup() {
 Serial.begin(9600);
 while (!Serial) {
   ; // wait for serial port to connect. Needed for Leonardo only
 }
 Serial.println("Please Enter your Name: ");
}
 
void loop() {
 while (!Serial.available()); // Wait for characters
 Serial.readBytes(Name, 8);
 Serial.println(Name);
 }

Is there a way to avoid overwriting? ... not sure if I should go back to the other suggestions.
12  Using Arduino / Programming Questions / Re: String or Char Arrays Length Definition on: February 06, 2013, 08:57:02 am
The Stream class has a readBytesUntil( ... ) function; have a look at it.

EUREKA!!! jajaja thanks!
13  Using Arduino / Programming Questions / Re: String or Char Arrays Length Definition on: February 06, 2013, 08:02:32 am
You could read and count the characters until you reach the terminator, while you store the characters in a character array.
The terminator could be Carriage return, or other special you choose
If the count is >8, warn the user, ans start over.

This sounds great, though I'm not sure how to implement the If. I have this so far:

Code:
char Name[9]; // My Data array
char inChar; // Where to store the character read
byte index = 0; // Index into array; where to store the character


 if(index < 8){
           inChar = Serial.read();
           Name[index] = inChar; // Store it
           index++; // Increment where to write next
           Name[index] = '\r'; // Carriage to terminate the string
       }
else{
           Serial.println("Invalid Input, please enter 3 to 8 characters");
}

Will that work?
14  Using Arduino / Programming Questions / Re: String or Char Arrays Length Definition on: February 06, 2013, 07:30:54 am
OK, but how can I limit strcat() to 8 chars?
15  Using Arduino / Programming Questions / Re: String or Char Arrays Length Definition on: February 06, 2013, 07:09:21 am
OK, I get It... I was trying to do the 3rd.

I wanted to add a string or an array of characters after user inputs the text and hits "send"
Pages: [1] 2 3