expr:class='"loading" + data:blog.mobileClass'>

Tuesday, October 9, 2012

Arduino controller


This project is based on Arduino Platform.
This current project implements a software architecture which eases the Arduino related peripheral operations such as Analog out(pwm), digital read/write and analog read operations. The core of the project is implemented in “trans_layer.cpp”. The central object in this project is “TransLayer” which has following methods:
TransLayer ()(constructor)
AddService()
SeeServices()
LookForService()
MainLoop()

Services here I am referring to are actually functions that accomplish certain task such as turning on an LED or reading Analog voltage at a given pin. The list of services are maintained within a linked list. The construct in this project (TransLayer()) initializes the head and tail pointers for the linked list. The linked list is list of data object of type service_list whose deceleration is:

struct service_list /**< Struct for holding service list */
{
call_back_ptr service_function; /**< call back function pointer */
char service_flag; /**< Packet service flag for which this service responds*/ service_ptr next_service;
};

call_back_ptr is the function pointer to the call back function. The service_flag is a char which uniquely represents the service. To add a service, AddService() should be used. It accepts a function pointer, to be used as call back function when the character which corresponds to the second argument to this function is received.


All the packets start with character 'S' followed by, the character which represents the given service. This is followed by any extra data required by the service. The generic structure of the packet is:

 

In the MainLoop() method, within an infinite loop, the incoming packets are examined. As soon as character 'S' is received, the next character in the packet is examined and if a match is found, the corresponding call back function is executed. These functions extract their input arguments from the input buffer and perform the required action.
On host side, to ease things, I have developed a Python script to transmit commands and receive responses from the Arduino. This script requires wx python and py serial to be installed on your system. The GUI was designed using visual wx tool.There are few bug fixes and more improvements required. I plan to fix bugs and make improvements shortly.

Some screen shots:
 


 
The central part of the application is 'TransLayer' object which has various methods that forms packets and transmits them over the serial port. It also has methods which receive incoming data over serial port and parse the response coming from Arduino and pass it to the upper layer.

Note: You need to specify serial port name in "ser.cfg" file as the first string. 

Download Arduino code
Download Python code

P.S: Improved GUI app here

No comments:

Post a Comment