Plane | Adding an LCD to the controller, and using Visual Basic for feedback

So here’s a video:

So pretty easy but important step here. For a while I’ve known that I need to have some more feedback from the robot that just LED brightness levels on the controller. This VB program allows me to get analog values from the vehicle and interpret them in any number of ways. You can download and run that program HERE, and like I said in the video I’ve refrained from going open source with my VB programs in the past because they’ve never really had any polish to them. But now I think it will be good to keep this all open.

I also added a 16 * 2 character LCD to my controller. I’ve sacrificed the 6 pins because hopefully in the long run it will be a better experience for the user. I may go back, but for now I’d rather build around something that’s a little more constraining as it will force me to innovate a little bit more. Here’s a picture of the new controller:

Here’s the program:

//Serial Handshake declaration
#include <string.h> // we'll need this for subString
#define MAX_STRING_LEN 100 // like 3 lines above, change as needed.
const char EOPmarker = '.';  //This is the end of packet marker
char serialbuf[100]; //This gives the incoming serial some room. Change it if you want a longer incoming.

//SoftwareSerial declaration
#include <SoftwareSerial.h>
SoftwareSerial xbee_serial(2, 3);

//Shift Register Pins declaration
int SER_Pin = 5;   //pin 14 on the 75HC595
int RCLK_Pin = 6;  //pin 12 on the 75HC595
int SRCLK_Pin = 7; //pin 11 on the 75HC595
#define number_of_74hc595s 1 //How many of the shift registers - change this
#define numOfRegisterPins number_of_74hc595s * 8 //do not touch
boolean registers[numOfRegisterPins];

//Servo declarations
int left_servo_val;
int rght_servo_val;

//lcd declaration
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

//Misc Pin declaration

//inputs
int debug_switch1 = 4;
int debug_switch2 = 6;
//these values are for communication, not hardware inputs
int in_ref;
int in_brightness;
int in_pot1;
int in_pot2;
int in_accelerometer_x;
int in_accelerometer_y;
int in_accelerometer_z;
int in_temp1;

//outputs
//int pot_LED = 6;
int fade_LED = 5;
int debug_switch1_LED = 13;
//these values are for communication, not hardware outputs
int out_joystick_x;
int out_joystick_y;

//Misc Integer Declarations
int brightness = 0;    // how bright the LED is
int fadeAmount = 51;    // how many points to fade the LED by

int accel_x_min = 293;
int accel_x_max = 440;
int accel_y_min = 290;
int accel_y_max = 434;

void setup(){
  Serial.begin(9600);
  xbee_serial.begin(9600);

  //shift register setup
  pinMode(SER_Pin, OUTPUT);
  pinMode(RCLK_Pin, OUTPUT);
  pinMode(SRCLK_Pin, OUTPUT);
  pinMode(0, INPUT);
  clearRegisters();
  writeRegisters();

  //Misc Pin Declarations
  pinMode(debug_switch1, INPUT);
  pinMode(debug_switch2, INPUT);

  //pinMode(pot_LED, OUTPUT);
  pinMode(fade_LED, OUTPUT);

  //lcd declaration
  lcd.begin(16, 2);

  xbee_serial.print("0,0,0."); // this is very important as it starts of the loop because it makes "xbee_serial.avalible() > 0.
}

void loop(){
  if (xbee_serial.available() > 0) {
    static int bufpos = 0;
    char inchar = xbee_serial.read();
      if (inchar != EOPmarker) {
        serialbuf[bufpos] = inchar;
        bufpos++;
      }
      else {
        serialbuf[bufpos] = 0; //restart the buff
        bufpos = 0; //restart the position of the buff

        if (digitalRead(debug_switch1) == LOW){
          digitalWrite(debug_switch1_LED, LOW); //LED in board indicates debug status
          handshake();
          lcd.setCursor(0, 0);
          lcd.print("Debug: OFF");
          lcd.setCursor(0, 1);
          lcd.print("             ");
          digitalWrite(debug_switch1_LED, LOW);
        }

        if (digitalRead(debug_switch1) == HIGH){
          handshake(); //no matter what, the handshake happens normally
          lcd.setCursor(0, 0);
          lcd.print("Debug: ON ");

          debug_handshake(); //the debug to console only slows the process downm no interference with data
          digitalWrite(debug_switch1_LED, HIGH);
        }
    }
  }
}

void handshake(){
  //inputs, recived from vehicle
  in_ref = atoi(subStr(serialbuf, "," , 1));
  in_brightness = atoi(subStr(serialbuf, "," , 2));
  in_pot1 = (map(atoi(subStr(serialbuf, "," , 3)),0,1023,0,255));
  in_pot2 = atoi(subStr(serialbuf, "," , 4));
  in_accelerometer_x = atoi(subStr(serialbuf, "," , 5));
  in_accelerometer_y = atoi(subStr(serialbuf, "," , 6));
  in_accelerometer_z = atoi(subStr(serialbuf, "," , 7));
  in_temp1 = atoi(subStr(serialbuf, "," , 8));

  analogWrite(fade_LED, in_brightness);
  //analogWrite(pot_LED, in_pot1);

  //outputs, sent to vehicle
  brightness = brightness + fadeAmount;

  // reverse the direction of the fading at the ends of the fade:
  if (brightness == 0 || brightness == 255) {
    fadeAmount = -fadeAmount ;
  }

  out_joystick_x = analogRead(7); //remap for coherency purposes
  out_joystick_y = analogRead(6);

  xbee_serial.print(brightness);
  xbee_serial.print(",");
  xbee_serial.print(out_joystick_x);
  xbee_serial.print(",");
  xbee_serial.print(out_joystick_y);
  xbee_serial.print("."); //EOP marker
  delay(10);

}

void debug_handshake() { //there are two debug modes
  if (digitalRead(debug_switch2) == HIGH){
    lcd.setCursor(0, 1);
    lcd.print("Mode: 1 Line");
    debug_handshake_fncy(); //this is good for looking at one line at a time (via the port monitor)
  }

  if (digitalRead(debug_switch2) == LOW){
    debug_handshake_smpl(); //this is great for data interpretation (via VB)
    lcd.setCursor(0, 1);
    lcd.print("Mode: VB     ");
  }
}

void debug_handshake_fncy(){
  Serial.print("INPUTS {");

  Serial.print("refvolt: ");
  Serial.print(in_ref);
  Serial.print(",");

  Serial.print(" fade: ");
  Serial.print(brightness);
  Serial.print(",");

  Serial.print(" LED1: ");
  Serial.print(in_pot1);
  Serial.print(",");

  Serial.print(" pot2: ");
  Serial.print(in_pot2);
  Serial.print(",");

  Serial.print(" accel_x: ");
  Serial.print(in_accelerometer_x);
  Serial.print(",");

  Serial.print(" accel_y: ");
  Serial.print(in_accelerometer_y);
  Serial.print(",");

  Serial.print(" accel_z: ");
  Serial.print(in_accelerometer_z);
  Serial.print(",");

  Serial.print(" temp1: ");
  Serial.print(in_temp1);

  Serial.print("}");

  Serial.print(" | ");
  Serial.print("OUTPUTS {");

  Serial.print("joystick_x: ");
  Serial.print(out_joystick_x);
  Serial.print(",");

  Serial.print(" joystick_y: ");
  Serial.print(out_joystick_y);

  Serial.print("}");

  Serial.println("");
}

