NeoSteamLabs
Published

Project #12: Robotics - Unmanned Vehicles 1b - XBee - Mk06

Robotics, Arduino UNO, Arduino Fio, XBee, LEDs, Etc...

IntermediateProtip2 hours489
Project #12: Robotics - Unmanned Vehicles 1b - XBee - Mk06

Things used in this project

Hardware components

Arduino Fio
SparkFun Arduino Fio
×1
Arduino UNO
Arduino UNO
×1
ProtoScrewShield
SparkFun ProtoScrewShield
×1
Adafruit RGB LCD Shield 16×2 Character Display
×1
SparkFun XBee S1
×2
SparkFun XBee Explorer Regulated
SparkFun XBee Explorer Regulated
×1
SparkFun Lithium Ion Battery - 2.5Ah
×1
5 mm LED: Red
5 mm LED: Red
×1
5 mm LED: Green
5 mm LED: Green
×1
LED BiPolar
×1
5 mm LED: Yellow
5 mm LED: Yellow
×1
Adafruit Jumper Wires 3in M/M
×4
Adafruit Jumper Wires 6in M/M
×10
Solderless Breadboard Half Size
Solderless Breadboard Half Size
×1
SparkFun XBee Explorer USB
SparkFun XBee Explorer USB
×1
SparkFun FTDI Basic Breakout - 3.3V
SparkFun FTDI Basic Breakout - 3.3V
×1
SparkFun Cerberus USB Cable - 6ft
SparkFun Cerberus USB Cable - 6ft
×1

Software apps and online services

Arduino IDE
Arduino IDE
DIGI XCTU Software

Story

Read more

Schematics

Fritzing

Code

DL2001Mk02p.ino

Arduino
// ***** Don Luc Electronics © *****
// Software Version Information
// Project #12: Robotics - Unmanned Vehicles 1b - Mk06
// 01-02
// DL2001Mk01p.ino 12-06
// Arduino UNO - R3
// ProtoScrewShield
// Adafruit RGB LCD Shield 16×2 Character Display
// EEPROM with Unique ID
// Transmitter
// XBee S1

// Include the library code:
// EEPROM library to read and write EEPROM with unique ID for unit
#include <EEPROM.h>
// Adafruit RGB LCD Shield
#include <Adafruit_RGBLCDShield.h>

// Adafruit RGB LCD Shield
Adafruit_RGBLCDShield RGBLCDShield = Adafruit_RGBLCDShield();

// These #defines make it easy to set the backlight color
#define OFF 0x0
#define RED 0x1
#define YELLOW 0x3
#define GREEN 0x2
#define TEAL 0x6
#define BLUE 0x4
#define VIOLET 0x5
#define WHITE 0x7

// Momentary Button
int yy = 0;
uint8_t momentaryButton = 0;

// Communication
unsigned long dTime = 1000;

// The current address in the EEPROM (i.e. which byte we're going to  read to next)
// Version
String sver = "12-2.p";
// Unit ID Information
String uid = "";

void loop() {

  // Clear
  RGBLCDShield.clear();

  // set the cursor to column 0, line 0
  RGBLCDShield.setCursor(0,0);
  RGBLCDShield.print("Robotics");         // Robotics 

  // Momentary Button
  momentaryButton = RGBLCDShield.readButtons();

  switch ( yy ) {
    case 1:
    
      // LED Green
      isSwitch1();
      
      break;
    case 2:
    
      // LED Bipolar (Green)
      isSwitch2();
      
      break;
    case 3:

      // Right
      isSwitch3();
      
      break;
    case 4:

      // Left
      isSwitch4();
      
      break;
    case 5:

      // LED Red
      isSwitch5();
      
      break;
    default:

      // LED Red
      yy = 5;
      RGBLCDShield.setBacklight(RED);
      isSwitch5();

   }
   
   if ( momentaryButton ) {
    
    if ( momentaryButton & BUTTON_UP ) {
      
      yy = 1;
      // LED Green
      RGBLCDShield.setBacklight(GREEN);
      
    }
    
    if ( momentaryButton & BUTTON_DOWN ) {
      
      yy = 2;
      // LED Bipolar A
      RGBLCDShield.setBacklight(VIOLET);
      
    }
    
    if ( momentaryButton & BUTTON_LEFT ) {
      
      yy = 3;
      // LED Bipolar B
      RGBLCDShield.setBacklight(TEAL);
      
    }
    
    if ( momentaryButton & BUTTON_RIGHT ) {

      yy = 4;
      // LED Bipolar A B
      RGBLCDShield.setBacklight(YELLOW);
    }
    
    if ( momentaryButton & BUTTON_SELECT ) {

      yy = 5;
      // LED Red
      RGBLCDShield.setBacklight(RED);
   
    }
    
  }

  // Process Message
  isProcessMessage();

  delay( dTime );
   
}

