Tool Accountability Box

Posted on
  • Working on integrating a tool box for the work place that will provide some accountability to the user of the tool. The idea is to use the PICO, a MS146-2G Slot Reader (ID cards), a few magnetic holds and slew of TI CD4021BE. The drawers or cabinets will be locked by the magnetic holds, a user will use his ID card to gain access and remove tools from the drawer. Once closed the PICO will scan through and note what tools were removed. I plan to upload the information to a google spreadsheet with the ESP8266 of which I will build some code to send a text reminder to the users to return the tools at the end of the day. Here is the test code for the CD4021 so far.

    
    SPI1.setup({sck:A5,miso:A6,baud:9500});/­/pins 10, 3 respectively
    function loop(){
      digitalWrite(B1,1); // to pin 9 on chip, this allows the chip to collect its data for 20 milliseconds
      setTimeout(function(){
        digitalWrite(B1,0); // turn pin 9 off then........
        console.log("register 1 is "+(SPI1.send([0x00])>>>0).toString(2)); //collect data from first chip //I am not 100% on the 0x00 because I've tried other values and it still returns the same.
        console.log("register 2 is "+(SPI1.send([0x00])>>>0).toString(2)); //collect data from second chip
      },20);
    }
    setInterval(loop,1000);
    
    

    if CD4021 gpio 1 is on return 1, if gpio 2 is on returns 10, 3-->100, all three on returns 111, etc.

    Here is a diagram of how the chips are put together. Thanks to the work of the people at arduino.cc was I able to get this part together as some of this would be way over my head. Ill try to get some pictures on here as the project progresses. Thanks

  • That's great - thanks for posting up! It'll be really good to see how this turns out.

    Where you're sending data, I don't think it matters what bytes you send at all (there's no mosi (output) pin specified so nothing will get sent anyway). Also you've set baud as 9500 - it's fine, but the chip itself seems to go up to 3000000, so you've got some headroom if you want to go a bit faster ;)

    Also, in Espruino you can just call send once to get an array of all your data, like:

    var d = SPI1.send(new Uint8Array(4 /* maybe you have 4 CD4014s */));
    console.log(d[0].toString());
     // etc etc
    

    Might be a bit tidier.

  • It doesn't matter what you send - the data you send is sent out over the MOSI pin - you have only defined a miso pin, so that 0x00 or 0xwhatever that you send out isn't going anywhere. It doesn't have to, though. You're only "sending" something in order to cause it to run the sck pin to clock out the data.

    Ugh, typed this hours ago, but by the time I saw I hadn't submitted it, Gordon had beaten me.

  • Ill do a little studying up on that Uint8Array. Thanks for the info!

  • Yeah, I think 9500 baud is excessively conservative. That's 1.1k bytes per second, or just under 1ms per byte....

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Tool Accountability Box

Posted by Avatar for Cale @Cale

Actions