Physical Hardware Abstraction LayerThe 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 installFirst 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.
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:
- Servo motor control, continuous and 180.
- DC motor control.
- Sensor subscription(for some event based programming).
- Use EEPROM to save settings between power cycles.
- Settings for the various parts.
- Sensor filter and transformation options on board.
- I2C command chaining(described below).
Syntax to playCurrently 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.
DigitalMentioned 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|
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.
AnalogAnalog 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.
I2CI2C 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:
|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.