A Python script to run the Arduino MiniPirate Sketch

A while back I wrote about the BusPirate. You can view that post here. In it, I mention an Arduino sketch called the “MiniPirate” which allows you  to try some of the functions of the BusPirate on an Arduino.

Over time, I have found that sketch to be very useful. You can use it to test/debug and prototype different electronic components. Even more than that, it is fun and an easy way to engage students to interact with the world around them.

Always have an Arduino around with the sketch loaded in so it will be as handy as the BusPirate. Then just plug it into your PC USB port and you are ready to go. No need to load up the Arduino IDE as I have a handy Python script (shown below) to interact with the sketch.

A Linux Python script to run the Arduino MiniPirate Sketch:

The Python script uses non-blocking console I/O to interact with the user. It needs the PySerial package which can be found here in case your Python install does not have it.

The MiniPirate sketch can be downloaded from here. Instructions on its use can be found here. Any questions? Leave a comment.

Arduino Leonardo WEB Server to Display Temperature and Humidity

In a previous post titled Arduino Leonardo and SPI Communications, I documented how to connect the Arduino Leonardo to the ENC28J60 Ethernet module. This post takes things a bit further and adds a DHT22 Sensor. The Arduino Leonardo is used as a WEB Server to Display Temperature and Humidity information from the DHT22 sensor.

The UIPEternet library is used to create a WEB server at IP Address 192.168.2.77 (which needs changed to whatever address would be appropriate for your LAN). The DHT library is used to communicate with the DHT22 sensor.

Here is the wiring graphic:

Leonardo  Enc28j60 DHT22You can get the Fritzing.org code to create that image here. When you visit the WEB page in a browser, here is what the page looks like:

 

DHT22 WEB Sample InformationHere is the DHT22_ENC28J60_WEB.ino source code to make it all happen:

Arduino Leonardo and SPI Communications

I just found out that my favorite Arduino of choice (the Leonardo) has a problem with SPI  “Serial Peripheral Interface” communications (if you need to use the SS pin).  For SPI (which is bidirectional) , the following pins are normally used:

  • SS – Slave Select – digital 10. You can use other digital pins, but 10 is generally the default as it is next to the other SPI pins (except for on the Leonardo)
  • MOSI  – Master Out / Slave In – digital 11;
  • MISO – Master In / Slave Out  – digital 12;
  • SCK – Serial Clock – digital 13;

Unlike the Arduino Uno, the Leonardo has those pins on the ICSP (In-Circuit Serial Programming) header except for the SS pin which is not available. I found that out when I tried to get my Leonardo to communicate with an ENC28J60 ethernet module. (See my earlier article on connecting an Arduino to a LAN via an ENC28J60 module. The Arduino is the master and the module is the slave.) To make the Arduino Leonardo and SPI communications work,I had to modify the library code to use a pin other than the Leornardo SS default. Here is the wiring diagram:

Leonardo ENC28J60

Arduino Leonardo SPI -> ENC28J60 (click to enlarge)

If you prefer my Fritzing.org source code from which this graphic was created, you can get it HERE. I use the UIPEthernet library for the ENC28J60 module. To make it work for the Leonardo, I changed the Enc28J60Network.h file in the utility directory. Find this line:

#define ENC28J60_CONTROL_CS     SS

and change it to this:

#define ENC28J60_CONTROL_CS     10

The only problem with modifying the library is that you will need to remember to always use pin 10 for SS if that is not already the default (when setting up SPI for other Arduinos). Here is a good article on connecting arduinos using SPI for your further research.

Nuqleo Zinq 7 Rooted for more flexible useage

I recently acquired a Nuqleo Zinc 7 Android Tablet. It looks like this:

Nuqleo Zinq 7I couldn’t resist 🙄 as it was such a good price. It comes with an OTG cable and works great to attach and host your Arduino(s).  Also, a tablet such as this one makes apps easier to use (i.e. to see) as a tablet has a larger screen area versus a phone.

In a previous article (HERE) I mention some useful Android apps to interface with your Arduino(s). There are also a number of things (i.e. commands / programs) that can be run from the command line if your Android device is ‘rooted‘. Being a Linux user from way way back, I like the flexibility to see what is going on and run various commands that are part of BusyBox. BusyBox combines tiny versions of many common UNIX/Linux utilities into a single small executable.

There are many methods (programs and scripts) around which take advantage of exploits to gain root (or super user) privileges. Some require your Android device to be hooked up via USB to another computer running Windows. Others (much simpler) are apps (apk files) which run directly on your android device.

