Bot Basics!
databot™ Basic Training
databot™ 2.0 is an amazing tool built on the Espressif ESP32 microcontroller. The ESP32 is used widely around the world in all kinds of devices ranging from home automation systems to hobbyist robots. Due to its popularity it can be programmed on a number of platforms and one of the most popular is the Arduino IDE. Read on to learn how to setup and code databot™ using the IDE!
Overview
Prepare to code! There are five stages to this process and if all goes smoothly you should be up and running in fifteen minutes.
- Install the Arduino IDE.
- Install the ESP32 hardware packages for the IDE.
- Activate and configure the correct ESP32 package for databot™.
- Install the databot 2.0 Libraries
- Test your code and connection to databot™ with your first data sketch!
Good luck and good coding – you are only minutes away from taking control of databot™
Step 1 – Installing the Arduino IDE
First step is to install the Arduino IDE The Arduino story is an exciting one, if you’re not familiar with it, you can get a quick run down by going through our online learning module Intro to Arduino.
In a nutshell, Arduino is an open source initiative with an enormous global community using it for education, invention, industry, and fun.
To begin your great databot™ coding adventure install the Arduino IDE (Integrated Development Environment). It is available for Win / Mac / Linux platforms – so you can code databot™ on just about any device! Click on the link below to visit the official Arduino site and select the right download for your system.
https://www.arduino.cc/en/software
Once your installation is complete the IDE will open up a new “sketch” window. Programs are called sketches in the Arduino ecosystem so you can see what the code looks like in this first window. You will also see the IDE software options in a menu across the top of your screen. The images below show the IDE on Windows (left) and MacOS (right). The only difference you will see in your installation instructions between the two is look for the “Preferences” menu under the Arduino IDE menu for MacOS and under the File menu for Windows.
Step 2 – Installing the ESP32 (databot™) Board Package
The ESP32 microcontroller on board databot™ is manufactured by Espressif Systems. To program it you will need to add it to the official Board library of the Arduino IDE.
1. Open your “Preferences” Menu as shown below.
2. Copy and Paste the following URL into the Additional boards manager URLs field in the form.
https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
3. Select OK to update the board manager!
Now that these files are available to the Arduino IDE Board Manager we need to install them. Go to your Tools menu, scroll down to Board, then select Boards Manager.
The Boards Manager will show up on the left hand side of your IDE as shown below. Look for the esp32 by Espressif Systems package. Select Version 2.0.4 (Important, as of 4 February, 2023 versions above 2.0.4 will not work. This notice will be updated when the new release is available). Select Install and the esp32 packages will begin downloading and installing. It may take a few minutes for this process to complete.
Upon concluding the package installation you should see the esp32 by Espressif Systems displaying INSTALLED. Good job!
Step 3 – Activate and Configure Your ESP32 Board (databot™)
Now that the packages are available, go to the Tools | Board | Boards Manager menu and select the ESP32 Wrover Module as shown. This is the correct hardware selection for the databot™ 2.0 microcontroller.
Check your board settings, you will see them displayed in the Tools menu, and confirm the following configuration:
- Flash Frequency 80MHz
- Flash Mode QIO
- Partition Scheme Huge APP
- Upload Speed 921600
Step 4 – Installing the databot™ Library
Now that you have installed your ESP32 databot™ board, you can download the databot™ Arduino library and test it out! Go to the Tools menu and select Manage Libraries. Install the databot2 library (make sure it is databot2) – this is the one for the ESP32. Once installed you can navigate from the File menu to Examples and scroll down until you find the databot2 library. There you will find folders holding various sketches. To test CO2, go to databot2 | Sensors | CO2 and load the sketch. Now go to the next step and let’s see it in action!
Step 5 – Testing Your First Sketch!
With your sketch loaded, you now need to connect to databot™! Plug your databot™ in to an open port on your computer and turn it on. In Windows you should see an active COM port and your computer will recognize it with a sound that a device has been added. On MacOS you will see available devices listed and you will be looking for a usb to serial device similar to this: /dev/cu.usbserial-1420.
Note: If you are not seeing an active port, disconnect databot™ and restart your system and try again. If it is still not being recognized you may need to install the CH341a USB to Serial driver. System drivers are located on the manufacturers website for MacOS, Windows, and Linux. Follow the driver installation instructions and then try connecting to databot™ again.
Now that you are connected select the “Upload” option (the arrow pointing to the right) and your CO2 sketch will compile and upload to databot™. Once it completes the upload it will reset and be actively running your CO2 sketch. You can see the CO2 data in the serial monitor by clicking on the magnifying glass in the upper right hand corner of your IDE window. The monitor displays the data in the lower window of your IDE as shown below. You are officially up and running and ready to code! The next step will show you how to change your code and begin experimenting.
Note on Compiling Times: Compiling code in the Arduino IDE can be a time consuming process depending on your hardware, you will want to test and troubleshoot before introducing to a class and plan accordingly. Older and lower performance systems may take as long as eight or nine minutes to compile a sketch initially. Subsequent compile times for your sketch will be much shorter as the core compilations are not done each time. Examples:
MacOS: 2018 Mac Air, 1.6 GHz Dual-Core Intel Core i5; 8GB RAM Initial compile time for CO2 1:28; subsequent compiles 20 seconds.
Windows: 2022 12th Gen Intel(R) Core(TM) i7-12700K 3.61 GHz; 16GB RAM. Initial compile time for CO2 1:09; subsequent compile times 14 seconds.
For your first coding challenge, you will be changing the format of the data output. Looking at the default serial monitor you should be seeing output formatted as shown above: CO2 404.00 ppm. This is very clear output for the text based monitor, but what if we ant to look at the data in a visual plotter? The Arduino IDE includes a visual data plotter but it cannot understand text, it just reads numbers. So we need to change our sketch to modify the output. You are going to change lines 34, 35, and 36 as shown in the image below. When you put // marks at the beginning of a line these are flagged as “comments” and are not part of your compiled program. You can put all kinds of comments in your code and are encouraged to document your work in this fashion. To remove the text labels of CO2 and ppm comment out lines 34 and 36. Now change line 35 from Serial.print(CO2) to Serial.println(CO2) so it will generate a line break after each value.
Upload your new code and activate the serial monitor again. Are your numbers displayed as shown below with no text now? If yes, great job – go on to the final step below! If no, review the changes you made – did you make any errors?
Final step! If your number values are displaying with no text as shown above, you can launch the “Serial Plotter” by selecting the waveform icon next to the Serial Console magnifying glass. You should see the data display as show below!
Congratulations!
You have successfully completed an exploration of the remarkable capabilities at your fingertips for programming and modifying databot™ to study the world around you and explore data. Now comes the fun part, challenge yourself to begin programming and inventing with databot™. Can you invent something that will make a better world?! Have fun!