getEEPROM.ino

Arduino
// EEPROM
// isUID
void isUID()
{
  
  // Is Unit ID
  uid = "";
  for (int x = 0; x < 5; x++)
  {
    uid = uid + char(EEPROM.read(x));
  }
  
}

getProcessMessage.ino

Arduino
// ProcessMessage
// isProcessMessage
void isProcessMessage() {

   //int incb = 0;  
   String msg = "";
  
   /// Loop through serial buffer one byte at a time until you reach * which will be end of message
   //while ( Serial.available() ) 
  // {

      // Print => XBEE + Unit ID + Version + *
      msg = "XBEE|" + uid + "|" + sver + "|" + yy + "|*";
      Serial.println( msg );
         
  // }
     
}

getSwitch.ino

Arduino
// Switch
// Switch 1
void isSwitch1(){

   yy = 1;
   
   isSwitchLEDStop();
   // LED 
   // turn LED on:
   RGBLCDShield.setCursor(0,1);    
   RGBLCDShield.print("Green");  
   
}
// Switch 2
void isSwitch2(){

   yy = 2;

   isSwitchLEDStop();
   // LED 
   // turn LED on:
   RGBLCDShield.setCursor(0,1);    
   RGBLCDShield.print("Bi-Colour A");    
      
}
// Switch 3
void isSwitch3(){

   yy = 3;

   isSwitchLEDStop();
   // LED 
   // turn LED on:
   RGBLCDShield.setCursor(0,1);    
   RGBLCDShield.print("Bi-Colour B");    
      
}
// Switch 4
void isSwitch4(){

   yy = 4;

   isSwitchLEDStop();
   // LED 
   // turn LED on:
   RGBLCDShield.setCursor(0,1);    
   RGBLCDShield.print("Bi-Colour A B"); 
      
}
// Switch 5
void isSwitch5(){

   yy = 5;

   RGBLCDShield.setCursor(0,1);    
   RGBLCDShield.print("Stop");

   //delay( 250 );

   isSwitchLEDStop();
   // LED 
   // turn LED on:
   //digitalWrite(iLEDRed, HIGH);   
       
}
void isSwitchLEDStop(){

  //digitalWrite(iLEDRed, LOW);
  //digitalWrite(iLEDGreen, LOW);
  //digitalWrite(iLEDB1, LOW);
  //digitalWrite(iLEDB2, LOW);
  //digitalWrite(iLEDYellow, LOW);
  
}

setup.ino

Arduino
// Setup
void setup() {
  
  //Open serial port at 9600 baud
  Serial.begin( 9600 );

  // Pause
  delay(5);

  // EEPROM Unit ID
  isUID();
  
  // Pause
  delay(5);
  
  // Adafruit RGB LCD Shield
  // Set up the LCD's number of columns and rows: 
  RGBLCDShield.begin(16, 2);
  RGBLCDShield.setBacklight(GREEN);
  
  // Display
  // Set the cursor to column 0, line 0  
  RGBLCDShield.setCursor(0,0);  
  RGBLCDShield.print("Don Luc Electron");         // Don luc Electron
  // Set the cursor to column 0, line 1
  RGBLCDShield.setCursor(0, 1);
  RGBLCDShield.print("Robotics");                 // Robotics

  // Serial
  Serial.println( "Don Luc Electronics");
  Serial.println( "Robotics");

  delay(5000);

  // Clear
  RGBLCDShield.clear();

  // Display
  // Set the cursor to column 0, line 0  
  RGBLCDShield.setCursor(0,0);  
  RGBLCDShield.print("Version: ");                // Version
  RGBLCDShield.print( sver );
  // Set the cursor to column 0, line 1
  RGBLCDShield.setCursor(0, 1);
  RGBLCDShield.print("UID: ");                    // Unit ID Information
  RGBLCDShield.print( uid );

  // Serial
  Serial.print( "Software Version Information: ");
  Serial.println( sver );
  Serial.print( "Unit ID Information: ");
  Serial.println( uid );

  delay(5000);

  // Clear
  RGBLCDShield.clear();

}

DL2001Mk02Rp.ino

