Loading...
Logo
Processing Forum
danielSpecht's Profile
2 Posts
5 Responses
0 Followers

Activity Trend

Last 30 days
Show:
Private Message
    Hi all,

    I have the Mifare 130 RFID Module with the sparkfun shield and I found some infos and sketch by Tom Igoe.
    It works to read my tags but now I would like to (e.g) display an image if the reader reads a defined ID.
    I tried to make a function (at the end of the code) who would show the image as soon as the reader reads the tag but it gives me a "unexpected token" error.

    I think i closed all the brackets and i registered the function in the draw method but i honestly don't know if the code would work like this. Any idea?
    Thank you!

    1. /*
       SonMicro RFID Reader simple example
       Language: Processing
       
       This sketch uses the SonMicroReader library to demonstrate how to read from
       Mifare RFID tags using the SonMicro reader.
       
       created 6 March 2009
       by Tom Igoe
       */

      // import libraries:
      import processing.serial.*;
      import sonMicroReader.*;
      Serial myPort;                // serial port instance
      SonMicroReader myReader;      // sonMicroReader instance

      int fontHeight = 24;         // font height for the text onscreen
      String lastTag;              // last tag read
      String tagID = "E2AB9C87";   // ADDED TAG ID
      PImage user;                 // USER IMAGE

      /* ------------------------------------------------- */

      void setup() {
        // set window size:
        size(400, 300);
        img = loadImage("m-icon.png");
        // list all the serial ports:
        println(Serial.list());

        // based on the list of serial ports printed from the
        // previous command, change the 0 to your port's number:
        String portnum = Serial.list()[0];
        // initialize the serial port. default data rate for
        // the SM130 reader is 19200:
        // myPort = new Serial(this, portnum, 19200);
        myPort = new Serial (this, "/dev/tty.usbserial-A6008smX", 19200);
        // initialize the reader instance:
        myReader = new SonMicroReader(this, myPort);
        myReader.start();
        myReader.reset();
        // create a font with the second font available to the system:
        PFont myFont = createFont(PFont.list()[2], fontHeight);
        textFont(myFont);
      }

      void draw() {

        // draw to the screen:
        background(255);
        fill(0);
        textAlign(CENTER);
        readTagOne();

        if (lastTag != null) {
          text(lastTag, width/2, height/2);
        }
        else {
          text("Hit any key to begin reading", width/2, height/2);
        }
      }

      void keyReleased() {
        // for manually starting a seek:
        myReader.seekTag();
      }

      /*
       This function is called automatically whenever there's
       a valid packet of data from the reader
       */
      void sonMicroEvent(SonMicroReader myReader) {
        // get all the relevant data from the last data packet:
        if (myReader.getTagString() != null) {
          lastTag = myReader.getTagString();
        }
        // get the error code and last command:
        int errorCode = myReader.getErrorCode();
        int lastCommand = myReader.getCommand();


        // a little debugging info:
        println("error code: " + hex(errorCode, 2));
        println("last command: " +  hex(lastCommand, 2));
        println("last tag type: " + myReader.getTagType());
        println("last tag: " + lastTag);
        println("-----");

        // if the last command was seekTag, then you're either waiting,
        // or ready to seek again:
        if (lastCommand == 0x82) {
          if (errorCode == 0x4C) {
            // you're waiting for a tag to appear
          }
          if (errorCode == 0) {
            // you got a successful read;
            // wat, then read again
            delay(300);
            myReader.seekTag();
          }
        }

        void readTagOne() {
          if (myReader.getTagString() == tagID) {
            user = loadImage("p-image.png");
          }
        }
      }

    There are already some questions arround cp5 and Lists but i was not able to solve "my" problem so far. Maybe someone out there knows a solution - would be great.

    In my Program there are some images and lines plus some cp5 elements which woorks fine so far. But if i want to ad a cp5 ListItem, it won't work properly until i set the background to some int value in the draw function. e.g -> background(128); As soon as i set the background to some value, the List works fine but all the other elements disapear.

    I have Processing 2.0b8 installed but i'm using the Sublime Text 2 IDE.

    Here is the Code. I'ts more or less taken from the cp5 example. I deleted most of the comments in order to limit the list.
    Thank you for the help and sorry for my english.

    1. import controlP5.*;
    2. ControlP5 cp5;
    3. DropdownList d1;
    4. int cnt = 0;
    5. PImage appHeader;
    6. PImage device;
    7. void setup() {
    8.   size(1000, 830, P3D);
    9.   cp5 = new ControlP5(this);
    10.   // create a DropdownList
    11.   d1 = cp5.addDropdownList("myList-d1")
    12.     .setPosition(100, 100)
    13.       ;
    14.   customize(d1); // customize the first list
    15.   // --------------- GUI OBEN ------------------
    16.   appHeader = loadImage("header.png");
    17.   image(appHeader, 0, 0); // position des headers
    18.   // --------------- DEVICE ------------------
    19.   device = loadImage("device.png");
    20.   image(device, 70, 140); // position of device
    21. }
    22. void customize(DropdownList ddl) {
    23.   // a convenience function to customize a DropdownList
    24.   ddl.setBackgroundColor(color(190));
    25.   ddl.setItemHeight(20);
    26.   ddl.setBarHeight(15);
    27.   ddl.captionLabel().set("HTC One X");
    28.   ddl.captionLabel().style().marginTop = 3;
    29.   ddl.captionLabel().style().marginLeft = 3;
    30.   ddl.valueLabel().style().marginTop = 3;
    31.   ddl.addItem("Samsung Galaxy S4", 0);
    32.   ddl.addItem("Google Nexus 4 ", 1);
    33.   //ddl.scroll(0);
    34.   ddl.setColorBackground(color(60));
    35.   ddl.setColorActive(color(255, 128));
    36. }
    37. void controlEvent(ControlEvent theEvent) {
    38.   if (theEvent.isGroup()) {
    39.     // check if the Event was triggered from a ControlGroup
    40.     println("event from group : "+theEvent.getGroup().getValue()+" from "+theEvent.getGroup());
    41.   }
    42.   else if (theEvent.isController()) {
    43.     println("event from controller : "+theEvent.getController().getValue()+" from "+theEvent.getController());
    44.   }
    45. }
    46. void draw() {
    47. }