Physical Hardware Abstraction Layer

The Physical Hardware Abstraction Layer(PHAL) is built so an end user should never have to read the source. It provides a simple human readable serial format to communicate with. It's built on the Romeo, an Arduino based platform, and it should work with any Arduino without much extra work(Romeo has a H-bridge built in).

It currently provides a simple query syntax to access digital, analog, and I2C ports.

How to install

First off download the Arduino sketch here and save it somewhere on your computer.

Next you will need the Arduino software here. On Windows this doesn't require an install, just unzip it somewhere to use. Open the folder and open the Arduino IDE.

The Arduino IDE
Open PHAL in the IDE. Verify/Compile the code then can upload it. Before you upload it you will need to set the COM/tty port that your Arduino is hooked to(hook up the Arduino to see what it registers as). With everything ready hit the upload button and wait some time. Once done you shouldn't need to ever do this again as the code won't go anywhere. When updates come out or you want to play in the source you will need to re upload code after any changes.
Features in the wind:

Syntax to play

Currently PHAL talks at 9600 baud, 8 bits, 1 stopbit, and no parity. Aside from I2C any request to the Arduino returns some value. I2C is a bit special as you can ask each device for information and can also command devices to do actions built into them. The Atmel chip that powers Arduino calls its implementation of I2C TWI(Two Wire Interface).

Once you're connected then it's time to ask for stuff. Simple talking format follows, example leading the way..


The above example asks for the state of the 2nd digital pin(0th based). The 2nd digital pin is actually the third digital port on the Arduino; will get to that later.

The letter starting the string is stating we want digital. Number is what port to ask, and the semicolon is the terminating character required after anything sent and received.

The above code returns a string like..


The "D1" and ";" means the same as above. The colon separates the value from the tag, the 1 in this case the returned value.
All the queries work this way, sans motors and servos(not implemented yet). The 'D' in this case is had from "digital"'s first letter. The other four follow the same pattern. I2C is 'I', analog 'A', motor 'M', and servo 'S'. It's also case sensitive, so capitals matter. Pins used for I2C, Digital, and Analog


Mentioned earlier was that digital pins didn't match up to actual pins. This is caused by other things needing various pins. The mapping is listed below.

user facing actual pin
0 2
1 3
2 8
3 11
4 12

Analog maps perfectly, but only allows you to use 0 - 3 as 4 and 5 are needed for I2C. I2C can handle more then 100 devices and its number scheme is a bit different from analog and digital.


Analog values are gotten from the 10bit ADC built into the Arduino. Where the digital will return 0 or 1, analog can return 0 to 1023.


I2C is the odd duck out on this board. Again some examples to explain..


The "I224" should look similar to how digital and analog are talked to. 224 is the address of the SRF02, a ultra sonic ping sensor, and it's given in the documentation for that device, found here.

Each I2C device has some address set at the factory. Some allow this to be changed if needed. The docs for a device will have this information.

The address isn't the only thing needed, as I2C is built to run off a register based system where a master device requests the contents from a register and then waits for the line to provide them. The registers can also be used to send commands to the slave. The ping sensor can take commands by writing some byte to the 0th register for example.

Following the address is a colon. The colon separates command strings. In the examples "c,0,80" and "s,2,2" are commands to tell the Arduino what to send the I2C slave device. The first character is a defined command followed by a comma delimited set of numbers that are arguments to the command and what is sent to the slave. All the number are decimal. The command characters currently active are as below:

command arguments description
c 0 Send a command, doesn't return anything
r 0 Ask for a single byte
s 1 Ask for arg1 bytes.

The arguments are the number of numbers that are taken off the comma separated list to fulfill some internal duties and aren't sent to the slave. For example "s,2,2" requests "2" bytes after sending it 2.
Later I want to allow command chaining; example..


Like above each colon separated item is a command. The 'w' is a to be implemented 'wait' command taking the milliseconds to spin as some devices need time to let physical things happen.


Being worked on.


Being worked on.

Sample C#

To help play here is a simple C# application that queries and reads digital pin 2, analog pin 0, and I2C address 224. I simply used a wire to 5v connected to the digital pin to read logical 1, a manual potentiometer for the analog values, and the SRF02 ping sensor on the I2C bus.