incompatible types in assignment of 'char' to 'char [10]

hey,
i am working on a project in wich i need to interface a 4x3 keypad to gsm 900a using arduino mega
for sending a txt msg form gsm module on the user specified number enter form the keypad by the user.
and when i am executing my program
i am geting an ERROR

incompatible types in assignment of ‘char’ to 'char [10]

and my program file is attached below plzz help me out if any one can
thankyou… :slight_smile:

nw_exp.ino (2.18 KB)

The compiler probably didn't like the italics in the lower part of your sketch.

Remember to always post code inside code tags.

AND DO NOT CROSS-POST.
Duplicates deleted/merged.

now whats the problem
:confused:

#include <GSM.h>

#define PINNUMBER ""

// initialize the library instance
GSM gsmAccess;
GSM_SMS sms;
#include <Keypad.h>

const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0','#'}
};
byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {8, 7, 6}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );


void setup()
{
  // initialize serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }
  Serial.println("SMS Messages Sender");

  // connection state
  boolean notConnected = true;

  // Start GSM shield
  // If your SIM has PIN, pass it as a parameter of begin() in quotes
  while (notConnected)
  {
    if (gsmAccess.begin(PINNUMBER) == GSM_READY)
      notConnected = false;
    else
    {
      Serial.println("Not connected");
      delay(1000);
    }
  }

  Serial.println("GSM initialized");
}

void loop()
{

  Serial.print("Enter a mobile number: ");
  char remoteNum[10];// telephone number to send sms
  
  // char* bar = remoteNum;
  readSerial(remoteNum);
  Serial.println(remoteNum);

  //char foo[2];
//char* bar = foo;

  // sms text
  Serial.print("Now, enter SMS content: ");
  char txtMsg[200];
 // readSerial(txtMsg);
  Serial.println("SENDING");
  Serial.println();
  Serial.println("Message:");
  Serial.println(txtMsg);

  // send the message
  sms.beginSMS(remoteNum);
  sms.print(txtMsg);
  sms.endSMS();
  Serial.println("\nCOMPLETE!\n");


  remoteNum = keypad.getKey();
  
  if (remoteNum){
    Serial.println(remoteNum);
  }
}


int readSerial(char result[])
{
  int i = 0;
  while (1)
  {
    while (Serial.available() > 0)
    {
      char inChar = Serial.read();
      if (inChar == '\n')
      {
        result[i] = '\0';
        Serial.flush();
        return 0;
      }
      if (inChar != '\r')
      {
        result[i] = inChar;
        i++;
      }
    }
  }
}

Let's approach this problem like detectives.
The compiler is telling you that it doesn't like an assignment involving a "char" and a ten element array of "char"s.

char remoteNum[10];// telephone number to send sms

There's the array.

remoteNum = keypad.getKey();

And there's the assignment.

That wasn't so hard, was it?

and when i am executing my program
i am geting an ERROR

No, you are not executing your program, because your program cannot compile.

no it was not so hard but finding the error is very difficul i am struggling this error from
last 2 days.
so what change i should do
to run the program perfectly..??

Well, first, you have to define "perfectly".
Start by deciding what constitutes a phone number, and how you indicate to the Arduino when it is complete.

Here i am declaring the phone number and even its limit to 10 digits

 char remoteNum[10];// telephone number to send sms

and here i am geting the number as input from keypad

remoteNum = keypad.getKey()

Here i am declaring the phone number and even its limit to 10 digits

Correct.

and here i am geting the number as input from keypad

That's what the compiler was complaining about.

"getKey" returns a single "char", and you need ten of them.
So, you need to call "getKey" ten times, and you need to assign each "char" returned to a different element of the array.

i can use for loop

for(i=10,i<10,++i)
             remoteNum;

:frowning:

or is there any other logig to solve this problem…?

i can use for loop

Your for loop and C syntax need some work doing on them.

Excuse me please, breakfast time.

ok waiting for u to finish your breakfast.
and by that time i"ll try to declare keypad.getkey 10 times.

You can use a for loop if you get the syntax right, but you will also need to make the target array larger in order to incorporate a training zero if you need it to be used as a C style string later in the code, which I expect you do.

ok but now i tried this

  remoteNum = keypad.getKey();
  for(keypad.getKey=0;keypad.getKey<10;keypad.getKey++)
  {
    if (remoteNum){
    Serial.println(remoteNum);
   
 }

but still its show same ERROR

incompatible types in assignment of 'char' to 'char [10]'

and sorry i am a learner so i may take little time to understand and even i may ask simple question so sorry for that :frowning:

but still its show same ERROR

Because it's the same code.

Then what change i should make ....?? :confused:

sorry for asking these stupid question becoz i realy don't know what else should be implemented

If you look in the IDE examples, I'm pretty sure there are some that cover for loops and arrays.

i checked its not there the you can get me the example code then i can implement it here and find or else you sugges in which example i should check

File/Examples/05.Control/Arrays
File/Examples/05.Control/ForLoopIteration

Hello and welcome,

You cannot just read 10 keys at once and store them in the char arrays, because your code doesn’t know if you pressed the keys or not… If you call getKey 10 times, it will read 10 times the same key in less than one millisecond… You want your code to check for a new key press and do appropriate actions depending which kkey was pressed ( if key is 0 to 9 store in array, else if key is Validate do something, else if key is Cancel do something else, etc… )

I suggest you read some beginner’s tutorial about C/C++ programming. Then look at the examples of the keypad library that you are using. If that is not sufficient, search on google something like “arduino keypad password” and adapt to your code… If you are lucky you may find an example that does exactly what you want :wink:

are you talking about some program like this

#include <LiquidCrystal.h>
#include <Keypad.h>
#include <Wire.h> 

#define Password_Lenght 10 // Give enough room for six chars + NULL char

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
char Data[Password_Lenght]; // 6 is the number of chars it can hold + the null char = 7
char remoteNumber = 0;
char customKey;

const byte ROWS = 4;
const byte COLS = 3;
char keys[ROWS][COLS] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0','#'}
};

byte rowPins[ROWS] = {
  22,24,26,28}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {
  30,32,34}; //connect to the column pinouts of the keypad

Keypad customKeypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS); //initialize an instance of class NewKeypad 

void setup()
{
  
  lcd.begin(16,2);// initialize the lcd 
 
}

void loop()
{
  lcd.setCursor(0,0);
  lcd.print("Enter number");

  customKey = customKeypad.getKey();
  if (customKey) // makes sure a key is actually pressed, equal to (customKey != NO_KEY)
  {
    Data[remoteNumber] = customKey; // store char into data array
    lcd.setCursor(remoteNumber,1); // move cursor to show each new char
    lcd.print(Data[remoteNumber]); // print char at said cursor
    remoteNumber++; // increment data array by 1 to store new char, also keep track of the number of chars entered
  }
}