I'm using the following code which basically echoes onto terminal whatever I send to the arduino. However, atoi only works to convert the ascii code to integer, so i guess I shouldn't have been surprised that the terminal echoed 0 for all non numeric characters. Is there someway to fix this?
#include <stdlib.h>
void setup(){
//Spi.mode((0<<CPOL) | (1 << CPHA)); // set SPI mode 1
Serial.begin(9600);
Serial.print(25, DEC);
delay(200);
Serial.print(17, DEC);
delay(5);
}
unsigned long time;
int command=0;
int array[20];
int num=0;
char* val="0";
void loop(){
while(Serial.available()>0){
val[0]=Serial.read();
array[num]=atoi(val);
if(array[num]!=int('
sorry about the terminology. Right now, serial.read gets the ascii chars and the arduino outputs it on the terminal as decimal values. I want it to output exactly the same chars that I inputed.
Here's what I have changed so far. Now I got it working that the terminal outputs exactly the same nonumeric chars I input. But now, any numbers i enter gets outputted as "."
#include <stdlib.h>
void setup(){
//Spi.mode((0<<CPOL) | (1 << CPHA)); // set SPI mode 1
Serial.begin(9600);
Serial.print(25, DEC);
delay(200);
Serial.print(17, DEC);
delay(5);
}
unsigned long time;
int command=0;
int array[20];
int num=0;
char* val="0";
void loop(){
while(Serial.available()>0){
val[0]=Serial.read();
if (val [0] >= '0' && val [0] <= '9'){
array[num]=atoi(val);
}else{
array[num]=val[0];
}
if(array[num]!=int('
nvm, i got it working, except that it take a considerable time for a response after i type something on the terminal for something to return. is there anything that I'm doing that's making it so slow?