Hi Everyone, It's been a little while since I've had an update, but I ended up tearing a meniscus, and that's making me pretty slow to move. Along with that, I have just a few days left to move everything out of my old shop into storage containers. Which, itself is difficult to do as I pack all my tools for long-term storage.
But, I can work on the electronics side of the Gate System, and that is what I have been doing in the mornings before I head down to hobble around slowly packing during the day. Currently, I can't do the heavy lifting part of this project, but after the new year, I may have some help to get that stuff done. That includes digging all of the ditches for wire runs, pouring concrete for the solar mast, keypad stanchions, and a small pad for the control box.
I have quite a bit done so far on the electronics side. Almost all of the major components are connected and lots of code. Here is a pic of the current prototype:
For the microcontroller I went with the ESP-DevKit-32UE since it has an external antenna connector, the motor controller is a Cytron MD13S which is pretty basic, but it fit the needs for this project. Just PWM and direction. I have added an MCP23017 for more IO to handle the keypads, which are Multicomp 12 key pads that are a matrix, and also have blue LED illumination. An ACS712 30A current Sensor for squish detection, and an SD card for storing data from the server.
The Microcontroller was difficult to find, there aren't that many ESP's that have external antenna connectors. I picked up a 15dbi directional antenna that will point back to the house, where I will have a small mast outside (eventually) with a high gain Omni wifi antenna, and a loRa antenna as a central data collector/access point.
I had one of those "how hard could it be?" moments connecting the keypad to the MCP where it just wouldn't work with the standard Keypad.h library. The MCP would initialize just fine, but I could not get anything out of the keypad. I thought maybe the MCP was not actually working and tried several different libraries for that, several keypad libraries, and still nothing. I finally found a post on Adafruit forum that said it handles registers differently and was pointed to a specific version of Keypad.h that was modified around the MCP23017. That bypassed all of the MCP libraries and just communicated directly with it. It worked!
The SD card reader was added in case the gate controller cannot communicate with the server, it would still be able to function and run off the last set of credentials it received. In a pinch, I could always pull the SD card, bring it back to the house, write it, and then put it back in. I don't anticipate a *lot* of changes, but it's nice to have. I first decided what data I needed to store on the SD card, then manually built a JSON file with all of the values. The data structure looks like this:
[{ "name": "Kaleb", "code": 1234, "time_start": "8:00", "time_end": "15:00" }, { "name": "other person", ... }]
I have the actual name of the person or entity accessing the gate instead of an ID, because the ID could change over time. The 4 digit code, and start/end times that the entity is allowed access. That way I can say deliveries can access the gate during business hours, but if someone wants to come back in the middle of the night and do something they should not be doing.... they can't. At my previous shop, there was one gate code that was given to ALL delivery drivers. There were probably 15 different people with the code, and any of them could come back whenever they wanted.
Once I had the format set, I popped the card into the reader and wrote the code to parse that out, then went to the front end and created a web portal to add/modify/delete users and generate the JSON file for download or push to the gate controller. I have not finished the receiving end of that on the ESP yet, but it's coming soon.
The motor controller was pretty straightforward. I have written a library to handle the actuator as an object, with the limit switches built-in to the library so it's pretty clean in the main body of the code. Once triggered, it will open the gate, wait for a configurable amount of time, and then close it.
I am currently working on the keypads, reading each digit into an array and comparing that with the code from the JSON file. I have a long history with interpreted programming languages that are very loose with variables (Perl, Python, PHP, etc) so C++ still throws a wrench in my brain trying to deal with strings as arrays and such. I did battle with trying to compare integers on the gate code for a while before I realized I should just do it as a char array since that's how I would end up with "1234" from entering 1, 2, 3, and 4 sequentially into the keypad. My brain didn't go there at first, it saw two integers that needed to be compared, and so I tried converting to ints and doing it that way. Easier to just compare strings.
The squish detection is connected, but I have not written much code for it yet. I just put the example code in there, ran the motor walked over to it, and tried to stop it to increase the current, but I could not see the output on the serial monitor since the font was so small, so I moved on to something more interesting. Ill deal with this later.
I have all of the solar equipment for the project now, it's just not hooked up. That will be pretty straightforward forward I hope. I have a 100w panel that I dumpster-dived, a 12v 10Ah Lifepo4 battery from Newark, and a small PWM charge controller.
I am going to install everything in the control box on DIN rails, so I picked up a PCB holder for that, some DIN rail power distribution modules, and a DIN rail 12-5v converter, as well as DIN rail breakers for the system and solar.
So, what is left to do?
- Reading sequential numbers from the keypad, and comparing them to data stored in the SD card.
- The logic around access granted vs access denied
- Sending granted/denied log entry back to the server (Maybe I should write that to a file on the SD card as well...)
- Squish Detection code and method to reverse gate.
- Multiple keypad button hold down to enable features (Hold gate open etc)
- Wire up the second keypad and test.
- Write code on server & ESP to handle pushing new credentials file.
- Remote keyfob gate entry (I have not located a good wireless relay yet that I like, but this should be simple as there is a pin on the ESP that is a "trigger" to activate the gate.
- Solder everything onto perf board.
- Assemble in the weather-resistant box.
- Dig the trenches from the solar location to the gate, the outside stanchion to the inside stanchion to the gate controller.
- Run conduit and wire in the above trenches.
- Pour concrete for stanchions and solar mast.
- Assemble the solar components
- Weld the actuator brackets to the gate post, and gate.
- Install the actuator
- Install the control box
- Install keypads in the stanchions
- Wire it all up
- Test and hope!
I think that's everything... There are a few small administrative tasks I need to complete before I can do some of it, such as setting up my camera ceiling mount, lights, etc so I can film the build for you. I will do time-lapses of the trenching, conduit, and welding. That should be fun.
I think that is it on this project for now. Keep an eye out on the main blog for other posts, I have updates on other things going on here.
Thanks all!
-Kaleb Clark