Tag Archives: High School Science

Raspberry Pi Linux Lesson 2: Getting Started and Installing Operating System

In LESSON 1 we described the gear you would need to work with the Raspberry Pi. At this point you should have the equipment in and be ready to go. In this lesson we will show you how to get your pi up and running. The first thing you are going to need to do is to format your SD card. Please note that you SHOULD NOT use the standard windows formatting routine. You need to download the SD association card formater. You can get the latest version HERE. At the bottom of the page accept the terms, and the download should begin.  After downloading, click the file and installation should begin. After installation, the program can be used to properly format your SD card.

After you have formatted your card, the next thing is to download the operating system for the pi. The easiest way to get started is to download the NOOBS system HERE.  You can select the Download Zip link. After downloading the file, open the zip folder and remover the contents from the zip folder. You can put the contents into another normal folder that you name “NOOBS”. After you have extracted the contents from the ZIP folder onto the NOOBS folder, you are ready to move it to the SD card. You want to copy the CONTENTS of the NOOBS folder to your SD card. Do not copy the NOOBS folder itself to the SD card, just the contents.

You are now ready to boot your Pi. First, plug the SD card into your Raspberry Pi. Now connect a keyboard to a USB port, and then connect a mouse to a USB port. You can also connect an Ethernet cable if you like. The last thing to connect is the power. Note that you must be careful to NEVER remove the SD card while the Pi is powered up. This will corrupt the card. You should always properly shutdown the pi with Linux command “sudo shutdown” before removing power from the Raspberry pi. It is fairly easy to corrupt the SD card if you are not careful.

When you see the pi come to life, you will be asked what to install. Choose the Raspbian operating system, and then click install. It will take about an hour for it to install the operating system.  After the installation is complete, it will offer you a menu of options on configuring the pi. For these lessons, we are going to use the Linux terminal to control the pi and learn Linux. We will go through the graphical user interface in later lessons, but for now we are going to learn Linux

Raspberry Pi Linux LESSON 1: Introduction to the Pi

If you have followed us through our series of lessons on the Arduino, and then the lessons on using Arduino with Python you have already learned some really cool stuff. You have probably learned so much, in fact, that you are starting to contemplate projects that will stretch the resources available on the arduino. For example, if you decided to add an LCD display to our GPS tracker project, you would probably find that you had run out of memory on the Arduino.

So while we all love, and will continue to love, the Arduino, you do finally reach the point you need a microcontroller with a little more horsepower. This is where the Raspberry Pi comes in. The raspberry pi is about the same size as the arduino, but it has the power of a desktop computer. With the Raspberry Pi, you still have direct access to ports and pins to build your own custom projects, but you have the speed, memory and CPU needed for much more sophisticated projects. The Raspberry Pi runs Linux, which we will have to learn in these lessons. The good news is that when we get the Pi up and running you can write and run python programs on it, and we have already spent quiet a bit of time learning python. So, with your background in Arduino and Python, you will be up and running on the Pi in no time.

To start with you will need to get your gear together. I definitely recommend the Raspberry Pi model 2, as it is the latest and greatest at the time this lesson is being made. You will need the Pi, a power supply, a micro SD card, and a monitor cable. You will also need a monitor, keyboard and mouse, but you probably already have those things laying around. I have found that the best thing is to buy a kit that includes the pi, power supply, micro SD card, monitor cable and USB WIFI adapter. A kit I really like that I think is an excellent value can be found HERE.  Please note that this kit (and most all kits) contain an HDMI to HDMI cable. The output of the Raspberry Pi is HDMI. However, many monitors to not have an HDMI input but want a DVI connector. If your monitor only has DVI input, you will need an additional cable, which you can find HERE. For most people, getting the kit and the cable will be all you need to get started.

If you only have a really old monitor with a VGA input, please note that the HDMI to VGA cables available on amazon do not work. (At least all that I have tried to not work). It is not just a matter of getting  a cable with the right connectors on the end. You have to convert HDMI to analog, which the cable does not do. For the case of making the Pi work with a VGA monitor, I have found the Belkin HDMI to VGA adapter will work with the Pi and you can get it HERE.

Please note that I have found the trickiest part of getting the Pi up and running is getting the right cable for your monitor. Please carefully check what type of monitor you have, and get the right cable.

So, get your gear ordered and in the next lesson we will cover how to get things hooked up and configured.

Python with Arduino LESSON 17: Sending and Receiving Data Over Ethernet

Arduino Ethernet
This circuit contains an Arduino Nano and Pressure Sensor Communicating over Ethernet

In LESSON 16 we showed a simple Client Server model that allows us to send strings between Python running on a PC and the arduino over Ethernet. That lesson simply passed strings back and forth to show a very basic Server on Arduino, and Python acting as the Client. In this lesson we show a more practical example, with the Arduino connected to an Adafruit BMP180 Pressure Sensor. In order to complete this lesson, you will need an Arduino, an Ethernet Shield, and the Pressure Sensor. If you do not have this particular pressure sensor, you can probably follow along in the lesson using whatever sensor you have that is of interest. The video will take you through the tutorial step-by-step, and then the code we developed is shown below.

