Arduino Megasquirt Library

This driver provides access to the MegaSquirt ECU with a level of abstraction above the MegaSquirt serial interface, enabling users with no knowledge of the MegaSquirt commands to access the register data easily without caring about the underlying communication required.

The MegaSquirt is a low cost engine control unit with support for fueling, ignition and idle control.

Wiring

The MegaSquirt is connected to the Arduino using the RS232 output on the MegaSquirt, a MAX232 chip, and the Serial interface on the arduino board.

Synopsis

 
#include >MegaSquirt.h<
void setup(){
 MegaSquirt::begin();
 
 byte status;
 String signature;
 status=MegaSquirt::signature(&signature);
 switch (status){
  case MS_COMM_SUCCESS:
   Serial.print("MegaSquirt Signature: ");
   Serial.println(signature);
   break;
  case MS_ERR_COMM_TIMEOUT:
   Serial.println(" FAILURE: Communication Timeout");
   break;
  case MS_ERR_COMM_OVERFLOW:
   Serial.println(" FAILURE: Communication Overflow");
   break;
  default:
   Serial.println(" FAILURE: Unknown Error"); 
 }

String revision;
 status=MegaSquirt::revision(&revision);

 uint16_t uptime;
 status=MegaSquirt::seconds(&uptime);

 MegaSquirtData registers;
 byte regTable[MS_TABLE_LENGTH];
 status=MegaSquirt::getData(regTable);

 registers.loadDAta(regTable);

 Serial.println(registers.lambda1()/10,DEC )
}

Download

You can download the ZIP file to import into the IDE here, or you can fork your own.

Arduino LIS331 Library

The LIS331HH is an ultra low-power full-scale three axis MEMS linear accelerometer.  The device also features ultra low-power operational modes that allow advanced power saving and smart sleep to wake-up functions.  I wrote a library for Arduino that provides an object oriented interface to these devices using the I2C bus.

The project is hosted on GitHub here and is licensed under the GPL.

Download

You can download the ZIP file to import into the IDE here, or you can fork your own.

Usage

Be sure to include the LIS331 and Wire libraries in your project first.

setPowerStatus(int status);

Set the power saving status of the device, options are: LR_POWER_OFF, LR_POWER_NORM, LR_POWER_LOW1, LR_POWER_LOW2,LR_POWER_LOW3

setXEnable(bool enable)

Enable or disable X axis

setYEnable(bool enable)

Enable or disable Y axis

setZEnable(bool enable)

Enable or disable Z axis

string lis.getXValue(int16_t &value);

Reads the X value and assigns it to value.

string lis.getYValue(int16_t &value);

Reads the Y value and assigns it to value.

string lis.getZValue(int16_t &value);

Reads the Z value and assigns it to value.

Example

You can download an example project here.

DHT Support for Loguino

The DHT range of sensors provide a cheap way to grab temperature and humidity information. The sensors are not fast, (250ms per query) but have a good price and require only a single digital pin to use.  Kyle had a few sitting around, so I added loguino support for them.

Arduino ELM327 Library

The ELM327 IC is a multi-function OBD2 Interpreter that can be used to query information about most relatively new vehicles.  The ELM327 connects to the vehicle using the OBD2 port, and provides an RS232 Interface.   I recently purchased an OBD2 shield form SparkFun which uses an ELM clone, the STN1110.  I wanted to add OBD2 support to Loguino, but first I needed to be able to communicate using the ELM protocol.

Subsequently I created a the ELM327 class, which contains both high level and low level methods to get information from the controller.  The low level class is used to send arbitrary commands to the ELM chip, there are two main methods,

  • getBytes which requests a specific PID and parses the returned bytes into an array of values.
  • runCommand which sends an arbitrary command to the ELM device, and parses the output into a buffer which contains the response from the ELM.

The high level class provides methods to gather metrics from the controller, each method parses the response from the ELM device into the actual value.  The following code illustrates how to use the class:

#define ELM_TIMEOUT 9000
#define ELM_BAUD_RATE 9600
#define ELM_PORT Serial3

byte status;
Elm327 Elm;
status=Elm.begin();
if (status != ELM_SUCCESS){
    Serial.print("Error: ");
    Serial.println(status);
}
int temp;
Serial.print("OBD2 Coolant Temperature: ");
status=Elm.coolantTemperature(temp);
if (status  == ELM_SUCCESS)
{
    Serial.println ("Pass");
    Serial.print(" Value: ");
    Serial.println(i);
}else{   
    Serial.print("Error: ");
    Serial.println(status);
}

byte values[2];
status=getBytes("01","41","0C",values,2);
if (status == ELM_SUCCESS){
    Serial.print("Elm returned: ");
    Serial.print(values[0], HEX);
    Serial.print(" ");
    Serial.println(values[1], HEX);
    Serial.print("Which is: ");
    Serial.print(((values[0]*256)+values[1])/4, DEC);
    Serial.println(" RPM");
}else{   
    Serial.print("Error: ");
    Serial.println(status);
}

