This is a project for the Georgia Tech class ECE 4180 (Embedded Systems Design) with Dr. Hamblen.
Team Members:
Landon Ballard
Alex Jostar
Sriharsha Singam
Parts Used:
Mbed LPC1768
Raspberry Pi 4
Xbox or Playstation Remote Controller
Bluetooth Module HC-06
Class D Audio Amp
Couple of LEDs
Lidar VL53L0X
H-Bridge
Pin Outs:
Raspberry Pi 4
Raspberry Pi 4
Logitech Web Camera
Usb Port
Usb Camera Cable
Bluetooth Module HC-06
Mbed
HC-06
Vu (5V)
VCC
GND
GND
p14
Tx
p13
Rx
Note: *The C# program connects to a COM port opened by the HC-06 chip. *Default pin to pair the HC-06 is 1234. *The C# program uses default windows libraries. *Sends data as character strings.
Class D Audio Amp
Mbed
Class-D Audio Amp
Battery
p5
S (pull low with 180ohm)
p23
ln+
GND
ln-
PWR+
5v from voltage regulator on batteries
GND
PWR-
Spkr+
Out+
Spkr-
Out-
Lidar VL53L0X
Mbed
VL53L0X
p28
SDA
p27
SCL
p26
shdn
Vout(3.3V)
VCC
GND
GND
H-Bridge
Mbed
H-Bridge
Motors
Battery
VM
Batteries + (6V from the AA battery pack)
Vout(3.3V)
VCC
GND
All GNDs
A01
Black on Right Motor
A02
Red on Right Motor
B01
Black on Left Motor
B02
Red on Left Motor
p21
PWMA
p8
AI1
p7
AI2
Pull high to Vout(3.3V) with a 180ohm resistor
STBY
p9
BI1
p10
BI2
p22
PWMB
LEDs
Mbed
LEDs Purpose
GND
All GNDs
p15
Green 1
p16
Green 2
p18
Red 1
p19
Red 2
MBED Side of the Code
#include "mbed.h"
#include "Motor.h"
#include "XNucleo53L0A1.h"
#define VL53L0_I2C_SDA p28 // To be changed based on Pins
#define VL53L0_I2C_SCL p27 // To be changed based on Pins
DigitalOut shdn(p26);
Motor lm(p21, p7, p8); // pwm, fwd, rev
Motor rm(p22, p6, p10); // pwm, fwd, rev
//BusOut myled(LED1,LED2,LED3,LED4);
Serial BT(p13,p14);
Serial pc(USBTX,USBRX);
BusOut led(p15,p16,p19,p18);
PwmOut spkr(p23);
DigitalOut spkrenable(p5);
static XNucleo53L0A1 *board=NULL;
bool stopMotor = false;
bool turbo = false;
float getSpeed(char& value) {
float ones, tens = 0, hundreds, n2, n3, dot;
dot = BT.getc();
n2 = BT.getc();
n3 = BT.getc();
ones = (float)(value -'0');
tens = (float)(n2 -'0');
tens = tens / 10.00;
hundreds = (float)(n3 - '0');
hundreds = hundreds/100.00;
return (ones + tens + hundreds);
}
void setMotorSpeed(Motor* motor, float mspeed) {
if(mspeed <= 1.0){
if(abs(mspeed) > 0.2 && !stopMotor || mspeed > .2){
pc.printf("%0.2f is the motor speed\n\r", mspeed);
if(turbo)
motor->speed(mspeed);
if(!turbo)
motor->speed(mspeed/1.25);
}
else
motor->speed(0);
}
}
void btMotorUpdate(Motor* motor) {
char PlusMinus = BT.getc();
if(PlusMinus == '-'){
char n1 = BT.getc();
setMotorSpeed(motor, -(getSpeed(n1)));
} else {
setMotorSpeed(motor, getSpeed(PlusMinus));
}
}
void btSerialInterrupt() {
char LRABYX = BT.getc();
if(LRABYX == 'L'){
btMotorUpdate(&lm);
}
if(LRABYX == 'R') {
btMotorUpdate(&rm);
}
if(LRABYX == 'A') {
turbo = true;
}
if(LRABYX == 'B') {
turbo = false;
}
}
int main() {
DevI2C *device_i2c = new DevI2C(VL53L0_I2C_SDA, VL53L0_I2C_SCL);
board = XNucleo53L0A1::instance(device_i2c, A2, D8, D2);
uint32_t distance;
shdn = 0; //must reset sensor for an mbed reset to work
wait(0.1);
shdn = 1;
wait(0.1);
/* init the 53L0A1 board with default values */
int status = board->init_board();
while (status) {
status = board->init_board();
}
BT.attach(&btSerialInterrupt);
lm.speed(0);
rm.speed(0);
led.write(0);
spkrenable = 0;
while (1) {
status = board->sensor_centre->get_distance(&distance);
if (status == VL53L0X_ERROR_NONE) {
pc.printf("%d\n\r",distance);
if (distance < 300) { // Distance might need to be adjusted
stopMotor = true;
led.write(15*!led.read());
spkrenable = 1;
spkr = .5;
wait(.1);
spkr = 0;
spkrenable = 0;
}
else{
stopMotor = false;
led.write(0);
}
// Any Lighting or Sound Effects for Crash Detection
}
}
}
C# Windows Program Side of the Code that Connects to an Xbox Controller
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Windows.Gaming.Input;
namespace xboxController
{
public partial class Form1 : Form
{
Gamepad Controller;
Timer t = new Timer();
public Form1()
{
InitializeComponent();
serialPort1.Open();
openit("http://192.168.43.48:8090/test.mjpg");
Gamepad.GamepadAdded += Gamepad_GamepadAdded;
Gamepad.GamepadRemoved += Gamepad_GamepadRemoved;
t.Tick += T_Tick;
t.Interval = 50;
t.Start();
}
private void T_Tick(object sender, EventArgs e)
{
if(Gamepad.Gamepads.Count > 0)
{
Controller = Gamepad.Gamepads.First();
var Reading = Controller.GetCurrentReading();
double LY = -Reading.LeftThumbstickY;
//double LX = Reading.LeftThumbstickX;
double RY = -Reading.RightThumbstickY;
//double RX = Reading.RightThumbstickX;
//double RT = Reading.RightTrigger;
//double LT = Reading.LeftTrigger;
serialPort1.Write("L" + RY.ToString("0.00"));
serialPort1.Write("R" + LY.ToString("0.00"));
switch (Reading.Buttons)
{
case GamepadButtons.A:
serialPort1.Write("A");
break;
case GamepadButtons.B:
serialPort1.Write("B");
break;
}
Debug.WriteLine("R" + LY.ToString("0.00"));
Debug.WriteLine("L" + RY.ToString("0.00"));
}
}
private async void Gamepad_GamepadRemoved(object sender, Gamepad e)
{
await Log("Controller Removed");
}
private async void Gamepad_GamepadAdded(object sender, Gamepad e)
{
await Log("Controller Added");
}
private async Task Log(string txt)
{
Task t = Task.Run(() =>
{
Debug.WriteLine(DateTime.Now.ToShortTimeString() + ":" + txt);
});
await t;
}
private void Form1_Load(object sender, EventArgs e)
{
}
public static void openit(string x)
{
System.Diagnostics.Process.Start("cmd", "/C start" + " " + x);
}
}
}
This site uses cookies to store information on your computer.
By continuing to use our site, you consent to our cookies.
If you are not happy with the use of these cookies, please review our
Cookie Policy
to learn how they can be disabled.
By disabling cookies, some features of the site will not work.
Access Warning
You do not have the correct permissions to perform this operation.