Has anyone else tried multiple servos moving at once? I'm curious how other systems will perform in terms of power supply capability required to get smooth motion.
[Release] HubDuino v1.1.4 - Hubitat to Arduino / ESP8266 / ESP32 / ThingShield Integration (ST_Anything)
Hey @ogiewon. I had a question for you regarding the PS_Voltage. I'm getting ready to build my own sensor for my drywer using a split core transistor. I have one that reports only up to 1v and also is below 100 mA when reading 20A and since I'll only be reading one of the two hot wires to my electric dryer, I figured that would be less than 20 since each circuit is 15A.
My question is about the constructor in the Hubduino sketch. The s_l,s_h,m_l,m_h are a bit confusing to me. I assume that the s_l and s_h are the low and high of the raw reading but what is the range of that normally? And I assume the m_l and m_h are the mapped low and high? Is one analog reading enough to be accurate or should I take 2 or 3? Any tips you might have would be very welcome.
Also, as far as how to set up the constructor to use the energy child device instead of the voltage one, all I have to do is build it like this:
st::PS_Voltage sensor1(F("energy1"), 60, 0, PIN_VOLTAGE, 0, 1023, 0.0, 20.0, 3);
In fact, that was the constructor I was planning on using, at least at first. I don't know if the 60 seconds is too aggressive. I used 1023 because that's what was in your example. Will both readings or only the mapped one come out in the serial log? Again, any times would be very welcome. Thank you!
The 0 to 1023 comes from the analog to digital converter on your micro controller. If you’re using a 10 bit ADC, then 0 to 1023 (or maybe 1024, actually) would be appropriate. Whereas a 12bit ADC would be 0 to 4096.
I think every 30 seconds should be fine. For a current transformer on an AC circuit, you’re going to have to deal with zero crossings where the voltage goes to zero 120 times a second. If you only sample once or twice, you may get erroneous readings. I would set the number of readings to at least 10 and see what you get. You can also use the filterConstant to help prevent a single low reading from messing up the result. I would probably set it to 80 as a starting point.
Further details are available in the documentation for the PS_Voltage device as follows
// st::PS_Voltage() constructor requires the following arguments // - String &name - REQUIRED - the name of the object - must match the Groovy ST_Anything DeviceType tile name // - long interval - REQUIRED - the polling interval in seconds // - long offset - REQUIRED - the polling interval offset in seconds - used to prevent all polling sensors from executing at the same time // - byte pin - REQUIRED - the Arduino Pin to be used as an analog input // - double s_l - OPTIONAL - first argument of Arduino map(s_l,s_h,m_l,m_h) function to scale the output - minimum raw AI value // - double s_h - OPTIONAL - second argument of Arduino map(s_l,s_h,m_l,m_h) function to scale the output - maximum raw AI value // - double m_l - OPTIONAL - third argument of Arduino map(s_l,s_h,m_l,m_h) function to scale the output - Engineering Unit Min (or Max if inverting) // - double m_h - OPTIONAL - fourth argument of Arduino map(s_l,s_h,m_l,m_h) function to scale the output - Engineering Unit Max (or Min if inverting) // - byte numSamples - OPTIONAL - defaults to 1, number of analog readings to average per scheduled reading of the analog input // - byte filterConstant - OPTIONAL - Value from 5% to 100% to determine how much filtering/averaging is performed 100 = none (default), 5 = maximum // // Filtering/Averaging // // Filtering the value sent to ST is performed per the following equation // // filteredValue = (filterConstant/100 * currentValue) + ((1 - filterConstant/100) * filteredValue) //
I'm using a Wemos D1 Mini which I'm 99.9% sure has a 10bit ADC. Thanks for all the info! I will definitely give it a try. You're the best!!
@ogiewon 10 bit ADC will return 1023 as the highest digital value which equates to 1111111111 binary. 12 bit ADC will return 4095 as the maximum digital value. While technically not correct, using 1024 instead of 1023 in the mapping function will not cause enough error to be noticed in most applications.
@Ryan780 using the value 20 is probably not the correct value to use for m_h depending on Aref for your microcontroller. If you reply with which microcontroller board you are using, I can assist in determining the correct mapping values. It would also help if you could send a link for the current sensor you plan to use.
Edit, I will look up Aref for Wemos D1 mini and reply with scaling values
Wemos D1 mini is 10 bit, so s_h = 1023 is correct.
If your sensor outputs 0 volts at 0 amps, then s_l = 0 and m_l = 0
If your sensor outputs 1.0 volts at 20 amps input, m_h = 66 would be appropriate for a Wemos D1 mini.
Here's why: A0 input range on the Wemos D1 mini is 0-3.3 volts. It has a voltage divider that scales 3.3 volts down to 1.0 volt at the input pin of the ESP8266. The ESP8266 will read a digital value of 1023 for a 1.0 volt input. Including scaling the effect of the voltage divider will give 1023 for a 3.3 volt input at A0 of the Wemos D1 mini.
Your sensor's maximum input voltage to A0 is 1.0 volt, so some scaling is required.
The calculation is: m_h = 20 x (3.3/1.0) = 66
Some things to note: You will only be using 1/3.3 = 30% of the ADC range at 20 amps input. The corresponding digital value will be 310. The precision (step size) you will see for the device in Hubitat is 20/310 = 0.065 amps.
I hope this helps.
PS. I'm curious about the current sensor you are building, especially the comment about 100 mA when reading 20A. Can you tell me more about the sensor? I want to be sure I am giving you good guidance on the scaling factors.
Wait.... What? What does 3.3 v have to do with anything. LOL. Now I'm so confused. What are you talking about?
The Wemos D1 mini A0 input voltage range is 0 volts to 3.3volts. 0 volts input will result in ADC conversion to 0 digital value. 3.3 volts input will result in ADC conversion to 1023 digital value.
Okay. So, why wouldn't I just use 341 for my s_l? Also, this is the transformer I got.
What output units would you like to send to Hubitat? Volts, Amps, or Watts? If using the Energy child device, I would think Watts or kW would be appropriate.
I would use
0, 1023, 0, 15840 for Watts
0, 1023, 0, 15.84 for kiloWatts
Your CT will produce 1 volt at 20 amps. Since the Wemos input allows for up to 3.3v, the maximum reading at 3.3v would be 66 amps. 66 amps * 240 volts = 15840 Watts.
Might as well be as accurate as possible, right?
Okay. Ill give that a shot.
If you are gong to use the power calculation proposed by Dan, it is especially important to use a high enough number of samples to average the current reading as the voltage goes through its alternating cycle. Start at a low value for:
(- byte numSamples - OPTIONAL - defaults to 1, number of analog readings to average per scheduled reading of the analog input)
Increase it until the output becomes consistent.
To answer this question concerning current measurement:
Assuming you meant to type 310, not 341, these two sets of scaling factors are equivalent:
0, 1023, 0, 66
0, 310, 0, 20
What matters is the ratio: 1023/66 = 310/20
You're so far over my head right now...it's like you're speaking Norwegian or something. LOL
Well, that's when it is important to tell the community what you are trying to do, and what hardware you are doing it with. Most times you will get an answer on what to do even if you don't understand. If you have the need to understand, keep asking questions.
BTW, I found a spec sheet for the current sensor you are using, and I believe the two options we gave you are correct for that sensor.
@Ryan780 I want to back up a bit after researching your sensor a little more. If you connect the sensor directly to the Wemos, you might fry the Wemos. The sensor output with no conditioning will be +/- 1 volt. the - 1 volt will not play well with the Wemos. You will need to use a circuit like this to make it work:
Replace the Arduino 5V with your Wemos 3.3V. The resistor and component values should still be ok as shown.
I'm too tired to calculate the scaling factors to use, but they will likely be different than we gave you previously. I can think about this again tomorrow.
Why would it output - 1v? I'm only going to be attaching it around 1 of the hot lines of the 220v. The current will only ever be positive. So, why would the voltage be negative? It says that the output is 0-1v.
AC = Alternating Current.
So it will be a sine wave that is positive and negative. I would recommend the circuit proposed too.
I have used some micros where the have internal diodes to protect against negative voltage/current but they can't handle much, so it is better to be safe than sorry.
I wouldn't need a burden resistor? Is that the same as the "sampling resistor"?
Also, would a 1000uF 6v capacitor work or no? I really don't want to have to buy a whole other set of capacitors. Also, the other pages I've looked at call for a 10K resistor instead of 22K. Is there a reason to use one or the other?
The SCT-013-020 already has an internal burden resistor, as shown in the diagram posted by Jeff (@VooDooFiveTwo) above. So, no need for an external burden resistor.
The goal of the circuit above is to act as a voltage level shifter, by biasing the voltage by 50% of the Wemos 3.3vdc supply. So, instead of the output of the CT varying from -1v to +1v, it will instead vary from ~0.65v to 2.65v for a full 20A load. for a 10A load, the voltage would vary between 1.15v to 2.15v.
So, that now leads us to the next issue... How do we calculate the current from an oscillating signal?
I am enjoying the discussion regarding this subject. I can imagine a new ST_Anything device being written that would be able to read the current value from a CT, and convert it to power (P = V * I, where the user would provide the voltage in the constructor as either 120VAC or 240VAC, for example). This would then be sent to to the Power Device (Watts or kW). We could also expand it to include some options for Energy as well, which is in kWh typically.
This will never be an incredibly accurate measurement of power/energy, but it wouldn't be too far off.
Keep the discussion going!
First of all, I don't expect the load to be any higher than 10A for the one hot line. So, is 1.15-2.15 enough variance to accurately measure that? Wouldn't I want a greater spread in the values?