Shop OBEX P1 Docs P2 Docs Learn Events
RFID and Servo Help Needed — Parallax Forums

RFID and Servo Help Needed

NWCCTVNWCCTV Posts: 3,629
edited 2015-06-06 20:47 in Learn with BlocklyProp
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

  • xanaduxanadu Posts: 3,347
    edited 2015-05-31 18:44
    Are you running SimpleIDE? It should throw some errors because you're missing two closing brackets.

    } }

    http://learn.parallax.com/propeller-c-functions
  • NWCCTVNWCCTV Posts: 3,629
    edited 2015-05-31 19:35
    Yes, The closing brackets are there. Just missed them in the Copy/Paste.
  • xanaduxanadu Posts: 3,347
    edited 2015-06-01 20:48
    Make sense. Did you get it working?

    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.
  • edited 2015-06-02 11:17
    I'd recommend using servo_disable (temporarily disable one servo) instead of servo_stop (stops the cog controlling all servos). Another thing you could do is pick one position for no card, and a different position for card detected.

    For more info, click SimpleIDE's Help -> Simple Library Reference -> servo.h.

    Andy
  • NWCCTVNWCCTV Posts: 3,629
    edited 2015-06-04 18:23
    Thanks Andy, I will give that a try when I get back to this project again.
  • NWCCTVNWCCTV Posts: 3,629
    edited 2015-06-04 18:45
    I tried that and I get a "undefined reference to servo_disable" error.
  • NWCCTVNWCCTV Posts: 3,629
    edited 2015-06-04 19:12
    I updated my SimpleIDE to the latest version and now I get the following error when trying to run the code from Post #1. And yes, I started with a new project.Error: RFID Read.c:35:5: error: too few arguments to function 'servo_disable'
  • NWCCTVNWCCTV Posts: 3,629
    edited 2015-06-06 18:15
    Any ideas why servo_disable does not work?
  • twm47099twm47099 Posts: 867
    edited 2015-06-06 20:47
    NWCCTV wrote: »
    Any ideas why servo_disable does not work?

    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
Sign In or Register to comment.