The key issue in getting this project to work is to get your mac address and IP address from your router or network. If you are at school, simply speak to your network administrator, and he will help you get an IP address for your arduino. If you are at home, you will need to connect to your router from a browser, and configure it to assign an IP address and agree on a mac address for your arduino. Some arduino Ethernet shields have a sticker with a mac address. If your Ethernet shield has a sticker with mac address, use that one. If it does not, you will need to come up with a unique mac address. There are thousands of possible routers and networks out there, so I can not help you with that part. But if you look in the router documentation, you should be able to get the IP address and mac address worked out. The arduino itself does not have a hard wired mac address, but you set the mac address in the arduino software, and the IP address as well. The key thing is that the mac address is unique on your network, and the router and arduino agree on the IP address and mac address. If you have a clearer way to explain this, please leave a comment below.

This is the server side software to run on the arduino. Again, you should use a suitable IP address and mac address for your network. Do not think you can just copy the ones I use in the code below.

Once you have this on your arduino, and the arduino connected to the internet via an Ethernet cable, you can test by opening a command line in Windows. Then ping the address you have assigned to the Arduino. If it pings correctly and you get a reply, you are ready to develop the Python code. The Python will be the client. It will send the requests to the Arduino, and the Arduino will respond with data. Since our circuit can measure pressure or temperature, you can request either of those. When the arduino receives a request for temperature, it will go out, make the temperature measurement and then return the data to Python. Similarly, if you request Pressure the arduino will read the request, will make the Pressure measurement, and then return pressure reading to the client (Python).

 This python code will request Temperature, will then read the response, and then will print the data. It then requests Pressure, reads the response, and then prints it. If you look at our earlier lessons you can see graphical techniques to visually present the data. The hard part is getting the data passed back and forth, which we show how to do in this lesson.

Python with Arduino LESSON 16: Simple Client Server Configuration over Ethernet

Arduino and Ethernet Shield
Ethernet Shields are available which allow the arduino to act as a server

In the previous lessons we have seen that powerful analytic and graphic programs can be written that allow data taken from the arduino to be displayed on a PC via Python. We have shown how the arduino can be connected to a PC by either a serial cable or Xbee radios. To fully unleash the power of the arduino, it can be set up as a server, and connected to a network via Ethernet. In this lesson, we will show how to set the arduino up as a server which is controlled and queried by clients on PC’s on the same network. In order to complete this tutorial, you will need an Arduino Uno and an Ethernet shield. The Ethernet Shield is a relatively expensive component, but I suggest getting an authentic arduino made shield, as I have had poor results from the cheap knock offs. Understand that this lesson is intended for High School students to show them a simple technique for connecting the arduino to a network. It is not an exhaustive treatise on Ethernet communication. The goal is to provide a simple protocol which should allow you to get your arduino talking over Ethernet. It requires that you already know, or can figure out how to assign a mac address and IP address in your router. Some arduino Ethernet shields have a sticker with a mac address. If your Ethernet shield has a sticker with mac address, use that one. If it does not, you will need to come up with a unique mac address. If you are at school, the network administrator can help you get the router configured. I can not provide support in getting this to work on your network, as there are many variables. The techniques provided in this tutorial should work for most networks. This tutorial does not present the most efficient or elegant solution, but the goal is a simple protocol for people just getting started. The video below gives a step-by-step demonstration of setting up the arduino as a server, and Python on a PC as the client. It uses UDP protocol to transfer data packets.

In order to get the arduino to work over Ethernet, you must first assign an IP address to the arduino in your router.  If you just plug the arduino with shield into the network, your router might assign an IP and report a mac address. If this is the case, you need to have the router assign those addresses permanently to the arduino. The bottom line is that the IP address and mac address you identify in the arduino code must match the IP address and mac address assigned in the router. I can not provide any additional help on that issue as there are so many different possible networks. You have to figure out how to do that.

Once you have the IP address and mac address sorted out, you will need to set up the arduino as a server. The video above explains how to do this, and results in this code. Note that your IP address and mac address must be set to a suitable configuration for your router and network. The numbers I use in this code would not work for your network.

This is the code developed in the video to set the arduino up:

Once you have this code in your arduino, ping the IP address of the arduino from your PC cmd line. Make sure your PC can talk to the arduino by successfully pinging it. If you get an error while you are trying to ping the arduino, you will have to stop and get figured out what is wrong. There is no reason to proceed with the lesson until you can successfully ping the arduino.

Once you can ping the arduino, you are ready to set up a client in Python. The code below is what we developed in the video. You will need to watch the video in order to understand the code. Also note, that the IP address in the code below is the IP address of the Arduino, NOT the PC. You should set this to whatever IP address is of YOUR arduino.

 Again, this is a bit of a tricky thing to set up, but if you get the PC successfully pinging the arduino, everything else should be straightforward.

Python with Arduino LESSON 15: Configuring and Using the Xbee Radios

This lesson describes how to program the Xbee Series 1 radios. It will work with either the standard Series 1 (S1) or the Series 1 Pro models. The Pro radios are higher power and will give greater range, but they cost more. The radios are configured using X-CTU software, which can be downloaded here.  The video gives step by step instructions on how to configure and use the radios to communicate wirelessly over the serial port. Lesson 14 gives information on the hardware needed. Lessons 1-13 sill show you how to communicate between Python and Arduino if you need to get caught up on basic serial communication and interfacing arduino and python. The techniques provided in the video above, however, should work for just about any arduino project where you want to communicate between two arduinos, an arduino and PC, or between two PCs.