Controlling a Servo Motor with Gmail and Raspberry Pi
Sep 16, 2017
You covered part one and part two (good work!), or maybe you didn't and you found yourself here anyway (welcome). Part three is focused on the servo motor, primarily making it spin. Later in part four we'll wrap things up by connecting it to the dispenser.
As always, let's start with what it is we're trying to accomplish here:
- Connect the servo motor to the Raspberry Pi's GPIO header pins
- Write some code to make that motor functional
- Tie in the GmailWrapper.py script we wrote in part two so the motor spins when the right email lands in your inbox
Here we go!
Connecting the Servo Motor to the Raspberry Pi
If you're using the same servo motor as me, it hasĀ power, ground and control wires. If you decided to use the standard non-continuous servo motorĀ (which is a viable alternative since we won't be performing a full revolution), then: power is red, ground is black and white is control.
Connect your male-to-female jumper cables to the servo. Now, using the GPIO diagram below as reference, connect the wires to the Pi's GPIO headers as follows:
Note: this diagram is for Raspberry Pi's with 40 pin GPIO, but the below works with 26 pin GPIO as well.
- powerĀ connects to header pin 2 (5v power)
- groundĀ (black wire for standard servo) connects to header pin 6 (Ground)
- controlĀ (white for standard servo)Ā connects to header pin 12 (GPIO18)

