Subscribe RSS

Programming the AdMoVeo in the Arduino environment is for Advanced users only, if you are inside the Creative Programming for Designers course you must follow the descriptions provided, programming the AdMoVeo in Arduino is NOT supported in this course.

For programming the AdMoVeo under the Arduino software environment you have to know and setup some things correctly.

First you  give the pin numbers names:

// AdMoVeo digital pins
#define encoderRight_Pin  2
#define buzzer_Pin  3
#define encoderLeft_Pin  4
#define speedRight_Pin  5
#define speedLeft_Pin  6
#define dirRight_Pin  7
#define dirLeft_Pin  8
#define ledBlue_Pin  9
#define ledRed_Pin  10
#define ledGreen_Pin  11
#define leftRight_Pin  12
#define frontRear_Pin  13
// AdMoVeo analog pins
#define sound_Pin  0
#define light_Pin  1
#define line_Pin  2
#define distance_Pin  3

Then declare Variables that can be used to store your data:

// AdMoVeo variables
int encoderRight = 0;
int encoderLeft = 0;
int soundLeft = 0;
int soundRight = 0;
int lightLeft = 0;
int lightRight = 0;
int lineLeft = 0;
int lineRight = 0;
int distanceFront = 0;
int distanceLeft = 0;
int distanceRight = 0;
byte speedRight = 0;          //  max speed value = 255
byte speedLeft = 0;
byte ledBlue  = 0;
byte ledRed = 0;
byte ledGreen = 0;
boolean dirRight = 0;         // forward or backward
boolean dirLeft = 0;

In the Setup configure the IO pin direction and if needed the serial communication speed, that is set to 57600 bps inside the Xbee modules.

void setup(){
  // serial output configuration
  Serial.begin(57600);
  Serial.println("setup");

  // AdMoVeo minimal pin configuration
  pinMode(leftRight_Pin, OUTPUT);       // sets the digital pin as output
  digitalWrite(leftRight_Pin, HIGH);    // define selected sensor
  pinMode(frontRear_Pin,OUTPUT);        // sets the digital pin as output
  digitalWrite(frontRear_Pin, HIGH);    // define selected sensor
  pinMode(dirRight_Pin, OUTPUT);        // sets the digital pin as output
  digitalWrite(dirRight_Pin, HIGH);     // define motor direction
  pinMode(dirLeft_Pin, OUTPUT);         // sets the digital pin as output
  digitalWrite(dirLeft_Pin, HIGH);      // define motor direction
  analogWrite(speedRight_Pin, 0);       // motor STOP
  analogWrite(speedLeft_Pin, 0);        // motor STOP
}

In your main loop you would like to do some interaction, such as reading the front distance sensor value and setting the intensity of the blue led according to the input value.

void loop(){
    distanceFront  = readSensor(DISTANCE,FRONT);
    Serial.print(distanceFront);
    analogWrite(ledBlue_Pin, distanceFront/4);
}

The AdMoVeo is designed in a way that multiple sensors are connected to one physical input pin, on the platform is multiplexing hardware present for switching between the different sensors that are connected to one pin.

To execute the code above you need some additional functions that setup the multiplexer for the correct sensor, one called readSensor() and another called setChannel(), you also need to configure some aditional parameters: DISTANCE, FRONT etc.

#define LEFT   0
#define RIGHT  1
#define BOTH   2
#define FRONT  3
#define NONE   4
#define LINE   5
#define LIGHT  6
#define SOUND  7
#define DISTANCE 8

void setChannel(int selection)
{
  switch (selection){
  case LEFT:
    digitalWrite(frontRear_Pin,LOW);
    digitalWrite(leftRight_Pin,LOW);
    break;
  case RIGHT:
    digitalWrite(frontRear_Pin,LOW);
    digitalWrite(leftRight_Pin,HIGH);
    break;
  case FRONT:
    digitalWrite(frontRear_Pin,HIGH);
    digitalWrite(leftRight_Pin,LOW);
    break;
  case NONE:
    digitalWrite(frontRear_Pin,HIGH);
    digitalWrite(leftRight_Pin,HIGH);
    break;
  default:
    digitalWrite(frontRear_Pin,HIGH);
    digitalWrite(leftRight_Pin,HIGH);
    break;
  }
}

int readSensor(int Sensor, int Side)
{
  int returnData;
  setChannel(Side);                  // activate measurement channel
  switch (Sensor){
  case LINE:
    returnData = analogRead(line_Pin);
    break;
  case LIGHT:
    returnData = analogRead(light_Pin);
    break;
  case SOUND:
    returnData = analogRead(sound_Pin);
    break;
  case DISTANCE:
    delay(1);                         // delay needed for reliable measurement infrared
    returnData = analogRead(distance_Pin);
    break;
  }
  setChannel(NONE);                   // set channel to unused channel, for power reasons
  return returnData;
}