void debug_handshake_smpl(){ //just inputs seperated by commas then a | then outputs seperated by commas
  Serial.print(in_ref);
  Serial.print(",");
  Serial.print(brightness);
  Serial.print(",");
  Serial.print(in_pot1);
  Serial.print(",");
  Serial.print(in_pot2);
  Serial.print(",");
  Serial.print(in_accelerometer_x);
  Serial.print(",");
  Serial.print(in_accelerometer_y);
  Serial.print(",");
  Serial.print(in_accelerometer_z);
  Serial.print(",");
  Serial.print(in_temp1);
  Serial.print(",");

  Serial.print("|");

  Serial.print(out_joystick_x);
  Serial.print(",");
  Serial.print(out_joystick_y);

  Serial.println("");
}

char* subStr (char* input_string, char *separator, int segment_number) { //for substring
 char *act, *sub, *ptr;
 static char copy[MAX_STRING_LEN];
 int i;

 strcpy(copy, input_string);

for (i = 1, act = copy; i <= segment_number; i++, act = NULL) {

 sub = strtok_r(act, separator, &ptr);
 if (sub == NULL) break;
 }
 return sub;
}

void clearRegisters(){ //for shift registers
  for(int i = numOfRegisterPins - 1; i >=  0; i--){
     registers[i] = LOW;
  }
}

void writeRegisters(){ //for shift registers
  digitalWrite(RCLK_Pin, LOW);
  for(int i = numOfRegisterPins - 1; i >=  0; i--){
    digitalWrite(SRCLK_Pin, LOW);
    int val = registers[i];
    digitalWrite(SER_Pin, val);
    digitalWrite(SRCLK_Pin, HIGH);
  }
  digitalWrite(RCLK_Pin, HIGH);
}

//set an individual pin HIGH or LOW
void setRegisterPin(int index, int value){
  registers[index] = value;
}

I didn’t mention in in the video, but I moved the mux from the controller, to the vehicle. It allows me to have 22 analog inputs, and the reason I took so long to finally add it was primarily laziness on my part. Aside from the the code is still very similar but close followers will notice that I cleaned up the way the program receives and sends code. It is much much more organized, and much more expandable. Here’s the “new” controller:

Here’s the new program:

//Serial Handshake declaration
#include <string.h> // we'll need this for subString
#define MAX_STRING_LEN 100 // like 3 lines above, change as needed.
const char EOPmarker = '.';  //This is the end of packet marker
char serialbuf[100]; //This gives the incoming serial some room. Change it if you want a longer incoming.

//SoftwareSerial declaration
#include <SoftwareSerial.h>
SoftwareSerial xbee_serial(8, 9);

//Mux control pins declarations
int s0 = 2;
int s1 = 3;
int s2 = 4;
int s3 = 7;
int SIG_pin = 0;

//Shift Register Pins declaration
int SER_Pin = 10;   //pin 14 on the 75HC595
int RCLK_Pin = 11;  //pin 12 on the 75HC595
int SRCLK_Pin = 12; //pin 11 on the 75HC595
#define number_of_74hc595s 1 //How many of the shift registers - change this
#define numOfRegisterPins number_of_74hc595s * 8 //do not touch
boolean registers[numOfRegisterPins];

//Servo declarations
#include <Servo.h>
Servo left_servo;
Servo rght_servo;

//Misc Pin declaration

//inputs
int debug_switch1 = 4;

//outputs
//these values are for communication, not hardware outputs
int out_ref;
int out_pot1;
int out_pot2;
int out_accelerometer_x;
int out_accelerometer_y;
int out_accelerometer_z;
int out_temp1;

int fade_LED = 13;
int x_LED = 5;
int y_LED = 6;
//int debug_switch1_LED = 12;

//Misc Integer declarations
int in_brightness;
int in_joystick_x;
int in_joystick_y;

int brightness = 0;    // how bright the LED is
int fadeAmount = 51;    // how many points to fade the LED by

int x_upperTrigger = 600;
int x_lowerTrigger = 450;
int y_upperTrigger = 600;
int y_lowerTrigger = 400;

void setup(){
  Serial.begin(9600);
  xbee_serial.begin(9600);

  //mux setup
  pinMode(s0, OUTPUT);
  pinMode(s1, OUTPUT);
  pinMode(s2, OUTPUT);
  pinMode(s3, OUTPUT);
  digitalWrite(s0, LOW);
  digitalWrite(s1, LOW);
  digitalWrite(s2, LOW);
  digitalWrite(s3, LOW);

  //shift register setup
  pinMode(SER_Pin, OUTPUT);
  pinMode(RCLK_Pin, OUTPUT);
  pinMode(SRCLK_Pin, OUTPUT);
  clearRegisters();
  writeRegisters();

  //misc pin declarations
  pinMode(x_LED, OUTPUT);
  pinMode(y_LED, OUTPUT);
  pinMode(fade_LED, OUTPUT);

  xbee_serial.print("0,0,0."); // this is very important as it starts of the loop because it makes "xbee_serial.avalible() > 0.
}

void loop(){

  if (xbee_serial.available() > 0) {
    static int bufpos = 0;
    char inchar = xbee_serial.read();
      if (inchar != EOPmarker) {
        serialbuf[bufpos] = inchar;
        bufpos++;
      }
      else {
        serialbuf[bufpos] = 0; //restart the buff
        bufpos = 0; //restart the position of the buff

          handshake();

          setRegisterPin(1, HIGH);
          writeRegisters();

    }
  }
}