Fortunately I found an apk that rooted my Zinq 7 quite easily called Baidu Root. I installed it and then installed the SuperSU apk to grant access rights to other programs and  Shell Terminal Emulator to access the command line. If you want an updated version of BusyBox, I suggest installing this BusyBox apk.

Controlling an Arduino from an Android Phone or Tablet

Question: What do you get when you connect your Android Phone or Tablet with a USB-OTG cable and connect that into another USB cable connected to an Arduino?

Android to Arduino

Connect an Android Device to an Arduino

 

Answer: A easy way to program and/or control your Arduino. This is a handy way to control (and/or re-program) your Arduinos in the field where it might be too inconvenient to use a laptop PC. The USB OTG cable tells the Android device to be the host and so the Arduino will be powered by the phone or tablet. Make sure your Android device is fully charged because this can drain the battery quickly. Also, make sure your Android device supports a USB OTG cable, not all do.

There are a number of Android apps that were created for both Electronics  and MicroControllers such as the PICs and Arduinos.

Here is a list of my favorite apps:

Electronics:   ElectroDroid  EveryCircuit  Electronics Toolkit

AVR: AVR Atmega Database

PIC:  PICmicro Database

Arduino:  ArduinoDroid   Arduino Examples    Arduino Companion   Arduino Commander   Arduino Libraries   Arduino Cheat Sheet

These apps are quite handy when you are ‘in the field’ and working on a project.  Note: the Arduino DUE has a USB host port, so you can plug your android phone or tablet directly into it, however the above mentioned apps only support the older IDE, they do not support the DUE.

ESP8266 Wi-Fi Module Revisited

A while back I posted some information about the ESP8266 Wi-Fi Module. You can view that post here. I mentioned that for testing it, an Arduino with multiple hardware serial ports would be ideal. Well, I just got an Arduino Leonardo which matches that criteria.

Here is how I hooked it up:

 

ESP8266 Fritzing Diagramyou can get the Fritzing file here. (The Fritzing part for the ESP8266 can be found here.)  Notice that the TX and RX serial connections ‘crossover’. Not crossing over is a common mistake when first hooking up a serial communications device.

The Arduino sketch I used was chosen via

Examples->04.Communication->MultiSerialMega

 

You only need to change the serial BAUD rate for Serial1 (the ESP8266) from the default of 9600 to 115200. Once you upload the sketch to the Arduino, run the serial monitor and the commands you type will be sent to the ESP8266. Any response from the ESP8266 will be ‘echoed’ in the serial monitor.

Testing the ESP8266 on an Arduino with two hardware serial ports is much easier than my original way. Now I can add sensors to this circuit and send the information they gather through the ESP8266 to the WEB.

 

UPDATE: 12/29/2014

 

I ran into a common problem with the ESP8266. Sometimes the ESP8266 will return ‘busy’ when you enter a command. The ESP8266 is essentially locked up (i.e. frozen) at this point. To recover you can power off the device and power back on. However that is not a programatic solution. Fortunately there is a way to ‘RESET’ the ESP8266 from code if this situation occurs.

 

Here is how to wire the ESP8266:

 

ESP8266 Reset Circuit

 

 

 

 

 

 

You can download the Fritzing diagram source here.

 

Here is a sketch showing the Reset function.

 

 

 

Explaindio Video Creator

You may not think this post has a lot to do with MicroController Electronics, however, read on before you formulate an opinion.

There is a new Windows and Mac Video Creator program called Eplaindio that recently became available. I am using it to create training, educational and advertising videos for various projects. It is very powerful yet simple to use.

Basically you can take images, SVG graphics, video backgrounds, optional audio files and create scenes which you put together in sequences to make a video. Additionally, slides created in Adobe Flash can be imported to provide additional animation like capabilities.

I made a sample demo video to demonstrate its potential use (especially in electronics)  which you can view below.

All of the electronic SVG images in the sample demo are from fritzing.org. I took those (~6,500) SVG files (which are distributed under the Creative Commons license) and put them into folders and then created a PNG image for each SVG. (The PNGs are used by Explaindio to present a view of the SVG for selection / inclusion into a ‘sketch’.)  I used Inkscape in non-gui batch mode (-z)  to take the SVGs and save them as  PNG images.  (You can download the python script I used to do that HERE.) Contact me if you want a copy of the Fritzing.org electronics SVG/PNG library for use with Explaindio.

