invalid conversion from 'char' to 'const char*


i'm getting the error 'invalid conversion from 'char' to 'const char*' when trying to convert a char pulled off the serial port into an int. any ideas why? thanks in advance for any help! :-*

here's my code:

void getData()
memset(inString,'\0',msglength); // initialize that string to all NULL characters
byte inByte = '\0';

for(int i=0; i<msglength; i++) {
inString =;

  • }*

  • for(int i=0; i<msglength; i++) {*

  • if (inByte == 0x7E)*

  • {*

  • int lengthMSB = atoi(inString[1]); // high byte for length of packet*

  • int lengthLSB = atoi(inString[2]); // low byte for length of packet*

  • int API_ID = atoi(inString[3]); // API Identifier indicates what type of packet this is*

  • int addrMSB = atoi(inString[4]); // high byte of sender's 16-bit address*

  • int addrLSB = atoi(inString[5]); // low byte of sender's 16-bit address *

  • int RSSI = atoi(inString[6]); // Received Signal Strength Indicator shows how strong a signal we received*

  • int options = atoi(inString[7]); // some options, that usually they aren't important*

  • //Data Section*

  • int totalSamples = atoi(inString[8]); // this is the number of sample packages that we're receiving*

  • int channelIndicatorHigh = atoi(inString[9]); // this tells us which analog channels (pins) are in use (and one digital channel)*

  • int channelIndicatorLow = atoi(inString[10]); // this tells us which digital channels (pins) are in use.*

  • int dh = atoi(inString[11]); //digital high status (status of D8)*

  • int dl = atoi(inString[12]); //digital low status (status of D0-D7 bitwise)*

  • int a1 = atoi(inString[13]); //analog high bit*

  • int a2 = atoi(inString[14]); //analog low bit*
    _ //to get full 0-1020: a1*255+a2_

  • //END Data Section*

  • int checksum = atoi(inString[15]);*

  • }*

  • } *

the compiler is telling you that atoi expects a pointer to an array of characters (char *) but you are passing a single character ( inString[x] is the char at position x, it is not a pointer )

the message in your code does not contain strings so you don't need atoi, you can do this:
int API_ID = (int)inString[3]; // this will convert this char to an int
// the compiler will do the cast for you so you could also just write:
int RSSI = inString[6];

you can convert high and low byte values like this:
int length = ( ((int)inString[1]) <<8) + inString[2]); // must do the cast before shifting

if msglength is a variable, you can make your code more robust by checking that it will never be greater then the number of characters declared inString. If msglength is a constant, then it is conventionally written in upper case

yeah I just tried casting it into an int; I dunno why I didn't try that the first time 'round. but it's all good now, and thanks for your other tips :slight_smile:

how would you convert an 'char' to 'const char*'
or even better, how would you convert an 'int' to 'const char*'