void handshake(){

   //inputs
  in_brightness = atoi(subStr(serialbuf, "," , 1));
  in_joystick_x = atoi(subStr(serialbuf, "," , 2));
  in_joystick_y = atoi(subStr(serialbuf, "," , 3));

  analogWrite(fade_LED,in_brightness);

  if (in_joystick_x > x_upperTrigger){ //the below boolean blocks set pins high or low
    setRegisterPin(4,HIGH);
    setRegisterPin(5,LOW);
    analogWrite(x_LED, map(in_joystick_x,x_upperTrigger,1023,0,255));
    writeRegisters();
  }

  if (in_joystick_x < x_lowerTrigger){
    setRegisterPin(4,LOW);
    setRegisterPin(5,HIGH);
    analogWrite(x_LED, map(in_joystick_x,x_upperTrigger,0,0,255));
    writeRegisters();
  }

  if (in_joystick_x > x_lowerTrigger && in_joystick_x < x_upperTrigger){
    setRegisterPin(4,LOW);
    setRegisterPin(5,LOW);
    analogWrite(x_LED,0);
    writeRegisters();
  }

  // x above y below

  if (in_joystick_y > y_upperTrigger){
    setRegisterPin(2,HIGH);
    setRegisterPin(3,LOW);
    analogWrite(y_LED, map(in_joystick_y,y_upperTrigger,1023,0,255));
    writeRegisters();
  }

  if (in_joystick_y < y_lowerTrigger){
    setRegisterPin(2,LOW);
    setRegisterPin(3,HIGH);
    analogWrite(y_LED, map(in_joystick_y,y_upperTrigger,0,0,255));
    writeRegisters();
  }

  if (in_joystick_y > y_lowerTrigger && in_joystick_y < y_upperTrigger){
    setRegisterPin(2,LOW);
    setRegisterPin(3,LOW);
    analogWrite(y_LED,0);
    writeRegisters();
  }

  //outputs
  brightness = brightness + fadeAmount;

  // reverse the direction of the fading at the ends of the fade:
  if (brightness == 0 || brightness == 255) {
    fadeAmount = -fadeAmount ;
  }

  out_ref = readMux(15);
  out_pot1 = readMux(0);
  out_pot2 = readMux(1);
  out_accelerometer_x = readMux(2);
  out_accelerometer_y = readMux(3);
  out_accelerometer_z = readMux(4);
  out_temp1 = readMux(5);

  xbee_serial.print(out_ref);
  xbee_serial.print(",");
  xbee_serial.print(brightness);
  xbee_serial.print(",");
  xbee_serial.print(out_pot1);
  xbee_serial.print(",");
  xbee_serial.print(out_pot2);
  xbee_serial.print(",");
  xbee_serial.print(out_accelerometer_x);
  xbee_serial.print(",");
  xbee_serial.print(out_accelerometer_y);
  xbee_serial.print(",");
  xbee_serial.print(out_accelerometer_z);
  xbee_serial.print(",");
  xbee_serial.print(out_temp1);

  xbee_serial.print("."); //EOP marker
  delay(10);

}

// for substring
char* subStr (char* input_string, char *separator, int segment_number) {
 char *act, *sub, *ptr;
 static char copy[MAX_STRING_LEN];
 int i;

 strcpy(copy, input_string);

for (i = 1, act = copy; i <= segment_number; i++, act = NULL) {

 sub = strtok_r(act, separator, &ptr);
 if (sub == NULL) break;
 }
 return sub;
}

// for mux
int readMux(int channel){
  int controlPin[] = {s0, s1, s2, s3};
  int muxChannel[16][4]={
    {0,0,0,0}, //channel 0
    {1,0,0,0}, //channel 1
    {0,1,0,0}, //channel 2
    {1,1,0,0}, //channel 3
    {0,0,1,0}, //channel 4
    {1,0,1,0}, //channel 5
    {0,1,1,0}, //channel 6
    {1,1,1,0}, //channel 7
    {0,0,0,1}, //channel 8
    {1,0,0,1}, //channel 9
    {0,1,0,1}, //channel 10
    {1,1,0,1}, //channel 11
    {0,0,1,1}, //channel 12
    {1,0,1,1}, //channel 13
    {0,1,1,1}, //channel 14
    {1,1,1,1}  //channel 15
  };

  //loop through the 4 sig
  for(int i = 0; i < 4; i ++){
    digitalWrite(controlPin[i], muxChannel[channel][i]);
  }

  //read the value at the SIG pin
  int val = analogRead(SIG_pin);

  //return the value
  return val;
}
// for shift registers
void clearRegisters(){
  for(int i = numOfRegisterPins - 1; i >=  0; i--){
     registers[i] = LOW;
  }
}

// for shift registers
void writeRegisters(){
  digitalWrite(RCLK_Pin, LOW);
  for(int i = numOfRegisterPins - 1; i >=  0; i--){
    digitalWrite(SRCLK_Pin, LOW);
    int val = registers[i];
    digitalWrite(SER_Pin, val);
    digitalWrite(SRCLK_Pin, HIGH);
  }
  digitalWrite(RCLK_Pin, HIGH);
}

//set an individual pin HIGH or LOW
void setRegisterPin(int index, int value){
  registers[index] = value;
}

Like I promised in the video, here are a few more properly focused pictures:

Plane | List of things to do [Documentation]

So as school and sports start to ramp up, it’s going to get harder and harder to make time for this project as I want to complete it by the first week of summer.

I made some huge progress today, but it’s really still a baby step, the proof of concept using a brushless motor was reassuring that this will be expandable into something  that is powered by brushless motors (some kind of tricopter) but there’s still quite a lot to get done.

 

First things first, I’d like to get started on re-tooling “Vehicle_Companion” to fit the needs of this new communication protocol I’ve established. Before it acted as an intermediate between the Arduinos, and now it shouldn’t have any effect on that at all, and should only supply visual feedback from the controller.

Reason being is that I need to get more feedback from the drone than led brightness levels. Plus I’m getting a little tired of C, it’ll be good to get back into VB for a while.

 

I also need to come up with a way to power the controller. Plain and simple it doesn’t make sense that it’s still tied to a computer.

 

After that I need to start locking down the vehicle’s PCB. I don’t need to do this to the controller as it’s BOUND to go through countless revisions as the vehicle does. Since the RC car is going to be able to be operated basically with just the joystick, It wouldn’t make sense to over complicate things. Here’s a preview of what it may look like.

 

After that it’s time to make some decisions on what the final form of this thing is going to be, I go back and forth because of a few reasons but for now I that some sort of multirotor is going to be the best.

Plane | Ground based system all working! [Demonstration]

Pretty big day for me today. Here’s a video:

I’m pretty proud of this one, the only problem of this is that the l298N get’s too hot, you can see in the pictures that I’ve installed a makeshift heatsink but it still get’s really hot:

Motor Driver 1

I also installed the 5v@3a regulator I mentioned in the last post, here are some pictures:

 

Here’s the vehicle code:

//Serial Handshake declaration
#include  // we'll need this for subString
#define MAX_STRING_LEN 20 // like 3 lines above, change as needed.
const char EOPmarker = '.';  //This is the end of packet marker
char serialbuf[32]; //This gives the incoming serial some room. Change it if you want a longer incoming.

//SoftwareSerial declaration
#include
SoftwareSerial xbee_serial(8, 9);

//Shift Register Pins declaration
int SER_Pin = 10;   //pin 14 on the 75HC595
int RCLK_Pin = 11;  //pin 12 on the 75HC595
int SRCLK_Pin = 12; //pin 11 on the 75HC595
#define number_of_74hc595s 1 //How many of the shift registers - change this
#define numOfRegisterPins number_of_74hc595s * 8 //do not touch
boolean registers[numOfRegisterPins];

//Servo declarations
#include
Servo left_servo;
Servo rght_servo;

//Misc Pin declaration

//inputs
int pot = 1;
int debug_switch1 = 4;

//outputs
int fade_LED = 13;
int x_LED = 5;
int y_LED = 6;
//int debug_switch1_LED = 12;

//Misc Integer declarations
int brightness = 0;    // how bright the LED is
int fadeAmount = 20;    // how many points to fade the LED by

int x_upperTrigger = 600;
int x_lowerTrigger = 400;
int y_upperTrigger = 600;
int y_lowerTrigger = 400;

