RFID reader
The Lab has a number of readers from Sparkfun which can be easily hooked up to a computer via mini-USB.
In the HTML-page in the P5 project we need to add a line at the top to include the library for serial communication:
<script src="https://unpkg.com/@gohai/p5.webserial@^1/libraries/p5.webserial.js"></script>
P5 code to receive:
let port; let connectBtn; function setup() { createCanvas(400, 400); port = createSerial(); // in setup, we can open ports we have used // previously without user interaction let usedPorts = usedSerialPorts(); if (usedPorts.length > 0) { port.open(usedPorts[0], 9600); } // if this is first use, you connect via // user interaction (see connectBtnClick below) connectBtn = createButton('Connect to Arduino'); connectBtn.position(0, 0); connectBtn.mousePressed(connectBtnClick); } function connectBtnClick() { if (!port.opened()) { port.open('MicroPython', 9600); //Note: "MicroPython" instead of "Arduino" } else { port.close(); } } function draw() { // reads in complete lines let str = port.readUntil("\n"); if (str.length > 0) { print(str); //printing the tag id //Check for any RFID id's you have //Make as many if-statements as you want if(reading.match("01023C13AA86")){ //do something here } } // hides button if connected if (!port.opened()) { connectBtn.html('Connect to Arduino'); } else { connectBtn.html('Disconnect'); connectBtn.remove(); } }
;