char data[20];
status=runCommand("ATI",data,20);
Serial.print("Current version is: ");
Serial.println(data);

Feature requests, bugs, suggestions and other feedback always appreciated.

NMEA Library for Arduino

NMEA 0183 (National Marine Electronics Association) is the communication standard for devices used in marine environments as an aid to navigation. The most common use outside of marine environments is for GPS devices, which use NMEA to broadcast their position.

I wrote this library for Loguino in order to provide global positioning metrics to the logger. For Loguino 2.0 I needed to simplify the build, which means moving non-core libraries into their own packages, a lot of people also use the libraries on their own without Loguino, so it’s about time this was the case.

The code is available on GitHub, under the GPL.

Download

You can download the ZIP file to import into the IDE here, or you can fork your own.

Methods

bool addChar(const char c)

Add a character from the gps stream. Returns True when a valid NMEA sentence has been completed. Generally you want to loop through all the data in the serial buffer and call addChar with the output of serial.read() until it returns true. At which point you can interrogate the NMEA object to determine if the fix is valid and then grab the location information if required.

bool validFix()

Returns true when the GPS has a valid fix.

string gps.getCourse()

Returns the course in degrees.

string getSpeed()

Returns the speed in Knots.

string getLatitude()

Returns the latitude.

string getLongitude()

Returns the longitude

string gps.getDate()

Returns the date as a string.

string gps.getTime()

Returns the time as a string.

Example

You can download an example project here.

El Altar

The Obispo summit of El Altar
The Obispo summit of El Altar

The Obispo summit of El Altar was without doubt one of the highlights of my trip, it’s technical, exposed, and stunningly pretty, especially if you get a good weather window.  Sadly, our weather on summit day was awful, and we had to turn around 30M from the actual summit, however in terms of experience this was much more technically and mentally challenging than the others.

The Altar was at one point a huge volcano, however the caldera collapsed, creating a horse shoe shaped ridge, with Obispo (The bishop) being the highest point. Access is via a small village behind Tungaragua (Which recently has been exceptionally active.) and Banos.  From the village its about an hour up a small track to the trailhead.  From the trailhead, its an easy days trek to Italian camp, its possible to arrange mules at the trailhead to carry equipment.  I had two guides on this trip, Rafael, and Ivan, who spent a day fixing ropes on the more exposed sections, before the three of us attempted the summit on day 3.

We set off at around 2am, with clear sky and little moonlight, the stars were wonderful, and the temperature surprisingly warm for the altitude.  There is a small climb, then steep descent down onto the lower glacier, which is traversed, and followed by a small mixed section, and steeper gulley onto the second glacier.  From here we ascended via what appeared to be a ridge and traversed to the final gulley which is a steep mixed section, with exceptionally loose rock.

The final rock wall
The final rock wall

From the top of this, there is a 10M rock wall, approx 90 degrees, by this time the wind had picked up, visibility dropped to a few meters, and it was snowing.  Whilst Ivan and I tied in on top of the gulley, Rafael attempted the rock wall, however the fixed lines had frozen, and now had a small build up of ice, and it wasn’t possible to lock off the jumars so we decided to turn around.  It was mildly frustrating as this was my main objective, but at the same time, a very wise decision.

The descent was just as tough as the ascent, the upper gulley was pretty much a bowling ally, I got clipped on the noggin by a small rock when i was unclipping which was a stark reminder to get the hell out of the way, whilst Rafael and I waited on Ivan rapping down, large boulders were hurtling down at terminal velocity which was quite nerve racking.

The traverse of the snow fields was pretty easy, but time consuming as we had to remove the fixed lines, and rap off snow bollards, it was nearly 4pm before we got back to camp.  Its a testament to the strength of Ivan and Rafael just how strong they were when we arrived back in camp considering they basically climbed the mountain twice by this point.

Oh dear...
Oh dear…

The next day we set off back to the car, with lovely weather and good clear visibility of the lakes and glaciers.  We arrived back at the car late afternoon ready for a hot shower and clean sheets, rounded the first bend, when I glanced up and saw a fantastic eruption form Tungaragua, “Oh look, an eruption, how nice” I said cheerfully to groans from Rafael and Ivan – little did I know that we were not cut off from Banos, where our clean clothes and hotel were, so we spent the night in another town.  Despite the inconvenience, the views of the ash cloud were stunning.

Cyclemeter Link