void setup(){
  Serial.begin(9600);
  xbee_serial.begin(9600);

  pinMode(SER_Pin, OUTPUT);
  pinMode(RCLK_Pin, OUTPUT);
  pinMode(SRCLK_Pin, OUTPUT);
  pinMode(0, INPUT);
  clearRegisters();
  writeRegisters();

  pinMode(pot, INPUT);
  pinMode(debug_switch1, INPUT);

  pinMode(x_LED, OUTPUT);
  pinMode(y_LED, OUTPUT);
  pinMode(fade_LED, OUTPUT);

  xbee_serial.print("0,0,0."); // this is very important as it starts of the loop because it makes "xbee_serial.avalible() > 0.
}

void loop(){
  if (xbee_serial.available() > 0) {
    static int bufpos = 0;
    char inchar = xbee_serial.read();
      if (inchar != EOPmarker) {
        serialbuf[bufpos] = inchar;
        bufpos++;
      }
      else {
        serialbuf[bufpos] = 0; //restart the buff
        bufpos = 0; //restart the position of the buff

          handshake();
          debug_handshake();

          setRegisterPin(1, HIGH);
          writeRegisters();

    }
  }
}

void handshake(){
  //input, recived from controller
  // led1val,ledval2,fade_LEDvalue.

  //analogWrite(x_LED, map(atoi(subStr(serialbuf, "," , 1)),0,1023,0,255));
  //analogWrite(y_LED, map(atoi(subStr(serialbuf, "," , 2)),0,1023,0,255));
  analogWrite(fade_LED, atoi(subStr(serialbuf, "," , 3)));

  brightness = brightness + fadeAmount;
  // reverse the direction of the fading at the ends of the fade:
  if (brightness == 0 || brightness == 255) {
    fadeAmount = -fadeAmount ;
  }

  if (atoi(subStr(serialbuf, "," , 1)) > x_upperTrigger ){
    analogWrite(x_LED, map(atoi(subStr(serialbuf, "," , 1)),512,1023,0,255));
    setRegisterPin(2, HIGH);
    setRegisterPin(3, LOW);
    writeRegisters();
  }

  if (atoi(subStr(serialbuf, "," , 1)) < x_lowerTrigger ){
    analogWrite(x_LED, map(atoi(subStr(serialbuf, "," , 1)),512,0,0,255));
    setRegisterPin(2, LOW);
    setRegisterPin(3, HIGH);
    writeRegisters();
  }

  if (atoi(subStr(serialbuf, "," , 1)) > x_lowerTrigger && atoi(subStr(serialbuf, "," , 1)) < x_upperTrigger){
    setRegisterPin(2, LOW);
    setRegisterPin(3, LOW);
    writeRegisters();
  }

  if (atoi(subStr(serialbuf, "," , 2)) > y_upperTrigger ){
    analogWrite(y_LED, map(atoi(subStr(serialbuf, "," , 2)),512,1023,0,255));
    setRegisterPin(4, HIGH);
    setRegisterPin(5, LOW);
    writeRegisters();
  }

  if (atoi(subStr(serialbuf, "," , 2)) < y_lowerTrigger ){
    analogWrite(y_LED, map(atoi(subStr(serialbuf, "," , 2)),512,0,0,255));
    setRegisterPin(4, LOW);
    setRegisterPin(5, HIGH);
    writeRegisters();
  }

  if (atoi(subStr(serialbuf, "," , 2)) > y_lowerTrigger && atoi(subStr(serialbuf, "," , 2)) < y_upperTrigger){
    setRegisterPin(4, LOW);
    setRegisterPin(5, LOW);
    writeRegisters();
  }

  //output, sent to controller
  //ledpot1,fade_LEDval.
  xbee_serial.print(analogRead(pot));
  xbee_serial.print(",");
  xbee_serial.print(brightness); //This second byte is for the purpose of the program, it is not being used.
  xbee_serial.print("."); //EOP marker
  delay(10);
}

void debug_handshake(){
  //input, recived from controller
  Serial.print("VEHICLE DEBUG: ");
  Serial.print("INPUTS|");
  Serial.print(" x_LED: ");
  Serial.print(map(atoi(subStr(serialbuf, "," , 1)),0,1023,0,255));
  Serial.print(" y_LED: ");
  Serial.print(map(atoi(subStr(serialbuf, "," , 2)),0,1023,0,255));
  Serial.print(" in fade_LED: ");
  Serial.print(atoi(subStr(serialbuf, "," , 3)));

  //output, sent to controller
  Serial.print(" OUTPUTS|");
  Serial.print(" Pot 1: ");
  Serial.print(analogRead(pot));
  Serial.print(" out fade_LED: ");
  Serial.print(brightness);
  Serial.println("");
}

char* subStr (char* input_string, char *separator, int segment_number) {
 char *act, *sub, *ptr;
 static char copy[MAX_STRING_LEN];
 int i;

 strcpy(copy, input_string);

for (i = 1, act = copy; i <= segment_number; i++, act = NULL) {

 sub = strtok_r(act, separator, &ptr);
 if (sub == NULL) break;
 }
 return sub;
}

void clearRegisters(){
  for(int i = numOfRegisterPins - 1; i >=  0; i--){
     registers[i] = LOW;
  }
}

void writeRegisters(){
  digitalWrite(RCLK_Pin, LOW);
  for(int i = numOfRegisterPins - 1; i >=  0; i--){
    digitalWrite(SRCLK_Pin, LOW);
    int val = registers[i];
    digitalWrite(SER_Pin, val);
    digitalWrite(SRCLK_Pin, HIGH);
  }
  digitalWrite(RCLK_Pin, HIGH);
}

//set an individual pin HIGH or LOW
void setRegisterPin(int index, int value){
  registers[index] = value;
}

Here’s the controller code:

//Serial Handshake declaration
#include  // we'll need this for subString
#define MAX_STRING_LEN 20 // like 3 lines above, change as needed.
const char EOPmarker = '.';  //This is the end of packet marker
char serialbuf[32]; //This gives the incoming serial some room. Change it if you want a longer incoming.

//SoftwareSerial declaration
#include
SoftwareSerial xbee_serial(2, 3);

//Mux control pins declarations
int s0 = 8;
int s1 = 9;
int s2 = 10;
int s3 = 11;
int SIG_pin = 0;

//Shift Register Pins declaration
int SER_Pin = 5;   //pin 14 on the 75HC595
int RCLK_Pin = 6;  //pin 12 on the 75HC595
int SRCLK_Pin = 7; //pin 11 on the 75HC595
#define number_of_74hc595s 1 //How many of the shift registers - change this
#define numOfRegisterPins number_of_74hc595s * 8 //do not touch
boolean registers[numOfRegisterPins];

//Servo declarations
int left_servo_val;
int rght_servo_val;

//Misc Pin declaration

//inputs
int debug_switch1 = 4;

//outputs
int pot_LED = 5;
int fade_LED = 6;
int debug_switch1_LED = 2;

//Misc Integer Declarations
int joystick_x;
int joystick_y;

int brightness = 0;    // how bright the LED is
int fadeAmount = 20;    // how many points to fade the LED by

