Hi I’m new to the PI .I want to use ADC input to turn on the relay. Where do I find the coding for the Automation pHAT?
the repository can be found here: https://github.com/pimoroni/automation-hat
to achieve what you want you’d need to read an analog input like so:
value = automationhat.analog.one.read()
then use it in a conditional to turn the relay on:
… that is broadly speaking the approach, the exact code you need to run will depend on your needs. Check the library doc for more options.
Hi thanks for the info. As I said I am very new to Pi. I have looked at the three examples in the GitHub is this the library doc you were referring to? I will be ok writing my code I just require the commands.
There is an API reference available in the ‘documentation’ directory. Most methods should be documented there.
… used alongside the examples they should give you a fair understanding of the library, but feel free to ask here if you get stuck.
Super thanks got the info now and prepared to start coding.
Hi I have started testing the automation phat but have hit a problem reading the ADC .i have connected ADC One input to 5v when I run the code using
Automation pHAT detected…
I assume this value should (if 10 bit ADC)be between 0 and 1023. Or am I missing something. I get the same result on the other two ADC inputs. I have checked with a DMM that there is 5v on the terminal.
The input, output and relay circuits are working ok. Also what current can the output circuits sink?
I believe it is a 12 bit Adc and the value back is a voltage. If you look at my topics I have created there is one about changing the value from an enviro phat from a voltage to a number between 0-1023 an a lot of it is cross compatible over to automation phat.
The topic is called getting a number from ads1015
Hi thanks for the info. Returning a voltage is what I need . But my problem is that the ADC is giving 0.0 when a voltage (5v) applied to any ADC input.
I believe tha ADC is 24 v but that wouldn’t be a problem. Can you attach a potentiometer and see what happens then?
Thanks I have found the issue. I only asked for one ADC read this gave 0.0v. I then used a while true loop which gave 5.3v on all but the first reading(0v).
So can you tell me why the first reading is always 0.0v as this may cause a problem with my project as I want to operate the relay when the ADC reading falls below 3.8v.
I have no idea why the ADc would do that. I am away from my kit at the moment so I can not test it on other ads1015 devidces but from memory this is not an issue that I have run into before and a quick google does not produce any promising results. Could you post the code you are using?
Hi ADC one is connected directly to the 3.3v pin on the phat.
When run gives
Automation pHat detected…
When run gives
Automation pHAT detected…
Thanks for the help this issue is not urgent I need to sort it before I start coding my project. So if its easier to leave it until after Easter that’s fine.
I think this is because creating the ads1015 class instance initialises the i2c bus, but perhaps the cause lies elsewhere. You should add a short pause after import of the library and that should take care of that.
Still, if there are readings that you would normally deem aberrations, i.e impossible under normal circumstances, it is probably a good idea for your code to exclude/ignore values returned outside of that expected range. Failing that you expose yourself to quite a lot of pain, potentially.
Thanks I put a sleep 1.0 delay after the import now getting consistent reading. I can now start writing code. Thanks for the advice re testing the input range.
Thank you guys you are very helpful at Pimoroni.
I’d definitely echo @RogueM’s advice and suggest you use something like a moving average or other smoothed value from the ADC. They’re definitely not immune to jitter and abnormal readings which could flutter your relay output.
There’s always a trade off between accuracy and response time. Although in this case you should get below 100ms response even when taking an average of 100 samples. Assuming Python can keep up, of course.