Here's what mine looks like (don't mind the zip tie):
Writing Code to Make the Servo Motor Spin
Before getting started, let's update our Pi to the latest packages and install the GPIO library. Run this in the terminal:
sudo apt-get update sudo apt-get upgrade sudo apt-get install rpi.gpio
We're all set. In the terminal, create a new python script using nano:Ā sudo nano CatFeeder.py
Within the CatFeeder.py script, add the following code:
#!/usr/bin/env python
import RPi.GPIO as GPIO
import time
def feed():
# let the GPIO library know where we've connected our servo to the Pi
GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.OUT)
try:
servo = GPIO.PWM(18, 50)
servo.start(12.5)
# spin left, right, then left again rather than in a continuous circle
# to prevent the food from jamming the servo
for index in range(0, 3):
dutyCycle = 2.5 if (index % 2 == 0) else 12.5
servo.ChangeDutyCycle(dutyCycle)
# adjust the sleep time to have the servo spin longer or shorter in that direction
time.sleep(0.8)
finally:
# always cleanup after ourselves
servo.stop()
GPIO.cleanup()
if __name__ == '__main__':
# kick off the feeding process (move the servo)
feed()
Save and exit the nano editor: CTRL+X, then Y, then Enter. Moment of truth, time to make that servo move! Let's drop back into the Python interpreter, in the terminal:
# remember, hit enter after each line to have the interpreter... interpret
python
import CatFeeder
CatFeeder.feed()I hope that went smooth for you, because I just got really excited. Welcome to physical computing! You moved a physical object with code, hell yeah.
GmailWrapper, Meet CatFeeder: Putting it all Together
Alright, so we've created a way to read emails, and we've created a way to move a servo motor. Now we need to combine the two so the servo motor moves when we read emails.
OpenĀ CatFeeder.py in nano and add the highlighted lines of code:Ā sudo nano CatFeeder.py
#!/usr/bin/env python
from GmailWrapper import GmailWrapper
import RPi.GPIO as GPIO
import time
HOSTNAME = 'imap.gmail.com'
USERNAME = '<your gmail username>'
PASSWORD = '<your app password or regular gmail password>'
def feedByGmail():
gmailWrapper = GmailWrapper(HOSTNAME, USERNAME, PASSWORD)
ids = gmailWrapper.getIdsBySubject('feed cats')
if(len(ids) > 0):
try:
feed()
gmailWrapper.markAsRead(ids)
except:
print("Failed to feed cats, they're starvingggg")
def feed():
# let the library know where we've connected our servo to the Pi
GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.OUT)
try:
servo = GPIO.PWM(18, 50)
servo.start(12.5)
# spin left, right, then left again rather than in a continuous circle
# to prevent the food from jamming the servo
for index in range(0, 3):
dutyCycle = 2.5 if (index % 2 == 0) else 12.5
servo.ChangeDutyCycle(dutyCycle)
time.sleep(0.8)
finally:
# always cleanup after ourselves
servo.stop()
GPIO.cleanup()
if __name__ == '__main__':
# kick off the feeding process (move the servo)
# we now use our new feedByGmail method to handle the feeding
feedByGmail()
Save and exit the nano editor: CTRL+X, then Y, then Enter. As always, let's give it a test. Send yourself an email with the subjectĀ feed cats. Drop into the python interpreter once the email arrives:
python
import CatFeeder
CatFeeder.feedByGmail()Did it work? It did? Excellent! If it didn't, don't be discouraged! Python's support community is huge, you'll find the answer. Plus, you can always leave a comment below.
Scheduling a Cron Job to Run Our Script Regularly
We have code to move our servo motor when the correct email lands in our inbox, but it currently only runs when we physically tell it to. Let's fix that by setting up a cron job to run our script every 60 seconds.
In order for the cron job to execute our script, we need to make our script executable. This is done by issuing the following command in the terminal:Ā sudo chmod +x CatFeeder.py
Now we'll add the cron job. In the terminal:Ā crontab -e. Add the following after the very last commented line (comments start withĀ #):
* * * * * python /path/to/your/script/CatFeeder.py
As Gabe called out in the comments, adding pythonĀ after the last asterisk (*) in the line above will force the python interpreter to be used while running our script. We're in the nano editor, so save and exit:Ā CTRL+X,Ā Y,Ā Enter. Easy as Pi (sorry). A job is now running every 60 seconds with the sole task of looking for emails and feeding cats. Don't believe me? Give it a shot, send yourself an email with the subjectĀ feed cats.
A nicety of cron jobs is they'll continue running automatically if your Pi ever restarts.
Scheduling an Email to be Sent Regularly
We have the code, we have the cron job. Sending an email on demand will cause the servo motor to spin, but what about spinning it on a schedule? That's where we'll make use of IFTTT. IFTTT stands for if this then that andĀ allows you to connect two disparate systems based on what they call a "recipe" (trigger and action). For our purpose, we need the clockĀ to triggerĀ an email to be sent (action). Here's what to do:
- Setup an account if you haven't already
- Use IFTTT website or download the app to your phone and log in
- In the My Applets section, add a new applet
- You'll see a screen sayingĀ if +this then that:Ā click the +this button, then select theĀ Date & Time service.
- Select theĀ Every day at trigger, and select the time you'd like the cat feeder to activate, then hitĀ next
- Now you'll seeĀ +that, click it and find theĀ Gmail service. You'll need to connect the service to your Gmail account. Once finished, set the action toĀ Send yourself an email with the subjectĀ Feed cats.
- HitĀ next, thenĀ Finish
There you have it, every day at the time you specified an email will be sent to your account. If you had any issues setting up the IFTTT recipe, check out this post for a really nice and in-depth walk-through.
Having fun? Here's Other Ways to Send an Email
Alexa
Alexa integrates nicely with IFTTT. In the IFTTT app, create a new recipe with the trigger (+this) connecting to Alexa. You'll need to connect the service like you did for Gmail. Once connected, set the action (+that) to send an email, like we did in the previous section.
Hands free feeding at your ready:Ā Alexa, trigger the cat feeder.
The DO Button App
Created by the IFTTT team, the DO Button app and accompanying widget provides a straightforward way to trigger the action. You! You're the trigger. You setup a recipe, same as before, except you'll notice there's noĀ +this. You are the +this. You open the app and click the button, it then triggers an email. This app can also be configured to show on your iPhone or Androids home screen, so triggering the email is even easier.
Conclusion and Next Steps
Part oneĀ has goals and items covered, part two has Gmail automation down, and part three provided the spinning of the motor. A lot has been done so far, we're nearly there. Up forĀ part four?Ā That's where I'm headed to connect the Pi and motor to the dispenser.