void setup(){
  Serial.begin(9600);
  xbee_serial.begin(9600);

  //mux setup
  pinMode(s0, OUTPUT);
  pinMode(s1, OUTPUT);
  pinMode(s2, OUTPUT);
  pinMode(s3, OUTPUT);
  digitalWrite(s0, LOW);
  digitalWrite(s1, LOW);
  digitalWrite(s2, LOW);
  digitalWrite(s3, LOW);

  //shift register setup
  pinMode(SER_Pin, OUTPUT);
  pinMode(RCLK_Pin, OUTPUT);
  pinMode(SRCLK_Pin, OUTPUT);
  pinMode(0, INPUT);
  clearRegisters();
  writeRegisters();

  //Misc Pin Declarations
  pinMode(pot_LED, OUTPUT);

  xbee_serial.print("0,0,0."); // this is very important as it starts of the loop because it makes "xbee_serial.avalible() > 0.
}

void loop(){
  if (xbee_serial.available() > 0) {
    static int bufpos = 0;
    char inchar = xbee_serial.read();
      if (inchar != EOPmarker) {
        serialbuf[bufpos] = inchar;
        bufpos++;
      }
      else {
        serialbuf[bufpos] = 0; //restart the buff
        bufpos = 0; //restart the position of the buff

        handshake();
    }
  }
}

void handshake(){
  //input, recived from vehicle
  //led1.
  analogWrite(pot_LED, map(atoi(subStr(serialbuf, "," , 1)),0,1023,0,255));
  analogWrite(fade_LED, atoi(subStr(serialbuf, "," , 2)));

  brightness = brightness + fadeAmount;
  // reverse the direction of the fading at the ends of the fade:
  if (brightness == 0 || brightness == 255) {
    fadeAmount = -fadeAmount ;
  }

  //output, sent to vehicle
  //joystick1_ledval,joystick2_ledval,fade_LED.
  analogRemap();
  xbee_serial.print(joystick_x); // Value that it sends over the serial
  xbee_serial.print(",");
  xbee_serial.print(joystick_y); //This second byte is for the purpose of the program, it is not being used.
  xbee_serial.print(",");
  xbee_serial.print(brightness);
  xbee_serial.print("."); //EOP marker
  delay(10);
}

void debug_handshake(){

}

void analogRemap(){
  joystick_x = readMux(15);
  joystick_y = readMux(14);
}

char* subStr (char* input_string, char *separator, int segment_number) {
 char *act, *sub, *ptr;
 static char copy[MAX_STRING_LEN];
 int i;

 strcpy(copy, input_string);

for (i = 1, act = copy; i <= segment_number; i++, act = NULL) {

 sub = strtok_r(act, separator, &ptr);
 if (sub == NULL) break;
 }
 return sub;
}

int readMux(int channel){
  int controlPin[] = {s0, s1, s2, s3};
  int muxChannel[16][4]={
    {0,0,0,0}, //channel 0
    {1,0,0,0}, //channel 1
    {0,1,0,0}, //channel 2
    {1,1,0,0}, //channel 3
    {0,0,1,0}, //channel 4
    {1,0,1,0}, //channel 5
    {0,1,1,0}, //channel 6
    {1,1,1,0}, //channel 7
    {0,0,0,1}, //channel 8
    {1,0,0,1}, //channel 9
    {0,1,0,1}, //channel 10
    {1,1,0,1}, //channel 11
    {0,0,1,1}, //channel 12
    {1,0,1,1}, //channel 13
    {0,1,1,1}, //channel 14
    {1,1,1,1}  //channel 15
  };

  //loop through the 4 sig
  for(int i = 0; i < 4; i ++){
    digitalWrite(controlPin[i], muxChannel[channel][i]);
  }

  //read the value at the SIG pin
  int val = analogRead(SIG_pin);

  //return the value
  return val;
}

void clearRegisters(){
  for(int i = numOfRegisterPins - 1; i >=  0; i--){
     registers[i] = LOW;
  }
}

void writeRegisters(){
  digitalWrite(RCLK_Pin, LOW);
  for(int i = numOfRegisterPins - 1; i >=  0; i--){
    digitalWrite(SRCLK_Pin, LOW);
    int val = registers[i];
    digitalWrite(SER_Pin, val);
    digitalWrite(SRCLK_Pin, HIGH);
  }
  digitalWrite(RCLK_Pin, HIGH);
}

//set an individual pin HIGH or LOW
void setRegisterPin(int index, int value){
  registers[index] = value;
}

I’m verrry proud of the progress thus far. As for next steps, I need to lock down the vehicle circuit into a soldered perf-board, and I need to come up with a better power solution for the controller. Thanks for reading!

Plane | Powering and Dual Motor Speed + Direction Control [Documentation]

Okay this post is going to be pretty media heavy, here’s a video of the overview of the system:

There are 4 main systems at work here, and like the video said I’ll be going over all of them.

The first is the power system. At it’s core, it’s a Turnigy 5000mAh 3S 20C Lipo Battery Pack that is fed through two voltage converters. The first is 12v-9v@3A and the second is 12v-5v@3A. They are connected all via screw terminals in case they blow out. This all is fed through a large switch before it is fed into the controller and the motor driver, so it can all be cut off at a moments notice.

Here’s a video of me explaining that:

And here are some more detailed pictures:

This is the bottom, I’m still not great at going from breadboard to perfboard so bear with me.

And here’s the top without the 5v module installed, but it would be exactly the same as the 9v one that is:

Power_Top

From there we go to the controller. It’s an Arduino Micro connected to a UartSBee V4 with a XBee Pro 60mW Wire Antenna – Series 1 (802.15.4) installed (the same goes for the controller). It also has a 74HC595 to free up pins which drive LED’s and the motor driver:

Here are some pictures:

Here’s the code:

//Serial Handshake declaration
#include <string.h> // we'll need this for subString
#define MAX_STRING_LEN 20 // like 3 lines above, change as needed.
const char EOPmarker = '.';  //This is the end of packet marker
char serialbuf[32]; //This gives the incoming serial some room. Change it if you want a longer incoming.

//SoftwareSerial declaration
#include <SoftwareSerial.h>
SoftwareSerial xbee_serial(8, 9);

//Shift Register Pins declaration
int SER_Pin = 10;   //pin 14 on the 75HC595
int RCLK_Pin = 11;  //pin 12 on the 75HC595
int SRCLK_Pin = 12; //pin 11 on the 75HC595
#define number_of_74hc595s 1 //How many of the shift registers - change this
#define numOfRegisterPins number_of_74hc595s * 8 //do not touch
boolean registers[numOfRegisterPins];

//Servo declarations
#include <Servo.h>
Servo left_servo;
Servo rght_servo;

//Misc Pin declaration

//inputs
int pot = 1;
int debug_switch1 = 4;

//outputs
int fade_LED = 3;
int x_LED = 5;
int y_LED = 6;
//int debug_switch1_LED = 12;

//Misc Integer declarations
int brightness = 0;    // how bright the LED is
int fadeAmount = 20;    // how many points to fade the LED by

int x_upperTrigger = 600;
int x_lowerTrigger = 400;
int y_upperTrigger = 600;
int y_lowerTrigger = 400;

