Go Down

Topic: Problem with two Serial communication (Read 1 time) previous topic - next topic


i have these two sketches in my arduino. one is sketch is for reading serial numbers sent by an rfid reader and the other is turning an LED on by sending a letter in my serial monitor/PC application.
The RFID code came from Seedstudio
Code: [Select]
#include <SoftwareSerial.h>

String msg;
char inChar;
int x;
SoftwareSerial Rfid(2, 3);    // RX as pin 2

void setup()

void loop()

while (inChar = Rfid.read() != 2)    // Wait for start byte from Rfid reader when tag is swiped

msg = "";
for (x = 0; x < 12; x++)
    inChar = Rfid.read();
    msg += inChar;

Serial.print(msg);    // Sends the ID plus the checksum byte (12 bytes)

2nd sketch LED on:
Code: [Select]
int ledpin = 9;
byte byteread
void setup()
pinMode (9,OUTPUT);


void loop() {

  if (Serial.available()) {
    byteread = Serial.read();
   if (byteRead == '1'){

Problem: when i combine the two codes together, i only get the reading from the rfid reader, and when I send the number 1, it doesnt turn on the led,, Can anyone help me with these serial events?


That's a pretty lousy way to read serial data. You know what the start of the packet marker is. There is an end of packet marker, too, You can't just cross your fingers and hope all the data arrives while you are diddling around.

I can't see your attempt to combine the two sketches. I'd guess that you left something important out.
The art of getting good answers lies in asking good questions.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131