Search
  • Joe Linogao

How to Assemble the Elegoo Tumbller Buggy (with custom code)


So, it finally came. The Elegoo Tumbller Buggy actually came. In this blog, I will be going over the process of assembling the Elegoo buggy. Additionally, I will be showing you some of the custom code I uploaded to the buggy for testing, as well as the various modifications I made. So without further adieu...let's get started!

What Comes in the Box?

Below is a list of all the bits and bobs that come with the box. This ranges from building parts to electronic components. Let's have a look at them now!


I was actually very impressed with how everything was packaged. All the boxes and bags inside were labelled with numbers so you knew exactly what to use every step of the way. Just with how nicely laid out it is, this could definitely be a great gift for anyone who's into electronics.

Anyways! After clearing my workspace and preparing all the tools I need (i.e. one screwdriver and some lofi hip hop beats), I got to work.


Assembling the Robot

Assembling just involved following instructions and putting pieces together. Firstly, I attached the motors and wheels to the baseplate of the buggy.

Next, I attached the circuit board to the baseplate using the included screws. The circuit board is actually a pre-soldered prototype board, and it's pretty cool. It includes components such as an Arduino NANO, gyroscope module, and power connectors for the motors. I also attached the front panel too. However, I was planning to replace this with a custom 3D print for the final buggy.

Next, I added the ultrasonic sensor to the board. This sensor will be providing most of the environmental scanning for the buggy as it accurately determines the distance the buggy is away from an obstacle.

I added the poles that would hold the higher panels. On top of those panels, I installed the battery box, which is charged with a USB-B cable. This provides power to all the components through the prototype board.

Finally, after placing the final plate and tightening some screws, I had a completed buggy! You can click through the pictures on the side to check out the photoshoot I did!


Buggy Modifications

While the buggy comes with code that allows it to balance by itself, the number of specific commands that it requires proved to be too much for my needs. Since the buggy was going to go through an obstacle course (i.e. it required custom code to be uploaded), having the buggy balance by itself seemed unnecessary. To account for this, I had to create stabilisers for the buggy. I found through some testing that the buggy required back stabilisers so it wouldn't fall back, and front stabilisers that kept it upright and give it a full range of motion.


To start, let's look at the front stabiliser. Since I had a lot of ping pong balls lying about (thanks to the launcher), I decided to make a housing for a ball, that can be attached to the front of the buggy. This would allow the buggy to have a 3rd wheel that could freely move in any direction, much like the wheel of a shopping cart. I got reference measurements of the original front panel (in particular, the diameters of the drill holes), and used them to create the new part in SOLIDWORKS.

I also created sticks that would act as back stabilisers. This would ensure that the buggy would stay upright no matter what direction it moves in. The back stabiliser only acted as supports and did not have any form of wheels.


Once I was happy with the CAD, I converted them to STL files and printed them on my 3D printer. I went through an iteration process, fine-tuning all the dimensions until the required sizes were achieved. Luckily, it only took me two tries to get the stabilisers right.


The final result is a brand new buggy with top-notch stabilisers!


Uploading a Program onto the Buggy

So with the buggy assembled, it was time to upload some code to it. While the robot has its own code, I needed to be able to edit For this blog, I just wanted it to move around a bit with a pre-defined program. However, for the final obstacle course, I will be implementing the sensors for obstacle detection.


To start, I had a read of all the instruction manuals that were available on the Elegoo website. For my first code, I only needed to use the information found in "Lesson 1 Moving Control."

The manual talks about four files that come with the buggy and are used to allow the buggy to move:

  • Main code (i.e. Custom_Buggy_Code_V1)

  • Measuring_speed.cpp

  • Motor.cpp

  • Motor.h

While the latter three are required for the motors to run, the most important of them is "Motor.cpp." Here, we are able to influence how the buggy moves, as well as assign predefined movements to keywords. I would like to stress that this is my first time using header files in Arduino (.cpp files in particular), so some of the things I say may not be right.


To start, here is the initial setup for the motor pins. The motors appear to be attached to a smaller module which determines how each one moves based on electrical inputs. It is clear here that "PWMA_LEFT" represents the left motor, and "PWMB_RIGHT" represents the right motor. These will be used regularly when creating predefined functions.

// in Motor.cpp
// function for the pins
void Motor::Pin_init()
{
  pinMode(AIN1, OUTPUT);
  pinMode(BIN1, OUTPUT);
  pinMode(PWMA_LEFT, OUTPUT);
  pinMode(PWMB_RIGHT, OUTPUT);
  pinMode(STBY_PIN, OUTPUT);
  digitalWrite(STBY_PIN, HIGH);
}

Next up, the code sets up five different predefined functions. Each of these functions checks for two things when called for:

  • Is the motor spinning backwards, or forwards?

  • What speed will the motor be spinning?

