RFID and Servo Help Needed
![NWCCTV](https://forums.parallax.com/uploads/userpics/406/nWOV2NX1YHRZF.jpg)
I am using the below code to turn a servo when a card ID matches and to stop when it does not. It is a While loop but only works the first time. When the correct card is scanned the Servo will turn, but I have tried pretty much every command in the header file and none of them will let the loop continue after the first time it starts and then stops.
/* RFID Read.c Reads and displays RFID tag numbers. Connect: Vcc to 5V, /ENABLE to P2, SOUT to (R = 2.2 k) to P1, GND to GND http://www.parallax.com/product/28140 */ #include "simpletools.h" // Include simpletools #include "rfidser.h" // Include rfidser #include "servo.h" // Include servo header int rfidEn = 2; // Reader /ENABLE pin to P2 int rfidSout = 1; // Reader SOUT pin to P1 rfidser *rfid; // Set up device ID int main() // Main function { rfid = rfid_open(rfidSout, rfidEn); // Open reader, start reading while(1) // Main loop { char *str = rfid_get(rfid, 1000); // Wait up to 1 s for card print("id = %s.\n", str); // Print ID. if(!strcmp(str, "05000038D4")) //Check for Card match servo_speed (9,200); // If card matches, start servo on pin 9 else servo_stop(); // If no match, do nothing }}
Comments
} }
http://learn.parallax.com/propeller-c-functions
Usually when something doesn't work I put a bunch of debug lines to see where it is held up or looping. Then adjust the code before the debug code that isn't executed.
For more info, click SimpleIDE's Help -> Simple Library Reference -> servo.h.
Andy
Did you use the servo pin number as the argument to the servo_disable function? It is needed according to the documentation.
I'm not sure what will happen if the incorrect tag is read on the first try. If the servo hasn't been used, can it be disabled?
Have you just tried using servo_speed(9, 0) when incorrect?
Tom