Comments
Leave a Comment
Mike
October 30, 2017 at 1:17:45āÆPM UTC
Everything is working great expect for the pesky cron job. It just wonāt run. Iāve always had issues getting python scripts to run using cron. Any ideas?
Sam Storino
October 30, 2017 at 8:07:53āÆPM UTC
Awesome, glad youāre making your way through the posts without much difficulty.
I had trouble running a cronjob in the past and wrote a post about the findings. Check it out and let me know if it helps!
https://storiknow.com/linux-cronjob-doesnt-execute-valid-python-script/
Carl
January 10, 2018 at 2:55:29āÆPM UTC
I must say this is one of the best tutorials I have seen. I particularly like the way you got me to check every step of the coding before proceeding to the next. I managed to troubleshoot every thing up to the Cron part Just Like Mike. I read the post you linked to on your blog and that line is in the script already. Im not sue what I have missed.
Sam Storino
January 11, 2018 at 7:46:09āÆAM UTC
Thatās excellent to hear, I appreciate the feedback, Carl! I wonāt pretend to be an expect in Cron jobs, but would start by ensuring you can run the script manually without issue. If you can then we can safely point the blame at the cronjob step. Hereās how:
In the terminal:
1) make the the script executable (chmod +x script.py) if you havenāt already
2) navigate to the directory of the script and type: ./script.py
If the script runs fine it all comes down to cron. Unfortunately, there could be any number of small issues here, ranging from security to simply adding a new line at the very end of the cron job. This [askubuntu](https://askubuntu.com/questions/23009/why-crontab-scripts-are-not-working) post really outlines a number of common gotchaās.
Hope that helps!
Carl
January 11, 2018 at 9:19:01āÆAM UTC
Thanks for the reply Sam
It works perfectly when using python
I have run the chmod +x script.py command but it said ānot possibleā until I put sudo in front (maybe this is the issue). I am logged in as pi
When I run the script using ./ I get the following
from: cant read /var/mail/GmailWrapperā¦
./CatFeeder.py: line6: import:command not found and several other lines up to line13
Itried making GmailWrapper.py executable as well and checked the shebang no joy
If I run ./GmailWrapper.py i get the same errors but listing imap client.
Searching the error brings me back to the shebang error any Ideas gratefully received
Carl
Gabe Byars
January 17, 2018 at 4:24:57āÆPM UTC
I got it to work by calling calling python in my cronjob
**** python CatFeeder.py
Hope this helps,
Gabe
Sam Storino
January 17, 2018 at 5:30:50āÆPM UTC
Thatās great, thanks for sharing Gabe. I believe Carl was able to resolve his issue by ensuring the SheBang tag was first and foremost in the script. If anything is before it, the python interpreter wonāt be used by default.
liam
March 8, 2018 at 10:01:56āÆAM UTC
Do you know how to implement a camera into this?
Sam Storino
March 8, 2018 at 8:11:53āÆPM UTC
Hi Liam, I havenāt hooked one up before but have thought about it using the Pi Camera (https://www.raspberrypi.org/products/camera-module-v2/).
Andrew
March 17, 2018 at 7:01:18āÆPM UTC
For many of us I think the issue may be we donāt know where the scripts we created are stored.
Jankei Shinde
April 8, 2018 at 6:12:43āÆAM UTC
Hi Sam,
Great project. Gotten down to making.
Iām using a 12V dc motor 3.5 rpm instead of the servo. Iāve used a driver circuit for my motor.
Iām implementing the same code, but the motor wonāt run.
How do I fix this?
Please Revert asap as Iām on a time crunch.
Thanks.
Sam Storino
April 8, 2018 at 4:34:50āÆPM UTC
Iāve never wired up/ controlled a DC motor before, so I canāt really give much advice here. There are a lot of tutorials online that should be able to help out.
https://medium.com/@Keithweaver_/controlling-dc-motors-using-python-with-a-raspberry-pi-40-pin-f6fa891dc3d
Jankei Shinde
April 8, 2018 at 4:41:40āÆPM UTC
Alright, Iāll check them out.
Thanks.
Jankei Shinde
April 9, 2018 at 2:15:55āÆPM UTC
Hey Sam,
So I changed my motor to servo motor as it was a more efficient option considering Iām on a time crunch.
Now my entire system is up and running with the email.
I have two issues-
1. How do I get the motor to run a complete circle in one direction, instead of left and right?
2. When I schedule a cron job, it shows in the status that itās running, but it actually isnāt. The email is not getting read automatically. Can you tell me why this could be happening and what can I do to fix this?
Thanks.
Sam Storino
April 9, 2018 at 4:34:14āÆPM UTC
Iām glad to hear youāre making some good progress. Assuming you purchased the continuous rotation servo, you can have it rotate one direction by replacing lines `33` through `36` in the āGmailWrapper, Meet CatFeeder: Putting it all Togetherā section above with:
servo.ChangeDutyCycle(2.5)time.sleep(3) # this is how long to rotate for
As for the cronjob, if setup correctly it should just be making a call to execute your `CatFeeder.py` script. Itās possible you have errors in that script. You can check that by running it manually. In your terminal, navigate to the directory where your `CatFeeder.py` script lives, and type:
./CatFeeder.pyIf thereās an issue, the terminal should show an error. Youāll then need to investigate what went wrong. If it runs fine but the email doesnāt get read, there may be a logical error with the code itself, at that point youāll just have to look in the code above and ensure you didnāt miss anything.
Jankei Shinde
April 9, 2018 at 6:27:05āÆPM UTC
Hi,
Alright Iāll check through this. Will revert back.
Thank you so much!
Jankei Shinde
April 10, 2018 at 4:03:16āÆPM UTC
Hey Sam,
So I followed your instruction.
The code for the motor didnt make my motor run according to it. I guess it started drawing more current from the Pi, cause it restarted it in the middle of it.
As for the cronjob, I ran it in the terminal and got something as below. Iām a little confused because the code works just fine when I run it in the terminal. How do I resolve this issue.
Please do help.
pi@raspberrypi:~ $ ./PetFeeder.py
from: canāt read /var/mail/GmailWrapper
./PetFeeder.py: line 3: import: command not found
./PetFeeder.py: line 4: import: command not found
./PetFeeder.py: line 6: HOSTNAME: command not found
./PetFeeder.py: line 7: USERNAME: command not found
./PetFeeder.py: line 8: PASSWORD: command not found
./PetFeeder.py: line 10: syntax error near unexpected token `(ā
./PetFeeder.py: line 10: `def feedByGmail():ā
Thanks.
Jankei Shinde
April 10, 2018 at 4:42:36āÆPM UTC
Hey Sam, Carl and Gabe,
I had the same errors. Gabeās solution really did help.
Thanks a ton!
Jankei Shinde
April 10, 2018 at 4:44:45āÆPM UTC
Hey,
Okay, Gabeās solution above helped resolve my issues.
Just the motor issue is left now. Help!
Thanks.
Jake C
April 26, 2018 at 6:45:14āÆAM UTC
just had to comment how amazing this project is! me and my son built one together and its running great!! Only time i had trouble was for some reason google wouldnt auth (had spaces in app key).
Sam Storino
April 26, 2018 at 2:16:25āÆPM UTC
Iām glad you two enjoyed the project! Thatās really great. Thank you for the feedback Jake.
Iām working on a new tutorial for a cat laser toy, which should be up in the next few days. Stay tuned.
Rob
May 10, 2018 at 2:00:35āÆPM UTC
Hey Sam,
Iām loving this tutorial but Iāve hit a stumbling block. Iām not able to make the servo rotate. Iāve followed your steps to the letter but id doesnāt move. When I run CatFeeder.py the servo makes a noise but doesnāt move.
Iām using a different servo to the one you recommended. Itās a carson reflex cs3. Will this make any difference?
Thanks in advance,
Rob
Rob
May 10, 2018 at 2:12:35āÆPM UTC
Ignore this, I did something stupidā¦haha
Sam Storino
May 10, 2018 at 7:59:11āÆPM UTC
Ha! I can certainly say I know the feeling. Iām glad you were able to get it figured out, Rob. Thanks for the feedback in your other comment, itās nice to hear the tutorial is working out for you. Feel free to reach out if youāre stuck in the future. Enjoy!
G
June 21, 2018 at 8:10:46āÆPM UTC
Got it to work by using Gabeās suggestion for the cronjob script. Very cool project and the steps were straight forward. Thanks!
Sam Storino
June 22, 2018 at 8:07:40āÆAM UTC
Thanks for the feedback, G!
Kevin Smits
July 10, 2018 at 12:58:54āÆPM UTC
Hi Sam,
Awesome project, thanks for sharing and answering questions.
I also have a question on the servo script, for some reason I canāt get my servo to start turning.
The servo is the FS5113R and Iāve followed your steps above. It does not provide any errors, but there is simply no movement.
Is there any way to troubleshoot this?
Also, when I enable pigpiod and use āset_servo_pulsewidth(18, 1600)ā it does start spinning, however it also spins randomly afterwards.
Are there any additional librabries or deamons required?
Thanks in advance!
Regards,
Kevin
Sam Storino
July 17, 2018 at 5:29:23āÆPM UTC
Hi Kevin,
If youāre able to make it move using the `pigpio` module, it may be worth continuing that route. It sounds like youāve started the necessary daemon, and were able to at least get the motor to make an initial move. I donāt have experience with the `pigpio` library, but according to their documentation it looks like you may be able to do something like this:
set_servo_pulsewidth(18, 1000) # rotate anti-clockwise safetime.sleep(1)
set_servo_pulsewidth(18, 1500) # rotate center safe
time.sleep(1)
set_servo_pulsewidth(18, 2000) # rotate clockwise safe
time.sleep(1)
Be sure youāre performing a
sleepbetween each change to allow the motor a chance to set itself.Hereās a forum post related to pigpio which may be helpful.
Kevin Smits
July 18, 2018 at 3:43:57āÆAM UTC
Hi Sam,
Thank you for your reply.
This is indeed exactly what I had and it works, however the issue I had is that if I leave it at 1500 at the end of the script it doesnāt fully stop (the stop() function does nothing) and it spins randomly after the script closes.
Reading your link, I should change it to 0. Will definitely give it a try this evening!
Again cool post(s) and thanks for sharing.
Regards,
Kevin
Justin
August 10, 2018 at 7:57:18āÆPM UTC
Hi, so far this guide is great! I am having problem with running the servo though. I bought the one you recommended but everytime I attempt to start it, power cycles on my pi. I have confirmed that I am wired up like you said and I donāt see any visible short in the cables. How did you determine which lead on the motor was what? I canāt seem to find a wire diagram for the motor.
Sam Storino
August 10, 2018 at 9:09:39āÆPM UTC
Iām glad youāre enjoying the guide! This sounds like a power issue. The motor draws a decent amount, so double check youāre not skimping out on the power supply. Check out the āpartsā section of part one and compare your specs with the one Iāve posted there.
I canāt recall exactly where I obtained the wiring information, but a quick search revealed this page which is pretty useful.
https://www.pololu.com/product/2820/faqs
Carl
September 22, 2018 at 5:11:08āÆPM UTC
Hi Sam,
Fantastic job on detailing this! It works perfect with a pizero. I want to keep the rotations of the servo but want to reduce the food output by half. I suspect this has to do with line 35 but I havenāt figured out how to reduce the rotation of the servo. I keep putting too much food out.
Carl
September 22, 2018 at 9:08:59āÆPM UTC
Sam,
Just figured out to just reduce the time.sleep(X). Iād still love to know how the LRL is coded. Would that be in the servo GPIO documentation or in python?
Richard Campbell
September 25, 2018 at 11:22:29āÆPM UTC
Sam,
For some reason after I did the cronjob the servo will turn every 60 seconds. I havenāt sent an email in the last 30 minutes but it keeps turning every 60 seconds?? Also, you added a link with the Monitoring script. Where do we get the code for the monitoring script?
Thanks
Richard
Sam Storino
September 26, 2018 at 7:53:16āÆAM UTC
Hey Carl. Apologies for the delay. Iām glad youāre experimenting with the code a bit, itās interesting to see what happens when you start modifying things.
The code responsible for rotating the motor left, right, then left again is in the first block of code above, line 18:
`dutyCycle = 2.5 if (index % 2 == 0) else 12.5`
2.5 translated to 0 degrees, while 12.5 is 180 degrees (7.5 is 90 degrees etcā¦). By modifying the sleep time youāve given the motor less time to get to its destination degree, which is why it reduced the output. Itās still trying to hit 0 and 180, but only making it a portion of the way, and thatās ok!
I hope that helps. For further reading you can look up Pulse Width Modulation and Duty Cycle.
Sam Storino
September 26, 2018 at 8:02:57āÆAM UTC
Hey Richard. It sounds like your email isnāt successfully being marked as read after the script runs. Can you verify this? Make sure you donāt have any unread emails, then send yourself one with the correct subject (e.g. Feed cats). Once the servo spins, check that your email is marked read. If for some reason it isnāt, or it becomes unread (or another email is sent to that email box), youāll see the motor continue to spin.
As for the monitoring script, I couldnāt find a reference to that in the code above. Would you mind pointing me to it? Regardless, that script isnāt necessary for this project.
Richard
September 26, 2018 at 11:59:02āÆAM UTC
Sam,
Thanks for getting back to me so quickly. I am actually trying to help a fifth grader finish this project for Maker Faire Seoul this weekend!!
When I send a feed cats email it take a pretty long time to go through and then nothing.
Thanks
Richard
Richard
September 26, 2018 at 12:03:44āÆPM UTC
Ok, so I found a mistake in the crontab. The command I entered had Catfeeder.py (Now CatFeeder.py) So now I am back to every 60 seconds the servo turns. I sent two emails, only one came through so far and it was read. But now I donāt have any unread emails in my inbox but the servo still turns every 60 seconds???
Thanks
Richard
Sam Storino
September 26, 2018 at 12:33:50āÆPM UTC
Interesting. It sounds like you have cron figured out at this point, and marking an email as read doesnāt seem to be an issue. All signs are pointing to the steps before that responsible for determining if a valid email is found/ should the feeder be triggered. If you just run the script normally, without the help of cron, does that trigger the feeder?
Sam Storino
September 26, 2018 at 12:48:29āÆPM UTC
Thatās fantastic! I just took a look at your linked website, youāre doing some very incredible work. If youāre still stuck after reading my response to your latest comment, send me a direct email to āsam@storiknow.comā with all the files youāre using attached. I can take a deeper looked to see if any of the code seems out of sorts.
Richard
September 26, 2018 at 12:57:59āÆPM UTC
Yes, when I run the python
import CatFeeder
CatFeeder.feedByGmail()
It will turn the servo and read the email.
Sam Storino
September 26, 2018 at 4:33:21āÆPM UTC
Right, but when you donāt have any āunreadā emails in your account and you run the script, does it still turn the servo?
To avoid bloating the comments, shoot me an email (sam@storiknow.com) with the response and the code files attached, Iāll take a look and see if anything is out of sorts.
Richard
September 26, 2018 at 8:01:34āÆPM UTC
Sam,
I was able to find the problem. In the last line of the CatFeeder.py code I had an extra line from the original code feed() Once I took that out everything is working fine!!
Now on to the scheduler!!
Thanks for your help!
Richard
Sam Storino
September 26, 2018 at 8:33:16āÆPM UTC
Excellent work. Best of luck at the maker faire!
Dylan Eave
January 9, 2019 at 5:12:59āÆPM UTC
Hi there Sam. I am another one of your very grateful readers. I am using the your concept to override a simple borehole pump controller which pumps water for over 800 people.
Sadly I cannot get the system working as a python script. If I run the commands individually at the python interpreter it all work just fine.
If I have an email unread in the inbox which has a matching subject line (āStop-Borehole-Aā), the code will detect this (as evidenced by a ids number returned) but a fault occurs when trying to mark this email as read.
Running the code below results in the following:
pi@raspberrypi:~ $ sudo python timer_by_email.py
Logging in as thosethreetowers
[56]
Low
Failed to stop pump
The code is pasted below ā I hope you will be able to assist me in resolving this:
#!/usr/bin/env python
from GmailWrapper import GmailWrapper
import RPi.GPIO as GPIO
import time
HOSTNAME = āimap.gmail.comā
USERNAME = āthosethreetowersā
PASSWORD = āoret pyzj czml xowvā
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(18, GPIO.OUT)
gmailWrapper = GmailWrapper(HOSTNAME, USERNAME, PASSWORD)
def StartByGmail():
ids = gmailWrapper.getIdsBySubject(āStart-Borehole-Aā)
if(len(ids) > 0):
print(ids)
try:
print āHighā
gpio.output(18, gpio.HIGH)
sleep (5)
gmailWrapper.markAsRead(ids)
except:
print(āFailed to start pumpā)
quit()
def StopByGmail():
ids = gmailWrapper.getIdsBySubject(āStop-Borehole-Aā)
if(len(ids) > 0):
print(ids)
try:
print āLowā
gpio.output(18, gpio.Low)
sleep (5)
gmailWrapper.markAsRead(ids)
except:
print(āFailed to stop pumpā)
quit()
if __name__ == ā__main__ā:
# kick off the feeding process (move the servo)
# we now use our new feedByGmail method to handle the feeding
StartByGmail()
StopByGmail()
Dylan Eave
January 9, 2019 at 5:14:45āÆPM UTC
I am not concerned about the password details shared. These will be modified following resolution of this problem. š
Dylan Eave
January 9, 2019 at 5:15:37āÆPM UTC
I also do believe that my white space in code is all correct.
Dylan Eave
January 10, 2019 at 9:33:18āÆAM UTC
I wish to thank Sam for contacting me directly with the solution š ā A simple case of case error š
Many many thanks for this well written tutorial ā Your system is now used also as a means of controlling a large pump and set of solenoid valves which direct water to various places š
EUSTACHE Thibaut
February 15, 2019 at 5:31:27āÆAM UTC
Great tutorial, it works very well.
Is it possible to go from 60 seconds to 10 seconds for the cronjab?
Sam Storino
February 15, 2019 at 4:49:11āÆPM UTC
Thanks for the feedback, itās good to hear the tutorial was easy enough to follow.
As far as Iām aware, cron only allows minimum 1 minute intervals.
If you need to run this more frequently, youāll need to take a different approach to the problem. I just so happen to have taken an alternative approach in my Automatic Laser Pointer series. There, I run the script when the Raspberry Pi boots up, and have it running continuously, rather than every 60 seconds via cron. I log into Gmail initially at launch of the script, then every 30 seconds it scans for new emails.
Technically you could alter this to check every 10 seconds. However, too much activity to a single Gmail account could look suspicious from Googleās perspective, and may result in an account lock. With that said, I havenāt tested the thresholds as I havenāt had a need for instantaneous feedback.
Hope that helps!
navi
March 11, 2019 at 2:53:08āÆPM UTC
i have error on ImportError: No module named āGmailWrapper, can you help?
Sam Storino
March 11, 2019 at 3:18:06āÆPM UTC
Hi Navi,
I can give it a shot. To avoid bloating the comments, shoot me a message through the āContactā page with the code youāre trying to run. This way I can take a look.