void setup(){
  Serial.begin(9600);
  xbee_serial.begin(9600);

  pinMode(SER_Pin, OUTPUT);
  pinMode(RCLK_Pin, OUTPUT);
  pinMode(SRCLK_Pin, OUTPUT);
  pinMode(0, INPUT);
  clearRegisters();
  writeRegisters();

  pinMode(pot, INPUT);
  pinMode(debug_switch1, INPUT);

  pinMode(x_LED, OUTPUT);
  pinMode(y_LED, OUTPUT);
  pinMode(fade_LED, OUTPUT);

  xbee_serial.print("0,0,0."); // this is very important as it starts of the loop because it makes "xbee_serial.avalible() > 0.
}

void loop(){
  if (xbee_serial.available() > 0) {
    static int bufpos = 0;
    char inchar = xbee_serial.read();
      if (inchar != EOPmarker) {
        serialbuf[bufpos] = inchar;
        bufpos++;
      }
      else {
        serialbuf[bufpos] = 0; //restart the buff
        bufpos = 0; //restart the position of the buff

          handshake();
          debug_handshake();

          setRegisterPin(1, HIGH);
          writeRegisters();

    }
  }
}

void handshake(){
  //input, recived from controller
  // led1val,ledval2,fade_LEDvalue.

  //analogWrite(x_LED, map(atoi(subStr(serialbuf, "," , 1)),0,1023,0,255));
  //analogWrite(y_LED, map(atoi(subStr(serialbuf, "," , 2)),0,1023,0,255));
  analogWrite(fade_LED, atoi(subStr(serialbuf, "," , 3)));

  brightness = brightness + fadeAmount;
  // reverse the direction of the fading at the ends of the fade:
  if (brightness == 0 || brightness == 255) {
    fadeAmount = -fadeAmount ;
  }

  if (atoi(subStr(serialbuf, "," , 1)) > x_upperTrigger ){
    analogWrite(x_LED, map(atoi(subStr(serialbuf, "," , 1)),512,1023,0,255));
    setRegisterPin(2, HIGH);
    setRegisterPin(3, LOW);
    writeRegisters();
  }

  if (atoi(subStr(serialbuf, "," , 1)) < x_lowerTrigger ){
    analogWrite(x_LED, map(atoi(subStr(serialbuf, "," , 1)),512,0,0,255));
    setRegisterPin(2, LOW);
    setRegisterPin(3, HIGH);
    writeRegisters();
  }

  if (atoi(subStr(serialbuf, "," , 1)) > x_lowerTrigger && atoi(subStr(serialbuf, "," , 1)) < x_upperTrigger){
    setRegisterPin(2, LOW);
    setRegisterPin(3, LOW);
    writeRegisters();
  }

  if (atoi(subStr(serialbuf, "," , 2)) > y_upperTrigger ){
    analogWrite(y_LED, map(atoi(subStr(serialbuf, "," , 2)),512,1023,0,255));
    setRegisterPin(4, HIGH);
    setRegisterPin(5, LOW);
    writeRegisters();
  }

  if (atoi(subStr(serialbuf, "," , 2)) < y_lowerTrigger ){
    analogWrite(y_LED, map(atoi(subStr(serialbuf, "," , 2)),512,0,0,255));
    setRegisterPin(4, LOW);
    setRegisterPin(5, HIGH);
    writeRegisters();
  }

  if (atoi(subStr(serialbuf, "," , 2)) > y_lowerTrigger && atoi(subStr(serialbuf, "," , 2)) < y_upperTrigger){
    setRegisterPin(4, LOW);
    setRegisterPin(5, LOW);
    writeRegisters();
  }

  //output, sent to controller
  //ledpot1,fade_LEDval.
  xbee_serial.print(analogRead(pot));
  xbee_serial.print(",");
  xbee_serial.print(brightness); //This second byte is for the purpose of the program, it is not being used.
  xbee_serial.print("."); //EOP marker
  delay(10);
}

void debug_handshake(){
  //input, recived from controller
  Serial.print("VEHICLE DEBUG: ");
  Serial.print("INPUTS|");
  Serial.print(" x_LED: ");
  Serial.print(map(atoi(subStr(serialbuf, "," , 1)),0,1023,0,255));
  Serial.print(" y_LED: ");
  Serial.print(map(atoi(subStr(serialbuf, "," , 2)),0,1023,0,255));
  Serial.print(" in fade_LED: ");
  Serial.print(atoi(subStr(serialbuf, "," , 3)));

  //output, sent to controller
  Serial.print(" OUTPUTS|");
  Serial.print(" Pot 1: ");
  Serial.print(analogRead(pot));
  Serial.print(" out fade_LED: ");
  Serial.print(brightness);
  Serial.println("");
}

char* subStr (char* input_string, char *separator, int segment_number) {
 char *act, *sub, *ptr;
 static char copy[MAX_STRING_LEN];
 int i;

 strcpy(copy, input_string);

for (i = 1, act = copy; i <= segment_number; i++, act = NULL) {

 sub = strtok_r(act, separator, &ptr);
 if (sub == NULL) break;
 }
 return sub;
}

void clearRegisters(){
  for(int i = numOfRegisterPins - 1; i >=  0; i--){
     registers[i] = LOW;
  }
}

void writeRegisters(){
  digitalWrite(RCLK_Pin, LOW);
  for(int i = numOfRegisterPins - 1; i >=  0; i--){
    digitalWrite(SRCLK_Pin, LOW);
    int val = registers[i];
    digitalWrite(SER_Pin, val);
    digitalWrite(SRCLK_Pin, HIGH);
  }
  digitalWrite(RCLK_Pin, HIGH);
}

//set an individual pin HIGH or LOW
void setRegisterPin(int index, int value){
  registers[index] = value;
}

Next is the motor driver. It’s built around the L298N. Here’s the video

Here are pictures:

It’s my first real use of a perfboard to make a project more permanent which is why it looks awful, but this is what it should look like:

Image generated by fritzing.

The last system is the controller. It’s an arduino micro hooked up to the same xbee system as seen earlier with a joystick and a multiplexer for more inputs. Here’s a video:

And some pictures:

So basically it receives and sends data to and from the controller as seen in the following code:

//Serial Handshake declaration
#include <string.h> // we'll need this for subString
#define MAX_STRING_LEN 20 // like 3 lines above, change as needed.
const char EOPmarker = '.'; //This is the end of packet marker
char serialbuf[32]; //This gives the incoming serial some room. Change it if you want a longer incoming.

//SoftwareSerial declaration
#include <SoftwareSerial.h>
SoftwareSerial xbee_serial(2, 3);

//Mux control pins declarations
int s0 = 8;
int s1 = 9;
int s2 = 10;
int s3 = 11;
int SIG_pin = 0;

//Shift Register Pins declaration
int SER_Pin = 5; //pin 14 on the 75HC595
int RCLK_Pin = 6; //pin 12 on the 75HC595
int SRCLK_Pin = 7; //pin 11 on the 75HC595
#define number_of_74hc595s 1 //How many of the shift registers - change this
#define numOfRegisterPins number_of_74hc595s * 8 //do not touch
boolean registers[numOfRegisterPins];

//Servo declarations
int left_servo_val;
int rght_servo_val;

//Misc Pin declaration

//inputs
int debug_switch1 = 4;

