Tag Archives: Arduino

Arduino Web Server

IMG_0244

Winter break means plenty of time to toy around with something new. I’m not sure what inspired this project, perhaps the ethernet driver we designed for our Operating Systems course, but I’ve decided to explore the field of embedded networking. And you can’t get much more embedded than a 16 MHz Arduino Uno with 32K of memory.

Goals

I want to create an Arduino-based web server, but with a few twists, because the idea already exists and has been implemented. The first link points to Lady Ada’s quick and dirty Arduino file server, which can serve up character-based files stored on micro SD. The second link offers a more functional server called Webduino, which claims to offer image support (ie. binary transfers). However, reading through the code, it looks like the developer took the easy way out by re-encoding a PNG as hex values, and then sending those values byte-by-byte over the network. That’s not image support! Also, both implementations seem to suffer from the limitation that only one client can connect at a time.

Because the Arduino has no formal notion of threads, it would make sense that multiple clients just won’t work. But I’ve been reading up on a project called Protothreads, which adds the most basic threading you can imagine. No separate stacks. No pre-emptive scheduling. Just a way to give the appearance that two computations are concurrent. I’m hoping that I can use protothreading to allow multiple clients to connect.

Additionally, it would be nice to find a way to do binary transfers. Glancing at the EthernetClient and EthernetServer API, it looks like they’re both set up for byte transfers. I wonder if there’s a way I can trick it into sending binary information. We’ll see.

Update – 26 January 2012:

I found an easy way (untested) to get the Arduino to send non-text content over the EthernetClient interface. When a client requests a file of a certain type, say, PNG, you can send a response indicating that you will be sending PNG binary data byte by byte as follows:

I hope to test this technique soon. Admittedly, I still have a long way to go on this project, but other projects (iPhone app, stay tuned) keep arising.

Arduino-controlled Robotic Arm with Android Interface

owi535large

Project hosted on Google Code [LINK].

Continuing my trend of Arduino projects, I decided to toy around with this robotic arm I got for Christmas. The arm is not the best construction, using DC motors instead of servos, but with Adafruit’s motor/stepper/servo shield kit, I think I can make it somewhat more useful.

First to go is the flimsy plastic controller. The motor shield allows up to four of the of five motor joints to be controlled with the Arduino. I want to use this opportunity to explore the Java serial libraries to communicate with the Arduino over the Internet in a Java applet *or* purchase an Arduino ethernet shield and send commands directly to the device (see below).

I suppose, as an overall goal, I would like to be able to feed my fish while away with the use of a webcam and this robotic arm.

Completed Robotic Arm connection to motor

IMAG0138_1 IMAG0135_1

This setup allows control of the maximum of four motors.  I’d rather have everything integrated into one cable, but the supplied cable didn’t have enough pins to handle 4 motors and power and ground.  That’s why I added the red/black leads shown above.  Here’s how everything looks hooked up to the freshly soldered motor shield:

IMAG0140_1

 

Right now the Arduino is powered by USB, and the motors are powered by the arm’s original DC power source — 4 D batteries. This can easily be changed to have the arm run off of a DC adapter.

Next up: Due to the number of pins that the motor shield requires, I won’t be able to use an ethernet shield with this project. So, Java-based serial communication it is!

Update 4/16/11

I wrote a Java application with SWT to handle the serial communication with the Arduino’s motor controller. Essentially, it relays messages over the serial line about what motor to enable. The “speed” of the motor is an illusion by using a custom TimerTask to repeatedly send requests to enable the motor (every 10ms) and then sleep the thread for a duration between each task interval, until the button is no longer pressed. This solution makes the robotic arm much more useful as it can now make very controlled movements (<1mm).

Here is a screen shot of the user interface:

ss

 

Update 9/7/12

I’ve started working on this project again! I decided to clean up some of the code and create an Android app that can control the arm wirelessly (as long as it’s connected to a host PC).

diagram

Project hosted on Google Code [LINK].

Arduino OBD-II Interface

IMAG0131_1

For my CS 497 Spring 2011 course, I worked on an independent study project creating an Arduino-based OBD-II (vehicle onboard diagnostic) interface written in C.

First, I assembled an interface between an Arduino Uno and the ISO9141 bus that most vehicles prior to 2008 use. An open-source project called OBDuino describes how to assemble such an interface, available here. Second, I wrote software for the Arduino to poll information from the vehicle’s engine control unit (ECU), such as instantaneous information like RPM and vehicle speed, and also diagnostic feedback, and display it in real time on an attached LCD screen. Third, I added an Arduino data-logging shield to allow the capturing of long-term data from a vehicle in a spreadsheet-ready format.

Download the presentation I gave on this project.

Download the source code used for this project.

Update – 3/27/11

Since my last progress update, I have written software for the Arduino to:

  • Interface with my automobile’s ISO-9141 bus, and
  • Begin polling for parameter IDs (PIDs)

Before the Arduino can begin polling data from the automobile’s ECU, it must first establish a serial connection. The initialization sequence was adapted from ISO standard 9141-2:1994, available at the Engineering library. Once started, it sends address 0x33 to the ECU at 5-baud to “bit-bang” the ECU and establish a serial connection. The Arduino then switches into normal serial communication at 10.4kbps and waits for a return address of 0x55 from the ECU followed by two keywords. The Arduino sends back the inverse of the second keyword and, upon a response of 0xCC (the inverse of 0x33) from the ECU, the Arduino displays “Init. Success!” on its LCD screen. Initialization usually takes a few seconds to complete, and the connection must be re-initialized if the ECU is not polled for data within 5 seconds.

Screen shot 2011-03-27 at 11.12.07 PM

 

Displayed on the LCD screen above are instantaneous readings from the four PIDs currently polled by the Arduino. Clockwise from the top-left corner, these include:

  • Engine RPM
  • Vehicle speed
  • Mass airflow (MAF) sensor, which can be used to calculate instantaneous MPG
  • Engine coolant temperature

Values update every 200ms on the LCD. Polling for PIDs involves sending a byte-encoded message to the ECU requesting a value for a PID defined in the SAE J1979 standard. The ECU then responds with a byte-encoded value that the Arduino can decode and extract information from to display on screen. Currently, the system only polls for these four PIDs, but will be expanded to poll for several more.

Upcoming Tasks

In addition to adding more PIDs to poll, I will mainly be focusing on implementing a data logger shield to hold data captured by the Arduino and display in spreadsheet form on a computer.

The data logger shield sits on top of the Arduino unit, and uses pins not used by the LCD or serial communication. The shield also contains a real-time clock to add a timestamp next to data read from the ECU. Data is stored on a 2GB SD card.

droppedImage

 

The ability to log large amounts of data from a vehicle demonstrates the usefulness for this system to offer diagnostic capabilities with a high degree of precision and temporal resolution. Implementing and programming this data logger shield, as well as graphically displaying spreadsheet data, should consume the remainder of the time allotted for myproject.

Update – 4/12/11

I’ve added the data logging shield and a way to compute MPG from the MAF (mass air flow) and VSS (vehicle speed sensor) PIDs.

Here are some Excel graphs plotted from data over a 20 minute period (844 data points). Click for larger graphs.

speedxrpm_1

coolantxspeed_1