[flexiblemap src=”http://www.clusterfsck.io/static/kml/el_altar.kml” width=”100%”]

Chimborazo

P1020634

Chimborazo: The highest peak in Ecuador, and probably the most mentally challenging of the six peaks I climbed there.  We set off to clear skies and no wind, but this quickly turned into a slog, Rafael had warned me this would happen, and I had lined up a bunch of my favorite songs to compensate.  From the refuge you ascend to the ridge, and follow this all the way to 20000ft summit, and from there descend into the crater, and waltz around the penitents until you attain the true (Whymper) summit.

The ascent on the ridge was exceptionally cold, with a fierce wind developing across our path which was mentally very tiring and required goggles and balaclava.  I also felt exceptionally tired for some reason, probably a combination of a 20 day climbing trip and not enough sleep.  Rafael must have also been suffering as we stopped for a 5 minute ‘cat nap’ half way up.  That seemed to do the trick and I started to wake up a little, I was resigned to enjoying just the 20000ft summit, but by that point it was light, warm, and I was back on my game – despite taking over an hour, the slog to Whymper and back felt like only a few minutes.

Cyclemeter Link

[flexiblemap src=”http://www.clusterfsck.io/static/kml/chimborazo.kml” width=”100%”]

Cotopaxi

Sunrise on the summit of Cotopaxi
Sunrise on the summit of Cotopaxi

Cotopaxi: Our fourth 5000M peak in Ecuador, and another perfect weather window.  By this point in the trip, Rafael and I have developed a good feel for each others pace, and a mutual respect.  We ascended most of the route unroped, with a good pace.  We started out about an hour after most groups, and were first to the summit by quite a margin, arriving just before sunrise to a spectacular view.

Cotopaxi is located almost in the center of the avenue of volcanoes and the view form the summit is second to none.  Beautiful colors, combined with the caldera of the volcano itself made for a most enjoyable summit, especially as we had it all for ourself to begin with.

Cyclemeter Link

[flexiblemap src=”http://www.clusterfsck.io/static/kml/cotopaxi.kml” width=”100%”]

Cayambe

The summit of Cayambe
The summit of Cayambe

Cayambe lies to the north of the avenue of volcanoes, the final few hundred meters involves some of the most spectacular crevasses and ice formations I’ve seen yet, and tops out to wonderful views over Ecuador.  Rafael and I enjoyed perfect weather yet again, and by this point we were getting pretty comfortable with each other and it was like climbing with an old friend rather than with a guide.

At this point I started to get the feeling that Rafael wasn’t your typical guide, everybody knows him, and refer to him respectfully as Don Rafael, it turns out, in addition to being a super-guide, Rafael trains guides in Ecuador, and subsequently has taught most of the guides on the mountain at some point in their career.  Our pace was excellent, and we arrived on the summit just in time for sun rise.  I spent a bit of time gaffing with my GoPro which I still haven’t found much of a knack for, its great in the car, but I don’t really have the patience for it when it’s attached to my helmet.

Cyclemeter Link

[flexiblemap src=”http://www.clusterfsck.io/static/kml/cayambe.kml” width=”100%”]

The Illinizas

Illiniza Norte
Illiniza Norte

This was my first climb with Rafael, climbing with somebody new is always a little hard for me at first.  I hire a guide primarily as a climbing partner, whilst I usually learn an enormous amount from my guides, I don’t believe in offloading responsibility, to me climbing is about taking responsibility for not just your own safety, but for those around you too.  The guide of course has the last word, as they bring experience, local knowledge, and usually a bit of perspective to the table, but I don’t expect them to wipe my ass, carry my backpack or winch me to the summit – If I can’t get there on my own, I don’t have a right to get there at all.

Rafael on the summit of Illiniza Norte
Rafael on the summit of Illiniza Norte

I had a good feeling about Rafael from the moment we met, he is extremely experienced, and in fact I had no idea just how experienced and respected he was until well into our climbing trip, but from our first meeting, I could tell he was going to be a great guide. From my side, the key now was making sure he had the confidence in me as a client.  Illiniza Norte is a fairly easy scramble, and in good weather there are multiple obvious routes to the summit, however add cold temperatures, sleight and poor visibility and it becomes quite challenging to find the correct route, and with a layer of slush the surface becomes quite slippy.  Rafael dropped me off at the trail head and I hiked up for a couple of hours the previous day before getting a lift back down to the refuge, and the next day I felt in pretty good shape for the summit.  The climb was enjoyable, but the view was pretty minimal.  We picked up another tourist who was a little bit lost, and descended back to the refuge for dinner and an early night.

The next day it was time for Illiniza Sur, this is a more technical climb, and was really the opportunity for me to prove myself to Rafael, if I wasn’t up to snuff, I wouldn’t be climbing on El Altar, so I felt a bit of pressure not to screw up, healthy pressure.  We set off from the saddle, the climb is a delight, with great views down onto Illiniza Norte, on a reasonably exposed snow slope.  We used a 30M rope, either using a running belay, or Rafael leading for a pitch before dropping in a picket and belaying me up.  I’m pretty comfortable on this type of terrain now, and it was a real pleasure taking in the views.

Me on the summit of Illiniza Sur
Me on the summit of Illiniza Sur

From the summit we had perfect visibility over the avenue of Volcanoes and Rafael pointed out the other peaks we could see, before our descent back to the refuge.  On the way down we had a perfect view of Cotopaxi, and lovely snow conditions.  I didn’t screw anything up, and so far things were going well.  It took me a while to get used to group rope travel, but felt very secure and pretty strong considering the altitude.

Cyclemeter Link

[flexiblemap src=”http://www.clusterfsck.io/static/kml/illiniza_norte.kml” width=”100%”]