//outputs
int pot_LED = 5;
int fade_LED = 6;
int debug_switch1_LED = 2;

//Misc Integer Declarations
int joystick_x;
int joystick_y;

int brightness = 0; // how bright the LED is
int fadeAmount = 20; // how many points to fade the LED by

void setup(){
 Serial.begin(9600);
 xbee_serial.begin(9600);

 //mux setup
 pinMode(s0, OUTPUT);
 pinMode(s1, OUTPUT);
 pinMode(s2, OUTPUT);
 pinMode(s3, OUTPUT);
 digitalWrite(s0, LOW);
 digitalWrite(s1, LOW);
 digitalWrite(s2, LOW);
 digitalWrite(s3, LOW);

 //shift register setup
 pinMode(SER_Pin, OUTPUT);
 pinMode(RCLK_Pin, OUTPUT);
 pinMode(SRCLK_Pin, OUTPUT);
 pinMode(0, INPUT);
 clearRegisters();
 writeRegisters();

 //Misc Pin Declarations
 pinMode(pot_LED, OUTPUT);

xbee_serial.print("0,0,0."); // this is very important as it starts of the loop because it makes "xbee_serial.avalible() > 0.
}

void loop(){
 if (xbee_serial.available() > 0) {
 static int bufpos = 0;
 char inchar = xbee_serial.read();
 if (inchar != EOPmarker) {
 serialbuf[bufpos] = inchar;
 bufpos++;
 }
 else {
 serialbuf[bufpos] = 0; //restart the buff
 bufpos = 0; //restart the position of the buff

 handshake();
 }
 }
}

void handshake(){
 //input, recived from vehicle
 //led1.
 analogWrite(pot_LED, map(atoi(subStr(serialbuf, "," , 1)),0,1023,0,255));
 analogWrite(fade_LED, atoi(subStr(serialbuf, "," , 2)));

 brightness = brightness + fadeAmount;
 // reverse the direction of the fading at the ends of the fade:
 if (brightness == 0 || brightness == 255) {
 fadeAmount = -fadeAmount ;
 }

 //output, sent to vehicle
 //joystick1_ledval,joystick2_ledval,fade_LED.
 analogRemap();
 xbee_serial.print(joystick_x); // Value that it sends over the serial
 xbee_serial.print(",");
 xbee_serial.print(joystick_y); //This second byte is for the purpose of the program, it is not being used.
 xbee_serial.print(",");
 xbee_serial.print(brightness);
 xbee_serial.print("."); //EOP marker
 delay(10);
}

void debug_handshake(){

}

void analogRemap(){
 joystick_x = readMux(15);
 joystick_y = readMux(14);
}
char* subStr (char* input_string, char *separator, int segment_number) {
 char *act, *sub, *ptr;
 static char copy[MAX_STRING_LEN];
 int i;

 strcpy(copy, input_string);

for (i = 1, act = copy; i <= segment_number; i++, act = NULL) {

 sub = strtok_r(act, separator, &ptr);
 if (sub == NULL) break;
 }
 return sub;
}

int readMux(int channel){
 int controlPin[] = {s0, s1, s2, s3};
 int muxChannel[16][4]={
 {0,0,0,0}, //channel 0
 {1,0,0,0}, //channel 1
 {0,1,0,0}, //channel 2
 {1,1,0,0}, //channel 3
 {0,0,1,0}, //channel 4
 {1,0,1,0}, //channel 5
 {0,1,1,0}, //channel 6
 {1,1,1,0}, //channel 7
 {0,0,0,1}, //channel 8
 {1,0,0,1}, //channel 9
 {0,1,0,1}, //channel 10
 {1,1,0,1}, //channel 11
 {0,0,1,1}, //channel 12
 {1,0,1,1}, //channel 13
 {0,1,1,1}, //channel 14
 {1,1,1,1} //channel 15
 };

//loop through the 4 sig
 for(int i = 0; i < 4; i ++){
 digitalWrite(controlPin[i], muxChannel[channel][i]);
 }

//read the value at the SIG pin
 int val = analogRead(SIG_pin);

//return the value
 return val;
}

void clearRegisters(){
 for(int i = numOfRegisterPins - 1; i >= 0; i--){
 registers[i] = LOW;
 }
}

void writeRegisters(){
 digitalWrite(RCLK_Pin, LOW);
 for(int i = numOfRegisterPins - 1; i >= 0; i--){
 digitalWrite(SRCLK_Pin, LOW);
 int val = registers[i];
 digitalWrite(SER_Pin, val);
 digitalWrite(SRCLK_Pin, HIGH);
 }
 digitalWrite(RCLK_Pin, HIGH);
}

//set an individual pin HIGH or LOW
void setRegisterPin(int index, int value){
 registers[index] = value;
}

All of the parts listed in this video can be seen here which is the parts list.

That was a huge post! Thanks for reading and leave a comment if you have any questions.

Plane | Working handshake code demo

First off, here’s a video:

If you’re a long time follower of the blog, than you may notice that it looks like I’m backtracking here. Let me go over the differences between the two systems I’ve developed.

The one I “finished” a few months ago can be found here. While the code is “good” and it works well for what it does, there are a few inherent problems with it. The first being that it has to have a computer to be used. The second being that the computer running the intermediate program has to be extremely fast, so it’s not totally feasible for field use. It would also be very hard for it to go wireless, but I had built that groundwork in so it could happen.

The one I’m working on now doesn’t require a computer as an intermediate, and is going to be totally wireless as from the start.

This morning I finished the handshake data exchange over xbee. Right now it’s just dimming a few LED’s but if you take a peek at the following code, it’s very expandable.

Here’s the working code:

 

#include <SoftwareSerial.h>
SoftwareSerial xbee_serial(2, 3); 
#include <string.h> // we'll need this for subString
#define MAX_STRING_LEN 20 // like 3 lines above, change as needed. 

int in_LED = 10;
int out_LED = 11;

int input = 2;

int sendval;


//serial stuff
const char EOPmarker = '.';  //This is the end of packet marker
char serialbuf[32]; //This gives the incoming serial some room. Change it if you want a longer incoming.

void setup(){
  pinMode(in_LED, OUTPUT);
  pinMode(out_LED, OUTPUT);
  pinMode(input, INPUT);
  
  Serial.begin(9600);
  xbee_serial.begin(9600);
  
  xbee_serial.print("0,0,0."); // this is very important as it starts of the loop because it makes "xbee_serial.avalible() > 0. 
}

void loop(){
  if (xbee_serial.available() > 0) { 
    static int bufpos = 0;
    char inchar = xbee_serial.read();
      if (inchar != EOPmarker) { 
        serialbuf[bufpos] = inchar; 
        bufpos++; 
      }
      else {
        serialbuf[bufpos] = 0; //restart the buff
        bufpos = 0; //restart the position of the buff

        Serial.println(atoi(subStr(serialbuf, "," , 1)));
        analogWrite(in_LED, atoi(subStr(serialbuf, "," , 1)));
        
         sendval = map(analogRead(input), 0, 1023, 0, 255);
         xbee_serial.print(sendval); // Value that it sends over the serial
         xbee_serial.print(",");
         xbee_serial.print("100"); //This second byte is for the purpose of the program, it is not being used. 
         xbee_serial.print("."); //EOP marker
         analogWrite(out_LED , sendval);
        
    }
  }
  
  //delay(10);
}

