gc_2117
Posts: 4
Joined: Wed Dec 03, 2014 8:30 am

Tweeting Babbage - Failing

Wed Dec 03, 2014 8:44 am

Hi All,

I am fairly new to RPi and started working through some of the learning resources. Last day or so I have gone through the Tweeting Babbage Bear Project and everthing was working through the lesson but at the final step adding the WHILE loop has caused me issue. I have even copied and pasted the online sample code exactly to try and make this work.

My issue is that I run the code with:
[email protected] ~/tweeting-babbage $ sudo python3 babbage.py

THe loop then keeps running with the following until I CTRL C to force quit the code:
babbage.py:46: TwythonDeprecationWarning: This method is deprecated. You should use Twython.upload_media instead.
twitter.update_status_with_media(status=message, media=photo)

babbage.py:46: TwythonDeprecationWarning: This method is deprecated. You should use Twython.upload_media instead.
twitter.update_status_with_media(status=message, media=photo)

babbage.py:46: TwythonDeprecationWarning: This method is deprecated. You should use Twython.upload_media instead.
twitter.update_status_with_media(status=message, media=photo)

So basic outline is THAT IT WORKS and posts the image and text to Twitter but it stays in loop indefinately and is uploading constantly every few seconds until force quit of code? Not really worried about hte depreciation issue unless its contributing to the endless looping? What have I missed thats causing the endless loop????

Any help or suggestions greatly appreciated.

GC

DirkS
Posts: 9871
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Tweeting Babbage - Failing

Wed Dec 03, 2014 10:51 am

I assume you're using http://www.raspberrypi.org/learning/twe ... rksheet.md.
You probably already triple checked your code and wiring...

The project uses GPIO14, which by default is set up for output to a serial console.
You'll have to disable the serial console for the code to work. From the command line run:

Code: Select all

sudo raspi-config
In the menu select Advanced / Serial / No to disable serial console.
After this change you have to reboot the Pi.

HTH
Dirk.

User avatar
B.Goode
Posts: 8021
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Tweeting Babbage - Failing

Wed Dec 03, 2014 12:14 pm

#1 guess for a python loop not behaving as expected would be incorrect indentation.

User avatar
DougieLawson
Posts: 35517
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Tweeting Babbage - Failing

Wed Dec 03, 2014 12:20 pm

The latest Twitter API update doesn't allow you to send any tweets unless you've got a mobile phone number associated with your account. Is your code checking for a bad status code when it attempts and fails to send a tweet?
Note: Having anything remotely humorous in your signature is completely banned on this forum. Wear a tinfoil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

DirkS
Posts: 9871
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Tweeting Babbage - Failing

Wed Dec 03, 2014 12:28 pm

B.Goode wrote:#1 guess for a python loop not behaving as expected would be incorrect indentation.
Yes, but looking at the tweeting babbage code that's unlikely to be the problem here.
'Official' babbage code:

Code: Select all

    with PiCamera() as camera:
        while True:
            GPIO.wait_for_edge(14, GPIO.FALLING)
            timestamp = datetime.now().isoformat()
            photo_path = '/home/pi/tweeting-babbage/photos/%s.jpg' % timestamp
            sleep(3)
            camera.capture(photo_path)

            with open(photo_path, 'rb') as photo:
                twitter.update_status_with_media(status=message, media=photo)

The first statement is a wait for edge. If that's not indented correctly you'll get an indentation error.
Incorrect indentation further down would not result in a tweet (or an indentation error).
So the most probable cause (to me at least): wait for edge is not working correctly...

Gr.
Dirk.

User avatar
croston
Posts: 701
Joined: Sat Nov 26, 2011 12:33 pm
Location: Blackpool
Contact: Website

Re: Tweeting Babbage - Failing

Wed Dec 03, 2014 8:06 pm

What version of RPI.GPIO are you using? Please post the result of:

Code: Select all

print(GPIO.VERSION)
There was a bug with GPIO.wait_for_event() in some versions of RPi.GPIO that would result in the exact symptoms you are seeing. AFAIK this is now fixed.

