All posts by admin

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

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.

Python with Arduino Lesson 14: Introduction to Xbee Radios and Wireless Communication

In the video lesson above, we introduce our next series of lessons, which will step you through using Xbee radios to allow your arduino projects to wirelessly communicate with your PC. The good news is that you already know how to communicate between your Arduino and the PC over the serial cable based on our previous lessons. Using Xbee radios is very similar, you just remove the cable. You are still communicating over the serial ports, so the coding remains virtually unchanged . . . you just have to configure and connect the radios. In order to do these lessons, you will need a pair of Series 1 (S1) Xbee Radios (you will need two). If you want longer range, and are willing to pay more, you can get the Seris 1 (S1) Xbee Pro Radios.

To program the radios, you will need a SparkFun USB Explorer.

The final equipment you need will be an Xbee Shield. The shield allows you to plug the Xbee radio into the Arduino.

LESSON 27: Instrument Package

In this lesson we bring together a lot of the material from the first 26 lessons to create an instrument package that could be deployed in a demonstration project. We will wire wrap up an Arduino Nano, a Virtuabotix SD card reader, and the Adafruit Ultimate GPS to create a system that will track and log position and altitude, and save the data in a format that can be displayed on Google Earth.

Wire Wrapping tools and Perforated Board

You will want to place the Adafruit GPS, the SD Card Reader, and the Arduino Nano into a perf board.  Then, you will want to carefully wire wrap the components as follows:

Connecting the Adafruit Ultimate GPS Unit to Arduino
GPS Pin Arduino Pin
Vin 5V
GND GND
RX Pin 2
TX Pin 3

 

Connecting the SD Card Reader
Sd Card Reader Pin Arduino Pin Details
GND GND Common Ground
3.3 V – (NOT USED)
+5 5V Power
CS 4 Chip Select
MOSI 11 SPI Data
SCK 13 Clock
MISO 12 SPI Data
GND GND Common Ground

 

Now the code you developed in LESSON 26 should run on this prototype. The code creates a Google Earth friendly set of coordinates. Just put a KML wrapper on the coordinates as described in LESSON 26.  Putting it all together, I took the system outside and walked around, and this is the data track I got.

GPS track generated by my wire wrapped prototype

 

LESSON 26: Wire Wrapping

The neat thing about using breadboards and jumper wires to build a circuit is that it is a quick and easy way to get your prototype up and working. It is an excellent way to get your circuit and code debugged. The wires are very easy to connect by just plugging them into the holes. the downside is, those wires come out just as easily as they went in.

Breadboard Prototype Wires are Not Securely Connected

The breadboard prototype is great for getting your prototype going, but to use in a real project like a robot, unmanned aerial drone, or high altitude balloon, you will need a more secure way to connect your circuit up. Typically the next step for commercial products would be to order a custom PC board, and then solder the components into the board. This is a great way to go, but there are some pretty large barriers to doing this. There is a fairly steep learning curve to the board design software. The second issue is that even for simple projects the minimum order is usually around $100. Once you order the board you really can not tweak or make changes to your design. Also, you typically solder the components into the board, so you can not take it apart and use your components in other projects.

Wire Wrapping Tool and Wire

Luckily, there is a good options for students working with a limited budget. It is an almost lost art form known as Wire Wrapping. To make a robust circuit suitable for deployment in real projects, you need a minimum of equipment, and it is very easy to learn.

In order to get started, you will need a few things. You will need a good Wire Wrapping Tool,  30 AWG Wrapping Wire,  and some Prototyping Boards.

Once you have your gear, the rest is pretty simple.  Measure out the length of wire you need, leaving excess on each end for the “wrap”. I like to use about 1 inc of wire for a wrap. Hence, I would leave 1 inch extra on each end, or two inches total extra for each wire. Then strip about 1 inch of wire off each end. Insert the wire into the small hole or indention in the wire wrap tool. Place the tool over the post or pin you want to wire wrap, and gently rotate the tool clockwise until the wire is wrapped around the post. Simple as that. The video above shows you just how to use it.