Tag Archives: Arduino

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 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.

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
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 PinArduino Pin
Vin5V
GNDGND
RXPin 2
TXPin 3

 

Connecting the SD Card Reader
Sd Card Reader PinArduino PinDetails
GNDGNDCommon Ground
3.3 V – (NOT USED)
+55VPower
CS4Chip Select
MOSI11SPI Data
SCK13Clock
MISO12SPI Data
GNDGNDCommon 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
GPS track generated by my wire wrapped prototype

 

LESSON 23: Arduino GPS with Data Logger

In this lesson we will extend what we did in lesson 22 to include a data logger with our GPS. You should be sure and do lesson 22 first, as that shows you how to hook up and program the GPS. In this project we will connect an SD Card Reader/Writer, and will power the whole thing with a 9 Volt battery. With this, you can walk around, and the device will constantly monitor and log your position. You can then bring it back inside, and look at where you have been using Google Earth.

GPS Data Logger
Arduino connected to Adafruit ultimate GPS and a n SD card Data Logger

To start with, lets talk about what you will need to do this project. As described earlier, you need to start by doing lesson 22 which will get you going on the GPS hookup and initial software. Now, to move forward, you will need an Arduino, Adafruit Ultimate GPS, Virtuabotix SD card reader, and a Battery Clip to power the arduino during your mobile jaunts.  You will need a 9V battery. If you are going to be doing a lot of mobile work, it is probably worth it to invest in a good 9v Rechargable battery system.

When you get your gear gathered up, you will be ready to get this project going. First, hook the GPS up to the arduino as we did in lesson 22:

Connecting the Adafruit Ultimate GPS Unit to Arduino
GPS PinArduino Pin
Vin5V
GNDGND
RXPin 2
TXPin 3

You also need to hook up the SC Card Reader/Writer. You should be familiar with this from lesson 21.

Connecting the SD Card Reader
Sd Card Reader PinArduino PinDetails
GNDGNDCommon Ground
3.3 V – (NOT USED)
+55VPower
CS4Chip Select
MOSI11SPI Data
SCK13Clock
MISO12SPI Data
GNDGNDCommon Ground

Remember that this SD card reader has two rows of pins. Don’t let that confuse you, both rows are equivalent. You can connect to either row.

Most of the code has already been written in Lesson  22. In this lesson, the main thing we will be doing is to write the GPS data to the SD card. This way, as we walk around outside, it will log our positions to the SD card.  We will create two files. One will hold the raw NMEA sentences, and the other our location data, as parsed by the adafruit GPS library. You should be able to figure most of this out from what you already know from lesson 22 and lesson 21. In the video above, we take you through this code step-by-step, so watch the video to understand what we are doing. If you get stuck, you can look at the code below.

 

LESSON 22: Build an Arduino GPS Tracker

OK, it is time for us to take our projects up to that next level. We are going to build a GPS tracker from scratch. This is going to take several lessons to complete, but it will build on what you already know, and is really not going to be that difficult of a project. We will be using the most excellent Adafruit Ultimate GPS module. This is an excellent GPS. I like it because it is affordable, easy to use, and is one of the few that will work at extreme elevations, making it ideal for our Edge of Space/High Altitude Balloon work.

Arduino GPS
We are using the Adafruit Ultimate GPS

This unit is pretty easy to hook up, as you can see in the Table below:

Connecting the Adafruit Ultimate GPS Unit to Arduino
GPS PinArduino Pin
Vin5V
GNDGND
RXPin 2
TXPin 3

Our goal in this lesson is to get the GPS connected, and get it reading NMEA sentences. NMEA is a data format used by GPS and mapping devices and software to keep track of position coordinates. There are lots of different NMEA sentences, but the two that contain the most useful information are the $GPRMC and $GPGGA sentences.

Our interest is in creating a location tracker for our High Altitude Balloon work, and the $GPRMC and $GPGGA sentences contain all the information and data we would need for that work. These sentences contain the lattitude, longitude, time, altitude, and velocity.

The GPS modules are pretty easy to work with. When you apply power to the GPS, it immediately starts spitting out NMEA sentences to its serial port. Our job on the arduino side is to simply read these data strings, and then parse them into useful data. The thing that is a challenge is that they constantly spit out data, whether you want it, or whether you are ready for it or not. In developing the software, we have to be mindful the the data is always spewing out of the GPS. Typically, we will have other components on our package, like temperature, pressure and inertial sensors. While our arduino is out making measurements on these other sensors, data continues to stream in from the GPS, likely overflowing our serial buffer. When we return to make a GPS measurement, it is very likely that the serial buffer will have old or corrupt GPS data in it. Hence,  we must be mindful to deal with this issue in developing our software.

The video above takes you step-by-step through connecting and reading the NMEA sentences step-by-step. Then in the next lesson we will parse and log the data to create a portable GPS tracker. The code below is explained in the video. You need to watch the video to understand this code, and so you will be able to begin to work with this code to create a portable GPS tracker.

In order for this software to work, you need to download and install the Adafruit GPS Library.