char* subStr (char* input_string, char *separator, int segment_number) {
 char *act, *sub, *ptr;
 static char copy[MAX_STRING_LEN];
 int i;
 
 strcpy(copy, input_string);
 
for (i = 1, act = copy; i <= segment_number; i++, act = NULL) {
 
 sub = strtok_r(act, separator, &ptr);
 if (sub == NULL) break;
 }
 return sub;
}

Plane | Working Handshake Code

This works so I want to write it down:

 

#include <SoftwareSerial.h>
SoftwareSerial xbee_serial(2, 3); 
#include <string.h> // we'll need this for subString
#define MAX_STRING_LEN 20 // like 3 lines above, change as needed. 

int in_LED = 10;
int out_LED = 11;

int input = 2;

int sendval;


//serial stuff
const char EOPmarker = '.';  //This is the end of packet marker
char serialbuf[32]; //This gives the incoming serial some room. Change it if you want a longer incoming.

void setup(){
  pinMode(in_LED, OUTPUT);
  pinMode(out_LED, OUTPUT);
  pinMode(input, INPUT);
  
  Serial.begin(9600);
  xbee_serial.begin(9600);
  
  xbee_serial.print("0,0,0.");
}

void loop(){
  if (xbee_serial.available() > 0) { 
    static int bufpos = 0;
    char inchar = xbee_serial.read();
      if (inchar != EOPmarker) { 
        serialbuf[bufpos] = inchar; 
        bufpos++; 
      }
      else {
        serialbuf[bufpos] = 0; //restart the buff
        bufpos = 0; //restart the position of the buff

        Serial.println(atoi(subStr(serialbuf, "," , 1)));
        analogWrite(in_LED, atoi(subStr(serialbuf, "," , 1)));
        
         sendval = map(analogRead(input), 0, 1023, 0, 255);
         xbee_serial.print(sendval); // Value that it sends over the serial
         xbee_serial.print(",");
         xbee_serial.print("100"); //This second byte is for the purpose of the program, it is not being used. 
         xbee_serial.print("."); //EOP marker
         analogWrite(out_LED , sendval);
        
    }
  }
  
  delay(10);
}

char* subStr (char* input_string, char *separator, int segment_number) {
 char *act, *sub, *ptr;
 static char copy[MAX_STRING_LEN];
 int i;
 
 strcpy(copy, input_string);
 
for (i = 1, act = copy; i <= segment_number; i++, act = NULL) {
 
 sub = strtok_r(act, separator, &ptr);
 if (sub == NULL) break;
 }
 return sub;
}

Plane | Transmitting Analog Values with Xbee

I made some progress today, here’s a video:

Basically this is a proof of concept. The transmitter is sending a line of data very similar to the one that will be sent by the final controller (as seen in the controller code) the receiving end with be receiving in the same way the vehicle code does (same as above).
Here are a few pictures, this first one is a top down view of my prototyping area:
This second one shows all components involved:
This is the code running on the transmitter side, the side with the pot that’s transmitting it’s analog value:
</div>
<div>

#include <SoftwareSerial.h>
SoftwareSerial xbee_serial(2, 3);

int pot_1 = 0;
int LED_1 = 5; //this will serve as an LED to compare to
int sendval;

void setup(){
 pinMode(pot_1, INPUT);
 pinMode(LED_1, OUTPUT);
 Serial.begin(9600);
 xbee_serial.begin(9600);
}

void loop(){
 Serial.println(analogRead(pot_1));
 sendval = map(analogRead(pot_1), 0, 1023, 0, 255);
 xbee_serial.print(sendval); // Value that it sends over the serial
 xbee_serial.print(",");
 xbee_serial.print("100"); //This second byte is for the purpose of the program, it is not being used.
 xbee_serial.print("."); //EOP marker
 analogWrite(LED_1,sendval);
 //delay(100);
}

This second half is on the receiving end. It may seem way overkill for what it does, but it’s all expandable to a pretty much infinite amount of data to be transmitted. For an example of what it’s capable of see this video:
</div>
<div>

#include <SoftwareSerial.h>
SoftwareSerial xbee_serial(2, 3);
#include <string.h> // we'll need this for subString
#define MAX_STRING_LEN 20 // like 3 lines above, change as needed.

int LED_1 = 5;

int led_val;

//serial stuff
const char EOPmarker = '.'; //This is the end of packet marker
char serialbuf[32]; //This gives the incoming serial some room. Change it if you want a longer incoming.

void setup(){
 pinMode(LED_1, OUTPUT);
 Serial.begin(9600);
 xbee_serial.begin(9600);
}

void loop(){
 if (xbee_serial.available() > 0) {
 static int bufpos = 0;
 char inchar = xbee_serial.read();
 if (inchar != EOPmarker) {
 serialbuf[bufpos] = inchar;
 bufpos++;
 }
 else {
 serialbuf[bufpos] = 0; //restart the buff
 bufpos = 0; //restart the position of the buff

Serial.println(atoi(subStr(serialbuf, "," , 1)));
 analogWrite(LED_1, atoi(subStr(serialbuf, "," , 1)));
 }
 }
}

char* subStr (char* input_string, char *separator, int segment_number) {
 char *act, *sub, *ptr;
 static char copy[MAX_STRING_LEN];
 int i;

 strcpy(copy, input_string);

for (i = 1, act = copy; i <= segment_number; i++, act = NULL) {

 sub = strtok_r(act, separator, &ptr);
 if (sub == NULL) break;
 }
 return sub;

}

Plane | First Functioning Xbee test

So the first round of parts have come in for the plane, including the Xbees and the UartSBee V4s. My life is going to be very scattered over the next 4 or 5 months, so I’m going to be making frequent rudimentary posts for my own benefit.

Here’s a video:

First thing’s first I want to outline how everything’s connected.

The first xbee is connected to the first UartSBee which is connected to an Ardunio Uno which is connected to the first computer which has the console open and is looking at the serial stream at 9600 baud. The xbee is connected to the uno via Software Serial which is detailed in the code below. Here’s a picture:

 

The second setup is identical, except i’m using an Ardunio nano.

Here’s the code, I’m using the SoftwareSerial library to accomplish this. Both Arduinos are running the same thing.

</p>
#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11); // RX, TX

void setup()
{
 // Open serial communications and wait for port to open:
 Serial.begin(9600);
 while (!Serial) {
 ; // wait for serial port to connect. Needed for Leonardo only
 }
 Serial.println("Goodnight moon!");

// set the data rate for the SoftwareSerial port
 mySerial.begin(9600);
 mySerial.println("Hello, world?");
}

void loop() // run over and over
{
 if (mySerial.available())
 Serial.write(mySerial.read());
 if (Serial.available())
 mySerial.write(Serial.read());
}
<p style="text-align: left;">

Here are a few pictures of the X-TCU setup. The baud is at 9600 and the pan ID is 115. The UartSbee itself is running at 115200 baud connected to the computer.

Thanks for reading!