Mini robotwars

The place to share and discuss your Ultibo projects.
Gavinmc42
Posts: 1552
Joined: Sun Jun 05, 2016 12:38 pm
Location: Brisbane, Australia

Mini robotwars

Postby Gavinmc42 » Fri Jan 25, 2019 12:37 pm

I really like this BLE uart mode, the old BT SPP was a real pain.
Basic Arduino code for a Microbit BLE robot controller.
Now to get Ultibo BLE uart receiver working.

The idea is to have microbits as Pi Zero W robot controllers.
Number on microbit to match the robot.
The Zero to transmit video with OpenVG overlay via fpv 5.8GHz transmitter.
WiFi not working yet and latency issues?
So these will be used instead.
https://www.nextfpv.com.au/collections/ ... -compliant

Got the idea from the kid playing with these years ago at the Art Galley, kids lined up to play.
https://botbitz.com.au/collections/antw ... rint-files
Been promising him some home made versions.
To test equipment, give it to kids, they can break anything.
So design bots kids can code, make and fix.

Code: Select all

// Example for using Adafruit Bluefruit App to plot accelerometer data

// BLE Serial code Copyright (c) Sandeep Mistry. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

#include <Adafruit_Microbit.h>

// Add accelerometer support
#include "Wire.h"
#include "MMA8653.h"

Adafruit_Microbit microbit;
Adafruit_Microbit_Matrix microbitGFX;
MMA8653 accel;

const uint8_t
  smile_bmp[] =
  { B00000,
    B01010,
    B00000,
    B10001,
    B01110, };
   
 const uint8_t
 no1_bmp[] =
  { B00100,
    B01100,
    B00100,
    B00100,
    B01110, };

void setup() {
  Serial.begin(115200);

  Serial.println("Plotter demo ready!");

  accel.begin(false, 2); // 8-bit mode, 2g range
   
  // custom services and characteristics can be added as well
  microbit.BTLESerial.begin();
  microbit.BTLESerial.setLocalName("microbit");

  // Start LED matrix driver after radio (required)
  microbitGFX.begin();
  pinMode(PIN_BUTTON_A, INPUT);
  pinMode(PIN_BUTTON_B, INPUT);
  microbitGFX.show( no1_bmp);
 
}

void loop() {
  microbit.BTLESerial.poll();
 
  accel.update();
  Serial.print("1");
  Serial.print(", ");
  // print the data on serial port
  if (! digitalRead(PIN_BUTTON_A)) {
    Serial.print("1");
  }
  else if (! digitalRead(PIN_BUTTON_B)) {
    Serial.print("2");
  }
  else {
    Serial.print("0");
  }
 
  Serial.print(", ");
  Serial.print(accel.getX());    Serial.print(", ");
  Serial.print(accel.getY());    Serial.print(", ");
  Serial.println(accel.getZ());

  // send it over bluetooth
  microbit.BTLESerial.print("1");
  microbit.BTLESerial.print(", ");
  // print the data on serial port
  if (! digitalRead(PIN_BUTTON_A)) {
    microbit.BTLESerial.print("1");
  }
  else if (! digitalRead(PIN_BUTTON_B)) {
    microbit.BTLESerial.print("2");
  }
  else {
    microbit.BTLESerial.print("0");
  }
  microbit.BTLESerial.print(", ");
 
  microbit.BTLESerial.print(accel.getX());   
  microbit.BTLESerial.print(",");
  microbit.BTLESerial.print(accel.getY());   
  microbit.BTLESerial.print(",");
  microbit.BTLESerial.println(accel.getZ());

  delay(100);
}
Gavinmc42
Posts: 1552
Joined: Sun Jun 05, 2016 12:38 pm
Location: Brisbane, Australia

Re: Mini robotwars

Postby Gavinmc42 » Sat Jan 26, 2019 1:14 pm

Been going back through all the Bluetooth posts catching up and understanding stuff I did not back 2 years ago.

Still a bit of Ultibo BLE code to sort out, but Mark has shown the way with Paul's help.
Hard to believe this was just an idea in Dec 2016, now it is possible.
With capabilities I had not considered back then.

Looks like Core Electronics now has the hardware I have been waiting years for.
Good enough to do acceptable Pi Zero prototype bots.
Time to order some motors, drivers and another microbit or two?

Garry, the BLE uart connect, so far, is looking like the easiest BLE mode.
That Arduino code has a number first in the string, the Ultibo code looks for the microbit that has the matching number.
That way the Ultibo client can be self connecting.

Full project will go on my github if I can remember how that works ;)

Very similar code and hardware will do DCC model trains and many other ideas that have been floating around in my head for decades.
BLE controlled indoor modelplanes, drones, blimps, tanks even RC controlled cars/trucks for train layouts..
A very long list I have been making for a long time, now becomes possible due to Ultibo.

Autonomous charging with AirFuel :D
Meshnetworked BLE IoT with Ultibo gateways, home automation.....
Latest BT spec will have radio direction finding :D
Gavinmc42
Posts: 1552
Joined: Sun Jun 05, 2016 12:38 pm
Location: Brisbane, Australia

Re: Mini robotwars

Postby Gavinmc42 » Wed Feb 20, 2019 12:08 pm

Work in progress getting the Microbit compass going.
Putting code here as i seem to lose track of it.
Lost my Ultibo code that tested the Microbit accel :oops:

Got an idea for Flightgear Pi based OpenVG instruments.
Expand the PFD demo into Cessna 172 6 pack instrument using OpenVG.
Flightgear data has SVG files for these :D
But how to test the display changing with data?

Without OTG USB serial on the Zero, Bluetooth LE serial is an option.
MicroBit sends accel sensor data as roll, tilt, yaw and compass sensor sends heading.

Buttons can be used as throttle.

The advantage of using Bluetooth comms is this can then be easily turned into a Robot rover basestation display.
Even drone or RPV base station.
Bluetooth serial can be swapped for LoRa serial transceiver for longer range

Code: Select all

#include "Wire.h"
#include <SparkFun_MAG3110.h>
#include <Adafruit_Microbit.h>

Adafruit_Microbit_Matrix microbit;
MAG3110 compass = MAG3110();  // The compass chip
int baseline = 0;
int x, y, z;             

void setup() {
   Serial.begin(115200);

  Serial.println("Plotter demo ready!");
  microbit.begin();
  compass.initialize();       // Initializes the compass chip
  compass.start();            // Puts the sensor in active mode
  baseline = readStrength();  // Take a baseline reading of magnetic strength
  delay(500);

}

void loop() {
  if (abs(readStrength() - baseline) > 15000) {
    // Magnetic field strength increased by 15000
    microbit.show(microbit.NO);
  }
  else {
    microbit.clear();
     
     readStrength();
     Serial.print(x); Serial.print(", ");
     Serial.print(y); Serial.print(", ");
     Serial.print(z); Serial.print(", ");
     Serial.println("");
  }
}

int readStrength() {
 
  while(!compass.dataReady()) {};   // Wait for data to become available to read
  compass.readMag(&x, &y, &z);      // Read data into variables
  // calculate the RMS power combining x, y and z readings
  int power = sqrt((sq(float(x)) + sq(float(y)) + sq(float(z))) / 3);
  return power;
}

Return to “Projects”

Who is online

Users browsing this forum: No registered users and 2 guests