This week we looked at sending texts and emails from our python scripts.
To send text messages you will need to set up an account on Twilio which is a platform that allows coders to make and receive phone calls, send and receive text messages from their programmes. You then install the Twilio python library which will allow us to send texts from our script using code like this.
# Download the helper library from https://www.twilio.com/docs/python/install
from twilio.rest import Client
# Your Account Sid and Auth Token from twilio.com/console
# DANGER! This is insecure. See http://twil.io/secure
account_sid = 'your account_sid'
auth_token = 'your auth_token'
client = Client(account_sid, auth_token)
message = client.messages \
To send an email we use smtplib which is an email library that’s built into python and which works well with Gmail. We need to change our Gmail setting to allow insecure apps and then we can use the code below to send our message.
This week in the Bodgers group we looked at the Pi Camera Module which is a high quality image sensor add-on board for the Raspberry Pi. You can capture images from the command line with:
raspistill -o cam.jpg
This will take a jpeg picture called cam which will be saved in your home folder.
You can take a picture from your Python script with:
from time import sleep
from picamera import PiCamera
camera = PiCamera()
camera.resolution = (1024, 768)
# Camera warm-up time
This will save a picture called foo in the folder you ran your script from.
OpenCV (Open source computer vision) is a library of programming functions mainly aimed at real-time computer vision. We tried a couple of scripts out, one from the Hackers group, thanks Kevin, that detects colours and another one that detects shapes, we will be looking at this much more in the next few sessions but next Saturday we will look at using an Arduino and a Raspberry Pi together.
This week we continued working on our Astro Pi entries and we also looked at FreeCAD and Fritzing which are tools that will help us with building our projects.
FreeCAD, available for download from here, is used for 3D modelling and allows us design very complicated things from simple 3D shapes such as cubes and cylinders. Here are a couple of quick videos to get you started.
Then we looked at Fritzing, download from here, an application for drawing very easy to understand circuits, here’s how to draw a simple circuit using it.
Dave will be leading next Saturday’s session and I will see you again on the ninth of Feb.
This week we started looking at physical computing and the Raspberry Pi. This involves attaching various components such as sensors, motors or controllers to the GPIO pins on our Pi. This week we connected a LED and two buttons, and we used the GPIO Zero module for Python to control them. I’ve made a video, it’s a little bit long, that covers everything from Saturday’s session.
At the end of the session the group started working on a traffic light idea and we will combine this with HC-SR04 ultrasonic distance sensor next week to create a measuring device.
We continued working with Pygame Zero this week, we began by getting everyone up to date with where we were with the game. I forgot to mention we were following the tutorial at https://pygame-zero.readthedocs.io/en/stable/introduction.html. We then changed the screen size and added a score to make our game more fun.
Next week we will add some elements to make our game more difficult and even more fun.
This week in the Bodgers group we started working with Pygame Zero. Pygame Zero allows us to write our own games quickly and easily by doing a lot of the work involved in setting up and running a game in the background. This allows us to focus on the more creative aspects of the game.
You will have to install Python and Pygame Zero if you’re going to use Pygame Zero at home, details on how to do this are in my slides. A few of us had installation problems on Saturday, so don’t worry if you have issues we will help sort it out when we return after the break.
We started of this week’s session by looking at the recent Soyuz rocket launch which was to send two people to the ISS. During the launch one of the booster rockets failed and the launch had to be aborted. Both crew members, astronaut Nick Hague and cosmonaut Aleksey Ovchinin, escaped without injuries.
Official astronaut portrait of Tyler (Nick) Hague – Blue Flight Suit Picture. Photo Date: January 13, 2014. Location: Building 8, Room 183 – Photo Studio. Photographer: Robert Markowitz
We then continued to work on our pictures and messages for the Mission Zero Challenge. I made a video of some of the work we did, but it’s very hard to film LEDs so the quality is very poor.
If you want to find out more about the Soyuz incident and have another look at how to make pictures and messages with the Sense-hat LEDs my notes are here day 4.
Next Saturday we’ll start looking at Pygame Zero. See you all then.