If you are interested in that library you might also be interested in the (~8000) SVG graphic files from OpenClipart.org.The SVGs from there can be freely used commercially. I converted them also into folders (with PNGs) for use in Explaindio. Contact me if you want a copy of that library.

It is interesting to note that the Explaindio project files ([.explaindio] used to create the videos) are XML like. That opens possibilities to generate them ‘programatically’.  For example, when I browse through an SVG library looking for ideas or specific images that I need, I can drag/drop them into a folder with my project/scene creator script (add optional text files for adding text slides) and when done, click on the creator script for it to create the project and/or scenes. It saves me a bit of time. Contact me if you are interested in it. (You’ll need to download and install Python in order to use it.)

All in all, I think Explaindio can be taken advantage of to teach Electronics (and other things).

What do you think? Leave a comment and buy your copy of Explaindio here.

 

Prototyping Circuits using a Breadboard

When I first heard the term ‘breadboard’ when reading about electronic circuits, I thought about bread of course and some great bread making recipes. I must have been hungry!

For electronic recipes 🙄 (i.e. circuits), originally a smooth piece of wood (literally a breadboard with nails and wiring) was used as a surface for assembling/wiring  electronic components. We still use the term breadboard today although the synonym protoboard  is also used.

The breadboard of today is reusable and does not use solder which makes it a good experimental tool to prototype circuits. It consists of a perforated block of plastic with numerous metal spring clips under the holes and comes in various colors and sizes (i.e. number of holes):

BreadBoard_170_red BreadBoard_170_green BreadBoard_170_blue

 

 

 

 

BreadBoard

BreadBoard

 

My favorite one is transparent so you can see the spring clips. It has 400 holes and looks like this:

BreadBoard

On this breadboard there are two identical sides separated by the middle notch. Each side has 200 holes ( each divided into two ‘strips’). One strip is called the terminal strip and the other is called a bus strip (which contains two columns:  one for ground – and one for a supply voltage +.)  The clips on the right and left of the middle notch are each connected in a radial way;  five clips (i.e., beneath five holes) in a row on each side of the notch are electrically connected. On the bus strip the whole row (+ or -) is electrically connected.

Breadboards usually have an adhesive backing and can be interlocked for larger projects. The spacing between the holes is typically 0.1 in (2.54 mm). Integrated circuits (ICs) in dual in-line packages (DIPs) can be inserted to straddle the centerline/notch of the block. Interconnecting wires and the leads of components (such as capacitors, resistors, and inductors) can be inserted into the remaining free holes to complete the circuit. Connecting wire should be 22 AWG (0.33 mm2) solid copper. If you have any CAT5 cable around, that is perfect.

Cat5_Cable

Just cut to the length you need unravel the wire  and straighten it out. The wire ends should be stripped 316 to 516 in (4.8 to 7.9 mm).

Arduino Weather Station

With just a few sensors, one can determine a lot about the weather.

 

BMP085 Barometric Sensor

BMP085

DHT11 Humidity and Temperature Sensor

DHT11

 

 

 

 

 

 

 

 

The BMP085 can be used to sense barometric pressure and temperature and the DHT11 can be used to sense humidity and also temperature.

Here is what they look like attached to a mini breadboard:

Weather_Station

Arudino Breadboard Weather Station

An FTDI cable (not shown in the above image) can be plugged in at the top left of the breadboard to power this circuit and collect the data.

To collect data in an arduino sketch. the DHT library and the Wire Library will be needed. Both of which are included in the Aruduino IDE.

Here is the arduino sketch (code) to display barometric pressure, humidity and temperature (from both devices) :

 

 

 

HC-SR04 Distance Sensing

Animals such as bats and porpoises use ultrasound for locating prey and obstacles.  If you have an electronic device that needs to sense distances from objects (like a robot or an automatic door opener) you might consider using an HC-SR04 Sensor Module.

HC-SR04 Ultrasonic Sensor

HC-SR04

No one can sneak up on you with a couple of these and a buzzer attached to your favorite Arduino board. 🙄

The HC-SR04 module sends out an ultrasonic ‘PING’ and then detects its return after ‘bouncing off’ something in the distance. By measuring the round trip time (and knowing the speed that sound travels), a calculation can be made to determine the distance of the object from the HC-SR04.

Here is a public domain Ardunio sketch (the comments show the math involved to calculate the distances, they also show how the HC-SR04 is wired):

 

Load more