What am I making?
The project goals here are to use a current sensor to monitor the electrical current going to the hot end and heat bed on a 3D printer. If overcurrent (wires get shorted); we open a relay and make alerts. If undercurrent, the wires could be fatigued and breaking. Open a relay and set an alert.
What am I up to in this blog?
Today's blog is the startup and getting things running.
I've already taken the kit components out of the box and gotten them stacked together as shown in the image below.
I've got my RaspberryPi imaged with the default Raspbian and am planning to use Python. There doesn't appear to be a ready-to-go library that is supported on the Pi so I plan to just hand-code the few lines I need to get the measurement values.
The Pi3 Click Shield from the kit has been nice so far in making it simple to connect the boards. I had forgotten that others had issues with finding the Current6Click board on the I2C bus and I too ran into that issue. I grabbed my scope and could see activity on the I2C bus so knew that it was alive (after enabling in the Pi settings). The Click Shield has a very convenient ground connection point sticking out of the board which made it much easier to probe.
Running I2CDetect shows nothing because the chip requires a GPIO pin (#8) to be set HIGH as an enable. Once this was done with the raspi-gpio command, we can see the device at address 0x21.
Pseudo-code
This is a rough outline of what my Python code will do. This code seems that it will be mostly written from scratch and its nice to do a simple outline to get all my thoughts down. I'm planning to use PyCharm for a code-editor and run it on the Pi.
Power on
Connect to MQTT
Read in current threshold from MQTT
Write Enable pin HIGH for Current6 Click
Check for module
Close relay to allow current to flow
Routine
Check for 12V
If 12v
read current AFAFP
Periodic voltage and current post to MQTT
MQTT callback for subscribed topic for current threshold.
If under-current:
re-check voltage; ensure still active.
re-read current and ensure still under-current
set alarm
Post to MQTT
Set output pin to close relay
break;
If no 12V; take tiny break and try again
Always:
Interrupt pin set for overcurrent
If over-current:
set alarm
Post to MQTT
Set output pin to open relay
Provide mechanism to re-set from MQTT; otherwise restart.
That's all for today!
This is just a quick update post. I'm starting on the Python but that will take a little more time and I wanted to post some progress as I go.