To upgrade RPi.GPIO to the latest version:

Code: Select all

$ sudo apt-get update
$ sudo apt-get install python-rpi.gpio python3-rpi.gpio

gc_2117
Posts: 4
Joined: Wed Dec 03, 2014 8:30 am

Re: Tweeting Babbage - Failing

Thu Dec 11, 2014 12:18 am

Firstly thankyou to all those who replied with help and suggestions and Apologies that its taken a week to get back to this!

Unfortunately none of these fixes have resolved the issue.

@croston - gpio version reported as latest when I ran
[code]$ sudo apt-get install python-rpi.gpio python3-rpi.gpio [/code]

@DirkS - after my own code failed I downloaded and copied and pasted the "Official" code for babbage.py and got same error.
- I disabled serial console in raspi-config and that had no visable effect
- I changed GPIO from 14 to 18 and tested with no effect

@B.Goode - cut and pasted official code indented neatly as far as I can tell.

@Dougie.Lawson - Tweets are being sucessfully sent so dont think this is the issue. The issue is stopping the tweets from continually firing off.

After all this failed I formatted by SD card installed fresh Raspbian and updated all, grabbed all required software and updates rebuilt folder structure and copied and pasted official code for babbage.py and my old working auth.py file and end result is exactly the same issue. Tweets fire off successfully but wont stop until CTRL-C'ing it.

[b]Again many thanks to all those who offered help and suggestions.[/b] If anyone has any other suggestions or options please let me knwow as I have an 8 year old harrassing me to get this going for him!

THanks

GC

User avatar
croston
Posts: 701
Joined: Sat Nov 26, 2011 12:33 pm
Location: Blackpool
Contact: Website

Re: Tweeting Babbage - Failing

Fri Dec 12, 2014 11:10 am

Apologies - the problem you are having is almost certainly as a result in recent changes to RPi.GPIIO.

I've been having a think about this one - the responsiveness of repeat calls to wait_for_edge() in RPi.GPIO was improved between 0.5.6 and 0.5.8. My unit test circuit for RPi.GPIO includes a 0.1uF capacitor across the switch. The problem might be as a side effect of switchbounce that was happening too quickly to be picked up before but is being handled now. I thought I had fixed the repeat edges problem with RPi.GPIO in 0.5.8 - it passed all my unit tests designed to replicate the problem. I might add a switchbounce parameter to it - watch this space.

The following workaround should solve the issue for now before I get chance to reproduce the problem this weekend:

Code: Select all

$ wget http://archive.raspberrypi.org/debian/pool/main/r/rpi.gpio/python-rpi.gpio_0.5.6-1_armhf.deb
$ wget http://archive.raspberrypi.org/debian/pool/main/r/rpi.gpio/python3-rpi.gpio_0.5.6-1_armhf.deb
$ sudo apt-get remove python-rpi.gpio python3-rpi.gpio
$ sudo dpkg -i python-rpi.gpio_0.5.6-1_armhf.deb python3-rpi.gpio_0.5.6-1_armhf.deb
$ sudo apt-mark hold python-rpi.gpio python3-rpi.gpio
Hopefully this will result in a happy 8 year old again!

gc_2117
Posts: 4
Joined: Wed Dec 03, 2014 8:30 am

Re: Tweeting Babbage - Failing

Sun Dec 14, 2014 10:02 am

THANKYOU! @Croston

I followed you instructions and tested and it appears to be working as I had orignally expected! I really want to thank you for the time and effort you spent on this and getting me to this point. This is certainly not something I could have worked out by myself or using other online resources.

My son is asleep but will be very happy tomorrow when I can show him this working properly.

Again Thankyou.

GC

User avatar
justinrains
Posts: 5
Joined: Mon Aug 18, 2014 2:44 pm
Location: Erlanger, KY
Contact: Website

Re: Tweeting Babbage - Failing

Tue Jan 12, 2016 5:27 pm

The latest GPIO worked for me also. Thanks! I have a Raspberry Pi digital camera I made using a cigar box.

Justin

Return to “General discussion”