EOS Library

Overview

The EOS Libraries are a quick toolkit for implementing EOS compatible boards based on Arudino's and Atmel ATMEGA series chips. It is actually a collection of libraries. Libraries which have interrupt definitions or take over timers are separated because they may conflict with other libraries or each other.

  • EOS - Base library required for using all others. Includes utility functions and EOS Bus implementation.
  • EOSServo - Library to expose servo motor control. Requires the default Servo library. This library takes control of timer 1.
  • EOSStepper - Library to expose stepper motor control including acceleration. This library takes control of timer 1.

All functions in the library are designed to be "non-blocking" so they call all be used together in a process loop and not interfere with BUS parsing.

Important Notes

EOS implements it's own low level UART routines and can not be used in conjunction with Arudino's native Serial object. If you try and use any of the Serial objects in your sketch you will get the follow error:

multiple definition of `__vector_18'

The one exception to this is on the Leonardo boards. When compiling on an Leonardo Serial is done via USB and not hardware UART so it can still be used in conjunction with EOS.

Installation

Installing the EOS Libraries is easy. First create a folder names "libraries" under your sketchbook directory. You can find your sketchbook directory on the preferences pane in the Arduino IDE (File->Preferences). Now expand the EOS Library into your libraries folder. If done correctly you should end up with three directories named "EOS", "EOSServo" and "EOSStepper" inside your libraries folder.

Using EOS Library

There are three steps to using the EOS library. First include the library and declare your objects as global variables. This example will have one digital input on pin 8 and a backlight led on pin 3. We also create a variable to track whether we have had input change since the last poll.

#include 
EOSAnalogLed gPanelBacklight(2);
EOSArduinoDigital gInput(9);

byte gName[9] = "Sample";
byte gFWVersion[5] = "SA01";

gPollDataChanged = false;

Now in your setup call initialize the bus and all objects. Note that the EOSBus object is pre-defined for you and you did not have to declare it as a variable. But you must give it the pin id for the TX Enable on your RS-485 driver. In this case we have pin 2 connected to the TX Enable pin of our driver. We also must specify the speed of the EOS bus. EOS standard is 250k and should be used unless testing requires otherwise. Last we set our address on the bus. (Normally you will store address in EEPROM and properly response to Set Address packets.)

void setup() {
  gPanelBacklight.begin();
  gPanelBacklight.setLevel(255);
  gPanelBacklight.setPower(true);
  gInput.begin();
  EOSBus.begin(2, 250000);
}

Next you should call the process method on the objects during your loop method. Last you check the EOSBus for packets address to you.

void loop() {
  gPollDataChanged |= ginput.process();
  
  byte state = EosBus.process();
  switch(state)
  {    
    case BUS_TIMEOUT:
      // Timeout has happened while you where waiting for a response.
      // Should never happen on client. Possibly light error led or ignore.
      break;
      
    case BUS_ERROR:
      // Error processing data on the bus.
      // Possibly light error led or ignore.
      break;

    case BUS_PACKETREADY:
      // A packet was received that is addressed to this board. 
      // See sample sketches for full examples.
      switch (EosBus.getCommand())
      {
        case PACKET_COMMAND_INFO:
        {
          EosBus.beginResponse();
          for(int i=0;i<8;i++)
          {
            EosBus.addData(gName[i]);
          }
          for(int i=0;i<4;i++)
          {
            EosBus.addData(gFWVersion[i]);
          }
          EosBus.addData((byte)1); // One digital inputs
          EosBus.addData((byte)0); // No analog inputs
          EosBus.addData((byte)0); // No encoder inputs
          EosBus.addData((byte)0); // No LED channels
          EosBus.addData((byte)0); // No Steppers
          EosBus.addData((byte)0); // No Servos
          EosBus.addData((byte)0); // No Alpha numeric Display
          EosBus.addData(EosBus.getGroup());
          EosBus.send();
        }
            
        case PACKET_COMMAND_BACKLIGHT_POWER:
        {
          byte led = EosBus.readByte();
          boolean power = EosBus.readBoolean();
          
          if (led == 0)
          {
            gPanelBacklight.setPower(power);
          }
          break;
        }
        
        case PACKET_COMMAND_BACKLIGHT_SET_LEVEL:
        {
          byte led = EosBus.readByte();
          
          if (led == 0)
          {
            byte level = EosBus.readByte();
            gPanelBacklight.setLevel(level);  
          }   
          break;    
        }

        
        case PACKET_COMMAND_POLL:
        {
          EosBus.beginResponse();         
          if (gPollDataChanged)
          {
            EosBus.addData(gInput.getPortAState());            
            gPollDataChanged = false;
          }
          EosBus.send();
          break;
        }
    }
    break;
  }
}

EOS Library Objects

  • EOSBus - Bus listening, packet parsing and response.
  • EOSDigitalPin - Fast digital read / write of digital pins on an ATMega
  • EOSAnalog - Reading ADC pins as analog inputs
  • EOSArduinoDigital - Reads a bank of arduino digital input pins as EOS digital inputs
  • EOSDigitalLed - Use a arduino digital pin as a non dimming led output.
  • EOSAnalogLed - Use an arduino PWM pin as a dimming led output.
  • EOSMCP23017 - Use an I2C connected MCP23017 chip as a bank of 16 digital inputs
  • EOSMCP23018 - Use an I2C connected MCP23018 chip as a bank of 16 non-dimming led outputs

EOS Servo Library Objects

  • EOSServo - Use an arduino digital pin as a servo signal output.

EOS Stepper Library Objects

  • EOSStepper - Use three arduino pins to control an stepper driver.