trying to send data to my arduino without success (to rx input- 0 )

Hello every one,

i am sending data 8 bit to my arduino and i want my data to get into the rx ( by rf module 434A receiver).

So, i tried to send data but he always gets the data as "-1" .

i did a check by shorting the rx and the tx of the arduino to where is the problem but it works ( the data from the tx of the arduino gets into the rx of the arduino pretty good)',

i also checked my transmitter and my receiver they works good too ,

anybody thinks he knows where the problem can come from?

here is my simple code:

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

}

void loop() {
Serial.write(255);
delay(100);
int x=Serial.read();
Serial.print(x);
delay(100);

}

thanks alot,

gidi

We need the exact ref of your rf module, the datasheet of it would help.

May the rf module works à 4800 bauds and not 9600.

So from there is mistake in your code.

If you get -1 it's NORMAL because :

Serial.read() will return a byte. or you are using an int. So from 255 is 0xFF that can be interpeted à -1 !

So from use a byte or char insteed of an int

You don't also check if serial datas are available, you could do a program like :

char x;

void loop()
{

Serial.write(65, BYTE);
delay(100);

if (Serial.available()
{
x =Serial.read();
Serial.print(x);
delay(100);
}
}

You must get more results

hi greg,

thanks for the answer i did what you wrote but its cannot comiled

it write me an eror : "cannot convrert from int to cont_units"

and i tried to write the program with byte and with char and now it givs me someting like y in Gibrish so i rhort with wireseally dont know what to do ' i tried to connect other microconroller in serial( srhort with wires the tx of the microcontroller -pic18f8520 to the rx of the arduinothwy both works at ttl level 0-5 volt) and desame ;

when i am writeing :
if( serial.available())
{
}
nothings happenes, the program seems to be stucked in a loop ....

so i really dont know what to do,

thanks alot,

gidi

Gibberish, ah yes.

Can you copy and paste the whole sketch please? And put "code" tags around it by selecting it and hitting the "#" button?

try with :

if (Serial.available()
{
x =Serial.read();
Serial.print(x, DEC);
Serial.proint(' ');
delay(100);
}
else
print('.');

if you see continuous dot ............ it's because no serial datas are coming to your arduino !

@grag38:
You're pushing towards 100 posts.
Don't you think it is about time you started posting code properly?

if (Serial.available()) {
   int x =Serial.read();
   Serial.print(x, HEX);  // Does anyone remember ASCII codes in decimal?
   Serial.print(' ');
   delay(10);
 } else Serial.print('.');