Show Posts
Pages: [1]
1  Using Arduino / Programming Questions / Re: char to byte conversion on: November 27, 2011, 03:41:51 am
Quote
Psst, Mike, what about 0x4f? (for example)
Yes but he didn't ask about that did he.  smiley-grin

That's just mean! How about using sscanf() instead? Or something like this:

Code:
char hexdig(char ch) {
  if (ch >= '0' && ch <= '9') return ch - '0';
  if (ch >= 'A' && ch <= 'F') return ch - 'A' + 10;
  if (ch >= 'a' && ch <= 'f') return ch - 'a' + 10;
  return -1;
}

int string_to_byte(char *data) {
  if (data[0] != '0' || data[1] != 'x') return -1;
  int a = hexdig(data[2]);
  if (a < 0) return -1;
  int b = hexdig(data[3]);
  if (b < 0) return -1;
  return (a << 4) + b;
}

Usage:

Code:
char *str = "0xfe";
int val = string_to_byte(str);

There are also functions in the standard library to do this, if you can afford to link that in. Look at strtol() and sscanf().


Thanks a lot! That worked pretty well! It also worked with:

Code:
str = "0x1d";
int n;
sscanf (str,"%x",&n);
Serial.prinln(n, BYTE);
2  Using Arduino / Programming Questions / Re: char to byte conversion on: November 26, 2011, 04:47:14 pm
Quote

No that statement is meaningless. The single quote defines a single ASCII character, I have no idea what that statement returns but it is not what you are expecting.
You need to find out what form the Ethernet library read() function returns.


Thanks! You are so right about the single quotes, really missed it! The read() returns int values, so reads it single character from the page and returns it into an int.
So now the question is how to convert '0', 'x', '6', '1' to 0x61 byte value!
3  Using Arduino / Programming Questions / Re: char to byte conversion on: November 26, 2011, 04:28:22 pm
Quote
Does not work,
Yes it does.

Code:
char a = '0x61';
Is a rubbish statement, you should use
Code:
char a = 0x61;
no single quotes

I know
Code:
char a = 0x61;
works fine, but maybe I was not very clear: the sketch reads the byte values from a web page using the Ethernet library using the read() function like:

Code:
char c = client.read();
which I think will return something like
Code:
char a = '0x61';
and not
Code:
char a = 0x61;
4  Using Arduino / Programming Questions / Re: char to byte conversion on: November 26, 2011, 04:18:55 pm
Use:-
Serial.write(a);

Does not work, when I try the following I get in Serial monitor two different things: 1a

Code:
char a = '0x61';
Serial.write(a);
Serial.write(0x61);
5  Using Arduino / Programming Questions / char to byte conversion on: November 26, 2011, 04:00:31 pm
Hello,

I am trying to send some binary data to my Arduino remotely, but I need the data to be retrieved from a web page. So the web page contains values like 0x61,0x00,0x0c,0x94,0x7e,...
I can receive the data from the page as a sequence of char variables or String objects but I am not sure how to convert them back to bytes.

It is like having the following:

Code:
char a = '0x61';
int bytevalue = ... //missing this step
Serial.print(bytevalue, BYTE);


I have tried casting but does not give the right output:
Code:
Serial.print((int)a, BYTE);
//I need Serial.print(0x61, BYTE);

Any help would be much appreciated,

Thanks!
6  Using Arduino / Sensors / Bio Sensors Board on: July 28, 2011, 07:57:01 am
Does anyone know or have some more information about the Arduino Bio Sensors boards found here?:
http://www.arduino.cc/en/Main/BioSensorsBoard
7  Topics / Science and Measurement / Re: Collection of medical and health projects with Arduino on: June 25, 2011, 06:05:44 am
Thanks for the link! I will check it and probably present it in the blog. Hopefully people will start suggesting more projects and ideas! In the meantime, the search continues!
8  Topics / Science and Measurement / Re: Collection of medical and health projects with Arduino on: June 25, 2011, 03:13:10 am
Hi mowcius,

you are right, but we are not expecting medical products and devices to be based on arduino, we are focusing only on projects, parts of research work, prototypes or self work that address issues like monitoring status, context, helping people with impairments, etc. I am sure there are quite some projects out there (apart from temp and ecg monitoring) and also plenty of ideas that people will come up with and implement them with Arduino  smiley

9  Topics / Science and Measurement / Collection of medical and health projects with Arduino on: June 24, 2011, 03:12:12 pm
Hi,

I would like to invite people with health and medical related projects (ECGs, EEG, EMGs, general monitoring of human, medical related actuators, etc.) to post their project in the medicarduino.wordpress.com
It is an effort to collect projects and resources on the interent about medical and health projects based on Arduino smiley

Thanks
Pages: [1]