From my testing, I found that a 0 represents forward motion, while a 1 represents backward motion. Using this idea, the code for each function becomes much clearer. By setting up these functions, it keeps the main code clean as you only have to type "Motor.<FunctionName>(SPEED)," to execute the movement at the specified speed (more on that later).


Below you can see all the functions I currently have in "Motor.cpp" that relate to the movement of the buggy.

// in Motor.cpp

void Motor::Stop() // stop buggy from moving
{
  digitalWrite(AIN1, HIGH);
  digitalWrite(BIN1, LOW);
  analogWrite(PWMA_LEFT, 0);
  analogWrite(PWMB_RIGHT, 0);
}

void Motor::Forward(int speed) // move buggy forward
{

  // 0 = forward motion, 1 = back motion?
  digitalWrite(AIN1, 0);
  digitalWrite(BIN1, 0);
  analogWrite(PWMA_LEFT, speed);
  analogWrite(PWMB_RIGHT, speed);
}

void Motor::Back(int speed) // move buggy back
{
  digitalWrite(AIN1, 1);
  digitalWrite(BIN1, 1);
  analogWrite(PWMA_LEFT, speed);
  analogWrite(PWMB_RIGHT, speed);
}

void Motor::Left(int speed) // move buggy forward left, as oppose to rotate left
{
  digitalWrite(AIN1, 0);
  digitalWrite(BIN1, 0);
  analogWrite(PWMA_LEFT, speed);
  analogWrite(PWMB_RIGHT, 0);
}

void Motor::Right(int speed) // move buggy forward right
{
  digitalWrite(AIN1, 0);
  digitalWrite(BIN1, 0);
  analogWrite(PWMA_LEFT,0);
  analogWrite(PWMB_RIGHT,speed);
}

With this header file setup, these functions can be called in the main code using the following commands (with my motor defined as "Motor"):

  • Motor.Stop(); Stops both motors from moving.

  • Motor.Forward(SPEED); Drives the buggy forward at a specified speed.

  • Motor.Back(SPEED); Drives the buggy backwards at a specified speed.

  • Motor.Left(SPEED); Moves the buggy left AND forward at a specified speed.

  • Motor.Right(SPEED); Moves the buggy right AND forward at a specified speed.

Moving on to the main code, the setup is mainly standard. I called on the "Motor.h" header file (which calls on the "Motor.cpp" file), defined the button "KEY_MODE" at pin 10, and specified the speed at which I wanted the motors to spin when active. Additionally, in the setup function, I called on the pins that controlled the motors, and the encoder which would encode my specified speed to the board with minimal effort.

#include "Motor.h"

// include button pin (PIN 10 IS THE BUTTON PIN)
#define KEY_MODE 10

// Name the motor as "Motor"
Motor Motor;

/*You can set the speed: 0~255 */
#define SPEED 100

// All this is required for encodcer fucntion 
char strbuf[][50]={
                    "Forward:encoder_count_right_a:",
                    "Forward:encoder_count_left_a:",
                    "Back:encoder_count_right_a:",
                    "Back:encoder_count_left_a:",
                    "Left:encoder_count_right_a:",
                    "Left:encoder_count_left_a:",
                    "Right:encoder_count_right_a:",
                    "Right:encoder_count_left_a:"
                   };

void setup() {


  // call input pins
  Motor.Pin_init();

  // include speed encoder
  Motor.Encoder_init();
  Serial.begin(9600);

}

I then wrote a simple program which, upon pressing the front button, would:

  • Wait 2 seconds.

  • Move the buggy forward for 2 seconds.

  • Move the buggy backwards for 2 seconds.

  • Spin the buggy left for 2 seconds.

  • Spin the buggy right for 2 seconds.

  • Stop the buggy.

  
  // in Custom_Buggy_Code_V1
  // Read the button state, 0 = pushed, 1 = not pushed 
  int buttonState = digitalRead(KEY_MODE);
  Serial.println(buttonState);
  
  if (buttonState == 0){
  // Testing the buggy moving 
    // delay just in case your finger gets stuck
    delay(2000);
    Motor.Forward(SPEED);
    delay(2000);
    Motor.Back(SPEED);
    delay(2000);
    Motor.Left(SPEED);
    delay(2000);
    
    Motor.Right(SPEED);
    delay(2000);

    // stop wheels moving
    Motor.Stop();

And, it actually managed to work as you can see in this video!

So, that was me building my Elegoo buggy! I hope you enjoyed reading my blog and hopefully, you learned something from it! Remember, don't forget to keep up to date with my blogs by subscribing to my mailing list OR, follow me on my Instagram, @joeceengineering! My IGTV about the assembly will also be out soon, so stay tuned to that!


Once again, thank you so much for reading and I hope to see you again!






44 views0 comments

Recent Posts

See All