Arduino
// ***** Don Luc Electronics © *****
// Software Version Information
// Project #12: Robotics - Unmanned Vehicles 1b - Mk06
// 01-02
// DL2001Mk02Rp.ino 12-06
// Arduino Fio
// SparkFun FTDI Basic Breakout - 3.3V
// EEPROM with Unique ID
// LED Red
// LED Green
// LED Bi-Colour
// LED Yellow
// Lithium Ion Battery - 2.5Ah
// Receiver
// XBee S1

// Include the library code:
// EEPROM library to read and write EEPROM with unique ID for unit
#include <EEPROM.h>

// LED Red
int iLEDRed = 13;
// LED Green
int iLEDGreen = 12;
// LED Bi-Colour
int iLEDBiCoA = 11;
int iLEDBiCoB = 10;
// LED Yellow
int iLEDYellow = 9;

// Momentary Button
int yy = "";

// Software Version Information
String sver = "12-02";
// Unit ID information
String uid = "DR001";

void loop() {

  // Check for serial messages
  if ( Serial.available() ) 
  {
    isProcessMessage();
  }

  // Switch
  isSwitch();
  
}

getEEPROM.ino

Arduino
// EEPROM
// isUID
void isUID()
{
  
  // Is Unit ID
  uid = "";
  for (int x = 0; x < 5; x++)
  {
    uid = uid + char(EEPROM.read(x));
  }
  
}

getProcessMessage.ino

Arduino
// ProcessMessage
// isProcessMessage
void isProcessMessage() {

   int incb = 0;  
   String msg = "";
   String zzz = "";
   
  // Loop through serial buffer one byte at a time until you reach * which will be end of message
  while ( Serial.available() ) 
  {
      
      // Read the incoming byte:
      incb = Serial.read();
      // Add character to string
      msg = msg + char(incb);
      
      // Check if receive character is the end of message *
      if ( incb == 42 ) 
      {
         
         Serial.println(msg);

         zzz = msg.charAt( 18 );
         
         Serial.println(zzz);
         
         yy = zzz.toInt();
         
        Serial.println( yy );
        
      }
   }
     
}

getSwitch.ino

Arduino
// Switch
// isSwitch
void isSwitch(){
  
  switch ( yy ) {
    case 1:
    
      // LED Green
      sLEDStop();
      digitalWrite(iLEDGreen, HIGH);
      delay( 1000 );
      
      break;
    case 2:
    
      // LED Bi-Colour A
      sLEDStop();
      digitalWrite(iLEDBiCoA, HIGH);
      delay( 1000 );
      
      break;
    case 3:

      // LED Bi-Colour B
      sLEDStop();
      digitalWrite(iLEDBiCoB, HIGH);
      delay( 1000 );
      
      break;
    case 4:

      // LED Bi-Colour A B
      sLEDStop();
      digitalWrite(iLEDBiCoA, HIGH);
      digitalWrite(iLEDBiCoB, HIGH);
      delay( 1000 );
      
      break;
    case 5:

      // LED Red
      sLEDStop();
      digitalWrite(iLEDRed, HIGH); 
      delay( 1000 );
       
      break;
    default:

      // LED Red
      sLEDStop();
      digitalWrite(iLEDRed, HIGH);
      delay( 1000 ); 

   }
  
}
// LED Stop
void sLEDStop(){

  digitalWrite(iLEDRed, LOW);
  digitalWrite(iLEDGreen, LOW);
  digitalWrite(iLEDBiCoA, LOW);
  digitalWrite(iLEDBiCoB, LOW);
  
}

setup.ino

Arduino
// Setup
void setup() {

  // Open the serial port at 9600 bps:
  Serial.begin( 9600 );

  // Pause
  delay(5);

  // EEPROM Unit ID
  isUID();
  
  // Pause
  delay(5);
  
  // Serial
  Serial.print( "Software Version Information: ");
  Serial.println( sver );
  Serial.print( "Unit ID Information: ");
  Serial.println( uid );
  
  delay(5000);

  // LED => OUTPUT
  pinMode(iLEDRed, OUTPUT);
  pinMode(iLEDGreen, OUTPUT);
  pinMode(iLEDBiCoA, OUTPUT);
  pinMode(iLEDBiCoB, OUTPUT);
  pinMode(iLEDYellow, OUTPUT);

  // LED Yellow
  digitalWrite(iLEDYellow, HIGH);

}

Credits

NeoSteamLabs

NeoSteamLabs

30 projects • 12 followers
IT consultant with over 36 years of experience Instructor: Arduino, Raspberry Pi, Espressif, Robotics, Unmanned Vehicles, etc...

Comments