#read the registers from logical address 0 to 30. Log = logging.getLogger('./modbus.error')Ĭlient = ModbusClient(method='rtu', port='/dev/ttyAMA0', baudrate=9600, timeout=1) Piface for controlling wirelessly controlled 230v sockets by using relays with the original remote controllerįrom import ModbusSerialClient as ModbusClient Other related Rpi-stuff that I have but are not yet at the cabin and I just got them yesterday: 1142316463) <- does not have any interface for computer, but maybe could be tinkered?Īnyway, I am really interested on this project. One combo meter measuring battery voltage and wind mill amps (. One 600W Inverter for Rpi, cameras and such One 2KW Inverter for house electricity (lights, coffeemaker etc, usually switched off when I am not there) 400W Wind turbine and its simple charge regulator 400W PV array, to be added another 400W, so it will be 800W MPP Solar PCM-6048 MPPT charge regulator (has RS232 and came with Windows software, would be nice to read it from Rpi) I have a remote cabin where I would like to monitor Solar PV and Wind turbine, battery pack, temperatures etc. DT goes LOW, CLK stays HIGH - clkLastState was HIGH, clkState is HIGH - Nothing happensģ.Wow, me too just stumbled across this topic. DT goes LOW, CLK stays LOW - clkLastState was LOW, clkState is LOW - Nothing happensĢ. CLK goes LOW, DT stays HIGH - clkLastState was HIGH, clkState is LOW (clkState != clkLastState ) so now we can determine direction - dtState is HIGH, clkState LOW, dtState != clkState, +1ģ. So here is a little example of how it works:Ģ. The logic for determining the direction of rotation is very simple to code, but not that easy to understand why it works. Line 26 - Pause the script from 0.01 of a second Line 25 - Update our clkLastState variable to match our clkState Line 24 - Simply prints the value of our counter variable Line 22-23 - If our DT pin's state is the same as our CLK pin state, then we are rotating in an anti-clockwise direction and therefore need to decrease our counter value by 1 Line 20-21 - If our DT pin's state is different to our CLK pin state, then we are rotating in a clockwise direction and therfore need to increase our counter value by 1 If it's different, the encoder is being rotated so we can then check to see the direction of rotation Line 19 - We then compare the current state of the CLK pin againts its previous state. Line 17-18 - So first, we get the current state of our CLK and DT pins Line 16 - 26 - This is an infinte loop in which we check the states of our CLK and DT pins to first see if the encoder is being rotated, and then to work our if its being rotated clockwise or anti-clockwise Line 12 - Get the inital state of our CLK pin Line 11 - Define our counter variable, starting at 0 Line 8-9 - Set our GPIO pins to inputs, with a pull down resistor. Line 5 - Define the GPIO pin for our DT pin of our rotary encoder Line 4 - Define the GPIO pin for our CLK pin of our rotary encoder Lets dive into the code and see how it works. As you rotate the encoder clockwise, the number increase by 1 each "click" and as you rotate it anti-clockwise it decrease by 1 each "click". Or download it directly to your Pi using this command in a terminal window: You can download our example code from our github. You don't need to worry about any resistors or other compontents, as the encoder has built in 10k Ohm resistors keeping the current to an absolute minimum! That's it as far as wiring up is concerned. This is what rotating the encode anti-clockwise 1 click looks like:Īs you can see from the diagram, you need to wire up the rotary encoder as follows: This is what the internals of a rotary encoder look like: With a simple bit of logic, you can work out the direction of the rotation (explained in detail below, be sure to check the code first!). If the internal contacts were originally HIGH (or making the circuit) after a single click, they would now both be LOW (breaking the circuit). As you turn the knob you can feel it "click" indicating that one position has been rotated. It works by having 2 internal contacts that make and break a circuit as the knob is turned. Lets start with a brief explanation of what a rotary encoder is, and how they work!Ī rotary encoder is a device that senses the rotation and direction of the attached knob. In this simple tutorial we will be showing you how to wire up your rotary encoder and how to use some python code to interact with it.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |